home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / compiler / ubasic / malm / malm.doc < prev    next >
Text File  |  1989-04-25  |  20KB  |  428 lines

  1.  
  2.  
  3. 14 March 1991
  4.  
  5. Procedures  ( File : ProcedureList )
  6. All procedures/functions written by Donald E. G. Malm and copyright by him. 
  7.  
  8. For each procedure/function we normally give its Pascal heading, together with 
  9. other pertinent information.  The UBASIC versions are like the Pascal versions, 
  10. using the same variable names.  The procedures are listed alphabetically,
  11. with the separation of the Pascal routines into the three files BODY 1,2, and 3
  12. indicated.  (The UBASIC subroutines are in individual files.)  There are minor 
  13. differences between the UBASIC and Pascal versions, chiefly because UBASIC has 
  14. no Boolean or character variables.
  15.  
  16.  
  17.  
  18. **************************    BODY1   *************************************
  19.  
  20. PROCEDURE BWppt1(n : number; VAR f : integer);
  21. { Baillie-Wagstaff Lucas pseudoprime test.  See their paper.  We assume
  22.   n is odd and > 11.  D is chosen by method "A".  f is 1 to indicate that n 
  23.   is a probable prime, 0 for composite, and -1 if n is a square.  Requires
  24.   unit MultiP.  Calls Add, Sub, Mul, Dvd, Dvdby2, Equal, Isqrt, Jacobi, and
  25.   Modd. }
  26. { 6 June 1990 }
  27. The article is "LUCAS PSEUDOPRIMES", Robert Baillie and Samuel S. Wagstaff, Jr., 
  28. Math. Comp., v. 35 (1980) pp. 1391-1417.
  29.  
  30.  
  31. PROCEDURE BWppt2(n : number; VAR f : integer);
  32. { Baillie-Wagstaff strong Lucas pseudoprime test.  See their paper.  We assume 
  33.   n is odd and > 11.  D is chosen by method "A*".  f is 1 to indicate that n
  34.   is a probable prime, 0 for composite and -1 if n is a square.  Requires unit
  35.   MultiP.  Calls Add, Sub, Mul, Dvd, Dvdby2, Isqrt, Equal, Modd, Jacobi, and 
  36.   Spwr. }
  37. { 6 June 1990  }
  38.  
  39.  
  40.  
  41. UBASIC: There is a subroutine Cgcd(A,B,&C,&Ca,&Cb). This is part of the unit
  42. MultiP in the Pascal versions.
  43.  
  44.  
  45.  
  46. PROCEDURE Chinese(n:longint; VAR A,B,M:Chn; VAR soln, modulus : number);
  47. { Algorithm for Chinese remaindering of the system A[i] X = B[i] (mod M[i]),
  48.   1 = 1,..,n.  It is NOT assumed that the moduli M[i] are pairwise relatively
  49.   prime.  Soln holds the solution. If there is no solution, modulus = 0,
  50.   otherwise modulus is the modulus of uniqueness of the solution.  Variables A,
  51.   B, and M are input variables; they are VAR only for efficiency.  The type Chn
  52.   is imported from the unit MultiP.  Requires MultiP.  Calls Fcgcd, Dvd, Mul,
  53.   Sub, Add, and Mod. Uses the type Chn.  }        
  54. { 4 August. 1990 }
  55.  
  56.  
  57.  
  58. PROCEDURE Confrat(VAR C : tenr; leng : longint; VAR a,b : number);
  59. { From the finite continued fraction C this procedure calculates the
  60.   rational a/b that corresponds.  Reverses the procedure Ratconf.  Parameter
  61.   C is VAR only for efficiency; it is an input parameter.  leng is the last
  62.   index used in C.  Note that it is assumed that leng >= 0.  Requires unit
  63.   MultiP, including type tenr.  Calls Mul and Add. }
  64. { 7 Jan. 1990 }
  65.  
  66.  
  67. PROCEDURE Elcfctr(n,c1,c2,a : number; VAR f : number);
  68. { Elliptic curve method to factorize n, returning a factor in f.  The
  69.   parameters c1,c2, and a are chosen randomly - more than one choice
  70.   may be necessary.  Requires unit MultiP.  Calls Add, Sub, Mul, Modd,
  71.   and Gcd.  }
  72. { 14 March 1991 }
  73.  
  74.  
  75. PROCEDURE Fermat(a : number; ubnd : longint; VAR f,g : number);
  76. {  Fermat's method of factoring a.  ubnd limits the number of iterations.
  77.    The factors (or -1 if ubnd is reached) are placed in f and g.  a must
  78.    be positive and odd.  Requires Unit MultiP.  Calls Isqrt, Mul, Add, Sub,
  79.    Equal, and Dvdby2. }
  80. {  30 Dec. 1989 }
  81.  
  82.  
  83.  
  84. UBASIC: There is a subroutine Fcgcd(A,B,&C,&Ca).  This is part of the unit
  85. MultiP in the Pascal versions.
  86.  
  87.  
  88.  
  89. PROCEDURE Gpcftoq(VAR CF : tenr; leng1,leng2 : longint; VAR A,B,C : number);
  90. { General periodic continued fraction to quadratic routine.  CF contains the
  91.   continued fraction - indexes 0 through leng1 contain the first part before
  92.   the period while indexes leng1+1 through leng2 contain the complete period.
  93.   It is assumed that the continued fraction represents a positive number.
  94.   CF is an input variable, made VAR for efficiency. A, B, and C return the
  95.   coefficients of the quadratic satisfied by the continued fraction z : 
  96.   A z^2 + Bz + C = 0.  There is no error checking to detect improper input.  
  97.   Requires unit MultiP, including type tenr.  Calls Mul, Add, Sub, Gcd, and Dvd. }   
  98. { 8 Jan. 1990 }
  99.  
  100.  
  101. PROCEDURE Lambda(VAR P, M : triala; k : longint; VAR Lam : number);
  102. { Returns in Lam the value of Carmichael's function - the minimum universal
  103.   exponent.  P, M, and k have the same meaning as in Sigma, and P and M are
  104.   input varaibles - VAR only for efficiency.  Defines by  convention
  105.   Lambda(1) = 0.  Requires unit MultiP, including type triala.  Calls Mul, Sub,
  106.   Dvd, and Gcd.  }
  107. { 2 May 1990 }
  108.  
  109.  
  110. PROCEDURE LDiosys(r,c : integer; VAR A,V : NumMat; VAR soln : Boolean;
  111.                     VAR rank : integer);                    
  112. { Solves the linear Diophantine system represented by the (augmented)
  113.   matrix A.  Matrix V contains a record of the manipulations.  A is r by c+1,
  114.   while V is c by c.  Soln is TRUE if there is a solution, otherwise FALSE.
  115.   Rank is the rank of the system.  Contains the function Pivotind.  Requires
  116.   unit MultiP.  Calls Sub, Mul, Dvd, Less, and Modd. Type NumMat is supplied
  117.   by MultiP. }
  118. { 16 June 1990 }
  119. This is the algorithm described in "A COMPUTER LABORATORY MANUAL FOR NUMBER
  120. THEORY, by Donald E. G. Malm, COMPRess, 1980.
  121.  
  122.  
  123. PROCEDURE Lehmer(p,q : number; VAR r : number);
  124. { D. H. Lehmer's method of solving x^2 = q (mod p), assuming that p is an
  125.   odd prime and q is a quadratic residue modulo p.  The solution is 
  126.   returned in r.  Requires unit MultiP.  Calls Add, Sub, Mul, Dvd, Dvdby2,
  127.   Spwr, Equal, Less, Jacobi, and Modd. }
  128. { 7 June 1990 }
  129. The algorithm is described in Lehmer's article "COMPUTER TECHNOLOGY APPLIED 
  130. TO THE THEORY OF NUMBERS", in "STUDIES IN NUMBER THEORY", MAA 1969,
  131. pp. 117 - 151.
  132.  
  133.  
  134. FUNCTION Mobius(VAR M : triala; k : longint) : longint;
  135. { Returns the Mobius function.  M and k have the same meaning as in Tau.
  136.   Requires unit MultiP for the type triala.  Calls no procedures nor functions.}
  137. { 22 April 1990 }
  138. UBASIC supplies this as a function in the language.
  139.  
  140.  
  141.  
  142. ********************************   BODY2   ************************************
  143.  
  144.  
  145. PROCEDURE Mppt(n,Q : number; VAR f : Boolean);
  146. { Implements Malm's probabilistic test for primality (or compositeness).
  147.   Assumes n is odd, not a square, and that (Q|n)=1.  Returns f = TRUE
  148.   if n is probably prime, and f = FALSE if n is composite. Requires unit 
  149.   MultiP.  Calls Add,Sub, Mul, Dvdby2, Modd, Gcd, Less, Jacobi, and Equal. }
  150. { 7 June 1990 }
  151.  
  152. This procedure Mppt and the following one Mst are very effective unpublished
  153. probable prime tests devised by the author.
  154.  
  155. PROCEDURE Mst(n : number; VAR f : Boolean);
  156. { Test for probable primality or compositeness devised by Malm.  Returns
  157.   f = TRUE if n is a probable prime, and f = FALSE if n is composite.  Requires
  158.   unit MultiP.  Calls Add, Sub, Mul, Dvdby2, Modd, Isqrt, Gcd, Equal, Jacobi,and
  159.   Less.  Contains a subprocedure Lehmerc, which is the procedure Lehmer adapted
  160.   to input that is not necessarily prime. }
  161. { 21 August 1990 }
  162.  
  163.  
  164. FUNCTION NxtPrm(a: integer): longint;
  165.  {  Returns the smallest prime greater than a, or else 0 if a < 0 or
  166.     a >= 10,000.  Returns an integer, not a number.  Requires unit MultiP
  167.     for the array prm[]. Calls no procedures nor functions. }
  168.  { 20 April 1990 }
  169.  UBASIC supplies this as a part of the language.
  170.  
  171.  
  172. PROCEDURE Pell(d : number; VAR x,y : number; VAR f : longint);
  173. { Uses continued fractions to compute the smallest nontrivial positive
  174.   solution to x^2 - d y^2 = f, where f is 1 or -1.  Note that f is computed
  175.   by the program; it is not your choice.  f = 0 indicates improper input.
  176.   Requires unit MultiP.  Calls Isqrt, Mul, Sub, Add, Dvd, and Equal. }
  177. {  10 January 1990 }
  178.  
  179.  
  180. Procedure Peralta(p,x : number; VAR s : number);
  181. { Implements Peralta's (second) probabilistic algorithm to compute  
  182.   s for which s^2 = x (mod p), assuming that p is an odd prime and that x 
  183.   is a quadratic residue modulo p.  Requires unit MultiP.  Calls Add, Sub,
  184.   Mul, Dvd, Dvdby2, Modd, Lcs, and Spwr.  }
  185. { 16 May 1990. }
  186. This algorithm is given in "A SIMPLE AND FAST PROBABILISTIC ALGORITHM FOR
  187. COMPUTING SQUARE ROOTS MODULO A PRIME NUMBER", by Rene C. Peralta, IEEE Trans.
  188. Info. Thry.,v. IT-32, pp. 846-848.
  189.  
  190.  
  191. PROCEDURE Perrin(n : number; VAR mc,mb,ma,a,b,c : number);
  192. { Given n, returns the signature of n (mod n) in the six output parameters.
  193.   Perrin-Shanks-Adams sequence. }
  194. { 18 May 1990 }
  195. This algorithm is described in "STRONG PRIMALITY TESTS THAT ARE NOT SUFFICIENT",
  196. by William Adams and Daniel Shanks, Math. Comp. v. 39, 1982, pp. 255-300.
  197.  
  198.  
  199. PROCEDURE Polpm1(n,b : number; ubnd : longint; VAR f,g : number);
  200. {  Pollard p-1 method of factoring n using base b.  ubnd is the maximum
  201.    number of iterations.  f and g hold the factors (or -1 if the method fails
  202.    or 0 if n < 2.). n and b should be relatively prime.  In practice, b is
  203.    small and n has been determined to have no small factors.  Needs Unit 
  204.    MultiP.  Calls Less, Spwr, Sub, Gcd, and Dvd.  ubnd must be less than Base. } 
  205. { 30 Dec. 1989 }
  206. The algorithm is described in "PRIME NUMBERS AND COMPUTER METHODS FOR 
  207. FACTORIZATION", by Hans Riesel, Birkhauser 1985. It is also in the book by D. 
  208. Bressoud listed above.
  209.  
  210.  
  211. PROCEDURE Primen1(n:number; VAR P:triala; leng:longint; VAR f:longint);
  212. { Attempts to prove n (assumed odd) is prime, given a partial prime 
  213.   factorization of  n-1. The array P is an input parameter made VAR for 
  214.   efficiency, which holds the prime factors of n-1.  Leng is the last index used
  215.   in P[].  If n is  prime then f= 1 is returned,while f= 0 is returned for no 
  216.   information and f= -1 for n composite.  Requires unit MultiP.  Calls Sub, Dvd,
  217.   Spwr, Gcd, and Equal.  Uses the array prm[]. }
  218. { 24 May 1990 }
  219. See Riesel or Bressoud.
  220.  
  221.  
  222. Function Prmdiv(a : number) : longint;
  223. {  Returns the smallest prime factor of a, or else 0. Assumes that Base is 10^8.  
  224.    Finds the smallest prime factor of all numbers less than Base, and of those
  225.    larger numbers that have a prime factor less than 10,000. Note that Prmdiv
  226.    is always less than Base (which is 10^8).  Requires unit MultiP, including
  227.    array prm[].  Calls Less and Modd.}
  228. { 20 April 1990 }
  229. UBASIC supplies Prmdiv in the language.
  230.  
  231.  
  232. FUNCTION Prroot(n : number ):longint;
  233. { Returns the smallest positive primitive root of n.  n > 0 is assumed to be 
  234.   prime and n-1 must be factorable by the function Prmdiv.  Returns 0 
  235.   for failure or error.  Requires unit MultiP.  Calls Prmdiv, Less, Equal,
  236.   Sub, Dvd, Mul, Add, and Spwr.  Note that Prmdiv is not in the unit MultiP.  }
  237. { 2 May 1990 }
  238.  
  239.  
  240. PROCEDURE Quadtocf(m,d,q : number; VAR CF : tenr; VAR lengs,lengf : longint;
  241.                      VAR s : Boolean);
  242. { Calculates the continued fraction for the positive quadratic irrational 
  243.   (m + ├d)/q and places it in the array CF.  s = TRUE indicates the array was 
  244.   long enough to hold the continued fraction.  s = FALSE indicates either that 
  245.   error or that d is a perfect square. lengs and lengf are indexes of the start 
  246.   and end respectively of the periodic part.  Type tenr is imported from the 
  247.   unit. Calls Isqrt, Equal, Mul, Sub, Dvd, and Add. }
  248. { 6 May 1990 }
  249.  
  250.  
  251. PROCEDURE Ratconf(a,b : number; VAR C : tenr; VAR leng : longint);
  252. { Calculates the continued fraction of the rational a/b, terms are in C
  253.   and the last index of C that is used is in leng.  (leng = -1 indicates
  254.   improper input.)  Note that indexing starts with 0.  It is assumed that
  255.   b > 0.  No error-checking is done to assure that the array isn't overrun,
  256.   so range-checking should be on. The type tenr is imported from MultiP.  
  257.   Requires unit MultiP, including the type tenr.  Calls Dvd. }
  258. {  7 Jan. 1990 }
  259.  
  260.  
  261. PROCEDURE Rennet(VAR CF : tenr; leng : longint; VAR A,B,C : number);
  262. { Given a purely periodic continued fraction in CF, with leng as the 
  263.   last index used, produces the coefficients A, B, and C of a quadratic
  264.   that the continued fraction satisfies: Az^2 + Bz + é =0.  It is
  265.   assumed that indices 0 through leng comprise the integer part plus the
  266.   complete period of the continued fraction, and that the cont. fraction
  267.   represents a positive number.  There is no error checking for proper input.  
  268.   The parameter CF is VAR only for efficiency - it is an input parameter.If 
  269.   leng < 0 then the output is A=B=C=0.  Requires unit MultiP, including type 
  270.   tenr.  Calls Mul, Add, Gcd, Dvd, and Sub.  }
  271. {  7 Jan. 1990 }
  272.  
  273.  
  274.  
  275. **********************************  BODY3  ************************************
  276.  
  277.  
  278. PROCEDURE Ressol(p,a : number; VAR r : number);
  279. { Shank's algorithm to solve x^2 = a (mod p).  The solution is returned
  280.   in r.  It is assumed that p is an odd prime, and that a is a quadratic
  281.   residue modulo p.  Requires unit MUltiP.  Calls Equal, Add, Sub, Mul,
  282.   Dvdby2, Modd, Jacobi, and Spwr. } 
  283. { 15 May 1990 }
  284. This algorithm is described in "FIVE NUMBER-THEORETIC ALGORITHMS", by Daniel
  285. Shanks, in PROC. SECOND MANITOBA CONFERENCE ON NUMERICAL MATH., 1972, pp. 51-70.
  286.  
  287.  
  288.  PROCEDURE Rho(n,c : number; ubnd : longint; VAR f,g : number);
  289.  { Brent's modification of Pollard's rho method of factoring n.  c is the
  290.    constant in the iteration formula x --> x*x + c.  ubnd is the maximum
  291.    number of iterations, while f and g hold the factors ( or -1 if 
  292.    factorization fails, or 0 if n <= 0).  n must be positive.  The user may
  293.    want to change the constant cc which governs how often the gcd is calculated. 
  294.    Needs Unit MultiP.  Calls Add, Mul, Modd, Sub, Gcd, and Dvd. }
  295.  {  30 Dec. 1989 }
  296.  See Riesel or Bressoud.
  297.  
  298.  
  299. PROCEDURE Sformf(n : number; VAR f : number);
  300. { The square form factoring method of Shanks.  This implementation uses two
  301.   continued fractions and rejects small denominators.  The constant zzz is the
  302.   upper limit for the number of iterations.  n must be positive.  Requires the 
  303.   unit MultiP.  Calls  Isqrt, Mul, Sub, Add, Dvd, Less, Equal, and Dvdby2. }
  304. { 6 May 1990  }
  305. This factoring method is described in Riesel.
  306.  
  307.  
  308. PROCEDURE Sigma(VAR P,M : triala; k : longint; VAR sig : number);
  309. { For the number n (which is not a parameter) its prime factor and 
  310.   multiplicity arrays and the last index used in them, namely k, are input
  311.   parameters.  The value of Sigma (the sum of the divisors of n) is computed
  312.   using the standard formula, and returned in sig.  P and M are input variables
  313.   which are VAR only for efficiency.  Requires unit MultiP.  Calls Mul and Add.}
  314. { 2 May 1990 }
  315.  
  316.  
  317.  FUNCTION Spspt(n,b : number) : Boolean;
  318.  { Strong pseudoprime test of n using witness b. 
  319.    n >= 2 is required.  Needs Unit MultiP.  Calls Dvdby2, Spwr, Lmod,
  320.    Sub, Less, Equal, and Mul. } 
  321.  {  20 May 1990 }
  322.  This is described in the article "THE PSEUDOPRIMES TO 25*10^9" by Carl
  323.  Pomerance, J. L. Selfridge, and Samuel S. Wagstaff, Jr., Math. of Comp.
  324.  v.35 (1980) pp1003-1026.
  325.  
  326.  
  327. PROCEDURE Squf(n : number; VAR f : number);
  328. { Implements the square forms factorization method of Shanks, using the
  329.   numerators of the convergents instead of a second continued fraction.
  330.   These numerators are subject to overflow.  n must be positive.  Requires 
  331.   the unit MultiP.  Calls Isqrt, Mul, Sub, Add, Dvd, Equal, and Gcd. }
  332. {  6 May 1990  }
  333. This is probably not as fast as the other implementation (Sformf).
  334.  
  335.  
  336. PROCEDURE Tau(VAR M : triala; k : longint; VAR ta : number);
  337. { For the number n (which is not a parameter) its prime factor multiplicity
  338.   array M and the last index used in M, namely k, are input parameters.  The
  339.   value of Tau (the number of divisors of n) is computed using the standard
  340.   formula.  M is VAR only for efficiency.  Requires unit MultiP.  Calls Mul. }
  341. { 2 May 1990 }
  342.  
  343.  
  344. PROCEDURE Tdvd(a: number; VAR P,M: triala; VAR k: longint; VAR b: number);
  345. {  Trial-divides a, using the primes in the prime list.  The prime factors
  346.    and their multiplicities are stored in P[] and M[] respectively.  The
  347.    variable b holds the remaining unfactored part (or 0 if a = 0). k is the
  348.    last index used in the arrays P and M. Note that a is allowed to be negative.
  349.    Requires unit MultiP, including the array prm and type triala.  Calls Dvdby2
  350.    and Dvd. Note that a prime factor found by Tdvd must be less than Base 
  351.    (10^8) (Pascal versions).  }
  352. {  20 April 1990 }
  353.  Pascal version:  If a number has all prime divisors less than Base, and if 
  354.  all but one of them are less than 10^5, then Tdvd will completely factor it.
  355.  UBASIC version:  If a number has all prime divisors less than 2^34, and if
  356.  all but one are less than 2^17, then Tdvd will completely factor it.
  357.  
  358.  
  359. PROCEDURE Tenner(n : number; VAR A : tenr; VAR leng:longint; VAR f:Boolean);
  360. { Tenner's algorithm for the continued fraction of ├n.  A contains the
  361.   integer part (in A[0]) and a full period.  leng is the last index used.
  362.   Improper input is indicated by setting leng = -1.  
  363.   If the period is too long to fit into A, then f = FALSE, else f = TRUE.
  364.   The type tenr is imported from the unit MultiP.  The constant ub = 100, 
  365.   making it easy to change the text of this procedure to accomodate a larger 
  366.   array. Requires MultiP, including the type tenr.  Calls Isqrt, Mul, Sub, 
  367.   Add, Dvd, and Equal. }
  368. {  3 Jan. 1990 }
  369.  
  370.  
  371. PROCEDURE Tenners(n:number; VAR A:tenr; VAR leng:longint; VAR f,odd:Boolean);
  372. { Tenner's algorithm for the continued fraction of ├n.  A contains the
  373.   integer part (in A[0]) and a half period.  leng is the last index used.
  374.   Improper input is indicated by setting leng = -1.
  375.   If the period is too long to fit into A, then f = FALSE, else f = TRUE.
  376.   odd = TRUE if the symmetric part of the period is of odd length, else odd =
  377.   FALSE and the symmetric part is of even length.
  378.   The type tenr is imported from the unit MultiP.  The constant ub = 100, 
  379.   making it easy to change the text of this procedure to accomodate a larger 
  380.   array.  Requires MultiP, including the type tenr.  Calls Isqrt, Mul, Sub, 
  381.   Add, Dvd, and Equal. }
  382. { 4 Jan. 1990 }
  383. Since Tenners stores only half as much as Tenner, it doesn't need as long 
  384. an array.  
  385.  
  386.  
  387. PROCEDURE TestPrime(n : number; VAR ans : longint);
  388. { This primality test is valid for n less than 50 (U.S.) billion.  TestPrime
  389.   first uses a base-2 strong pseudoprime test, then the Shanks-Adams-Perrin
  390.   sequence test, and then checks the six composites less than 5*10^10 which
  391.   pass both tests.  Small numbers are tested separately by looking in prm[].
  392.   Returns 1 for prime, 0 for composite (or 1), and -1 for error: too big
  393.   or 0. Requires unit MultiP.  Calls Sub, Less, Dvdby2, Spwr, Equal, Mul,
  394.   Lmod, Modd, and Add. }
  395. { 20 May 1990 }
  396. See "FAST PRIMALITY TESTS FOR NUMBERS LESS THAN 50*10^9", by G. C. Kurtz,
  397. Daniel Shanks, and H. C. Williams, Math. of Comp. v.46 (1986) pp.691-701.
  398.  
  399.  
  400. PROCEDURE Totient(VAR P,M : triala; k : longint; VAR tot : number);
  401. { Returns the Euler totient function in the variable tot.  P, M, and k
  402.   have the same meaning as in Sigma.  Requires unit MultiP, including type
  403.   triala.  Calls Mul and Sub.  }
  404. { 2 May 1990 }
  405. This is supplied in the language UBASIC as a function EUL(N).
  406.  
  407.  
  408. PROCEDURE TwoSum(p : number; VAR a, b : number);
  409. { Expresses p = a^2 + b^2 for prime p = 1 (mod 4).  Note that primality
  410.   is not checked.  Requires the unit MultiP.  Calls Modd, Equal, Add,
  411.   Sub, Spwr, Dvd, Dvdby2, Less, Jacobi, and Isqrt. }
  412. {  2 May 1990 }
  413. See "NOTE ON REPRESENTING A PRIME AS A SUM OF TWO SQUARES", by John Brillhart, 
  414. Math. of Comp. v.26 (1972) pp. 1011-1013.
  415.  
  416.  
  417. PROCEDURE Wilpp1(n,P : number; ub : longint; VAR f : number);
  418. { William's p+1 method for factoring n, returning the result in f.  If
  419.   the method fails, f = 1 (or n).  ub is the maximum number of cycles.  
  420.   The constant cc determines how often the gcd is calculated. Requires 
  421.   unit MultiP.  Calls Sub, Gcd, Mul, Modd, and Equal. }
  422. {  7 June 1990 }
  423. This algorithm is described in Bressoud.
  424.  
  425.  
  426.  
  427.  
  428.