ASSIST.LOG 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137
  1. REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
  2. % Tests of Assist Package version 2.1.
  3. % DATE : 25 December 1993
  4. % Author: H. Caprasse <caprasse@vm1.ulg.ac.be>
  5. %load_package assist$
  6. Comment 2. HELP for ASSIST:;
  7. ;
  8. helpassist(assist);
  9. Arguments must be integers from 3 to 15
  10. They correspond to the section numbers in the documentation:
  11. 3 for switches 4 for lists 5 for bags 6 for sets
  12. 7 for utilities 8 for properties 9 for control functions
  13. 10 for polynomes
  14. 11 for trigonometric or
  15. hyperbolic functions
  16. 12 for arrays 13 for vectors
  17. 14 for grassmann variables 15 for matrices
  18. ;
  19. helpassist(6);
  20. {union,setp,mkset,setdiff,symdiff}
  21. ;
  22. Comment 3. CONTROL OF SWITCHES:;
  23. ;
  24. switches;
  25. **** exp:=t .................... allfac:= t ****
  26. **** ezgcd:=nil ................. gcd:= nil ****
  27. **** mcd:=t ....................... lcm:= t ****
  28. **** div:=nil ................... rat:= nil ****
  29. **** intstr:=nil ........... rational:= nil ****
  30. **** precise:=t ........... reduced:= nil ****
  31. **** complex:=nil ....... rationalize:= nil ****
  32. **** factor:= nil ....... combineexpt:= nil ****
  33. **** complex:= nil ....... distribute:= nil ****
  34. off exp;
  35. on gcd;
  36. switches;
  37. **** exp:=nil .................... allfac:= t ****
  38. **** ezgcd:=nil ................. gcd:= t ****
  39. **** mcd:=t ....................... lcm:= t ****
  40. **** div:=nil ................... rat:= nil ****
  41. **** intstr:=nil ........... rational:= nil ****
  42. **** precise:=t ........... reduced:= nil ****
  43. **** complex:=nil ....... rationalize:= nil ****
  44. **** factor:= nil ....... combineexpt:= nil ****
  45. **** complex:= nil ....... distribute:= nil ****
  46. switchorg;
  47. switches;
  48. **** exp:=t .................... allfac:= t ****
  49. **** ezgcd:=nil ................. gcd:= nil ****
  50. **** mcd:=t ....................... lcm:= t ****
  51. **** div:=nil ................... rat:= nil ****
  52. **** intstr:=nil ........... rational:= nil ****
  53. **** precise:=nil ........... reduced:= nil ****
  54. **** complex:=nil ....... rationalize:= nil ****
  55. **** factor:= nil ....... combineexpt:= nil ****
  56. **** complex:= nil ....... distribute:= nil ****
  57. ;
  58. if !*mcd then "the switch mcd is on";
  59. the switch mcd is on
  60. if !*gcd then "the switch gcd is on";
  61. ;
  62. Comment 4. MANIPULATION OF THE LIST STRUCTURE:;
  63. ;
  64. t1:=mklist(4);
  65. t1 := {0,0,0,0}
  66. Comment MKLIST does NEVER destroy anything ;
  67. mklist(t1,3);
  68. {0,0,0,0}
  69. mklist(t1,10);
  70. {0,0,0,0,0,0,0,0,0,0}
  71. ;
  72. % Generation of n duplicates of list :
  73. algnlist({a,x^2,1},3);
  74. 2
  75. {{a,x ,1},
  76. 2
  77. {a,x ,1},
  78. 2
  79. {a,x ,1}}
  80. ;
  81. sequences 3;
  82. {{0,0,0},
  83. {1,0,0},
  84. {0,1,0},
  85. {1,1,0},
  86. {0,0,1},
  87. {1,0,1},
  88. {0,1,1},
  89. {1,1,1}}
  90. lisp;
  91. nil
  92. sequences 3;
  93. ((0 0 0) (1 0 0) (0 1 0) (1 1 0) (0 0 1) (1 0 1) (0 1 1) (1 1 1))
  94. algebraic;
  95. ;
  96. frequency append(t1,t1);
  97. {{0,8}}
  98. elmult(a1,t1);
  99. 0
  100. insert(a1,t1,2);
  101. {0,a1,0,0,0}
  102. li:=list(1,2,5);
  103. li := {1,2,5}
  104. insert_keep_order(4,li,lessp);
  105. {1,2,4,5}
  106. merge_list(li,li,lessp);
  107. {1,1,2,2,5,5}
  108. for i:=1:4 do t1:= (t1.i:=mkid(a,i));
  109. % for i:=1:2 do t1:=(t1.i:=mkid(a,i));
  110. t1.1;
  111. a1
  112. t1:=(t1.1) . t1;
  113. t1 := {a1,a1,a2,a3,a4}
  114. position(a2,t1);
  115. 3
  116. pair(t1,t1);
  117. {{a1,a1},{a1,a1},{a2,a2},{a3,a3},{a4,a4}}
  118. depth list t1;
  119. 2
  120. depth a1;
  121. 0
  122. appendn(li,li,li);
  123. {1,2,5,1,2,5,1,2,5}
  124. ;
  125. comment 5. THE BAG STRUCTURE AND ITS ASSOCIATED FUNCTIONS
  126. ;
  127. aa:=bag(x,1,"A");
  128. aa := bag(x,1,A)
  129. putbag bg1,bg2;
  130. t
  131. on errcont;
  132. putbag list;
  133. ***** list invalid as BAG
  134. off errcont;
  135. aa:=bg1(x,y**2);
  136. 2
  137. aa := bg1(x,y )
  138. ;
  139. if bagp aa then "this is a bag";
  140. this is a bag
  141. ;
  142. clearbag bg2;
  143. ;
  144. depth bg2(x);
  145. 0
  146. ;
  147. if baglistp aa then "this is a bag or list";
  148. this is a bag or list
  149. if baglistp list(x) then "this is a bag or list";
  150. this is a bag or list
  151. ;
  152. ab:=bag(x1,x2,x3);
  153. ab := bag(x1,x2,x3)
  154. al:=list(y1,y2,y3);
  155. al := {y1,y2,y3}
  156. first ab;
  157. bag(x1)
  158. third ab;
  159. bag(x3)
  160. first al;
  161. y1
  162. last ab;
  163. bag(x3)
  164. last al;
  165. y3
  166. belast ab;
  167. bag(x1,x2)
  168. belast al;
  169. {y1,y2}
  170. rest ab;
  171. bag(x2,x3)
  172. rest al;
  173. {y2,y3}
  174. depth al;
  175. 1
  176. depth bg1(ab);
  177. 2
  178. ;
  179. ab.1;
  180. x1
  181. al.3;
  182. y3
  183. on errcont;
  184. ab.4;
  185. ***** Expression bag(x1,x2,x3) does not have part 4
  186. off errcont;
  187. kernlist(aa);
  188. 2
  189. {x,y }
  190. listbag(list x,bg1);
  191. bg1(x)
  192. size ab;
  193. 3
  194. length al;
  195. 3
  196. remove(ab,3);
  197. bag(x1,x2)
  198. delete(y2,al);
  199. {y1,y3}
  200. reverse al;
  201. {y3,y2,y1}
  202. member(x3,ab);
  203. bag(x3)
  204. al:=list(x**2,x**2,y1,y2,y3);
  205. 2
  206. al := {x ,
  207. 2
  208. x ,
  209. y1,
  210. y2,
  211. y3}
  212. ;
  213. elmult(x**2,al);
  214. 2
  215. position(y3,al);
  216. 5
  217. ;
  218. repfirst(xx,al);
  219. 2
  220. {xx,x ,y1,y2,y3}
  221. represt(xx,ab);
  222. bag(x1,xx)
  223. insert(x,al,3);
  224. 2 2
  225. {x ,x ,x,y1,y2,y3}
  226. insert( b,ab,2);
  227. bag(x1,b,xx)
  228. insert(ab,ab,1);
  229. bag(bag(x1,xx),x1,xx)
  230. substitute (new,y1,al);
  231. 2 2
  232. {x ,x ,new,y2,y3}
  233. ;
  234. appendn(ab,ab,ab);
  235. {x1,xx,x1,xx,x1,xx}
  236. append(ab,al);
  237. 2 2
  238. bag(x1,xx,x ,x ,y1,y2,y3)
  239. append(al,ab);
  240. 2 2
  241. {x ,x ,y1,y2,y3,x1,xx}
  242. ;
  243. comment Association list or bag may be constructed and thoroughly used;
  244. ;
  245. l:=list(a1,a2,a3,a4);
  246. l := {a1,a2,a3,a4}
  247. b:=bg1(x1,x2,x3);
  248. b := bg1(x1,x2,x3)
  249. al:=pair(list(1,2,3,4),l);
  250. al := {{1,a1},{2,a2},{3,a3},{4,a4}}
  251. ab:=pair(bg1(1,2,3),b);
  252. ab := bg1(bg1(1,x1),bg1(2,x2),bg1(3,x3))
  253. ;
  254. comment : A BOOLEAN function abaglistp to test if it is an association;
  255. ;
  256. if abaglistp bag(bag(1,2)) then "it is an associated bag";
  257. it is an associated bag
  258. ;
  259. % Values associated to the keys can be extracted
  260. % first occurence ONLY.
  261. ;
  262. asfirst(1,al);
  263. {1,a1}
  264. asfirst(3,ab);
  265. bg1(3,x3)
  266. ;
  267. assecond(a1,al);
  268. {1,a1}
  269. assecond(x3,ab);
  270. bg1(3,x3)
  271. ;
  272. aslast(z,list(list(x1,x2,x3),list(y1,y2,z)));
  273. {y1,y2,z}
  274. asrest(list(x2,x3),list(list(x1,x2,x3),list(y1,y2,z)));
  275. {x1,x2,x3}
  276. ;
  277. clear a1;
  278. ;
  279. % All occurences.
  280. asflist(x,bg1(bg1(x,a1,a2),bg1(x,b1,b2)));
  281. bg1(bg1(x,a1,a2),bg1(x,b1,b2))
  282. asslist(a1,list(list(x,a1),list(y,a1),list(x,y)));
  283. {{x,a1},{y,a1}}
  284. restaslist(bag(a1,x),bg1(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
  285. bg1(bg1(x,b2),bg1(a1,a2))
  286. restaslist(list(a1,x),bag(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
  287. bag(bag(x,b2),bag(a1,a2))
  288. ;
  289. Comment 6. SETS AND THEIR MANIPULATION FUNCTIONS
  290. ;
  291. ts:=mkset list(a1,a1,a,2,2);
  292. ts := {a1,a,2}
  293. if setp ts then "this is a SET";
  294. this is a SET
  295. ;
  296. union(ts,ts);
  297. {a1,a,2}
  298. diffset(ts,list(a1,a));
  299. {2}
  300. diffset(list(a1,a),ts);
  301. {}
  302. symdiff(ts,ts);
  303. {}
  304. intersect(listbag(ts,set1),listbag(ts,set2));
  305. set1(a1,a,2)
  306. Comment 7. GENERAL PURPOSE UTILITY FUNCTIONS :;
  307. ;
  308. clear a1,a2,a3,a,x,y,z,x1,x2,op$
  309. ;
  310. % DETECTION OF A GIVEN VARIABLE IN A GIVEN SET
  311. ;
  312. mkidnew();
  313. G0
  314. mkidnew(a);
  315. aG1
  316. dellastdigit 23;
  317. 2
  318. detidnum aa;
  319. detidnum a10;
  320. 10
  321. detidnum a1b2z34;
  322. 34
  323. list_to_ids list(a,1,rr,22);
  324. a1rr22
  325. ;
  326. if oddp 3 then "this is an odd integer";
  327. this is an odd integer
  328. ;
  329. <<prin2 1; followline 7; prin2 8;>>;
  330. 1
  331. 8
  332. ;
  333. operator foo;
  334. foo(x):=x;
  335. foo(x) := x
  336. foo(x)==value;
  337. value
  338. x:=x;
  339. x := value
  340. ;
  341. clear x;
  342. ;
  343. randomlist(10,20);
  344. {8,1,8,0,5,7,3,8,0,5,5,9,0,5,2,0,7,5,5,1}
  345. % Generation of tables of random numbers:
  346. % One dimensional:
  347. mkrandtabl({4},10,ar);
  348. {4}
  349. ;
  350. % Two dimensional:
  351. mkrandtabl({3,4},10,ar);
  352. *** array ar redefined
  353. {3,4}
  354. ;
  355. % With a base which is a decimal number:
  356. on rounded;
  357. mkrandtabl({5},3.5,ar);
  358. *** array ar redefined
  359. {5}
  360. off rounded;
  361. ;
  362. combnum(8,3);
  363. 56
  364. permutations(bag(a1,a2,a3));
  365. bag(bag(a1,a2,a3),bag(a1,a3,a2),bag(a2,a1,a3),bag(a2,a3,a1),bag(a3,a1,a2),
  366. bag(a3,a2,a1))
  367. permutations {1,2,3};
  368. {{1,2,3},{1,3,2},{2,1,3},{2,3,1},{3,1,2},{3,2,1}}
  369. cyclicpermlist{1,2,3};
  370. {{1,2,3},{2,3,1},{3,1,2}}
  371. combinations({1,2,3},2);
  372. {{2,3},{1,3},{1,2}}
  373. labc:={a,b,c};
  374. labc := {a,bg1(x1,x2,x3),c}
  375. symmetrize(labc,foo,cyclicpermlist);
  376. foo(bg1(x1,x2,x3),c,a) + foo(a,bg1(x1,x2,x3),c) + foo(c,a,bg1(x1,x2,x3))
  377. symmetrize(labc,list,permutations);
  378. {bg1(x1,x2,x3),a,c} + {bg1(x1,x2,x3),c,a} + {a,bg1(x1,x2,x3),c}
  379. + {a,c,bg1(x1,x2,x3)} + {c,bg1(x1,x2,x3),a} + {c,a,bg1(x1,x2,x3)}
  380. symmetrize({labc},foo,cyclicpermlist);
  381. foo({bg1(x1,x2,x3),c,a}) + foo({a,bg1(x1,x2,x3),c}) + foo({c,a,bg1(x1,x2,x3)})
  382. extremum({1,2,3},lessp);
  383. 1
  384. extremum({1,2,3},geq);
  385. 3
  386. extremum({a,b,c},ordp);
  387. bg1(x1,x2,x3)
  388. ;
  389. funcvar(x+y);
  390. {x,y}
  391. funcvar(sin log(x+y));
  392. {x,y}
  393. funcvar(sin pi);
  394. funcvar(x+e+i);
  395. {x}
  396. ;
  397. depatom a;
  398. a
  399. depend a,x,y;
  400. depatom a;
  401. {x,y}
  402. depend op,x,y,z;
  403. implicit op;
  404. op
  405. explicit op;
  406. op(x,y,z)
  407. depend y,zz;
  408. explicit op;
  409. op(x,y(zz),z)
  410. aa:=implicit op;
  411. aa := op
  412. clear op;
  413. ;
  414. korder x,z,y;
  415. korderlist;
  416. (x z y)
  417. ;
  418. if checkproplist({1,2,3},fixp) then "it is a list of integers";
  419. it is a list of integers
  420. ;
  421. if checkproplist({a,b1,c},idp) then "it is a list of identifiers";
  422. it is a list of identifiers
  423. ;
  424. if checkproplist({1,b1,c},idp) then "it is a list of identifiers";
  425. ;
  426. lmix:={1,1/2,a,"st"};
  427. 1
  428. lmix := {1,---,a,st}
  429. 2
  430. ;
  431. extractlist(lmix,fixp);
  432. {1}
  433. extractlist(lmix,numberp);
  434. 1
  435. {1,---}
  436. 2
  437. extractlist(lmix,idp);
  438. {a}
  439. extractlist(lmix,stringp);
  440. {st}
  441. ;
  442. comment 8. PROPERTIES AND FLAGS:;
  443. ;
  444. putflag(list(a1,a2),fl1,t);
  445. t
  446. putflag(list(a1,a2),fl2,t);
  447. t
  448. displayflag a1;
  449. {fl1,fl2}
  450. ;
  451. clearflag a1,a2;
  452. displayflag a2;
  453. {}
  454. putprop(x1,propname,value,t);
  455. x1
  456. displayprop(x1,prop);
  457. {}
  458. displayprop(x1,propname);
  459. {propname,value}
  460. ;
  461. putprop(x1,propname,value,0);
  462. displayprop(x1,propname);
  463. {}
  464. ;
  465. Comment 9. CONTROL FUNCTIONS:;
  466. ;
  467. alatomp z;
  468. t
  469. z:=s1;
  470. z := s1
  471. alatomp z;
  472. t
  473. ;
  474. alkernp z;
  475. t
  476. alkernp log sin r;
  477. t
  478. ;
  479. precp(difference,plus);
  480. t
  481. precp(plus,difference);
  482. precp(times,.);
  483. precp(.,times);
  484. t
  485. ;
  486. if stringp x then "this is a string";
  487. if stringp "this is a string" then "this is a string";
  488. this is a string
  489. ;
  490. if nordp(b,a) then "a is ordered before b";
  491. operator op;
  492. for all x,y such that nordp(x,y) let op(x,y)=x+y;
  493. op(a,a);
  494. op(a,a)
  495. op(b,a);
  496. op(bg1(x1,x2,x3),a)
  497. op(a,b);
  498. bg1(x1,x2,x3) + a
  499. clear op;
  500. ;
  501. depvarp(log(sin(x+cos(1/acos rr))),rr);
  502. t
  503. ;
  504. operator op;
  505. symmetric op;
  506. op(x,y)-op(y,x);
  507. 0
  508. remsym op;
  509. op(x,y)-op(y,x);
  510. op(x,y) - op(y,x)
  511. ;
  512. clear y,x,u,v;
  513. clear op;
  514. ;
  515. % DISPLAY and CLEARING of user's objects of various types entered
  516. % to the console. Only TOP LEVEL assignments are considered up to now.
  517. % The following statements must be made INTERACTIVELY. We put them
  518. % as COMMENTS for the user to experiment with them. We do this because
  519. % in a fresh environment all outputs are nil.
  520. ;
  521. % THIS PART OF THE TEST SHOULD BE REALIZED INTERACTIVELY.
  522. % SEE THE ** ASSIST LOG ** FILE .
  523. %v1:=v2:=1;
  524. %show scalars;
  525. %aa:=list(a);
  526. %show lists;
  527. %array ar(2);
  528. %show arrays;
  529. %load matr$
  530. %matrix mm;
  531. %show matrices;
  532. %x**2;
  533. %saveas res;
  534. %show saveids;
  535. %suppress scalars;
  536. %show scalars;
  537. %show lists;
  538. %suppress all;
  539. %show arrays;
  540. %show matrices;
  541. ;
  542. comment end of the interactive part;
  543. ;
  544. clear op;
  545. operator op;
  546. op(x,y,z);
  547. op(x,y,s1)
  548. clearop op;
  549. t
  550. clearfunctions abs,tan;
  551. *** abs is unprotected : Cleared ***
  552. *** tan is a protected function: NOT cleared ***
  553. "Clearing is complete"
  554. ;
  555. comment THIS FUNCTION MUST BE USED WITH CARE !!"!!!;
  556. ;
  557. Comment 10. HANDLING OF POLYNOMIALS
  558. clear x,y,z;
  559. COMMENT To see the internal representation :;
  560. ;
  561. off pri;
  562. ;
  563. pol:=(x-2*y+3*z**2-1)**3;
  564. 3 2 2 2 2 4
  565. pol := x + ( - 6*y + 9*s1 - 3)*x + (12*y + ( - 36*s1 + 12)*y + 27*s1 - 18*
  566. 2 3 2 2 4 2
  567. s1 + 3)*x - 8*y + (36*s1 - 12)*y + ( - 54*s1 + 36*s1 - 6)*y + 27*s1
  568. 6 4 2
  569. - 27*s1 + 9*s1 - 1
  570. ;
  571. pold:=distribute pol;
  572. 6 4 2 3 2 2 2 2 2
  573. pold := 27*s1 - 27*s1 + 9*s1 + x - 6*y*x + 9*s1 *x - 3*x + 12*y *x + 27*
  574. 4 2 2 3 2 2 2
  575. s1 *x - 18*s1 *x - 36*s1 *y*x + 12*y*x + 3*x - 8*y + 36*s1 *y - 12*y
  576. 4 2
  577. - 54*s1 *y + 36*s1 *y - 6*y - 1
  578. ;
  579. on distribute;
  580. leadterm (pold);
  581. 6
  582. 27*s1
  583. pold:=redexpr pold;
  584. 4 2 3 2 2 2 2 2 4
  585. pold := - 27*s1 + 9*s1 + x - 6*y*x + 9*s1 *x - 3*x + 12*y *x + 27*s1 *x -
  586. 2 2 3 2 2 2
  587. 18*s1 *x - 36*s1 *y*x + 12*y*x + 3*x - 8*y + 36*s1 *y - 12*y - 54*s1
  588. 4 2
  589. *y + 36*s1 *y - 6*y - 1
  590. leadterm pold;
  591. 4
  592. - 27*s1
  593. ;
  594. off distribute;
  595. polp:=pol$
  596. leadterm polp;
  597. 3
  598. x
  599. polp:=redexpr polp;
  600. 2 2 2 2 4 2
  601. polp := ( - 6*y + 9*s1 - 3)*x + (12*y + ( - 36*s1 + 12)*y + 27*s1 - 18*s1
  602. 3 2 2 4 2 6
  603. + 3)*x - 8*y + (36*s1 - 12)*y + ( - 54*s1 + 36*s1 - 6)*y + 27*s1 -
  604. 4 2
  605. 27*s1 + 9*s1 - 1
  606. leadterm polp;
  607. 2 2
  608. ( - 6*y + 9*s1 - 3)*x
  609. ;
  610. monom polp;
  611. 6
  612. {27*s1 ,
  613. 4
  614. - 27*s1 ,
  615. 2
  616. 9*s1 ,
  617. 2
  618. - 6*y*x ,
  619. 2 2
  620. 9*s1 *x ,
  621. 2
  622. - 3*x ,
  623. 2
  624. 12*y *x,
  625. 4
  626. 27*s1 *x,
  627. 2
  628. - 18*s1 *x,
  629. 2
  630. - 36*s1 *y*x,
  631. 12*y*x,
  632. 3*x,
  633. 3
  634. - 8*y ,
  635. 2 2
  636. 36*s1 *y ,
  637. 2
  638. - 12*y ,
  639. 4
  640. - 54*s1 *y,
  641. 2
  642. 36*s1 *y,
  643. - 6*y,
  644. -1}
  645. ;
  646. on pri;
  647. ;
  648. splitterms polp;
  649. 2 2
  650. {{9*s1 *x ,
  651. 2
  652. 12*x*y ,
  653. 12*x*y,
  654. 4
  655. 27*s1 *x,
  656. 3*x,
  657. 2 2
  658. 36*s1 *y ,
  659. 2
  660. 36*s1 *y,
  661. 6
  662. 27*s1 ,
  663. 2
  664. 9*s1 },
  665. 2
  666. {6*x *y,
  667. 2
  668. 3*x ,
  669. 2
  670. 36*s1 *x*y,
  671. 2
  672. 18*s1 *x,
  673. 3
  674. 8*y ,
  675. 2
  676. 12*y ,
  677. 4
  678. 54*s1 *y,
  679. 6*y,
  680. 4
  681. 27*s1 ,
  682. 1}}
  683. ;
  684. splitplusminus polp;
  685. 6 4 2 2 2 2 2 2 2
  686. {3*(9*s1 + 9*s1 *x + 3*s1 *x + 12*s1 *y + 12*s1 *y + 3*s1 + 4*x*y + 4*x*y
  687. + x),
  688. 4 4 2 2 2 2 3 2
  689. - 54*s1 *y - 27*s1 - 36*s1 *x*y - 18*s1 *x - 6*x *y - 3*x - 8*y - 12*y
  690. - 6*y - 1}
  691. ;
  692. divpol(pol,x+2*y+3*z**2);
  693. 4 2 2 2 2 2
  694. {9*s1 + 6*s1 *x - 24*s1 *y - 9*s1 + x - 8*x*y - 3*x + 28*y + 18*y + 3,
  695. 3 2
  696. - 64*y - 48*y - 12*y - 1}
  697. ;
  698. lowestdeg(pol,y);
  699. 0
  700. ;
  701. Comment 11. HANDLING OF SOME TRANSCENDENTAL FUNCTIONS:;
  702. ;
  703. trig:=((sin x)**2+(cos x)**2)**4;
  704. trig :=
  705. 8 6 2 4 4 2 6 8
  706. cos(x) + 4*cos(x) *sin(x) + 6*cos(x) *sin(x) + 4*cos(x) *sin(x) + sin(x)
  707. trigreduce trig;
  708. 1
  709. trig:=sin (5x);
  710. trig := sin(5*x)
  711. trigexpand trig;
  712. 4 2 2 4
  713. sin(x)*(5*cos(x) - 10*cos(x) *sin(x) + sin(x) )
  714. trigreduce ws;
  715. sin(5*x)
  716. trigexpand sin(x+y+z);
  717. cos(s1)*cos(x)*sin(y) + cos(s1)*cos(y)*sin(x) + cos(x)*cos(y)*sin(s1)
  718. - sin(s1)*sin(x)*sin(y)
  719. ;
  720. ;
  721. hypreduce (sinh x **2 -cosh x **2);
  722. -1
  723. ;
  724. ;
  725. clear a,b,c,d;
  726. ;
  727. Comment 12. COERCION FROM ARRAY TO LIST AND VICE-VERSA:;
  728. on rounded;
  729. array_to_list ar;
  730. {2.77546499305,1.79693268486,3.43100115041,2.11636272025,3.45447023392}
  731. ;
  732. off rounded;
  733. ll:={{a,b},{b,c},{c,d}}$
  734. list_to_array(ll,1,ar);
  735. *** array ar redefined
  736. ar(1);
  737. {b,c}
  738. list_to_array(ll,2,ar);
  739. *** array ar redefined
  740. ar(1,1);
  741. c
  742. ;
  743. clear ar;
  744. ;
  745. Comment 13. HANDLING OF N-DIMENSIONAL VECTORS:;
  746. ;
  747. clear u1,u2,v1,v2,v3,v4,w3,w4;
  748. u1:=list(v1,v2,v3,v4);
  749. u1 := {v1,v2,v3,v4}
  750. u2:=bag(w1,w2,w3,w4);
  751. u2 := bag(w1,w2,w3,w4)
  752. %
  753. sumvect(u1,u2);
  754. {v1 + w1,
  755. v2 + w2,
  756. v3 + w3,
  757. v4 + w4}
  758. minvect(u2,u1);
  759. bag( - v1 + w1, - v2 + w2, - v3 + w3, - v4 + w4)
  760. scalvect(u1,u2);
  761. v1*w1 + v2*w2 + v3*w3 + v4*w4
  762. crossvect(rest u1,rest u2);
  763. {v3*w4 - v4*w3,
  764. - v2*w4 + v4*w2,
  765. v2*w3 - v3*w2}
  766. mpvect(rest u1,rest u2, minvect(rest u1,rest u2));
  767. 0
  768. scalvect(crossvect(rest u1,rest u2),minvect(rest u1,rest u2));
  769. 0
  770. ;
  771. Comment 14. HANDLING OF GRASSMANN OPERATORS:;
  772. ;
  773. putgrass eta,eta1;
  774. grasskernel:=
  775. {eta(~x)*eta(~y) => -eta y * eta x when nordp(x,y),
  776. (~x)*(~x) => 0 when grassp x};
  777. grasskernel := {eta(~x)*eta(~y) => - eta(y)*eta(x) when nordp(x,y),
  778. ~x*~x => 0 when grassp(x)}
  779. ;
  780. eta(y)*eta(x);
  781. eta(y)*eta(x)
  782. eta(y)*eta(x) where grasskernel;
  783. - eta(x)*eta(y)
  784. let grasskernel;
  785. eta(x)^2;
  786. 0
  787. eta(y)*eta(x);
  788. - eta(x)*eta(y)
  789. operator zz;
  790. grassparity (eta(x)*zz(y));
  791. 1
  792. grassparity (eta(x)*eta(y));
  793. 0
  794. grassparity(eta(x)+zz(y));
  795. parity undefined
  796. clearrules grasskernel;
  797. grasskernel:=
  798. {eta(~x)*eta(~y) => -eta y * eta x when nordp(x,y),
  799. eta1(~x)*eta(~y) => -eta x * eta1 y,
  800. eta1(~x)*eta1(~y) => -eta1 y * eta1 x when nordp(x,y),
  801. (~x)*(~x) => 0 when grassp x};
  802. grasskernel := {eta(~x)*eta(~y) => - eta(y)*eta(x) when nordp(x,y),
  803. eta1(~x)*eta(~y) => - eta(x)*eta1(y),
  804. eta1(~x)*eta1(~y) => - eta1(y)*eta1(x) when nordp(x,y),
  805. ~x*~x => 0 when grassp(x)}
  806. ;
  807. let grasskernel;
  808. eta1(x)*eta(x)*eta1(z)*eta1(w);
  809. - eta(x)*eta1(s1)*eta1(w)*eta1(x)
  810. clearrules grasskernel;
  811. remgrass eta,eta1;
  812. clearop zz;
  813. t
  814. ;
  815. Comment 15. HANDLING OF MATRICES:;
  816. ;
  817. clear m,mm,b,b1,bb,cc,a,b,c,d,a1,a2;
  818. load_package matrix;
  819. baglmat(bag(bag(a1,a2)),m);
  820. t
  821. m;
  822. [a1 a2]
  823. on errcont;
  824. ;
  825. baglmat(bag(bag(a1),bag(a2)),m);
  826. ***** (mat ((*sq ((((a1 . 1) . 1)) . 1) t) (*sq ((((a2 . 1) . 1)) . 1) t)))
  827. should be an identifier
  828. off errcont;
  829. % **** i.e. it cannot redefine the matrix! in order
  830. % to avoid accidental redefinition of an already given matrix;
  831. clear m;
  832. baglmat(bag(bag(a1),bag(a2)),m);
  833. t
  834. m;
  835. [a1]
  836. [ ]
  837. [a2]
  838. on errcont;
  839. baglmat(bag(bag(a1),bag(a2)),bag);
  840. ***** operator bag invalid as matrix
  841. off errcont;
  842. comment Right since a bag-like object cannot become a matrix.;
  843. ;
  844. coercemat(m,op);
  845. op(op(a1),op(a2))
  846. coercemat(m,list);
  847. {{a1},{a2}}
  848. ;
  849. on nero;
  850. unitmat b1(2);
  851. matrix b(2,2);
  852. b:=mat((r1,r2),(s1,s2));
  853. [r1 r2]
  854. b := [ ]
  855. [s1 s2]
  856. b1;
  857. [1 0]
  858. [ ]
  859. [0 1]
  860. b;
  861. [r1 r2]
  862. [ ]
  863. [s1 s2]
  864. mkidm(b,1);
  865. [1 0]
  866. [ ]
  867. [0 1]
  868. ;
  869. seteltmat(b,newelt,2,2);
  870. [r1 r2 ]
  871. [ ]
  872. [s1 newelt]
  873. geteltmat(b,2,1);
  874. s1
  875. %
  876. b:=matsubr(b,bag(1,2),2);
  877. [r1 r2]
  878. b := [ ]
  879. [1 2 ]
  880. ;
  881. submat(b,1,2);
  882. [1]
  883. ;
  884. bb:=mat((1+i,-i),(-1+i,-i));
  885. [i + 1 - i]
  886. bb := [ ]
  887. [i - 1 - i]
  888. cc:=matsubc(bb,bag(1,2),2);
  889. [i + 1 1]
  890. cc := [ ]
  891. [i - 1 2]
  892. ;
  893. cc:=tp matsubc(bb,bag(1,2),2);
  894. [i + 1 i - 1]
  895. cc := [ ]
  896. [ 1 2 ]
  897. matextr(bb, bag,1);
  898. bag(i + 1, - i)
  899. ;
  900. matextc(bb,list,2);
  901. { - i, - i}
  902. ;
  903. hconcmat(bb,cc);
  904. [i + 1 - i i + 1 i - 1]
  905. [ ]
  906. [i - 1 - i 1 2 ]
  907. vconcmat(bb,cc);
  908. [i + 1 - i ]
  909. [ ]
  910. [i - 1 - i ]
  911. [ ]
  912. [i + 1 i - 1]
  913. [ ]
  914. [ 1 2 ]
  915. ;
  916. tpmat(bb,bb);
  917. [ 2*i - i + 1 - i + 1 -1]
  918. [ ]
  919. [ -2 - i + 1 i + 1 -1]
  920. [ ]
  921. [ -2 i + 1 - i + 1 -1]
  922. [ ]
  923. [ - 2*i i + 1 i + 1 -1]
  924. bb tpmat bb;
  925. [ 2*i - i + 1 - i + 1 -1]
  926. [ ]
  927. [ -2 - i + 1 i + 1 -1]
  928. [ ]
  929. [ -2 i + 1 - i + 1 -1]
  930. [ ]
  931. [ - 2*i i + 1 i + 1 -1]
  932. ;
  933. clear hbb;
  934. hermat(bb,hbb);
  935. [ - i + 1 - (i + 1)]
  936. [ ]
  937. [ i i ]
  938. % id hbb changed to a matrix id and assigned to the hermitian matrix
  939. % of bb.
  940. ;
  941. end;
  942. (TIME: assist 940 950)