# intmodp Specification Sheet

Computer Algebra Kit (c) 1993,00 by Comp.Alg.Objects. All Rights Reserved.

# IntegerModp

Inherits from: CAObject

Maturity Index: Relatively immature

## Class Description

Instances are integers modulo a small, prime number, the modulus of the object. The modulus can currently not be equal to two; it must be equal to or less than USHRT_MAX_PRIME (the largest prime number that fits in an unsigned short word, as defined in the header file cakit/IntegerModp.h). Objects belong to the same class in the sense of sameClass: iff. the moduli are equal.

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.

## Method types

### Creation

- modulus:
- int:modulus:

### Identity

- hash
- isEqual:
- modulus
- intValue
- intValue:

### Addition

- zero
- isZero
- isOpposite:
- negate
- double
- add:
- subtract:

### Multiplication

- one
- minusOne
- isOne
- isMinusOne
- square
- multiply:
- inverse
- divide:

### Characteristic

- characteristic
- frobenius
- frobeniusInverse

### Printing

- printsLeadingSign
- printOn:

## Methods

### modulus:

> +modulus:(unsigned short)aPrime

Creates a new object, equal to zero, with modulus equal to aPrime. The modulus must be a prime number less than or equal to USHRT_MAX_PRIME.

### int:modulus:

> +int:(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 less than or equal to USHRT_MAX_PRIME.

### modulus

> - (unsigned short)modulus

Returns the modulus, a prime number 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

### one

> -one

### minusOne

> -minusOne

### 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.

### printsLeadingSign

> - (BOOL)printsLeadingSign

Returns NO, because representants are taken positive for printing.

### printOn:

> -printOn:(IOD)aFile

Prints a (nonnegative) representant of the integer modulo p.