tayintro.red 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. module TayIntro;
  2. %*****************************************************************
  3. %
  4. % General utility functions
  5. %
  6. %*****************************************************************
  7. exports
  8. confusion, constant!-sq!-p, delete!-nth, delete!-nth!-nth,
  9. replace!-nth, replace!-nth!-nth, smemberlp, Taylor!-error,
  10. var!-is!-nth;
  11. imports
  12. % from REDUCE kernel
  13. constant_exprp, denr, domainp, error1, kernp, mvar, neq, numr,
  14. prepsq, prin2t, rerror,
  15. % from the header module
  16. TayTpElVars;
  17. fluid '(!*tayexpanding!* !*tayrestart!* Taylor!:date!* Taylor!:version);
  18. symbolic procedure var!-is!-nth(tp,var);
  19. %
  20. % Determines in which part of template tp the kernel var occurs.
  21. % Returns a pair (n . m) of positive integers which means
  22. % that var is the mth subkernel in nth element of template tp
  23. % This would look a lot better if the loop statements allowed
  24. % the use of the return statement.
  25. %
  26. begin scalar el,found; integer n,m;
  27. repeat <<
  28. n := n + 1;
  29. el := TayTpElVars car tp;
  30. m := 1;
  31. while el do <<
  32. if var neq car el then <<el := cdr el; m := m + 1>>
  33. else <<el := nil; found := t>>>>;
  34. tp := cdr tp>>
  35. until null tp or found;
  36. if not found then confusion 'var!-is!-nth
  37. else return (n . m)
  38. end;
  39. symbolic procedure delete!-nth (l, n);
  40. %
  41. % builds a new list with nth element of list l removed
  42. %
  43. if n = 1 then cdr l else car l . delete!-nth (cdr l, n - 1);
  44. symbolic procedure delete!-nth!-nth (l, n, m);
  45. %
  46. % builds a new list with mth element of nth sublist of list l
  47. % removed
  48. %
  49. if n = 1 then delete!-nth (car l, m) . cdr l
  50. else car l . delete!-nth!-nth (cdr l, n - 1, m);
  51. symbolic procedure replace!-nth (l, n, v);
  52. %
  53. % builds a new list with the nth element of list l replaced by v
  54. %
  55. if n = 1 then v . cdr l else car l . replace!-nth (cdr l, n - 1, v);
  56. symbolic procedure replace!-nth!-nth (l, n, m, v);
  57. %
  58. % builds a new list with the mth element of nth sublist of list l
  59. % replaced by v
  60. %
  61. if n = 1 then replace!-nth (car l, m, v) . cdr l
  62. else car l . replace!-nth!-nth (cdr l, n - 1, m, v);
  63. symbolic procedure constant!-sq!-p u;
  64. %
  65. % returns t if s.q. u represents a constant
  66. %
  67. numberp denr u and domainp numr u
  68. or kernp u and atom mvar u and flagp (mvar u, 'constant)
  69. or constant_exprp prepsq u;
  70. symbolic procedure smemberlp (u, v);
  71. %
  72. % true if any member of list u is contained at any level in v
  73. %
  74. if null v then nil
  75. else if atom v then v member u
  76. else smemberlp (u, car v) or smemberlp (u, cdr v);
  77. symbolic procedure confusion msg;
  78. %
  79. % called if an internal error occurs.
  80. % (I borrowed the name from Prof. Donald E. Knuth's TeX program)
  81. %
  82. << terpri ();
  83. prin2 "TAYLOR PACKAGE (version ";
  84. prin2 Taylor!:version;
  85. prin2 ", as of ";
  86. prin2 Taylor!:date!*;
  87. prin2t "):";
  88. prin2 "This can't happen (";
  89. prin2 msg;
  90. prin2t ") !";
  91. rerror (taylor, 1,
  92. "Please send input and output to Rainer M. Schoepf!") >>;
  93. symbolic procedure Taylor!-error (type, info);
  94. %
  95. % called if a normal error occurs.
  96. % type is the type of error, info the error info.
  97. %
  98. begin scalar msg; integer errno;
  99. msg := if type eq 'not!-a!-unit then "Not a unit in argument to"
  100. else if type eq 'wrong!-no!-args
  101. then "Wrong number of arguments to"
  102. else if type eq 'expansion
  103. then "Error during expansion"
  104. else if type eq 'wrong!-type!-arg
  105. then "Wrong argument type"
  106. else if type eq 'no!-original
  107. then "Taylor kernel doesn't have an original part in"
  108. else if type eq 'zero!-denom
  109. then "Zero divisor in"
  110. else if type eq 'essential!-singularity
  111. then "Essential singularity in"
  112. else if type eq 'branch!-point
  113. then "Branch point detected in"
  114. else if type eq 'branch!-cut
  115. then "Expansion point lies on branch cut in"
  116. % else if type eq 'inttaylorwrttayvar
  117. % then
  118. % "Integration of Taylor kernel yields non-analytical term"
  119. else if type eq 'invalid!-subst
  120. then "Invalid substitution in Taylor kernel:"
  121. else if type eq 'tayrevert
  122. then "Reversion of Taylor series not possible:"
  123. else if type eq 'implicit_taylor
  124. then
  125. "Computation of Taylor series of implicit function failed"
  126. else if type eq 'inverse_taylor
  127. then
  128. "Computation of Taylor series of inverse function failed"
  129. else if type eq 'max_cycles
  130. then "Computation loops (recursive definition?):"
  131. else if type eq 'not!-implemented
  132. then "Not implemented yet"
  133. else confusion 'Taylor!-ERROR;
  134. % rerror (taylor, errno,
  135. rerror (taylor, 2,
  136. if null info then msg
  137. else if atom info then {msg, info}
  138. else msg . info);
  139. end;
  140. symbolic procedure Taylor!-error!*(type,info);
  141. %
  142. % Like Taylor!-error, but calls sets !*tayrestart!* and calls
  143. % error1 if !*tayexpanding!* indicates that expansion is going
  144. % on and more terms might be necessary.
  145. %
  146. if !*tayexpanding!* then <<!*tayrestart!* := t; error1()>>
  147. else Taylor!-error(type,info);
  148. endmodule;
  149. end;