next | previous | forward | backward | up | index | toc

# Classic -- a parser for classic Macaulay syntax

## Description

This package provides a parser for polynomials in the classic Macaulay format. Some users prefer it, for ease and speed of typing polynomials, ideals, and matrices.

Only ring variables that are single letters, or single letters indexed by a sequence of numbers can be handled with this parser.

The rules for creating polynomials using the classic parser include:

• Spaces, tabs, and newline characters are completely ignored.
• A variable is either (1) a single letter, (2) a subscripted variable, or (3) a polynomial enclosed in parentheses.
• Subscripted variables, e.g., y_(1,1), are written using brackets, as in y[1,1]. Instead of explicit numbers for subscripted variables, Macaulay2 user variables that have an integer value may be used.
• Coefficients are either integers or rational numbers, starting with a + or - (which may be omitted for the first monomial). Over finite fields, the division is performed in that field.
• A monomial is written without symbols for multiplication or exponentiation, where the (optional) coefficient comes first.
• A polynomial is a collection of monomials one after the other.
• Parenthesized subexpressions are allowed.
• Except for indices for subscripted variables, integers must be explicitly given.
• All of the variables used must already belong to a specific ring. If in doubt, first type use R to ensure that all the symbols of R are in use.

The source code for this parser is relatively short, since it is based on the package Parsing. Here it is.

 export "poly" symbolP = (x -> ( if not isGlobalSymbol x then error("symbol ",x," undefined"); getGlobalSymbol x)) % letterParser seqP = (comma, parser) -> prepend % parser @ * (last % comma @ parser) variableP = value % symbolP intP = NNParser | variableP subscriptP = ((lb,x,rb) -> x) % andP( "[", unsequence % seqP_"," intP, "]" ) ringVariableP = ((x,n) -> value if n === nil then x else x_n) % symbolP @ optP subscriptP numberP = ZZParser | QQParser powerP = ((x,n) -> if n === nil then x else x^n) % (futureParser parenExprP | ringVariableP) @ optP NNParser monomialP = times @@ deepSplice % optionalSignParser @ (numberP @ *powerP | +powerP ) polyP = plus @@ deepSplice % +monomialP | terminalParser 0 parenExprP = ((l,x,r) -> x) % andP("(", futureParser parenExprP | polyP, ")") listPolyP = toList % seqP_"," polyP arrayPolyP = toList % seqP_";" listPolyP poly = method() polyParser = polyP : nonspaceAnalyzer poly String := RingElement => x -> polyParser x idealParser = ideal % listPolyP : nonspaceAnalyzer ideal String := Ideal => x -> idealParser x monomialIdealParser = monomialIdeal % listPolyP : nonspaceAnalyzer monomialIdeal String := MonomialIdeal => x -> monomialIdealParser x matrix String := Matrix => opts -> matrix_opts % arrayPolyP : nonspaceAnalyzer

## Version

This documentation describes version 1.0 of Classic.

## Source code

The source code from which this documentation is derived is in the file Classic.m2.

## Exports

• Functions and commands
• poly -- see poly(String) -- make a polynomial using classic Macaulay syntax
• Methods

## For the programmer

The object Classic is .