expvec.red 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. fluid '(dipsortmode!* dipvars!*);
  15. symbolic procedure evperm (e1,n);
  16. % /* Exponent vector permutation. e1 is an exponent vector, n is a
  17. % index list , a list of digits. evperm(e1,n) returns a list e1
  18. % permuted in respect to n. */
  19. if null n then nil
  20. else evnth(e1, car n) . evperm(e1, cdr n);
  21. symbolic procedure evcons (e1,e2);
  22. % /* Exponent vector construct. e1 and e2 are exponents. evcons(e1,e2)
  23. % constructs an exponent vector. */
  24. e1 . e2;
  25. symbolic procedure evnth (e1,n);
  26. % /* Exponent vector n-th element. e1 is an exponent vector, n is a
  27. % digit. evnth(e1,n) returns the n-th element of e1, an exponent. */
  28. if null e1 then 0 else
  29. if n = 1 then evfirst e1 else evnth(evred e1, n - 1);
  30. symbolic procedure evred e1;
  31. % /* Exponent vector reductum. e1 is an exponent vector. evred(e1)
  32. % returns the reductum of the exponent vector e1. */
  33. if e1 then cdr e1 else NIL;
  34. symbolic procedure evfirst e1;
  35. % /* Exponent vector first. e1 is an exponent vector. evfirst(e1)
  36. % returns the first element of the exponent vector e1, an exponent. */
  37. if e1 then car e1 else 0;
  38. symbolic procedure evsum0(n,p);
  39. % exponent vector sum version 0. n is the length of dipvars!*.
  40. % p is a distributive polynomial.
  41. if dipzero!? p then evzero1 n else
  42. evsum(dipevlmon p, evsum0(n,dipmred p));
  43. symbolic procedure evzero1 n;
  44. % Returns the exponent vector power representation
  45. % of length n for a zero power.
  46. begin scalar x;
  47. for i:=1: n do << x := 0 . x >>;
  48. return x
  49. end;
  50. symbolic procedure indexcpl(ev,n);
  51. % returns a list of indexes of non zero exponents.
  52. if null ev then ev else ( if car ev = 0 then
  53. indexcpl(cdr ev,n + 1) else
  54. ( n . indexcpl(cdr ev,n + 1)) );
  55. symbolic procedure evzer1!? e;
  56. % returns a boolean expression. true if e is null else false.
  57. null e;
  58. symbolic procedure evzero!? e;
  59. % /* Returns a boolean expression. True if all exponents are zero*/
  60. null e or car e = 0 and evzero!? cdr e;
  61. symbolic procedure evzero;
  62. % /* Returns the exponent vector representation for a zero power*/
  63. % for i := 1:length dipvars!* collect 0;
  64. begin scalar x;
  65. for i := 1:length dipvars!* do <<x := 0 . x>>;
  66. return x
  67. end;
  68. symbolic procedure mkexpvec u;
  69. % /* Returns an exponent vector with a 1 in the u place*/
  70. if not(u member dipvars!*) then typerr(u,"dipoly variable")
  71. else for each x in dipvars!* collect if x eq u then 1 else 0;
  72. symbolic procedure evlcm (e1,e2);
  73. % /* Exponent vector least common multiple. e1 and e2 are
  74. % exponent vectors. evlcm(e1,e2) computes the least common
  75. % multiple of the exponent vectors e1 and e2, and returns
  76. % an exponent vector. */
  77. % for each lpart in e1 each rpart in e2 collect
  78. % if lpart #> rpart then lpart else rpart;
  79. begin scalar x;
  80. while e1 and e2 do
  81. <<x := (if car e1 #> car e2 then car e1 else car e2) . x;
  82. e1 := cdr e1; e2 := cdr e2>>;
  83. return reversip x
  84. end;
  85. symbolic procedure evmtest!? (e1,e2);
  86. % /* Exponent vector multiple test. e1 and e2 are compatible exponent
  87. % vectors. evmtest!?(e1,e2) returns a boolean expression.
  88. % True if exponent vector e1 is a multiple of exponent
  89. % vector e2, else false. */
  90. if e1 and e2 then not(car e1 #< car e2) and evmtest!?(cdr e1,cdr e2)
  91. else evzero!? e2 ;
  92. symbolic procedure evsum (e1,e2);
  93. % /* Exponent vector sum. e1 and e2 are exponent vectors.
  94. % evsum(e1,e2) calculates the sum of the exponent vectors.
  95. % e1 and e2 componentwise and returns an exponent vector. */
  96. % for each lpart in e1 each rpart in e2 collect lpart #+ rpart;
  97. begin scalar x;
  98. while e1 and e2 do
  99. <<x := (car e1 #+ car e2) . x; e1 := cdr e1; e2 := cdr e2>>;
  100. x := reversip x;
  101. return if e1 then nconc(x,e1) else
  102. if e2 then nconc(x,e2) else x;
  103. end;
  104. symbolic procedure evdif (e1,e2);
  105. % /* Exponent vector difference. e1 and e2 are exponent
  106. % vectors. evdif(e1,e2) calculates the difference of the
  107. % exponent vectors e1 and e2 componentwise and returns an
  108. % exponent vector. */
  109. % for each lpart in e1 each rpart in e2 collect lpart #- rpart;
  110. begin scalar x;
  111. while e2 do
  112. <<if null e1 then e1 := '(0);
  113. x := (car e1 #- car e2) . x; e1 := cdr e1; e2 := cdr e2>>;
  114. return nconc (reversip x,e1);
  115. end;
  116. symbolic procedure intevprod(n,e);
  117. % /* Multiplies each element of the exponent vector u by the integer n*/
  118. for each x in e collect n #* x;
  119. symbolic procedure expvec2a e;
  120. % /* Returns list of prefix equivalents of exponent vector e*/
  121. expvec2a1(e,dipvars!*);
  122. symbolic procedure expvec2a1(u,v);
  123. % /* Sub function of expvec2a */
  124. if null u then nil
  125. else if car u = 0 then expvec2a1(cdr u,cdr v)
  126. else if car u = 1 then car v . expvec2a1(cdr u,cdr v)
  127. else list('expt,car v,car u) . expvec2a1(cdr u,cdr v);
  128. symbolic procedure dipevlpri(e,v);
  129. % /* Print exponent vector e in infix form. V is a boolean variable
  130. % which is true if an element in a product has preceded this one*/
  131. dipevlpri1(e,dipvars!*,v);
  132. symbolic procedure dipevlpri1(e,u,v);
  133. % /* Sub function of dipevlpri */
  134. if null e then nil
  135. else if car e = 0 then dipevlpri1(cdr e,cdr u,v)
  136. else <<if v then dipprin2 "*";
  137. if atom car u or null get(caar u,'dipprifn)
  138. then dipprin2 car u
  139. else apply1(get(caar u,'dipprifn),car u);
  140. if car e #> 1 then <<dipprin2 "**"; dipprin2 car e>>;
  141. dipevlpri1(cdr e,cdr u,t)>>;
  142. endmodule;
  143. end;