next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc > The Macaulay2 language > using functions

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.
i1 : ?sin

  * Usage: sin x
  * Inputs:
      * x, a real number
  * Outputs:
      * a real number, the sine of x

Ways to use sin

  * sin(CC), see "sin" -- compute the sine
  * sin(QQ), see "sin" -- compute the sine
  * sin(RR), see "sin" -- compute the sine
  * sin(ZZ), see "sin" -- compute the sine
In this case, we 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.
i2 : sin 1.2

o2 = .932039085967226

o2 : RR (of precision 53)
i3 : sin(1.2)

o3 = .932039085967226

o3 : RR (of precision 53)
i4 : sin(1.0+0.2)

o4 = .932039085967226

o4 : 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.
i5 : print(10 + 1)^2
Some functions take more than one argument, and the arguments are separated by a comma, and then parentheses are needed.
i6 : append

o6 = append

o6 : CompiledFunction
i7 : append({a,b,c},d)

o7 = {a, b, c, d}

o7 : List
Some functions take a variable number of arguments.
i8 : join

o8 = join

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

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

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

o11 = {a, b, c, d}

o11 : List