ASSIST.TEX 46 KB

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