2 * @author Walther Neuper
3 * Created on Sep 25, 2015
4 * (c) copyright due to license terms
9 import isac.gui.mawen.syntax.Ast._ //"._" simplifies "Ast.Ast" to "Ast"
10 import edu.tum.cs.isabelle.api.XML
17 //---------------------------- for <code>TestXml</code>
18 // the priorities of the operators are from ~~/src/HOL/Groups.thy, Fields.thy, Power.thy, ...
20 // "1 + (2 * x * (y + 3)) / (4 * z * (y + 3)) + 5" ... Isabelle's + is left-associative:
21 // "(1 + (2 * x * (y + 3)) / (4 * z * (y + 3))) + 5"
22 def term_1(): XML.Tree = {
23 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
24 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
25 XML.Elem(("NUM", Nil), List(XML.Text ("1"))),
26 XML.Elem(("OP", List(("id", "/"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
27 XML.Elem(("OP", List(("id", "*"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
28 XML.Elem(("OP", List(("id", "*"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
29 XML.Elem(("NUM", Nil), List(XML.Text ("2"))),
30 XML.Elem(("VAR", Nil), List(XML.Text ("x")))
32 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
33 XML.Elem(("VAR", Nil), List(XML.Text ("y"))),
34 XML.Elem(("NUM", Nil), List(XML.Text ("3")))
37 XML.Elem(("OP", List(("id", "*"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
38 XML.Elem(("OP", List(("id", "*"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
39 XML.Elem(("NUM", Nil), List(XML.Text ("4"))),
40 XML.Elem(("VAR", Nil), List(XML.Text ("y")))
42 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
43 XML.Elem(("VAR", Nil), List(XML.Text ("y"))),
44 XML.Elem(("NUM", Nil), List(XML.Text ("3")))
49 XML.Elem(("NUM", Nil), List(XML.Text ("5")))
52 // the above term cancelled
53 // "1 + (2 * x) / (4 * z) + 5" ... Isabelle's + is left-associative, thus () omitted:
54 // "(1 + (2 * x) / (4 * z)) + 5"
55 def term_2(): XML.Tree = {
56 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
57 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
58 XML.Elem(("NUM", Nil), List(XML.Text ("1"))),
59 XML.Elem(("OP", List(("id", "/"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
60 XML.Elem(("OP", List(("id", "*"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
61 XML.Elem(("NUM", Nil), List(XML.Text ("2"))),
62 XML.Elem(("VAR", Nil), List(XML.Text ("x")))
64 XML.Elem(("OP", List(("id", "*"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
65 XML.Elem(("NUM", Nil), List(XML.Text ("4"))),
66 XML.Elem(("VAR", Nil), List(XML.Text ("y")))
70 XML.Elem(("NUM", Nil), List(XML.Text ("5")))
74 //---------------------------- for <code>TestWorksheetForMawen</code>
75 // "Diff (x + sin (x ^ 2), x)"
76 def term_Nil_Frm(): XML.Tree = {
77 XML.Elem(("CASCMD", List(("id", "Diff"), ("args", "2"))), List(
78 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
79 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
80 XML.Elem(("OP", List(("id", "sin"), ("args", "1"), ("prior", "99"), ("fix", "pre"))), List(
81 XML.Elem(("OP", List(("id", "^"), ("args", "2"), ("prior", "80"), ("fix", "in"))), List(
82 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
83 XML.Elem(("NUM", Nil), List(XML.Text ("2"))))))))),
84 XML.Elem(("VAR", Nil), List(XML.Text ("x")))))
87 // "d_d x (x + sin (x ^ 2))" as it comes from Isabelle (as SMLString)
88 def term_1_Frm_from_ISA(): XML.Tree = { // vvvvvvvvvvv--- enforces (term)
89 XML.Elem(("OP", List(("id", "d_d"), ("args", "2"), ("prior", "99"), ("fix", "pre"))), List(
90 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
91 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
92 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
93 XML.Elem(("OP", List(("id", "sin"), ("args", "1"), ("prior", "99"), ("fix", "pre"))), List(
94 XML.Elem(("OP", List(("id", "^"), ("args", "2"), ("prior", "80"), ("fix", "in"))), List(
95 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
96 XML.Elem(("NUM", Nil), List(XML.Text ("2")))))))))))
98 // "d_d x (x + sin (x ^ 2))" as presented to the gui ??????????????????????????????????????????????????
99 // version a: involves not-clarified mixfix notation
100 def term_1_Frm(): XML.Tree = {
101 // ambiguous..: no division -------v vvv vvv--- like "=" in HOL.thy ?????????
102 XML.Elem(("OP", List(("id", "/"), ("args", "3"), ("prior", "50"), ("fix", "mixfix"))), List(
103 XML.Elem(("CONST", Nil), List(XML.Text ("d"))), // CONST or OP or VAR ??????????????????????
104 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
105 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
106 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
107 XML.Elem(("OP", List(("id", "sin"), ("args", "1"), ("prior", "99"), ("fix", "pre"))), List(
108 XML.Elem(("OP", List(("id", "^"), ("args", "2"), ("prior", "80"), ("fix", "in"))), List(
109 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
110 XML.Elem(("NUM", Nil), List(XML.Text ("2")))))))))))
111 } // if ("args", "2") then we have no root for "/ d x" and "(x + sin (x ^ 2))" ????????????????????????
112 // but we could treat this as fraction --------^^^^^^^ and ^^^^^^^^^^^^^^^^^^^ is dangling without root
114 // "d_d x (x + sin (x ^ 2))" as presented to the gui ??????????????????????????????????????????????????
115 // version b: allows to represent "d_d x" as a normal fraction, but introduces additional TERM
116 def term_1_Frmb(): XML.Tree = {
117 XML.Elem(("TERM", List(("args", "2"))), List(
118 XML.Elem(("OP", List(("id", "/"), ("args", "2"), ("prior", "70"), ("fix", "in"))), List(
119 XML.Elem(("CONST", Nil), List(XML.Text ("d"))), // CONST or OP or VAR ????????????????????
120 XML.Elem(("TERM", List(("args", "2"))), List( // "d x" in the denominator have no root otherwise !!!!!!!!
121 XML.Elem(("CONST", Nil), List(XML.Text ("d"))),
122 XML.Elem(("VAR", Nil), List(XML.Text ("x"))))))),
123 XML.Elem(("OP", List(("id", "+"), ("args", "2"), ("prior", "65"), ("fix", "in"))), List(
124 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
125 XML.Elem(("OP", List(("id", "sin"), ("args", "1"), ("prior", "99"), ("fix", "pre"))), List(
126 XML.Elem(("OP", List(("id", "^"), ("args", "2"), ("prior", "80"), ("fix", "in"))), List(
127 XML.Elem(("VAR", Nil), List(XML.Text ("x"))),
128 XML.Elem(("NUM", Nil), List(XML.Text ("2")))))))))))
130 // CONCLUSION: either d_d as mixfix (with fraction?), or introduce TERM as root, or ???????????????????
132 // TestData from TestUseCases.testUC_userguide()
135 Constant("Groups.plus_class.plus"),
137 Constant("Diff.d_d"),
141 Constant("Diff.d_d"),
143 Appl(List( //added to above
144 Constant("BOX.1"), //added to above
146 Constant("Transcendental.sin"),
147 Appl(List( //added to above
148 Constant("BOX.2"), //added to above
150 Constant("Power.power_class.power"),
152 Variable("2")))))))))))))
158 Constant("Diff.d_d"),
160 Appl(List( //added to above
161 Constant("BOX.1"), //added to above
163 Constant("Transcendental.sin"),
164 Appl(List( //added to above
165 Constant("BOX.2"), //added to above
166 Variable("u"))))))))),
168 Constant("Groups.times_class.times"),
169 Appl(List( //added to above
170 Constant("BOX.3"), //added to above
172 Constant("Transcendental.cos"),
175 Constant("Diff.d_d"),
177 Appl(List( //added to above
178 Constant("BOX.4"), //added to above
179 Variable("u")))))))))
183 Constant("Groups.plus_class.plus"),
185 Constant("Diff.d_d"),
189 Constant("Groups.times_class.times"),
190 Appl(List( //added to above
191 Constant("BOX.3"), //added to above
193 Constant("Transcendental.cos"),
195 Constant("Power.power_class.power"),
199 Constant("Diff.d_d"),
201 Appl(List( //added to above
202 Constant("BOX.4"), //added to above
203 Variable("GAP")))))))))