assist.log 17 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. REDUCE 3.4, 15-Jul-91 ...
  2. 1:
  3. (ASSIST)
  4. % Tests of Assist Package for version 3.4 of REDUCE.
  5. % DATE : 1 June 1991.
  6. % Author: H. Caprasse <u214001@bliulg11.bitnet>.
  7. % <u214001@vm1.ulg.ac.be>
  8. % 1. TESTS OF THE SWITCH CONTROL FUNCTIONS :
  9. ;
  10. switches;
  11. **** exp:=T ************* div:= NIL ****
  12. **** gcd:=NIL *********** mcd:= T ****
  13. **** allfac:=T *********** intstr:= NIL ****
  14. **** rat:=NIL *********** rational:= NIL ****
  15. *** factor:= NIL *********** distribute:= NIL ***
  16. switchoff;
  17. switches;
  18. **** exp:=NIL ************* div:= NIL ****
  19. **** gcd:=NIL *********** mcd:= NIL ****
  20. **** allfac:=NIL *********** intstr:= NIL ****
  21. **** rat:=NIL *********** rational:= NIL ****
  22. *** factor:= NIL *********** distribute:= NIL ***
  23. switchorg;
  24. switches;
  25. **** exp:=T ************* div:= NIL ****
  26. **** gcd:=NIL *********** mcd:= T ****
  27. **** allfac:=T *********** intstr:= NIL ****
  28. **** rat:=NIL *********** rational:= NIL ****
  29. *** factor:= NIL *********** distribute:= NIL ***
  30. ;
  31. if !*mcd then "the switch mcd is on";
  32. the switch mcd is on
  33. if !*gcd then "the switch gcd is on";
  34. ;
  35. % A new switch :
  36. !*distribute;
  37. %
  38. % 2. THE "LIST" MANIPULATION FACILITIES" :
  39. ;
  40. % generation of a new list
  41. ;
  42. t1:=mklist(4);
  43. T1 := {0,0,0,0}
  44. for i:=1:4 do t1:= (t1.i:=mkid(a,i));
  45. ;
  46. % notice that part(t1,i) has become t1.i. as also shown here :
  47. ;
  48. t1.1;
  49. A1
  50. t1:=(t1.1).t1;
  51. T1 := {A1,A1,A2,A3,A4}
  52. % MKLIST does NEVER destroy anything
  53. ;
  54. mklist(t1,3);
  55. {A1,A1,A2,A3,A4}
  56. mklist(t1,10);
  57. {A1,A1,A2,A3,A4,0,0,0,0,0}
  58. % 3. THE DEFINITION OF A BAG
  59. ;
  60. % The atom "BAG" is an available (and reserved) name for a BAG envelope
  61. % it is an OPERATOR. In what follows we mostly use it but we insist that
  62. % ANY identifier (there are a few exceptions) may be used.
  63. ;
  64. aa:=bag(x,1,"A");
  65. AA := BAG(X,1,A)
  66. % It is easy to construct NEW bag-like objects
  67. ;
  68. putbag bg1,bg2;
  69. T
  70. % now one can verify that
  71. ;
  72. aa:=bg1(x,y**2);
  73. 2
  74. AA := BG1(X,Y )
  75. % is a bag by BAGP
  76. ;
  77. if bagp aa then "this is a bag";
  78. this is a bag
  79. ;
  80. % One can erase the bag property of bg2 by the command
  81. ;
  82. clearbag bg2;
  83. ;
  84. % baglistp works in the same way for either a LIST OR a BAG
  85. ;
  86. if baglistp aa then "this is a bag or list";
  87. this is a bag or list
  88. if baglistp list(x) then "this is a bag or list";
  89. this is a bag or list
  90. ;
  91. % Use of the DISPLAYFLAG command that we shall illustrate below is
  92. % another way.
  93. % "LIST" MAY NOT be a bag.
  94. on errcont;
  95. % The command below gives an error message:
  96. ;
  97. putbag list;
  98. ***** LIST invalid as BAG
  99. % LISTS may be transformed to BAGS and vice versa
  100. off errcont;
  101. ;
  102. kernlist(aa);
  103. 2
  104. {X,Y }
  105. listbag(list x,bg1);
  106. BG1(X)
  107. %
  108. %
  109. % 4. BASIC MANIPULATION FUNCTIONS WORKING FOR BOTH STRUCTURES :
  110. ;
  111. % define:
  112. ;
  113. ab:=bag(x1,x2,x3);
  114. AB := BAG(X1,X2,X3)
  115. al:=list(y1,y2,y3);
  116. AL := {Y1,Y2,Y3}
  117. % We illustrate how the elementary functions do work DIFFERENTLY
  118. ;
  119. first ab;
  120. BAG(X1)
  121. third ab;
  122. BAG(X3)
  123. first al;
  124. Y1
  125. last ab;
  126. BAG(X3)
  127. last al;
  128. Y3
  129. % The subsequent one do act in the SAME way;
  130. rest ab;
  131. BAG(X2,X3)
  132. rest al;
  133. {Y2,Y3}
  134. belast ab;
  135. BAG(X1,X2)
  136. belast al;
  137. {Y1,Y2}
  138. ;
  139. % depth determines if the depth of the list is uniform.
  140. % when it is, it gives its deepness as an integer.
  141. ;
  142. depth al;
  143. 1
  144. depth bg1(ab);
  145. 2
  146. % It is very convenient to define the PICKUP function PART(x,n) by . :
  147. ;
  148. ab.1;
  149. X1
  150. al.3;
  151. Y3
  152. on errcont;
  153. ab.4;
  154. ***** Expression BAG(X1,X2,X3) does not have part 4
  155. off errcont;
  156. % For bags, it is possible to avoid an error message when one
  157. % has an index out of range using "first", "second" and "third".
  158. % For instance:
  159. ;
  160. second second ab;
  161. BAG()
  162. % This is coherent because the envelope of a bag always remains.
  163. ;
  164. size ab;
  165. 3
  166. length al;
  167. 3
  168. remove(ab,3);
  169. BAG(X1,X2)
  170. delete(y2,al);
  171. {Y1,Y3}
  172. reverse al;
  173. {Y3,Y2,Y1}
  174. member(x3,ab);
  175. BAG(X3)
  176. % notice the output.
  177. ;
  178. al:=list(x**2,x**2,y1,y2,y3);
  179. 2
  180. AL := {X ,
  181. 2
  182. X ,
  183. Y1,
  184. Y2,
  185. Y3}
  186. ;
  187. elmult(x**2,al);
  188. 2
  189. position(y3,al);
  190. 5
  191. ;
  192. repfirst(xx,al);
  193. 2
  194. {XX,X ,Y1,Y2,Y3}
  195. represt(xx,ab);
  196. BAG(X1,XX)
  197. insert(x,al,3);
  198. 2 2
  199. {X ,X ,X,Y1,Y2,Y3}
  200. insert( b,ab,2);
  201. BAG(X1,B,XX)
  202. insert(ab,ab,1);
  203. BAG(BAG(X1,XX),X1,XX)
  204. substitute (new,y1,al);
  205. 2 2
  206. {X ,X ,NEW,Y2,Y3}
  207. ;
  208. % Function that acts on TWO lists or bags :
  209. ;
  210. append(ab,al);
  211. 2 2
  212. BAG(X1,XX,X ,X ,Y1,Y2,Y3)
  213. append(al,ab);
  214. 2 2
  215. {X ,X ,Y1,Y2,Y3,X1,XX}
  216. ;
  217. % Association list or bag may be constructed and thoroughly used
  218. ;
  219. l:=list(a1,a2,a3,a4);
  220. L := {A1,A2,A3,A4}
  221. b:=bg1(x1,x2,x3);
  222. B := BG1(X1,X2,X3)
  223. % PAIR is the CONSTRUCTOR of the ASSOCIATION LIST or BAG.
  224. al:=pair(list(1,2,3,4),l);
  225. AL := {{1,A1},{2,A2},{3,A3},{4,A4}}
  226. ab:=pair(bg1(1,2,3),b);
  227. AB := BG1(BG1(1,X1),BG1(2,X2),BG1(3,X3))
  228. ;
  229. % A BOOLEAN function abaglistp to test if it is an association
  230. ;
  231. if abaglistp bag(bag(1,2)) then "it is an associated bag";
  232. it is an associated bag
  233. ;
  234. % Values associated to the keys can be extracted
  235. % first occurence ONLY.
  236. ;
  237. asfirst(1,al);
  238. {1,A1}
  239. asfirst(3,ab);
  240. BG1(3,X3)
  241. ;
  242. assecond(a1,al);
  243. {1,A1}
  244. assecond(x3,ab);
  245. BG1(3,X3)
  246. ;
  247. aslast(z,list(list(x1,x2,x3),list(y1,y2,z)));
  248. {Y1,Y2,Z}
  249. asrest(list(x2,x3),list(list(x1,x2,x3),list(y1,y2,z)));
  250. {X1,X2,X3}
  251. ;
  252. % All occurences.
  253. asflist(x,bg1(bg1(x,a1,a2),bg1(x,b1,b2)));
  254. BG1(BG1(X,A1,A2),BG1(X,B1,B2))
  255. asslist(a1,list(list(x,a1,a2),list(x,a1,b2),list(x,y,z)));
  256. {{X,A1,A2},{X,A1,B2}}
  257. restaslist(bag(a1,x),bg1(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
  258. BG1(BG1(X,B2),BG1(A1,A2))
  259. restaslist(list(a1,x),bag(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
  260. BAG(BAG(X,B2),BAG(A1,A2))
  261. %********
  262. % Mapping functions can be used with bags through
  263. ;
  264. on errcont;
  265. ;
  266. for each j in list(list(a),list(c)) join j;
  267. {A,C}
  268. for each j in list(bg1(a),bg1(b)) collect first j;
  269. {BG1(A),BG1(BG1(X1,X2,X3))}
  270. off errcont;
  271. ;
  272. % The FOR EACH .. IN .. statement requires a LIST-LIKE object.;
  273. ;
  274. % There are functions available for manipulating bags or lists
  275. % as sets. (they exist in the symbolic mode).
  276. ;
  277. ts:=mkset list(a1,a1,a,2,2);
  278. TS := {A1,A,2}
  279. ;
  280. % Again a boolean function to test the SET property
  281. ;
  282. if setp ts then "this is a SET";
  283. this is a SET
  284. ;
  285. union(ts,ts);
  286. {A1,A,2}
  287. diffset(ts,list(a1,a));
  288. {2}
  289. diffset(list(a1,a),ts);
  290. {}
  291. symdiff(ts,ts);
  292. {}
  293. intersect(listbag(ts,set1),listbag(ts,set2));
  294. SET1(A1,A,2)
  295. % 5. MISCELLANEOUS GENERAL PURPOSE FUNCTIONS :
  296. ;
  297. clear a1,a2,a3,a,x,y,z,x1,x2,op$
  298. minlist(list(1/2,1,3));
  299. 1
  300. ---
  301. 2
  302. maxlist(list(1/2,1,3));
  303. 3
  304. % DETECTION OF A GIVEN VARIABLE IN A GIVEN SET
  305. ;
  306. detidnum aa;
  307. detidnum a10;
  308. 10
  309. detidnum a1b2z34;
  310. 34
  311. % A list of a finite number of randomly chosen integers can be
  312. % generated:
  313. %
  314. randomlist(3,10);
  315. {0,0,1,2,2,2,0,0,0,0}
  316. %
  317. fact(120);
  318. 6689502913449127057588118054090372586752746333138029810295671352301633557244962989366874165271984981308157637893214090552534408589408121859898481114389650005964960521256960000000000000000000000000000
  319. combnum(8,3);
  320. 56
  321. permutations(bag(a1,a2,a3));
  322. BAG(BAG(A1,A2,A3),BAG(A1,A3,A2),BAG(A2,A1,A3),BAG(A2,A3,A1),
  323. BAG(A3,A1,A2),BAG(A3,A2,A1))
  324. combinations({a1,a2,a3},2);
  325. {{A2,A3},{A1,A3},{A1,A2}}
  326. ;
  327. % The "depend" command can be traced and made EXPLICIT :
  328. ;
  329. depatom a;
  330. A
  331. depend a,x,y;
  332. depatom a;
  333. {X,Y}
  334. % The second use of DEPEND
  335. ;
  336. depend op,x,y,z;
  337. implicit op;
  338. OP
  339. explicit op;
  340. OP(X,Y,Z)
  341. depend y,zz;
  342. explicit op;
  343. OP(X,Y(ZZ),Z)
  344. aa:=implicit op;
  345. AA := OP
  346. % The ENTIRE dependence of OP becomes "IMPLICIT"
  347. ;
  348. df(aa,y);
  349. DF(OP,Y)
  350. % These two last functions work properly ONLY when the command "DEPEND"
  351. %involves ATOMIC quantities.
  352. ;
  353. % Detection of variables a given function depends on is possible
  354. ;
  355. funcvar(x+y);
  356. {X,Y}
  357. funcvar(sin log(x+y));
  358. {X,Y}
  359. ;
  360. % Variables on which an expression depends :
  361. %
  362. funcvar(sin pi);
  363. funcvar(x+e+i);
  364. {X}
  365. %
  366. % CONSTANT and RESERVED identifiers are recognize and not taken
  367. % as variables.
  368. %
  369. % Now we illustrate functions that give, display or erase
  370. % a "FLAG" or a "PROPERTY" :
  371. ;
  372. % It is possible to give "flags" in the algebraic mode;
  373. %
  374. putflag(list(a1,a2),fl1,t);
  375. T
  376. putflag(list(a1,a2),fl2,t);
  377. T
  378. displayflag a1;
  379. {FL1,FL2}
  380. % to clear ALL flags created for a1 :
  381. ;
  382. clearflag a1,a2;
  383. displayflag a2;
  384. {}
  385. putprop(x1,propname,value,t);
  386. X1
  387. displayprop(x1,prop);
  388. {}
  389. displayprop(x1,propname);
  390. {{PROPNAME,VALUE}}
  391. % To clear ONE property
  392. ;
  393. putprop(x1,propname,value,0);
  394. displayprop(x1,propname);
  395. {}
  396. %
  397. %
  398. % 6. FUNCTIONS TO CONTROL THE ENVIRONMENT :
  399. ;
  400. % Algebraic ATOMS detection
  401. ;
  402. alatomp z;
  403. T
  404. z:=s1;
  405. Z := S1
  406. alatomp z;
  407. T
  408. % Algebraic KERNEL detection
  409. ;
  410. alkernp z;
  411. T
  412. alkernp log sin r;
  413. T
  414. % PRECEDENCE detection
  415. ;
  416. precp(difference,plus);
  417. T
  418. precp(plus,difference);
  419. precp(times,.);
  420. precp(.,times);
  421. T
  422. % STRING detection
  423. ;
  424. if stringp x then "this is a string";
  425. if stringp "this is a string" then "this is a string";
  426. this is a string
  427. ;
  428. ;
  429. % A function which detects the dependence of u with respect
  430. %to the ATOM or KERNEL v at ANY LEVEL
  431. ;
  432. depvarp(log(sin(x+cos(1/acos rr))),rr);
  433. T
  434. ;
  435. operator op;
  436. *** OP already defined as operator
  437. symmetric op;
  438. op(x,y)-op(y,x);
  439. 0
  440. remsym op;
  441. op(x,y)-op(y,x);
  442. OP(X,Y) - OP(Y,X)
  443. ;
  444. clear y,x,u,v;
  445. korder y,x,u,v;
  446. korderlist;
  447. (Y X U V)
  448. ;
  449. for all x,y such that nordp(x,y) let op(x,y)=x+y;
  450. op(a,b);
  451. BG1(X1,X2,X3) + A
  452. op(b,a);
  453. OP(BG1(X1,X2,X3),A)
  454. clear op;
  455. % DISPLAY and CLEARING of user's objects of various types entered
  456. % to the console. Only TOP LEVEL assignments are considered up to now.
  457. % The following statements must be made INTERACTIVELY. We put them
  458. % as COMMENTS for the user to experiment with them. We do this because
  459. % in a fresh environment all outputs are nil.
  460. ;
  461. % THIS PART OF THE TEST SHOULD BE REALIZED INTERACTIVELY.
  462. % SEE THE ** ASSIST LOG ** FILE .
  463. %v1:=v2:=1;
  464. %show variables; % For REDUCE 3.3 ONLY.
  465. %show scalars;
  466. %aa:=list(a);
  467. %show lists;
  468. %array ar(2);
  469. %show arrays;
  470. %load matr$
  471. %matrix mm;
  472. %show matrices;
  473. %x**2;
  474. %saveas res;
  475. %show saveids;
  476. %suppress variables; % For REDUCE 3.3 ONLY
  477. %show variables; % For REDUCE 3.3 ONLY
  478. %suppress scalars;
  479. %show scalars;
  480. %show lists;
  481. %suppress all;
  482. %show arrays;
  483. %show matrices;
  484. clear op;
  485. operator op;
  486. op(x,y,z);
  487. OP(X,Y,S1)
  488. clearop op;
  489. T
  490. clearfunctions abs,tan;
  491. *** ABS is unprotected : Cleared ***
  492. *** TAN is unprotected : Cleared ***
  493. "Clearing is complete"
  494. ;
  495. % THIS FUNCTION MUST BE USED WITH CARE !!"!!!
  496. ;
  497. % 7. NEW POLYNOMIAL MANIPUKLATION FACILITIES
  498. %
  499. %
  500. clear x,y,z;
  501. % To see the internal representation :
  502. %
  503. off pri;
  504. ;
  505. pol:=(x+2*y+3*z**2)**3;
  506. 3 2 2 2 2 4 3
  507. POL := 8*Y + (12*X + 36*Z )*Y + (6*X + 36*Z *X + 54*Z )*Y + X + 9
  508. 2 2 4 6
  509. *Z *X + 27*Z *X + 27*Z
  510. ;
  511. % Notice the recursive form.
  512. ;
  513. pold:=distribute pol;
  514. 3 2 2 2 4 2 2 3
  515. POLD := 8*Y + 36*Z *Y + 12*X*Y + 54*Z *Y + 36*Z *X*Y + 6*X *Y + X
  516. 2 2 4 6
  517. + 9*Z *X + 27*Z *X + 27*Z
  518. ;
  519. % Now it is in a distributive form.
  520. ;
  521. % Terms and reductums may be extracted individually :
  522. on distribute;
  523. polp:=pol$
  524. leadterm (pold);
  525. 3
  526. 8*Y
  527. pold:=redexpr pold;
  528. 2 2 2 4 2 2 3 2
  529. POLD := 36*Z *Y + 12*X*Y + 54*Z *Y + 36*Z *X*Y + 6*X *Y + X + 9*Z
  530. 2 4 6
  531. *X + 27*Z *X + 27*Z
  532. leadterm pold;
  533. 2 2
  534. 36*Z *Y
  535. ;
  536. off distribute;
  537. polp:=pol$
  538. leadterm polp;
  539. 3
  540. 8*Y
  541. polp:=redexpr polp;
  542. 2 2 2 2 4 3 2 2
  543. POLP := (12*X + 36*Z )*Y + (6*X + 36*Z *X + 54*Z )*Y + X + 9*Z *X
  544. 4 6
  545. + 27*Z *X + 27*Z
  546. leadterm polp;
  547. 2 2
  548. (12*X + 36*Z )*Y
  549. ;
  550. % "leadterm" and "redexpr" extract the leading term and reductum of a
  551. % polynomial respectively WITHOUT specifying the variable.
  552. % The default ordering is then assumed.
  553. % They work both for the distributive and recursive representations.
  554. %
  555. % The function "monom" puts in a list all monoms of a multivariate
  556. % polynomial.
  557. monom polp;
  558. 6
  559. {27*Z ,
  560. 4
  561. 27*Z *X,
  562. 2 2
  563. 9*Z *X ,
  564. 3
  565. X ,
  566. 2
  567. 6*X *Y,
  568. 2
  569. 36*Z *X*Y,
  570. 4
  571. 54*Z *Y,
  572. 2
  573. 12*X*Y ,
  574. 2 2
  575. 36*Z *Y }
  576. % "lowestdeg" extracts the smallest power of a given indeterminate
  577. % in a polynomial:
  578. lowestdeg(pol,z);
  579. 0
  580. ;
  581. on pri;
  582. ;
  583. divpol(pol,x+2*y+3*z**2);
  584. 2 2 2 2 4
  585. {X + 4*X*Y + 6*X*Z + 4*Y + 12*Y*Z + 9*Z ,
  586. 0}
  587. % This function gives the quotient AND the remainder directly inside a
  588. % list.
  589. ;
  590. % 8. MANIPUKLATIONS OF SOME ELEMENTARY TRANSCENDENTAL FUNCTIONS
  591. trig:=((sin x)**2+(cos x)**2)**4;
  592. 8 6 2 4 4
  593. TRIG := SIN(X) + 4*SIN(X) *COS(X) + 6*SIN(X) *COS(X)
  594. 2 6 8
  595. + 4*SIN(X) *COS(X) + COS(X)
  596. trigreduce trig;
  597. 1
  598. trig:=sin (5x);
  599. TRIG := SIN(5*X)
  600. trigexpand trig;
  601. 4 2 2 4
  602. SIN(X)*(SIN(X) - 10*SIN(X) *COS(X) + 5*COS(X) )
  603. trigreduce ws;
  604. SIN(5*X)
  605. trigexpand sin(x+y+z);
  606. - SIN(X)*SIN(Y)*SIN(Z) + SIN(X)*COS(Y)*COS(Z) + SIN(Y)*COS(X)*COS(Z)
  607. + SIN(Z)*COS(X)*COS(Y)
  608. ;
  609. % The same functions exist for hyperbolic functions:
  610. ;
  611. hypreduce (sinh x **2 -cosh x **2);
  612. -1
  613. ;
  614. % For expressions containing log's. Expansion in terms of sums,
  615. % differences, .. is given by "logplus" while concatenation is given
  616. % by the function "concsumlog".
  617. ;
  618. clear a,b;
  619. logplus log(a*log(x**b));
  620. LOG(LOG(X)) + LOG(A) + LOG(B)
  621. concsumlog((2*log x + a*b*log(x*y)+1)/(3*x**2*log(y)));
  622. A*B A*B 2
  623. LOG(Y *X *X ) + 1
  624. -----------------------
  625. 2
  626. 3*X
  627. LOG(Y )
  628. % Though these functions do use substitution rules, these are
  629. % active only during the time they actually do their work.
  630. % 9. VECTOR CALCULUS OPERATIONS
  631. ;
  632. clear u1,u2,v1,v2,v3,v4,w3,w4;
  633. u1:=list(v1,v2,v3,v4);
  634. U1 := {V1,V2,V3,V4}
  635. u2:=bag(w1,w2,w3,w4);
  636. U2 := BAG(W1,W2,W3,W4)
  637. %
  638. sumvect(u1,u2);
  639. {V1 + W1,
  640. V2 + W2,
  641. V3 + W3,
  642. V4 + W4}
  643. minvect(u2,u1);
  644. BAG( - V1 + W1, - V2 + W2, - V3 + W3, - V4 + W4)
  645. scalvect(u1,u2);
  646. V1*W1 + V2*W2 + V3*W3 + V4*W4
  647. crossvect(rest u1,rest u2);
  648. {V3*W4 - V4*W3,
  649. - V2*W4 + V4*W2,
  650. V2*W3 - V3*W2}
  651. mpvect(rest u1,rest u2, minvect(rest u1,rest u2));
  652. 0
  653. scalvect(crossvect(rest u1,rest u2),minvect(rest u1,rest u2));
  654. 0
  655. ;
  656. % 10. NEW OPERATIONS ON MATRICES
  657. ;
  658. clear m,mm,b,b1,bb,cc,a,b,c,d;
  659. matrix mm(2,2);
  660. baglmat(bag(bag(a1,a2)),m);
  661. T
  662. m;
  663. [A1 A2]
  664. on errcont;
  665. ;
  666. baglmat(bag(bag(a1),bag(a2)),m);
  667. ***** (MAT ((*SQ ((((A1 . 1) . 1)) . 1) T) (*SQ ((((A2 . 1) . 1)) . 1) T)))
  668. should be an identifier
  669. off errcont;
  670. % **** i.e. it cannot redefine the matrix! in order
  671. % to avoid accidental redefinition of an already given matrix;
  672. clear m;
  673. baglmat(bag(bag(a1),bag(a2)),m);
  674. T
  675. m;
  676. [A1]
  677. [ ]
  678. [A2]
  679. on errcont;
  680. baglmat(bag(bag(a1),bag(a2)),bag);
  681. ***** OPERATOR BAG invalid as matrix
  682. off errcont;
  683. % Right since a bag-like object cannot become a matrix.
  684. coercemat(m,op);
  685. OP(OP(A1),OP(A2))
  686. coercemat(m,list);
  687. {{A1},{A2}}
  688. ;
  689. on nero;
  690. unitmat b1(2);
  691. matrix b(2,2);
  692. b:=mat((r1,r2),(s1,s2));
  693. [R1 R2]
  694. B := [ ]
  695. [S1 S2]
  696. b1;
  697. [1 0]
  698. [ ]
  699. [0 1]
  700. b;
  701. [R1 R2]
  702. [ ]
  703. [S1 S2]
  704. mkidm(b,1);
  705. [1 0]
  706. [ ]
  707. [0 1]
  708. % Allows to relate matrices already defined.
  709. ;
  710. % Convenient to replace or get a matrix element inside a procedure :
  711. %
  712. seteltmat(b,newelt,2,2);
  713. [R1 R2 ]
  714. [ ]
  715. [S1 NEWELT]
  716. geteltmat(b,2,1);
  717. S1
  718. %
  719. b:=matsubr(b,bag(1,2),2);
  720. [R1 R2]
  721. B := [ ]
  722. [1 2 ]
  723. % It gives automatically a new matrix with the second row substituted.
  724. ;
  725. submat(b,1,2);
  726. [1]
  727. % What is left when row 1 and column 2 are taken off the matrix.
  728. bb:=mat((1+i,-i),(-1+i,-i));
  729. [I + 1 - I]
  730. BB := [ ]
  731. [I - 1 - I]
  732. cc:=matsubc(bb,bag(1,2),2);
  733. [I + 1 1]
  734. CC := [ ]
  735. [I - 1 2]
  736. % Second column substituted.
  737. cc:=tp matsubc(bb,bag(1,2),2);
  738. [I + 1 I - 1]
  739. CC := [ ]
  740. [ 1 2 ]
  741. matextr(bb, bag,1);
  742. BAG(I + 1, - I)
  743. % First row extracted and placed in a bag.
  744. matextc(bb,list,2);
  745. { - I, - I}
  746. % Second column extracted and placed in a bag.
  747. ;
  748. hconcmat(bb,cc);
  749. [I + 1 - I I + 1 I - 1]
  750. [ ]
  751. [I - 1 - I 1 2 ]
  752. vconcmat(bb,cc);
  753. [I + 1 - I ]
  754. [ ]
  755. [I - 1 - I ]
  756. [ ]
  757. [I + 1 I - 1]
  758. [ ]
  759. [ 1 2 ]
  760. % Horizontal an vertical concatenations.
  761. ;
  762. tpmat(bb,bb);
  763. [ 2*I - I + 1 - I + 1 -1]
  764. [ ]
  765. [ -2 - I + 1 I + 1 -1]
  766. [ ]
  767. [ -2 I + 1 - I + 1 -1]
  768. [ ]
  769. [ - 2*I I + 1 I + 1 -1]
  770. % Tensor product.
  771. %
  772. % It is an INFIX operation :
  773. bb tpmat bb;
  774. [ 2*I - I + 1 - I + 1 -1]
  775. [ ]
  776. [ -2 - I + 1 I + 1 -1]
  777. [ ]
  778. [ -2 I + 1 - I + 1 -1]
  779. [ ]
  780. [ - 2*I I + 1 I + 1 -1]
  781. ;
  782. clear hbb;
  783. hermat(bb,hbb);
  784. [ - I + 1 - (I + 1)]
  785. [ ]
  786. [ I I ]
  787. % id hbb changed to a matrix id and assigned to the hermitian matrix
  788. % of bb.
  789. ;
  790. end;
  791. Quitting