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:
The source code for this parser is relatively short, since it is based on the package Parsing. Here it is.
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) -> if n === nil then value 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 export poly ; poly = method() poly String := RingElement => polyP : nonspaceAnalyzer ideal String := Ideal => ideal % listPolyP : nonspaceAnalyzer monomialIdeal String := MonomialIdeal => monomialIdeal % listPolyP : nonspaceAnalyzer matrix String := Matrix => opts -> matrix_opts % arrayPolyP : nonspaceAnalyzer |