]>
There are many times when you compute a complicated expression and then wish to use that expression as the body of a function. Axiom provides an operation called function to do function:from an object this. function:made by function @{made by function} It creates a function object and places it into the workspace. There are several versions, depending on how many arguments the function has. The first argument to function is always the expression to be converted into the function body, and the second is always the name to be used for the function. For more information, see section MakeFunctionXmpPage .
Start with a simple example of a polynomial in three variables.
To make this into a function of no arguments that simply returns the polynomial, use the two argument form of function.
To avoid possible conflicts (see below), it is a good idea to quote always this second argument.
This is what you get when you evaluate the function.
To make a function in , use a version of function that takes three arguments. The last argument is the name of the variable to use as the parameter. Typically, this variable occurs in the expression and, like the function name, you should quote it to avoid possible confusion.
This is what the new function looks like.
This is the value of f1 at . Notice that the return type of the function is Polynomial (Integer), the same as .
To use and as parameters, use the four argument form of function.
Evaluate at and . The return type of f2 is still Polynomial(Integer) because the variable is still present and not one of the parameters.
Finally, use all three variables as parameters. There is no five argument form of function, so use the one with three arguments, the third argument being a list of the parameters.
Evaluate this using the same values for and as above, but let be . The result type of f3 is Integer.
The four functions we have defined via have been undeclared. To declare a function whose body is to be generated by function:declaring function, issue the declaration before the function is created.
It is an error to use without the quote in the penultimate expression since had been declared but did not have a value. Similarly, since it is common to overuse variable names like , , and so on, you avoid problems if you always quote the variable names for function. In general, if has a value and you use without a quote in a call to function, then Axiom does not know what you are trying to do.
What kind of object is allowable as the first argument to function? Let's use the Browse facility of HyperDoc to find out. Browse@Browse At the main Browse menu, enter the string function and then click on Operations. The exposed operations called function all take an object whose type belongs to category ConvertibleTo InputForm. What domains are those? Go back to the main Browse menu, erase function, enter ConvertibleTo in the input area, and click on categories on the Constructors line. At the bottom of the page, enter InputForm in the input area following S =. Click on Cross Reference and then on Domains. The list you see contains over forty domains that belong to the category ConvertibleTo InputForm. Thus you can use function for Integer, Float, String, Complex, Expression, and so on.