Genius implements modular arithmetic.
To use it you just add "mod <integer>" after
the expression. Example:
It could be possible to do modular arithmetic by computing with integers and then modding in the end with
the
% operator, but
that may be time consuming if not impossible when working with larger numbers.
For example
10^(10^10) % 6 will simply not work (the exponent
will be too large), while
10^(10^10) mod 6 is instanteneous.
You can calculate the inverses of numbers mod some integer by just using
rational numbers (of course the inverse has to exist).
Examples:
10^-1 mod 101
1/10 mod 101 |
You can also do modular evaluation with matrices including taking inverses,
powers and dividing.
Example:
A = [1,2;3,4]
B = A^-1 mod 5
A*B mod 5 |
This should yield the identity matrix as B will be the inverse of A mod 5.
Some functions such as
sqrt or
log
work in a different way when in modulo mode. These will then work like their
discrete versions working within the ring of integers you selected. For
example:
genius> sqrt(4) mod 7
=
[2, 5]
genius> 2*2 mod 7
= 4 |
sqrt will actually return all the possible square
roots.