tailot's picture
physics-stratum: the conversational layer over the physics topology
3a0a69b verified
Raw History Blame Contribute Delete
2.58 kB
-- Node reader_a (reader_a): First reader: turns a question written in one of the six user languages into a sentence of PhysLang, without seeing the other reader.
-- PhysLang: the controlled physical language this stratum writes, which is the input language of the physics topology.
-- Reference implementation: the readers lgphysstratum/read_a.py and lgphysstratum/read_b.py, the printer lgphysstratum/canonical.py, the words lexicon/{lang}.json.
-- The three funs the readers of this stratum produce are Convert, Audit and Pi. Potential belongs to the language of
-- the physics topology and is listed here because it is part of the target language, but no variety of this stratum
-- writes it yet, and a question that would need it stays outside the coverage of every lexicon.
-- NOTE: this specification has not been compiled with the GF toolchain in the authoring environment.
-- In the abstractSyntaxTree numbers and unit names are written bare (3, km) instead of (Lit 3), (Q km); a list of
-- names is written (One period) or (And mass stiffness); and a ratio is written (Slash 1 2).
abstract PhysLang = {
cat
Problem ; Qty ; Num ; Unit ; Eq ; Side ; Names ; Rows ; Ratio ;
fun
Convert : Qty -> Unit -> Problem ;
Audit : Eq -> Problem ;
Pi : Names -> Names -> Problem ;
Potential : Num -> Num -> Rows -> Rows -> Ratio -> Ratio -> Problem ;
MkQty : Num -> Unit -> Qty ;
Add, Sub, Mul, Div, Pow : Side -> Side -> Side ;
Neg : Side -> Side ;
Q : Unit -> Unit ;
Row : Num -> Num -> Num -> Rows ;
Nil : Rows ;
One : Names ;
And : Names -> Names -> Names ;
MkNum : String -> Num ;
Slash : Num -> Num -> Ratio ;
}
concrete PhysLangEng of PhysLang = {
lincat
Problem, Qty, Num, Unit, Eq, Side, Names, Rows, Ratio = Str ;
lin
Convert q u = "convert" ++ q ++ "to" ++ u ;
Audit e = "audit" ++ e ;
Pi t ns = "pi" ++ t ++ "from" ++ ns ;
Potential n k r s z f = "potential" ++ "node" ++ n ++ "circuit" ++ k
++ "resistors" ++ r ++ "sources" ++ s ++ "size" ++ z ++ "frequency" ++ f ;
MkQty n u = n ++ u ;
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 ++ ")" ;
Neg a = "(" ++ "-" ++ a ++ ")" ;
Q u = u ;
Row a b c = "[" ++ a ++ b ++ c ++ "]" ;
Nil = "" ;
One n = n ;
And a b = a ++ "," ++ b ;
MkNum s = s.s ;
Slash n d = n ++ "/" ++ d ;
}