Évaluation modulaire

Genius implements modular arithmetic. To use it you just add "mod <integer>" after the expression. Example: 2^(5!) * 3^(6!) mod 5 It could be possible to do modular arithmetic by computing with integers and then modding in the end with the % operator, which simply gives the remainder, 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 instantaneous. The first expression first tries to compute the integer 10^(10^10) and then find remainder after division by 6, while the second expression evaluates everything modulo 6 to begin with.

Vous pouvez calculer l'inverse de nombres modulo des entiers juste en utilisant des nombres rationnels (bien sûr, l'inverse doit exister). Exemples :

10^-1 mod 101
1/10 mod 101

Vous pouvez aussi faire de l'évaluation modulaire avec des matrices y compris prendre l'inverse, mettre à la puissance ou multiplier. Exemple :

A = [1,2;3,4]
B = A^-1 mod 5
A*B mod 5

Cela doit donner la matrice identité car B est l'inverse de A modulo 5.

Certaines fonctions telles que sqrt ou log fonctionnent différemment en mode modulaire. Elles vont alors fonctionner comme leur version discrète travaillant avec l'ensemble des entiers que vous avez sélectionnés, par exemple,

genius> sqrt(4) mod 7
=
[2, 5]
genius> 2*2 mod 7
= 4

La fonction sqrt renvoie en fait toutes les racines carrées possibles.

Do not chain mod operators, simply place it at the end of the computation, all computations in the expression on the left will be carried out in mod arithmetic. If you place a mod inside a mod, you will get unexpected results. If you simply want to mod a single number and control exactly when remainders are taken, best to use the % operator. When you need to chain several expressions in modular arithmetic with different divisors, it may be best to just split up the expression into several and use temporary variables to avoid a mod inside a mod.