taylor.red 50 KB

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