ASSIST contains a large number of additional general purpose functions that allow a user to better adapt REDUCE to various calculational strategies and to make the programming task more straightforward and more efficient.
Author: Hubert Caprasse.
The package ASSIST contains an appreciable number of additional general purpose functions which allow one to better adapt REDUCE to various calculational strategies, to make the programming task more straightforward and, sometimes, more efficient.
In contrast with all other packages, ASSIST does not aim to provide either a new facility to compute a definite class of mathematical objects or to extend the base of mathematical knowledge of REDUCE . The functions it contains should be useful independently of the nature of the application which is considered. They were initially written while applying REDUCE to specific problems in theoretical physics. Most of them were designed in such a way that their applicability range is broad. Though it was not the primary goal, efficiency has been sought whenever possible.
The source code in ASSIST contains many comments concerning the meaning and use of the supplementary functions available in the algebraic mode. These comments, hopefully, make the code transparent and allow a thorough exploitation of the package. The present documentation contains a non–technical description of it and describes the various new facilities it provides.
An elementary help facility is available both within the MS-DOS and Windows environments. It is independent of the help facility of REDUCE itself. It includes two functions:
ASSIST is a function which takes no argument. If entered, it returns the informations
required for a proper use of ASSISTHELP.
ASSISTHELP takes one argument.
The package contains several modules. Their content reflects closely the various categories of facilities listed below. Some functions do already exist inside the KERNEL of REDUCE . However, their range of applicability is extended.
MKLIST KERNLIST ALGNLIST LENGTH POSITION FREQUENCY SEQUENCES SPLIT INSERT INSERT_KEEP_ORDER MERGE_LIST FIRST SECOND THIRD REST REVERSE LAST BELAST CONS ( . ) APPEND APPENDN REMOVE DELETE DELETE_ALL DELPAIR MEMBER ELMULT PAIR DEPTH MKDEPTH_ONE REPFIRST REPREST ASFIRST ASLAST ASREST ASFLIST ASSLIST RESTASLIST SUBSTITUTE BAGPROP PUTBAG CLEARBAG BAGP BAGLISTP ALISTP ABAGLISTP LISTBAG
MKSET SETP UNION INTERSECT DIFFSET SYMDIFF
LIST_TO_IDS MKIDN MKIDNEW DELLASTDIGIT
PUTFLAG PUTPROP DISPLAYPROP DISPLAYFLAG
NORDP DEPVARP ALATOMP ALKERNP PRECP
TRIGEXPAND HYPEXPAND TRIGREDUCE HYPREDUCE
SUMVECT MINVECT SCALVECT CROSSVECT MPVECT
PUTGRASS REMGRASS GRASSP GRASSPARITY GHOSTFACTOR
UNITMAT MKIDM BAGLMAT COERCEMAT
REMVECTOR REMINDEX MKGAM
In the following all these functions are described.
The two available functions i.e. SWITCHES, SWITCHORG have no argument and are called as if they were mere identifiers.
SWITCHES displays the actual status of the most frequently used switches when manipulating rational functions. The chosen switches are
EXP, ALLFAC, EZGCD, GCD, MCD, LCM, DIV, RAT,
The new switch DISTRIBUTE allows one to put polynomials in a distributed form (see the description below of the new functions for manipulating them. ).
Most of the symbolic variables !*EXP, !*DIV, … which have either the value T or the value NIL are made available in the algebraic mode so that it becomes possible to write conditional statements of the kind
SWITCHORG resets the switches enumerated above to the status they had when starting REDUCE .
Additional functions for list manipulations are provided and some already defined functions in the kernel of REDUCE are modified to properly generalize them to the available new structure BAG.
An arbitrary splitting of a list can be done. The function SPLIT generates a list which contains the splitted parts of the original list.
The function ALGNLIST constructs a list which contains n copies of a list bound to its first argument.
The function KERNLIST transforms any prefix of a kernel into the list prefix. The output list is a copy:
Four functions to delete elements are DELETE, REMOVE, DELETE_ALL and DELPAIR. The first two act as in symbolic mode, and the third eliminates from a given list all elements equal to its first argument. The fourth acts on a list of pairs and eliminates from it the first pair whose first element is equal to its first argument :
The functions INSERT_KEEP_ORDER and MERGE_LIST allow one to keep a given ordering when inserting one element inside a list or when merging two lists. Both have 3 arguments. The last one is the name of a binary boolean ordering function:
Notice that MERGE_LIST will act correctly only if the two lists are well ordered themselves.
. (“dot”), POSITION, DEPTH, MKDEPTH_ONE,
POSITION returns the POSITION of the first occurrence of x in a list or a message if x is not present in it.
DEPTH returns an integer equal to the number of levels where a list is found if and only if this number is the same for each element of the list otherwise it returns a message telling the user that the list is of unequal depth. The function MKDEPTH_ONE allows to transform any list into a list of depth equal to 1.
PAIR has two arguments which must be lists. It returns a list whose elements are
lists of two elements. The nth sublist contains the nth element of the first list
and the nth element of the second list. These types of lists are called
association lists or ALISTS in the following. To test for these type of
lists a boolean function ABAGLISTP is provided. It will be discussed
APPENDN has any fixed number of lists as arguments. It generalizes the already existing function APPEND which accepts only two lists as arguments. It may also be used for arbitrary kernels but, in that case, it is important to notice that the concatenated object is always a list.
REPFIRST has two arguments. The first one is any object, the second one is a list. It replaces the first element of the list by the object. It works like the symbolic function REPLACA except that the original list is not destroyed.
REPREST has also two arguments. It replaces the rest of the list by its first argument and returns the new list without destroying the original list. It is analogous to the symbolic function REPLACD. Here are examples:
The LIST structure of REDUCE is very convenient for manipulating groups of objects which are, a priori, unknown. This structure is endowed with other properties such as “mapping” i.e. the fact that if OP is an operator one gets, by default,
It is not permitted to submit lists to the operations valid on rings so that, for example,
lists cannot be indeterminates of polynomials.
Very frequently too, procedure arguments cannot be lists. At the other extreme, so to say, one has the KERNEL structure associated with the algebraic declaration operator . This structure behaves as an “unbreakable” one and, for that reason, behaves like an ordinary identifier. It may generally be bound to all non-numeric procedure parameters and it may appear as an ordinary indeterminate inside polynomials.
The BAG structure is intermediate between a list and an operator. From the operator it borrows the property of being a KERNEL and, therefore, may be an indeterminate of a polynomial. From the list structure it borrows the property of being a composite object.
A bag is an object endowed with the following properties:
declares id1,.....,idn as bag envelopes. Analogously, the command
eliminates the bag property on id1,...,idn.
FIRST, SECOND, LAST, REST, BELAST, DEPTH,
the NAME of the ENVELOPE is KEPT by the functions
FIRST, SECOND and LAST.
Here are a few examples (more examples are given inside the test file):
When “appending” two bags with different envelopes, the resulting bag gets the
name of the one bound to the first parameter of APPEND. When APPENDN is used,
the output is always a list.
The function LENGTH gives the number of objects contained in the bag.
The identifier <id>, if allowed, is automatically declared as a bag envelope or an
error message is generated.
Finally, two boolean functions which work both for bags and lists are provided. They are BAGLISTP and ABAGLISTP. They return t or nil (in a conditional statement) if their argument is a bag or a list for the first one, or if their argument is a list of sublists or a bag containing bags for the second one.
Functions for sets exist at the level of symbolic mode. The package makes them available in algebraic mode but also generalizes them so that they can be applied to bag-like objects as well.
SETP is a boolean function which recognizes set–like objects.
UNION, INTERSECT, DIFFSET, SYMDIFF.
They have two arguments which must be sets otherwise an error message is issued. Their meaning is transparent from their name. They respectively give the union, the intersection, the difference and the symmetric difference of two sets.
Functions in this sections have various purposes. They have all been used many times in applications in some form or another. The form given to them in this package is adjusted to maximize their range of applications.
MKIDNEW has either 0 or 1 argument. It generates an identifier which has not yet been used before.
DELLASTDIGIT takes an integer as argument and strips it from its last digit.
DETIDNUM deletes the last digit from an identifier. It is a very convenient function when one wants to make a do loop starting from a set of indices a1,…,an.
LIST_to_IDS generalizes the function MKID to a list of atoms. It creates and intern an identifier from the concatenation of the atoms. The first atom cannot be an integer.
The function ODDP detects odd integers.
The function FOLLOWLINE is convenient when using the function PRIN2. It
allows one to format output text in a much more flexible way than with the
Try the following examples :
The function == is a short and convenient notation for the SET function. In fact it is a generalization of it to allow one to deal also with KERNELS:
The function RANDOMLIST generates a list of random numbers. It takes two arguments which are both integers. The first one indicates the range inside which the random numbers are chosen. The second one indicates how many numbers are to be generated. Its output is the list of generated numbers.
MKRANDTABL generates a table of random numbers. This table is either a one or two dimensional array. The base of random numbers may be either an integer or a decimal number. In this last case, to work properly, the switch rounded must be ON. It has three arguments. The first is either a one integer or a two integer list. The second is the base chosen to generate the random numbers. The third is the chosen name for the generated array. In the example below a two-dimensional table of random integers is generated as array elements of the identifier ar.
The output is the dimension of the constructed array.
PERMUTATIONS gives the list of permutations of n objects. Each permutation is itself a list. CYCLICPERMLIST gives the list of cyclic permutations. For both functions, the argument may also be a bag.
PERM_TO_NUM and NUM_TO_PERM allow to associate to a given permutation of n numbers or identifiers a number between 0 and n! - 1. The first function has the two permutated lists as its arguments and it returns an integer. The second one has an integer as its first argument and a list as its second argument. It returns the list of permutated objects.
COMBNUM gives the number of combinations of n objects taken p at a time. It has the two integer arguments n and p.
COMBINATIONS gives a list of combinations on n objects taken p at a time. It has two arguments. The first one is a list (or a bag) and the second one is the integer p.
REMSYM is a command that suppresses the effect of the REDUCE commands symmetric or antisymmetric .
SYMMETRIZE is a powerful function which generates a symmetric expression. It has 3 arguments. The first is a list (or a list of lists) containing the expressions which will appear as variables for a kernel. The second argument is the kernel-name and the third is a permutation function which exists either in algebraic or symbolic mode. This function may be constructed by the user. Within this package the two functions PERMUTATIONS and CYCLICPERMLIST may be used. Examples:
Notice that, taking for the first argument a list of lists gives rise to an expression where each kernel has a list as argument. Another peculiarity of this function is the fact that, unless a pattern matching is made on the operator OP, it needs to be reevaluated. This peculiarity is convenient when OP is an abstract operator if one wants to control the subsequent simplification process. Here is an illustration:
The functions SORTNUMLIST and SORTLIST are functions which sort lists. They use the bubblesort and the quicksort algorithms.
SORTNUMLIST takes as argument a list of numbers. It sorts it in increasing order.
SORTLIST is a generalization of the above function. It sorts the list according to any well defined ordering. Its first argument is the list and its second argument is the ordering function. The content of the list need not necessarily be numbers but must be such that the ordering function has a meaning. ALGSORT exploits the PSL SORT function. It is intended to replace the two functions above.
It is important to realise that using these functions for kernels or bags may be dangerous since they are destructive. If it is necessary, it is recommended to first apply KERNLIST to them to act on a copy.
The function EXTREMUM is a generalization of the already defined functions MIN, MAX to include general orderings. It is a 2 argument function. The first is the list and the second is the ordering function. With the list ll defined in the last example, one gets
GCDNL takes a list of integers as argument and returns their gcd.
DEPATOM has an atom as argument. It returns it if it is a number or if no dependency has previously been declared. Otherwise, it returns the list of variables which the prevoius DEPEND declarations imply.
The functions EXPLICIT and IMPLICIT make explicit or implicit the dependencies. This example shows how they work:
These are useful when one wants to trace the names of the independent variables and (or) the nature of the dependencies.
KORDERLIST is a zero argument function which displays the actual ordering.
CHECKPROPLIST is a boolean function which checks if the elements of a list have a definite property. Its first argument is the list, its second argument is a boolean function (FIXP NUMBERP …) or an ordering function (as ORDP).
EXTRACTLIST extracts from the list given as its first argument the elements which satisfy the boolean function given as its second argument. For example:
Since lists and arrays have quite distinct behaviour and storage properties, it is interesting to coerce lists into arrays and vice-versa in order to fully exploit the advantages of both datatypes. The functions ARRAY_TO_LIST and LIST_TO_ARRAY are provided to do that easily. The first function has the array identifier as its unique argument. The second function has three arguments. The first is the list, the second is the dimension of the array and the third is the identifier which defines it. If the chosen dimension is not compatible with the the list depth, an error message is issued. As an illustration suppose that ar is an array whose components are 1,2,3,4. then
generates the array arr with the components 1,2,3,4.
The commands REMVECTOR and REMINDEX remove the property of being a 4-vector or a 4-index respectively.
The function MKGAM allows to assign to any identifier the property of a Dirac gamma matrix and, eventually, to suppress it. Its interest lies in the fact that, during a calculation, it is often useful to transform a gamma matrix into an abstract operator and vice-versa. Moreover, in many applications in basic physics, it is interesting to use the identifier g for other purposes. It takes two arguments. The first is the identifier. The second must be chosen equal to t if one wants to transform it into a gamma matrix. Any other binding for this second argument suppresses the property of being a gamma matrix the identifier is supposed to have.
In spite of the fact that many facets of the handling of property lists is easily accessible in algebraic mode, it is useful to provide analogous functions genuine to the algebraic mode. The reason is that, altering property lists of objects, may easily destroy the integrity of the system. The functions, which are here described, do ignore the property list and flags already defined by the system itself. They generate and track the addtional properties and flags that the user issues using them. They offer him the possibility to work on property lists so that he can design a programming style of the “conceptual” type.
PUTFLAG has 3 arguments. The first one is the identifier or a list of identifiers, the second one is the name of the flag, and the third one is T (true) or 0 (zero). When the third argument is T, it creates the flag, when it is 0 it destroys it. In this last case, the function does return nil (not seen inside the algebraic mode).
DISPLAYFLAG allows one to extract flags. The previous actions give:
CLEARFLAG is a command which clears all flags associated with the identifiers id1,…,idn.
In general, one enters
To display a specific property, one uses DISPLAYPROP which takes two arguments. The first is the name of the identifier, the second is the indicator of the property.
Finally, CLEARPROP is a nary commmand which clears all properties of the identifiers which appear as arguments.
Here we describe additional functions which improve user control on the environment.
ALATOMP has the value T iff x is an integer or an identifier after it has been evaluated down to the bottom.
ALKERNP has the value T iff x is a kernel after it has been evaluated down to the bottom.
DEPVARP returns T iff the expression x depends on v at any level.
The above functions together with PRECP have been declared operator functions to ease the verification of their value.
NORDP is equal to NOT ORDP.
The option all is the most convenient for SHOW but, with it, it may takes some time to get the answer after one has worked several hours. When entering REDUCE the option all for SHOW gives:
It is a convenient way to remind the various options. Here is an example which is valid when one starts from a fresh environment:
complete cleaning and, also, automatically takes into account the user flag and properties that the functions PUTFLAG and PUTPROP may have introduced.
Their names are CLEAROP and CLEARFUNCTIONS. CLEAROP takes one
operator as its argument.
CLEARFUNCTIONS is a nary command. If one issues
The functions with names a1,a2, ... ,an are cleared. One should be careful when using this facility since the only functions which cannot be erased are those which are protected with the lose flag.
The module contains some utility functions to handle standard quotients and several new facilities to manipulate polynomials.
gives, for instance,
The function MKDEPTH_ONE described above implements that functionality.
By default, the representation of multivariate polynomials is recursive. It is justified since it is the one which takes the least memory. With such a representation, the function LEADTERM does not necessarily extract a true monom. It extracts a monom in the leading indeterminate multiplied by a polynomial in the other indeterminates. However, very often, one needs to handle true monoms separately. In that case, one needs a polynomial in distributive form. Such a form is provided by the package GROEBNER (H. Melenk et al.). The facility there is, however, much too involved in many applications and the necessity to load the package makes it interesting to construct an elementary facility to handle the distributive representation of polynomials. A new switch has been created for that purpose. It is called DISTRIBUTE and a new function DISTRIBUTE puts a polynomial in distributive form. With that switch set to on, LEADTERM gives true monoms.
MONOM transforms a polynomial into a list of monoms. It works whatever the position of the switch DISTRIBUTE.
SPLITTERMS is analoguous to MONOM except that it gives a list of two lists. The first sublist contains the positive terms while the second sublist contains the negative terms.
SPLITPLUSMINUS gives a list whose first element is the positive part of the polynomial and its second element is its negative part.
The functions TRIGREDUCE and TRIGEXPAND and the equivalent ones for hyperbolic functions HYPREDUCE and HYPEXPAND make the transformations to multiple arguments and from multiple arguments to elementary arguments. Here is a simple example:
When a trigonometric or hyperbolic expression is symmetric with respect to the interchange of SIN (SINH) and COS (COSH), the application of TRIG(HYP)-REDUCE may often lead to great simplifications. However, if it is highly assymetric, the repeated application of TRIG(HYP)-REDUCE followed by the use of TRIG(HYP)-EXPAND will lead to more complicated but more symmetric expressions:
Explicit vectors in EUCLIDEAN space may be represented by list-like or bag-like objects of depth 1. The components may be bags but may not be lists. Functions are provided to do the sum, the difference and the scalar product. When the space-dimension is three there are also functions for the cross and mixed products. SUMVECT, MINVECT, SCALVECT, CROSSVECT have two arguments. MPVECT has three arguments. The following example is sufficient to explain how they work:
Grassman variables are often used in physics. For them the multiplication operation is associative, distributive but anticommutative. The KERNEL of REDUCE does not provide it. However, implementing it in full generality would almost certainly decrease the overall efficiency of the system. This small module together with the declaration of antisymmetry for operators is enough to deal with most calculations. The reason is, that a product of similar anticommuting kernels can easily be transformed into an antisymmetric operator with as many indices as the number of these kernels. Moreover, one may also issue pattern matching rules to implement the anticommutativity of the product. The functions in this module represent the minimum functionality required to identify them and to handle their specific features.
PUTGRASS is a (nary) command which give identifiers the property of being the names of Grassmann kernels. REMGRASS removes this property.
GRASSP is a boolean function which detects grassmann kernels.
GRASSPARITY takes a monom as argument and gives its parity. If the monom is a simple grassmann kernel it returns 1.
GHOSTFACTOR has two arguments. Each one is a monom. It is equal to
Here is an illustration to show how the above functions work:
This module provides functions for handling matrices more comfortably.
where M1,...Mi are names of matrices and n1, n2, ..., ni are integers .
MKIDM is a generalization of MKID. It allows one to connect two or several matrices. If u and u1 are two matrices, one can go from one to the other:
This function allows one to make loops on matrices like in the following illustration. If U, U1, U2,.., U5 are matrices:
can be issued.
COERCEMAT transforms the matrix U into a list of lists. The entry is
where id is equal to list othewise it transforms it into a bag of bags whose envelope is equal to id.
BAGLMAT does the opposite job. The first argument is the bag-like or list-like object while the second argument is the matrix identifier. The entry is
bgl becomes the matrix U . The transformation is not done if U is already the name of a previously defined matrix. This is to avoid ACCIDENTAL redefinition of that matrix.
SUBMAT has three arguments. The entry is
The first is the matrix name, and the other two are the row and column numbers. It gives the submatrix obtained from U by deleting the row nr and the column nc. When one of them is equal to zero only column nc or row nr is deleted.
MATEXTR and MATEXTC extract a row or a column and place it into a list-like or bag-like object. The entries are
where U is the matrix, VN is the “vector name”, nr and nc are integers. If VN is equal to list the vector is given as a list otherwise it is given as a bag.
MATSUBR MATSUBC substitute rows and columns. They have three arguments. Entries are:
The meaning of the variables U, nr, nc is the same as above while bgl is a list-like or bag-like vector. Its length should be compatible with the dimensions of the matrix.
HCONCMAT VCONCMAT concatenate two matrices. The entries are
The first function concatenates horizontally, the second one concatenates vertically. The dimensions must match.
TPMAT makes the tensor product of two matrices. It is also an infix function. The entry is
HERMAT takes the hermitian conjuguate of a matrix The entry is
where HU is the identifier for the hermitian matrix of U. It should be unassigned for this function to work successfully. This is done on purpose to prevent accidental redefinition of an already used identifier .