taylor.red 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  1. module Taylor;
  2. %****************************************************************
  3. %
  4. % THE TAYLOR PACKAGE
  5. % ==================
  6. %
  7. %****************************************************************
  8. %
  9. % Copyright (C) 1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999
  10. % by Rainer M. Schoepf, all rights reserved.
  11. %
  12. % Copying of this file is authorized only if either
  13. % (1) you make absolutely no changes to your copy, including name, or
  14. % (2) if you do make changes, you name it something other than
  15. % taylor.red.
  16. %
  17. % Error reports please to: Rainer Schoepf
  18. % Zentrum fuer Datenverarbeitung
  19. % der Universitaet Mainz
  20. % Anselm-Franz-von-Bentzel-Weg 12
  21. % D-55099 Mainz
  22. % Germany
  23. % Email: <Schoepf@Uni-Mainz.DE>
  24. %
  25. %
  26. % This package implements a new data structure:
  27. %
  28. % >>> the TAYLOR KERNEL <<<
  29. %
  30. % and the functions necessary to operate on it.
  31. %
  32. % A TAYLOR KERNEL is a kernel of the following form:
  33. %
  34. % (Taylor!* TayCoeffList TayTemplate TayOrig TayFlags)
  35. %
  36. % where:
  37. % Taylor!* is a symbol identifying the kernel.
  38. % TayCoeffList is a list of TayCoeff's.
  39. % A TayCoeff is a pair
  40. % (TayPowerList . StandardQuotient).
  41. % A TayPowerList is a list of TayDegreeList's,
  42. % each of which is a list of integers that
  43. % denote the exponents of the Taylor variables.
  44. % TayTemplate is a list of lists, each containing the three
  45. % elements TayVars, TayPoint, TayOrder,
  46. % TayNextOrder, (being the list of variables, the
  47. % expansion point the power of the variable in the
  48. % last coefficient computed, and the power of the
  49. % next coefficient, respectively)
  50. % It is used as a template for the car of the
  51. % pairs in a TayCoeffList.
  52. % TayOrig is the original expression to be Taylor expanded,
  53. % as a standard quotient. It is held mainly for
  54. % the use by possible future extensions.
  55. % This part is nil if the switch taylorkeeporiginal
  56. % was off during expansion.
  57. % TayFlags is currently unused and reserved for future
  58. % extensions.
  59. %
  60. %
  61. %
  62. %*****************************************************************
  63. %
  64. % Revision history
  65. %
  66. %*****************************************************************
  67. %
  68. %
  69. % 17-Jun-97 2.1g
  70. % Minor improvement in procedure taylorexpand!-samevar: do not signal
  71. % an error if we are content with the terms we got (i.e. third
  72. % argument flg is nil.
  73. %
  74. % 16-Apr-97 2.1f
  75. % Slight improvement in tracing output (smacro Taylor!-trace).
  76. % Avoid infinite recursion when mcd is off (pointed out by
  77. % Wolfram Koepf).
  78. %
  79. % 03-May-95 2.1e
  80. % Corrected differentation of Taylor kernels if expansion point
  81. % depends on variable. (Integration still gives wrong result.)
  82. % Printing procedures did not always work for right hand side of
  83. % rules.
  84. %
  85. % 03-Apr-95 2.1d
  86. % Removed special handling for constant Taylor series in taysimptan,
  87. % taysimpsin and taysimpsinh, as it didn't work when the function in
  88. % question has a pole and the expansion point.
  89. %
  90. % 09-Jan-95 2.1c
  91. % Changed rules in tayfns.red to new ~~ format.
  92. %
  93. % 22-Jul-94 2.1b
  94. % Corrected glitch in function common!-increment.
  95. %
  96. % 10-Jun-94 2.1a
  97. % Corrected expansion of tan at pole up to order 0: make quottaylor
  98. % and invtaylor signal restartable error, have taylorexpand truncate
  99. % its result.
  100. % Operator expint is now called ei.
  101. % Changed error message in taysimpasin to signal a branch point, not
  102. % an essential singularity.
  103. %
  104. % 08-May-94 2.1
  105. % Added implicit_taylor and inverse_taylor.
  106. %
  107. %
  108. % 02-May-94 2.0c
  109. % Corrected missing Next field in function taylor2e.
  110. %
  111. % 14-Apr-94 2.0b
  112. % Corrected function expttayi.
  113. % Renamed pos!-rat!-kern!-pow to rat!-kern!-pow and changed calling
  114. % convention, moved to tayutils module.
  115. % subfg!* changed from global to fluid.
  116. % Removed a few unused local variables.
  117. % Added TayExp!-max2.
  118. % Rewrote expansion code for monomials to produce higher order terms.
  119. %
  120. % 14-Mar-94 2.0a
  121. % Corrected generation of simple Taylor kernels when switch mcd is
  122. % off.
  123. % Added code to catch looping with increased order, introduced a
  124. % better error message.
  125. % Added a few missing parentheses in functions taysimpexpt and
  126. % tayrevert1.
  127. %
  128. % 03-Mar-94 2.0
  129. % Introduced rational exponents for Puiseux series. This required
  130. % changes to various functions:
  131. % Taylor exponent manipulation functions
  132. % expttayrat
  133. % expttayrat!* (removed)
  134. % pos!-rat!-kern!-pow
  135. % smallest!-increment and common!-increment
  136. % truncate!-Taylor!*
  137. % tayrevert1
  138. % Added exceeds!-order!-variant that uses strict greaterp, rather
  139. % than geq as exceeds!-order does.
  140. % Added lcmn to compute the least common multiple of two integers.
  141. % Replaced call to subs2 with binding of !*sub2 by subs2!* in
  142. % functions below.
  143. % Removed error type inttaylorwrttayvar, no longer generated.
  144. %
  145. %
  146. %
  147. % 15-Feb-94 1.9c
  148. % Improved taysimpsinh to generate hyperbolic functions in the
  149. % the coefficients of the result rather than exponentials.
  150. % Improved handling of zero Taylor kernels if TayOrig is present.
  151. % Improved taylorexpand!-samevar to handle expansions in more
  152. % than one variable.
  153. % Corrected Taylor substitution to handle parallel substitution
  154. % of several Taylor variables.
  155. % Updated check for differentiation rules of kernels.
  156. % Added new error types for Taylor expansion of implicit and
  157. % inverse functions.
  158. % Made division by zero in taysubst recoverable error during
  159. % expansion.
  160. % Corrected term ordering in Taylorexpand!-diff2.
  161. % Corrected addition and multiplication of Taylor kernels in
  162. % taylorexpand!-sf.
  163. % Added taysimpasec!* to handle singular arguments of asec and
  164. % friends.
  165. %
  166. % 02-Dec-93 1.9b
  167. % Added missing setting of TayOrig part in make!-var!-Taylor!*.
  168. % Corrected handling of substitution of all Taylor variables in
  169. % taysubst.
  170. % Ensure that psi is declared algebraic operator.
  171. % Corrected substitution of Taylor variable by a power of itself.
  172. %
  173. % 30-Nov-93 1.9a
  174. % Corrected cdr of nil in several places, caused by makecoeffs
  175. % returning an empty list.
  176. % Improved handling of zero Taylor kernels if TayOrig is present.
  177. % Added missing setting of TayOrig part in taylorexpand!-diff2.
  178. %
  179. % 29-Nov-93 1.9
  180. % Added min2!-order and replace!-next.
  181. % Improved basic Taylor manipulation functions addtaylor, multtaylor,
  182. % quottaylor.
  183. % Added taylorsingularity feature to expansion code.
  184. %
  185. %
  186. % 24-Nov-93 1.8h
  187. % Changed calling convention for addtaylor1 to include the template.
  188. %
  189. % 15-Nov-93 1.8g
  190. % Rewritten parts of subsubtaylor to better recognize invalid
  191. % substitutions.
  192. %
  193. % 09-Nov-93 1.8f
  194. % Added TayExp!-geq and TayExp!-leq.
  195. % Changed protocol of truncate!-coefflist and exceeds!-order to use
  196. % the next part rather than the order part of a template.
  197. % Cleaned up inv!.tp!..
  198. %
  199. % 08-Nov-93 1.8e
  200. % Improved handling of negative first coefficient in taysimplog.
  201. % Removed binding of !*taylorautocombine in taysimpsq!*.
  202. %
  203. % 03-Nov-93 1.8d
  204. % Improved taysimpsq and taysimpf to avoid returning a constant Taylor
  205. % series as part of an expression.
  206. % Fixed bug in error handling of expansion code that would produce
  207. % "This can't happen" error message.
  208. % Improved error detection for (unknown) operators with logarithmic
  209. % singularity in derivative.
  210. % Removed tayinpoly/tayinpoly1 (no longer used).
  211. % Replaced !*f2q by !*TayExp2q in difftaylorwrttayvar.
  212. % Changed evaluation and printing procedures so that they can be used
  213. % in rule patterns.
  214. % Corrected bug in Taylor kernel integration if the switch
  215. % taylorkeeporiginal was on.
  216. % Improved integration of Taylor kernels in combination with
  217. % logarithmic terms.
  218. % Rewrote rules integration rules in algebraic form.
  219. % Added TpNextList smacro.
  220. % Changed mult!.comp!.tp!. in preparation for non-integer exponents,
  221. % to handle next parts.
  222. % Added invert!-powerlist smacro and used in invtaylor1.
  223. % Renamed taydegree!-lessp to taydegree!< and
  224. % taydegree!-strict!-less!-or!-equal!-p to taydegree!-strict!<!=.
  225. % Added smacro prune!-coefflist.
  226. % Introduced prepTayExp.
  227. % Changed protocol for add!.comp!.tp!. to return a list of the new
  228. % template, so that an empty template can be distiguished from
  229. % failure.
  230. % Changed procedures for Taylor reversion to use addtaylor and friends
  231. % instead of addtaylor1, etc.
  232. % Added an increment argument to all the makecoeff... procedures.
  233. % Added smallest!-increment and common!-increment procedures.
  234. % Rewrote taysimpsq to better handle Taylor kernel in denominator.
  235. %
  236. % 23-Sep-93 1.8c
  237. % Changed Taylor!-generate!-big!-O to produce a capital O even if
  238. % !*lower is t.
  239. %
  240. % 03-Sep-93 1.8b
  241. % Changed multintocoefflist to bind !*sub2 and first call subs2
  242. % and then resimp so that power substitutions are carried out
  243. % properly.
  244. %
  245. % 02-Sep-93 1.8a
  246. % Corrected stupid error that caused car/cdr of an atom.
  247. % Corrected code for expansion by differentiation and for caching
  248. % of intermediate results to use the template of the computed kernel
  249. % rather than the template given to the expansion functions.
  250. % Corrected truncate!-Taylor!* to correctly handle the case that
  251. % the kernel to be truncated has already fewer terms than expected.
  252. %
  253. % 17-Aug-93 1.8
  254. % Improvement in expttayrat if zero is raised to negative power;
  255. % this might be a case for expansion to higher order.
  256. % Rewritten code for expansion by differentiation to handle
  257. % occurrence of a kernel in its own derivative.
  258. %
  259. %
  260. % 12-Aug-93 1.7e
  261. % Rewritten part of the expansion by differentiation code to try
  262. % to differentiate once and expand the result.
  263. % Slight improvement in trace printing.
  264. %
  265. % 13-Jul-93 1.7d
  266. % Corrected taysimpasin and taysimpasin!* to handle branch points
  267. % correctly.
  268. % simpTaylor!* can now handle free variables as part of Taylor!*
  269. % kernel.
  270. %
  271. % 28-Jun-93 1.7c
  272. % Corrected error introduced by last change to mult!.comp!.tp!.
  273. % and inv!.tp!.
  274. %
  275. % 21-Jun-93 1.7b
  276. % Changed taylor2f to not collect zero coefficients into coefflist.
  277. % Changed subs2coefflist to leave out zero coefficients.
  278. % Set default of Taylorautocombine switch to on.
  279. % Replaced calls to subs2!* be calls to subs2 with explicit binding
  280. % of !*sub2.
  281. %
  282. % 17-Jun-93 1.7a
  283. % Added get!-min!-degreelist to find minimum degree list of a
  284. % coefflist; corrected mult!.comp!.tp!. and inv!.comp!.tp!. to
  285. % use it.
  286. % Corrected error in quottaylor that could wrongly calculate first
  287. % coefficient of result.
  288. % Shortened lines in tayfns.red to 72 characters.
  289. % Improved taysimpexp and expttayrat!* to yield an exponential only
  290. % if there are no analytical terms.
  291. % Added code to expand inverse trigonometric and hyperbolic functions
  292. % around their logarithmic singularities.
  293. % Corrected taysimpsin, improved taysimpsinh.
  294. %
  295. % 15-Jun-93 1.7
  296. % Added a lot of utility functions to test for zero, constant,
  297. % and nonzero constant Taylor series.
  298. % Rewritten the Taylor simplification functions in modules TaySimp
  299. % and TayFns to handle non-analytical terms as well.
  300. % Split expttayrat into two procedures.
  301. %
  302. %
  303. % 14-Jun-93 1.6
  304. % Added Taylor!*!-zerop and TayCoeffList!-zerop.
  305. % Introduced addtaylor!-as!-sq, multtaylor!-as!-sq, and
  306. % quottaylor!-as!-sq.
  307. % Changed taymincoeff into an expr procedure, added tayminpowerlist.
  308. % simptaylor returns now the input if it cannot expand.
  309. % Added trtaylor switch and some procedures for tracing.
  310. % Added Taylor!-error!*, currently used only in taysimplog.
  311. % Added TayExpnd module, removed taylorexpand from tayinterf module.
  312. % Moved taymincoeff and tayminpowerlist into TayUtils module.
  313. % Corrected procedures in tayfns.red to not crash for Taylor kernels
  314. % with empty TayCoefflist.
  315. %
  316. %
  317. % 10-Jun-93 1.5b
  318. % Introduced get!-degreelist.
  319. % Rewritten exceeds!-order to be tail-recursive.
  320. % Changed protocol for makecoeffs call, introduced makecoeffs0.
  321. % Introduced !*TayExp2q to convert a power into a standard quotient.
  322. %
  323. % 09-Jun-93 1.5a
  324. % Introduced has!-TayVars predicate, replaced calls to smemberlp
  325. % and smemqlp by it.
  326. % Split addtaylor, multtaylor and quottaylor into two procedures.
  327. % Replaced taysimpp by expttayi in difftaylor.
  328. % Introduced taysimpsq!* (taysimpsq with taylorautoexpand off).
  329. %
  330. % 08-Jun-93 1.5
  331. % Introduction of special operations for exponents in powerlists:
  332. % TayExp!-<op>. The macro Taylor!: is used to replace normal
  333. % operations by these.
  334. % Changed makecoeffpairs and addcoeffs to avoid consing pairs and
  335. % taking them apart again.
  336. % Changed makecoeffpairshom to allow steps different from 1.
  337. %
  338. %
  339. % 07-Jun-93 1.4l
  340. % Introduced TayNextOrder and made corresponding changes to the
  341. % sources.
  342. % Added addto!-all!-TayTpElOrders function.
  343. % Corrected problem in expttayrat that would result in extra (wrong)
  344. % terms if there was no constant term in the Taylor series to be
  345. % raised to a power.
  346. % Removed some calls to !*n2f.
  347. % Replaced call to subs2 by subs2!* in taysimptan.
  348. % Corrected generation of new template in inttaylorwrttayvar
  349. %
  350. % 03-Jun-93 1.4k
  351. % Changed expttayi to handle negative integer powers as well,
  352. % changed taysimpp correspondingly.
  353. %
  354. % 27-May-93 1.4j
  355. % Corrected some oversights in taysimpexpt.
  356. % Added smacro TayTpVars.
  357. % Added code to taysimpp to handle s.f. as main variable.
  358. % Added function subtr!-degrees to tayutils.red.
  359. % Corrected error in var!-is!-nth in tayintro.red.
  360. % Corrected error in taydegree!-lessp in tayutils.red that caused
  361. % incorrect ordering of coefficients.
  362. % Corrected error in quottaylor1.
  363. %
  364. % 06-May-93 1.4i
  365. % Changed printing routines for better interface to fancy printing.
  366. %
  367. % 21-Apr-93 1.4h
  368. % Corrected cosec --> csc, cosech --> csch in tayfns.red.
  369. % Corrected taysimpsin to calculate coth with correct overall sign.
  370. % Improved handling of poles in taysimptan.
  371. % Rewritten taysimpsin to use exponential rather than tangent.
  372. % Added slight optimization in taylorsamevar if desired matches
  373. % actual expansion order.
  374. %
  375. % 01-Apr-93 1.4g
  376. % Changed multtaylor1 so that in multiplication of Taylor kernels
  377. % products would be simplified as well.
  378. % Changed taysimptan to allow expansion point to be a pole of tan,
  379. % cot, tanh, or coth.
  380. % Changed constant!-sq!-p and taysimpexpt to recognize constant
  381. % expression in first argument to expt.
  382. % Changed printing so that only non-vanishing terms are counted.
  383. % Introduced taysimpsinh for simplifcation of expressions involving
  384. % sinh, coth, sech, csch.
  385. % Added subs2coefflist and resimpcoefflist smacros.
  386. % Modified addtaylor1, multtaylor1, quottaylor1 and invtaylor1 to call
  387. % subs2coefflist.
  388. % Protected klist property of atom Taylor!* against being filled
  389. % unnecessarily with intermediate results.
  390. % Changed expttayrat to print a more meaningful error message when it
  391. % detects a branch point.
  392. % Improved taysimpexpt to handle more cases.
  393. %
  394. % 08-Mar-93 1.4f
  395. % Changed printing of Taylor kernels to include `(nn terms)' instead
  396. % of `...'.
  397. %
  398. % 25-Feb-93 1.4e
  399. % Made expttayi more efficient by replacing straightforward
  400. % multiplication by a scheme that computes powers of 2.
  401. % Corrected error in taysimpexp.
  402. %
  403. % 24-Feb-93 1.4d
  404. % Corrected error in taydiffp.
  405. % Made especially multtaylor1, but also addtaylor1 and expttayrat
  406. % more efficient.
  407. %
  408. % 01-Feb-93 1.4c
  409. % Corrected error in tayrevert1: constant term was missing.
  410. % Changed frlis!* from global to fluid.
  411. % Corrected error in taylor2f that caused certain expressions, like
  412. % i^2, not to be simplified correctly (discovered by Stan Kameny).
  413. %
  414. % 16-Apr-92 1.4b
  415. % Corrected errors in taysimpexpt, mult!.comp!.tp!., and expttayrat.
  416. % The error corrected in version 1.4a was also present in invtaylor.
  417. % Corrected error in taylor2e/taylor2f.
  418. % Improved printing of negative coefficients.
  419. % Corrected error in subsubtaylor.
  420. % Corrected error in taysimpexp.
  421. % Added simp0fn property to Taylor!* for proper handling of
  422. % substitutions.
  423. % Added make!-cst!-coefficient smacro.
  424. % Added partial suppression of printing of coefficients and
  425. % TAYLORPRINTTERMS variable.
  426. %
  427. % 11-Feb-92 1.4a
  428. % Corrected error in quottaylor1: If numerator or denominator had
  429. % a zero constant term, the result had the wrong number of terms.
  430. %
  431. % 09-Jan-92 1.4
  432. % Implemented Taylor reversion.
  433. %
  434. %
  435. % 07-Jan-92 1.3e
  436. % Corrected bug in taysimpsin: wrong type of return value.
  437. %
  438. % 27-Nov-91 1.3d
  439. % Corrected glitch in quottaylor1: Taylor kernel representing 0
  440. % as numerator gave an error.
  441. %
  442. % 06-Nov-91 1.3c
  443. % Improved support for integration of expressions involving Taylor
  444. % kernels.
  445. %
  446. % 31-Oct-91 1.3b
  447. % Added (limited) support for the integration of Taylor kernels.
  448. %
  449. % 19-Jul-91 1.3a
  450. % Introduced taysimpmainvar for main variables that are standard
  451. % forms, as in factored expressions. Changed taysimpp accordingsly.
  452. % Introduced new smacros !*tay2f and !*tay2q that make Taylor kernels
  453. % unique.
  454. %
  455. % 03-Jun-91 1.3
  456. % Started version for REDUCE 3.4.
  457. % Updated diffp according to changes for REDUCE 3.4.
  458. % Replaced freeof by has!-Taylor!* in taysimpf and taysimpt, and by
  459. % depends in difftaylor and taylor2e.
  460. % Changed module names to conform to file names.
  461. % Moved (nearly) all smacros into header (taylor) module,
  462. % made cst!-Taylor!* an smacro, moved remaining functions from
  463. % taymacros into tayutils, deleted taymacros module.
  464. % Made makecoeffpairs (in module taybasic) from smacro to expr.
  465. % Changed taylorsamevar to use TayOrig part of Taylor kernel if
  466. % present.
  467. % Changed Taylor printing functions since it is now possible to
  468. % pass information of operator precedence (via pprifn property).
  469. % Fixed bug in subsubtaylor (found by H. Melenk): did not substitute
  470. % in expansion point.
  471. % Changed error handling to call new function rerror instead of
  472. % rederr.
  473. % Changed for use of new hooks prepfn2, subfunc, and dfform
  474. % instead of redefining sqchk, subsublis, and diffp.
  475. %
  476. % 20-Oct-90 1.2j
  477. % Added check in subsubtaylor for variable dependency.
  478. % Fixed stupid bug in taylorsamevar.
  479. % Corrected taysimpexpt to handle rational exponents with ON RATIONAL.
  480. % Corrected expttayrat: looks now at first NON-ZERO coefficient to
  481. % determine whether root can safely be computed.
  482. % Fixed bug in mult!.comp!.tp..
  483. % Added error check in invtaylor1 and quottaylor1.
  484. % Fixed bug in quottaylor1 that produced wrong results for
  485. % multidimensional Taylor series, introduced taydegree!-min2 and
  486. % taydegree!-strict!-less!-or!-equal!-p.
  487. %
  488. % 05-Oct-90 1.2i
  489. % Replaced variable name nn by nm in taysimpsq to avoid name conflicts
  490. % with the SPDE package by Fritz Schwartz.
  491. % Replaced call to apply by apply1 in taysimpkernel.
  492. % Minor changes in expttayrat, taysimplog, taysimpexp, and taysimptan:
  493. % inserted explicit calls to invsq to allow negative numbers in
  494. % denominator.
  495. % Fixed bugs in difftaylorwrttayvar, inttaylorwrttayvar and
  496. % subsubtaylor: treatment of a Taylor kernel expanded about infinity
  497. % would give a wrong result. Found by John Stewart.
  498. %
  499. % 11-Aug-90 1.2h
  500. % Replaced call to get!* by get in diffp since get!* will no longer
  501. % be available in REDUCE 3.4.
  502. % Fixed bug in multintocoefflist that was introduced by replacing
  503. % car by TayCfPl.
  504. % Moved setting of TayOrig part from taylor1 to taylorexpand. This
  505. % avoids Taylor kernels in the TayOrig part of multidimensional
  506. % Taylor expansions. It does not fully solve the problem since
  507. % they can still be generated by applying the Taylor operator to
  508. % expressions that do not contain fully Taylor-combined Taylor
  509. % kernels.
  510. % Reversed list of expansions in call to taylorexpand in simptaylor.
  511. % Modified taylor1 accordingly. Previously this could trigger a
  512. % `This can't happen' error message (due to incorrect ordering of
  513. % the Taylor variables).
  514. % Removed procedures delete!-coeff and replace!-coeff since they are
  515. % no longer used.
  516. % Moved call to subs2 out of differentiation loop in taylor2f,
  517. % improves timing significantly; deleted superfluous declared
  518. % integer variable.
  519. % Fixed bug in taylorsamevar.
  520. % Added extra checks and double evaluation of lists in simptaylor.
  521. % Replaced a number of ./ by !*f2q, introduced some !*n2f conversion
  522. % functions.
  523. % Development frozen, version shipped out.
  524. %
  525. % 06-May-90 1.2g
  526. % Fixed bug in taylor2e that caused order of kernels in homogenous
  527. % expansions to be reverted. Discovered by Karin Gatermann.
  528. % Removed binomial!-coeff since no longer needed (in expttayrat).
  529. % Replaced some forgotten car/cdr by TayCfPl/TayCfSq.
  530. % Reordered import declarations.
  531. % Replaced many semicolons by dollar signs. Decreases amount of
  532. % printing during input of this file.
  533. % Minor bug fix in taysimpsin.
  534. % Minor change in taysimpasin and taysimpatan.
  535. % Split inttaylorwrttayvar into two procedures, added check for
  536. % logarithmic term in integration procedure inttaylorwrttayvar1.
  537. % Replaced combination of addsq and negsq by subtrsq in quottaylor1,
  538. % subsubtaylor and taysimplog.
  539. % Renamed taygetcoeff to TayGetCoeff (doesn't make any difference
  540. % on case-insensitive systems).
  541. % Minor changes in taymultcoeffs, multintocoefflist, resimptaylor,
  542. % taylor1sq, taylor2f, negtaylor1, quottaylor1, invtaylor1,
  543. % expttayrat, subsubtaylor, difftaylor, taysimpasin, taysimpatan,
  544. % taysimplog, taysimpexp, taysimptan, difftaylorwrttayvar,
  545. % inttaylorwrttayvar1, addtaylor1 (cons -> TayMakeCoeff).
  546. % Similar change in taysimpp (cons -> .**, i.e. to).
  547. %
  548. % 29-Mar-90 1.2f
  549. % Fixed bug in taysimpf (addition of Taylor kernels) that could cause
  550. % "This can't happen" message.
  551. % Fixed bug in difftaylorwrttayvar: arguments to make!-cst!-coefflis
  552. % were interchanged.
  553. % Fixed similar bug in expttayrat (this procedure was never used!)
  554. % Added forgotten call to list in taylor2f.
  555. % Changed representation of big-O notation: print O(x^3,y^3) instead
  556. % of O(x^3*y^3) if expansion was done up to x^2*y^2.
  557. % Introduced new version of expttayrat (algorithm as quoted by Knuth)
  558. % which is faster by about a factor of two.
  559. % Fixed Taylor!-gen!-big!-O so that expansion point at infinity
  560. % is treated correctly for homogeneously expanded series.
  561. %
  562. % 27-Feb-90 1.2e
  563. % Removed procedures addlogcoeffs, addexpcoeffs and addtancoeffs,
  564. % inserted code directly into taysimplog, taysimpexp, and
  565. % taysimptan.
  566. % taylorvars renamed to TayVars.
  567. % find!-non!-zero moved into Taylor!:macros module.
  568. %
  569. % 26-Feb-90 1.2d
  570. % Added following selector, constructor, and modification smacros:
  571. % TayCfPl, TayCfSq, TayMakeCoeff, set!-TayCfPl, set!-TayCfSq,
  572. % TayTpElVars, TayTpElPoint, TayTpElOrder.
  573. % Some minor changes in several procedures to improve readability.
  574. %
  575. % 19-Jan-90 1.2c
  576. % Removed first argument of addtaylor since never used.
  577. %
  578. % 14-Nov-89 1.2b
  579. % Added taysimpsin.
  580. % Split tayinpoly1 off from tayinpoly, modified expttayrat
  581. % accordingly.
  582. % Changed global declarations to fluid. No reason to prevent
  583. % binding.
  584. %
  585. % 11-Nov-89 1.2a
  586. % Minor changes in the procedures changed yesterday (cleanup).
  587. % Added procedure taysimptan.
  588. % Replaced taylor1sq by taylorexpand in taysimpf1.
  589. % taysimpsq partly rewritten (will these bugs never die out?)
  590. % taysimpf1 renamed to taysimpf, taylor!*!-sf!-p to
  591. % Taylor!-kernel!-sf!-p.
  592. % Replaced a few of these by Taylor!-kernel!-sq!-p.
  593. %
  594. % 10-Nov-89 1.2
  595. % Introduced taylorexpand to be the heart of simptaylor and to
  596. % replace simptaylor in taysimpt and multpowerintotaylor.
  597. % Added new versions of procedures taysimplog and taysimpexp
  598. % (Knuth's algorithm).
  599. % Taylor!:basic module moved up (so that some smacros are
  600. % defined earlier).
  601. %
  602. %
  603. % 09-Nov-89 1.1b
  604. % Fixed bug in taylor2e: quottaylor1 got the wrong template so
  605. % that it would truncate the resulting coeff list.
  606. % Added call to subs2 after call to diffsq in taylor2f so that
  607. % expressions containing radicals are simplified already at
  608. % this point.
  609. %
  610. % 21-Aug-89 1.1a
  611. % Fixed bug in taysimpp: it could return a s.q. instead of a s.f.
  612. % Added a few forgotten import declarations.
  613. %
  614. % 31-Jul-89 1.1
  615. % Slight changes in calls to confusion, minor change in taysimpp.
  616. % Introduced big-O notation, added taylorprintorder switch.
  617. % taysimpasin and taysimpatan now also calculate the inverse
  618. % hyperbolic functions.
  619. % New smacro Taylor!-kernel!-sq!-p replaces combinations of
  620. % kernp and Taylor!*p.
  621. %
  622. %
  623. % 24-Jul-89 1.0a
  624. % Bug fix in constant!-sq!-p: mvar applied to s.q., not s.f.
  625. % Added safety check in taysimpt.
  626. %
  627. % 27-May-89 1.0
  628. % Decided to call this version 1.0, it seems to be sufficiently (?)
  629. % bug free to do so.
  630. % Minor bug fix in expttayrat (forgotten variable declaration).
  631. %
  632. %
  633. % 25-May-89 0.9l
  634. % Bug fixed in taylor2e
  635. % (thanx to Rich Winkel from UMC for pointing out this one).
  636. % Cleaned up the code for truncating when combining Taylor kernels
  637. % of different order.
  638. % Introduced taysimpasin for computing the asin, acos, etc.
  639. % of a Taylor kernel.
  640. % Changed some internal procedures to call addtaylor1, etc.
  641. % instead of addtaylor, etc. if both arguments have the same
  642. % template.
  643. % Changed representation of the coefflist: expansion with respect
  644. % to one variable is a special case of homogeneous expansion.
  645. % This is now reflected in the internal representation. These
  646. % changes make the code shorter since all expansions are
  647. % done the same way (fewer checks necessary).
  648. %
  649. % 23-Mar-89 0.9k
  650. % Numerous bug fixes.
  651. % Changed subsubtaylor to allow error checking in var!-is!-nth.
  652. % Rewrote taydegree!-lessp to iterate over its arguments rather
  653. % than call itself recursively.
  654. % Introduced exceeds!-order instead of taydegree!-lessp
  655. % (in truncate!-coefflist and multtaylor1).
  656. % Minor changes in Taylor!*!-sf!-p, taysimpexp, var!-is!-nth,
  657. % taysimpexpt, and inttaylorwrttayvar.
  658. % Changed simptaylor!* to apply resimp to all coefficients and
  659. % to the tayorig part.
  660. % Changed subsubtaylor to allow substitution of a kernel into a
  661. % homogeneously expanded expression.
  662. % Changed difftaylorwrttayvar to allow differentiation of
  663. % homogeneously expanded expressions.
  664. % Changed subsubtaylor so that substitution of a kernel is possible
  665. % (not only a variable).
  666. % New constructor smacros make!-Taylor!* and TayFlagsCombine replace
  667. % explicit list building.
  668. % New procedures: get!-degree and truncate!-coefflist induced
  669. % changes in addtaylor/multtaylor/quottaylor/invtaylor.
  670. % This fixes the other problem pointed out by H. Melenk.
  671. % Split addtaylor/multtaylor the same way as quottaylor/invtaylor.
  672. % Introduced taylorautocombine switch and interface to simp!*
  673. % (via mul!* list).
  674. % Added symbolic; statement in taylor!-intro module; necessary
  675. % until module/endmodule are fixed to work together with faslout.
  676. % Changed subsubtaylor to return a conventional prefix form
  677. % if all Taylor variables are substituted by constants.
  678. % Changed difftaylorwrttayvar to ensure that the coefflist of
  679. % the Taylor kernel it returns is not empty.
  680. % Changed subsubtaylor to avoid 0**n for n<=0 when substituting
  681. % a Taylor variable (to signal an error instead); changed
  682. % taylor!-error accordingly.
  683. % Added taylortemplate operator, removed smacro
  684. % taylor!-map!-over!-coefficients.
  685. % Added code for expansion about infinity.
  686. % Split quottaylor into two parts: the driver (quottaylor) and
  687. % the routine doing the work (quottaylor1). Same for invtaylor.
  688. % Rewrote the expansion procedures taylor1, taylor2,...
  689. % Change in taylor2e: added flg parameter, introduced
  690. % delete!-superfluous!-coeffs.
  691. % Added set!-tayorig and multintocoefflist.
  692. % Replaced simp by simp!* for simplication of tayorig part in
  693. % taysimplog and taysimpexpt.
  694. % Removed taysimpsq in taylorseriesp: it now returns t iff its
  695. % argument is a Taylor kernel disguised as a standard quotient.
  696. % Added taylororiginal operator.
  697. % Added a number of tests if tayorig of a Taylor kernel is non-nil
  698. % if !*taylorkeeporiginal is set.
  699. % Replaced calls to simpdiff in taylor2e and simpexpt by a call
  700. % to simp.
  701. % Minor change in taylor!*print!*1.
  702. % H. Melenk discovered that the code did not behave as documented:
  703. % addition of Taylor kernels differing only in their order did not
  704. % work, and Taylor expansion of a Taylor kernel w.r.t. one of its
  705. % variables would fail.
  706. % Corrected the latter problem by changing the substitution code
  707. % to allow a Taylor variable to be replaced by a constant.
  708. % taylorseriesp is now a boolean operator and therefore only
  709. % usable in if statements.
  710. % Replaced calls to subsq1/subf1 by subsq/subf,
  711. % definitions of subsq1 and taymaxdegree deleted.
  712. % Minor changes in taylor2hom and taylor2e.
  713. %
  714. % 28-Nov-88 0.9j
  715. % Changed printing of `. . . ' to `...'.
  716. % Changed simptrig to simp in taysimpatan.
  717. % Changed simptaylor to simplify all its arguments, not only
  718. % the first one.
  719. % Added !*verboseload switch to conditionalize printing of
  720. % loading info.
  721. % Changed taylor2 to call taylor!-error instead of rederr.
  722. % Modified taylor!-error accordingly.
  723. %
  724. % 16-Nov-88 0.9i
  725. % Fixed a Typo in quottaylor.
  726. % Inserted module/endmodule declarations.
  727. % Added errorset in taylor2 to catch zero denominators, etc.,
  728. % caused by expansion about essential singularities.
  729. %
  730. % 10-Nov-88 0.9h
  731. % Fixed bugs that caused taking car of an atom (found by A.C.Hearn).
  732. % taysimpt used multf instead of multpf.
  733. % I also discovered a car/cdr of nil in
  734. % makecoeffpairs1/makecoeffpairshom1.
  735. % Reason: (nil . nil) == (nil), but what I want is
  736. % ((nil . nil)) == ((nil)). Stupid, eh?
  737. %
  738. % 23-Jul-88 0.9g
  739. % Added dmode!* to list of fluid variables,
  740. % removed taylor!-map!-over!-coefficients!-and!-orig.
  741. %
  742. % 26-May-88 0.9f
  743. % Minor bug fix in taydegree!-lessp.
  744. %
  745. % 25-May-88 0.9e
  746. % Fixed a number of smaller bugs.
  747. % Finally implemented multiplication and division for
  748. % homogeneously expanded Taylor series.
  749. % Today I realized that the procedure diffp in ALG2 had
  750. % been changed for REDUCE 3.3.
  751. %
  752. % 21-May-88 0.9d
  753. % Fixed bug in invtaylor.
  754. % Rewrote quottaylor to do direct division rather use invtaylor.
  755. %
  756. % 14-May-88 0.9c
  757. % Fixed substitution for expansion variable.
  758. %
  759. % 11-May-88 0.9b
  760. % Fixed user interface functions taylorseriesp and taylortostandard.
  761. %
  762. % 10-May-88 0.9a
  763. % Small changes in subsubtaylor and difftaylor to make the code
  764. % compilable, plus minor bug fixes.
  765. %
  766. % 08-May-88 0.9
  767. % invtaylor changed to allow inversion of multidimensional
  768. % Taylor kernels (but still not for homogeneous expansion).
  769. %
  770. %
  771. % 06-May-88 0.8i
  772. % `conc' changed to `join' (for mnemonic purposes).
  773. %
  774. % 29-Apr-88 0.8h
  775. % Minor bug fix in invtaylor (missing quote).
  776. %
  777. % 21-Mar-88 0.8g
  778. % Minor change in TayDegreeSum.
  779. %
  780. % 17-Jan-88 0.8f
  781. % Started implementation of homogeneous expansion
  782. % (required change in conversion to prefix form).
  783. %
  784. % 16-Jan-88 0.8e
  785. % Minor change in the definition of confusion.
  786. %
  787. % 15-Jan-88 0.8d
  788. % Changed to conform to REDUCE 3.3
  789. % (SWITCH statement, minor changes in parsing).
  790. %
  791. % 03-Jan-88 0.8c
  792. % First version that is supposed to return always a correct result
  793. % (but not all possible cases are handled).
  794. %
  795. %
  796. %*****************************************************************
  797. %
  798. % Things to do:
  799. %
  800. %*****************************************************************
  801. %
  802. % a) Finish implementation of homogeneous expansion (hard).
  803. % b) Find a method to handle singularities (very hard).
  804. % c) Perhaps I should change the definition of ORDP to order
  805. % Taylor kernels in some special way?
  806. % d) An interface for the PART operator is desirable. Currently
  807. % Taylor kernels are converted into prefix form.
  808. % Alas, with REDUCE 3.x this requires redefinition of some
  809. % functions. (More hooks, please!)
  810. % Same applies to COEFF and COEFFN.
  811. % e) Rewrite the expansion code to recursively descend a standard
  812. % form. This allows recognition of certain special functions,
  813. % e.g., roots and logarithms. (Much work, requires rewriting
  814. % of a large part of the code.)
  815. % f) With e) it is easy to implement a DEFTAYLOR operator so that
  816. % the user may define the Taylor expansion of an unknown
  817. % function.
  818. % g) This would also allow the use of Taylor for power series
  819. % solutions of ODEs.
  820. % h) Implement a sort of lazy evaluation scheme, similar to the
  821. % one used in the TPS package written by Alan Barnes and
  822. % Julian Padget. This would allow the calculation of more
  823. % terms of a series when they are needed.
  824. % i) Replace all non-id kernels that are independent of the Taylor
  825. % variables by gensyms. This would reduce the size of the
  826. % expressions.
  827. %
  828. %
  829. create!-package('(Taylor TayIntro TayUtils TayIntrf TayExpnd TayBasic
  830. TaySimp TaySubst TayDiff TayConv TayPrint
  831. TayFront TayFns TayRevrt TayImpl TayPart),
  832. '(contrib taylor));
  833. %*****************************************************************
  834. %
  835. % Non-local variables used in this package
  836. %
  837. %*****************************************************************
  838. fluid '(Taylor!:version % version number
  839. Taylor!:date!* % release date
  840. TaylorPrintTerms % Number of terms to be printed
  841. !*tayexpanding!*
  842. !*tayrestart!*
  843. !*taylorkeeporiginal % \
  844. !*taylorautoexpand % \
  845. !*taylorautocombine % > see below
  846. !*taylorprintorder % /
  847. !*trtaylor % /
  848. convert!-Taylor!*
  849. !*sub2
  850. !*verboseload);
  851. share TaylorPrintTerms;
  852. comment This package has six switches:
  853. `TAYLORKEEPORIGINAL' causes the expression for which the
  854. expansion is performed to be kept.
  855. `TAYLORAUTOEXPAND' makes Taylor expressions ``contagious''
  856. in the sense that all other terms are automatically
  857. Taylor expanded and combined.
  858. `TAYLORAUTOCOMBINE' causes taysimpsq to be applied to all
  859. expressions containing Taylor kernels. This is equivalent
  860. to applying `TAYLORCOMBINE' to all those expressions.
  861. If `TAYLORPRINTORDER' is set to ON Taylor kernels are
  862. printed in big-O notation instead of just printing three dots.
  863. `TRTAYLOR', if on, prints some information about the expansion
  864. process.
  865. `VERBOSELOAD' is a variable used by Portable Standard Lisp
  866. and causes a loading info to be printed;
  867. switch taylorautocombine,
  868. taylorautoexpand,
  869. taylorkeeporiginal,
  870. taylorprintorder,
  871. trtaylor,
  872. verboseload;
  873. convert!-Taylor!* := nil; % flag indicating that Taylor kernels
  874. % should be converted to prefix forms
  875. TaylorPrintTerms := 5; % Only this nubmer of non-zero terms
  876. % will normally be printed.
  877. !*taylorkeeporiginal := nil; % used to indicate if the original
  878. % expressions (before the expansion)
  879. % are to be kept.
  880. !*taylorautoexpand := nil; % set if non-taylor expressions are to
  881. % be expanded automatically on
  882. % combination.
  883. !*taylorautocombine := t; % set if taysimpsq should be added to
  884. % the MUL!* list.
  885. !*taylorprintorder := t; % set if Taylor kernels should be printed
  886. % with big-O notation, now on by default.
  887. %!*verboseload := nil; % set if loading info should be printed
  888. !*tayexpanding!* := nil; % set by taylorexpand to indicate that
  889. % expansion is in progress.
  890. !*tayrestart!* := nil; % set by Taylor!-error!* if expansion is
  891. % in progress to indicate that the error
  892. % might disappear if the order is
  893. % increased.
  894. Taylor!:version := "2.1g"; % version number of the package
  895. Taylor!:date!* := "17-Jun-97"; % release date
  896. if !*verboseload then
  897. << terpri ();
  898. prin2 "TAYLOR PACKAGE, version ";
  899. prin2 Taylor!:version;
  900. prin2 ", as of ";
  901. prin2 Taylor!:date!*;
  902. prin2t " for REDUCE 3.6 being loaded...";
  903. terpri () >> ;
  904. exports !*tay2f, !*tay2q, !*TayExp2q, copy!-list, cst!-Taylor!*,
  905. get!-degree, get!-degreelist, has!-Taylor!*, has!-TayVars,
  906. make!-cst!-coefficient, make!-cst!-coefflis,
  907. make!-cst!-powerlist, make!-Taylor!*, multintocoefflist,
  908. nzerolist, prepTayExp, resimpcoefflist, resimptaylor,
  909. set!-TayCfPl, set!-TayCfSq, set!-TayCoeffList, set!-TayFlags,
  910. set!-TayOrig, set!-TayTemplate, subs2coefflist, TayCfPl,
  911. TayCfSq, TayCoeffList, TayDegreeSum, TayExp!-difference,
  912. TayExp!-greaterp, TayExp!-lessp, TayExp!-max2, TayExp!-min2,
  913. TayExp!-minus, TayExp!-minusp, TayExp!-plus, TayExp!-plus2,
  914. TayExp!-times, TayExp!-times2, TayFlags, TayFlagsCombine,
  915. TayGetCoeff, Taylor!*p, Taylor!-kernel!-sf!-p,
  916. Taylor!-kernel!-sq!-p, Taylor!:, TayMakeCoeff, taymincoeff,
  917. taymultcoeffs, TayOrig, TayTemplate, TayTpElNext,
  918. TayTpElOrder, TayTpElPoint, TayTpElVars, TayVars,
  919. TpDegreeList;
  920. imports
  921. % from REDUCE kernel:
  922. !*f2q, !*i2rn, !*p2f, !*p2q, !:minusp, confusion, domainp,
  923. eqcar, kernp, lastpair, lc, ldeg, lpriw, mathprint, mk!*sq,
  924. mksp, multsq, mvar, nlist, numr, over, prin2t, red, resimp,
  925. rndifference!:, rnminus!:, rnminusp!:, rnplus!:, rnprep!:,
  926. rnquotient!:, rntimes!:, simprn, smember, subs2, subs2!*,
  927. % from module Tayintro:
  928. smemberlp,
  929. % from module Tayutils:
  930. add!-degrees;
  931. %*****************************************************************
  932. %
  933. % General utility smacros
  934. %
  935. %*****************************************************************
  936. symbolic smacro procedure nzerolist n;
  937. %
  938. % generates a list of n zeros
  939. %
  940. nlist (0, n);
  941. symbolic smacro procedure copy!-list l;
  942. %
  943. % produces a copy of list l.
  944. %
  945. append (l, nil);
  946. %*****************************************************************
  947. %
  948. % Selector and constructor smacros for Taylor kernels
  949. %
  950. %*****************************************************************
  951. symbolic smacro procedure make!-Taylor!* (cflis, tp, orig, flgs);
  952. %
  953. % Builds a new Taylor kernel structure out of its parts.
  954. %
  955. {'Taylor!*, cflis, tp, orig, flgs};
  956. symbolic smacro procedure TayMakeCoeff (u, v);
  957. %
  958. % Builds a coefficient from degreelist and s.q.
  959. %
  960. u . v;
  961. comment Selector smacros for the parts of a Taylor kernel;
  962. symbolic smacro procedure TayCoeffList u; cadr u;
  963. symbolic smacro procedure TayTemplate u; caddr u;
  964. symbolic smacro procedure TayOrig u; cadddr u;
  965. symbolic smacro procedure TayFlags u; car cddddr u;
  966. symbolic smacro procedure TayCfPl u; car u;
  967. symbolic smacro procedure TayCfSq u; cdr u;
  968. symbolic smacro procedure TayTpVars tp;
  969. for each x in tp join copy!-list car x;
  970. symbolic smacro procedure TayVars u;
  971. TayTpVars TayTemplate u;
  972. symbolic smacro procedure TayGetCoeff (degrlis, coefflis);
  973. (if null cc then nil ./ 1 else TayCfSq cc)
  974. where cc := assoc (degrlis, coefflis);
  975. symbolic smacro procedure TayTpElVars u; car u;
  976. symbolic smacro procedure TayTpElPoint u; cadr u;
  977. symbolic smacro procedure TayTpElOrder u; caddr u;
  978. symbolic smacro procedure TayTpElNext u; cadddr u;
  979. symbolic smacro procedure TpDegreeList tp;
  980. for each x in tp collect TayTpElOrder x;
  981. symbolic smacro procedure TpNextList tp;
  982. for each x in tp collect TayTpElNext x;
  983. %symbolic smacro procedure TayDegreeList u;
  984. % TpDegreeList TayTemplate u;
  985. symbolic smacro procedure TayDegreeSum u;
  986. for each x in TayTemplate u sum TayTpElOrder x;
  987. comment Modification smacros;
  988. symbolic smacro procedure set!-TayCoeffList (u, v);
  989. %
  990. % Sets TayCoeffList part of Taylor kernel u to v
  991. %
  992. rplaca (cdr u, v);
  993. symbolic smacro procedure set!-TayTemplate (u, v);
  994. %
  995. % Sets TayTemplate part of Taylor kernel u to v
  996. %
  997. rplaca (cddr u, v);
  998. symbolic smacro procedure set!-TayOrig (u, v);
  999. %
  1000. % Sets TayOrig part of Taylor kernel u to v
  1001. %
  1002. rplaca (cdddr u, v);
  1003. symbolic smacro procedure set!-TayFlags (u, v);
  1004. %
  1005. % Sets TayFlags part of Taylor kernel u to v
  1006. %
  1007. rplaca (cddddr u, v);
  1008. symbolic smacro procedure set!-TayCfPl (u, v);
  1009. rplaca (u, v);
  1010. symbolic smacro procedure set!-TayCfSq (u, v);
  1011. rplacd (u, v);
  1012. comment Smacro that implement arithmetic operations on
  1013. exponents in powerlist;
  1014. symbolic smacro procedure exponent!-check!-int rn;
  1015. if cddr rn=1 then cadr rn else rn;
  1016. symbolic procedure !*TayExp2q u;
  1017. if atom u then !*f2q (if zerop u then nil else u)
  1018. else cdr u;
  1019. symbolic procedure !*q2TayExp u;
  1020. (if null x then confusion '!*q2TayExp
  1021. else exponent!-check!-int car x)
  1022. where x := simprn {mk!*sq u};
  1023. symbolic procedure prepTayExp u;
  1024. if atom u then u else rnprep!: u;
  1025. symbolic macro procedure TayExp!-plus x;
  1026. if null cdr x then 0
  1027. else if null cddr x then cadr x
  1028. else expand(cdr x,'TayExp!-plus2);
  1029. symbolic procedure TayExp!-plus2(e1,e2);
  1030. if atom e1 and atom e2 then e1+e2
  1031. else exponent!-check!-int(
  1032. if atom e1 then rnplus!:(!*i2rn e1,e2)
  1033. else if atom e2 then rnplus!:(e1,!*i2rn e2)
  1034. else rnplus!:(e1,e2));
  1035. symbolic procedure TayExp!-difference(e1,e2);
  1036. if atom e1 and atom e2 then e1-e2
  1037. else exponent!-check!-int(
  1038. if atom e1 then rndifference!:(!*i2rn e1,e2)
  1039. else if atom e2 then rndifference!:(e1,!*i2rn e2)
  1040. else rndifference!:(e1,e2));
  1041. symbolic procedure TayExp!-minus e;
  1042. if atom e then -e else rnminus!: e;
  1043. symbolic macro procedure TayExp!-times x;
  1044. if null cdr x then 1
  1045. else if null cddr x then cadr x
  1046. else expand(cdr x,'TayExp!-times2);
  1047. symbolic procedure TayExp!-times2(e1,e2);
  1048. if atom e1 and atom e2 then e1*e2
  1049. else exponent!-check!-int(
  1050. if atom e1 then rntimes!:(!*i2rn e1,e2)
  1051. else if atom e2 then rntimes!:(e1,!*i2rn e2)
  1052. else rntimes!:(e1,e2));
  1053. symbolic procedure TayExp!-quotient(u,v);
  1054. exponent!-check!-int
  1055. rnquotient!:(if atom u then !*i2rn u else u,
  1056. if atom v then !*i2rn v else v);
  1057. symbolic procedure TayExp!-minusp e;
  1058. if atom e then minusp e
  1059. else rnminusp!: e;
  1060. symbolic procedure TayExp!-greaterp(a,b);
  1061. TayExp!-lessp(b,a);
  1062. symbolic macro procedure TayExp!-geq x;
  1063. {'not,'TayExp!-lessp . cdr x};
  1064. symbolic procedure TayExp!-lessp(e1,e2);
  1065. if atom e1 and atom e2 then e1<e2
  1066. else !:minusp TayExp!-difference(e1,e2);
  1067. symbolic macro procedure TayExp!-leq x;
  1068. {'not,'TayExp!-greaterp . cdr x};
  1069. symbolic procedure TayExp!-max2(e1,e2);
  1070. if TayExp!-lessp(e1,e2) then e2 else e1;
  1071. symbolic procedure TayExp!-min2(e1,e2);
  1072. if TayExp!-lessp(e1,e2) then e1 else e2;
  1073. symbolic macro procedure Taylor!: u;
  1074. sublis('((plus . TayExp!-plus)
  1075. (plus2 . TayExp!-plus2)
  1076. (difference . TayExp!-difference)
  1077. (minus . TayExp!-minus)
  1078. (times . TayExp!-times)
  1079. (times2 . TayExp!-times2)
  1080. (minusp . TayExp!-minusp)
  1081. (greaterp . TayExp!-greaterp)
  1082. (geq . TayExp!-geq)
  1083. (lessp . TayExp!-lessp)
  1084. (leq . TayExp!-leq)
  1085. (max2 . TayExp!-max2)
  1086. (min2 . TayExp!-min2)),
  1087. cadr u);
  1088. comment Smacros and procedures that are commonly used ;
  1089. symbolic smacro procedure TayFlagsCombine (u, v);
  1090. %
  1091. % Not much for now
  1092. %
  1093. nil;
  1094. symbolic smacro procedure get!-degree dg;
  1095. %
  1096. % Procedure to handle degree parts of Taylor kernels.
  1097. %
  1098. Taylor!: for each n in dg sum n;
  1099. symbolic smacro procedure get!-degreelist dgl;
  1100. for each dg in dgl collect get!-degree dg;
  1101. symbolic smacro procedure invert!-powerlist pl;
  1102. Taylor!:
  1103. for each nl in pl collect
  1104. for each p in nl collect -p;
  1105. symbolic smacro procedure taymultcoeffs (c1, c2);
  1106. %
  1107. % (TayCoeff, TayCoeff) -> TayCoeff
  1108. %
  1109. % multiplies the two coefficients c1,c2.
  1110. % both are of the form (TayPowerList . s.q.)
  1111. % so generate an appropriate degreelist by adding the degrees.
  1112. %
  1113. TayMakeCoeff (add!-degrees (TayCfPl c1, TayCfPl c2),
  1114. multsq (TayCfSq c1, TayCfSq c2));
  1115. symbolic smacro procedure prune!-coefflist(cflist);
  1116. <<while not null cflis and null numr TayCfSq car cflis
  1117. do cflis := cdr cflis;
  1118. cflis>> where cflis := cflist;
  1119. symbolic smacro procedure multintocoefflist(coefflis,sq);
  1120. %
  1121. % (TayCoeffList, s.q.) -> TayCoeffList
  1122. %
  1123. % Multiplies each coefficient in coefflis by the s.q. sq.
  1124. %
  1125. for each p in coefflis collect
  1126. TayMakeCoeff(TayCfPl p,resimp subs2!* multsq(TayCfSq p,sq));
  1127. symbolic smacro procedure subs2coefflist clist;
  1128. for each pp in clist join
  1129. ((if not null numr sq then {TayMakeCoeff(TayCfPl pp,sq)})
  1130. where sq := subs2!* TayCfSq pp);
  1131. symbolic smacro procedure resimpcoefflist clist;
  1132. for each cc in clist collect
  1133. TayMakeCoeff(TayCfPl cc,subs2 resimp TayCfSq cc);
  1134. symbolic smacro procedure resimptaylor u;
  1135. %
  1136. % (TaylorKernel) -> TaylorKernel
  1137. %
  1138. % u is a Taylor kernel, value is the Taylor kernel
  1139. % with coefficients and TayOrig part resimplified
  1140. %
  1141. make!-Taylor!* (
  1142. resimpcoefflist TayCoeffList u,
  1143. TayTemplate u,
  1144. if !*taylorkeeporiginal and TayOrig u
  1145. then resimp TayOrig u else nil,
  1146. TayFlags u);
  1147. symbolic smacro procedure make!-cst!-powerlist tp;
  1148. %
  1149. % (TayTemplate) -> TayPowerList
  1150. %
  1151. % Generates a powerlist for the constant coefficient
  1152. % according to template tp
  1153. %
  1154. for each el in tp collect nzerolist length TayTpElVars el;
  1155. symbolic smacro procedure make!-cst!-coefficient (cst, tp);
  1156. %
  1157. % (s.q., TayTemplate) -> TayCoefficient
  1158. %
  1159. % Generates the constant coefficient cst
  1160. % according to Taylor template tp
  1161. %
  1162. TayMakeCoeff (make!-cst!-powerlist tp, cst);
  1163. symbolic smacro procedure make!-cst!-coefflis (cst, tp);
  1164. %
  1165. % (s.q., TayTemplate) -> TayCoeffList
  1166. %
  1167. % Generates a TayCoeffList with only the constant coefficient cst
  1168. % according to Taylor template tp
  1169. %
  1170. {make!-cst!-coefficient (cst, tp)};
  1171. symbolic smacro procedure cst!-Taylor!* (cst, tp);
  1172. %
  1173. % (s.q., TayTemplate) -> TaylorKernel
  1174. %
  1175. % generates a Taylor kernel with template tp for the constant cst.
  1176. %
  1177. make!-Taylor!* (
  1178. make!-cst!-coefflis (cst, tp), tp, cst, nil);
  1179. comment Predicates;
  1180. symbolic smacro procedure has!-Taylor!* u;
  1181. %
  1182. % (Any) -> Boolean
  1183. %
  1184. % checks if an expression u contains a Taylor kernel
  1185. %
  1186. smember ('Taylor!*, u);
  1187. symbolic smacro procedure Taylor!*p u;
  1188. %
  1189. % (Kernel) -> Boolean
  1190. %
  1191. % checks if kernel u is a Taylor kernel
  1192. %
  1193. eqcar (u, 'Taylor!*);
  1194. symbolic smacro procedure Taylor!-kernel!-sf!-p u;
  1195. %
  1196. % (s.f.) -> Boolean
  1197. %
  1198. % checks if s.f. u is a Taylor kernel
  1199. %
  1200. not domainp u and null red u and lc u = 1
  1201. and ldeg u = 1 and Taylor!*p mvar u;
  1202. symbolic smacro procedure Taylor!-kernel!-sq!-p u;
  1203. %
  1204. % u is a standard quotient,
  1205. % returns t if it is simply a Taylor kernel
  1206. %
  1207. kernp u and Taylor!*p mvar numr u;
  1208. symbolic smacro procedure has!-TayVars(tay,ex);
  1209. %
  1210. % Checks whether ex contains any of the Taylor variables
  1211. % of Taylor kernel tay.
  1212. %
  1213. smemberlp(TayVars tay,ex);
  1214. symbolic procedure Taylor!*!-zerop tay;
  1215. TayCoeffList!-zerop TayCoefflist tay;
  1216. symbolic procedure TayCoeffList!-zerop tcl;
  1217. null tcl
  1218. or null numr TayCfSq car tcl and TayCoeffList!-zerop cdr tcl;
  1219. comment smacros for the generation of unique Taylor kernels;
  1220. symbolic smacro procedure !*tay2f u;
  1221. !*p2f mksp (u, 1);
  1222. symbolic smacro procedure !*tay2q u;
  1223. !*p2q mksp (u, 1);
  1224. comment some procedures for tracing;
  1225. symbolic smacro procedure Taylor!-trace u;
  1226. if !*trtaylor then lpri("Taylor: " . if u and atom u then list u else u);
  1227. symbolic smacro procedure Taylor!-trace!-mprint u;
  1228. if !*trtaylor then mathprint u;
  1229. endmodule;
  1230. end;