Coding Math

Modular arithmetic

$a\equiv b\space(\text{mod}\space n)$ means a mod n = b mod n. The parentheses mean that $(\text{mod}\space n)$ applies to the entire equation, not just to the right-hand side.

Reflexivity, Symmetry and Transitivity:

  • $a\equiv a\space(\text{mod}\space n)$
  • $a\equiv b\space(\text{mod}\space n) \Leftrightarrow b\equiv a\space(\text{mod}\space n)$
  • If $a\equiv b\space(\text{mod}\space n)$ and $b\equiv c\space(\text{mod}\space n)$, then $a\equiv c\space(\text{mod}\space n)$

If $a_1\equiv b_1\space(\text{mod}\space n)$ and $a_2\equiv b_2\space(\text{mod}\space n)$, or if $a\equiv b\space(\text{mod}\space n)$, then:

  • $a+k\equiv b+k\space(\text{mod}\space n)$, for any integer $k$
  • $ka\equiv kb\space(\text{mod}\space n)$, for any integer $k$
  • $a_1+a_2\equiv b_1+b_2\space(\text{mod}\space n)$
  • $a_1-a_2\equiv b_1-b_2\space(\text{mod}\space n)$
  • $a_1a_2\equiv b_1b_2\space(\text{mod}\space n)$
  • $a^k\equiv b^k\space(\text{mod}\space n)$, for any non-negative integer $k$
  • $p(a)\equiv p(b)\space(\text{mod}\space n)$, for any polynomial $p(x)$ with integer coefficients

Compatibility with translation, scaling, addition, subtraction, multiplication, exponentiation and polynomial evaluation.

Read exponential expressions

2^16: two to the power of sixteen. 3^4: three to the power of four. x^2: x squared. x^3: x cubed.

Author

Weihao Ye

Posted on

2022-01-10

Updated on

2022-05-08

Licensed under