xexcalc.red 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. module xexcalc;
  2. % Modifications to Eberhard Schruefer's excalc
  3. % Author: David Hartley
  4. Comment. The core routines in EXCALC have symbols:
  5. wedgepf2: pf,wedgepf -> wedgepf
  6. wedgek2: lpow pf,lpow wedgepf -> wedgepf
  7. addpf: pf,pf -> pf
  8. addpf: wedgepf,wedgepf -> wedgepf
  9. The overloading on addpf makes it hard to modify to use a different
  10. order: the following routines cannot guarantee that ordering of terms
  11. in a polynomial will be the same in pf or wedgpf representation.
  12. endcomment;
  13. global '(dimex!*);
  14. symbolic procedure addpf(u,v);
  15. % change to use termordp!! rather than ordop
  16. if null u then v
  17. else if null v then u
  18. else if ldpf u = 1 then addmpf(u,v)
  19. else if ldpf v = 1 then addmpf(v,u)
  20. else if ldpf u = ldpf v then
  21. (lambda x,y;
  22. if null numr x then y else ldpf u .* x .+ y)
  23. (addsq(lc u,lc v),addpf(red u,red v))
  24. else if termordp!!(ldpf u,ldpf v) then lt u .+ addpf(red u,v)
  25. else lt v .+ addpf(u,red v);
  26. symbolic procedure termordp!!(u,v);
  27. % u,v:lpow pf|lpow wedgepf -> termordp!!:bool
  28. % as for termordp, but trying to accomodate wedgepf and pf terms
  29. u neq v and
  30. termordp(guesspftype u,guesspftype v);
  31. symbolic procedure guesspftype u;
  32. % u:lpow pf|lpow wedgepf -> guesspftype:lpow pf
  33. % if we have pform x=1,y=1,x(i)=1, then we can't tell whether
  34. % (x y) means x^y or x(y). Here we choose the former.
  35. if atom u then u
  36. else if car u memq '(wedge d partdf hodge innerprod liedf) then u
  37. else if assoc(length cdr u,get(car u,'ifdegree)) and
  38. not xvarlistp cdr u then u
  39. else mknwedge u;
  40. symbolic procedure xvarlistp x;
  41. % x:list of kernel -> xvarlistp:bool
  42. % heuristic to check if x is a list of pform variables
  43. null x or xvarp car x and xvarlistp cdr x;
  44. symbolic procedure addmpf(u,v);
  45. % add extra test for vanishing coefficient
  46. if null v then u
  47. else if ldpf v = 1 then
  48. (if numr x then 1 .* x .+ nil) where x = addsq(lc u,lc v)
  49. else lt v .+ addmpf(u,red v);
  50. symbolic procedure deg!*form u;
  51. %U is a prefix expression. Result is the degree of u;
  52. % add !*sq prefix forms
  53. if atom u then get!*fdeg u
  54. else (if flagp(x,'indexvar) then get!*ifdeg u
  55. else if x eq 'wedge then deg!*farg cdr u
  56. else if x eq 'd then addd(1,deg!*form cadr u)
  57. else if x eq 'hodge then addf(dimex!*,negf deg!*form cadr u)
  58. else if x eq 'partdf then if cddr u then nil else -1
  59. else if x eq 'liedf then deg!*form caddr u
  60. else if x eq 'innerprod then addd(-1,deg!*form caddr u)
  61. else if x memq '(plus minus difference quotient) then
  62. deg!*form cadr u
  63. else if x eq 'times then deg!*farg cdr u
  64. else if x eq '!*sq then deg!*form prepsq simp!* u
  65. else nil) where x = car u;
  66. % The following two routines are copied from the development version of
  67. % excalc to overcome an error message "+++ oddp nil" in the CSL version.
  68. symbolic procedure oddp m;
  69. if not fixp m then typerr(m,"integer") else remainder(m,2) neq 0;
  70. symbolic procedure wedgek2(u,v,w);
  71. if u eq car v and null eqcar(u,'wedge)
  72. then if (fixp n and oddp n) where n = deg!*form u then nil
  73. else multpfsq(wedgef(u . v),mksgnsq w)
  74. else if eqcar(car v,'wedge) then wedgek2(u,cdar v,w)
  75. else if eqcar(u,'wedge)
  76. then multpfsq(wedgewedge(cdr u,v),mksgnsq w)
  77. else if wedgeordp(u,car v)
  78. then multpfsq(wedgef(u . v),mksgnsq w)
  79. else if cdr v
  80. then wedgepf2(!*k2pf car v,
  81. wedgek2(u,cdr v,addf(w,multf(deg!*form u,
  82. deg!*form car v))))
  83. else multpfsq(wedgef list(car v,u),
  84. mksgnsq addf(w,multf(deg!*form u,deg!*form car v)));
  85. endmodule;
  86. end;