hdiff.red 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. module hdiff;
  2. %% Harmonic differentiation and Integration.
  3. symbolic procedure hdiff(x, u);
  4. if null x then nil
  5. else fs!:plus(hdiff(fs!:next x,u), hdiffterm(x,u));
  6. symbolic procedure hdiffterm(x, u);
  7. begin scalar n;
  8. n := getv!.unsafe(fs!:angle x, u);
  9. if n = 0 then return nil;
  10. n := multsq( n . 1, fs!:coeff x);
  11. if fs!:fn x = 'cos then return make!-term('sin, fs!:angle x, negsq n)
  12. else return make!-term('cos, fs!:angle x, n)
  13. end;
  14. symbolic procedure hdiff1(x, u);
  15. if null x then nil
  16. else begin scalar ans, aaa;
  17. ans := diffsq(fs!:coeff x, u);
  18. if ans then <<
  19. aaa := mkvect 3;
  20. fs!:set!-coeff(aaa, ans);
  21. fs!:set!-fn(aaa, fs!:fn x);
  22. fs!:set!-angle(aaa,fs!:angle x);
  23. fs!:set!-next(aaa, hdiff1(fs!:next x, u));
  24. return aaa >>
  25. else return hdiff1(fs!:next x, u)
  26. end;
  27. symbolic procedure simphdiff uu;
  28. begin scalar x, u;
  29. if not (length uu = 2) then
  30. rerror(fourier, 10, "Improper number of arguments to HDIFF");
  31. x := car uu; uu := cdr uu;
  32. u := car uu;
  33. x := simp x;
  34. if not eqcar(car x, '!:fs!:) then x := !*sq2fourier x ./ 1;
  35. if not harmonicp u then
  36. return (get('fourier, 'tag) . hdiff1(cdar x, u)) ./ 1;
  37. x := hdiff(cdar x,get(u,'fourier!-angle));
  38. if null x then return nil ./ 1;
  39. return (get('fourier, 'tag) . x) ./ 1
  40. end;
  41. put('hdiff, 'simpfn, 'simphdiff);
  42. symbolic procedure hint(x, u);
  43. if null x then nil
  44. %% Bind fs!:zero!-generated ??
  45. else fs!:plus(hint(fs!:next x,u), hintterm(x,u));
  46. symbolic procedure hintterm(x, u);
  47. begin scalar n;
  48. n := getv!.unsafe(fs!:angle x, u);
  49. if n = 0 then return make!-term(fs!:fn x, fs!:angle x, fs!:coeff x);
  50. n := multsq( 1 ./ n, fs!:coeff x);
  51. if fs!:fn x = 'cos then return make!-term('sin, fs!:angle x, n)
  52. else return make!-term('cos, fs!:angle x, negsq n)
  53. end;
  54. symbolic procedure hint1(x , u);
  55. if null x then nil
  56. else begin scalar aaa;
  57. aaa := mkvect 3;
  58. fs!:set!-coeff(aaa, simpint list(prepsq fs!:coeff x, u));
  59. fs!:set!-fn(aaa, fs!:fn x);
  60. fs!:set!-angle(aaa,fs!:angle x);
  61. fs!:set!-next(aaa, hint1(fs!:next x, u));
  62. return aaa
  63. end;
  64. symbolic procedure simphint uu;
  65. begin scalar x, u;
  66. if not (length uu = 2) then
  67. rerror(fourier, 11, "Improper number of arguments to HINT");
  68. x := car uu; uu := cdr uu;
  69. u := car uu;
  70. x := simp x;
  71. if not eqcar(car x, '!:fs!:) then x := !*sq2fourier x ./ 1;
  72. if not harmonicp u then
  73. return (get('fourier, 'tag) . hint1(cdar x, u)) ./ 1;
  74. x := hint(cdar x,get(u,'fourier!-angle));
  75. if null x then return nil ./ 1;
  76. return (get('fourier, 'tag) . x) ./ 1
  77. end;
  78. put('hint, 'simpfn, 'simphint);
  79. initdmode 'fourier;
  80. endmodule;
  81. end;