Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 5294

Macaulay2-1.3.1-8.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8" ?>  <!-- for emacs: -*- coding: utf-8 -*- -->
<!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"	 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>using functions</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="_using_spfunctions_spwith_spoptional_spinputs.html">next</a> | <a href="_catch.html">previous</a> | <a href="_using_spfunctions_spwith_spoptional_spinputs.html">forward</a> | <a href="_catch.html">backward</a> | <a href="___The_sp__Macaulay2_splanguage.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div>

    </td>
  </tr>
</table>
<div><a href="index.html" title="">Macaulay2Doc</a> > <a href="___The_sp__Macaulay2_splanguage.html" title="">The Macaulay2 language</a> > <a href="_using_spfunctions.html" title="">using functions</a></div>
<hr/>
<div><h1>using functions</h1>
<div>There are many functions in Macaulay2 that do various things.  You can get a brief indication of what a function does by typing its name.<table class="examples"><tr><td><pre>i1 : sin

o1 = sin

o1 : CompiledFunction</pre>
</td></tr>
</table>
In this case, we see that the function <a href="_sin.html" title="compute the sine">sin</a> takes a single argument <tt>x</tt>.  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.<table class="examples"><tr><td><pre>i2 : sin 1.2

o2 = .932039085967226

o2 : RR (of precision 53)</pre>
</td></tr>
<tr><td><pre>i3 : sin(1.2)

o3 = .932039085967226

o3 : RR (of precision 53)</pre>
</td></tr>
<tr><td><pre>i4 : sin(1.0+0.2)

o4 = .932039085967226

o4 : RR (of precision 53)</pre>
</td></tr>
</table>
In parsing the operator <a href="_^.html" title="a binary operator, usually used for powers">^</a> 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.<table class="examples"><tr><td><pre>i5 : print(10 + 1)^2
121</pre>
</td></tr>
</table>
Some functions take more than one argument, and the arguments are separated by a comma, and then parentheses are needed.<table class="examples"><tr><td><pre>i6 : append

o6 = append

o6 : CompiledFunction</pre>
</td></tr>
<tr><td><pre>i7 : append({a,b,c},d)

o7 = {a, b, c, d}

o7 : List</pre>
</td></tr>
</table>
Some functions take a variable number of arguments.<table class="examples"><tr><td><pre>i8 : join

o8 = join

o8 : CompiledFunction</pre>
</td></tr>
<tr><td><pre>i9 : join({a,b},{c,d},{e,f},{g,h,i})

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

o9 : List</pre>
</td></tr>
</table>
Functions, like anything else, can be assigned to variables.  You may do this to provide handy private abbreviations.<table class="examples"><tr><td><pre>i10 : ap = append;</pre>
</td></tr>
<tr><td><pre>i11 : ap({a,b,c},d)

o11 = {a, b, c, d}

o11 : List</pre>
</td></tr>
</table>
</div>
</div>
</body>
</html>