forder.red 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. module forder;
  2. % Author: Eberhard Schruefer;
  3. global '(keepl!* wedgemtch!* lftshft!* indxl!*);
  4. fluid '(kord!* subfg!*);
  5. symbolic procedure add2l(u,v);
  6. !*a2k u . if u memq v then delete(u,v) else v;
  7. symbolic procedure forder u;
  8. forder1 u;
  9. symbolic procedure forder1 u;
  10. (lambda x;
  11. while x do
  12. <<kord!* := add2l(car x,kord!*);
  13. if eqcar(car x,'wedge) then
  14. for each j in reverse cdar x do
  15. kord!* := add2l(j,kord!*);
  16. x:=cdr x>>)
  17. reverse u;
  18. symbolic procedure remforder u;
  19. for each j in u do kord!* := delete(j,kord!*);
  20. symbolic procedure isolate u;
  21. rerror(excalc,2,"Sorry, ISOLATE not supported in this version");
  22. % for each j in u do
  23. % <<lftshft!* := !*a2k car u . lftshft!*;
  24. % kord!* := !*a2k car u . kord!*>>;
  25. symbolic procedure remisolate u;
  26. for each j in u do lftshft!* := delete(j,lftshft!*);
  27. symbolic procedure worderp(x,y);
  28. if null atom x and flagp(car x,'indexvar) and
  29. null atom y and flagp(car y,'indexvar)
  30. then indexvarordp(x,y)
  31. else if atom x or (x memq kord!*) then
  32. if atom y or (y memq kord!*) then ordop(x,y)
  33. else (if x eq z then t
  34. else worderp(x,z)) where z = peel y
  35. else if atom y or (y memq kord!*)
  36. then (if z eq y then nil
  37. else worderp(z,y)) where z = peel x
  38. else worderp(peel x,peel y);
  39. symbolic procedure indexvarordp(u,v);
  40. if not(car u eq car v) or (u memq kord!*) or (v memq kord!*) then
  41. ordop(u,v)
  42. else ((if boundindp(x,indxl!*) then
  43. if boundindp(y,indxl!*) then indordlp(cdr u,cdr v)
  44. else t
  45. else if boundindp(y,indxl!*) then nil
  46. else ordop(u,v))
  47. where x = flatindxl cdr u, y = flatindxl cdr v);
  48. symbolic procedure indordlp(u,v);
  49. if null u then nil
  50. else if null v then t
  51. else if car u = car v then indordlp(cdr u, cdr v)
  52. else if atom car u then
  53. if atom car v then indordp(car u,car v)
  54. else t
  55. else if atom car v then nil
  56. else indordp(cadar u,cadar v);
  57. symbolic procedure peel u;
  58. if car u memq '(liedf innerprod) then caddr u
  59. else if car u eq 'quotient then
  60. if worderp(cadr u,caddr u) then cadr u
  61. else caddr u
  62. else cadr u;
  63. symbolic procedure indordp(u,v);
  64. begin scalar x;
  65. x := indxl!*;
  66. if null(u memq x) then return t;
  67. a: if null x then return orderp(u,v);
  68. if u eq car x then return t
  69. else if v eq car x then return nil;
  70. x := cdr x;
  71. go to a
  72. end;
  73. symbolic procedure indordn u;
  74. if null u then nil
  75. else if null cdr u then u
  76. else if null cddr u then indord2(car u,cadr u)
  77. else indordad(car u,indordn cdr u);
  78. symbolic procedure indord2(u,v);
  79. if indordp(u,v) then list(u,v) else list(v,u);
  80. symbolic procedure indordad(a,u);
  81. if null u then list a
  82. else if indordp(a,car u) then a . u
  83. else car u . indordad(a,cdr u);
  84. symbolic procedure keep u;
  85. while u do
  86. <<if not eqexpr car u then errpri2(car u,'hold)
  87. else begin scalar x,y,z;
  88. z := subfg!*;
  89. subfg!* := nil;
  90. x := !*a2k cadar u;
  91. y := !*a2k caddar u;
  92. forder1 list(x,y);
  93. keepl!* := (x . y) . keepl!*;
  94. flag(list x,'keep);
  95. put(x,'keepl,list y);
  96. subfg!* := z;
  97. putdep(x,y);
  98. if null exdfk y then flag(list x,'closed);
  99. if eqcar(y,'wedge) then
  100. <<wedgemtch!*:=(cdr y . x) . wedgemtch!*;
  101. for each j in cdr y do
  102. wedgemtch!* := (list(x,j) . nil) . wedgemtch!*>>
  103. else let2(y,x,nil,t)
  104. end;
  105. u := cdr u>>;
  106. symbolic procedure putdep(u,v);
  107. for each j in cdr v do
  108. if atom j then depend1(u,j,t) else putdep(u,j);
  109. endmodule;
  110. end;