nbasis.red 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. module nbasis;
  2. % Author: James H. Davenport.
  3. fluid '(!*tra nestedsqrts sqrt!-intvar taylorasslist);
  4. exports normalbasis;
  5. imports substitutesq,taylorform,printsq,newplace,sqrtsinsq,union,
  6. sqrtsign,interr,vecsort,mapvec,firstlinearrelation,mksp,multsq,
  7. !*multsq,addsq,removecmsq,antisubs,involvesq;
  8. symbolic procedure normalbasis(zbasis,x,infdegree);
  9. begin
  10. scalar n,nestedsqrts,sqrts,u,v,w,li,m,lam,i,inf,basis,save;
  11. save:=taylorasslist;
  12. inf:=list list(x,'quotient,1,x);
  13. n:=upbv zbasis;
  14. basis:=mkvect n;
  15. lam:=mkvect n;
  16. m:=mkvect n;
  17. goto a;
  18. square:
  19. sqrts:=nil;
  20. inf:=append(inf,list list(x,'expt,x,2));
  21. % we were in danger of getting sqrt(x) where we didnt want it.
  22. a:
  23. newplace(inf);
  24. for i:=0:n do <<
  25. v:=substitutesq(getv(zbasis,i),inf);
  26. putv(basis,i,v);
  27. sqrts:=union(sqrts,sqrtsinsq(v,x)) >>;
  28. if !*tra then <<
  29. princ "Normal integral basis reduction with the";
  30. prin2t " following sqrts lying over infinity:";
  31. superprint sqrts >>;
  32. if member(list('sqrt,x),sqrts)
  33. then goto square;
  34. sqrts:=sqrtsign(sqrts,x);
  35. if iadd1 n neq length sqrts
  36. then interr "Length mismatch in normalbasis";
  37. for i:=0:n do <<
  38. v:=cl8roweval(getv(basis,i),sqrts);
  39. putv(m,i,cdr v);
  40. putv(lam,i,car v) >>;
  41. reductionloop:
  42. vecsort(lam,list(basis,m));
  43. if !*tra then <<
  44. prin2t "Matrix before a reduction step at infinity is:";
  45. mapvec(m,function prin2t) >>;
  46. v:=firstlinearrelation(m,iadd1 n);
  47. if null v
  48. then goto ret;
  49. i:=n;
  50. while null numr getv(v,i) do
  51. i:=isub1 i;
  52. li:=getv(lam,i);
  53. w:=nil ./ 1;
  54. for j:=0:i do
  55. w:=!*addsq(w,!*multsq(getv(basis,j),
  56. multsq(getv(v,j),1 ./ !*fmksp(x,-li+getv(lam,j)) )));
  57. % note the change of sign. my x is coates 1/x at this point!.
  58. if !*tra then <<
  59. princ "Element ";
  60. princ i;
  61. prin2t " replaced by the function printed below:" >>;
  62. w:=removecmsq w;
  63. putv(basis,i,w);
  64. w:=cl8roweval(w,sqrts);
  65. if car w <= li
  66. then interr "Normal basis reduction did not work";
  67. putv(lam,i,car w);
  68. putv(m,i,cdr w);
  69. goto reductionloop;
  70. ret:
  71. newplace list (x.x);
  72. u:= 1 ./ !*p2f mksp(x,1);
  73. inf:=antisubs(inf,x);
  74. u:=substitutesq(u,inf);
  75. m:=nil;
  76. for i:=0:n do begin
  77. v:=getv(lam,i)-infdegree;
  78. if v < 0
  79. then goto next;
  80. w:=substitutesq(getv(basis,i),inf);
  81. for j:=0:v do <<
  82. if not involvesq(w,sqrt!-intvar)
  83. then m:=w.m;
  84. w:=!*multsq(w,u) >>;
  85. next:
  86. end;
  87. tayshorten save;
  88. return m
  89. end;
  90. symbolic procedure !*fmksp(x,i);
  91. % sf for x**i.
  92. if i iequal 0
  93. then 1
  94. else !*p2f mksp(x,i);
  95. symbolic procedure cl8roweval(basiselement,sqrts);
  96. begin
  97. scalar lam,row,i,v,minimum,n;
  98. n:=isub1 length sqrts;
  99. lam:=mkvect n;
  100. row:=mkvect n;
  101. i:=0;
  102. minimum:=1000000;
  103. while sqrts do <<
  104. v:=taylorform substitutesq(basiselement,car sqrts);
  105. v:=assoc(taylorfirst v,taylorlist v);
  106. putv(row,i,cdr v);
  107. v:=car v;
  108. putv(lam,i,v);
  109. if v < minimum
  110. then minimum:=v;
  111. i:=iadd1 i;
  112. sqrts:=cdr sqrts >>;
  113. if !*tra then <<
  114. princ "Evaluating ";
  115. printsq basiselement;
  116. prin2t lam;
  117. prin2t row >>;
  118. v:=1000000;
  119. for i:=0:n do <<
  120. v:=getv(lam,i);
  121. if v > minimum
  122. then putv(row,i,nil ./ 1) >>;
  123. return minimum.row
  124. end;
  125. endmodule;
  126. end;