;;; MODULAR-INVERSE (x p) [FUNCTION] ;;; Find the inverse of X modulo prime P, using Euclid algorithm. ;;; ;;; MODULAR-DIVISION (x y p) [FUNCTION] ;;; Divide X by Y modulo prime P. ;;; ;;; *INVERSE-BY-LOOKUP-LIMIT* (100000) [VARIABLE] ;;; If prime modulus is < this number then the division algorithm ;;; will use a lookup table of inverses created at the time when ;;; field-modulo-prime is called. ;;; ;;; MAKE-INVERSE-TABLE (modulus &aux (table (list 0))) [FUNCTION] ;;; Make a vector of length MODULUS containing all inverses modulo ;;; MODULUS, which should be a prime number. The inverse of 0 is 0. ;;; ;;; MAKE-MODULAR-DIVISION (modulus) [FUNCTION] ;;; Return a function of two arguments which will perform division ;;; modulo MODULUS. Currently, if MODULUS is < *INVERSE-BY-LOOKUP-LIMIT* ;;; then the returned function does table lookup, otherwise it uses ;;; the Euclid algorithm to find the inverse. ;;;