Mod
Class Mod
Elements of the residue class rings Z[m]
Mod(n, m)
returns element n des of the residue class ring Z[m]
Arithmetic operators may be applied to the objects.
Some operations are defined only,
if Z[m] is a field (<==> m is prime number)
See also Mod
Overview:
Mod (n, m)
Operator | Meaning |
abs(x) | |
x + y | Addition |
x / y | |
x == y | with other Mod object or 0 |
int(x) | |
x * y | a * b à a.__mul__(b), if a is of type Mod b.__rmul__(a), otherwise |
x != y | with other Mod object or 0 |
-x | -a à a.__neg__() |
str(x) | |
x - y | a - b à a.__sub__(b), if a is of type Mod b.__rsub__(a), otherwise |
x / y | a / b à a.__div__(b), if a is of type Mod b.__rdiv__(a), otherwise |
Method | Meaning |
copy () | independent copy ("clone") of A |
inverse () | Multiplicative inverse |
operators () | For documentation only |
Constructor
Usage: Mod(n, m)
Absolute value
Usage: abs(x)
Description:
a.__add__(b)
Usage: x + y
Description:
Addition
Also operator notation: a + b
Instead of a = a + b
you can write a += b
.
Usage:
Usage: x / y
Test for equality (operator ==)
Usage: x == y
Description:
with other Mod object or 0
Usage: int(x)
Multiplication:
Usage: x * y
Description:
a * b à a.__mul__(b), if a is of type Mod
b.__rmul__(a), otherwise
Test for unequality (Operator !=)
Usage: x != y
Description:
with other Mod object or 0
Unary Operator -
Usage: -x
Description:
-a à a.__neg__()
Object representation as string
Usage: str(x)
Description:
Subtraction:
Usage: x - y
Description:
a - b à a.__sub__(b), if a is of type Mod
b.__rsub__(a), otherwise
exact division:
Usage: x / y
Description:
a / b à a.__div__(b), if a is of type Mod
b.__rdiv__(a), otherwise
A.copy()
Usage: self.copy()
Description:
independent copy ("clone") of A
p.inverse()
Usage: self.inverse()
Description:
Multiplicative inverse
defined in fields only. Therefore modulus must be prime number!
Mod.operators()
Usage: self.operators()
Description:
For documentation only
The following operators are defined in the class Mod:
Op. | Function | Examples |
---|---|---|
+ | Addition | a + b; a += b |
- | Subtraction | a - b; a -= b |
* | Multiplication | a * b; a *= b |
/ | Division | a / b; a /= b |
% | Modulo (in fields only , i.e. modulus is prime) | a & b; a &= b |
- | Unary minus | -a |