NumTheory

© 2009 John Abbott
GNU Free Documentation License, Version 1.2



index page

User documentation

Generalities

The functions in the NumTheory file are predominantly basic operations from number theory. Most of the functions may be applied to machine integers or big integers (i.e. values of type ZZ). Please recall that computational number theory is not the primary remit of CoCoALib, so do not expect to find a complete collection of operations here -- you would do better to look at Victor Shoup's NTL (Number Theory Library), or PARI/GP, or some other specialized library/system.

The Functions Available For Use

Several of these functions give errors if they are handed unsuitable values: unless otherwise indicated below the error is of type ERR::BadArg.

The main functions available are:

Maintainer Documentation

Correctness of ExtendedEuclideanAlg is not immediately clear, because the cofactor variables could conceivably overflow -- in fact this cannot happen (at least on a binary computer): for a proof see Shoup's book A Computational Introduction to Number Theory and Algebra, in particular Theorem 4.3 and the comment immediately following it. There is just one line where a harmless "overflow" could occur -- it is commented in the code.

Several functions are more complicated than you might expect because I wanted them to be correct for all possible machine integer inputs (e.g. including the most negative long value).

In some cases the function which does all the work is implemented as a file local function operating on unsigned long values: the function should normally be used only via the "dispatch" functions whose args are of type MachineInteger or ZZ.

Bugs, Shortcomings, etc.

Several functions return unsigned long values (which could cause nasty surprises to unwary users unfamiliar with the foibles of unsigned values in C++).

Should there also be procedural forms of functions which return ZZ values? (e.g. gcd, lcm, InvMod, PowerMod, and so on).

Certain implementations of PowerMod should be improved (e.g. to use PowerModSmallModulus whenever possible). Is behaviour for 0^0 correct?

LucasTest should produce a certificate.