tayprint.red 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. module TayPrint;
  2. %*****************************************************************
  3. %
  4. % Functions for printing Taylor kernels
  5. %
  6. %*****************************************************************
  7. exports Taylor!*print, Taylor!*print1;
  8. imports
  9. % from the REDUCE kernel:
  10. denr, eqcar, fmprint, kernp, lastpair, maprint, mvar, numr,
  11. prepsq, simp!*, smemq, typerr,
  12. % from the header module:
  13. TayCfSq, TayCoeffList, TayOrig, TayTemplate, TayTpElOrder,
  14. TayTpElPoint, TayTpElVars,
  15. % from module Tayconv:
  16. prepTaylor!*, prepTaylor!*1, Taylor!-gen!-big!-O;
  17. fluid '(!*fort !*nat !*taylorprintorder Taylor!-truncation!-flag
  18. TaylorPrintTerms);
  19. symbolic procedure check!-print!-terms u;
  20. begin scalar x;
  21. x := simp!* u;
  22. if kernp x and mvar numr x eq 'all then return nil
  23. else if denr x = 1 and fixp numr x then return numr x
  24. else typerr (x, "value of TaylorPrintTerms")
  25. end;
  26. symbolic procedure Taylor!*print1 u;
  27. if smemq('!~,u) or atom TayCoeffList u and not null TayCoeffList u
  28. then 'Taylor . cdr u
  29. else begin scalar Taylor!-truncation!-flag, prepexpr, rest, nterms;
  30. nterms := if !*taylorprintorder
  31. then check!-print!-terms TaylorPrintTerms
  32. else nil;
  33. prepexpr := prepTaylor!*1 (
  34. TayCoeffList u,
  35. TayTemplate u,
  36. nterms);
  37. if !*taylorprintorder then <<
  38. rest := {Taylor!-gen!-big!-O TayTemplate u};
  39. if Taylor!-truncation!-flag then begin integer notprinted;
  40. notprinted := -nterms;
  41. for each pp in TayCoeffList u do
  42. if not null numr TayCfSq pp then
  43. notprinted := notprinted + 1;
  44. if notprinted=1 then rest := "(1 term)" . rest
  45. else rest := compress append('(!" !(),
  46. nconc(explode notprinted,
  47. '(! !t !e !r !m !s !) !"))) . rest
  48. end
  49. %%%if prepexpr=0 and null cdr rest then return car rest
  50. >>
  51. else rest := {'!.!.!.};
  52. return if not eqcar (prepexpr, 'plus)
  53. then 'plus . (prepexpr or 0) . rest
  54. else nconc (prepexpr, rest)
  55. end;
  56. comment The following statement is the interface for the XReduce
  57. fancy printer;
  58. put('Taylor!*,'fancy!-reform,'Taylor!*print1);
  59. symbolic procedure Taylor!*print(u,p);
  60. if !*fort then fmprint(prepTaylor!* u,0)
  61. else if null !*nat then maprint(
  62. 'taylor .
  63. (if TayOrig u
  64. then prepsq Tayorig u
  65. else prepTaylor!* u) .
  66. for each el in TayTemplate u join
  67. {if null cdr TayTpElVars el
  68. then car TayTpElVars el
  69. else 'list . TayTpElVars el,
  70. TayTpElPoint el,
  71. TayTpElOrder el},
  72. p)
  73. else maprint(Taylor!*print1 u,p);
  74. put('Taylor!*,'pprifn,'Taylor!*print);
  75. comment We need another printing function for use with the
  76. TeX-REDUCE interface; %not yet done;
  77. endmodule;
  78. end;