mathml_1.red 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052
  1. module mathml;
  2. % Version 5 August 1999
  3. % Modified by FJW, 22 May 2000
  4. % Modified by Winfried Neun , 1 August 2000
  5. fluid '(atts ch cha char count file!* pvar rdci!* rdelems!* rdlist!*
  6. rdreln!* space safe_atts temp2 unary!* !*mathprint
  7. consts_compl consts_int flagg found_compl found_int consts_mat_int
  8. consts_mat_compl found_mat_compl found_mat_int indent);
  9. %Declaration of some switches.
  10. %_mathml_ allows all output to be printed in mathml.
  11. %_both_ allows all output to be printed in mathml and in normal reduce
  12. %output.
  13. load assist;
  14. load matrix;
  15. global '(f);
  16. global '(!*mathml);
  17. switch mathml;
  18. global '(!*both);
  19. switch both;
  20. global '(!*web);
  21. switch web;
  22. LISP (FILE!*:=nil);
  23. !*mathml:=nil;
  24. !*both:=nil;
  25. !*web:=nil;
  26. off both;
  27. off mathml;
  28. off web;
  29. %Declaration of a series of lists which contain the function to be executed
  30. %when the token (cadr) is found.
  31. %Tokens to be found between <ci></ci> tags.
  32. RDci!*:='
  33. ((!&imaginaryi!; . (consts 'i))
  34. (!&ii!; . (consts 'i))
  35. (!&exponential!; . (consts 'e))
  36. (!&ee!; . (consts 'e))
  37. (!&pi!; . (consts 'p))
  38. (!&differentiald!; . (const 'd))
  39. (!&dd!; . (consts 'd)));
  40. %Tokens to be found between <reln></reln> tags.
  41. RDreln!*:=
  42. '((tendsto . (tendstoRD ))
  43. (eq!/ . (relationRD 'eq))
  44. (neq!/ . (relationRD 'neq))
  45. (lt!/ . (relationRD 'lt))
  46. (gt!/ . (relationRD 'gt))
  47. (geq!/ . (relationRD 'geq))
  48. (leq!/ . (relationRD 'leq))
  49. (in!/ . (inRD ))
  50. (notin!/ . (notinRD ))
  51. (subset!/ . (relationRD 'subset))
  52. (prsubset!/ . (relationRD 'prsubset))
  53. (notprsubset!/ . (notprsubsetRD ))
  54. (notsubset!/ . (notsubsetRD )));
  55. %Tokens to be found between <apply></apply> tags.
  56. RDlist!*:=
  57. '((divide!/ . (divideRD))
  58. (setdiff!/ . ( setdiffRD))
  59. (select!/ . (selectRD))
  60. (transpose!/ . ( transposeRD))
  61. (determinant!/ . ( determinantRD))
  62. (fn . ( applyfnRD))
  63. (union!/ . (unionRD))
  64. (intersect!/ . (intersectionRD))
  65. (implies!/ . ( impliesRD))
  66. (not!/ . ( notRD))
  67. (xor!/ . (xorRD))
  68. (or!/ . (orRD))
  69. (and!/ . (andRD))
  70. (mean!/ . ( meanRD))
  71. (var!/ . ( varRD))
  72. (sdev!/ . ( sdevRD))
  73. (moment!/ . ( momentRD))
  74. (median!/ . ( medianRD))
  75. (sin!/ . ( sinRD))
  76. (sec!/ . ( secRD))
  77. (sinh!/ . ( sinhRD))
  78. (sech!/ . ( sechRD))
  79. (arcsin!/ . ( arcsinRD))
  80. (cos!/ . ( cosRD))
  81. (csc!/ . ( cscRD))
  82. (cosh!/ . ( coshRD))
  83. (csch!/ . ( cschRD))
  84. (arccos!/ . ( arccosRD))
  85. (tan!/ . ( tanRD))
  86. (cot!/ . ( cotRD))
  87. (tanh!/ . ( tanhRD))
  88. (coth!/ . ( cothRD))
  89. (arctan!/ . ( arctanRD))
  90. (abs!/ . ( absRD))
  91. (ln!/ . ( lnRD))
  92. (plus!/ . ( plusRD))
  93. (times!/ . ( timesRD))
  94. (power!/ . ( powerRD))
  95. (exp!/ . ( expRD))
  96. (factorial!/ . ( factorialRD))
  97. (quotient!/ . ( quotientRD))
  98. (max!/ . ( maxRD))
  99. (min!/ . ( minRD))
  100. (minus!/ . ( minusRD))
  101. (rem!/ . (remRD))
  102. (conjugate!/ . ( conjugateRD))
  103. (root!/ . ( rootRD))
  104. (gcd!/ . ( gcdRD))
  105. (log!/ . (logRD))
  106. (int!/ . (intRD))
  107. (sum!/ . ( sumRD))
  108. (limit!/ . (limitRD))
  109. (condition . (conditionRD))
  110. (product!/ . (productRD))
  111. (diff!/ . (diffRD))
  112. (partialdiff!/ . (partialdiffRD)));
  113. RDelems!* :=
  114. '((reln . (relnRD !/reln "</reln>"))
  115. (set . ( setRD !/set "</set>"))
  116. (fn . ( fnRD !/fn "</fn>"))
  117. (declare . ( declareRD !/declare "</declare>"))
  118. (list . ( listRD !/list "</list>"))
  119. (matrix . ( matrixRD !/matrix "</matrix>"))
  120. (cn . ( cnML !/cn "</cn>"))
  121. (ci . ( ciML !/ci "</ci>"))
  122. (lambda . ( lambdaRD !/lambda "</lambda>")));
  123. unary!* :=
  124. '((determinant . (unary determinant))
  125. (transpose . (unary transpose))
  126. (sum . (sum_prodML sum))
  127. (prod . (sum_prodML product))
  128. (df . (dfML nil)) % FJW: (df.(dfML df))
  129. (impart . (complpart impart))
  130. (repart . (complpart repart))
  131. (abs . (unary abs))
  132. (gcd . (n_nary gcd))
  133. (set . (setML set))
  134. (factorial . (unary factorial))
  135. (max . (n_nary max))
  136. (min . (n_nary min))
  137. (cos . (unary cos))
  138. (sin . (unary sin))
  139. (sec . (unary sec))
  140. (cosh . (unary cosh))
  141. (cot . (unary cot))
  142. (coth . (unary coth))
  143. (csch . (unary csch))
  144. (acos . (trigML acos))
  145. (asin . (trigML asin))
  146. (atan . (trigML atan))
  147. (sech . (unary sech))
  148. (sinh . (unary sinh))
  149. (tan . (unary tan))
  150. (tanh . (unary tanh))
  151. (csc . (unary csc))
  152. (quotient . (quotientML nil))
  153. (plus . (n_nary plus))
  154. (times . (n_nary times))
  155. (expt . (n_nary power))
  156. (sqrt . (sqrtML sqrt))
  157. (log . (unary log))
  158. (logb . (log_baseML logb))
  159. (log10 . (log_baseML log10))
  160. (ln . (unary ln))
  161. (eq . (reln eq))
  162. (neq . (reln neq))
  163. (gt . (reln gt))
  164. (lt . (reln lt))
  165. (geq . (reln geq))
  166. (leq . (reln leq))
  167. (union . (sets union))
  168. (intersection . (sets intersection))
  169. (in . (reln in))
  170. (notin . (reln notin))
  171. (subset . (reln subset))
  172. (prsubset . (reln prsubset))
  173. (notsubset . (reln notsubset))
  174. (notprsubset . (reln notprsubset))
  175. (setdf . (sets setdf))
  176. (arbcomplex . (printsub2cadr arbcomplex))
  177. (arbint . (printsub2cadr arbint))
  178. (mat . (matrixML nil))
  179. (minus . (minusML nil))
  180. (int . (integralML nil))
  181. (equal . (equalML nil))
  182. (list . (listML nil)));
  183. %The next three functions are the lexer. When called they returns the next
  184. %mathml token in the input stream.
  185. symbolic procedure lex();
  186. begin scalar token;
  187. token:=nil;
  188. if atts neq nil then safe_atts:=atts;
  189. atts:=nil;
  190. if ch neq !$EOF!$ then <<
  191. if ch=space then while (ch:=readch())=space do
  192. else
  193. if ch='!< then char:=get_token()
  194. else char:=get_content();
  195. if char neq nil then
  196. << count:=count+1;
  197. token:=reverse char;
  198. char:=butes(token);
  199. %By decomenting the following line, the tokens read in are one by one
  200. %printed onto the output stream.
  201. % print char;
  202. attributes(char,token)>>
  203. else lex(); >>
  204. end;
  205. symbolic procedure get_token();
  206. begin scalar d;
  207. d:=();
  208. while (ch:=readch()) neq '!> do d:=cons(ch,d);
  209. return cons('!$,d);
  210. end;
  211. symbolic procedure get_content();
  212. begin scalar d;
  213. d:=();
  214. while (ch:=readch()) neq '!< AND ch neq !$EOF!$
  215. do
  216. if ch neq space AND id2int(ch)>10 then
  217. d:=cons(ch,d);
  218. if d neq nil then d:=cons('!$,d);
  219. return d;
  220. end;
  221. %This function will search the list of attributes _att_ for the attribute
  222. %named _key_
  223. symbolic procedure search_att( att, key);
  224. begin scalar l, stop,d;
  225. l:=nil;
  226. d:=();
  227. stop:=0;
  228. att:= find(att, key);
  229. if att neq '(stop) then
  230. <<
  231. while (car att='! ) do att:=cdr att;
  232. if (car att = '!=) then
  233. <<
  234. att:=cdr att;
  235. while (car att='! ) do att:=cdr att;
  236. if (car att='!") then
  237. << att:=cdr att;
  238. while (stop=0) do
  239. << d:=cons(car att, d);
  240. att:=cdr att;
  241. if (car att='! ) OR (car att='!$) then stop:=1
  242. >>
  243. >>
  244. else
  245. while (stop=0) do
  246. << d:=cons(car att, d);
  247. att:=cdr att;
  248. if (car att='! ) OR (car att='!$) then stop:=1
  249. >>
  250. >>
  251. else
  252. errorML(compress key,1);
  253. if car d='!" then d:=cdr d;
  254. return reverse d
  255. >>
  256. end;
  257. symbolic procedure find(fatt, fkey);
  258. begin;
  259. return if fkey= '() then if fatt neq nil then cdr fatt else '(stop)
  260. else
  261. find(member(car fkey, fatt), cdr fkey);
  262. end;
  263. symbolic procedure attributes(a,b);
  264. begin scalar l;
  265. l:=length a;
  266. for a:=1:l do b:=cdr b;
  267. while (car b='! ) do b:=cdr b;
  268. if b neq '(!$) then atts:=b;
  269. end;
  270. symbolic procedure butes( str );
  271. %Removes all attributes to a token.
  272. begin cha;
  273. cha:=car str;
  274. return if (cha='! OR cha='!$) then <<'(); >>
  275. else cons(car str, butes cdr str);
  276. end;
  277. %This is the MAIN function. It is given the name of a file which contains
  278. %the mathml input. It launches the program by calling parseML().
  279. symbolic procedure mml(ff);
  280. begin;
  281. FILE!*:=t;
  282. ff:= open(ff, 'input);
  283. ff:= rds(ff);
  284. parseML();
  285. close rds ff;
  286. FILE!*:=nil;
  287. end;
  288. %This function starts the parsing mechanism, which is a recursive descent
  289. %parsing.
  290. symbolic procedure parseML();
  291. begin scalar res, vswitch;
  292. res:=nil;
  293. vswitch:=nil;
  294. % FLUID '(safe_atts char ch atts count temp space temp2);
  295. space:=int2id(32);
  296. count:=0;
  297. ch:=readch();
  298. temp2:=nil;
  299. lex();
  300. if char='(m a t h) then
  301. res:=mathML()
  302. else errorML("<math>",2);
  303. lex();
  304. if char='(!/ m a t h) then
  305. terpri()
  306. else errorML("</math>",19);
  307. return algebraic res;
  308. end;
  309. %The two next functions differ in that one of them parses from the next
  310. %token onwards, and the other one from the actual token onwards.
  311. symbolic procedure mathML();
  312. begin scalar a;
  313. a:=nil;
  314. lex();
  315. return sub_math();
  316. end;
  317. symbolic procedure mathML2();
  318. begin scalar a;
  319. a:=nil;
  320. return sub_math();
  321. end;
  322. %Parses all tokens which legally follow a mathml token.
  323. symbolic procedure sub_math();
  324. begin scalar a,aa;
  325. if char='(a p p l y)
  326. then <<a := applyML();
  327. if char neq '(!/ a p p l y) then errorML("</apply>",3)>>
  328. else if char='(v e c t o r)
  329. then <<a := vectorRD();
  330. if char neq '(!/ v e c t o r)
  331. then errorML("</vector>",2)>>
  332. else if (aa := assoc(compress!* char, RDelems!*))
  333. then <<a := apply(cadr aa, '() );
  334. if compress!* char neq third aa
  335. then errorML(third cdr aa, 2)>>;
  336. return a
  337. end;
  338. symbolic procedure compress!* u;
  339. begin scalar x;
  340. if digit car u then return compress u;
  341. for each j in u do
  342. if j eq '!/ or j eq '!- or j eq '!; or j eq '!.
  343. then x := j . '!! . x
  344. else x := j . x;
  345. return intern compress reversip x
  346. end;
  347. %The next two functions parse the <cn> and <ci> tokens and extracts its
  348. %content to be used by the function calling it. It will have different
  349. %behaviours according to the type of the <cn> data.
  350. symbolic procedure cnML();
  351. begin scalar type, sep, tt,aa;
  352. %Must check that what is being returned is an int.
  353. type:=nil; sep:=nil;
  354. type:=search_att(atts, '(t y p e));
  355. lex();
  356. tt := char;
  357. lex();
  358. if type='(c o n s t a n t) then
  359. <<
  360. if (aa:=assoc(intern compress tt, RDci!*)) then
  361. return apply(first cdr aa, rest cdr aa) >>;
  362. if IDP compress tt then errorML(compress tt, 16);
  363. if type=nil then return compress tt;
  364. if member(type, '((r e a l) (i n t e g e r))) neq nil then
  365. return compress tt;
  366. if member(type, '((r a t i o n a l) (c o m p l e x !- c a r t e s i a n)
  367. (c o m p l e x !- p o l a r))) neq nil then
  368. << sep:=sepRD();
  369. if type='(r a t i o n a l) then <<lex();return alg_quotient(compress tt, sep)>>
  370. else
  371. if type='(c o m p l e x !- c a r t e s i a n) then
  372. << lex();return comp2(compress tt, sep) >>else
  373. if type='(c o m p l e x !- p o l a r) then
  374. <<sep:= po2ca(compress tt, sep);
  375. <<lex();return comp2(car sep, cadr sep)>> >>
  376. >>;
  377. end;
  378. symbolic procedure ciML();
  379. begin scalar test, type,aa, tt;
  380. aa:=nil; type:=nil; test:=nil;
  381. type:=search_att(atts, '(t y p e));
  382. lex();
  383. tt := char;
  384. lex();
  385. << test:=compress tt;
  386. if NUMBERP test then errorML(test, 4);
  387. test:=intern test;
  388. return test>>
  389. end;
  390. %returns the algebraic value of the constant values.
  391. algebraic procedure consts(c);
  392. begin;
  393. if c=i then return i;
  394. if c=d then return d;
  395. if c=e then return e;
  396. if c=p then return pi;
  397. end;
  398. %Constructs a complex number.
  399. algebraic procedure comp2(a,b);
  400. begin;
  401. return a+b*i;
  402. end;
  403. %Returns the two values separated by a <sep/> tag.
  404. symbolic procedure sepRD();
  405. begin scalar p1, p2;
  406. p1:=nil; p2:=nil;
  407. if char neq '(s e p !/) then errorML("<sep/>",2);
  408. lex();
  409. p2:=compress char;
  410. return p2;
  411. end;
  412. %Creates a vector by using function matrix_row.
  413. symbolic procedure vectorRD();
  414. begin scalar a;
  415. a:=nil;
  416. a:=matrixrowRD();
  417. a:=lisp aeval list('mat, a);
  418. return a;
  419. end;
  420. %The following functions construct the matrix from the mathml information.
  421. symbolic procedure matrixRD();
  422. begin scalar b1, b2, stop;
  423. stop:=0;
  424. b1:='();
  425. b2:=nil;
  426. while stop=0 do
  427. <<
  428. lex();
  429. if char='(m a t r i x r o w) then
  430. <<b2:=matrixrowRD();
  431. if b1 neq nil then b1:=append(b1, list b2)
  432. else b1:=list b2;
  433. if char neq '(!/ m a t r i x r o w) then
  434. errorML("</matrixrow>",2)>>
  435. else stop:=1
  436. >>;
  437. return aeval cons ('mat ,b1);
  438. end;
  439. symbolic procedure matrixrowRD();
  440. begin scalar a;
  441. a:=nil;
  442. a:=mathML();
  443. return if a=nil then nil
  444. else cons(a, matrixrowRD());
  445. end;
  446. %returns a lambda function constructed from the information supplied.
  447. symbolic procedure lambdaRD();
  448. begin scalar b1, b2;
  449. lex();
  450. b1:=bvarRD();
  451. b1:=car b1;
  452. b2:=mathML();
  453. lex();
  454. return algebraic( (lambda b1; b2) b1 );
  455. end;
  456. %returns a set constructed from the information supplied.
  457. symbolic procedure setRD();
  458. begin scalar setvars;
  459. atts:='(t y p e != s e t !$);
  460. setvars:= cons('list,stats_getargs());
  461. setvars:=cons(car setvars, norepeat(cdr setvars));
  462. return setvars;
  463. end;
  464. %This function will keep one copy only of any repeating elements
  465. symbolic procedure norepeat(args);
  466. begin;
  467. return if args=nil then nil else
  468. if length args=1 then list car args
  469. else append(list car args, norepeat(delall(car args, cdr args)));
  470. end;
  471. %This function will delete all occurences of element x in list l
  472. symbolic procedure delall(x,l);
  473. if l=nil then nil
  474. else if x=car l then delall(x, cdr l)
  475. else append(list car l ,delall(x, cdr l));
  476. %returns a list constructed from the information supplied.
  477. symbolic procedure listRD();
  478. begin scalar setvars, lorder, tmp;
  479. lorder:=search_att(atts, '(o r d e r));
  480. atts:='(t y p e != l i s t !$);
  481. setvars:= cons('list,stats_getargs());
  482. tmp := setvars;
  483. if lorder='(l e x i c o g r a p h i c) then
  484. setvars:=algebraic sortlist (setvars, lexog);
  485. if lorder='(n u m e r i c) then
  486. setvars:=algebraic sortlist (setvars, numer)
  487. else
  488. setvars:=algebraic sortlist (setvars, pred);
  489. if setvars = nil then setvars:= tmp;
  490. return setvars;
  491. end;
  492. %Defines the predicate function used by function _sortlist_. Sortlist comes
  493. %from package assist, and its documentation can be found in assist's
  494. %documentation
  495. %This one will sort all elements in numerical and alphanumerical order
  496. symbolic procedure pred(u,v);
  497. begin;
  498. return if NUMBERP u and NUMBERP v then <<if u<v then t>> else
  499. if IDP u and IDP v then <<if id2int(u) < id2int(v) then t>>
  500. else if NUMBERP u and IDP v then <<if u<id2int(v) then t>> else
  501. if IDP u and NUMBERP v then <<if id2int(u)<v then t>>;
  502. end;
  503. %This one sorts in alphanumerical order
  504. symbolic procedure lexog(u,v);
  505. begin;
  506. return if IDP u and IDP v then <<if id2int(u) < id2int(v) then t>>
  507. else t;
  508. end;
  509. %This one sorts in numerical order
  510. symbolic procedure numer(u,v);
  511. begin;
  512. return if NUMBERP u and NUMBERP v then <<if u<v then t>>
  513. else t;
  514. end;
  515. %Makes the next token in the inputstream an operator.
  516. symbolic procedure fnRD();
  517. begin scalar b1;
  518. lex();
  519. if char neq '(c i) then errorML(compress char,20)
  520. else b1:= mathML2();
  521. if ATOM b1 then algebraic operator b1;
  522. lex();
  523. return b1;
  524. end;
  525. %Reads the declare construct and sets the value of the given variable to
  526. %the given value.
  527. symbolic procedure declareRD();
  528. begin scalar b1, b2, flagg, at;
  529. at:=atts;
  530. flagg := nil;
  531. b1:=mathML();
  532. clear b1;
  533. clear reval b1;
  534. lex();
  535. if at neq nil then
  536. put(b1, 'type, search_att(at,'(t y p e)));
  537. if search_att(at, '(t y p e)) = '(v e c t o r) then
  538. flagg:=t;
  539. if char='(!/ d e c l a r e) then return nil;
  540. b2 :=mathML2();
  541. if get(b1, 'type)='(f n) then
  542. << algebraic operator b1>>;
  543. if flagg = t then setk(b1, b2)
  544. else algebraic set(b1, b2);
  545. lex();
  546. return nil;
  547. end;
  548. %This function will determine if the next token is a valid token following
  549. %an apply token. It then calls the appropriate function if succesful.
  550. symbolic procedure applyML();
  551. begin scalar aa;
  552. lex();
  553. if (aa := assoc(compress!* char, RDlist!*))
  554. then return apply(first cdr aa, rest cdr aa)
  555. else if char='(i d e n t !/) or char='(c o m p o s e !/)
  556. then return nil
  557. else if char='(i n v e r s e !/) then return t
  558. else errorML(compress!* char, 17)
  559. end;
  560. %Reads the next two elements and returns their setdifference.
  561. symbolic procedure setdiffRD();
  562. begin scalar b1, b2;
  563. b1:=mathML();
  564. b2:=mathML();
  565. lex();
  566. if b1=reval b1 and b2=reval b2 then return list('setdiff,b1, b2)
  567. else
  568. if b1=reval b1 then return list('setdiff, b1, reval b2) else
  569. if b2=reval b2 then return list('setdiff, reval b1, b2) else
  570. return append(list('set), setdiff(reval b1, reval b2));
  571. end;
  572. %Reads through a select construct and acts accordingly.
  573. symbolic procedure selectRD();
  574. begin scalar a1, res;
  575. a1:=stats_getargs();
  576. if caar a1='mat then res:=mat_select(a1);
  577. if caar a1='list then res:=list_select(a1);
  578. if ATOM res then return res;
  579. return cons('list, res);
  580. end;
  581. symbolic procedure mat_select(a1);
  582. begin
  583. if length car a1=2 then return nth(cadar a1, cadr a1)
  584. else
  585. if length a1=2 then return nth(cdar a1, cadr a1);
  586. if length a1=3 then return nth(nth(cdar a1, caddr a1), cadr a1);
  587. end;
  588. symbolic procedure list_select(a1);
  589. begin scalar b1;
  590. b1:=cdar a1;
  591. return nth(b1, cadr a1);
  592. end;
  593. %Returns the transpose of the element contained in the transpose tags.
  594. symbolic procedure transposeRD();
  595. begin scalar a, res;
  596. a:=mathML();
  597. res:=algebraic(tp a);
  598. lex();
  599. return res;
  600. end;
  601. %Returns the determinant of the given element.
  602. symbolic procedure determinantRD();
  603. begin scalar a, res;
  604. a:=mathML();
  605. res:=alg_det a;
  606. lex();
  607. return res;
  608. end;
  609. algebraic procedure alg_det(a);
  610. begin;
  611. return det a;
  612. end;
  613. %Takes the given function name, makes it an operator, and then
  614. %applies it to the arguments specified in the mathml input.
  615. symbolic procedure applyfnRD();
  616. begin scalar b1, b2, c1;
  617. b1:=nil; b2:=nil; c1:=nil;
  618. b1:=fnRD();
  619. b2:=stats_getargs();
  620. b2:=cons(b1, b2);
  621. c1:=algebraic b2;
  622. return c1;
  623. end;
  624. %Returns the union of the elements specified.
  625. symbolic procedure unionRD();
  626. begin scalar b1, a1, a2,type,res;
  627. b1:=stats_getargs();
  628. a1:=car b1;
  629. a2:=cadr b1;
  630. if PAIRP a1 AND PAIRP a2 then <<
  631. type := car a1;
  632. a1:=cons('list, eval_list cdr a1);
  633. a2:=cons('list, eval_list cdr a2);
  634. res:=algebraic union(a1,a2);
  635. >>
  636. else <<
  637. type := 'list;
  638. res := cons('list,cons(a1,list a2));
  639. >>;
  640. return cons(type, cdr res);
  641. end;
  642. %Returns the intersection of the elements specified.
  643. symbolic procedure intersectionRD();
  644. begin scalar b1, a1, a2,type,res;
  645. b1:=stats_getargs();
  646. a1:=car b1;
  647. a2:=cadr b1;
  648. if PAIRP a1 AND PAIRP a2 then <<
  649. type := car a1;
  650. a1:=cons('list, eval_list cdr a1);
  651. a2:=cons('list, eval_list cdr a2);
  652. res:=algebraic intersect(a1,a2);
  653. >>
  654. else <<
  655. type := 'list;
  656. res := cons('list,cons(a1,list a2));
  657. >>;
  658. return cons(type, cdr res);
  659. end;
  660. %Takes all the arguments in a list, and forces an evaluation on them if they can be
  661. %evaluated.
  662. symbolic procedure eval_list(args);
  663. begin;
  664. return if args=nil then nil
  665. else cons(reval car args, eval_list(cdr args));
  666. end;
  667. %Takes all the arguments in a list of sets, and evaluates them if they can
  668. %be evaluated.
  669. symbolic procedure eval_list_sets(args);
  670. begin scalar ab;
  671. return if args=nil then nil
  672. else <<if PAIRP reval car args then
  673. <<
  674. if car reval car args='list then
  675. ab:=cons('set, cdr reval car args)>>
  676. else ab:=reval car args;
  677. cons(ab, eval_list_sets(cdr args))>>;
  678. end;
  679. %Sets global variable temp2 to 'stop if an evaluatable element is found in
  680. %list args.
  681. symbolic procedure constants(args);
  682. begin scalar b1;
  683. if args neq nil then b1:=car args;
  684. return if args=nil then nil
  685. else <<if b1=reval b1 AND IDP b1 OR PAIRP b1 then temp2:='stop
  686. else constants(cdr args)>>;
  687. end;
  688. %Return boolean values of the arguments given.
  689. symbolic procedure notRD();
  690. begin scalar a;
  691. a:=mathML();
  692. lex();
  693. return not(reval a);
  694. end;
  695. symbolic procedure impliesRD();
  696. begin scalar a1,b1,c1;
  697. a1:=mathML();
  698. b1:=mathML();
  699. if b1='false then b1:=nil;
  700. if a1='false then a1:=nil;
  701. if reval a1 AND not reval b1 then c1:=nil
  702. else c1:=t;
  703. lex();
  704. return c1;
  705. end;
  706. symbolic procedure andRD();
  707. begin scalar a;
  708. a:=stats_getargs();
  709. a:=subst(nil, 'false, a);
  710. a:=and2RD(a);
  711. return a;
  712. end;
  713. symbolic procedure and2RD(args);
  714. begin
  715. return if length args=1 then reval car args
  716. else and(reval car args, and2RD(cdr args));
  717. end;
  718. symbolic procedure orRD();
  719. begin scalar a;
  720. a:=stats_getargs();
  721. a:=subst(nil, 'false, a);
  722. a:=or2RD(a);
  723. return a;
  724. end;
  725. symbolic procedure or2RD(args);
  726. begin
  727. return if length args=1 then reval car args
  728. else or(reval car args, or2RD(cdr args));
  729. end;
  730. symbolic procedure xorRD();
  731. begin scalar a;
  732. a:=stats_getargs();
  733. a:=subst(nil, 'false, a);
  734. a:=xor2RD(a);
  735. return a;
  736. end;
  737. symbolic procedure xor2RD(args);
  738. begin
  739. return if args=() then nil
  740. else alg_xor(reval car args, xor2RD(cdr args));
  741. end;
  742. symbolic procedure alg_xor(a,b);
  743. begin;
  744. return and(or(a,b),not(and(a,b)));
  745. end;
  746. %All defined trigonometric functions.
  747. algebraic procedure sinRD();
  748. begin scalar a;
  749. a:=symbolic mathML();
  750. symbolic lex();
  751. return sin(a);
  752. end;
  753. algebraic procedure secRD();
  754. begin scalar a;
  755. a:=symbolic mathML();
  756. symbolic lex();
  757. return sec(a);
  758. end;
  759. algebraic procedure sinhRD();
  760. begin scalar a;
  761. a:=symbolic mathML();
  762. symbolic lex();
  763. return sinh(a);
  764. end;
  765. algebraic procedure sechRD();
  766. begin scalar a;
  767. a:=symbolic mathML();
  768. symbolic lex();
  769. return sech(a);
  770. end;
  771. algebraic procedure arcsinRD();
  772. begin scalar a;
  773. a:=symbolic mathML();
  774. symbolic lex();
  775. return asin(a);
  776. end;
  777. algebraic procedure cosRD();
  778. begin scalar a;
  779. a:=symbolic mathML();
  780. symbolic lex();
  781. return cos(a);
  782. end;
  783. algebraic procedure cscRD();
  784. begin scalar a;
  785. a:=symbolic mathML();
  786. symbolic lex();
  787. return csc(a);
  788. end;
  789. algebraic procedure coshRD();
  790. begin scalar a;
  791. a:=symbolic mathML();
  792. symbolic lex();
  793. return cosh(a);
  794. end;
  795. algebraic procedure cschRD();
  796. begin scalar a;
  797. a:=symbolic mathML();
  798. symbolic lex();
  799. return csch(a);
  800. end;
  801. algebraic procedure arccosRD();
  802. begin scalar a;
  803. a:=symbolic mathML();
  804. symbolic lex();
  805. return acos(a);
  806. end;
  807. algebraic procedure tanRD();
  808. begin scalar a;
  809. a:=symbolic mathML();
  810. symbolic lex();
  811. return tan(a);
  812. end;
  813. algebraic procedure cotRD();
  814. begin scalar a;
  815. a:=symbolic mathML();
  816. symbolic lex();
  817. return cot(a);
  818. end;
  819. algebraic procedure tanhRD();
  820. begin scalar a;
  821. a:=symbolic mathML();
  822. symbolic lex();
  823. return tanh(a);
  824. end;
  825. algebraic procedure cothRD();
  826. begin scalar a;
  827. a:=symbolic mathML();
  828. symbolic lex();
  829. return coth(a);
  830. end;
  831. algebraic procedure arctanRD();
  832. begin scalar a;
  833. a:=symbolic mathML();
  834. symbolic lex();
  835. return atan(a);
  836. end;
  837. %Reads the condition tag.
  838. symbolic procedure conditionRD();
  839. begin scalar a;
  840. lex();
  841. if char='(r e l n) then a:=relnRD()
  842. else a:=mathML();
  843. lex();
  844. return a;
  845. end;
  846. %This function will read all legal tags following the <reln> tag.
  847. symbolic procedure relnRD();
  848. begin scalar a,aa;
  849. lex();
  850. if (aa := assoc(compress!* char, RDreln!*))
  851. then a := apply(first cdr aa, rest cdr aa)
  852. else errorML(compress!* char, 18);
  853. return if a=t then t else if null a then 'false else a;
  854. end;
  855. symbolic procedure relationRD( type );
  856. begin scalar args,a;
  857. args:=stats_getargs();
  858. if type='(quote eq) then <<a:= alg_eq(args)>> else
  859. if type='(quote neq) then <<a:= alg_neq(args)>> else
  860. if type='(quote lt) then <<a:= alg_lt(args)>> else
  861. if type='(quote gt) then <<a:= alg_gt(args)>> else
  862. if type='(quote subset) then <<a:=subsetRD(args)>> else
  863. if type='(quote prsubset) then <<a:=prsubsetRD(args)>> else
  864. if type='(quote geq) then <<a:= alg_geq(args)>> else
  865. if type='(quote leq) then <<a:= alg_leq(args)>>;
  866. return if a=t then t
  867. else if a=nil then 'false else a;
  868. end;
  869. %The following functions do all the necessay actions in order to evaluate
  870. %what should be by the tags.
  871. symbolic procedure notsubsetRD();
  872. begin scalar b1, b2;
  873. b1:=mathML();
  874. b2:=mathML();
  875. lex();
  876. if b1=reval b1 AND b2=reval b2 then
  877. return list('notsubset, b1, b2);
  878. if b1= reval b1 then
  879. return list('notsubset, b1,cons ('set, cdr reval b2));
  880. if b2= reval b2 then
  881. return list('notsubset, cons('set,cdr reval b1), b2);
  882. if intersection(cdr reval b1,cdr reval b2)=nil then
  883. return t
  884. else
  885. return nil;
  886. end;
  887. symbolic procedure notprsubsetRD();
  888. begin scalar b1, b2;
  889. b1:=mathML();
  890. b2:=mathML();
  891. lex();
  892. if b1=reval b1 AND b2=reval b2 then
  893. return list('notprsubset, b1, b2);
  894. if b1= reval b1 then
  895. return list('notprsubset, b1,cons('set, cdr reval b2));
  896. if b2= reval b2 then
  897. return list('notprsubset, cons('set,cdr reval b1), b2);
  898. if reval b1 = reval b2 then return t;
  899. if intersection(cdr reval b1,cdr reval b2)=nil then return t else
  900. return nil;
  901. end;
  902. symbolic procedure subsetRD(sets);
  903. begin scalar args,val;
  904. args:=sets;
  905. val:=t;
  906. while (length args > 1) do
  907. << if NUMBERP reval car args then
  908. errorML(reval car args,5);
  909. if car args = reval car args OR cadr args = reval cadr args then
  910. << args:='();
  911. val:=cons('subset, eval_list_sets(sets))>>
  912. else
  913. << val:=AND(val, alg_subset(reval car args, reval cadr args));
  914. args:=cdr args >>
  915. >>;
  916. return val;
  917. end;
  918. symbolic procedure alg_subset(a,b);
  919. begin;
  920. if a=b then return t
  921. else
  922. if setdiff(a,b)=nil then return t else return nil;
  923. end;
  924. symbolic procedure prsubsetRD(sets);
  925. begin scalar args, val;
  926. val:=t;
  927. while (length args > 1) do
  928. << if car args = reval car args OR cadr args = reval cadr args then
  929. << args:='();
  930. val:=cons('prsubset, eval_list_sets(sets))>>
  931. else
  932. << val:=AND(val, alg_prsubset(reval car args, reval cadr args));
  933. args:=cdr args >> >>;
  934. return val;
  935. end;
  936. symbolic procedure alg_prsubset(a,b);
  937. begin;
  938. if setdiff(a,b)=nil then return t else return nil;
  939. end;
  940. symbolic procedure inRD();
  941. begin scalar b1,b2;
  942. b1:= mathML();
  943. b2:= mathML();
  944. lex();
  945. if b2 = reval b2 AND ATOM b2 then
  946. <<
  947. if b2='n then <<if FIXP b1 then return t else return nil>>;
  948. if b2='r then <<if NUMBERP b1 then return t else return nil>>;
  949. return list('in, reval b1, b2)
  950. >>;
  951. if MEMBER(reval b1,reval b2) neq nil then return t
  952. else return nil;
  953. end;
  954. symbolic procedure notinRD();
  955. begin scalar b1,b2;
  956. b1:= mathML();
  957. b2:= mathML();
  958. lex();
  959. if b2 = reval b2 AND ATOM b2 then
  960. <<
  961. if b2='N then if FIXP b1 then return nil else return nil;
  962. if b2='R then if NUMBERP b1 then return nil else return nil;
  963. return list('notin, reval b1, b2)>>;
  964. if MEMBER(reval b1,reval b2) neq nil then return nil
  965. else return t;
  966. end;
  967. symbolic procedure alg_eq(args);
  968. begin;
  969. constants(args);
  970. return alg_eq2 eval_list args;
  971. end;
  972. symbolic procedure alg_eq2(args);
  973. begin;
  974. return if length args=1 then t
  975. else if (reval car args eq reval cadr args) then
  976. alg_eq2(cdr args);
  977. end;
  978. symbolic procedure alg_neq(args);
  979. begin;
  980. constants(args);
  981. return alg_neq2(eval_list(args));
  982. end;
  983. symbolic procedure alg_neq2(args);
  984. begin;
  985. return if length args=1 then t
  986. else if (reval car args neq reval cadr args) then
  987. alg_neq2(cdr args);
  988. end;
  989. symbolic procedure alg_lt(args);
  990. begin;
  991. constants(args);
  992. if temp2='stop then
  993. <<temp2:=nil; return append(list 'lt, eval_list(args))>>
  994. else return alg_lt2(eval_list(args));
  995. end;
  996. symbolic procedure alg_lt2(args);
  997. begin;
  998. return if length args=1 then t
  999. else
  1000. if (NUMBERP reval car args AND NUMBERP reval cadr args )then
  1001. <<if (reval car args < reval cadr args) then
  1002. alg_lt2(cdr args)
  1003. else nil>>
  1004. else errorML("",6);
  1005. end;
  1006. symbolic procedure alg_gt(args);
  1007. begin;
  1008. constants(args);
  1009. if temp2='stop then
  1010. <<temp2:=nil; return append(list 'gt, eval_list(args))>>
  1011. else return alg_gt2(eval_list(args));
  1012. end;
  1013. symbolic procedure alg_gt2(args);
  1014. begin;
  1015. return if length args=1 then t
  1016. else
  1017. if (NUMBERP reval car args AND NUMBERP reval cadr args )then
  1018. <<if (reval car args > reval cadr args) then
  1019. alg_gt2(cdr args)
  1020. else nil>>
  1021. else errorML("",6);
  1022. end;
  1023. symbolic procedure alg_geq(args);
  1024. begin;
  1025. constants(args);
  1026. if temp2='stop then
  1027. <<temp2:=nil; return append(list 'g_eq, eval_list(args))>>
  1028. else return alg_geq2(eval_list(args));
  1029. end;
  1030. symbolic procedure alg_geq2(args);
  1031. begin;
  1032. return if length args=1 then t
  1033. else
  1034. if (NUMBERP reval car args AND NUMBERP reval cadr args )then
  1035. <<if (reval car args >= reval cadr args) then
  1036. alg_geq2(cdr args)
  1037. else nil>>
  1038. else errorML("",6);
  1039. end;
  1040. symbolic procedure alg_leq(args);
  1041. begin;
  1042. constants(args);
  1043. if temp2='stop then
  1044. <<temp2:=nil; return append(list 'l_eq, eval_list(args))>>
  1045. else return alg_leq2(eval_list(args));
  1046. end;
  1047. symbolic procedure alg_leq2(args);
  1048. begin;
  1049. return if length args=1 then t
  1050. else
  1051. if (NUMBERP reval car args AND NUMBERP reval cadr args )then
  1052. <<if (reval car args <= reval cadr args) then
  1053. alg_leq2(cdr args)
  1054. else nil>>
  1055. else errorML("",6);
  1056. end;
  1057. %Interprets the <tendsto> tag when used in the <limit> tag.
  1058. symbolic procedure tendstoRD();
  1059. begin scalar attr, arg1 ,arg2;
  1060. if intersection(atts, '(t y p e)) neq nil then
  1061. attr:=search_att(atts, '(t y p e))
  1062. else attr:=nil;
  1063. arg1:=mathML();
  1064. arg2:=mathML();
  1065. lex();
  1066. return list (attr,arg2);
  1067. end;
  1068. %Returns the limit of the information given. Uses the Reduce package
  1069. %LIMITS.
  1070. symbolic procedure limitRD();
  1071. begin scalar var, condi, low, exp;
  1072. lex();
  1073. if char='(b v a r) then
  1074. << var:=bvarRD();
  1075. if eqn(cadr var,1) then var:=car var
  1076. else
  1077. errorML("<degree>",8);
  1078. lex()>>
  1079. else var:=nil;
  1080. if char='(l o w l i m i t) then
  1081. << low:=lowlimitRD();
  1082. lex()>>
  1083. else if char='(c o n d i t i o n) then
  1084. << condi:=conditionRD();
  1085. if char neq '(!/ c o n d i t i o n) then
  1086. errorML("</condition>",2);
  1087. lex()>>
  1088. else condi:=nil;
  1089. exp:=mathML2();
  1090. lex();
  1091. if condi=nil then
  1092. return alg_limit(exp, var, low, 'norm);
  1093. if low=nil then
  1094. if car condi='(a b o v e) then
  1095. return alg_limit(exp, var, cadr condi, 'plus)
  1096. else return alg_limit(exp, var, cadr condi, 'min);
  1097. end;
  1098. algebraic procedure alg_limit(exp, var, tendto, type);
  1099. begin;
  1100. if type='norm then return limit(exp, var, tendto);
  1101. if type='plus then return limit!+(exp,var,tendto);
  1102. if type='min then return limit!-(exp,var,tendto);
  1103. end;
  1104. %Returns the sum.
  1105. symbolic procedure sumRD();
  1106. begin scalar svar, low, upper, express, res;
  1107. svar:=nil; low:=nil; upper:=nil; express:=nil; res:=nil;
  1108. lex();
  1109. if char='(b v a r) then
  1110. <<svar:=bvarRD();
  1111. if eqn(cadr svar,1) then svar:=car svar
  1112. else
  1113. errorML("<degree>",7);
  1114. lex()>>
  1115. else errorML("<bvar>",9);
  1116. if char='(l o w l i m i t) then
  1117. << low:=lowlimitRD();
  1118. lex();
  1119. if char='(u p l i m i t) then
  1120. << upper:=upperlimitRD();
  1121. lex()>>
  1122. else errorML("<uplimit>",10) >>
  1123. else if char='(i n t e r v a l) then
  1124. << res:=intervalRD();
  1125. lex();
  1126. low:=car res;
  1127. upper:=cadr res >>
  1128. else errorML("<lowlimit> or <interval>",11);
  1129. express:=mathML2();
  1130. lex();
  1131. return algebraic sum(express, svar, low, upper);
  1132. end;
  1133. algebraic procedure alg_sum( low, upper, formu);
  1134. begin scalar temp,var2;
  1135. algebraic;
  1136. temp:=0;
  1137. var2:=symbolic svar;
  1138. for tt:=low:upper do
  1139. << set(var2,tt);
  1140. temp:=temp+formu;
  1141. clear symbolic svar;
  1142. var2:=symbolic svar>>;
  1143. symbolic;
  1144. return temp;
  1145. end;
  1146. %Returns the product.
  1147. symbolic procedure productRD();
  1148. begin scalar pvar, low, upper, pexpress, res;
  1149. lex();
  1150. if char='(b v a r) then
  1151. <<pvar:=bvarRD();
  1152. if eqn(cadr pvar,1) then pvar:=car pvar
  1153. else
  1154. errorML("<degree>",12);
  1155. lex()>>
  1156. else errorML("<bvar>",9);
  1157. if char='(l o w l i m i t) then
  1158. << low:=lowlimitRD();
  1159. lex();
  1160. if char='(u p l i m i t) then
  1161. << upper:=upperlimitRD();
  1162. lex()>>
  1163. else errorML("<uplimit>",10)>>
  1164. else if char='(i n t e r v a l) then
  1165. << res:=intervalRD();
  1166. lex();
  1167. low:=car res;
  1168. upper:=cadr res >>
  1169. else errorML("<lowlimit> or <interval>",11);
  1170. pexpress:=mathML2();
  1171. lex();
  1172. return algebraic prod(pexpress, pvar, low, upper);
  1173. end;
  1174. algebraic procedure alg_prod( low, upper, formu);
  1175. begin scalar temp,var2;
  1176. algebraic;
  1177. temp:=1;
  1178. var2:=symbolic pvar;
  1179. for tt:=low:upper do
  1180. << set(var2,tt);
  1181. temp:=temp*formu;
  1182. clear symbolic pvar;
  1183. var2:=symbolic pvar>>;
  1184. symbolic;
  1185. return temp;
  1186. end;
  1187. %Returns the partial derivative.
  1188. symbolic procedure partialdiffRD();
  1189. begin scalar res, bvar, express;
  1190. lex();
  1191. bvar:=getargsRD();
  1192. express:=mathML2();
  1193. lex();
  1194. res:=differentiate(express, bvar);
  1195. return res;
  1196. end;
  1197. symbolic procedure differentiate(express, bvar);
  1198. begin scalar temp,diffed;
  1199. return
  1200. if eqn(length bvar,0) then express
  1201. else
  1202. <<temp:=car bvar;
  1203. diffed:=alg_df(express, car temp, cadr temp);
  1204. differentiate(diffed, cdr bvar)>>;
  1205. end;
  1206. %This function reads through the a series of <bvar> tags and extracts the
  1207. %variables.
  1208. symbolic procedure getargsRD();
  1209. begin scalar a;
  1210. %Dont forget. This function leaves the file pointer on
  1211. %the next token after the last bvar. So you need to use mathML2 after.
  1212. if char='(b v a r) then
  1213. <<a:=bvarRD();
  1214. lex();
  1215. return cons (a,getargsRD())>>;
  1216. end;
  1217. %Returns the derivative.
  1218. symbolic procedure diffRD();
  1219. begin scalar bvar, degree, express, res;
  1220. lex();
  1221. if char='(b v a r) then
  1222. <<bvar:=bvarRD();
  1223. degree:=cadr bvar;
  1224. bvar:=car bvar; lex()>>
  1225. else <<bvar:=nil; degree:=nil>>;
  1226. express:=mathML2();
  1227. lex();
  1228. res:=alg_df(express, bvar, degree);
  1229. return res;
  1230. end;
  1231. algebraic procedure alg_df(a,b,c);
  1232. begin;
  1233. return df(a,b,c);
  1234. end;
  1235. %This function will calculate the integral. Takes in the expression, then
  1236. %the bound variable, and finally the limits if they exist.
  1237. symbolic procedure intRD();
  1238. begin scalar bvar, low, upper, int, exp;
  1239. lex();
  1240. if char='(b v a r) then
  1241. <<bvar:=bvarRD();
  1242. if eqn(cadr bvar,1) then bvar:=car bvar
  1243. else
  1244. errorML("",13);
  1245. lex()>>
  1246. else errorML("<bvar>",14);
  1247. if char='(l o w l i m i t) then <<low:=lowlimitRD(); lex()>>
  1248. else low:=nil;
  1249. if char='(u p l i m i t) then <<upper:=upperlimitRD(); lex()>>
  1250. else upper:=nil;
  1251. if char='(i n t e r v a l) then
  1252. <<int:=intervalRD();
  1253. low:=car int;
  1254. upper:=cadr int;
  1255. lex()>>
  1256. else int:=nil;
  1257. exp:=mathML2();
  1258. lex();
  1259. return alg_int(exp, bvar, low, upper);
  1260. end;
  1261. algebraic procedure alg_int(exp, bvar, low, upper);
  1262. begin scalar res;
  1263. if (low='nil) AND (upper=nil) then res:= int(exp, bvar)
  1264. else res:= int(exp,bvar,low,upper);
  1265. return res;
  1266. end;
  1267. %Here we parse bound variables. The function reads the variable as well as
  1268. %the degree if there is one.
  1269. symbolic procedure bvarRD();
  1270. begin scalar var, deg;
  1271. lex();
  1272. if char='(d e g r e e) then
  1273. errorML("<bvar>",15);
  1274. var:=mathML2();
  1275. lex();
  1276. if char='(d e g r e e) then
  1277. << deg:=mathML();
  1278. lex();
  1279. if char neq '(!/ d e g r e e) then
  1280. error("</degree>",2);
  1281. lex()>>
  1282. else deg:=1;
  1283. if char='(!/ b v a r) then return list(var, deg)
  1284. else errorML("</bvar>", 2);
  1285. end;
  1286. %Functions used to parse the limits of an integral, sum, or product.
  1287. symbolic procedure lowlimitRD();
  1288. begin scalar lowlimit;
  1289. lowlimit:=mathML();
  1290. lex();
  1291. if char='(!/ l o w l i m i t) then return lowlimit
  1292. else errorML("</lowlimit>", 2);
  1293. end;
  1294. symbolic procedure upperlimitRD();
  1295. begin scalar upperlimit;
  1296. upperlimit:=mathML();
  1297. lex();
  1298. if char='(!/ u p l i m i t) then return upperlimit
  1299. else errorML("</uplimit>", 2);
  1300. end;
  1301. symbolic procedure intervalRD();
  1302. begin scalar l,u;
  1303. l:=mathML();
  1304. u:=mathML();
  1305. lex();
  1306. if char='(!/ i n t e r v a l) then return list(l,u)
  1307. else errorML("</interval>", 2);
  1308. end;
  1309. %Following functions just evaluate calculus functions.
  1310. symbolic procedure lnRD();
  1311. begin scalar a;
  1312. a:=alg_ln(mathML());
  1313. lex();
  1314. return a;
  1315. end;
  1316. algebraic procedure alg_ln(a);
  1317. begin;
  1318. return ln(a);
  1319. end;
  1320. symbolic procedure logRD();
  1321. begin scalar a, a1, base;
  1322. base:=nil;
  1323. lex();
  1324. if char='(l o g b a s e) then
  1325. <<base:=logbaseRD();
  1326. lex()>>;
  1327. a1:=mathML2();
  1328. lex();
  1329. a:=alg_log(a1, base);
  1330. return a;
  1331. end;
  1332. algebraic procedure alg_log(a, base);
  1333. begin;
  1334. if base=nil then return log(a)
  1335. else
  1336. return logb(a, base);
  1337. end;
  1338. symbolic procedure logbaseRD();
  1339. begin scalar a;
  1340. a:=mathML();
  1341. lex();
  1342. if char='(!/ l o g b a s e) then return a
  1343. else errorML("</logbase>",2);
  1344. end;
  1345. symbolic procedure conjugateRD();
  1346. begin scalar a;
  1347. a:= alg_conj(mathML());
  1348. lex();
  1349. return a;
  1350. end;
  1351. algebraic procedure alg_conj(a);
  1352. begin;
  1353. return conj(a);
  1354. end;
  1355. symbolic procedure minusRD();
  1356. begin scalar c,b;
  1357. c:=mathML();
  1358. b:=mathML();
  1359. if b=nil then c:=alg_minus(c)
  1360. else <<
  1361. c:=alg_difference(c,b);
  1362. lex()>>;
  1363. return c;
  1364. end;
  1365. algebraic procedure alg_minus(a);
  1366. begin;
  1367. return -a;
  1368. end;
  1369. algebraic procedure alg_difference(a,b);
  1370. begin;
  1371. return difference(a,b);
  1372. end;
  1373. symbolic procedure absRD();
  1374. begin scalar a;
  1375. a:=alg_abs(mathML());
  1376. lex();
  1377. return a;
  1378. end;
  1379. algebraic procedure alg_abs(a);
  1380. begin;
  1381. return abs(a);
  1382. end;
  1383. symbolic procedure rootRD();
  1384. begin scalar b,deg;
  1385. lex();
  1386. if char='(d e g r e e) then
  1387. << deg:=mathML();
  1388. lex();
  1389. if char neq '(!/ d e g r e e) then
  1390. error("</degree>","Syntax ERROR: Missing end tag");
  1391. lex()>>
  1392. else deg:=2;
  1393. b:=mathML2();
  1394. lex();
  1395. return alg_root(b,deg);
  1396. end;
  1397. algebraic procedure alg_root(b,a);
  1398. begin;
  1399. return b**(1/a);
  1400. end;
  1401. symbolic procedure remRD();
  1402. begin scalar a, a1, a2;
  1403. a1:=mathml();
  1404. a2:=mathml();
  1405. a:=alg_remainder(a1, a2);
  1406. lex();
  1407. return a;
  1408. end;
  1409. algebraic procedure alg_remainder(a,b);
  1410. begin;
  1411. return remainder(a,b);
  1412. end;
  1413. symbolic procedure factorialRD();
  1414. begin scalar a;
  1415. a:=alg_factorial(mathML());
  1416. lex();
  1417. return a;
  1418. end;
  1419. algebraic procedure alg_factorial(a);
  1420. begin;
  1421. return factorial(a);
  1422. end;
  1423. symbolic procedure expRD();
  1424. begin scalar a;
  1425. a:= alg_exp(mathML());
  1426. lex();
  1427. return a;
  1428. end;
  1429. algebraic procedure alg_exp(a);
  1430. begin;
  1431. return exp(a);
  1432. end;
  1433. symbolic procedure quotientRD();
  1434. begin scalar a, a1, a2;
  1435. a1:=mathML();
  1436. a2:=mathML();
  1437. if IDP reval a1 OR IDP reval a2 then a:=alg_quotient(a1,a2)
  1438. else
  1439. a:= (reval a1)/(reval a2);
  1440. lex();
  1441. return a;
  1442. end;
  1443. algebraic procedure alg_quotient(a,b);
  1444. begin;
  1445. return a/b;
  1446. end;
  1447. symbolic procedure divideRD();
  1448. begin scalar a, a1, a2;
  1449. a1:=mathML();
  1450. a2:=mathML();
  1451. if a2 = 0 then errorML("", 21);
  1452. a:=alg_divide(a1,a2);
  1453. lex();
  1454. return a;
  1455. end;
  1456. algebraic procedure alg_divide(a,b);
  1457. begin;
  1458. return quotient(a,b);
  1459. end;
  1460. symbolic procedure gcdRD();
  1461. begin scalar c1;
  1462. c1:=stats_getargs();
  1463. constants(c1);
  1464. if temp2='stop then
  1465. << temp2:=nil;
  1466. return cons('gcd, eval_list(c1))>>
  1467. else return gcdRD2(c1);
  1468. end;
  1469. symbolic procedure gcdRD2(args);
  1470. begin scalar a;
  1471. a:=reval car args;
  1472. return if length args=1 then car args
  1473. else alg_gcd2(a, gcdRD2(cdr args));
  1474. end;
  1475. algebraic procedure alg_gcd2(a , b);
  1476. begin;
  1477. return gcd(a,b);
  1478. end;
  1479. symbolic procedure minRD();
  1480. begin scalar a;
  1481. a:=mathML();
  1482. return if a=nil then nil
  1483. else alg_min(a,minRD());
  1484. end;
  1485. algebraic procedure alg_min(a,b);
  1486. begin;
  1487. return min(b,a);
  1488. end;
  1489. symbolic procedure maxRD();
  1490. begin scalar a;
  1491. a:=mathML();
  1492. return if a=nil then nil
  1493. else alg_max(a,maxRD());
  1494. end;
  1495. algebraic procedure alg_max(a,b);
  1496. begin;
  1497. return max(a,b)
  1498. end;
  1499. lisp operator plusRD;
  1500. symbolic procedure plusRD();
  1501. begin scalar abc1;
  1502. abc1:=nil;
  1503. abc1:=mathML();
  1504. return if abc1 = nil then 0
  1505. else alg_plus(abc1, plusRD());
  1506. end;
  1507. algebraic procedure alg_plus(acb1,b);
  1508. begin;
  1509. return acb1+b;
  1510. end;
  1511. symbolic procedure timesRD();
  1512. begin scalar a;
  1513. a:=nil;
  1514. a:=mathML();
  1515. return if a=nil then 1
  1516. else alg_times(a, timesRD());
  1517. end;
  1518. algebraic procedure alg_times(a,b);
  1519. begin;
  1520. if b=i then return a*i;
  1521. return a*b;
  1522. end;
  1523. symbolic procedure powerRD();
  1524. begin scalar var,power;
  1525. var:=mathML();
  1526. power:=mathML();
  1527. lex();
  1528. return alg_expt(var,power);
  1529. end;
  1530. algebraic procedure alg_expt(a,b);
  1531. begin;
  1532. return expt(a,b);
  1533. end;
  1534. %The following function is in charge of providing the correct error message
  1535. %as well as closing the input/output stream, and exiting the program
  1536. %correctly.
  1537. symbolic procedure errorML( str, msg );
  1538. begin;
  1539. terpri();
  1540. princ "***** Error in token number ";
  1541. princ count;
  1542. princ " (<";
  1543. princ compress char;
  1544. princ ">)";
  1545. terpri();
  1546. if msg=1 then
  1547. << princ "Needed attribute";
  1548. princ str;
  1549. princ " and none was found.">> else
  1550. if msg=2 then
  1551. << princ "Missing tag: ";
  1552. princ str >> else
  1553. if msg=3 then
  1554. << princ "Undefined error!";
  1555. princ " Token number "; princ sub1 count;
  1556. princ " probably mispelled or an";
  1557. princ "ambiguous or erroneous use of <apply></apply>.">> else
  1558. if msg=4 then
  1559. << princ "Numerical constant ";
  1560. princ str;
  1561. princ " was enclosed between <ci></ci> tags.";
  1562. terpri();
  1563. princ "Correct syntax: <cn>";
  1564. princ str;
  1565. princ "</cn>.">> else
  1566. if msg=5 then
  1567. << princ "All arguments must be sets";
  1568. terpri();
  1569. princ str;
  1570. princ " does not represent a set.">> else
  1571. if msg=6 then
  1572. << princ "Non-numeric argument in arithmetic.">> else
  1573. if msg=7 then
  1574. << princ "The degree quantifier is of no use in the sumation";
  1575. princ "operator.">> else
  1576. if msg=8 then
  1577. << princ "The degree quantifier is of no use in the limit";
  1578. princ " operator.">> else
  1579. if msg=9 then
  1580. << princ "The index of sumation has not been specified.";
  1581. terpri();
  1582. princ "Please use <bvar></bvar> tags to specify an index.">>
  1583. else
  1584. if msg=10 then
  1585. << princ "Upperlimit not specified.">> else
  1586. if msg=11 then
  1587. << princ "Upper and lower limits have not been specified.">> else
  1588. if msg=12 then
  1589. << princ "The degree quantifier is of no use in the product";
  1590. princ " operator.">> else
  1591. if msg=13 then
  1592. << princ "The degree quantifier is not allowed in the integral";
  1593. princ " operator.">> else
  1594. if msg=14 then
  1595. << princ "Variable of integration not specified.";
  1596. princ "Please use <bvar></bvar> tags to specify variable.">>
  1597. else
  1598. if msg=15 then
  1599. << princ "Incorrect use of <bvar></bvar> tags.";
  1600. princ " Correct use:";
  1601. terpri();
  1602. princ
  1603. "<bvar> bound_var </bvar> [<degree> degree </degree>] </bvar>">> else
  1604. if msg=16 then
  1605. << princ "Symbolic constant ";
  1606. princ str;
  1607. princ " was enclosed between <cn></cn> tags.";
  1608. terpri();
  1609. princ "Correct syntax: <ci> ";
  1610. princ str;
  1611. princ " </ci>";
  1612. terpri();
  1613. princ "or <cn type=""constant""> </cn>";
  1614. princ "if using constants &ImaginaryI;, &ii;, &ExponentialE;, &ee; or &pi;."
  1615. >> else
  1616. if msg=17 then
  1617. << princ "Unknown tag: <";
  1618. princ str;princ ">.";
  1619. terpri();
  1620. princ "Token not allowed within <apply></apply> tags.";
  1621. terpri();
  1622. princ "Might be: <"; princ str; princ "/>.">> else
  1623. if msg=18 then
  1624. << princ "Unknown tag: <";
  1625. princ str;princ ">.";
  1626. terpri();
  1627. princ "Not allowed within <reln></reln> tags.">> else
  1628. if msg=19 then
  1629. << princ "Undefined error!";
  1630. princ " Token "; princ sub1 count;
  1631. princ " is probably mispelled";
  1632. terpri();
  1633. princ "or unknown, ";
  1634. princ "or the </math> tag is missing">> else
  1635. if msg=20 then
  1636. << princ "Function ";
  1637. princ str;
  1638. princ "()";
  1639. princ " was not enclosed in <ci></ci> tags.";
  1640. terpri();
  1641. princ "Correct syntax: <fn><ci>";
  1642. princ str;
  1643. princ "</ci></fn>.">> else
  1644. if msg=21 then
  1645. << princ "Error, division by 0">>;
  1646. terpri();
  1647. if FILE!*=t then close rds f;
  1648. FILE!*:=nil;
  1649. rederr("");
  1650. rederr("");
  1651. terpri();
  1652. end;
  1653. %Following function are in charge of parsing statistics related mathml.
  1654. symbolic procedure meanRD();
  1655. begin scalar b, size, args;
  1656. args:=stats_getargs();
  1657. b:=0;
  1658. size:=length( args );
  1659. while (args neq ()) do
  1660. << b:=alg_plus(b, car args);
  1661. args:= cdr args >>;
  1662. return alg_quotient(b,size);
  1663. end;
  1664. symbolic procedure sdevRD( );
  1665. begin scalar args,mean,b,size;
  1666. args:=stats_getargs();
  1667. mean:=alg_mean( args );
  1668. size:=length(args);
  1669. while(args neq ()) do
  1670. << b:=alg_plus(b, alg_expt(alg_difference(car args, mean),2));
  1671. args:=cdr args; >>;
  1672. return b;
  1673. end;
  1674. symbolic procedure varRD( );
  1675. begin scalar args;
  1676. args:=stats_getargs();
  1677. return alg_expt(sdev( args ), 2);
  1678. end;
  1679. symbolic procedure medianRD( );
  1680. begin scalar args, siz, si;
  1681. args:=stats_getargs();
  1682. args:=cons('list, args);
  1683. args:=sortl(args);
  1684. args:=cdr args;
  1685. si:=length args;
  1686. siz:=si/2;
  1687. if remainder(si,2)=0 then
  1688. return alg_quotient(alg_plus(nth(args,siz),nth(args,(siz+1))),2)
  1689. else return nth(args, siz);
  1690. end;
  1691. algebraic procedure sortl(args);
  1692. begin scalar rr;
  1693. rr:=sortlist(args, pred);
  1694. if rr=nil then return sortnumlist(args)
  1695. else return rr;
  1696. end;
  1697. symbolic procedure momentRD( );
  1698. begin scalar args,size,d,i;
  1699. args:=stats_getargs();
  1700. if char='(d e g r e e) then
  1701. <<i:=mathML();
  1702. lex();
  1703. if char='(!/ d e g r e e) then lex()
  1704. else errorML("</degree>",2)>>
  1705. else i:=1;
  1706. d:=();
  1707. size:=length args;
  1708. while args neq () do
  1709. << d:=cons(alg_expt(car args, i),d);
  1710. args:=cdr args>>;
  1711. return alg_mean(d);
  1712. end;
  1713. symbolic procedure alg_mean ( args );
  1714. begin scalar b, size, args;
  1715. b:=0;
  1716. size:=length( args );
  1717. while (args neq ()) do
  1718. << b:=alg_plus(b, car args);
  1719. args:= cdr args >>;
  1720. return alg_quotient(b,size);
  1721. end;
  1722. symbolic procedure sdev( args );
  1723. begin scalar mean,b,size;
  1724. mean:=alg_mean( args );
  1725. size:=length(args);
  1726. while(args neq ()) do
  1727. << b:=alg_plus(b, alg_expt(alg_difference(car args, mean),2));
  1728. args:=cdr args; >>;
  1729. return b;
  1730. end;
  1731. %The following function gets all arguments from the mathml input.
  1732. symbolic procedure stats_getargs();
  1733. begin scalar ww;
  1734. ww:=nil;
  1735. ww:=mathML();
  1736. if ww neq nil then <<
  1737. return cons (ww,stats_getargs())>>;
  1738. end;
  1739. %Transforms polar-complex to cartesian-complex.
  1740. symbolic procedure po2ca(r,p);
  1741. begin scalar theta,x,y;
  1742. theta:=rad p;
  1743. x:=r*cos(theta);
  1744. y:=r*sin(theta);
  1745. return(list(x,y))
  1746. end;
  1747. symbolic procedure rad(mu); %note approx. pi
  1748. begin scalar b;
  1749. b:=mu*3.141529/180;
  1750. return b
  1751. end;
  1752. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1753. %Here start the functions in charge of pasing reduce's output and printing%
  1754. %it out in mathml. %
  1755. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1756. %This the mathml printer which reads reduce output and translates it to
  1757. %mathml.
  1758. symbolic procedure math_ml_printer (mode,u);
  1759. <<
  1760. if !*both=t then
  1761. (<< if u=t then else maprin(u); terpri!* nil>>) where outputhandler!* := nil;
  1762. if mode neq 'terpri then
  1763. << % FLUID '(indent, flagg,found_int, found_compl, consts_compl, consts_int);
  1764. % FLUID '(found_mat_int, found_mat_compl, consts_mat_int, consts_mat_compl);
  1765. found_mat_int=0$;
  1766. found_mat_compl=0$;
  1767. indent:=0$
  1768. consts_compl:=()$
  1769. consts_mat_compl:=()$
  1770. consts_int:=()$
  1771. consts_mat_int:=()$
  1772. found_int:=0$
  1773. found_compl:=0$
  1774. flagg:=0$
  1775. if (PAIRP u) then <<
  1776. if !*web=t then printout("<EMBED TYPE=""text/mathml"" MMLDATA=""");
  1777. printout("<math>");
  1778. indent:=3;
  1779. if ((car u)='setq) then
  1780. <<if (PAIRP caddr u) then
  1781. if (issq(caddr u)=1) then arbitrary_c( PREPSQ cadr caddr u )
  1782. else
  1783. if (caaddr u='mat) then arbitrary_c(caddr u)
  1784. else
  1785. if (caaddr u='list) then arbitrary_c( !*a2k caddr u);
  1786. setqML( u )>>
  1787. else
  1788. if ((car u)='list) then
  1789. << arbitrary_c( !*a2k u );
  1790. listML(cdr u)>>
  1791. else
  1792. if ((car u)='mat) then
  1793. << arbitrary_c( u );
  1794. matrixML(cdr u)>>
  1795. else
  1796. if ((car u)='!*sq) then
  1797. << arbitrary_c(PREPSQ (cadr u));
  1798. expression(PREPSQ (cadr u))>>
  1799. else expression(u);
  1800. indent:=indent-3;
  1801. close_forall();
  1802. indent:=0;
  1803. printout( "</math>" );
  1804. if !*web=t then princ(""" HEIGHT=300 WIDTH=500>");
  1805. terpri()
  1806. >>
  1807. else
  1808. if (ATOM u) then <<
  1809. if !*web=t then printout("<EMBED TYPE=""text/mathml"" MMLDATA="" ");
  1810. printout( "<math>" );
  1811. indent:=3;
  1812. expression( u );
  1813. indent:=0;
  1814. printout( "</math>" );
  1815. if !*web=t then princ(" "" HEIGHT=300 WIDTH=500>");
  1816. terpri() >>
  1817. else ; >> >>;
  1818. %Prints out vectors.
  1819. symbolic procedure vectorML( elem );
  1820. begin;
  1821. printout("<vector>");
  1822. indent:=indent+3;
  1823. multi_elem(car elem);
  1824. indent:=indent-3;
  1825. printout("</vector>")
  1826. end;
  1827. %Following functions print out matrices.
  1828. symbolic procedure matrixML( elem );
  1829. begin;
  1830. if length elem=1 then vectorML( elem )
  1831. else
  1832. << printout("<matrix>");
  1833. indent:=indent+3;
  1834. matrix_rows(elem);
  1835. indent:=indent-3;
  1836. printout("</matrix>")
  1837. >>;
  1838. end;
  1839. symbolic procedure matrix_rows( elem );
  1840. begin;
  1841. if (elem neq()) then
  1842. << printout("<matrixrow>");
  1843. indent:=indent+3;
  1844. row(car elem);
  1845. indent:=indent-3;
  1846. printout("</matrixrow>");
  1847. matrix_rows( cdr elem ); >>
  1848. end;
  1849. symbolic procedure row( elem );
  1850. begin;
  1851. if (elem neq()) then
  1852. << expression(car elem); row(cdr elem);>>
  1853. end;
  1854. %This function searches for arbitrary integers, or complex in the reduce
  1855. %output. If so, it declares these variables in a forall statement.
  1856. symbolic procedure arbitrary_c( elem );
  1857. begin;
  1858. found_int:=nil;
  1859. found_mat_int:=nil;
  1860. found_compl:=nil;
  1861. found_mat_compl:=nil;
  1862. if (PAIRP elem) then <<
  1863. if (car elem='mat) then
  1864. << isarb_mat_compl(cdr elem);
  1865. isarb_mat_int(cdr elem)>>
  1866. else
  1867. << isarb_compl(elem);
  1868. isarb_int(elem)>>;
  1869. if ((found_compl=1) OR (found_int=1)) then
  1870. << flagg:=1;
  1871. printout( "<apply><forall/>" );
  1872. indent:=indent+3;
  1873. print_arb_compl(elem);
  1874. print_arb_int(elem);
  1875. printout( "<condition>");
  1876. indent:=indent+3;
  1877. if ((found_compl=1) AND (found_int=1)) then
  1878. << printout( "<apply><and/>" );
  1879. indent:=indent+3>>
  1880. else
  1881. if ((length consts_compl) > 1) then
  1882. << printout( "<apply><and/>" );
  1883. indent:=indent+3>>
  1884. else
  1885. if ((length consts_int) > 1) then
  1886. << printout( "<apply><and/>" );
  1887. indent:=indent+3>>;
  1888. if (found_compl=1) then
  1889. in_complexML( consts_compl );
  1890. if (found_int=1) then
  1891. in_integerML( consts_int );
  1892. if ((found_compl=1) AND (found_int=1)) then
  1893. << indent:=indent-3;
  1894. printout( "</apply>" )>>
  1895. else
  1896. if ((length consts_compl) > 1) then
  1897. << indent:=indent-3;
  1898. printout( "</apply>" )>>
  1899. else
  1900. if ((length consts_int) > 1) then
  1901. << indent:=indent-3;
  1902. printout( "</apply>" )>>;
  1903. indent:=indent-3;
  1904. printout( "</condition>" )>>;
  1905. if ((found_mat_compl=1) OR (found_mat_int=1)) then
  1906. << flagg:=1;
  1907. printout( "<apply><forall/>" );
  1908. indent:=indent+3;
  1909. printarb_mat_compl(cdr elem);
  1910. printarb_mat_int(cdr elem);
  1911. printout( "<condition>");
  1912. indent:=indent+3;
  1913. if ((found_mat_compl=1) AND (found_mat_int=1)) then
  1914. << printout( "<apply><and/>" );
  1915. indent:=indent+3>>
  1916. else
  1917. if ((length consts_mat_compl) > 1) then
  1918. << printout( "<apply><and/>" );
  1919. indent:=indent+3>>
  1920. else
  1921. if ((length consts_mat_int) > 1) then
  1922. << printout( "<apply><and/>" );
  1923. indent:=indent+3>>;
  1924. if (found_mat_compl=1) then
  1925. in_complexML( consts_mat_compl );
  1926. if (found_mat_int=1) then
  1927. in_integerML( consts_mat_int );
  1928. if ((found_mat_compl=1) AND (found_mat_int=1)) then
  1929. << indent:=indent-3;
  1930. printout( "</apply>" )>>
  1931. else
  1932. if ((length consts_mat_compl) > 1) then
  1933. << indent:=indent-3;
  1934. printout( "</apply>" )>>
  1935. else
  1936. if ((length consts_mat_int) > 1) then
  1937. << indent:=indent-3;
  1938. printout( "</apply>" )>>;
  1939. indent:=indent-3;
  1940. printout( "</condition>" )>>;
  1941. >>
  1942. end;
  1943. symbolic procedure in_complexML( elem );
  1944. begin;
  1945. if (elem neq ()) then <<
  1946. printout("<reln><in/>");
  1947. indent:=indent+3;
  1948. printsub2( car elem, 'compl );
  1949. printout("<ci type=""set""> C </ci>");
  1950. indent:=indent-3;
  1951. printout("</reln>");
  1952. in_complexML( cdr elem )>>;
  1953. end;
  1954. symbolic procedure in_integerML( elem );
  1955. begin;
  1956. if (elem neq ()) then <<
  1957. printout("<reln><in/>");
  1958. indent:=indent+3;
  1959. printsub2( car elem, 'int );
  1960. printout("<ci type=""set""> N </ci>");
  1961. indent:=indent-3;
  1962. printout("</reln>");
  1963. in_integerML( cdr elem )>>;
  1964. end;
  1965. symbolic procedure close_forall();
  1966. begin;
  1967. if (flagg=1) then printout("</apply>");
  1968. end;
  1969. %Prints out setq statements as <declare> statements.
  1970. symbolic procedure setqML( elem );
  1971. begin;
  1972. printout( "<declare>" );
  1973. indent:=indent+3;
  1974. expression(cadr elem);
  1975. expression( caddr elem);
  1976. indent:=indent-3;
  1977. printout( "</declare>" );
  1978. end;
  1979. %Prints out lists.
  1980. symbolic procedure listML( elem );
  1981. begin;
  1982. printout( "<list>" );
  1983. indent:=indent+3;
  1984. multilists( elem );
  1985. indent:=indent-3;
  1986. printout( "</list>" );
  1987. end;
  1988. symbolic procedure multilists( elem );
  1989. begin;
  1990. if elem neq nil then
  1991. if ((LENGTH elem)=1) then expression (car elem)
  1992. else <<expression(car elem); multilists(cdr elem);>>
  1993. end;
  1994. %This function takes in a reduce expression, and parses it. It also takes
  1995. %expressions created by the above program.
  1996. symbolic procedure expression( elem );
  1997. begin scalar aa;
  1998. if (ATOM elem) then f4( elem ) else
  1999. if car elem='!:RD!: then <<printout elem>> else
  2000. <<
  2001. if (aa:=assoc(car elem, unary!*)) then <<
  2002. if caddr aa = nil then
  2003. apply(cadr aa, list cdr elem)
  2004. else
  2005. apply(cadr aa, list(cdr elem, caddr aa)) >> else
  2006. if ((car elem)= '!*sq) then expression (PREPSQ (cadr elem)) else
  2007. operator_fn(elem);>>;
  2008. end;
  2009. %Prints out sum, or products.
  2010. symbolic procedure sum_prodML( elem, tty );
  2011. begin;
  2012. printout("<apply>");
  2013. princ "<"; princ tty; princ "/>";
  2014. indent:=indent+3;
  2015. printout("<bvar>");
  2016. indent:=indent+3;
  2017. expression( cadr elem );
  2018. indent:=indent-3;
  2019. printout("</bvar>");
  2020. printout("<lowlimit>");
  2021. indent:=indent+3;
  2022. expression( caddr elem );
  2023. indent:=indent-3;
  2024. printout("</lowlimit>");
  2025. printout("<uplimit>");
  2026. indent:=indent+3;
  2027. expression( cadddr elem );
  2028. indent:=indent-3;
  2029. printout("</uplimit>");
  2030. expression car elem;
  2031. indent:=indent-3;
  2032. printout("</apply>");
  2033. end;
  2034. %Prints out derivatives.
  2035. symbolic procedure dfml( elem );
  2036. begin scalar test;
  2037. test:=cdr elem;
  2038. if length test=1 OR (length test=2 AND NUMBERP cadr test) then
  2039. printout("<apply><diff/>")
  2040. else
  2041. printout("<apply><partialdiff/>");
  2042. indent:=indent+3;
  2043. dfargs(cdr elem); % FJW: two statements swapped
  2044. expression(car elem);
  2045. indent:=indent-3;
  2046. printout("</apply>");
  2047. end;
  2048. symbolic procedure dfargs( elem );
  2049. begin;
  2050. if elem neq nil then
  2051. << if length elem>1 then
  2052. << if NUMBERP cadr elem then
  2053. <<printout("<bvar>");
  2054. indent:=indent+3;
  2055. expression car elem;
  2056. degreeML(cadr elem);
  2057. indent:=indent-3;
  2058. printout("</bvar>");
  2059. dfargs(cddr elem)>>
  2060. else
  2061. <<printout("<bvar>");
  2062. indent:=indent+3;
  2063. expression car elem;
  2064. indent:=indent-3;
  2065. printout("</bvar>");
  2066. dfargs(cdr elem)>>; >>
  2067. else
  2068. << printout("<bvar>");
  2069. indent:=indent+3;
  2070. expression car elem;
  2071. indent:=indent-3;
  2072. printout("</bvar>");
  2073. dfargs(cdr elem)>> >>;
  2074. end;
  2075. %Prints out degree statements.
  2076. symbolic procedure degreeML( elem );
  2077. begin;
  2078. printout("<degree>");
  2079. indent:=indent+3;
  2080. expression( elem );
  2081. indent:=indent-3;
  2082. printout("</degree>");
  2083. end;
  2084. symbolic procedure complpart( elem, tty);
  2085. begin;
  2086. printout("<apply><fn><");
  2087. princ tty;
  2088. princ "></fn>";
  2089. indent:=indent+3;
  2090. expression(car elem);
  2091. indent:=indent-3;
  2092. printout("<apply>");
  2093. end;
  2094. %Prints out set theory related functions.
  2095. symbolic procedure sets(elem, tty);
  2096. begin;
  2097. printout("<apply>");
  2098. princ "<"; princ tty; princ "/>";
  2099. indent:=indent+3;
  2100. multi_elem( elem );
  2101. indent:=indent-3;
  2102. printout("</apply>");
  2103. end;
  2104. %Prints out relns.
  2105. symbolic procedure reln(elem, tty);
  2106. begin;
  2107. printout("<reln>");
  2108. princ "<"; princ tty; princ "/>";
  2109. indent:=indent+3;
  2110. multi_elem( elem );
  2111. indent:=indent-3;
  2112. printout("</reln>");
  2113. end;
  2114. %Prints out a set.
  2115. symbolic procedure setML( elem );
  2116. begin;
  2117. printout("<set>");
  2118. indent:=indent+3;
  2119. multi_elem( elem );
  2120. indent:=indent-3;
  2121. printout("</set>");
  2122. end;
  2123. %Prints out unknown functions as a function. It prints out all variables
  2124. %declared a soperators.
  2125. symbolic procedure operator_fn( elem );
  2126. begin;
  2127. printout("<apply><fn><ci>");
  2128. princ car elem;
  2129. princ "</ci></fn>";
  2130. indent:=indent+3;
  2131. multi_args(cdr elem);
  2132. indent:=indent-3;
  2133. printout("</apply>");
  2134. end;
  2135. %Reads through a list and prints out each component.
  2136. symbolic procedure multi_args( elem );
  2137. begin;
  2138. if (elem neq ()) then <<expression(car elem); multi_args( cdr elem );>>
  2139. end;
  2140. %Prints out all trigonometric functions which have not the same tag name,
  2141. %as reduce function.
  2142. symbolic procedure trigML(elem, type);
  2143. begin;
  2144. printout("<apply>");
  2145. if ((type='acos) OR (type='asin) OR (type='atan)) then
  2146. << if (type='acos) then princ "<arccos/>";
  2147. if (type='asin) then princ "<arcsin/>";
  2148. if (type='atan) then princ "<arctan/>">>;
  2149. indent:=indent+3;
  2150. expression(car elem);
  2151. indent:=indent-3;
  2152. printout("</apply>");
  2153. end;
  2154. %Prints out all unary functions such as log, or many trig functions.
  2155. symbolic procedure unary( elem, type );
  2156. begin;
  2157. printout("<apply>");
  2158. princ "<";
  2159. princ type;
  2160. princ "/>";
  2161. indent:=indent+3;
  2162. expression(car elem );
  2163. indent:=indent-3;
  2164. printout("</apply>");
  2165. end;
  2166. %Prints out logs with a base.
  2167. symbolic procedure log_baseML(elem, type);
  2168. begin;
  2169. printout("<apply><log/>");
  2170. indent:=indent+3;
  2171. printout("<logbase>");
  2172. indent:=indent+3;
  2173. if (type='logb) then expression(cadr elem);
  2174. if (type='log10) then f4(10);
  2175. indent:=indent-3;
  2176. printout("</logbase>");
  2177. expression(car elem);
  2178. indent:=indent-3;
  2179. printout("<apply>");
  2180. end;
  2181. %Prints out equal relns.
  2182. symbolic procedure equalML( elem );
  2183. begin;
  2184. printout( "<reln><eq/>" );
  2185. indent:=indent+3;
  2186. expression(car elem);
  2187. expression(cadr elem);
  2188. indent:=indent-3;
  2189. printout( "</reln>" );
  2190. end;
  2191. %Prints out square roots.
  2192. symbolic procedure sqrtML( elem , type);
  2193. begin;
  2194. printout( "<apply><root/>" );
  2195. indent:=indent+3;
  2196. printout( "<degree><cn> 2 </cn></degree>" );
  2197. expression( car elem );
  2198. indent:=indent-3;
  2199. printout( "</apply>" );
  2200. end;
  2201. %Prints out integrals.
  2202. symbolic procedure integralML( elem );
  2203. begin;
  2204. printout( "<apply><int/>" );
  2205. indent:=indent+3;
  2206. printout( "<bvar>" );
  2207. indent:=indent+3;
  2208. expression (cadr elem);
  2209. indent:=indent-3;
  2210. printout( "</bvar>" );
  2211. if (length cdr elem >1) then
  2212. << printout("<lowlimit>");
  2213. indent:=indent+3;
  2214. expression( caddr elem );
  2215. indent:=indent-3;
  2216. printout("</lowlimit>");
  2217. printout("<uplimit>");
  2218. indent:=indent+3;
  2219. expression( cadddr elem );
  2220. indent:=indent-3;
  2221. printout("</uplimit>")>>;
  2222. expression( car elem );
  2223. indent:=indent-3;
  2224. printout( "</apply>" );
  2225. end;
  2226. %Prints out quotients.
  2227. symbolic procedure quotientML( elem );
  2228. begin;
  2229. if (NUMBERP car elem) AND (NUMBERP cadr elem) then <<
  2230. if !*web=nil then printout("<cn type=""rational""> ")
  2231. else printout("<cn type=&quot;rational&quot;> ");
  2232. princ car elem;
  2233. princ " <sep/> ";
  2234. princ cadr elem;
  2235. princ " </cn>">>
  2236. else <<
  2237. printout( "<apply><divide/>" );
  2238. indent:=indent+3;
  2239. expression( car elem );
  2240. expression( cadr elem );
  2241. indent:=indent-3;
  2242. printout( "</apply>" )>>;
  2243. end;
  2244. %Prints out all n_nary functions.
  2245. symbolic procedure n_nary( elem, type );
  2246. begin;
  2247. if car elem = 'e AND type = 'power then unary(cdr elem, 'exp)
  2248. else <<
  2249. printout( "<apply>" );
  2250. princ "<";
  2251. princ type;
  2252. princ "/>";
  2253. indent:=indent+3;
  2254. multi_elem( elem );
  2255. indent:=indent-3;
  2256. printout( "</apply>" )>>
  2257. end;
  2258. symbolic procedure multi_elem( elem );
  2259. begin;
  2260. if ((length elem)=1) then expression( car elem )
  2261. else <<expression( car elem ); multi_elem( cdr elem );>>
  2262. end;
  2263. symbolic procedure minusML( elem );
  2264. begin;
  2265. printout( "<apply><minus/>" );
  2266. indent:=indent+3;
  2267. multiminus( elem );
  2268. indent:=indent-3;
  2269. printout( "</apply>" );
  2270. end;
  2271. symbolic procedure multiminus( elem );
  2272. begin;
  2273. expression(car elem);
  2274. if ((length elem)=2) then expression (cadr elem);
  2275. end;
  2276. %Prints out all pieces of data: i.e terminal symbols.
  2277. %They can be numbers, identifiers, or constants.
  2278. symbolic procedure f4(exp);
  2279. begin;
  2280. if (exp='infinity) then
  2281. << if !*web=nil then printout("<cn type=""constant"">")
  2282. else printout("<cn type=&quot;constant&quot;>");
  2283. princ "&infin;";
  2284. princ "</cn>">>
  2285. else <<
  2286. if (exp='e) then
  2287. << if !*web=nil then printout("<cn type=""constant"">")
  2288. else printout("<cn type=&quot;constant&quot;>");
  2289. princ "&ExponentialE;";
  2290. princ "</cn>">>
  2291. else <<
  2292. if (exp='i) then
  2293. << if !*web=nil then printout("<cn type=""constant"">")
  2294. else printout("<cn type=&quot;constant&quot;>");
  2295. princ "&ImaginaryI;";
  2296. princ "</cn>">>
  2297. else <<
  2298. if (NUMBERP exp) then
  2299. << printout "<cn";
  2300. if (FLOATP exp) then <<if !*web=nil then princ " type=""real"">"
  2301. else princ " type=&quot;real&quot;>" >>
  2302. else
  2303. if (FIXP exp) then <<if !*web=nil then princ " type=""integer"">"
  2304. else princ " type=&quot;integer&quot;>" >>
  2305. else princ ">";
  2306. princ exp;
  2307. princ "</cn>">>;
  2308. if (IDP exp) then
  2309. << printout "<ci";
  2310. if (listp exp) then <<if !*web=nil then princ " type=""list"">"
  2311. else princ " type=&quot;list&quot;>">>
  2312. else
  2313. if (vectorp exp) then <<if !*web=nil then princ " type=""vector"">"
  2314. else princ " type=&quot;vector&quot;>">>
  2315. else princ ">";
  2316. princ exp;
  2317. princ "</ci>">>;
  2318. >>
  2319. >>
  2320. >>
  2321. end;
  2322. %Functions used to print out variables with a subscript.
  2323. symbolic procedure printsub( subscript, type );
  2324. begin;
  2325. printout("<bvar>");
  2326. indent:=indent+3;
  2327. printout("<ci>");
  2328. indent:=indent+3;
  2329. printout( "<msub>" );
  2330. indent:=indent+3;
  2331. if (type='compl) then printout( "<mi>c</mi>" );
  2332. if (type='int) then printout( "<mi>d</mi>" );
  2333. printout( "<mn>" );
  2334. princ subscript;
  2335. princ "</mn>";
  2336. indent:=indent-3;
  2337. printout( "</msub>" );
  2338. indent:=indent-3;
  2339. printout("</ci>");
  2340. indent:=indent-3;
  2341. printout("</bvar>");
  2342. end;
  2343. symbolic procedure printsub2( subscript, type );
  2344. begin;
  2345. printout("<ci>");
  2346. indent:=indent+3;
  2347. printout( "<msub>" );
  2348. indent:=indent+3;
  2349. if (type='compl) then printout( "<mi>c</mi>" );
  2350. if (type='int) then printout( "<mi>d</mi>" );
  2351. printout( "<mn>" );
  2352. princ subscript;
  2353. princ "</mn>";
  2354. indent:=indent-3;
  2355. printout( "</msub>" );
  2356. indent:=indent-3;
  2357. printout("</ci>");
  2358. end;
  2359. %Prints out expressions in math form. Plagiarised from reduce code of
  2360. %mathprint
  2361. symbolic procedure ma_print l;
  2362. begin scalar temp;
  2363. temp:=outputhandler!*;
  2364. outputhandler!*:=nil;
  2365. terpri!* nil;
  2366. if !*web=nil then maprin "<cn type=""real"">"
  2367. else maprin "<cn type=&quot;real&quot;>";
  2368. maprin l;
  2369. maprin "</cn>";
  2370. terpri!* nil;
  2371. outputhandler!*:=temp;
  2372. end;
  2373. %Function in charge of doing all printing in order to make sure the
  2374. %indentation is always correct.
  2375. symbolic procedure printout( str );
  2376. begin;
  2377. if !*web = nil then terpri();
  2378. if !*web = nil then for i := 1:indent
  2379. do << princ " " >>;
  2380. if PAIRP str then
  2381. <<if car str='!:rd!: OR car str='!:rn!: then ma_print str
  2382. else princ str>>
  2383. else princ str;
  2384. end;
  2385. %Following functions are quite obscure. They find arbitrary constants in
  2386. %expressions and matrices. Then record them, and everytime they appear, are
  2387. %replaced with a fancy subscripts C, or D.
  2388. symbolic procedure issq( elem );
  2389. begin scalar value;
  2390. value:=0;
  2391. if (ATOM elem) then value:=0
  2392. else <<if ((car elem)='!*sq) then value:=1
  2393. else value:=0>>;
  2394. return value;
  2395. end;
  2396. symbolic procedure isarb_compl( elem );
  2397. begin;
  2398. if (PAIRP elem) then <<
  2399. if ((car elem)= 'arbcomplex) then found_compl:=1
  2400. else multi_isarb_compl(cdr elem);>>
  2401. end;
  2402. symbolic procedure multi_isarb_compl( elem );
  2403. begin;
  2404. if (PAIRP elem) then <<
  2405. if (elem=()) then
  2406. else <<isarb_compl(car elem); multi_isarb_compl( cdr elem);>> >>
  2407. end;
  2408. symbolic procedure isarb_int( elem );
  2409. begin;
  2410. if (PAIRP elem) then <<
  2411. if ((car elem)= 'arbint) then found_int:=1
  2412. else multi_isarb_int(cdr elem);>>
  2413. end;
  2414. symbolic procedure multi_isarb_int( elem );
  2415. begin;
  2416. if (PAIRP elem) then <<
  2417. if (elem=()) then
  2418. else <<isarb_int(car elem); multi_isarb_int( cdr elem);>> >>
  2419. end;
  2420. symbolic procedure print_arb_compl( elem );
  2421. begin;
  2422. if (PAIRP elem) then <<
  2423. if ((car elem)= 'arbcomplex) then
  2424. << if (xnp(list (cadr elem),consts_compl) eq nil) then
  2425. << printsub(cadr elem, 'compl);
  2426. consts_compl:=cons(cadr elem, consts_compl)>> >>
  2427. else multi_compl(cdr elem);>>
  2428. end;
  2429. symbolic procedure multi_compl( elem );
  2430. begin;
  2431. if (elem=()) then
  2432. else <<print_arb_compl(car elem); multi_compl( cdr elem);>>
  2433. end;
  2434. symbolic procedure print_arb_int( elem );
  2435. begin;
  2436. if (PAIRP elem) then <<
  2437. if ((car elem)= 'arbint) then
  2438. << if (xnp(list (cadr elem),consts_int) eq nil) then
  2439. << printsub(cadr elem, 'int);
  2440. consts_int:=cons(cadr elem, consts_int)>> >>
  2441. else multi_int(cdr elem);>>
  2442. end;
  2443. symbolic procedure multi_int( elem );
  2444. begin;
  2445. if (elem=()) then
  2446. else <<print_arb_int(car elem); multi_int( cdr elem);>>
  2447. end;
  2448. symbolic procedure isarb_mat_int( elem );
  2449. begin;
  2450. if (elem neq()) then
  2451. << isarb_row_int(car elem);
  2452. isarb_mat_int( cdr elem ); >>
  2453. end;
  2454. symbolic procedure isarb_row_int( elem );
  2455. begin;
  2456. if (elem neq()) then
  2457. << if (issq(car elem)=1) then
  2458. if (PAIRP (PREPSQ cadr (car elem))) then
  2459. if (car (PREPSQ cadr (car elem))='arbint) then
  2460. found_mat_int:=1;
  2461. isarb_row_int(cdr elem);>>
  2462. end;
  2463. symbolic procedure isarb_mat_compl( elem );
  2464. begin;
  2465. if (elem neq()) then
  2466. <<
  2467. isarb_row_compl(car elem);
  2468. isarb_mat_compl( cdr elem ); >>
  2469. end;
  2470. symbolic procedure isarb_row_compl( elem );
  2471. begin;
  2472. if (elem neq()) then
  2473. << if (issq(car elem)=1) then
  2474. if (PAIRP (PREPSQ cadr (car elem))) then
  2475. if (car (PREPSQ cadr (car elem))='arbcomplex) then
  2476. found_mat_compl:=1;
  2477. isarb_row_compl(cdr elem);>>
  2478. end;
  2479. symbolic procedure printarb_mat_compl( elem );
  2480. begin;
  2481. if (elem neq()) then
  2482. << printarb_row_compl(car elem);
  2483. printarb_mat_compl( cdr elem ); >>
  2484. end;
  2485. symbolic procedure printarb_row_compl( elem );
  2486. begin scalar value;
  2487. if (elem neq()) then
  2488. << if (issq(car elem)=1) then
  2489. if (PAIRP (PREPSQ cadr (car elem))) then
  2490. << value:=cadr PREPSQ cadr car elem;
  2491. if (car (PREPSQ cadr (car elem)))='arbcomplex then
  2492. if (xnp(list (value), consts_mat_compl) eq nil) then
  2493. << printsub(value, 'compl);
  2494. consts_mat_compl:=cons(value, consts_mat_compl)>> >>;
  2495. printarb_row_compl(cdr elem);>>
  2496. end;
  2497. symbolic procedure printarb_mat_int( elem );
  2498. begin;
  2499. if (elem neq()) then
  2500. <<
  2501. printarb_row_int(car elem);
  2502. printarb_mat_int( cdr elem ); >>
  2503. end;
  2504. symbolic procedure printarb_row_int( elem );
  2505. begin scalar value;
  2506. if (elem neq()) then
  2507. << if (issq(car elem)=1) then
  2508. if (PAIRP (PREPSQ cadr (car elem))) then
  2509. << value:=cadr PREPSQ cadr car elem;
  2510. if (car (PREPSQ cadr (car elem)))='arbint then
  2511. if (xnp(list (value), consts_mat_int) eq nil) then
  2512. << printsub(value, 'int);
  2513. consts_mat_int:=cons(value, consts_mat_int)>> >>;
  2514. printarb_row_int(cdr elem);>>
  2515. end;
  2516. %Following function is the same as math_ml_printer, just that it prints out
  2517. %input given from mml, which reads from files, and not form the reduce
  2518. %normal output stream.
  2519. symbolic procedure math_ml (u);
  2520. << % FLUID '(indent flagg found_int found_compl consts_compl
  2521. % consts_int !*mathprint);
  2522. % FLUID '(found_mat_int found_mat_compl consts_mat_int
  2523. % consts_mat_compl);
  2524. !*mathprint:=0;
  2525. found_mat_int=0$;
  2526. found_mat_compl=0$;
  2527. indent:=0$
  2528. consts_compl:=()$
  2529. consts_mat_compl:=()$
  2530. consts_int:=()$
  2531. consts_mat_int:=()$
  2532. found_int:=0$
  2533. found_compl:=0$
  2534. flagg:=0$
  2535. if (PAIRP u) then <<
  2536. printout("<math>");
  2537. indent:=3;
  2538. if ((car u)='setq) then
  2539. <<if (PAIRP caddr u) then
  2540. if (issq(caddr u)=1) then arbitrary_c( PREPSQ cadr caddr u )
  2541. else
  2542. if (caaddr u='mat) then arbitrary_c(caddr u)
  2543. else
  2544. if (caaddr u='list) then arbitrary_c( !*a2k caddr u);
  2545. setqML( u )>>
  2546. else
  2547. if ((car u)='list) then
  2548. << arbitrary_c( !*a2k u );
  2549. listML(cdr u)>>
  2550. else
  2551. if ((car u)='mat) then
  2552. << arbitrary_c( u );
  2553. matrixML(cdr u)>>
  2554. else
  2555. if ((car u)='!*sq) then
  2556. << arbitrary_c(PREPSQ (cadr u));
  2557. expression(PREPSQ (cadr u))>>
  2558. else expression(u);
  2559. indent:=indent-3;
  2560. close_forall();
  2561. indent:=0;
  2562. printout( "</math>" )
  2563. >>
  2564. else
  2565. if (ATOM u) then <<
  2566. printout( "<math>" );
  2567. indent:=3;
  2568. expression( u );
  2569. indent:=0;
  2570. printout( "</math>" )>>
  2571. else ; >>;
  2572. %This function executes certain commands when switches state are changed.
  2573. %It will change the outputhandler!* when mathml is set to on or both is set
  2574. %to on. And then modify it accroding to the switches states.
  2575. symbolic procedure onoff(u,bool);
  2576. begin scalar x,y;
  2577. if not idp u then typerr(u,"switch")
  2578. else if not flagp(u,'switch)
  2579. then rerror(rlisp,25,list(u,"not defined as switch"));
  2580. x := intern compress append(explode '!*,explode u);
  2581. if !*switchcheck and lispeval x eq bool then return nil
  2582. else if y := atsoc(bool,get(u,'simpfg))
  2583. then lispeval('progn . append(cdr y,list nil));
  2584. if bool and x eq '!*!r!a!i!s!e then x := '!*raise; % Special case.
  2585. if x='!*web AND bool=t then
  2586. outputhandler!*:='math_ml_printer;
  2587. if x='!*web AND bool=nil then
  2588. if !*mathml neq t then outputhandler!*:=nil;
  2589. if x='!*mathml AND bool=t then
  2590. outputhandler!*:='math_ml_printer;
  2591. if x='!*mathml AND bool=nil then
  2592. if !*both=nil then
  2593. outputhandler!*:=nil;
  2594. if x='!*both AND bool=t then
  2595. outputhandler!*:='math_ml_printer;
  2596. if x='!*both AND bool=nil then
  2597. if !*mathml=nil then
  2598. outputhandler!*:=nil
  2599. else outputhandler!*:='math_ml_printer;
  2600. set(x,bool);
  2601. end;
  2602. lisp operator mml;
  2603. lisp operator parseml;
  2604. endmodule;
  2605. end;