Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > using functions
next | previous | forward | backward | up | index | toc

using functions

There are many functions in Macaulay2 that do various things. You can get a brief indication of what a function does by typing a ? before its name. In this case, one would see that the function sin takes a single argument x. We apply a function to its argument by typing them in adjacent positions. It is possible but not necessary to place parentheses around the argument.
i1 : sin 1.2

o1 = .932039085967226

o1 : RR (of precision 53)
i2 : sin(1.2)

o2 = .932039085967226

o2 : RR (of precision 53)
i3 : sin(1.0+0.2)

o3 = .932039085967226

o3 : RR (of precision 53)
In parsing the operator ^ takes precedence over adjacency, so the function is applied after the power is computed in the following code. This may not be what you expect.
i4 : print(10 + 1)^2
121
Some functions take more than one argument, and the arguments are separated by a comma, and then parentheses are needed.
i5 : append

o5 = append

o5 : CompiledFunction
i6 : append({a,b,c},d)

o6 = {a, b, c, d}

o6 : List
Some functions take a variable number of arguments.
i7 : join

o7 = join

o7 : CompiledFunction
i8 : join({a,b},{c,d},{e,f},{g,h,i})

o8 = {a, b, c, d, e, f, g, h, i}

o8 : List
Functions, like anything else, can be assigned to variables. You may do this to provide handy private abbreviations.
i9 : ap = append;
i10 : ap({a,b,c},d)

o10 = {a, b, c, d}

o10 : List