assist.tst 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. % Tests of Assist Package version 2.0 for REDUCE 3.4 and 3.4.1.
  2. % DATE : 30 May 1993
  3. % Author: H. Caprasse <caprasse@vm1.ulg.ac.be>
  4. showtime;
  5. Comment 1. CONTROL OF SWITCHES;
  6. ;
  7. switches;
  8. off exp; on gcd;
  9. switches;
  10. switchorg;
  11. switches;
  12. ;
  13. if !*mcd then "the switch mcd is on";
  14. if !*gcd then "the switch gcd is on";
  15. ;
  16. comment 2. MANIPULATION OF THE LIST STRUCTURE:;
  17. ;
  18. t1:=mklist(4);
  19. Comment MKLIST does NEVER destroy anything ;
  20. mklist(t1,3);
  21. mklist(t1,10);
  22. ;
  23. sequences 3;
  24. lisp;
  25. sequences 3;
  26. algebraic;
  27. frequency append(t1,t1);
  28. elmult(a1,t1);
  29. insert(a1,t1,2);
  30. li:=list(1,2,5);
  31. insert_keep_order(4,li,lessp);
  32. merge_list(li,li,lessp);
  33. for i:=1:4 do t1:= (t1.i:=mkid(a,i));
  34. % for i:=1:2 do t1:=(t1.i:=mkid(a,i));
  35. t1.1;
  36. t1:=(t1.1) . t1;
  37. position(a2,t1);
  38. pair(t1,t1);
  39. depth list t1;
  40. depth a1;
  41. appendn(li,li,li);
  42. ;
  43. comment 3. THE BAG STRUCTURE AND ITS ASSOCIATED FUNCTIONS
  44. ;
  45. aa:=bag(x,1,"A");
  46. putbag bg1,bg2;
  47. on errcont;
  48. putbag list;
  49. off errcont;
  50. aa:=bg1(x,y**2);
  51. ;
  52. if bagp aa then "this is a bag";
  53. ;
  54. clearbag bg2;
  55. ;
  56. depth bg2(x);
  57. ;
  58. if baglistp aa then "this is a bag or list";
  59. if baglistp list(x) then "this is a bag or list";
  60. ;
  61. ab:=bag(x1,x2,x3);
  62. al:=list(y1,y2,y3);
  63. first ab; third ab; first al;
  64. last ab; last al;
  65. belast ab; belast al;
  66. rest ab; rest al;
  67. depth al; depth bg1(ab);
  68. ;
  69. ab.1; al.3;
  70. on errcont;
  71. ab.4;
  72. off errcont;
  73. kernlist(aa);
  74. listbag(list x,bg1);
  75. size ab; length al;
  76. remove(ab,3);
  77. delete(y2,al);
  78. reverse al;
  79. member(x3,ab);
  80. al:=list(x**2,x**2,y1,y2,y3);
  81. ;
  82. elmult(x**2,al);
  83. position(y3,al);
  84. ;
  85. repfirst(xx,al);
  86. represt(xx,ab);
  87. insert(x,al,3);
  88. insert( b,ab,2);
  89. insert(ab,ab,1);
  90. substitute (new,y1,al);
  91. ;
  92. appendn(ab,ab,ab);
  93. append(ab,al);
  94. append(al,ab);
  95. ;
  96. comment Association list or bag may be constructed and thoroughly used;
  97. ;
  98. l:=list(a1,a2,a3,a4);
  99. b:=bg1(x1,x2,x3);
  100. al:=pair(list(1,2,3,4),l);
  101. ab:=pair(bg1(1,2,3),b);
  102. ;
  103. comment : A BOOLEAN function abaglistp to test if it is an association;
  104. ;
  105. if abaglistp bag(bag(1,2)) then "it is an associated bag";
  106. ;
  107. % Values associated to the keys can be extracted
  108. % first occurence ONLY.
  109. ;
  110. asfirst(1,al);
  111. asfirst(3,ab);
  112. ;
  113. assecond(a1,al);
  114. assecond(x3,ab);
  115. ;
  116. aslast(z,list(list(x1,x2,x3),list(y1,y2,z)));
  117. asrest(list(x2,x3),list(list(x1,x2,x3),list(y1,y2,z)));
  118. ;
  119. clear a1;
  120. ;
  121. % All occurences.
  122. asflist(x,bg1(bg1(x,a1,a2),bg1(x,b1,b2)));
  123. asslist(a1,list(list(x,a1),list(y,a1),list(x,y)));
  124. restaslist(bag(a1,x),bg1(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
  125. restaslist(list(a1,x),bag(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
  126. ;
  127. comment 4. SETS AND THEIR MANIPULATION FUNCTIONS
  128. ;
  129. ts:=mkset list(a1,a1,a,2,2);
  130. if setp ts then "this is a SET";
  131. ;
  132. union(ts,ts);
  133. diffset(ts,list(a1,a));
  134. diffset(list(a1,a),ts);
  135. symdiff(ts,ts);
  136. intersect(listbag(ts,set1),listbag(ts,set2));
  137. COMMENT 5. MISCELLANEOUS UTILITY FUNCTIONS :;
  138. ;
  139. clear a1,a2,a3,a,x,y,z,x1,x2,op$
  140. ;
  141. % DETECTION OF A GIVEN VARIABLE IN A GIVEN SET
  142. ;
  143. mkidnew();
  144. mkidnew(a);
  145. dellastdigit 23;
  146. detidnum aa;
  147. detidnum a10;
  148. detidnum a1b2z34;
  149. list_to_ids list(a,1,rr,22);
  150. ;
  151. if oddp 3 then "this is an odd integer";
  152. ;
  153. <<prin2 1; followline 7; prin2 8;>>;
  154. ;
  155. operator foo;
  156. foo(x):=x;
  157. foo(x)==value;
  158. x:=x;
  159. ;
  160. clear x;
  161. ;
  162. randomlist(10,20);
  163. combnum(8,3);
  164. permutations(bag(a1,a2,a3));
  165. permutations {1,2,3};
  166. cyclicpermlist{1,2,3};
  167. combinations({1,2,3},2);
  168. labc:={a,b,c};
  169. symmetrize(labc,foo,cyclicpermlist);
  170. symmetrize(labc,list,permutations);
  171. symmetrize({labc},foo,cyclicpermlist);
  172. extremum({1,2,3},lessp);
  173. extremum({1,2,3},geq);
  174. extremum({a,b,c},ordp);
  175. ;
  176. funcvar(x+y);
  177. funcvar(sin log(x+y));
  178. funcvar(sin pi);
  179. funcvar(x+e+i);
  180. ;
  181. depatom a;
  182. depend a,x,y;
  183. depatom a;
  184. depend op,x,y,z;
  185. implicit op;
  186. explicit op;
  187. depend y,zz;
  188. explicit op;
  189. aa:=implicit op;
  190. clear op;
  191. ;
  192. korder x,z,y;
  193. korderlist;
  194. ;
  195. if checkproplist({1,2,3},fixp) then "it is a list of integers";
  196. ;
  197. if checkproplist({a,b1,c},idp) then "it is a list of identifiers";
  198. ;
  199. if checkproplist({1,b1,c},idp) then "it is a list of identifiers";
  200. ;
  201. lmix:={1,1/2,a,"st"};
  202. ;
  203. extractlist(lmix,fixp);
  204. extractlist(lmix,numberp);
  205. extractlist(lmix,idp);
  206. extractlist(lmix,stringp);
  207. ;
  208. comment 6. PROPERTIES AND FLAGS:;
  209. ;
  210. putflag(list(a1,a2),fl1,t);
  211. putflag(list(a1,a2),fl2,t);
  212. displayflag a1;
  213. ;
  214. clearflag a1,a2;
  215. displayflag a2;
  216. putprop(x1,propname,value,t);
  217. displayprop(x1,prop);
  218. displayprop(x1,propname);
  219. ;
  220. putprop(x1,propname,value,0);
  221. displayprop(x1,propname);
  222. ;
  223. comment CONTROL FUNCTIONS:;
  224. ;
  225. alatomp z;
  226. z:=s1;
  227. alatomp z;
  228. ;
  229. alkernp z;
  230. alkernp log sin r;
  231. ;
  232. precp(difference,plus);
  233. precp(plus,difference);
  234. precp(times,.);
  235. precp(.,times);
  236. ;
  237. if stringp x then "this is a string";
  238. if stringp "this is a string" then "this is a string";
  239. ;
  240. if nordp(b,a) then "a is ordered before b";
  241. operator op;
  242. for all x,y such that nordp(x,y) let op(x,y)=x+y;
  243. op(a,a);
  244. op(b,a);
  245. op(a,b);
  246. clear op;
  247. ;
  248. depvarp(log(sin(x+cos(1/acos rr))),rr);
  249. ;
  250. operator op;
  251. symmetric op;
  252. op(x,y)-op(y,x);
  253. remsym op;
  254. op(x,y)-op(y,x);
  255. ;
  256. clear y,x,u,v;
  257. clear op;
  258. ;
  259. % DISPLAY and CLEARING of user's objects of various types entered
  260. % to the console. Only TOP LEVEL assignments are considered up to now.
  261. % The following statements must be made INTERACTIVELY. We put them
  262. % as COMMENTS for the user to experiment with them. We do this because
  263. % in a fresh environment all outputs are nil.
  264. ;
  265. % THIS PART OF THE TEST SHOULD BE REALIZED INTERACTIVELY.
  266. % SEE THE ** ASSIST LOG ** FILE .
  267. %v1:=v2:=1;
  268. %show variables; % For REDUCE 3.3 ONLY.
  269. %show scalars;
  270. %aa:=list(a);
  271. %show lists;
  272. %array ar(2);
  273. %show arrays;
  274. %load matr$
  275. %matrix mm;
  276. %show matrices;
  277. %x**2;
  278. %saveas res;
  279. %show saveids;
  280. %suppress variables; % For REDUCE 3.3 ONLY
  281. %show variables; % For REDUCE 3.3 ONLY
  282. %suppress scalars;
  283. %show scalars;
  284. %show lists;
  285. %suppress all;
  286. %show arrays;
  287. %show matrices;
  288. ;
  289. comment end of the interactive part;
  290. ;
  291. clear op;
  292. operator op;
  293. op(x,y,z);
  294. clearop op;
  295. clearfunctions abs,tan;
  296. ;
  297. comment THIS FUNCTION MUST BE USED WITH CARE !!"!!!;
  298. ;
  299. comment 6. HANDLING OF POLYNOMIALS
  300. clear x,y,z;
  301. COMMENT To see the internal representation :;
  302. ;
  303. off pri;
  304. ;
  305. pol:=(x-2*y+3*z**2-1)**3;
  306. ;
  307. pold:=distribute pol;
  308. ;
  309. on distribute;
  310. leadterm (pold);
  311. pold:=redexpr pold;
  312. leadterm pold;
  313. ;
  314. off distribute;
  315. polp:=pol$
  316. leadterm polp;
  317. polp:=redexpr polp;
  318. leadterm polp;
  319. ;
  320. monom polp;
  321. ;
  322. on pri;
  323. ;
  324. splitterms polp;
  325. ;
  326. splitplusminus polp;
  327. ;
  328. divpol(pol,x+2*y+3*z**2);
  329. ;
  330. lowestdeg(pol,y);
  331. ;
  332. comment 7. HANDLING OF SOME TRANSCENDENTAL FUNCTIONS:;
  333. ;
  334. trig:=((sin x)**2+(cos x)**2)**4;
  335. trigreduce trig;
  336. trig:=sin (5x);
  337. trigexpand trig;
  338. trigreduce ws;
  339. trigexpand sin(x+y+z);
  340. ;
  341. ;
  342. hypreduce (sinh x **2 -cosh x **2);
  343. ;
  344. ;
  345. clear a,b;
  346. pluslog log(a*log(x**b));
  347. concsumlog((2*log x + a*b*log(x*y)+1)/(3*x**2*log(y)));
  348. ;
  349. comment 8. HANDLING OF N6DIMENSIONAL VECTORS:;
  350. ;
  351. clear u1,u2,v1,v2,v3,v4,w3,w4;
  352. u1:=list(v1,v2,v3,v4);
  353. u2:=bag(w1,w2,w3,w4);
  354. %
  355. sumvect(u1,u2);
  356. minvect(u2,u1);
  357. scalvect(u1,u2);
  358. crossvect(rest u1,rest u2);
  359. mpvect(rest u1,rest u2, minvect(rest u1,rest u2));
  360. scalvect(crossvect(rest u1,rest u2),minvect(rest u1,rest u2));
  361. ;
  362. comment 9. HANDLING OF GRASSMANN OPERATORS:;
  363. ;
  364. putgrass eta,eta1;
  365. grasskernel:=
  366. {eta(~x)*eta(~y) => -eta y * eta x when nordp(x,y),
  367. (~x)*(~x) => 0 when grassp x};
  368. ;
  369. eta(y)*eta(x);
  370. eta(y)*eta(x) where grasskernel;
  371. let grasskernel;
  372. eta(x)^2;
  373. eta(y)*eta(x);
  374. operator zz;
  375. grassparity (eta(x)*zz(y));
  376. grassparity (eta(x)*eta(y));
  377. grassparity(eta(x)+zz(y));
  378. clearrules grasskernel;
  379. grasskernel:=
  380. {eta(~x)*eta(~y) => -eta y * eta x when nordp(x,y),
  381. eta1(~x)*eta(~y) => -eta x * eta1 y,
  382. eta1(~x)*eta1(~y) => -eta1 y * eta1 x when nordp(x,y),
  383. (~x)*(~x) => 0 when grassp x};
  384. ;
  385. let grasskernel;
  386. eta1(x)*eta(x)*eta1(z)*eta1(w);
  387. clearrules grasskernel;
  388. remgrass eta,eta1;
  389. clearop zz;
  390. ;
  391. COMMENT 10. HANDLING OF MATRICES:;
  392. ;
  393. clear m,mm,b,b1,bb,cc,a,b,c,d;
  394. matrix mm(2,2);
  395. baglmat(bag(bag(a1,a2)),m);
  396. m;
  397. on errcont;
  398. ;
  399. baglmat(bag(bag(a1),bag(a2)),m);
  400. off errcont;
  401. % **** i.e. it cannot redefine the matrix! in order
  402. % to avoid accidental redefinition of an already given matrix;
  403. clear m; baglmat(bag(bag(a1),bag(a2)),m);
  404. m;
  405. on errcont;
  406. baglmat(bag(bag(a1),bag(a2)),bag);
  407. off errcont;
  408. comment Right since a bag-like object cannot become a matrix.;
  409. ;
  410. coercemat(m,op);
  411. coercemat(m,list);
  412. ;
  413. on nero;
  414. unitmat b1(2);
  415. matrix b(2,2);
  416. b:=mat((r1,r2),(s1,s2));
  417. b1;b;
  418. mkidm(b,1);
  419. ;
  420. seteltmat(b,newelt,2,2);
  421. geteltmat(b,2,1);
  422. %
  423. b:=matsubr(b,bag(1,2),2);
  424. ;
  425. submat(b,1,2);
  426. ;
  427. bb:=mat((1+i,-i),(-1+i,-i));
  428. cc:=matsubc(bb,bag(1,2),2);
  429. ;
  430. cc:=tp matsubc(bb,bag(1,2),2);
  431. matextr(bb, bag,1);
  432. ;
  433. matextc(bb,list,2);
  434. ;
  435. hconcmat(bb,cc);
  436. vconcmat(bb,cc);
  437. ;
  438. tpmat(bb,bb);
  439. bb tpmat bb;
  440. ;
  441. clear hbb;
  442. hermat(bb,hbb);
  443. % id hbb changed to a matrix id and assigned to the hermitian matrix
  444. % of bb.
  445. ;
  446. showtime;
  447. end;