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

using functions with optional inputs

Some functions accept optional inputs in addition to their required inputs. In the documentation, such an optional input is indicated by writing NAME => ..., where NAME is the name of the optional input, and the dots indicate the place where the user will provide the value of the optional input.

Optional inputs can be provided between parentheses along with the other inputs (or arguments) of the function. For example, if the function is normally used with two required inputs, then instead of typing f(x,y), you may type f(x,y,FOO => t, BAR => u), where t is the value to be provided to f as the value of the optional input named FOO and u is the value to be provided to f as the value of the optional input named BAR.

The optional inputs can be inserted in any order, and may even occur before the required inputs. If more than one optional input with the same option name are given, then the value accompanying the right-most one is the value provided to the function.

Use options to discover the optional arguments accepted by a function.

i1 : R = ZZ/101[x,y,z,w];
i2 : gb ideal(x*y-z^2,y^2-w^2)

o2 = GroebnerBasis[status: done; S-pairs encountered up to degree 4]

o2 : GroebnerBasis
i3 : gens oo

o3 = | y2-w2 xy-z2 yz2-xw2 z4-x2w2 |

             1       4
o3 : Matrix R  <--- R
One of the optional arguments for gb is named DegreeLimit; we may use options to discover that, as follows.
i4 : options gb

o4 = OptionTable{Algorithm => Inhomogeneous        }
                 BasisElementLimit => infinity
                 ChangeMatrix => false
                 CodimensionLimit => infinity
                 DegreeLimit => {}
                 GBDegrees => null
                 HardDegreeLimit => null
                 Hilbert => null
                 MaxReductionCount => 10
                 PairLimit => infinity
                 StopBeforeComputation => false
                 StopWithMinimalGenerators => false
                 Strategy => {}
                 SubringLimit => infinity
                 Syzygies => false
                 SyzygyLimit => infinity
                 SyzygyRows => infinity

o4 : OptionTable
The optional input named DegreeLimit can be used to specify that the computation should stop after a certain degree has been reached.
i5 : gb(ideal(x*y-z^2,y^2-w^2), DegreeLimit => 2)

o5 = GroebnerBasis[status: DegreeLimit; all S-pairs handled up to degree 2]

o5 : GroebnerBasis
i6 : gens oo

o6 = | y2-w2 xy-z2 |

             1       2
o6 : Matrix R  <--- R

Programming hint

The value returned by options is a type of hash table that can be used to obtain default values.

See also making new functions with optional arguments.

i7 : (options gb).Syzygies

o7 = false