STANDARD MATH MODULE
The Standard Mathematicalmodule is an original implementation of various mathematical facilities. The module can be divided into several catgeories which include convenient functions, linear algebra and real analysis.
Random number services
The mathmodule provides various functions that generate random numbers in different formats.
Function  Description 
getrandominteger  return a random integer number 
getrandomreal  return a random real number between 0.0 and 1.0 
getrandomrelatif  return a random relatif number 
getrandomprime  return a random probable prime relatif number 
The numbers are generated with the help of the system random generator. Such generator is machine dependant and results can vary from one machine to another.
Primality testing services
The mathmodule provides various predicates that test a number for a primality condition. Most of these predicates are intricate and are normally not used except the primeprobableppredicate.
Predicate  Description 
fermatp  Fermat test predicate 
millerrabinp  MillerRabin test predicate 
primeprobablep  general purpose prime probable test 
getrandomprime  return a random probable prime relatif number 
The fermatpand millerrabinppredicates return true if the primality condition is verified. These predicate operate with a base number. The prime number to test is the second argument.
Fermat primality testing
The fermatppredicate is a simple primality test based on the "little Fermat theorem". A base number greater than 1 and less than the number to test must be given to run the test.
afnix:mth:fermatp 2 7
In the preceeding example, the number 7 is tested, and the fermatppredicate returns true. If a number is prime, it is guaranted to pass the test. The oppositte is not true. For example, 561 is a composite number, but the Fermat test will succeed with the base 2. Numbers that successfully pass the Fermat test but which are composite are called Carmichael numbers. For those numbers, a better test needs to be employed, such like the MillerRabin test.
MillerRabin primality testing
The millerrabinppredicate is a complex primality test that is more efficient in detecting prime number at the cost of a longer computation. A base number greater than 1 and less than the number to test must be given to run the test.
afnix:mth:millerrabinp 2 561
In the preceeding example, the number 561, which is a Carmichael number, is tested, and the millerrabinppredicate returns false. The probability that a number is prime depends on the number of times the test is ran. Numerous studies have been made to determine the optimal number of passes that are needed to declare that a number is prime with a good probability. The primeprobableppredicate takes care to run the optimal number of passes.
General primality testing
The primeprobableppredicate is a complex primality test that incorporates various primality tests. To make the story short, the prime candidate is first tested with a series of small prime numbers. Then a fast Fermat test is executed. Finally, a series of MillerRabin tests are executed. Unlike the other primality tests, this predicate operates with a number only and optionally, the number of test passes. This predicate is the recommended test for the folks who want to test their numbers.
afnix:mth:primeprobablep 17863
STANDARD MATH REFERENCE
Functions

getrandominteger > Integer (noneInteger)
The getrandomintegerfunction returns a random integer number. Without argument, the integer range is machine dependent. With one integer argument, the resulting integer number is less than the specified maximum bound.

getrandomreal > Real (noneBoolean)
The getrandomrealfunction returns a random real number between 0.0 and 1.0. In the first form, without argument, the random number is between 0.0 and 1.0 with 1.0 included. In the second form, the boolean flag controls whether or not the 1.0 is included in the result. If the argument is false, the 1.0 value is guaranted to be excluded from the result. If the argument is true, the 1.0 is a possible random real value. Calling this function with the argument set to true is equivalent to the first form without argument.

getrandomrelatif > Relatif (IntegerInteger Boolean)
The getrandomrelatiffunction returns a n bits random positive relatif number. In the first form, the argument is the number of bits. In the second form, the first argument is the number of bits and the second argument, when true produce an odd number, or an even number when false.

getrandomprime > Relatif (Integer)
The getrandomprimefunction returns a n bits random positive relatif probable prime number. The argument is the number of bits. The prime number is generated by using the MillerRabin primality test. As such, the returned number is declared probable prime. The more bits needed, the longer it takes to generate such number.

getrandombitset > Bitset (Integer)
The getrandombitsetfunction returns a n bits random bitset. The argument is the number of bits.

fermatp > Boolean (IntegerRelatif IntegerRelatif)
The fermatppredicate returns true if the little fermat theorem is validated. The first argument is the base number and the second argument is the prime number to validate.

millerrabinp > Boolean (IntegerRelatif IntegerRelatif)
The millerrabinppredicate returns true if the MillerRabin test is validated. The first argument is the base number and the second argument is the prime number to validate.

primeprobablep > Boolean (IntegerRelatif [Integer])
The primeprobableppredicate returns true if the argument is a probable prime. In the first form, only an integer or relatif number is required. In the second form, the number of iterations is specified as the second argument. By default, the number of iterations is specified to 56.