assist.tst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. % Test of Assist Package version 2.31.
  2. % DATE : 30 August 1996
  3. % Author: H. Caprasse <hubert.caprasse@ulg.ac.be>
  4. %load_package assist$
  5. Comment 2. HELP for ASSIST:;
  6. ;
  7. assist();
  8. ;
  9. assisthelp(7);
  10. ;
  11. Comment 3. CONTROL OF SWITCHES:;
  12. ;
  13. switches;
  14. off exp; on gcd; off precise;
  15. switches;
  16. switchorg;
  17. switches;
  18. ;
  19. if !*mcd then "the switch mcd is on";
  20. if !*gcd then "the switch gcd is on";
  21. ;
  22. Comment 4. MANIPULATION OF THE LIST STRUCTURE:;
  23. ;
  24. t1:=mklist(5);
  25. Comment MKLIST does NEVER destroy anything ;
  26. mklist(t1,10);
  27. mklist(t1,3);
  28. ;
  29. sequences 3;
  30. lisp;
  31. sequences 3;
  32. algebraic;
  33. ;
  34. for i:=1:5 do t1:= (t1.i:=mkid(a,i));
  35. t1;
  36. ;
  37. t1.5;
  38. ;
  39. t1:=(t1.3).t1;
  40. ;
  41. % Notice the blank spaces ! in the following illustration:
  42. 1 . t1;
  43. ;
  44. % Splitting of a list:
  45. split(t1,{1,2,3});
  46. ;
  47. % It truncates the list :
  48. split(t1,{3});
  49. ;
  50. % A KERNEL may be coerced to a list:
  51. kernlist sin x;
  52. ;
  53. % algnlist constructs a list which contains n-times a given list
  54. algnlist(t1,2);
  55. ;
  56. % Delete :
  57. delete(x, {a,b,x,f,x});
  58. ;
  59. % delete_all eliminates ALL occurences of x:
  60. delete_all(x,{a,b,x,f,x});
  61. ;
  62. remove(t1,4);
  63. ;
  64. % delpair deletes a pair if it is possible.
  65. delpair(a1,pair(t1,t1));
  66. ;
  67. elmult(a1,t1);
  68. ;
  69. frequency append(t1,t1);
  70. ;
  71. insert(a1,t1,3);
  72. ;
  73. li:=list(1,2,5);
  74. ;
  75. % Not to destroy an already ordered list during insertion:
  76. insert_keep_order(4,li,lessp);
  77. insert_keep_order(bb,t1,ordp);
  78. ;
  79. % the same function when appending two correctly ORDERED lists:
  80. merge_list(li,li,<);
  81. ;
  82. merge_list({5,2,1},{5,2,1},geq);
  83. ;
  84. depth list t1;
  85. ;
  86. depth a1;
  87. % Any list can be flattened into a list of depth 1:
  88. mkdepth_one {1,{{a,b,c}},{c,{{d,e}}}};
  89. position(a2,t1);
  90. appendn(li,li,li);
  91. ;
  92. clear t1,li;
  93. comment 5. THE BAG STRUCTURE AND OTHER FUNCTION FOR LISTS AND BAGS.
  94. ;
  95. aa:=bag(x,1,"A");
  96. putbag bg1,bg2;
  97. on errcont;
  98. putbag list;
  99. off errcont;
  100. aa:=bg1(x,y**2);
  101. ;
  102. if bagp aa then "this is a bag";
  103. ;
  104. % A bag is a composite object:
  105. clearbag bg2;
  106. ;
  107. depth bg2(x);
  108. ;
  109. depth bg1(x);
  110. ;
  111. if baglistp aa then "this is a bag or list";
  112. if baglistp {x} then "this is a bag or list";
  113. if bagp {x} then "this is a bag";
  114. if bagp aa then "this is a bag";
  115. ;
  116. ab:=bag(x1,x2,x3);
  117. al:=list(y1,y2,y3);
  118. % The basic lisp functions are also active for bags:
  119. first ab; third ab; first al;
  120. last ab; last al;
  121. belast ab; belast al; belast {a,b,a,b,a};
  122. rest ab; rest al;
  123. ;
  124. % The "dot" plays the role of the function "part":
  125. ab.1; al.3;
  126. on errcont;
  127. ab.4;
  128. off errcont;
  129. a.ab;
  130. % ... but notice
  131. 1 . ab;
  132. % Coercion from bag to list and list to bag:
  133. kernlist(aa);
  134. ;
  135. listbag(list x,bg1);
  136. ;
  137. length ab;
  138. ;
  139. remove(ab,3);
  140. ;
  141. delete(y2,al);
  142. ;
  143. reverse al;
  144. ;
  145. member(x3,ab);
  146. ;
  147. al:=list(x**2,x**2,y1,y2,y3);
  148. ;
  149. elmult(x**2,al);
  150. ;
  151. position(y3,al);
  152. ;
  153. repfirst(xx,al);
  154. ;
  155. represt(xx,ab);
  156. ;
  157. insert(x,al,3);
  158. insert( b,ab,2);
  159. insert(ab,ab,1);
  160. ;
  161. substitute (new,y1,al);
  162. ;
  163. appendn(ab,ab,ab);
  164. ;
  165. append(ab,al);
  166. append(al,ab);
  167. clear ab; a1;
  168. ;comment Association list or bag may be constructed and thoroughly used;
  169. ;
  170. l:=list(a1,a2,a3,a4);
  171. b:=bg1(x1,x2,x3);
  172. al:=pair(list(1,2,3,4),l);
  173. ab:=pair(bg1(1,2,3),b);
  174. ;
  175. clear b;
  176. comment : A BOOLEAN function abaglistp to test if it is an association;
  177. ;
  178. if abaglistp bag(bag(1,2)) then "it is an associated bag";
  179. ;
  180. % Values associated to the keys can be extracted
  181. % first occurence ONLY.
  182. ;
  183. asfirst(1,al);
  184. asfirst(3,ab);
  185. ;
  186. assecond(a1,al);
  187. assecond(x3,ab);
  188. ;
  189. aslast(z,list(list(x1,x2,x3),list(y1,y2,z)));
  190. asrest(list(x2,x3),list(list(x1,x2,x3),list(y1,y2,z)));
  191. ;
  192. clear a1;
  193. ;
  194. % All occurences.
  195. asflist(x,bg1(bg1(x,a1,a2),bg1(x,b1,b2)));
  196. asslist(a1,list(list(x,a1),list(y,a1),list(x,y)));
  197. restaslist(bag(a1,x),bg1(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
  198. restaslist(list(a1,x),bag(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
  199. ;
  200. Comment 6. SETS AND THEIR MANIPULATION FUNCTIONS
  201. ;
  202. ts:=mkset list(a1,a1,a,2,2);
  203. if setp ts then "this is a SET";
  204. ;
  205. union(ts,ts);
  206. ;
  207. diffset(ts,list(a1,a));
  208. diffset(list(a1,a),ts);
  209. ;
  210. symdiff(ts,ts);
  211. ;
  212. intersect(listbag(ts,set1),listbag(ts,set2));
  213. Comment 7. GENERAL PURPOSE UTILITY FUNCTIONS :;
  214. ;
  215. clear a1,a2,a3,a,x,y,z,x1,x2,op$
  216. ;
  217. % DETECTION OF A GIVEN VARIABLE IN A GIVEN SET
  218. ;
  219. mkidnew();
  220. mkidnew(a);
  221. ;
  222. dellastdigit 23;
  223. ;
  224. detidnum aa;
  225. detidnum a10;
  226. detidnum a1b2z34;
  227. ;
  228. list_to_ids list(a,1,rr,22);
  229. ;
  230. if oddp 3 then "this is an odd integer";
  231. ;
  232. <<prin2 1; followline 7; prin2 8;>>;
  233. ;
  234. operator foo;
  235. foo(x):=x;
  236. foo(x)==value;
  237. x; % it is equal to value
  238. clear x;
  239. ;
  240. randomlist(10,20);
  241. % Generation of tables of random numbers:
  242. % One dimensional:
  243. mkrandtabl({4},10,ar);
  244. array_to_list ar;
  245. ;
  246. % Two dimensional:
  247. mkrandtabl({3,4},10,ar);
  248. array_to_list ar;
  249. ;
  250. % With a base which is a decimal number:
  251. on rounded;
  252. mkrandtabl({5},3.5,ar);
  253. array_to_list ar;
  254. off rounded;
  255. ;
  256. % Combinatorial functions :
  257. permutations(bag(a1,a2,a3));
  258. permutations {1,2,3};
  259. ;
  260. cyclicpermlist{1,2,3};
  261. ;
  262. combnum(8,3);
  263. ;
  264. combinations({1,2,3},2);
  265. ;
  266. perm_to_num({3,2,1,4},{1,2,3,4});
  267. num_to_perm(5,{1,2,3,4});
  268. ;
  269. operator op;
  270. symmetric op;
  271. op(x,y)-op(y,x);
  272. remsym op;
  273. op(x,y)-op(y,x);
  274. ;
  275. labc:={a,b,c};
  276. symmetrize(labc,foo,cyclicpermlist);
  277. symmetrize(labc,list,permutations);
  278. symmetrize({labc},foo,cyclicpermlist);
  279. ;
  280. extremum({1,2,3},lessp);
  281. extremum({1,2,3},geq);
  282. extremum({a,b,c},nordp);
  283. ;
  284. funcvar(x+y);
  285. funcvar(sin log(x+y));
  286. funcvar(sin pi);
  287. funcvar(x+e+i);
  288. funcvar sin(x+i*y);
  289. ;
  290. operator op;
  291. noncom op;
  292. op(0)*op(x)-op(x)*op(0);
  293. remnoncom op;
  294. op(0)*op(x)-op(x)*op(0);
  295. clear op;
  296. ;
  297. depatom a;
  298. depend a,x,y;
  299. depatom a;
  300. ;
  301. depend op,x,y,z;
  302. ;
  303. implicit op;
  304. explicit op;
  305. depend y,zz;
  306. explicit op;
  307. aa:=implicit op;
  308. clear op;
  309. ;
  310. korder x,z,y;
  311. korderlist;
  312. ;
  313. if checkproplist({1,2,3},fixp) then "it is a list of integers";
  314. ;
  315. if checkproplist({a,b1,c},idp) then "it is a list of identifiers";
  316. ;
  317. if checkproplist({1,b1,c},idp) then "it is a list of identifiers";
  318. ;
  319. lmix:={1,1/2,a,"st"};
  320. ;
  321. extractlist(lmix,fixp);
  322. extractlist(lmix,numberp);
  323. extractlist(lmix,idp);
  324. extractlist(lmix,stringp);
  325. ;
  326. % From a list to an array:
  327. list_to_array({a,b,c,d},1,ar);
  328. array_to_list ar;
  329. list_to_array({{a},{b},{c},{d}},2,ar);
  330. ;
  331. comment 8. PROPERTIES AND FLAGS:;
  332. ;
  333. putflag(list(a1,a2),fl1,t);
  334. putflag(list(a1,a2),fl2,t);
  335. displayflag a1;
  336. ;
  337. clearflag a1,a2;
  338. displayflag a2;
  339. putprop(x1,propname,value,t);
  340. displayprop(x1,prop);
  341. displayprop(x1,propname);
  342. ;
  343. putprop(x1,propname,value,0);
  344. displayprop(x1,propname);
  345. ;
  346. Comment 9. CONTROL FUNCTIONS:;
  347. ;
  348. alatomp z;
  349. z:=s1;
  350. alatomp z;
  351. ;
  352. alkernp z;
  353. alkernp log sin r;
  354. ;
  355. precp(difference,plus);
  356. precp(plus,difference);
  357. precp(times,.);
  358. precp(.,times);
  359. ;
  360. if stringp x then "this is a string";
  361. if stringp "this is a string" then "this is a string";
  362. ;
  363. if nordp(b,a) then "a is ordered before b";
  364. operator op;
  365. for all x,y such that nordp(x,y) let op(x,y)=x+y;
  366. op(a,a);
  367. op(b,a);
  368. op(a,b);
  369. clear op;
  370. ;
  371. depvarp(log(sin(x+cos(1/acos rr))),rr);
  372. ;
  373. clear y,x,u,v;
  374. clear op;
  375. ;
  376. % DISPLAY and CLEARING of user's objects of various types entered
  377. % to the console. Only TOP LEVEL assignments are considered up to now.
  378. % The following statements must be made INTERACTIVELY. We put them
  379. % as COMMENTS for the user to experiment with them. We do this because
  380. % in a fresh environment all outputs are nil.
  381. ;
  382. % THIS PART OF THE TEST SHOULD BE REALIZED INTERACTIVELY.
  383. % SEE THE ** ASSIST LOG ** FILE .
  384. %v1:=v2:=1;
  385. %show scalars;
  386. %aa:=list(a);
  387. %show lists;
  388. %array ar(2);
  389. %show arrays;
  390. %load matr$
  391. %matrix mm;
  392. %show matrices;
  393. %x**2;
  394. %saveas res;
  395. %show saveids;
  396. %suppress scalars;
  397. %show scalars;
  398. %show lists;
  399. %suppress all;
  400. %show arrays;
  401. %show matrices;
  402. ;
  403. comment end of the interactive part;
  404. ;
  405. clear op;
  406. operator op;
  407. op(x,y,z);
  408. clearop op;
  409. ;
  410. clearfunctions abs,tan;
  411. ;
  412. comment THIS FUNCTION MUST BE USED WITH CARE !!!!!;
  413. ;
  414. Comment 10. HANDLING OF POLYNOMIALS
  415. clear x,y,z;
  416. COMMENT To see the internal representation :;
  417. ;
  418. off pri;
  419. ;
  420. pol:=(x-2*y+3*z**2-1)**3;
  421. ;
  422. pold:=distribute pol;
  423. ;
  424. on distribute;
  425. leadterm (pold);
  426. pold:=redexpr pold;
  427. leadterm pold;
  428. ;
  429. off distribute;
  430. polp:=pol$
  431. leadterm polp;
  432. polp:=redexpr polp;
  433. leadterm polp;
  434. ;
  435. monom polp;
  436. ;
  437. on pri;
  438. ;
  439. splitterms polp;
  440. ;
  441. splitplusminus polp;
  442. ;
  443. divpol(pol,x+2*y+3*z**2);
  444. ;
  445. lowestdeg(pol,y);
  446. ;
  447. Comment 11. HANDLING OF SOME TRANSCENDENTAL FUNCTIONS:;
  448. ;
  449. trig:=((sin x)**2+(cos x)**2)**4;
  450. trigreduce trig;
  451. trig:=sin (5x);
  452. trigexpand trig;
  453. trigreduce ws;
  454. trigexpand sin(x+y+z);
  455. ;
  456. ;
  457. hypreduce (sinh x **2 -cosh x **2);
  458. ;
  459. ;
  460. clear a,b,c,d;
  461. ;
  462. Comment 13. HANDLING OF N-DIMENSIONAL VECTORS:;
  463. ;
  464. clear u1,u2,v1,v2,v3,v4,w3,w4;
  465. u1:=list(v1,v2,v3,v4);
  466. u2:=bag(w1,w2,w3,w4);
  467. %
  468. sumvect(u1,u2);
  469. minvect(u2,u1);
  470. scalvect(u1,u2);
  471. crossvect(rest u1,rest u2);
  472. mpvect(rest u1,rest u2, minvect(rest u1,rest u2));
  473. scalvect(crossvect(rest u1,rest u2),minvect(rest u1,rest u2));
  474. ;
  475. Comment 14. HANDLING OF GRASSMANN OPERATORS:;
  476. ;
  477. putgrass eta,eta1;
  478. grasskernel:=
  479. {eta(~x)*eta(~y) => -eta y * eta x when nordp(x,y),
  480. (~x)*(~x) => 0 when grassp x};
  481. ;
  482. eta(y)*eta(x);
  483. eta(y)*eta(x) where grasskernel;
  484. let grasskernel;
  485. eta(x)^2;
  486. eta(y)*eta(x);
  487. operator zz;
  488. grassparity (eta(x)*zz(y));
  489. grassparity (eta(x)*eta(y));
  490. grassparity(eta(x)+zz(y));
  491. clearrules grasskernel;
  492. grasskernel:=
  493. {eta(~x)*eta(~y) => -eta y * eta x when nordp(x,y),
  494. eta1(~x)*eta(~y) => -eta x * eta1 y,
  495. eta1(~x)*eta1(~y) => -eta1 y * eta1 x when nordp(x,y),
  496. (~x)*(~x) => 0 when grassp x};
  497. ;
  498. let grasskernel;
  499. eta1(x)*eta(x)*eta1(z)*eta1(w);
  500. clearrules grasskernel;
  501. remgrass eta,eta1;
  502. clearop zz;
  503. ;
  504. Comment 15. HANDLING OF MATRICES:;
  505. ;
  506. clear m,mm,b,b1,bb,cc,a,b,c,d,a1,a2;
  507. load_package matrix;
  508. baglmat(bag(bag(a1,a2)),m);
  509. m;
  510. on errcont;
  511. ;
  512. baglmat(bag(bag(a1),bag(a2)),m);
  513. off errcont;
  514. % **** i.e. it cannot redefine the matrix! in order
  515. % to avoid accidental redefinition of an already given matrix;
  516. clear m; baglmat(bag(bag(a1),bag(a2)),m);
  517. m;
  518. on errcont;
  519. baglmat(bag(bag(a1),bag(a2)),bag);
  520. off errcont;
  521. comment Right since a bag-like object cannot become a matrix.;
  522. ;
  523. coercemat(m,op);
  524. coercemat(m,list);
  525. ;
  526. on nero;
  527. unitmat b1(2);
  528. matrix b(2,2);
  529. b:=mat((r1,r2),(s1,s2));
  530. b1;b;
  531. mkidm(b,1);
  532. ;
  533. seteltmat(b,newelt,2,2);
  534. geteltmat(b,2,1);
  535. %
  536. b:=matsubr(b,bag(1,2),2);
  537. ;
  538. submat(b,1,2);
  539. ;
  540. bb:=mat((1+i,-i),(-1+i,-i));
  541. cc:=matsubc(bb,bag(1,2),2);
  542. ;
  543. cc:=tp matsubc(bb,bag(1,2),2);
  544. matextr(bb, bag,1);
  545. ;
  546. matextc(bb,list,2);
  547. ;
  548. hconcmat(bb,cc);
  549. vconcmat(bb,cc);
  550. ;
  551. tpmat(bb,bb);
  552. bb tpmat bb;
  553. ;
  554. clear hbb;
  555. hermat(bb,hbb);
  556. % id hbb changed to a matrix id and assigned to the hermitian matrix
  557. % of bb.
  558. ;
  559. load_package HEPHYS;
  560. % Use of remvector.
  561. ;
  562. vector v1,v2;
  563. v1.v2;
  564. remvector v1,v2;
  565. on errcont;
  566. v1.v2;
  567. off errcont;
  568. % To see the compatibility with ASSIST:
  569. v1.{v2};
  570. ;
  571. index u; vector v;
  572. (v.u)^2;
  573. remindex u;
  574. (v.u)^2;
  575. ;
  576. % Gamma matrices properties may be translated to any identifier:
  577. clear l,v;
  578. vector v;
  579. g(l,v,v);
  580. mkgam(op,t);
  581. op(l,v,v);
  582. mkgam(g,0);
  583. operator g;
  584. g(l,v,v);
  585. ;
  586. clear g,op;
  587. ;
  588. % showtime;
  589. end;