tayimpl.red 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. module tayimpl;
  2. %*****************************************************************
  3. %
  4. % Functions for computing Taylor expansions of implicit
  5. % or inverse functions
  6. %
  7. %*****************************************************************
  8. exports implicit_taylor, inverse_taylor;
  9. imports
  10. % from the REDUCE kernel:
  11. !*f2q, !*n2f, diffsq, errorp, errorset!*, invsq, mkquote,
  12. mk!*sq, mvar, negsq, numr, quotsq, typerr, simp!*,
  13. % from the header module:
  14. has!-taylor!*, make!-Taylor!*, Taylor!-kernel!-sq!-p,
  15. TayMakeCoeff,
  16. % from module taybasic:
  17. addtaylor, multtaylor, multtaylorsq,
  18. % from module taydiff:
  19. difftaylor,
  20. % from module tayexpnd:
  21. taylorexpand,
  22. % from module taysubst:
  23. subsubtaylor;
  24. symbolic procedure implicit_taylor(f,x,y,x0,y0,n);
  25. % if not fixp n or n < 0 then typerr(n,"expansion order") else
  26. begin scalar x,l,!*tayexpanding!*;
  27. f := simp!* f;
  28. if not null numr subsq(f,{x . x0,y . y0})
  29. then Taylor!-error('implicit_taylor,
  30. " Input expression non-zero at given point");
  31. !*tayexpanding!* := t;
  32. l := {'implicit_taylor1,
  33. mkquote f,
  34. mkquote x,
  35. mkquote y,
  36. mkquote x0,
  37. mkquote y0,
  38. mkquote n};
  39. x := errorset!*(l,!*trtaylor);
  40. if not errorp x then return car x
  41. else Taylor!-error('implicit_taylor,nil)
  42. end;
  43. symbolic procedure implicit_taylor1(f,x,y,x0,y0,n);
  44. begin scalar ft,fn,f1,g;
  45. if n <= 0
  46. then return make!-Taylor!*({TayMakeCoeff({{0}},simp!* y0)},
  47. {{{x},x0,n,n+1}},nil,nil);
  48. ft := quotsq(negsq diffsq(f,x),diffsq(f,y));
  49. f1 := taylorexpand(ft,{{{x},x0,n,n+1}});
  50. if not Taylor!-kernel!-sq!-p f1 then typerr(f,"implicit function");
  51. fn := f1 := mvar numr f1;
  52. g := {TayMakeCoeff({{1}},simp!* subsubtaylor({x . x0,y . y0},f1)),
  53. TayMakeCoeff({{0}},simp!* y0)};
  54. for i := 2 : n do
  55. <<fn := multtaylorsq(
  56. addtaylor(difftaylor(fn,x),
  57. multtaylor(difftaylor(fn,y),f1)),
  58. invsq !*f2q !*n2f i);
  59. g := TayMakeCoeff({{i}},
  60. simp!* subsubtaylor({x . x0,y . y0},fn))
  61. . g>>;
  62. return construct!-Taylor!*(reversip g,x,x0,n)
  63. end;
  64. symbolic operator implicit_taylor;
  65. symbolic procedure construct!-Taylor!*(cfl,x,x0,n);
  66. if not has!-Taylor!* cfl
  67. then make!-Taylor!*(cfl,{{{x},x0,n,n+1}},nil,nil)
  68. else mk!*sq
  69. taylorexpand(simp!* prepTaylor!*1(cfl,{{{x},x0,n,n+1}},nil),
  70. {{{x},x0,n,n+1}});
  71. symbolic operator implicit_taylor;
  72. symbolic procedure inverse_taylor(f,y,x,y0,n);
  73. begin scalar x,l,!*tayexpanding!*;
  74. !*tayexpanding!* := t;
  75. l := {'inverse_taylor1,
  76. mkquote simp!* f,
  77. mkquote x,
  78. mkquote y,
  79. mkquote subeval {{'replaceby,y,y0},f},
  80. mkquote y0,
  81. mkquote n};
  82. x := errorset!*(l,!*trtaylor);
  83. if not errorp x then return car x
  84. else Taylor!-error('inverse_taylor,nil)
  85. end;
  86. symbolic procedure inverse_taylor1(f,x,y,x0,y0,n);
  87. begin scalar fn,f1,g;
  88. if n < 0 then n := 0;
  89. f1 := taylorexpand(invsq diffsq(f,y),{{{y},y0,n,n+1}});
  90. if not Taylor!-kernel!-sq!-p f1 then typerr(f,"implicit function");
  91. fn := f1 := mvar numr f1;
  92. g := {TayMakeCoeff({{1}},simp!* subsubtaylor({y . y0},f1)),
  93. TayMakeCoeff({{0}},simp!* y0)};
  94. for i := 2 : n do
  95. <<fn := multtaylorsq(multtaylor(difftaylor(fn,y),f1),
  96. invsq !*f2q !*n2f i);
  97. g := TayMakeCoeff({{i}},simp!* subsubtaylor({y . y0},fn)) . g>>;
  98. return construct!-Taylor!*(reversip g,x,x0,n)
  99. end;
  100. symbolic operator inverse_taylor;
  101. endmodule;
  102. end;