2 * @author Walther Neuper
3 * Created on May 18, 2017
4 * (c) due to copyright terms
9 import isac.bridge.Isabelle_Isac
10 import isac.bridge.xml.DataTypes
11 import isac.gui.mawen.syntax.Ast._ //"._" simplifies "Ast.Ast" to "Ast"
13 import edu.tum.cs.isabelle.japi._
15 import junit.framework.TestCase
16 import org.junit.Assert._
19 * Use Cases from Marco Mahringer's master thesis.
20 * We assert <code>Ast.math_string_of</code>, because <code>Formula.math_text_</code>'s String
21 * is used for transfer of formulas for front-end --> Isabelle_Isac.
22 * References use labels in mmahringer-master.tex.
24 class TestUseCases extends TestCase {
26 var sys_ : JSystem = null
27 override def setUp() {
28 sys_ = Isabelle_Isac.connect();
31 /* mmahringer-master.tex \label{UC:user-guide} */
32 def testUC_userguide() {
33 println("/--BEGIN isac.gui.mawen.TestUseCases#testUC_userguide");
35 var term_str = "d_d x x + d_d x (sin (x ^ 2))"
36 var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
37 var form = DataTypes.xml_to_Formula_NEW(tree)
38 var ast = form.getTerm
39 //println(Ast.raw_string_of(ast))
42 Constant("Groups.plus_class.plus"),
51 Constant("Transcendental.sin"),
53 Constant("Power.power_class.power"),
55 Variable("2"))))))))))
56 //println(Ast.math_string_of(ast))
57 assertEquals(math_string_of(ast), term_str)
58 val ast_05 = // copied to TestData.scala
60 Constant("Groups.plus_class.plus"),
68 Appl(List( //added to above
69 Constant("BOX.1"), //added to above
71 Constant("Transcendental.sin"),
72 Appl(List( //added to above
73 Constant("BOX.2"), //added to above
75 Constant("Power.power_class.power"),
77 Variable("2")))))))))))))
79 term_str = "d_d bdv (sin (u)) = cos (u) * d_d bdv u"
80 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
81 form = DataTypes.xml_to_Formula_NEW(tree)
83 //println(Ast.raw_string_of(ast))
91 Constant("Transcendental.sin"),
94 Constant("Groups.times_class.times"),
96 Constant("Transcendental.cos"),
102 //println(Ast.math_string_of(ast))
103 assertEquals(math_string_of(ast), term_str)
104 val ast_06 = // copied to TestData.scala
108 Constant("Diff.d_d"),
110 Appl(List( //added to above
111 Constant("BOX.1"), //added to above
113 Constant("Transcendental.sin"),
114 Appl(List( //added to above
115 Constant("BOX.2"), //added to above
116 Variable("u"))))))))),
118 Constant("Groups.times_class.times"),
119 Appl(List( //added to above
120 Constant("BOX.3"), //added to above
122 Constant("Transcendental.cos"),
125 Constant("Diff.d_d"),
127 Appl(List( //added to above
128 Constant("BOX.4"), //added to above
129 Variable("u")))))))))
131 term_str = "d_d x x + cos (x ^ 2) * d_d x GAP"
132 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
133 form = DataTypes.xml_to_Formula_NEW(tree)
135 //println(Ast.raw_string_of(ast))
138 Constant("Groups.plus_class.plus"),
140 Constant("Diff.d_d"),
144 Constant("Groups.times_class.times"),
146 Constant("Transcendental.cos"),
148 Constant("Power.power_class.power"),
152 Constant("Diff.d_d"),
154 Variable("GAP")))))))) //NOT Constant("#"), because comes from Isabelle_Isac
155 //println(Ast.math_string_of(ast))
156 assertEquals(math_string_of(ast), term_str) //Isabelle requires (sin (x ^ 2)
157 val ast_07 = // copied to TestData.scala
159 Constant("Groups.plus_class.plus"),
161 Constant("Diff.d_d"),
165 Constant("Groups.times_class.times"),
166 Appl(List( //added to above
167 Constant("BOX.3"), //added to above
169 Constant("Transcendental.cos"),
171 Constant("Power.power_class.power"),
175 Constant("Diff.d_d"),
177 Appl(List( //added to above
178 Constant("BOX.4"), //added to above
179 Variable("GAP")))))))))
181 println("\\--END isac.gui.mawen.TestUseCases#testUC_userguide");
184 /* mmahringer-master.tex \label{UC:mult-frac} */
185 def testUC_multfrac() {
186 println("/--BEGIN isac.gui.mawen.TestUseCases#testUC_multfrac");
188 var term_str = "Simplify (1 + 1 / 2 + (2 / (x + 3) + 2 / (x - 3)) / (8 * x / (x ^ 2 - 9)))"
189 var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
190 var form = DataTypes.xml_to_Formula_NEW(tree)
191 var ast = form.getTerm
193 Appl(List(Constant("Simplify.Simplify"), Appl(List(Constant("Groups.plus_class.plus"), Appl(List(Constant("Groups.plus_class.plus"), Variable("1"), Appl(List(Constant("Fields.inverse_class.divide"), Variable("1"), Variable("2"))))), Appl(List(Constant("Fields.inverse_class.divide"), Appl(List(Constant("Groups.plus_class.plus"), Appl(List(Constant("Fields.inverse_class.divide"), Variable("2"), Appl(List(Constant("Groups.plus_class.plus"), Variable("x"), Variable("3"))))), Appl(List(Constant("Fields.inverse_class.divide"), Variable("2"), Appl(List(Constant("Groups.minus_class.minus"), Variable("x"), Variable("3"))))))), Appl(List(Constant("Fields.inverse_class.divide"), Appl(List(Constant("Groups.times_class.times"), Variable("8"), Variable("x"))), Appl(List(Constant("Groups.minus_class.minus"), Appl(List(Constant("Power.power_class.power"), Variable("x"), Variable("2"))), Variable("9"))))))))))))
194 assertEquals(term_str, math_string_of(ast))
196 term_str = "1 + 1 / 2 + (2 / (x + 3) + 2 / (x - 3)) / (8 * x / (x ^ 2 - 9))"
197 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
198 form = DataTypes.xml_to_Formula_NEW(tree)
201 Appl(List(Constant("Groups.plus_class.plus"), Appl(List(Constant("Groups.plus_class.plus"), Variable("1"), Appl(List(Constant("Fields.inverse_class.divide"), Variable("1"), Variable("2"))))), Appl(List(Constant("Fields.inverse_class.divide"), Appl(List(Constant("Groups.plus_class.plus"), Appl(List(Constant("Fields.inverse_class.divide"), Variable("2"), Appl(List(Constant("Groups.plus_class.plus"), Variable("x"), Variable("3"))))), Appl(List(Constant("Fields.inverse_class.divide"), Variable("2"), Appl(List(Constant("Groups.minus_class.minus"), Variable("x"), Variable("3"))))))), Appl(List(Constant("Fields.inverse_class.divide"), Appl(List(Constant("Groups.times_class.times"), Variable("8"), Variable("x"))), Appl(List(Constant("Groups.minus_class.minus"), Appl(List(Constant("Power.power_class.power"), Variable("x"), Variable("2"))), Variable("9"))))))))))
202 assertEquals(term_str, math_string_of(ast))
204 println("\\--END isac.gui.mawen.TestUseCases#testUC_multfrac");
207 //\label{UC:gaps} --------------------------------------------------------------------
209 TODO in cooperation with mmahringer
212 /* mmahringer-master.pdf \label{UC:eng-math} */
213 def testUC_engmath() {
214 println("/--BEGIN isac.gui.mawen.TestUseCases#testUC_engmath");
216 // the integral's "D x" is only input, NOT output -------------vvv
217 //assertEquals("y (x) = Integral (c_3 + 1 / (-1 * EI ) * (c_2 * x + c / 2 * x ^ 2 + -1 * q_0 / 6 * x ^ 3)) x"
218 var term_str = "y (x) = Integral (c_3 + 1 / (-1 * EI ) * (c_2 * x + c / 2 * x ^ 2 + -1 * q_0 / 6 * x ^ 3)) D x"
219 var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
220 var form = DataTypes.xml_to_Formula_NEW(tree)
221 var ast = form.getTerm
225 Appl(List(Variable/*NOT Constant*/("y"), Variable("x"))),
227 Constant("Integrate.Integral"),
229 Constant("Groups.plus_class.plus"),
232 Constant("Groups.times_class.times"),
234 Constant("Fields.inverse_class.divide"),
237 Constant("Groups.times_class.times"),
239 Constant("Biegelinie.EI"))))),
241 Constant("Groups.plus_class.plus"),
243 Constant("Groups.plus_class.plus"),
245 Constant("Groups.times_class.times"), Variable("c_2"), Variable("x"))),
247 Constant("Groups.times_class.times"),
249 Constant("Fields.inverse_class.divide"), Variable("c"), Variable("2"))),
251 Constant("Power.power_class.power"), Variable("x"), Variable("2"))))))),
253 Constant("Groups.times_class.times"),
255 Constant("Fields.inverse_class.divide"),
257 Constant("Groups.times_class.times"), Variable("-1"), Variable("q_0"))),
259 Appl(List(Constant("Power.power_class.power"), Variable("x"), Variable("3"))))))))))),
262 assertEquals("y (x) = Integral (c_3 + 1 / (-1 * EI ) * (c_2 * x + c / 2 * x ^ 2 + -1 * q_0 / 6 * x ^ 3)) x",
266 //NOTE: -----------vv (reason unclear):
267 //term_str = "Problem (Biegelinie, [setzeRandbedingungen, Biegelinien])" //NOT ok
268 term_str = "Probl (Biegelinie , [setzeRandbedingungen, Biegelinien])" //OK
269 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
270 form = DataTypes.xml_to_Formula_NEW(tree)
272 //println(math_string_of(ast))
273 assertEquals(term_str, math_string_of(ast))
275 term_str = "[L * q_0 = c, 0 = (2 * c_2 + 2 * L * c + -1 * L ^ 2 * q_0) / 2, 0 = c_4, 0 = c_3]"
276 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
277 form = DataTypes.xml_to_Formula_NEW(tree)
279 //println(raw_string_of(ast))
281 Appl(List(Constant("_list"), Appl(List(Constant("_args"), Appl(List(Constant("HOL.eq"), Appl(List(Constant("Groups.times_class.times"), Variable("L"), Variable("q_0"))), Variable("c"))), Appl(List(Constant("_args"), Appl(List(Constant("HOL.eq"), Variable("0"), Appl(List(Constant("Fields.inverse_class.divide"), Appl(List(Constant("Groups.plus_class.plus"), Appl(List(Constant("Groups.plus_class.plus"), Appl(List(Constant("Groups.times_class.times"), Variable("2"), Variable("c_2"))), Appl(List(Constant("Groups.times_class.times"), Appl(List(Constant("Groups.times_class.times"), Variable("2"), Variable("L"))), Variable("c"))))), Appl(List(Constant("Groups.times_class.times"), Appl(List(Constant("Groups.times_class.times"), Variable("-1"), Appl(List(Constant("Power.power_class.power"), Variable("L"), Variable("2"))))), Variable("q_0"))))), Variable("2"))))), Appl(List(Constant("_args"), Appl(List(Constant("HOL.eq"), Variable("0"), Variable("c_4"))), Appl(List(Constant("HOL.eq"), Variable("0"), Variable("c_3")))))))))))
283 assertEquals(term_str, math_string_of(ast))
285 println("\\--END isac.gui.mawen.TestUseCases#testUC_engmath");
288 /* mmahringer-master.pdf \label{UC:if-then-else} */
289 def testUC_ifthenelse() {
290 println("/--BEGIN isac.gui.mawen.TestUseCases#testUC_ifthenelse");
292 //if 0 < n then fac n = n * fac (n - 1) else 1
293 //NOTE: Isabelle error messages indicates problems with termination
294 // Coercion inference failed:
297 // Cannot fulfil subtype constraints:
298 // bool <: ??'a from function Application If (0 < n) (fac n = n * fac (n - 1))
299 // ??'a <: ??'b from function Ast.Application
300 // if 0 < n then fac n = n * fac (n - 1) else 1
303 "Program Simplify t_t =" +
305 " Try (Rewrite_Set klammern_aufloesen False) @@" +
306 " Try (Rewrite_Set ordne_alphabetisch False) @@" +
307 " Try (Rewrite_Set fasse_zusammen False) @@" +
308 " Try (Rewrite_Set verschoenere False)) t_t"
309 //NOTE: pretty blocks have not yet been considered
310 var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
311 var form = DataTypes.xml_to_Formula_NEW(tree)
312 var ast = form.getTerm
314 Appl(List(Constant("HOL.eq"), Appl(List(Variable("Program"), Constant("Simplify.Simplify"), Variable("t_t"))), Appl(List(Constant("Script.Repeat"), Appl(List(Constant("Script.Seq"), Appl(List(Constant("Script.Try"), Appl(List(Constant("Script.Rewrite'_Set"), Variable("klammern_aufloesen"), Constant("HOL.False"))))), Appl(List(Constant("Script.Seq"), Appl(List(Constant("Script.Try"), Appl(List(Constant("Script.Rewrite'_Set"), Variable("ordne_alphabetisch"), Constant("HOL.False"))))), Appl(List(Constant("Script.Seq"), Appl(List(Constant("Script.Try"), Appl(List(Constant("Script.Rewrite'_Set"), Variable("fasse_zusammen"), Constant("HOL.False"))))), Appl(List(Constant("Script.Try"), Appl(List(Constant("Script.Rewrite'_Set"), Variable("verschoenere"), Constant("HOL.False"))))))))))), Variable("t_t")))))
316 assertEquals(math_string_of(ast), "Program Simplify t_t = Repeat (Seq (Try (Rewrite'_Set klammern_aufloesen False )) (Seq (Try (Rewrite'_Set ordne_alphabetisch False )) (Seq (Try (Rewrite'_Set fasse_zusammen False )) (Try (Rewrite'_Set verschoenere False ))))) t_t")
318 println("\\--END isac.gui.mawen.TestUseCases#testUC_ifthenelse");
321 override def tearDown() {