assist.tex 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  1. \documentstyle[11pt,reduce]{article}
  2. \newcommand{\nl}{\hfill\newline}
  3. \newcommand{\bq}{\begin{quotation}}
  4. \newcommand{\eq}{\end{quotation}}
  5. \newcommand{\bi}{\begin{itemize}}
  6. \newcommand{\ei}{\end{itemize}}
  7. \title{{\bf ASSIST}\ :\\[2pt]
  8. A General Purpose Addition to~\REDUCE \\[5pt]
  9. \mbox{\hfill Version 2.3\hfil}}
  10. \author{Hubert Caprasse \\
  11. D\'epartement d'Astronomie et d'Astrophysique \\
  12. Institut de Physique, B--5, Sart Tilman \\
  13. B--4000 LIEGE 1 \\[3pt]
  14. E--mail: caprasse@vm1.ulg.ac.be}
  15. \begin{document}
  16. \maketitle
  17. %\index{ASSIST package}
  18. \section{Introduction}
  19. The package ASSIST contains
  20. an appreciable number of additional general purpose functions which allow
  21. one to better adapt \REDUCE\ to various calculational strategies,
  22. to make the programming task more straightforward and, sometimes,
  23. more efficient.
  24. In contrast with all other packages, ASSIST does not aim to provide either a
  25. new facility to compute a definite class of mathematical objects or to extend
  26. the base of mathematical knowledge of \REDUCE\ .
  27. The functions it contains should be
  28. useful independently of the nature of the application which is considered.
  29. They were initially written while applying \REDUCE\ to specific problems in
  30. theoretical physics. Most of them were designed
  31. in such a way that their applicability range is broad. Though it was not
  32. the primary goal, efficiency has been sought whenever possible.
  33. The source code in ASSIST contains many comments concerning
  34. the meaning and use of the supplementary functions available
  35. in the algebraic mode. These comments, hopefully, make the code transparent
  36. and allow a thorough exploitation of the package. The present documentation
  37. contains a non--technical description of it and describes the
  38. various new facilities it provides.
  39. \section{ Survey of the Available New Facilities}
  40. An elementary help facility is available both within
  41. the MS-DOS\ and Windows environments. It is independent of the
  42. help facility of \REDUCE\ itself. It includes two functions:
  43. \f{ASSIST} is a function which takes no argument. If entered, it returns
  44. the informations required for a proper use of \f{ASSISTHELP}.\\
  45. \f{ASSISTHELP} takes one argument.
  46. \begin{itemize}
  47. \item[i.] If the argument is the identifier \f{assist}, the function
  48. returns the information necessary to retrieve the names of all the available
  49. functions.
  50. \item[ii.] If the argument is an integer equal to one of the section numbers
  51. of the present documentation. The names of the functions described
  52. in that section are obtained.\nl
  53. There is, presently, no possibility to retrieve the number and the type of
  54. the arguments of a given function.
  55. \end{itemize}
  56. The package contains several modules. Their content reflects closely
  57. the various categories of facilities listed below. Some functions do
  58. already exist inside the KERNEL of \REDUCE\ . However, their range
  59. of applicability is {\em extended}.\nl
  60. \begin{itemize}
  61. \item{Control of Switches:}
  62. \begin{quotation}
  63. \noindent
  64. \f{SWITCHES SWITCHORG}
  65. \end{quotation}
  66. \item{Operations on Lists and Bags:}
  67. \begin{quotation}
  68. \noindent
  69. \f{MKLIST KERNLIST ALGNLIST LENGTH \nl
  70. POSITION FREQUENCY SEQUENCES SPLIT \nl
  71. INSERT INSERT\_KEEP\_ORDER MERGE\_LIST \nl
  72. FIRST SECOND THIRD REST REVERSE LAST \nl
  73. BELAST CONS ( . ) APPEND APPENDN \nl
  74. REMOVE DELETE DELETE\_ALL DELPAIR \nl
  75. MEMBER ELMULT PAIR DEPTH MKDEPTH\_ONE \nl
  76. REPFIRST REPREST ASFIRST ASLAST ASREST \nl
  77. ASFLIST ASSLIST RESTASLIST SUBSTITUTE \nl
  78. BAGPROP PUTBAG CLEARBAG BAGP BAGLISTP \nl
  79. ALISTP ABAGLISTP LISTBAG }
  80. \end{quotation}
  81. \item{Operations on Sets:}
  82. \begin{quotation}
  83. \noindent
  84. \f{MKSET SETP UNION INTERSECT DIFFSET SYMDIFF}
  85. \end{quotation}
  86. %\newpage
  87. \item{General Purpose Utility Functions:}
  88. \begin{quotation}
  89. \noindent
  90. \f{LIST\_TO\_IDS MKIDN MKIDNEW DELLASTDIGIT DETIDNUM \\
  91. ODDP FOLLOWLINE == RANDOMLIST MKRANDTABL \\
  92. PERMUTATIONS CYCLICPERMLIST PERM\_TO\_NUM NUM\_TO\_PERM\\
  93. COMBNUM COMBINATIONS SYMMETRIZE REMSYM \\
  94. SORTNUMLIST SORTLIST ALGSORT EXTREMUM GCDNL\\
  95. DEPATOM FUNCVAR IMPLICIT EXPLICIT REMNONCOM \\
  96. KORDERLIST SIMPLIFY CHECKPROPLIST EXTRACTLIST}
  97. \end{quotation}
  98. \item{ Properties and Flags:}
  99. \begin{quotation}
  100. \noindent
  101. \f{PUTFLAG PUTPROP DISPLAYPROP DISPLAYFLAG \\
  102. CLEARFLAG CLEARPROP }
  103. \end{quotation}
  104. \item{ Control Statements, Control of Environment:}
  105. \begin{quotation}
  106. \noindent
  107. \f{NORDP DEPVARP ALATOMP ALKERNP PRECP \\
  108. SHOW SUPPRESS CLEAROP CLEARFUNCTIONS }
  109. \end{quotation}
  110. \item{Handling of Polynomials:}
  111. \begin{quotation}
  112. \noindent
  113. \f{ALG\_TO\_SYMB SYMB\_TO\_ALG \\
  114. DISTRIBUTE LEADTERM REDEXPR MONOM\\
  115. LOWESTDEG DIVPOL SPLITTERMS SPLITPLUSMINUS}
  116. \end{quotation}
  117. % \vfill\pagebreak
  118. \item{Handling of Transcendental Functions:}
  119. \begin{quotation}
  120. \noindent
  121. \f{TRIGEXPAND HYPEXPAND TRIGREDUCE HYPREDUCE}
  122. \end{quotation}
  123. \item{Coercion from Lists to Arrays and converse:}
  124. \begin{quotation}
  125. \f{LIST\_TO\_ARRAY ARRAY\_TO\_LIST}
  126. \end{quotation}
  127. \item{Handling of n-dimensional Vectors:}
  128. \begin{quotation}
  129. \noindent
  130. \f{SUMVECT MINVECT SCALVECT CROSSVECT MPVECT }
  131. \end{quotation}
  132. {\item Handling of Grassmann Operators:}
  133. \begin{quotation}
  134. \noindent
  135. \f{PUTGRASS REMGRASS GRASSP GRASSPARITY GHOSTFACTOR }
  136. \end{quotation}
  137. \item{Handling of Matrices:}
  138. \begin{quotation}
  139. \noindent
  140. \f{UNITMAT MKIDM BAGLMAT COERCEMAT \\
  141. SUBMAT MATSUBR MATSUBC RMATEXTR RMATEXTC \\
  142. HCONCMAT VCONCMAT TPMAT HERMAT \\
  143. SETELTMAT GETELTMAT}
  144. \eq
  145. \item{Control of the HEPHYS package:}
  146. \bq
  147. \noindent
  148. \f{REMVECTOR REMINDEX MKGAM}
  149. \end{quotation}
  150. \end{itemize}
  151. In the following all these functions are described.
  152. \section{Control of Switches}
  153. The two available functions i.e. \f{SWITCHES, SWITCHORG} have
  154. no argument and are called as if they were mere identifiers.
  155. \f{SWITCHES} displays the actual status of the most frequently used switches
  156. when manipulating rational functions. The chosen switches are
  157. \begin{quotation}
  158. \noindent
  159. {\tt EXP, ALLFAC, EZGCD, GCD, MCD, LCM, DIV, RAT, \\%
  160. INTSTR, RATIONAL, PRECISE, REDUCED, RATIONALIZE, \\%
  161. COMBINEEXPT, COMPLEX, REVPRI, DISTRIBUTE.}
  162. \end{quotation}
  163. The selection is somewhat arbitrary but it may be changed in a trivial
  164. fashion by the user.
  165. The new switch {\tt DISTRIBUTE} allows one to put polynomials in a
  166. distributed form (see the description below of
  167. the new functions for manipulating them.~).
  168. Most of the symbolic variables {\tt !*EXP, !*DIV, $\ldots$}
  169. which have either the value T or the value NIL are made available in the
  170. algebraic mode so that it becomes possible to write conditional
  171. statements of the kind
  172. \begin{verbatim}
  173. IF !*EXP THEN DO ......
  174. IF !*GCD THEN OFF GCD;
  175. \end{verbatim}
  176. \f{SWITCHORG} resets the switches enumerated above to the status
  177. they had when {\bf starting} \REDUCE\ .
  178. \section{Manipulation of the List Structure}
  179. Additional functions for list manipulations are provided and some already
  180. defined functions in the kernel of \REDUCE\ are modified to properly
  181. generalize them to the available new structure {\tt BAG}.
  182. \begin{itemize}
  183. \item[i.]
  184. Generation of a list of length n with all its elements initialized to 0
  185. and possibility to append to a list $l$ a certain number of
  186. zero's to make it of length $n$:
  187. \begin{verbatim}
  188. MKLIST n ; n is an INTEGER
  189. MKLIST(l,n); l is List-like, n is an INTEGER
  190. \end{verbatim}
  191. \item[ii.]
  192. Generation of a list of sublists of length n containing p elements
  193. equal to 0 and q elements equal to 1 such that $$p+q=n .$$
  194. The function \f{SEQUENCES} works both in algebraic and
  195. symbolic modes. Here is an example in the algebraic mode:
  196. \begin{verbatim}
  197. SEQUENCES 2 ; ==> {{0,0},{0,1},{1,0},{1,1}}
  198. \end{verbatim}
  199. An arbitrary splitting of a list can be done. The function \f{SPLIT}
  200. generates a list which contains the splitted parts of the original list.
  201. \begin{verbatim}
  202. SPLIT({a,b,c,d},{1,1,2}) ==> {{a},{b},{c,d}}
  203. \end{verbatim}
  204. The function \f{ALGNLIST} constructs a list which contains n copies
  205. of a list bound to its first argument.
  206. \begin{verbatim}
  207. ALGNLIST({a,b,c,d},2); ==> {{a,b,c,d},{a,b,c,d}}
  208. \end{verbatim}
  209. The function \f{KERNLIST} transforms any prefix of a kernel into the
  210. {\bf \verb+list+} prefix. The output list is a copy:
  211. \begin{verbatim}
  212. KERNLIST (<kernel>); ==> {<kernel arguments>}
  213. \end{verbatim}
  214. Four functions to delete elements are \f{DELETE, REMOVE, DELETE\_ALL} and
  215. \f{DELPAIR}. The first two act as in symbolic mode, and the third
  216. eliminates from a given list {\em all}
  217. elements equal to its first argument. The fourth acts on a list of pairs
  218. and eliminates from it the {\em first} pair whose first element is equal to
  219. its first argument :
  220. \begin{verbatim}
  221. DELETE(x,{a,b,x,f,x}); ==> {a,b,f,x}
  222. REMOVE({a,b,x,f,x},3); ==> {a,b,f,x}
  223. DELETE_ALL(x,{a,b,x,f,x}); ==> {a,b,f}
  224. DELPAIR(a,{{a,1},{b,2},{c,3}}; ==> {{b,2},{c,3}}
  225. \end{verbatim}
  226. \item[iv.]
  227. The function \f{ELMULT} returns an {\em integer} which is the
  228. {\em multiplicity} of its first argument inside the list which is its
  229. second argument.
  230. The function \f{FREQUENCY} gives a list of pairs
  231. whose second element indicates the number of times the first element
  232. appears inside the original list:
  233. \begin{verbatim}
  234. ELMULT(x,{a,b,x,f,x}) ==> 2
  235. FREQUENCY({a,b,c,a}); ==> {{a,2},{b,1},{c,1}}
  236. \end{verbatim}
  237. \item[v.]
  238. The function \f{INSERT} allows one to insert a given object into a list
  239. at the desired position.
  240. The functions \f{INSERT\_KEEP\_ORDER} and \f{MERGE\_LIST} allow one to
  241. keep a given ordering when inserting one element inside a list or
  242. when merging two lists. Both have 3 arguments. The last one is
  243. the name of a binary boolean ordering function:
  244. \begin{verbatim}
  245. ll:={1,2,3}$
  246. INSERT(x,ll,3); ==> {1,2,x,3}
  247. INSERT_KEEP_ORDER(5,ll,lessp); ==> {1,2,3,5}
  248. MERGE_LIST(ll,ll,lessp); ==> {1,1,2,2,3,3}
  249. \end{verbatim}
  250. Notice that \f{MERGE\_LIST} will act correctly only if the two lists
  251. are well ordered themselves.
  252. \item[vi.]
  253. Algebraic lists can be read from right to left or left to right.
  254. They {\em look} symmetrical. One would like to dispose of manipulation
  255. functions which reflect this.
  256. So, to the already defined functions \f{FIRST} and \f{REST} are
  257. added the functions \f{LAST} and \f{BELAST}. \f{LAST} gives the last
  258. element of the list while \f{BELAST} gives the list {\em without} its
  259. last element. \\
  260. Various additional functions are provided. They are:
  261. \bq
  262. \noindent
  263. \f{ . (``dot''), POSITION, DEPTH, MKDEPTH\_ONE, \\
  264. PAIR, APPENDN, REPFIRST, REPREST}
  265. \eq
  266. The token ``dot'' needs a special comment. It corresponds to
  267. several different operations.
  268. \begin{enumerate}
  269. \item If one applies it on the left of a list, it acts as the \f{CONS}
  270. function. Note however that blank spaces are required around the dot:
  271. \begin{verbatim}
  272. 4 . {a,b}; ==> {4,a,b}
  273. \end{verbatim}
  274. \item If one applies it on the right of a list, it has the same
  275. effect as the \f{PART} operator:
  276. \begin{verbatim}
  277. {a,b,c}.2; ==> b
  278. \end{verbatim}
  279. \item If one applies it to a 4--dimensional vectors, it acts as in the
  280. HEPHYS package.
  281. \end{enumerate}
  282. \f{POSITION} returns the POSITION of the first occurrence of x in
  283. a list or a message if x is not present in it.
  284. \f{DEPTH} returns an {\em integer} equal to the number of levels where a
  285. list is found if and only if this number is the {\em same} for each
  286. element of the list otherwise it returns a message telling the user
  287. that the list is of {\em unequal depth}. The function \f{MKDEPTH\_ONE}
  288. allows to transform any list into a list of depth equal to 1.
  289. \f{PAIR} has two arguments which must be lists. It returns a list
  290. whose elements are {\em lists of two elements.}
  291. The $n^{th}$ sublist contains the $n^{th}$ element of the first list
  292. and the $n^{th}$ element of the second list. These types of lists are called
  293. {\em association lists} or ALISTS in the following.
  294. To test for these type of lists a boolean function \f{ABAGLISTP}
  295. is provided. It will be discussed below.\\
  296. \f{APPENDN} has {\em any} fixed number of lists as arguments. It
  297. generalizes the already existing function \f{APPEND} which accepts
  298. only two lists as arguments. It may also be used for arbitrary kernels
  299. but, in that case, it is important to notice that {\em the concatenated
  300. object is always a list}.\\
  301. \f{REPFIRST} has two arguments. The first one is any object, the second one
  302. is a list. It replaces the first element of the list by the object. It
  303. works like the symbolic function \f{REPLACA} except that the
  304. original list is not destroyed.\\
  305. \f{REPREST} has also two arguments. It replaces the rest of the list by
  306. its first argument and returns the new list {\em without destroying} the
  307. original list. It is analogous to the symbolic function \f{REPLACD}.
  308. Here are examples:
  309. \begin{verbatim}
  310. ll:={{a,b}}$
  311. ll1:=ll.1; ==> {a,b}
  312. ll.0; ==> list
  313. 0 . ll; ==> {0,{a,b}}
  314. DEPTH ll; ==> 2
  315. PAIR(ll1,ll1); ==> {{a,a},{b,b}}
  316. REPFIRST{new,ll); ==> {new}
  317. ll3:=APPENDN(ll1,ll1,ll1); ==> {a,b,a,b,a,b}
  318. POSITION(b,ll3); ==> 2
  319. REPREST(new,ll3); ==> {a,new}
  320. \end{verbatim}
  321. \item[vii.]
  322. The functions \f{ASFIRST, ASLAST, ASREST, ASFLIST, ASSLIST, \\RESTASLIST}
  323. act on ALISTS or on lists of lists of well defined depths
  324. and have two arguments. The first is the key object
  325. which one seeks to associate in some way with an element of the association
  326. list which is the second argument.\\
  327. \f{ASFIRST} returns the pair whose first element is equal to the
  328. first argument.\\
  329. \f{ASLAST} returns the pair whose last element is equal to the first
  330. argument.\\
  331. \f{ASREST} needs a {\em list} as its first argument. The function
  332. seeks the first sublist of a list of lists (which is its second argument)
  333. equal to its first argument and returns it.\\
  334. \f{RESTASLIST} has a {\em list of keys} as its first argument. It
  335. returns the collection of pairs which meet the criterium of \f{ASREST}.\\
  336. \f{ASFLIST} returns a list containing {\em all pairs} which
  337. satisfy the criteria of the function \f{ASFIRST}. So the output
  338. is also an association list.\\
  339. \f{ASSLIST} returns a list which contains {\em all pairs} which have
  340. their second element equal to the first argument.\\
  341. Here are a few examples:
  342. \begin{verbatim}
  343. lp:={{a,1},{b,2},{c,3}}$
  344. ASFIRST(a,lp); ==> {a,1}
  345. ASLAST(1,lp); ==> {a,1}
  346. ASREST({1},lp); ==> {a,1}
  347. RESTASLIST({a,b},lp); ==> {{1},{2}}
  348. lpp:=APPEND(lp,lp)$
  349. ASFLIST(a,lpp); ==> {{a,1},{a,1}}
  350. ASSLIST(1,lpp); ==> {{a,1},{a,1}}
  351. \end{verbatim}
  352. \item[vii.] The function \f{SUBSTITUTE} has three arguments. The first
  353. is the object to be substituted, the second is the object which must be
  354. replaced by the first, and the third is the list in which the substitution
  355. must be made. Substitution is made to
  356. all levels. It is a more elementary function than \f{SUB} but its
  357. capabilities are less. When dealing with algebraic quantities, it is
  358. important to make sure that {\em all} objects involved in the function
  359. have either the prefix lisp or the standard quotient representation
  360. otherwise it will not properly work.
  361. \end{itemize}
  362. \section{ The Bag Structure and its Associated Functions}
  363. The LIST structure of \REDUCE\ is very convenient for manipulating
  364. groups of objects which are, a priori, unknown. This structure is
  365. endowed with other properties such as ``mapping'' i.e. the fact that
  366. if \verb+OP+ is an operator one gets, by default,
  367. \begin{verbatim}
  368. OP({x,y}); ==> {OP(x),OP(y)}
  369. \end{verbatim}
  370. It is not permitted to submit lists to the operations valid on rings
  371. so that, for example, lists cannot be indeterminates of polynomials.\\
  372. Very frequently too, procedure arguments cannot be lists.
  373. At the other extreme, so to say, one has the \verb+KERNEL+
  374. structure associated
  375. with the algebraic declaration \verb+operator+ . This structure behaves as
  376. an ``unbreakable'' one and, for that reason, behaves
  377. like an ordinary identifier.
  378. It may generally be bound to all non-numeric procedure parameters
  379. and it may appear
  380. as an ordinary indeterminate inside polynomials. \\
  381. The \verb+BAG+ structure is intermediate between a list and an operator.
  382. From the operator it borrows the property of being a \verb+KERNEL+ and,
  383. therefore, may be an indeterminate of a polynomial. From the list structure
  384. it borrows the property of being a {\em composite} object.\\[5pt]
  385. \mbox{\underline{{\bf Definition}:\hfill}}\\[4pt]
  386. A bag is an object endowed with the following properties:
  387. \begin{enumerate}
  388. \item It is a \verb+KERNEL+ i.e. it is composed of an atomic prefix (its
  389. envelope) and
  390. its content (miscellaneous objects).
  391. \item Its content may be handled in an analogous way as the content of a
  392. list. The important difference is that during these manipulations
  393. the name of the bag is {\em kept}.
  394. \item Properties may be given to the envelope. For instance, one may
  395. declare it \verb+NONCOM+ or \verb+SYMMETRIC+ etc.\ $\ldots$
  396. \end{enumerate}
  397. \vspace{5pt}
  398. \mbox{\underline{{\bf Available Functions}:\hfill}}
  399. \bi
  400. \item[i.] A default bag envelope \verb+BAG+ is defined.
  401. It is a reserved identifier.
  402. An identifier other than \verb+LIST+ or one which is already associated
  403. with a boolean function may be defined as a bag envelope through the
  404. command \f{PUTBAG}. In particular, any operator may also be declared
  405. to be a bag. {\bf When and only when} the identifier is not an already defined
  406. function does \f{PUTBAG} put on it the property of an OPERATOR PREFIX.
  407. The command:
  408. \begin{verbatim}
  409. PUTBAG id1,id2,....idn;
  410. \end{verbatim}
  411. declares \verb+id1,.....,idn+ as bag envelopes.
  412. Analogously, the command
  413. \begin{verbatim}
  414. CLEARBAG id1,...idn;
  415. \end{verbatim}
  416. eliminates the bag property on \verb+id1,...,idn+.
  417. \item[ii.] The boolean function \f{BAGP} detects the bag property.
  418. Here is an example:
  419. \begin{verbatim}
  420. aa:=bag(x,y,z)$
  421. if BAGP aa then "ok"; ==> ok
  422. \end{verbatim}
  423. \item[iii.] The functions listed below may act both on lists or bags.
  424. Moreover, functions subsequently defined for SETS also work for a bag
  425. when its content is a set.
  426. Here is a list of the main ones:
  427. \begin{quotation}
  428. \noindent
  429. \f{FIRST, SECOND, LAST, REST, BELAST, DEPTH, LENGTH, REVERSE,\\
  430. MEMBER, APPEND, . (``dot''), REPFIRST, REPREST} $\ldots$
  431. \end{quotation}
  432. However, since they keep track of the envelope, they act
  433. somewhat differently. Remember that
  434. \vspace{5pt}
  435. \begin{center}
  436. the NAME of the ENVELOPE is KEPT by the functions \\[3pt]
  437. \f{FIRST, SECOND and LAST}.
  438. \end{center}
  439. Here are a few examples (more examples are
  440. given inside the test file):
  441. \begin{verbatim}
  442. PUTBAG op; ==> T
  443. aa:=op(x,y,z)$
  444. FIRST op(x,y,z); ==> op(x)
  445. REST op(x,y,z); ==> op(y,z)
  446. BELAST op(x,y,z); ==> op(x,y)
  447. APPEND(aa,aa); ==> op(x,y,z,x,y,z)
  448. APPENDN(aa,aa,aa); ==> {x,y,z,x,y,z,x,y,z}
  449. LENGTH aa; ==> 3
  450. DEPTH aa; ==> 1
  451. MEMBER(y,aa); ==> op(y,z)
  452. \end{verbatim}
  453. When ``appending'' two bags with {\em different} envelopes, the resulting bag
  454. gets the name of the one bound to the first parameter of \f{APPEND}. When
  455. \f{APPENDN} is used, the output is always a list.\\
  456. The function \f{LENGTH} gives the number of objects contained in the
  457. bag.
  458. \item[iv.]
  459. The connection between the list and the bag structures is made easy
  460. thanks to \f{KERNLIST} which transforms a bag into a list and thanks to
  461. the coercion function \f{LISTBAG} which transforms a list into a bag.
  462. This function has 2 arguments
  463. and is used as follows:
  464. \begin{verbatim}
  465. LISTBAG(<list>,<id>); ==> <id>(<arg_list>)
  466. \end{verbatim}
  467. The identifier \verb+<id>+, if allowed, is automatically declared as a bag
  468. envelope or an error message is generated. \\[3pt]
  469. Finally, two boolean functions which work both for bags and lists are
  470. provided. They are \f{BAGLISTP} and \f{ABAGLISTP}.
  471. They return t or nil (in a conditional statement) if their argument
  472. is a bag or a list for the first one, or if their argument is a list of
  473. sublists or a bag containing bags for the second one.
  474. \end{itemize}
  475. \section{Sets and their Manipulation Functions}
  476. Functions for sets exist at the level of symbolic mode. The
  477. package makes them available in algebraic mode but also {\em generalizes}
  478. them so that they can be applied to bag-like objects as well.
  479. \bi
  480. \item[i.]
  481. The constructor \f{MKSET} transforms a list or bag into a set by eliminating
  482. duplicates.
  483. \begin{verbatim}
  484. MKSET({1,a,a}); ==> {1,a}
  485. MKSET bag(1,a,1,a); ==> bag(1,a)
  486. \end{verbatim}
  487. \f{SETP} is a boolean function which recognizes set--like objects.
  488. \begin{verbatim}
  489. if SETP {1,2,3} then ... ;
  490. \end{verbatim}
  491. \item[ii.]
  492. The available functions are
  493. \begin{center}
  494. \f{UNION, INTERSECT, DIFFSET, SYMDIFF}.
  495. \end{center}
  496. They have two arguments which must be sets otherwise an error message
  497. is issued.
  498. Their meaning is transparent from their name. They respectively give the
  499. union, the intersection, the difference and the symmetric difference of two
  500. sets.
  501. \ei
  502. \section{General Purpose Utility Functions}
  503. Functions in this sections have various purposes. They have all been used
  504. many times in applications in some form or another. The form given
  505. to them in this package is adjusted to maximize their range of applications.
  506. \bi
  507. \item[i.]
  508. The functions \f{MKIDNEW DELLASTDIGIT DETIDNUM LIST\_TO\_IDS}
  509. handle identifiers.
  510. \f{MKIDNEW} has either 0 or 1 argument.
  511. It generates an identifier which has not yet been used before.
  512. \begin{verbatim}
  513. MKIDNEW(); ==> g0001
  514. MKIDNEW(a); ==> ag0002
  515. \end{verbatim}
  516. \f{DELLASTDIGIT} takes an integer as argument and strips it from its last
  517. digit.
  518. \begin{verbatim}
  519. DELLASTDIGIT 45; ==> 4
  520. \end{verbatim}
  521. \f{DETIDNUM} deletes the last digit from an
  522. identifier. It is a very convenient function when one wants to make a do
  523. loop starting from a set of indices $ a_1, \ldots , a_{n} $.
  524. \begin{verbatim}
  525. DETIDNUM a23; ==> 23
  526. \end{verbatim}
  527. \f{LIST\_to\_IDS} generalizes the function \f{MKID} to a list of
  528. atoms. It creates and intern an identifier from the concatenation of
  529. the atoms. The first atom cannot be an integer.
  530. \begin{verbatim}
  531. LIST_TO_IDS {a,1,id,10}; ==> a1id10
  532. \end{verbatim}
  533. The function \f{ODDP} detects odd integers.
  534. The function \f{FOLLOWLINE} is convenient when using the function \f{PRIN2}.
  535. It allows one to format output text in a much more flexible way than with
  536. the function \f{WRITE}. \\
  537. Try the following examples :
  538. \begin{verbatim}
  539. <<prin2 2; prin2 5>>$ ==> ?
  540. <<prin2 2; followline(5); prin2 5;>>; ==> ?
  541. \end{verbatim}
  542. The function \f{==} is a short and convenient notation for the \f{SET}
  543. function. In fact it is a {\em generalization} of it to allow one to
  544. deal also with KERNELS:
  545. \begin{verbatim}
  546. operator op;
  547. op(x):=abs(x)$
  548. op(x) == x; ==> x
  549. op(x); ==> x
  550. abs(x); ==> x
  551. \end{verbatim}
  552. The function \f{RANDOMLIST} generates a list of random numbers. It takes
  553. two arguments which are both integers. The first one indicates the range
  554. inside which the random numbers are chosen. The second one indicates how
  555. many numbers are to be generated. Its output is the list of
  556. generated numbers.
  557. \begin{verbatim}
  558. RANDOMLIST(10,5); ==> {2,1,3,9,6}
  559. \end{verbatim}
  560. \f{MKRANDTABL} generates a table of random numbers. This table is either
  561. a one or two dimensional array. The base of random numbers may be either
  562. an integer or a decimal number. In this last case, to work properly,
  563. the switch \f{rounded} must be ON. It has three arguments. The first is
  564. either a one integer or a two integer list. The second is the base chosen
  565. to generate the random numbers. The third is the chosen name for the
  566. generated array. In the example below a two-dimensional table of
  567. random integers is generated as array elements of the identifier {\f ar}.
  568. \begin{verbatim}
  569. MKRANDTABL({3,4},10,ar); ==>
  570. *** array ar redefined
  571. {3,4}
  572. \end{verbatim}
  573. The output is the dimension of the constructed array.
  574. \f{PERMUTATIONS} gives the list of permutations of $n$ objects.
  575. Each permutation is itself a list. \f{CYCLICPERMLIST} gives the list of
  576. {\em cyclic} permutations. For both functions, the argument may
  577. also be a {\tt bag}.
  578. \begin{verbatim}
  579. PERMUTATIONS {1,2} ==> {{1,2},{2,1}}
  580. CYCLICPERMLIST {1,2,3} ==>
  581. {{1,2,3},{2,3,1},{3,1,2}}
  582. \end{verbatim}
  583. \f{PERM\_TO\_NUM} and \f{NUM\_TO\_PERM} allow to associate to a given
  584. permutation of n numbers or identifiers a number between $0$ and
  585. $n! - 1$. The first function has the two permutated lists
  586. as its arguments and it returns an integer. The second one has an integer
  587. as its first argument and a list as its second argument. It returns the
  588. list of permutated objects.
  589. \begin{verbatim}
  590. PERM_TO_NUM({4,3,2,1},{1,2,3,4}) ==> 23
  591. NUM_TO_PERM(23,{1,2,3,4}); ==> {4,3,2,1}
  592. \end{verbatim}
  593. \f{COMBNUM} gives the number of combinations of $n$ objects
  594. taken $p$ at a time. It has the two integer arguments $n$ and $p$.
  595. \f{COMBINATIONS} gives a list of combinations on $n$ objects taken $p$
  596. at a time. It has two arguments. The first one is a list (or a bag) and
  597. the second one is the integer $p$.
  598. \begin{verbatim}
  599. COMBINATIONS({1,2,3},2) ==> {{2,3},{1,3},{1,2}}
  600. \end{verbatim}
  601. \f{REMSYM} is a command that suppresses the effect of the \REDUCE\ commands
  602. \verb+symmetric+ or \verb+antisymmetric+ .
  603. \f{SYMMETRIZE} is a powerful function which generates a symmetric expression.
  604. It has 3 arguments. The first is a list (or a list of lists) containing
  605. the expressions which will appear as variables for a kernel. The second
  606. argument is the kernel-name and the third is a permutation function
  607. which exists either in algebraic or symbolic mode. This
  608. function may be constructed by the user. Within this package
  609. the two functions \f{PERMUTATIONS} and \f{CYCLICPERMLIST} may be used.
  610. Examples:
  611. \begin{verbatim}
  612. ll:={a,b,c}$
  613. SYMMETRIZE(ll,op,cyclicpermlist); ==>
  614. OP(A,B,C) + OP(B,C,A) + OP(C,A,B)
  615. SYMMETRIZE(list ll,op,cyclicpermlist); ==>
  616. OP({A,B,C}) + OP({B,C,A}) + OP({C,A,B})
  617. \end{verbatim}
  618. Notice that, taking for the first argument a list of lists gives rise to
  619. an expression where each kernel has a {\em list as argument}. Another
  620. peculiarity of this function is the fact that, unless a pattern matching is
  621. made on the operator \verb+OP+, it needs to be reevaluated. This peculiarity
  622. is convenient when \verb+OP+ is an abstract operator if one wants to
  623. control the subsequent simplification process. Here is an illustration:
  624. \begin{verbatim}
  625. op(a,b,c):=a*b*c$
  626. SYMMETRIZE(ll,op,cyclicpermlist); ==>
  627. OP(A,B,C) + OP(B,C,A) + OP(C,A,B)
  628. REVAL ws; ==>
  629. OP(B,C,A) + OP(C,A,B) + A*B*C
  630. for all x let op(x,a,b)=sin(x*a*b);
  631. SYMMETRIZE(ll,op,cyclicpermlist); ==>
  632. OP(B,C,A) + SIN(A*B*C) + OP(A,B,C)
  633. \end{verbatim}
  634. The functions \f{SORTNUMLIST} and \f{SORTLIST} are functions which sort
  635. lists. They use the {\em bubblesort} and the {\em quicksort} algorithms.
  636. \f{SORTNUMLIST} takes as argument a list of numbers. It sorts it in
  637. increasing order.
  638. \f{SORTLIST} is a generalization of the above function.
  639. It sorts the list according
  640. to any well defined ordering. Its first argument is the list and its
  641. second argument is the ordering function. The content of the list
  642. need not necessarily be numbers but must be such that the ordering function
  643. has a meaning.
  644. \f{ALGSORT} exploits the PSL \f{SORT} function. It is intended to replace
  645. the two functions above.
  646. \begin{verbatim}
  647. l:={1,3,4,0}$ SORTNUMLIST l; ==> {0,1,3,4}
  648. ll:={1,a,tt,z}$ SORTLIST(ll,ordp); ==> {a,z,tt,1}
  649. l:={-1,3,4,0}$ ALGSORT(l,>); ==> {4,3,0,-1}
  650. \end{verbatim}
  651. It is important to realise that using these functions for kernels or bags
  652. may be dangerous since they are destructive. If it is necessary, it is
  653. recommended to first apply \f{KERNLIST} to them to act on a copy.
  654. The function \f{EXTREMUM} is a generalization of the already defined functions
  655. \f{MIN, MAX} to include general orderings. It is a 2 argument function.
  656. The first is the list and the second is the ordering function.
  657. With the list \verb+ll+ defined in the last example, one gets
  658. \begin{verbatim}
  659. EXTREMUM(ll,ordp); ==> 1
  660. \end{verbatim}
  661. \f{GCDNL} takes a list of integers as argument and returns their gcd.
  662. \item[iii.] There are four functions to identify dependencies.
  663. \f{FUNCVAR} takes any expression as argument and returns the set of
  664. variables on which it depends. Constants are eliminated.
  665. \begin{verbatim}
  666. FUNCVAR(e+pi+sin(log(y)); ==> {y}
  667. \end{verbatim}
  668. \f{DEPATOM} has an {\bf atom} as argument. It returns it if it is
  669. a number or if no dependency has previously been declared. Otherwise,
  670. it returns the list of variables which the prevoius \f{DEPEND} declarations
  671. imply.
  672. \begin{verbatim}
  673. depend a,x,y;
  674. DEPATOM a; ==> {x,y}
  675. \end{verbatim}
  676. The functions \f{EXPLICIT} and \f{IMPLICIT} make explicit or
  677. implicit the dependencies. This example shows how they work:
  678. \begin{verbatim}
  679. depend a,x; depend x,y,z;
  680. EXPLICIT a; ==> a(x(y,z))
  681. IMPLICIT ws; ==> a
  682. \end{verbatim}
  683. These are useful when one wants to trace the names of the independent
  684. variables
  685. and (or) the nature of the dependencies.
  686. \f{KORDERLIST} is a zero argument function which displays the actual
  687. ordering.
  688. \begin{verbatim}
  689. korder x,y,z;
  690. KORDERLIST; ==> (x,y,z)
  691. \end{verbatim}
  692. \item[iv.] A command \f{REMNONCOM} to remove the non-commutativity of
  693. operators previously declared non-commutative is available. Its use is like
  694. the one of the command \f{NONCOM}.
  695. \item[v.] Filtering functions for lists.
  696. \f{CHECKPROPLIST} is a boolean function which checks if the
  697. elements of a list have a definite property. Its first argument
  698. is the list, its second argument is a boolean function
  699. (\f{FIXP NUMBERP $\ldots$}) or an ordering function (as \f{ORDP}).
  700. \f{EXTRACTLIST} extracts from the list given as its first argument
  701. the elements which satisfy the boolean function given as its second
  702. argument. For example:
  703. \begin{verbatim}
  704. if CHECKPROPLIST({1,2},fixp) then "ok"; ==> ok
  705. l:={1,a,b,"st")$
  706. EXTRACTLIST(l,fixp); ==> {1}
  707. EXTRACTLIST(l,stringp); ==> {st}
  708. \end{verbatim}
  709. \item[vi.] Coercion.
  710. Since lists and arrays have quite distinct behaviour and storage properties,
  711. it is interesting to coerce lists into arrays and vice-versa in order to
  712. fully exploit the advantages of both datatypes. The functions
  713. \f{ARRAY\_TO\_LIST} and \f{LIST\_TO\_ARRAY} are provided to do that easily.
  714. The first function has the array identifier as its unique argument.
  715. The second
  716. function has three arguments. The first is the list, the second is the
  717. dimension of the array and the third is the identifier which defines it.
  718. If the chosen dimension is not compatible with the
  719. the list depth, an error message is issued.
  720. As an illustration suppose that $ar$ is an array whose components are
  721. 1,2,3,4. then
  722. \begin{verbatim}
  723. ARRAY_TO_LIST ar; ==> {1,2,3,4}
  724. LIST_TO_ARRAY({1,2,3,4},1,arr}; ==>
  725. \end{verbatim}
  726. generates the array $arr$ with the components 1,2,3,4.
  727. \item[vii.] Control of the \f{HEPHYS} package.
  728. The commands \f{REMVECTOR} and \f{REMINDEX} remove the property of
  729. being a 4-vector or a 4-index respectively.
  730. The function \f{MKGAM} allows to assign to any identifier the property
  731. of a Dirac gamma matrix and, eventually, to suppress it. Its interest lies
  732. in the fact that, during a calculation, it is often useful to transform
  733. a gamma matrix into an abstract operator and vice-versa. Moreover, in many
  734. applications in basic physics, it is interesting to use the identifier $g$
  735. for other purposes.
  736. It takes two arguments. The first is the identifier. The second must be
  737. chosen equal to {\tt\bf t} if one wants to transform it into a gamma matrix. Any
  738. other binding for this second argument suppresses the property of being
  739. a gamma matrix the identifier is supposed to have.
  740. \ei
  741. \section{Properties and Flags}
  742. In spite of the fact that many facets of the handling of
  743. property lists is easily accessible in algebraic mode, it is useful to
  744. provide analogous functions {\em genuine} to the algebraic mode. The reason is
  745. that, altering property lists of objects, may easily destroy the integrity
  746. of the system. The functions, which are here described, {\bf do ignore}
  747. the property list and flags already defined by the system itself. They
  748. generate and track the {\em addtional properties and flags} that the user
  749. issues using them. They offer him
  750. the possibility to work on property lists so
  751. that he can design a programming style of the ``conceptual'' type.
  752. \bi
  753. \item[i.] We first consider ``flags''. \\
  754. To a given identifier, one may
  755. associate another one linked to it ``in the background''. The three
  756. functions \f{PUTFLAG, DISPLAYFLAG} and \f{CLEARFLAG} handle them.
  757. \f{PUTFLAG} has 3 arguments. The first one is the identifier or a list
  758. of identifiers, the second one is the name of the flag,
  759. and the third one is T (true) or 0 (zero).
  760. When the third argument is T, it creates the flag, when it is 0 it
  761. destroys it. In this last case, the function does return nil (not seen
  762. inside the algebraic mode).
  763. \begin{verbatim}
  764. PUTFLAG(z1,flag_name,t); ==> flag_name
  765. PUTFLAG({z1,z2},flag1_name,t); ==> t
  766. PUTFLAG(z2,flag1_name,0) ==>
  767. \end{verbatim}
  768. \f{DISPLAYFLAG} allows one to extract flags. The previous actions give:
  769. \begin{verbatim}
  770. DISPLAYFLAG z1; ==>{flag_name,flag1_name}
  771. DISPLAYFLAG z2 ; ==> {}
  772. \end{verbatim}
  773. \f{CLEARFLAG} is a command which clears {\em all} flags associated with
  774. the identifiers $id_1, \ldots , id_n .$
  775. \item[ii.] Properties are handled by similar functions.
  776. \f{PUTPROP} has four arguments. The second argument is, here, the
  777. {\em indicator} of the property. The third argument may be {\em any
  778. valid expression}. The fourth one is also T or 0.
  779. \begin{verbatim}
  780. PUTPROP(z1,property,x^2,t); ==> z1
  781. \end{verbatim}
  782. In general, one enters
  783. \begin{verbatim}
  784. PUTPROP(LIST(idp1,idp2,..),<propname>,<value>,T);
  785. \end{verbatim}
  786. To display a specific property, one uses
  787. \f{DISPLAYPROP} which takes two arguments. The first is the name of the
  788. identifier, the second is the indicator of the property.
  789. \begin{verbatim}
  790. 2
  791. DISPLAYPROP(z1,property); ==> {property,x }
  792. \end{verbatim}
  793. Finally, \f{CLEARPROP} is a nary commmand which clears {\em all}
  794. properties of the identifiers which appear as arguments.
  795. \ei
  796. \section{Control Functions}
  797. Here we describe additional functions which
  798. improve user control on the environment.
  799. \bi
  800. \item[i.]
  801. The first set of functions is composed of unary and binary boolean functions.
  802. They are:
  803. \begin{verbatim}
  804. ALATOMP x; x is anything.
  805. ALKERNP x; x is anything.
  806. DEPVARP(x,v); x is anything.
  807. (v is an atom or a kernel)
  808. \end{verbatim}
  809. \f{ALATOMP} has the value T iff x is an integer or an identifier
  810. {\em after} it has been evaluated down to the bottom.
  811. \f{ALKERNP} has the value T iff x is a kernel {\em after}
  812. it has been evaluated down to the bottom.
  813. \f{DEPVARP} returns T iff the expression x depends on v at
  814. {\bf any level}.
  815. The above functions together with \f{PRECP} have
  816. been declared operator functions to ease the verification of
  817. their value.
  818. \f{NORDP} is equal to \verb+NOT+\f{ ORDP}.
  819. \item[ii.]
  820. The next functions allow one to {\em analyze} and to
  821. {\em clean} the environment
  822. of \REDUCE\ created by the user while working
  823. {\bf interactively}. Two functions are provided:\\
  824. \f{SHOW} allows the user to get the various identifiers already
  825. assigned and to see their type. \f{SUPPRESS} selectively clears the
  826. used identifiers or clears them all. It is to be stressed that identifiers
  827. assigned from the input of files are {\bf ignored}.
  828. Both functions have one argument and the same options for this
  829. argument:
  830. \begin{verbatim}
  831. SHOW (SUPPRESS) all
  832. SHOW (SUPPRESS) scalars
  833. SHOW (SUPPRESS) lists
  834. SHOW (SUPPRESS) saveids (for saved expressions)
  835. SHOW (SUPPRESS) matrices
  836. SHOW (SUPPRESS) arrays
  837. SHOW (SUPPRESS) vectors
  838. (contains vector, index and tvector)
  839. SHOW (SUPPRESS) forms
  840. \end{verbatim}
  841. The option \verb+all+ is the most convenient for \f{SHOW} but,
  842. with it, it may
  843. takes some time to get the answer after one has worked several hours.
  844. When entering \REDUCE\ the option \verb+all+ for \f{SHOW} gives:
  845. \begin{verbatim}
  846. SHOW all; ==>
  847. scalars are: NIL
  848. arrays are: NIL
  849. lists are: NIL
  850. matrices are: NIL
  851. vectors are: NIL
  852. forms are: NIL
  853. \end{verbatim}
  854. It is a convenient way to remind the various options. Here is an example
  855. which is valid when one starts from a fresh environment:
  856. \begin{verbatim}
  857. a:=b:=1$
  858. SHOW scalars; ==> scalars are: (A B)
  859. SUPPRESS scalars; ==> t
  860. SHOW scalars; ==> scalars are: NIL
  861. \end{verbatim}
  862. \item[iii.]
  863. The \f{CLEAR} function of the system does not do a complete cleaning of
  864. \verb+OPERATORS+ and \verb+FUNCTIONS+ . The following two functions do a more
  865. complete cleaning and, also, automatically takes into account the
  866. {\em user} flag and properties that the functions
  867. \f{PUTFLAG} and \f{PUTPROP} may have introduced.
  868. Their names are \f{CLEAROP} and \f{CLEARFUNCTIONS}.
  869. \f{CLEAROP} takes one operator as its argument.\\
  870. \f{CLEARFUNCTIONS} is a nary command. If one issues
  871. \begin{verbatim}
  872. CLEARFUNCTIONS a1,a2, ... , an $
  873. \end{verbatim}
  874. The functions with names \verb+ a1,a2, ... ,an+ are cleared.
  875. One should be careful when using this facility since the
  876. only functions which cannot be erased are those which are
  877. protected with the \verb+lose+ flag.
  878. \ei
  879. \section{Handling of Polynomials}
  880. The module contains some utility functions to handle
  881. standard quotients and several new facilities to manipulate polynomials.
  882. \bi
  883. \item[i.] Two functions \f{ALG\_TO\_SYMB} and \f{SYMB\_TO\_ALG}
  884. allow one to change an expression which is in the algebraic standard
  885. quotient form into a prefix lisp form and vice-versa. This is done
  886. in such a way that the symbol \verb+list+ which appears in the
  887. algebraic mode disappears in the symbolic form (there it becomes
  888. a parenthesis ``()'' ) and it is reintroduced in the translation
  889. from a symbolic prefix lisp expression to an algebraic one.
  890. Here, is an example, showing how the wellknown lisp function
  891. \f{FLATTENS} can be trivially transposed inside the algebraic mode:
  892. \begin{verbatim}
  893. algebraic procedure ecrase x;
  894. lisp symb_to_alg flattens1 alg_to_symb algebraic x;
  895. symbolic procedure flattens1 x;
  896. % ll; ==> ((A B) ((C D) E))
  897. % flattens1 ll; (A B C D E)
  898. if atom x then list x else
  899. if cdr x then
  900. append(flattens1 car x, flattens1 cdr x)
  901. else flattens1 car x;
  902. \end{verbatim}
  903. gives, for instance,
  904. \begin{verbatim}
  905. ll:={a,{b,{c},d,e},{{{z}}}}$
  906. ECRASE ll; ==> {A, B, C, D, E, Z}
  907. \end{verbatim}
  908. The function \f{MKDEPTH\_ONE} described above implements that functionality.
  909. \item[ii.]
  910. \f{LEADTERM} and \f{REDEXPR} are the algebraic equivalent of the
  911. symbolic functions \f{LT} and \f{RED}. They give, respectively, the
  912. {\em leading term} and the {\em reductum} of a polynomial. They also work
  913. for rational functions. Their interest lies in the fact that they do not
  914. @@require one to extract the main variable. They work according to the current
  915. ordering of the system:
  916. \begin{verbatim}
  917. pol:=x++y+z$
  918. LEADTERM pol; ==> x
  919. korder y,x,z;
  920. LEADTERM pol; ==> y
  921. REDEXPR pol; ==> x + z
  922. \end{verbatim}
  923. By default, the representation of multivariate polynomials is recursive.
  924. It is justified since it is the one which takes the least memory.
  925. With such a representation, the function \f{LEADTERM} does not necessarily
  926. extract a true monom. It extracts a monom in the leading indeterminate
  927. multiplied by a polynomial in the other indeterminates. However, very often,
  928. one needs to handle true monoms separately. In that case, one needs a
  929. polynomial in {\em distributive} form. Such a form is provided by the
  930. package GROEBNER (H. Melenk et al.). The facility there is, however,
  931. much too involved in many applications and the necessity to load the package
  932. makes it interesting
  933. to construct an elementary facility to handle the distributive representation
  934. of polynomials. A new switch has been created for that purpose.
  935. It is called {\tt DISTRIBUTE} and a new function \f{DISTRIBUTE} puts a
  936. polynomial in distributive form. With that switch set to {\bf on},
  937. \f{LEADTERM} gives {\bf true} monoms.
  938. \f{MONOM} transforms a polynomial into a list of monoms. It works
  939. {\em whatever the position of the switch} {\tt DISTRIBUTE}.
  940. \f{SPLITTERMS} is analoguous to \f{MONOM} except that it gives
  941. a list of two lists. The first sublist contains the positive terms
  942. while the second sublist contains the negative terms.
  943. \f{SPLITPLUSMINUS} gives a list whose first element is the positive
  944. part of the polynomial and its second element is its negative part.
  945. \item[iii.]
  946. Two complementary functions \f{LOWESTDEG} and \f{DIVPOL} are provided.
  947. The first takes a polynomial as its first argument and the name of an
  948. indeterminate as its second argument. It returns the {\em lowest degree}
  949. in that indeterminate. The second function takes two polynomials and
  950. returns both the quotient and its remainder.
  951. \ei
  952. \section{Handling of Transcendental Functions}
  953. %\item[i.]
  954. The functions \f{TRIGREDUCE} and \f{TRIGEXPAND} and the equivalent
  955. @@ones for hyperbolic functions \f{HYPREDUCE} and \f{HYPEXPAND}
  956. make the transformations to multiple arguments and from
  957. @@multiple arguments to elementary arguments. Here is a simple example:
  958. \begin{verbatim}
  959. aa:=sin(x+y)$
  960. TRIGEXPAND aa; ==> SIN(X)*COS(Y) + SIN(Y)*COS(X)
  961. TRIGREDUCE ws; ==> SIN(Y + X)
  962. \end{verbatim}
  963. When a trigonometric or hyperbolic expression is symmetric with
  964. respect to the interchange of {\tt SIN (SINH)} and {\tt COS (COSH)},
  965. the application of\nl \f{TRIG(HYP)-REDUCE} may often lead to great
  966. simplifications. However, if it is highly assymetric, the repeated
  967. application of \f{TRIG(HYP)-REDUCE} followed by the use of
  968. \f{TRIG(HYP)-EXPAND} will lead to {\em more} complicated
  969. but more symmetric expressions:
  970. \begin{verbatim}
  971. aa:=(sin(x)^2+cos(x)^2)^3$
  972. TRIGREDUCE aa; ==> 1
  973. \end{verbatim}
  974. \begin{verbatim}
  975. bb:=1+sin(x)^3$
  976. TRIGREDUCE bb; ==>
  977. - SIN(3*X) + 3*SIN(X) + 4
  978. ---------------------------
  979. 4
  980. TRIGEXPAND ws; ==>
  981. 3 2
  982. SIN(X) - 3*SIN(X)*COS(X) + 3*SIN(X) + 4
  983. -------------------------------------------
  984. 4
  985. \end{verbatim}
  986. %\ei
  987. %\section{Coercion from lists to arrays and converse}
  988. %Sometimes when a list is very long and,
  989. % especially if frequent access to its elements are needed,
  990. %it is advantageous to (temporarily) transform it into an array.\nl
  991. %\f{LIST\_TO\_ARRAY} has three arguments. The first is the list. The
  992. %second is an integer which indicates the array dimension required. The
  993. %third is the name of an identifier which will play the role of the array
  994. %name generated by it. If the chosen dimension is not compatible with the
  995. % the list depth, an error message is issued.
  996. %\f{ARRAY\_TO\_LIST} does the opposite coercion. It takes the array
  997. %name as its unique argument.
  998. \section{Handling of n--dimensional Vectors}
  999. Explicit vectors in {\tt EUCLIDEAN} space may be represented by
  1000. list-like or bag-like objects of depth 1.
  1001. The components may be bags but may {\bf not} be lists.
  1002. Functions are provided to do the sum, the difference and the
  1003. @@scalar product. When the space-dimension is three there are also functions
  1004. for the cross and mixed products.
  1005. \f{SUMVECT, MINVECT, SCALVECT, CROSSVECT} have two arguments.
  1006. \f{MPVECT} has three arguments. The following example
  1007. is sufficient to explain how they work:
  1008. \begin{verbatim}
  1009. l:={1,2,3}$
  1010. ll:=list(a,b,c)$
  1011. SUMVECT(l,ll); ==> {A + 1,B + 2,C + 3}
  1012. MINVECT(l,ll); ==> { - A + 1, - B + 2, - C + 3}
  1013. SCALVECT(l,ll); ==> A + 2*B + 3*C
  1014. CROSSVECT(l,ll); ==> { - 3*B + 2*C,3*A - C, - 2*A + B}
  1015. MPVECT(l,ll,l); ==> 0
  1016. \end{verbatim}
  1017. \section{Handling of Grassmann Operators}
  1018. Grassman variables are often used in physics. For them the multiplication
  1019. operation is associative, distributive but anticommutative. The
  1020. {\tt KERNEL} of \REDUCE\ does not provide it. However, implementing
  1021. it in full generality would almost
  1022. certainly decrease the overall efficiency of the system. This small
  1023. module together with the declaration of antisymmetry for operators is
  1024. enough to deal with most calculations. The reason is, that a
  1025. product of similar anticommuting kernels can easily be transformed
  1026. into an antisymmetric operator with as many indices as the number of
  1027. these kernels. Moreover, one may also issue pattern matching rules
  1028. to implement the anticommutativity of the product.
  1029. The functions in this module represent the minimum functionality
  1030. required to identify them and to handle their specific features.
  1031. \f{PUTGRASS} is a (nary) command which give identifiers the property
  1032. @@of being the names of Grassmann kernels. \f{REMGRASS} removes this property.
  1033. \f{GRASSP} is a boolean function which detects grassmann kernels.
  1034. \f{GRASSPARITY} takes a {\bf monom} as argument and gives its parity.
  1035. If the monom is a simple grassmann kernel it returns 1.
  1036. \f{GHOSTFACTOR} has two arguments. Each one is a monom. It is equal to
  1037. \begin{verbatim}
  1038. (-1)**(GRASSPARITY u * GRASSPARITY v)
  1039. \end{verbatim}
  1040. Here is an illustration to show how the above functions work:
  1041. \begin{verbatim}
  1042. PUTGRASS eta; ==> t
  1043. if GRASSP eta(1) then "grassmann kernel"; ==>
  1044. grassmann kernel
  1045. aa:=eta(1)*eta(2)-eta(2)*eta(1); ==>
  1046. AA := - ETA(2)*ETA(1) + ETA(1)*ETA(2)
  1047. GRASSPARITY eta(1); ==> 1
  1048. GRASSPARITY (eta(1)*eta(2)); ==> 0
  1049. GHOSTFACTOR(eta(1),eta(2)); ==> -1
  1050. grasskernel:=
  1051. {eta(~x)*eta(~y) => -eta y * eta x when nordp(x,y),
  1052. (~x)*(~x) => 0 when grassp x};
  1053. exp:=eta(1)^2$
  1054. exp where grasskernel; ==> 0
  1055. aa where grasskernel; ==> - 2*ETA(2)*ETA(1)
  1056. \end{verbatim}
  1057. \section{Handling of Matrices}
  1058. This module provides functions for handling matrices more comfortably.
  1059. \bi
  1060. \item[i.]
  1061. Often, one needs to construct some {\tt UNIT} matrix of
  1062. a given dimension. This construction is done by the system thanks
  1063. @@to the function \f{UNITMAT}. It is a nary function. The command is
  1064. \begin{verbatim}
  1065. UNITMAT M1(n1), M2(n2), .....Mi(ni) ;
  1066. \end{verbatim}
  1067. where \verb+M1,...Mi+ are names of matrices and
  1068. \verb+ n1, n2, ..., ni+ are integers .
  1069. @@\f{MKIDM} is a generalization of \f{MKID}. It allows one to connect
  1070. two or several matrices. If \verb+u+ and \verb+u1+ are two matrices,
  1071. one can go from one to the other:
  1072. \begin{verbatim}
  1073. matrix u(2,2);$ unitmat u1(2)$
  1074. u1; ==>
  1075. [1 0]
  1076. [ ]
  1077. [0 1]
  1078. mkidm(u,1); ==>
  1079. [1 0]
  1080. [ ]
  1081. [0 1]
  1082. \end{verbatim}
  1083. @@This function allows one to make loops on matrices like in the following
  1084. illustration. If \verb+U, U1, U2,.., U5+ are matrices:
  1085. \begin{verbatim}
  1086. FOR I:=1:5 DO U:=U-MKIDM(U,I);
  1087. \end{verbatim}
  1088. can be issued.
  1089. \item[ii.]
  1090. The next functions map matrices on bag-like or list-like objects
  1091. and conversely they generate matrices from bags or lists.
  1092. \f{COERCEMAT} transforms the matrix \verb+U+ into a list of lists.
  1093. The entry is
  1094. \begin{verbatim}
  1095. COERCEMAT(U,id)
  1096. \end{verbatim}
  1097. where \verb+id+ is equal to \verb+list+ othewise it transforms it into
  1098. a bag of bags whose envelope is equal to \verb+id+.
  1099. \f{BAGLMAT} does the opposite job. The {\bf first} argument is the
  1100. bag-like or list-like object while the second argument is the matrix
  1101. identifier. The entry is
  1102. \begin{verbatim}
  1103. BAGLMAT(bgl,U)
  1104. \end{verbatim}
  1105. \verb+bgl+ becomes the matrix \verb+U+ . The transformation is
  1106. {\bf not} done if \verb+U+ is {\em already} the name of a
  1107. previously defined matrix. This is to avoid ACCIDENTAL redefinition
  1108. of that matrix.
  1109. \item[ii.]
  1110. The functions \f{SUBMAT, MATEXTR, MATEXTC} take parts of a given matrix.
  1111. \f{SUBMAT} has three arguments. The entry is
  1112. \begin{verbatim}
  1113. SUBMAT(U,nr,nc)
  1114. \end{verbatim}
  1115. The first is the matrix name, and the other two are the row and column
  1116. @@numbers. It gives the
  1117. @@submatrix obtained from \verb+U+ by deleting the row \verb+nr+ and
  1118. the column \verb+nc+.
  1119. When one of them is equal to zero only column \verb+nc+
  1120. or row \verb+nr+ is deleted.
  1121. \f{MATEXTR} and \f{MATEXTC} extract a row or a column and place it into
  1122. a list-like or bag-like object.
  1123. @@The entries are
  1124. \begin{verbatim}
  1125. MATEXTR(U,VN,nr)
  1126. MATEXTC(U,VN,nc)
  1127. \end{verbatim}
  1128. where \verb+U+ is the matrix, \verb+VN+ is the ``vector name'',
  1129. \verb+nr+ and \verb+nc+ are integers. If \verb+VN+ is equal
  1130. to {\tt list} the vector is given as a list otherwise it is
  1131. given as a bag.
  1132. \item[iii.]
  1133. Functions which manipulate matrices. They are
  1134. \f{MATSUBR, MATSUBC, HCONCMAT, VCONCMAT, TPMAT, HERMAT}
  1135. \f{MATSUBR MATSUBC} substitute rows and columns. They have three arguments.
  1136. Entries are:
  1137. \begin{verbatim}
  1138. MATSUBR(U,bgl,nr)
  1139. MATSUBC(U,bgl,nc)
  1140. \end{verbatim}
  1141. The meaning of the variables \verb+U, nr, nc+ is the same as above
  1142. while \verb+bgl+ is a list-like or bag-like vector.
  1143. Its length should be compatible with the dimensions of the matrix.
  1144. \f{HCONCMAT VCONCMAT} concatenate two matrices. The entries are
  1145. \begin{verbatim}
  1146. HCONCMAT(U,V)
  1147. VCONCMAT(U,V)
  1148. \end{verbatim}
  1149. The first function concatenates horizontally, the second one
  1150. concatenates vertically. The dimensions must match.
  1151. \f{TPMAT} makes the tensor product of two matrices. It is also an
  1152. {\em infix} function. The entry is
  1153. \begin{verbatim}
  1154. TPMAT(U,V) or U TPMAT V
  1155. \end{verbatim}
  1156. \f{HERMAT} takes the hermitian conjuguate of a matrix
  1157. The entry is
  1158. \begin{verbatim}
  1159. HERMAT(U,HU)
  1160. \end{verbatim}
  1161. where \verb+HU+ is the identifier for the hermitian matrix of \verb+U+.
  1162. @@It should be {\bf unassigned} for this function to work successfully.
  1163. This is done on purpose to prevent accidental redefinition of an already
  1164. used identifier .
  1165. \item[iv.]
  1166. \f{SETELMAT GETELMAT} are functions of two integers. The first one
  1167. @@resets the element \verb+(i,j)+ while the second one extracts an
  1168. element identified by \verb+(i,j)+. They may be useful when
  1169. dealing with matrices {\em inside procedures}.
  1170. \ei
  1171. \end{document}