assist.rlg 25 KB

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