tayconv.red 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. module TayConv;
  2. %*****************************************************************
  3. %
  4. % Functions converting Taylor kernels to prefix forms
  5. %
  6. %*****************************************************************
  7. exports prepTaylor!*!*, prepTaylor!*, prepTaylor!*1,
  8. Taylor!-gen!-big!-O;
  9. imports
  10. % from the REDUCE kernel:
  11. eqcar, lastpair, prepsq!*, replus, retimes, reval,
  12. % from the header module:
  13. prepTayExp, TayCfPl, TayCfSq, TayCoeffList, TayTemplate,
  14. TayTpElNext, TayTpElPoint, TayTpElVars;
  15. fluid '(convert!-Taylor!*
  16. TaylorPrintTerms
  17. Taylor!-truncation!-flag);
  18. symbolic procedure prepTaylor!*1 (coefflist, template, no!-of!-terms);
  19. replus for each cc in coefflist join
  20. begin scalar x; integer count;
  21. if Taylor!-truncation!-flag then return nil;
  22. x := prepTaylor!*2 (cc, template);
  23. if null x or null no!-of!-terms then return x;
  24. no!-of!-terms := no!-of!-terms - 1;
  25. if no!-of!-terms < 0
  26. then << Taylor!-truncation!-flag := t;
  27. return nil >>;
  28. return x
  29. end;
  30. symbolic procedure prepTaylor!*2 (coeff, template);
  31. (lambda (pc);
  32. if pc = 0 then nil
  33. else {retimes (
  34. (if eqcar (pc, 'quotient) and eqcar (cadr pc, 'minus)
  35. then {'minus, {'quotient, cadr cadr pc, caddr pc}}
  36. else pc) . preptaycoeff (TayCfPl coeff, template))})
  37. (prepsq!* TayCfSq coeff);
  38. symbolic procedure checkdifference (var, var0);
  39. if var0 = 0 then var else {'difference, var, var0};
  40. symbolic procedure checkexp(bas,exp);
  41. if exp = 0 then 1
  42. else if exp = 1 then bas
  43. else {'expt,bas,prepTayExp exp};
  44. symbolic smacro procedure checkpower (var, var0, n);
  45. if var0 eq 'infinity
  46. then if n = 0 then 1
  47. else {'quotient, 1, checkexp (var, n)}
  48. else checkexp (checkdifference (var, reval var0), n);
  49. symbolic procedure preptaycoeff (cc, template);
  50. begin scalar result;
  51. while not null template do begin scalar ccl;
  52. ccl := car cc;
  53. for each var in TayTpElVars car template do <<
  54. result := checkpower (var, TayTpElPoint car template, car ccl)
  55. . result;
  56. ccl := cdr ccl >>;
  57. cc := cdr cc;
  58. template := cdr template
  59. end;
  60. return result
  61. end;
  62. put ('taylor!*, 'prepfn2, 'preptaylor!*!*);
  63. symbolic procedure prepTaylor!*!* u;
  64. if null convert!-taylor!* then u else preptaylor!* u;
  65. symbolic procedure prepTaylor!* u;
  66. prepTaylor!*1 (TayCoeffList u, TayTemplate u, nil);
  67. symbolic procedure Taylor!-gen!-big!-O tp;
  68. %
  69. % Generates a big-O notation for the Taylor template tp
  70. %
  71. "O" . for each el in tp collect
  72. if null cdr TayTpElVars el
  73. then checkpower(car TayTpElVars el,TayTpElPoint el,
  74. TayTpElNext el)
  75. else begin scalar var0;
  76. var0 := reval TayTpElPoint el;
  77. return
  78. if var0 eq 'infinity
  79. then {'quotient,1,
  80. checkexp('list . TayTpElVars el,TayTpElNext el)}
  81. else checkexp(
  82. 'list .
  83. for each krnl in TayTpElVars el collect
  84. checkdifference(krnl,var0),
  85. TayTpElNext el)
  86. end;
  87. endmodule;
  88. end;