control.red 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. module control;
  2. global '(!:flaglis !:proplis indices!*);
  3. switch distribute;
  4. % functions which offer a BETTER CONTROL on various objects.
  5. % 1. BOOLEAN functions.
  6. symbolic procedure nordp(u,v);
  7. % TRUE if a>b, FALSE if a=<b.
  8. not ordp(u,v);
  9. symbolic procedure depvarp(u,v)$
  10. % V is an idf. or a kernel$
  11. if depends(u,v) then t else nil$
  12. symbolic procedure alatomp(u)$
  13. % U is any expression . Test if U is an idf. whose only value is its
  14. % printname or another atom$
  15. fixp u or idp u$
  16. symbolic procedure alkernp u$
  17. % U is any expression . Test if U is a kernel.
  18. not stringp u and kernp(simp!* u);
  19. symbolic procedure precp(u,v)$
  20. % Tests if the operator U has precedence over the operator V.
  21. begin integer nn$scalar uu,vv,aa$
  22. uu:=u$ vv:=v$aa:=preclis!*$
  23. if or(not(uu member aa),not(vv member aa)) then return nil$
  24. nn:=lpos(u,aa)$;
  25. nn:=nn-lpos(v,aa)$
  26. if nn geq 0 then return t else return nil
  27. end;
  28. flag('(null idp flagp nordp alatomp alkernp precp
  29. depvarp stringp ),'boolean);
  30. % THE declaration below is useful for "teaching" purpose.
  31. flag('(alatomp precp depvarp alkernp depatom ) ,'opfn);
  32. % 2. MISCELLANEOUS functions.
  33. symbolic procedure korderlist;
  34. % gives a list of the user defined internal order of the
  35. % indeterminates. Just issue KORDERLIST; to get it.
  36. kord!*;
  37. flag('(korderlist), 'opfn);
  38. put('korderlist,'stat,'endstat);
  39. symbolic procedure remsym u;
  40. % ALLOWS TO ELIMINATE THE DECLARED SYMMETRIES.
  41. for each j in u do
  42. if flagp(j,'symmetric) then remflag(list j,'symmetric) else
  43. if flagp(j,'antisymmetric) then remflag(list j,'antisymmetric);
  44. put('remsym,'stat,'rlis);
  45. symbolic procedure listofvars u $
  46. if null u or numberp u then nil else
  47. if atom u then list u else
  48. varsinargs if eqcar(u,'list) then cdr reval u else cdr u$
  49. symbolic procedure varsinargs(u)$
  50. if null u then nil else
  51. append(listofvars car u,varsinargs cdr u)$
  52. symbolic procedure rfuncvar(u)$
  53. % U is an arbitrary expression
  54. % Gives a list which contains all the variables whom U depends
  55. % in an ARBITRARY order$
  56. <<if atom (u:=reval car u) then
  57. if not flagp(u,'reserved) then
  58. if depatom u neq u then depatom u else nil
  59. else nil else
  60. begin scalar wi,aa$
  61. aa:=listofvars(u)$
  62. if null cdr aa then return
  63. if flagp(car aa,'reserved) or flagp(car aa,'constant)
  64. then nil else car aa
  65. else aa:=list2set aa $ wi:=aa$
  66. while wi do if flagp(car wi ,'reserved) then
  67. <<aa:=delete(car wi ,aa)$ wi:=cdr wi >> else wi:=cdr wi $
  68. return aa:='list . aa end >>;
  69. put('funcvar,'psopfn ,'rfuncvar);
  70. flag('(e i),'reserved);
  71. symbolic procedure implicit u;
  72. if atom u then u else
  73. begin scalar prf;
  74. prf:=car u;
  75. if get(prf,'simpfn) neq 'simpiden then
  76. rederr list(u,"must be an OPERATOR");
  77. remprop(car u,'simpfn);
  78. depl!*:=union(list (car u . reverse
  79. for each y in cdr u collect implicit y),depl!*);
  80. return prf end;
  81. symbolic procedure depatom a$
  82. %Gives a list of variables declared in DEPEND commands whom A depends
  83. %A must be an atom$
  84. if not atom a then rederr("ARGUMENT MUST BE AN ATOM") else
  85. if null assoc(a,depl!*) then a else
  86. 'list . reverse cdr assoc(a,depl!*);
  87. flag('(depatom),'opfn);
  88. symbolic procedure explicit u$
  89. % U is an atom. It gives a function named A which depends on the
  90. % variables detected by DEPATOM and this to all levels$
  91. begin scalar aa$
  92. aa:=depatom u $
  93. if aa = u then return u$
  94. put(u,'simpfn,'simpiden)$
  95. return u . (for each x in cdr aa collect explicit x) end$
  96. flag('(implicit explicit),'opfn);
  97. symbolic procedure simplify u;
  98. % Enforces simplifications if necessary.
  99. % u is any expression.
  100. mk!*sq resimp simp!* reval u;
  101. flag('(simplify),'opfn);
  102. % This function is for dummy.red:
  103. rlistat('(remnoncom));
  104. symbolic procedure remnoncom u;
  105. <<for each x in u do
  106. remflag(list x,'noncom);t>>;
  107. % To have a better control on the HEPHYS package.
  108. symbolic procedure remvector u;
  109. for each x in u do <<remprop(x,'rtype); remflag(list x,'used!*); 0>>;
  110. symbolic procedure remindex u;
  111. begin;
  112. for each x in u do <<remprop(x,'rtype); indices!*:=delete(x,indices!*);
  113. remflag(list x, 'used!*)>>;
  114. return t
  115. end;
  116. rlistat('(remvector remindex));
  117. symbolic procedure mkgam(u,v);
  118. % u is supposed to be an idp. v equals either t or another idp.
  119. if v neq t then
  120. <<remflag(list u,'noncom); remprop(u,'simpfn);
  121. if v eq 'op then put(u,'simpfn,'simpiden); remflag(list u, 'used!*)>>
  122. else
  123. <<clear u; clearop u; put(u,'simpfn,'simpgamma); flag(list u,'noncom); t>>;
  124. symbolic operator getmas, mkgam;
  125. % 3. Control of SWITCHES.
  126. symbolic procedure switches;
  127. %This procedure allows to see the values of the switches chosen.
  128. <<terpri();
  129. prin2 " **** exp:=";prin2 !*exp;prin2 " .................... ";
  130. prin2 "allfac:= ";prin2 !*allfac;prin2 " ****";terpri(); terpri();
  131. prin2 " **** ezgcd:=";prin2 !*ezgcd;prin2 " ................. ";
  132. prin2 "gcd:= ";prin2 !*gcd;prin2 " ****";terpri();terpri();
  133. prin2 " **** mcd:=";prin2 !*mcd;prin2 " ....................... ";
  134. prin2 "lcm:= ";prin2 !*lcm;prin2 " ****";terpri();terpri();
  135. prin2 " **** div:=";prin2 !*div;prin2 " ................... ";
  136. prin2 "rat:= ";prin2 !*rat;prin2 " ****";terpri();terpri();
  137. prin2 " **** intstr:=";prin2 !*intstr;prin2 " ........... ";
  138. prin2 "rational:= ";prin2 !*rational;prin2 " ****";terpri();terpri();
  139. prin2 " **** precise:=";prin2 !*precise;prin2 " ............. ";
  140. prin2 "reduced:= ";prin2 !*reduced;prin2 " ****";terpri();terpri();
  141. prin2 " **** complex:=";prin2 !*complex;prin2 " ....... ";
  142. prin2 "rationalize:= ";prin2 !*rationalize;
  143. prin2 " ****";terpri();terpri();
  144. prin2 " **** factor:= "; prin2 !*factor;prin2 " ....... ";
  145. prin2 "combineexpt:= ";prin2 !*combineexpt;
  146. prin2 " ****";terpri();terpri();
  147. prin2 " **** revpri:= "; prin2 !*revpri;prin2 " ........ ";
  148. prin2 "distribute:= "; prin2 !*distribute;prin2 " ****";>>;
  149. symbolic procedure switchorg$
  150. %It puts all switches relevant to current algebra calculations to
  151. % their initial values.
  152. << !*exp:=t;
  153. !*allfac:=t;
  154. !*gcd:=nil;
  155. !*mcd:=t;
  156. !*div:=nil;
  157. !*rat:=nil;
  158. !*distribute:=nil;
  159. !*intstr:=nil;
  160. !*rational:=nil;
  161. !*ezgcd:=nil;
  162. !*ratarg:=nil;
  163. !*precise:=t;
  164. !*complex:=nil;
  165. !*heugcd:=nil;
  166. !*lcm:=t;
  167. !*factor:=nil;
  168. !*ifactor:=nil;
  169. !*rationalize:=nil;
  170. !*reduced:=nil;
  171. !*savestructr:=nil;
  172. !*combineexpt:=nil;
  173. !*revpri:=nil>>;
  174. flag('(switchorg ),'opfn)$
  175. deflist('((switches endstat) (switchorg endstat) ),
  176. 'stat)$
  177. % 4. Control of USER DEFINED objects.
  178. % The procedures below allow to extract from the history of the
  179. % INTERACTIVE run in the ALGEBRAIC mode the data previously
  180. % defined by the user.
  181. % It DOES NOT give insights on operations done
  182. % in the SYMBOLIC mode.
  183. symbolic procedure remvar!:(u,v)$
  184. % This procedure traces and clear both assigned or saved scalars and
  185. % lists.
  186. begin scalar buf,comm,lv;
  187. buf:=inputbuflis!*;
  188. for each x in buf do if not atom (comm:=caddr x)
  189. and car comm = 'setk then
  190. begin scalar obj;
  191. l1: if null cddr comm or car comm eq 'prog then return lv;
  192. obj:=cadadr comm;
  193. if gettype obj eq v then
  194. lv:=adjoin(obj,lv);
  195. comm:=caddr comm;
  196. go to l1 end;
  197. if null u then
  198. <<for each x in lv do clear x; return t>> else return lv
  199. end;
  200. flag('(displaylst displayscal),'noform);
  201. symbolic procedure displayscal;
  202. % Allows to see all scalar variables which have been assigned
  203. % independently DIRECTLY ON THE CONSOLE. It does not work
  204. % for assignments introduced THROUGH an input file;
  205. union(remvar!:(t,'scalar),remsvar!:(t,'scalar));
  206. symbolic procedure displaylst$
  207. % Allows to see all list variables which have been assigned
  208. % independently DIRECTLY ON THE CONSOLE. It does not work
  209. % for assignments introduced THROUGH an input file;
  210. union(remvar!:(t,'list),remsvar!:(t,'list)) ;
  211. symbolic procedure clearscal$
  212. % Allows to clear all scalar variables introduced
  213. % DIRECTLY ON THE CONSOLE;
  214. <<remvar!:(nil,'scalar);remsvar!:(nil,'scalar)>>$
  215. symbolic procedure clearlst$
  216. % Allows to clear all list variables introduced
  217. % DIRECTLY ON THE CONSOLE;
  218. <<remvar!:(nil,'list);remsvar!:(nil,'list)>>;
  219. symbolic procedure remsvar!:(u,v)$
  220. begin scalar buf,comm,lsv,obj;
  221. buf:= inputbuflis!*;
  222. for each x in buf do
  223. if not atom (comm:=caddr x) and car comm eq 'saveas then
  224. if v eq t then
  225. if gettype (obj:=cadr cadadr comm)
  226. member list('scalar,'list,'matrix,'hvector,'tvector)
  227. then lsv:=adjoin(obj,lsv)
  228. else nil
  229. else if v eq gettype (obj:=cadr cadadr comm)
  230. then lsv:=adjoin(obj,lsv);
  231. % lsv:= !:mkset lsv$
  232. if null u then
  233. <<for each x in lsv do clear x$ return t>> else return lsv
  234. end;
  235. flag('(displaysvar),'noform);
  236. symbolic procedure displaysvar;
  237. % Allows to see all variables created by SAVEAS.
  238. remsvar!:(t,t) ;
  239. symbolic procedure clearsvar;
  240. % Allows to clear all variables created.
  241. % independently DIRECTLY ON THE CONSOLE. It does not work
  242. % for assignments introduced THROUGH an input file.
  243. remsvar!:(nil,t);
  244. symbolic procedure rema!:(u);
  245. % This function works to trace or to clear arrays.
  246. begin scalar buf,comm,la$
  247. buf:=inputbuflis!*$
  248. for each x in buf do if not atom (comm:=caddr x) and
  249. car comm eq 'arrayfn then
  250. begin scalar arl,obj;
  251. arl:=cdaddr comm;
  252. l1: if null arl then return la else
  253. if gettype (obj:=cadadr car arl ) eq 'array then
  254. la:=adjoin(obj,la);
  255. arl:=cdr arl$
  256. go to l1 end$
  257. if null u then
  258. <<for each x in la do clear x$ return t>> else return la
  259. end;
  260. flag('(displayar),'noform);
  261. symbolic procedure displayar;
  262. % Allows to see all array variables created.
  263. % independently DIRECTLY ON THE CONSOLE. It does not work
  264. % for assignments introduced THROUGH an input file.
  265. rema!:(t)$
  266. symbolic procedure clearar;
  267. % Allows to clear array variables introduced
  268. % DIRECTLY ON THE CONSOLE;
  269. rema!:(nil)$
  270. symbolic procedure remm!:(u)$
  271. % This function works to trace or to clear matrices. Be CAREFUL to use
  272. % the declaration MATRIX on input (not m:=mat(...) directly).
  273. % declaration MATRIX ..
  274. %x ==> (97 SYMBOLIC (MATRIX (LIST (LIST (QUOTE MM) 1 1))))
  275. % Declaration MM:=MAT((...))
  276. % x==>(104 ALGEBRAIC
  277. % (SETK (QUOTE M2) (AEVAL (LIST (QUOTE MAT) (LIST 1) (LIST 1)))))
  278. begin scalar buf,comm,lm;
  279. buf:= inputbuflis!*;
  280. for each x in buf do if not atom (comm:=caddr x) and
  281. car comm eq 'matrix then
  282. begin scalar lob,obj;
  283. lob:=cdadr comm;
  284. l1: if null lob then return lm else
  285. if gettype(obj:=if length car lob = 2 then cadr car lob else
  286. cadadr car lob) then
  287. lm:=adjoin(obj,lm);
  288. lob:=cdr lob;
  289. go to l1 end$
  290. lm :=union(lm,remvar!:(t,'matrix));
  291. if null u then
  292. <<for each x in lm do clear x$ return t>> else return lm
  293. end;
  294. flag('(displaymat),'noform);
  295. symbolic procedure displaymat$
  296. % Allows to see all variables of matrix type
  297. % independently DIRECTLY ON THE CONSOLE. It does not work
  298. % for assignments introduced THROUGH an input file;
  299. union( remm!:(t),remsvar!:(t,'matrix));
  300. symbolic procedure clearmat$
  301. % Allows to clear all user variables introduced
  302. % DIRECTLY ON THE CONSOLE;
  303. <<remm!:(nil);remsvar!:(nil,'matrix)>>;
  304. symbolic procedure remv!:(u)$
  305. % This function works to trace or to clear vectors.
  306. begin scalar buf,av$
  307. buf:= inputbuflis!*$
  308. for each x in buf do if not atom (x:=caddr x) and
  309. car x member list('vector,'tvector,'index)
  310. then
  311. begin scalar uu,xx$
  312. uu:=cdadr x$
  313. l1: if null uu then return av else
  314. if gettype(xx:=cadar uu) or get(xx,'fdegree) then
  315. av:=adjoin(xx,av);
  316. uu:=cdr uu$
  317. go to l1 end$
  318. if null u then
  319. <<for each x in av do clear x$ return t>> else return av
  320. end$
  321. flag('(displayvec),'noform);
  322. symbolic procedure displayvec$
  323. % Allows to see all variables which have been assigned
  324. % independently DIRECTLY ON THE CONSOLE. It does not work
  325. % for assignments introduced THROUGH an input file;
  326. union(remv!:(t),union(remsvar!:(t,'hvector),remsvar!:(t,'tvector)) );
  327. symbolic procedure clearvec$
  328. % Allows to clear all user variables introduced
  329. % DIRECTLY ON THE CONSOLE;
  330. <<remv!:(nil);remsvar!:(nil,'hvector);remsvar!:(nil,'tvector)>>;
  331. symbolic procedure remf!:(u)$
  332. % This function works to trace or to clear forms.
  333. begin scalar buf,av$
  334. buf:= inputbuflis!*$
  335. for each x in buf do if not atom (x:=caddr x) and
  336. car x eq 'pform then
  337. begin scalar uu,xx$
  338. uu:=cdadr x$
  339. l1: if null uu then return av else
  340. if get(xx:=cadadr cdar uu ,'fdegree) or
  341. (not atom xx and get(xx:=cadr xx,'ifdegree))
  342. then
  343. av:=adjoin(xx,av);
  344. uu:=cdr uu$
  345. go to l1 end$
  346. if null u then
  347. <<for each x in av do clear x$ return t>> else return av
  348. end$
  349. flag('(displayform),'noform);
  350. symbolic procedure displayform$
  351. % Allows to see all variables which have been assigned
  352. % independently DIRECTLY ON THE CONSOLE. It does not work
  353. % for assignments introduced THROUGH an input file;
  354. union(remf!:(t),remvar!:(t,'pform));
  355. symbolic procedure clearform$
  356. % Allows to clear all user variables introduced
  357. % DIRECTLY ON THE CONSOLE;
  358. <<remf!:(nil);remvar!:(nil,'pform)>>;
  359. symbolic procedure clear!_all;
  360. <<remvar!: (nil,'scalar); remvar!:(nil,'list); remvar!:(nil,'pform);
  361. remsvar!:(nil,t);rema!: nil;remv!: nil;remm!: nil; remf!: nil ;t>>;
  362. symbolic procedure show u;
  363. begin u:=car u;
  364. if u eq 'scalars then
  365. return write "scalars are: ", displayscal()
  366. else
  367. if u eq 'lists then
  368. return write "lists are: ", displaylst()
  369. else
  370. if u eq 'arrays then
  371. return write "arrays are: ", displayar()
  372. else
  373. if u eq 'matrices then
  374. return write "matrices are: ",displaymat()
  375. else
  376. if u member list('vectors,'tvectors,'indices) then
  377. return write "vectors are: ", displayvec()
  378. else
  379. if u eq 'forms then
  380. return write "forms are: ", displayform()
  381. else
  382. if u eq 'all then for each i in
  383. list('scalars,'arrays,'lists,'matrices,'vectors,'forms) do
  384. <<show list i;lisp terpri()>>;
  385. end;
  386. put('show,'stat,'rlis);
  387. symbolic procedure suppress u;
  388. begin u:=car u;
  389. if u member list('vectors,'tvectors,'indices) then
  390. return clearvec() else
  391. if u eq 'variables then return clearvar() else
  392. if u eq 'scalars then return clearscal() else
  393. if u eq 'lists then return clearlst() else
  394. if u eq 'saveids then return clearsvar() else
  395. if u eq 'matrices then return clearmat() else
  396. if u eq 'arrays then return clearar() else
  397. if u eq 'forms then return clearform() else
  398. if u eq 'all then return clear!_all() end;
  399. put('suppress,'stat,'rlis);
  400. % 5. Complementary means to CLEAR operators and functions.
  401. symbolic procedure clearop u;
  402. <<clear u; remopr u; remprop(u , 'kvalue);remprop(u,'klist)$
  403. for each x in !:flaglis do
  404. if u eq car x then putflag(u,cadr x,0) else nil;
  405. for each x in !:proplis do
  406. if u eq car x then putprop(u,cadr x,caddr x,0)
  407. else nil;
  408. remflag(list u,'used!*); t>>;
  409. flag('(clearop),'opfn);
  410. symbolic procedure clearfunctions u$
  411. % U is any number of idfs. This function erases properties of non
  412. % protected functions described by the idfs.
  413. % It is very convenient but is dangerous if applied to the
  414. % basic functions of the system since most of them are NOT protected.
  415. % It clears all properties introduced by PUTFLAG, PUTPROP and DEPEND.
  416. begin scalar uu,vv$
  417. l1: uu:=car u$
  418. vv:=cdr rdisplayflag (list uu )$
  419. if flagp(uu,'lose) then go to l2 else
  420. << terpri();spaces(5)$
  421. write "*** ",uu," is unprotected : Cleared ***"$
  422. followline(0)>>$
  423. for each x in !:proplis do
  424. if u eq car x then putprop(u,cadr x,caddr x,0)
  425. else nil;
  426. remprop('uu,'!*lambdalink);
  427. if get(uu,'simpfn) then <<clearop uu; remprop(uu,'!:ft!:);
  428. remprop(uu,'!:gf!:)>> ;
  429. remprop(uu,'psopfn);
  430. remprop(uu,'expr);
  431. if get(uu,'subr) then remd uu$
  432. remprop(uu,'stat);
  433. remprop(uu,'dfn);
  434. remprop(uu,'rtypefn);
  435. remprop(uu,'number!-of!-args);
  436. remflag(list uu,'opfn)$
  437. remflag(list uu,'full)$
  438. remflag(list uu,'odd)$
  439. remflag(list uu,'even)$
  440. remflag(list uu,'boolean)$
  441. remflag(list uu,'used!*)$
  442. for each x in vv do putflag( uu,x,0)$
  443. depl!*:=delete(assoc(uu,depl!*),depl!*);
  444. remflag(list uu,'impfun)$ % to be effective in EXCALC;
  445. u:= cdr u$ go to l3$
  446. l2: << spaces(5)$
  447. write "*** ",uu," is a protected function: NOT cleared ***"$
  448. terpri(); u:=cdr u>>$
  449. l3: if null u then <<terpri();
  450. return "Clearing is complete">> else
  451. go to l1 end$
  452. rlistat '(clearfunctions);
  453. endmodule;
  454. end;