basis.red 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. %----------------------------------------------------------------
  2. % File: basis.red
  3. % Purpose: Build the triangle form of basis
  4. % Copyright: (C) 1990-1996, A.Kryukov, kryukov@theory.npi.msu.su
  5. % Version: 2.21 Mar. 25, 1996
  6. %----------------------------------------------------------------
  7. % Revision: 27/11/90 insertv
  8. % 26/11/90 SieveV
  9. % 05/03/91 AppS
  10. % Nov. 12, 1993 updatev
  11. % Mar. 25, 1996 sieved_pv0, reduce_pv0
  12. %----------------------------------------------------------------
  13. lisp <<
  14. if null getd 'mkunitp then in "perm.red"$
  15. if null getd 'pv_add then in "pvector.red"$
  16. >>$
  17. module basis$
  18. %===================================
  19. % basis ::= (v1 v2 ...)
  20. %===================================
  21. global '(!*basis)$
  22. procedure sieve_pv(v,b)$
  23. sieve_pv0(v,b,t)$
  24. procedure sieve_pv0(v,b,norm)$
  25. %---------------------------
  26. % v - vector.
  27. % b - basis.
  28. % norm=t -> normalized vector
  29. % return sieved vector.
  30. %---------------------------
  31. if null v then nil
  32. else <<
  33. while b and cdaar b > cdar v do b:=cdr b$
  34. while v and b do << % reduce v.
  35. v:=reduce_pv0(v,car b,norm)$
  36. b:=cdr b$
  37. >>$
  38. v
  39. >>$
  40. procedure reduce_pv(v,q)$
  41. reduce_pv0(v,q,t)$
  42. global '(pv_den)$
  43. procedure reduce_pv0(v,q,norm)$
  44. %---------------------------
  45. % v is reduced by q.
  46. % norm=t -> normalized vector
  47. % return reduced v.
  48. %---------------------------
  49. if null q then v
  50. else if null v then nil
  51. else begin scalar w,k$
  52. w:=v$
  53. while w and q and (cdar w > cdar q)
  54. do w := cdr w$ % find needed component.
  55. if w and q and (cdar q = cdar w) then <<
  56. k:=lcm(caar w,caar q)$ % Least Common Multiplier.
  57. v:=pv_add(pv_multc(v,k/caar w),pv_multc(q,-k/caar q))$
  58. % if v then v:=pv_renorm v$
  59. if null norm then pv_den:=pv_den*k/caar w % +AK 26/03/96
  60. else pv_den:=1$ % +AK 28/03/96
  61. >>$
  62. return v$
  63. end$
  64. %------------------- Insert new vector ----------------
  65. symbolic procedure insert_pv(pv,bl)$
  66. % pv - pvector
  67. % bl - original basis list
  68. % (r.v.) - new basis list
  69. (if null x then bl
  70. else insert_pv1(pv_renorm x,bl,nil)
  71. ) where x=sieve_pv(pv,bl)$
  72. symbolic procedure insert_pv1(pv,bl,bl1)$
  73. % pv - pvector
  74. % bl,bl1(r.v.) - basis list
  75. if null bl then if null pv then reversip bl1
  76. else reversip(pv . bl1)
  77. else if null pv then insert_pv1(nil,cdr bl,car bl . bl1)
  78. else if cdaar bl > cdar pv
  79. then insert_pv1(pv,cdr bl,pv_renorm reduce_pv(car bl,pv) . bl1)
  80. else insert_pv1(nil,bl,pv . bl1)$
  81. procedure insert_pv_(v,b)$
  82. % v - vector.
  83. % b - basis (midified.).
  84. % return updatev basis.
  85. if null v then b
  86. else if null b then list v
  87. % bug: if .. then .. <missing else> if .. then .. else ..
  88. else begin scalar b1,w$
  89. v:=pv_renorm sieve_pv(v,b);
  90. if null v then return b$
  91. b1:=b$
  92. while cdr b1 and cdaar b1 > cdar v do << % reduce car b1.
  93. rplacA(b1,pv_renorm reduce_pv(car b1,v))$
  94. b1:=cdr b1$
  95. >>$
  96. if cdaar b1 > cdar v then <<
  97. rplacA(b1,pv_renorm reduce_pv(car b1,v))$
  98. rplacD(b1,v . cdr b1)$ % insert after.
  99. >> else << % insert before.
  100. w:=car b1 . cdr b1;
  101. rplacD(rplacA(b1,v),w)$
  102. >>$
  103. return b$
  104. end$
  105. remprop('basis,'stat)$
  106. symbolic procedure update_pv(v,b)$
  107. % v - vector (modified)$
  108. % b - basis (modified)$
  109. % return updatevd vector v.
  110. if null v then nil
  111. else begin scalar r,w$
  112. if null(car b eq '!*basis)
  113. then rederr list('updatev,": 2-nd arg. is not a basis.")$
  114. r:=v$
  115. while v do <<
  116. w:=member(cdar v,cdr b)$
  117. if w then rplacD(car v,car w)
  118. else rplacD(b,cdar v . cdr b)$
  119. v:=cdr v$
  120. >>$
  121. return r$
  122. end$
  123. endmodule;
  124. end;