taypart.red 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. module TayPart;
  2. %*****************************************************************
  3. %
  4. % The interface to the PART operator
  5. %
  6. %*****************************************************************
  7. %exports Taylor!*part,Taylor!*setpart;
  8. exports Taylor!*part;
  9. imports
  10. % from the REDUCE kernel:
  11. !*a2k, aeval, eqcar, parterr, rederr, revalsetp1, simp!*,
  12. typerr,
  13. % from the header module:
  14. make!-Taylor!*, TayCoefflist, TayFlags, TaylorTemplate,
  15. TayOrig,
  16. % from module TayConv:
  17. prepTaylor!*;
  18. %fluid '(!*taylorprintorder TaylorPrintTerms);
  19. symbolic procedure Taylor!*part(tay,n);
  20. begin scalar prep;
  21. % prep := (Taylor!*print1 tay) where !*taylorprintorder='t,
  22. % TaylorPrintTerms='all;
  23. prep := prepTaylor!* tay;
  24. if atom prep then parterr(prep,n);
  25. if n=0 then return car prep;
  26. prep := cdr prep;
  27. if n<0 then <<n := -n; prep := reverse prep>>;
  28. if length prep < n then parterr(tay,n);
  29. return nth(prep,n)
  30. end;
  31. put('Taylor!*,'partop,'Taylor!*part);
  32. %symbolic procedure Taylor!*setpart(tay,nl,repl);
  33. % if car nl=2
  34. % then make!-Taylor!*(
  35. % TayCoefflist tay,
  36. % list!-to!-template(
  37. % revalsetp1(TaylorTemplate tay,cdr nl,repl),
  38. % length TayTemplate tay),
  39. % TayOrig tay,
  40. % TayFlags tay)
  41. % else if car nl=3 and TayOrig tay
  42. % then make!-Taylor!*(
  43. % TayCoefflist tay,
  44. % TayTemplate tay,
  45. % simp!* revalsetp1(reval!* mk!*sq TayOrig tay,cdr nl,repl),
  46. % TayFlags tay)
  47. % else rederr {"Cannot replace part",car nl,"in Taylor kernel"};
  48. %
  49. %
  50. %put('Taylor!*,'setpartop,'Taylor!*setpart);
  51. %
  52. %
  53. %symbolic procedure list!-to!-template (ttp,l);
  54. % if not eqcar(ttp,'list) or length cdr ttp neq l
  55. % then typerr(ttp,"Taylor template")
  56. % else for each ttpel in cdr ttp collect list!-to!-tpel ttpel;
  57. %
  58. %symbolic procedure list!-to!-tpel ttpel;
  59. % if not eqcar(ttpel,'list) or length ttpel<4
  60. % then typerr(ttpel,"Taylor Template element")
  61. % else {if eqcar(cadr ttpel,'list)
  62. % then for each var in cdr cadr ttpel collect !*a2k var
  63. % else {!*a2k cadr ttpel},
  64. % caddr ttpel,
  65. % ((if fixp x then x else typerr(x,"number"))
  66. % where x := aeval cadddr ttpel)};
  67. endmodule;
  68. end;