factor.red 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. module factor; % Header for factorizer.
  2. % Authors: A. C. Norman and P. M. A. Moore, 1981.
  3. create!-package('(factor bigmodp degsets facprim facmod facuni % factrr
  4. imageset pfactor vecpoly pfacmult),
  5. nil);
  6. % Other packages needed.
  7. load!-package 'ezgcd;
  8. for each j in get('factor,'package)
  9. do put(j,'compiletime,'(setq !*fastfor t));
  10. fluid '(!*ifactor !*overview !*trallfac !*trfac factor!-level
  11. factor!-trace!-list posn!*);
  12. global '(spare!*);
  13. switch ifactor,overview,trallfac,trfac;
  14. comment This factorizer should be used with a system dependent file
  15. containing a setting of the variable LARGEST!-SMALL!-MODULUS. If at all
  16. possible the integer arithmetic operations used here should be mapped
  17. onto corresponding ones available in the underlying Lisp implementation,
  18. and the support for modular arithmetic (perhaps based on these integer
  19. arithmetic operations) should be reviewed. This file provides
  20. placeholder definitions of functions that are used on some
  21. implementations to support block compilation, car/cdr access checks and
  22. the like. The front-end files on the systems that can use these
  23. features will disable the definitions given here by use of a 'LOSE flag;
  24. deflist('((minus!-one -1)),'newnam); % So that it EVALs properly.
  25. symbolic smacro procedure carcheck u; nil;
  26. % symbolic smacro procedure irecip u; 1/u;
  27. % symbolic smacro procedure isdomain u; domainp u;
  28. % symbolic smacro procedure readgctime; gctime();
  29. % symbolic smacro procedure readtime; time()-gctime();
  30. % symbolic smacro procedure ttab n; spaces(n-posn());
  31. % ***** The remainder of this module used to be in FLUIDS.
  32. % Macro definitions for functions that create and access reduce-type
  33. % datastructures.
  34. % smacro procedure polyzerop u; null u;
  35. smacro procedure didntgo q; null q;
  36. % smacro procedure depends!-on!-var(a,v);
  37. % (lambda !#!#a; (not domainp !#!#a) and (mvar !#!#a=v)) a;
  38. % smacro procedure l!-numeric!-c(a,vlist); lnc a;
  39. % Macro definitions for use in Berlekamp's algorithm.
  40. % Smacros used in linear equation package.
  41. % smacro procedure getm2(a,i,j);
  42. % % Store by rows, to ease pivoting process.
  43. % getv(getv(a,i),j);
  44. % smacro procedure putm2(a,i,j,v);
  45. % putv(getv(a,i),j,v);
  46. smacro procedure !*f2mod u; u;
  47. smacro procedure !*mod2f u; u;
  48. %%%smacro procedure adjoin!-term (p,c,r);
  49. %%% (lambda !#c!#; % Lambda binding prevents repeated evaluation of C.
  50. %%% if null !#c!# then r else (p .* !#c!#) .+ r) c;
  51. symbolic smacro procedure get!-f!-numvec s; cadr cddr cdddr s;
  52. % !*overshoot:=nil; % Default not to show overshoot occurring.
  53. % reconstructing!-gcd:=nil; % This is primarily a factorizer!
  54. symbolic procedure ttab!* n;
  55. <<if n>(linelength nil - spare!*) then n:=0;
  56. if posn!* > n then terpri!*(nil);
  57. while not(posn!*=n) do prin2!* '! >>;
  58. smacro procedure printstr l; << prin2!* l; terpri!*(nil) >>;
  59. smacro procedure printvar v; printstr v;
  60. smacro procedure prinvar v; prin2!* v;
  61. % smacro procedure display!-time(str,mt);
  62. % Displays the string str followed by time mt (millisecs).
  63. % << prin2 str; prin2 mt; prin2t " millisecs." >>;
  64. % trace control package.
  65. % smacro procedure trace!-time action; if !*timings then action;
  66. smacro procedure new!-level(n,c); (lambda factor!-level; c) n;
  67. symbolic procedure set!-trace!-factor(n,file);
  68. factor!-trace!-list:=(n . (if file=nil then nil
  69. else open(mkfil file,'output))) .
  70. factor!-trace!-list;
  71. symbolic procedure clear!-trace!-factor n;
  72. begin
  73. scalar w;
  74. w := assoc(n,factor!-trace!-list);
  75. if w then <<
  76. if cdr w then close cdr w;
  77. factor!-trace!-list:=delasc(n,factor!-trace!-list) >>;
  78. return nil
  79. end;
  80. symbolic procedure close!-trace!-files();
  81. << while factor!-trace!-list
  82. do clear!-trace!-factor(caar factor!-trace!-list);
  83. nil >>;
  84. endmodule;
  85. end;