Maturity Index:Relatively immature
Every integer mod p keeps its own copy of the modulus; you don't need to set a global modulus. As a consequence, it is possible to do multiple calculations modulo a different prime, even concurrenlty.
IntegerModp is the prototype, in the Computer Algebra Kit, of a field i.e., a structure where each (nonzero) element has a multiplicative inverse (see inField and inverse). Matrix (in Gaussian elimination) and Polynomial (in polynomial division) take advantage of the field structure of scalars, such as integers mod p.
+ newModulus :(unsigned short) aPrimeCreates a new object, equal to zero, with modulus equal to aPrime. The modulus must be a prime number greater than 2 and less than or equal to USHRT_MAX_PRIME.
newIntValue:modulus:
+ newIntValue :(int) intValue modulus :(unsigned short) aPrime
Creates a new object with modulus equal to aPrime. The value of the object is equal to intValue mod aPrime. The modulus must be a prime number greater than 2 and less than or equal to USHRT_MAX_PRIME.
hash
- (unsigned) hash
Returns a small integer that is the same for objects that are equal (in the sense of isEqual:).
isEqual:
- (BOOL) isEqual : b
modulus
- (unsigned short) modulus
Returns the modulus, a prime number greater than 2 and equal to or less than USHRT_MAX_PRIME.
intValue
- (int) intValue
Returns a representant of the modular number in the range [0,modulus[.
intValue:
- intValue :(int) aValue
Returns a new object for aValue, modulo the modulus of the receiving object.
zero
- zero
isZero
- (BOOL) isZero
Whether the object is equal to zero.
isOpposite:
- (BOOL) isOpposite : b
Whether the object is the opposite of b.
negate
- negate
Returns the opposite of the object.
double
- double
Returns a new object, equal to the object multiplied by two i.e., added to itself.
add:
- add : b
Adds b to the object. Returns a new object.
subtract:
- subtract : b
Subtracts b from the object. Returns a new object.
one
- one
minusOne
- minusOne
isOne
- (BOOL) isOne
Whether the object is equal to one.
isMinusOne
- (BOOL) isMinusOne
Whether the object is equal to minus one.
square
- square
Returns the square of the object i.e., a new object equal to the original object multiplied by itself.
multiply:
- multiply : b
Returns a new object, the product of the object multiplied (to the right) by b. If the objects are pointer equal, this method is equivalent to square.
inverse
- inverse
Returns the multiplicative inverse of the object (returns a new object). Returns nil if the object is equal to zero or cannot be inverted.
divide:
- divide : b
Multiplies the object by the inverse of b. Returns nil if b is zero (has no inverse).
characteristic
- (int) characteristic
Returns the modulus of the object.
frobenius
- frobenius
Simply returns a new reference to the object itself, since the p-th power of an integer modulo p is equal to that integer.
frobeniusInverse
- frobeniusInverse
Simply returns a new reference to the object itself, since the p-th power of an integer modulo p is equal to that integer. This method also returns zero for the zero object.