expvec.red 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. module expvec;
  2. % Specific support for distributive polynomial exponent vectors
  3. % Authors: R. Gebauer, A. C. Hearn, H. Kredel
  4. % We assume here that an exponent vector is a list of integers. This
  5. % version uses small integer arithmetic on the individual exponents
  6. % and assumes that a compiled function can be dynamically redefined
  7. % Modification H. Melenk (August 1988)
  8. % 1. Most ev-routines handle exponent vectors with variable length:
  9. % the convention is, that trailing zeros may be omitted.
  10. % 2. evcompless!? is mapped to evcomp such that each term order mode
  11. % is supported by exactly one procedure entry.
  12. % 3. complete exponent vector compare collected in separate module
  13. % TORDER (TORD33)
  14. symbolic procedure evperm (e1,n);
  15. % Exponent vector permutation. e1 is an exponent vector, n is a
  16. % index list , a list of digits. evperm(e1,n) returns a list e1
  17. % permuted in respect to n.
  18. if null n then nil
  19. else evnth(e1, car n) . evperm(e1, cdr n);
  20. symbolic procedure evcons (e1,e2);
  21. % Exponent vector construct. e1 and e2 are exponents. evcons(e1,e2)
  22. % constructs an exponent vector.
  23. e1 . e2;
  24. symbolic procedure evnth (e1,n);
  25. % Exponent vector n-th element. e1 is an exponent vector, n is a
  26. % digit. evnth(e1,n) returns the n-th element of e1, an exponent.
  27. if null e1 then 0 else
  28. if n = 1 then evfirst e1 else evnth(evred e1, n - 1);
  29. symbolic procedure evred e1;
  30. % Exponent vector reductum. e1 is an exponent vector. evred(e1)
  31. % returns the reductum of the exponent vector e1.
  32. if e1 then cdr e1 else NIL;
  33. symbolic procedure evfirst e1;
  34. % Exponent vector first. e1 is an exponent vector. evfirst(e1)
  35. % returns the first element of the exponent vector e1, an exponent.
  36. if e1 then car e1 else 0;
  37. symbolic procedure evsum0(n,p);
  38. % exponent vector sum version 0. n is the length of dipvars!*.
  39. % p is a distributive polynomial.
  40. if dipzero!? p then evzero1 n else
  41. evsum(dipevlmon p, evsum0(n,dipmred p));
  42. symbolic procedure evzero1 n;
  43. % Returns the exponent vector power representation
  44. % of length n for a zero power.
  45. begin scalar x;
  46. for i:=1:n do <<x:=0 . x>>;
  47. return x
  48. end;
  49. symbolic procedure indexcpl(ev,n);
  50. % returns a list of indexes of non zero exponents.
  51. if null ev then ev else(if car ev = 0 then
  52. indexcpl(cdr ev,n + 1) else
  53. (n . indexcpl(cdr ev,n + 1)));
  54. symbolic procedure evzer1!? e;
  55. % returns a boolean expression. true if e is null else false.
  56. null e;
  57. symbolic procedure evzero!? e;
  58. % Returns a boolean expression. True if all exponents are zero
  59. null e or car e = 0 and evzero!? cdr e;
  60. symbolic procedure evzero;
  61. % Returns the exponent vector representation for a zero power
  62. % for i:=1:length dipvars!* collect 0;
  63. begin scalar x;
  64. for i:=1:length dipvars!* do <<x:=0 . x>>;
  65. return x end;
  66. symbolic procedure mkexpvec u;
  67. % Returns an exponent vector with a 1 in the u place
  68. if not(u member dipvars!*) then typerr(u,"dipoly variable")
  69. else for each x in dipvars!* collect if x eq u then 1 else 0;
  70. symbolic procedure evlcm (e1,e2);
  71. % Exponent vector least common multiple. e1 and e2 are
  72. % exponent vectors. evlcm(e1,e2) computes the least common
  73. % multiple of the exponent vectors e1 and e2, and returns
  74. % an exponent vector.
  75. % for each lpart in e1 each rpart in e2 collect
  76. % if lpart #> rpart then lpart else rpart;
  77. begin scalar x;
  78. while e1 and e2 do
  79. <<x:=(if car e1 #> car e2 then car e1 else car e2) . x;
  80. e1:=cdr e1;e2:=cdr e2>>;
  81. return reversip x
  82. end;
  83. symbolic procedure evmtest!? (e1,e2);
  84. % Exponent vector multiple test. e1 and e2 are compatible exponent
  85. % vectors. evmtest!?(e1,e2) returns a boolean expression.
  86. % True if exponent vector e1 is a multiple of exponent
  87. % vector e2, else false.
  88. if e1 and e2 then not(car e1 #< car e2) and evmtest!?(cdr e1,cdr e2)
  89. else evzero!? e2;
  90. symbolic procedure evsum (e1,e2);
  91. % Exponent vector sum. e1 and e2 are exponent vectors.
  92. % evsum(e1,e2) calculates the sum of the exponent vectors.
  93. % e1 and e2 componentwise and returns an exponent vector.
  94. % for each lpart in e1 each rpart in e2 collect lpart #+ rpart;
  95. begin scalar x;
  96. while e1 and e2 do
  97. <<x:=(car e1 #+ car e2) . x;e1:=cdr e1;e2:=cdr e2>>;
  98. x:= reversip x;
  99. return if e1 then nconc(x,e1) else
  100. if e2 then nconc(x,e2) else x;
  101. end;
  102. symbolic procedure evdif (e1,e2);
  103. % Exponent vector difference. e1 and e2 are exponent
  104. % vectors. evdif(e1,e2) calculates the difference of the
  105. % exponent vectors e1 and e2 componentwise and returns an
  106. % exponent vector.
  107. % for each lpart in e1 each rpart in e2 collect lpart #- rpart;
  108. begin scalar x;
  109. while e2 do
  110. <<if null e1 then e1:='(0);
  111. x:=(car e1 #- car e2) . x;e1:=cdr e1;e2:=cdr e2>>;
  112. return nconc (reversip x,e1);
  113. end;
  114. symbolic procedure intevprod(n,e);
  115. % Multiplies each element of the exponent vector u by the integer n
  116. for each x in e collect n #* x;
  117. symbolic procedure expvec2a e;
  118. % Returns list of prefix equivalents of exponent vector e
  119. expvec2a1(e,dipvars!*);
  120. symbolic procedure expvec2a1(u,v);
  121. % Sub function of expvec2a
  122. if null u then nil
  123. else if car u = 0 then expvec2a1(cdr u,cdr v)
  124. else if car u = 1 then car v . expvec2a1(cdr u,cdr v)
  125. else list('expt,car v,car u) . expvec2a1(cdr u,cdr v);
  126. symbolic procedure dipevlpri(e,v);
  127. % Print exponent vector e in infix form. V is a boolean variable
  128. % which is true if an element in a product has preceded this one
  129. dipevlpri1(e,dipvars!*,v);
  130. symbolic procedure dipevlpri1(e,u,v);
  131. % Sub function of dipevlpri
  132. if null e then nil
  133. else if car e = 0 then dipevlpri1(cdr e,cdr u,v)
  134. else <<if v then dipprin2 "*";
  135. if atom car u or null get(caar u,'dipprifn)
  136. then dipprin2 car u
  137. else apply1(get(caar u,'dipprifn),car u);
  138. if car e #> 1 then <<dipprin2 "**";dipprin2 car e>>;
  139. dipevlpri1(cdr e,cdr u,t)>>;
  140. endmodule;;end;