math-stratum / nodes /reader_b /grammar.gf
tailot's picture
publish math-stratum bundle
e9dac18 verified
Raw History Blame Contribute Delete
4.62 kB
-- Node reader_b (reader_b): Second reader: an independent reading of the same question, its own search over the same lexicon and the same templates.
-- MathLang: the controlled mathematical language this stratum writes, which is the input language of the math topology.
-- Reference implementation: the readers lgstratum/read_a.py and lgstratum/read_b.py, the printer lgstratum/canonical.py, the words lexicon/{lang}.json.
-- NOTE: this specification has not been compiled with the GF toolchain in the authoring environment.
-- In the abstractSyntaxTree string literals and variables are written bare (3, x) instead of (Lit 3), (V x),
-- an absent optional 'wrt' variable is omitted from the tree, matrix literals are written (Mat (Row 1 2) (Row 3 4)),
-- a column vector (Vec 5 6), and the optimization direction as the lower case word max or min.
abstract MathLang = {
cat
Problem ; Formula ; Term ; Var ; Dom ; Dir ; Mat ; Vec ; Names ;
fun
Evaluate : Term -> Problem ;
Prove, ProveZ : Formula -> Problem ;
Solve, SolveZ : Formula -> Var -> Problem ;
SolveSys : Formula -> Names -> Problem ;
Derivative, Antiderivative : Term -> Problem ;
DerivativeWrt, AntiderivativeWrt : Term -> Var -> Problem ;
Integral : Term -> Term -> Term -> Problem ;
IntegralWrt : Term -> Var -> Term -> Term -> Problem ;
Optimize : Dir -> Term -> Formula -> Problem ;
Max, Min : Dir ;
Det, Rank, Inverse, Nullspace : Mat -> Problem ;
Linsolve : Mat -> Vec -> Problem ;
Product : Mat -> Mat -> Problem ;
Power : Mat -> Term -> Problem ;
Maxflow : Mat -> Term -> Term -> Problem ;
Reduce : Mat -> Problem ;
Sos : Mat -> Problem ;
Dot : Vec -> Vec -> Term ;
Matvec : Mat -> Vec -> Vec ;
Eq, Ne, Lt, Le, Gt, Ge, Dvd : Term -> Term -> Formula ;
And, Or, Imp, Iff : Formula -> Formula -> Formula ;
Not : Formula -> Formula ;
Forall, Exists : Var -> Dom -> Formula -> Formula ;
True, False : Formula ;
Add, Sub, Mul, Div, Pow, Mod, Idiv : Term -> Term -> Term ;
Neg : Term -> Term ;
Lit : String -> Term ;
V : Var -> Term ;
MkVar : String -> Var ;
R, Z : Dom ;
}
concrete MathLangEng of MathLang = {
lincat
Problem, Formula, Term, Var, Dom, Dir, Mat, Vec, Names = Str ;
lin
Evaluate t = "evaluate" ++ t ;
Prove f = "prove" ++ f ;
ProveZ f = "prove" ++ f ++ "over" ++ "Z" ;
Solve f v = "solve" ++ f ++ "for" ++ v ;
SolveZ f v = "solve" ++ f ++ "for" ++ v ++ "over" ++ "Z" ;
SolveSys f ns = "solve" ++ f ++ "for" ++ ns ;
Derivative t = "derivative" ++ t ;
DerivativeWrt t v = "derivative" ++ t ++ "wrt" ++ v ;
Antiderivative t = "antiderivative" ++ t ;
AntiderivativeWrt t v = "antiderivative" ++ t ++ "wrt" ++ v ;
Integral t a b = "integral" ++ t ++ "from" ++ a ++ "to" ++ b ;
IntegralWrt t v a b = "integral" ++ t ++ "from" ++ a ++ "to" ++ b ++ "wrt" ++ v ;
Optimize d t f = d ++ t ++ "subject" ++ "to" ++ f ;
Max = "maximize" ;
Min = "minimize" ;
Det m = "det" ++ m ;
Rank m = "rank" ++ m ;
Inverse m = "inverse" ++ m ;
Nullspace m = "nullspace" ++ m ;
Linsolve m v = "linsolve" ++ m ++ v ;
Product a b = "product" ++ a ++ b ;
Power m t = "power" ++ m ++ t ;
Maxflow m a b = "maxflow" ++ m ++ "from" ++ a ++ "to" ++ b ;
Reduce m = "reduce" ++ m ;
Sos m = "sos" ++ m ;
Dot a b = "dot(" ++ a ++ ", " ++ b ++ ")" ;
Matvec m v = "matvec(" ++ m ++ ", " ++ v ++ ")" ;
Eq a b = "(" ++ a ++ "=" ++ b ++ ")" ;
Ne a b = "(" ++ a ++ "!=" ++ b ++ ")" ;
Lt a b = "(" ++ a ++ "<" ++ b ++ ")" ;
Le a b = "(" ++ a ++ "<=" ++ b ++ ")" ;
Gt a b = "(" ++ a ++ ">" ++ b ++ ")" ;
Ge a b = "(" ++ a ++ ">=" ++ b ++ ")" ;
Dvd a b = "(" ++ a ++ "|" ++ b ++ ")" ;
And a b = "(" ++ a ++ "and" ++ b ++ ")" ;
Or a b = "(" ++ a ++ "or" ++ b ++ ")" ;
Imp a b = "(" ++ a ++ "=>" ++ b ++ ")" ;
Iff a b = "(" ++ a ++ "<=>" ++ b ++ ")" ;
Not a = "not" ++ a ;
Forall v d f = "(" ++ "forall" ++ v ++ "in" ++ d ++ "." ++ f ++ ")" ;
Exists v d f = "(" ++ "exists" ++ v ++ "in" ++ d ++ "." ++ f ++ ")" ;
True = "true" ;
False = "false" ;
Add a b = "(" ++ a ++ "+" ++ b ++ ")" ;
Sub a b = "(" ++ a ++ "-" ++ b ++ ")" ;
Mul a b = "(" ++ a ++ "*" ++ b ++ ")" ;
Div a b = "(" ++ a ++ "/" ++ b ++ ")" ;
Pow a b = "(" ++ a ++ "^" ++ b ++ ")" ;
Mod a b = "(" ++ a ++ "mod" ++ b ++ ")" ;
Idiv a b = "(" ++ a ++ "div" ++ b ++ ")" ;
Neg a = "(" ++ "-" ++ a ++ ")" ;
Lit s = s.s ;
V v = v ;
MkVar s = s.s ;
R = "R" ;
Z = "Z" ;
}