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 junit.framework.TestCase
14 import org.junit.Assert._
17 * Use Cases from Marco Mahringer's master thesis.
18 * References labels from mmahringer-master.tex.
20 class TestUseCases extends TestCase {
22 val sys_ = Isabelle_Isac.connect();
24 /* mmahringer-master.tex \label{UC:user-guide} */
25 def testUC_userguide() {
26 println("/--BEGIN isac.gui.mawen.TestUseCases#testUC_userguide");
28 var term_str = "d_d x x + d_d x (sin (x ^ 2))"
29 var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
30 var form = DataTypes.xml_to_Formula_NEW(tree)
31 var ast = form.getTerm
32 //println(Ast.raw_string_of(ast))
35 Constant("Groups.plus_class.plus"),
44 Constant("Transcendental.sin"),
46 Constant("Power.power_class.power"),
48 Variable("2"))))))))))
49 //println(Ast.math_string_of(ast))
50 assertEquals(math_string_of(ast), term_str)
52 term_str = "d_d bdv (sin (u)) = cos (u) * d_d bdv u"
53 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
54 form = DataTypes.xml_to_Formula_NEW(tree)
56 //println(Ast.raw_string_of(ast))
64 Constant("Transcendental.sin"),
67 Constant("Groups.times_class.times"),
69 Constant("Transcendental.cos"),
75 //println(Ast.math_string_of(ast))
76 assertEquals(math_string_of(ast), term_str)
78 term_str = "d_d x x + cos (x ^ 2) * d_d x GAP"
79 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
80 form = DataTypes.xml_to_Formula_NEW(tree)
82 //println(Ast.raw_string_of(ast))
85 Constant("Groups.plus_class.plus"),
91 Constant("Groups.times_class.times"),
93 Constant("Transcendental.cos"),
95 Constant("Power.power_class.power"),
101 Variable("GAP")))))))) //NOT Constant("#"), because comes from Isabelle_Isac
102 //println(Ast.math_string_of(ast))
103 assertEquals(math_string_of(ast), term_str) //Isabelle requires (sin (x ^ 2)
105 println("\\--END isac.gui.mawen.TestUseCases#testUC_userguide");
108 /* mmahringer-master.tex \label{UC:mult-frac} */
109 def testUC_multfrac() {
110 println("/--BEGIN isac.gui.mawen.TestUseCases#testUC_multfrac");
112 var term_str = "Simplify (1 + 1 / 2 + (2 / (x + 3) + 2 / (x - 3)) / (8 * x / (x ^ 2 - 9)))"
113 var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
114 var form = DataTypes.xml_to_Formula_NEW(tree)
115 var ast = form.getTerm
117 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"))))))))))))
118 assertEquals(term_str, math_string_of(ast))
120 term_str = "1 + 1 / 2 + (2 / (x + 3) + 2 / (x - 3)) / (8 * x / (x ^ 2 - 9))"
121 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
122 form = DataTypes.xml_to_Formula_NEW(tree)
125 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"))))))))))
126 assertEquals(term_str, math_string_of(ast))
128 println("\\--END isac.gui.mawen.TestUseCases#testUC_multfrac");
131 //\label{UC:gaps} --------------------------------------------------------------------
133 TODO in cooperation with mmahringer
136 /* mmahringer-master.pdf \label{UC:eng-math} */
137 def testUC_engmath() {
138 println("/--BEGIN isac.gui.mawen.TestUseCases#testUC_engmath");
140 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"
141 var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
142 var form = DataTypes.xml_to_Formula_NEW(tree)
143 var ast = form.getTerm
147 Appl(List(Variable/*NOT Constant*/("y"), Variable("x"))),
149 Constant("Integrate.Integral"),
151 Constant("Groups.plus_class.plus"),
154 Constant("Groups.times_class.times"),
156 Constant("Fields.inverse_class.divide"),
159 Constant("Groups.times_class.times"),
161 Constant("Biegelinie.EI"))))),
163 Constant("Groups.plus_class.plus"),
165 Constant("Groups.plus_class.plus"),
167 Constant("Groups.times_class.times"), Variable("c_2"), Variable("x"))),
169 Constant("Groups.times_class.times"),
171 Constant("Fields.inverse_class.divide"), Variable("c"), Variable("2"))),
173 Constant("Power.power_class.power"), Variable("x"), Variable("2"))))))),
175 Constant("Groups.times_class.times"),
177 Constant("Fields.inverse_class.divide"),
179 Constant("Groups.times_class.times"), Variable("-1"), Variable("q_0"))),
181 Appl(List(Constant("Power.power_class.power"), Variable("x"), Variable("3"))))))))))),
184 // assertEquals(term_str, math_string_of(ast)) ------ TODO math_string_of UNCOVERED CASE
187 //NOTE: -----------vv (reason unclear):
188 //term_str = "Problem (Biegelinie, [setzeRandbedingungen, Biegelinien])" //NOT ok
189 term_str = "Probl (Biegelinie, [setzeRandbedingungen, Biegelinien])" //OK
190 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
191 form = DataTypes.xml_to_Formula_NEW(tree)
193 //TODO fun + pair + list
195 // Appl(List(Variable("Probl"), Appl(List(Constant("Product_Type.Pair"), Constant("Biegelinie.Biegelinie"), Appl(List(Constant("List.list.Cons"), Variable("setzeRandbedingungen"), Appl(List(Constant("List.list.Cons"), Variable("Biegelinien"), Constant("List.list.Nil")))))))))
197 // assertEquals(term_str, math_string_of(ast)) ------ math_string_of UNCOVERED CASE
199 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]"
200 tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
201 form = DataTypes.xml_to_Formula_NEW(tree)
205 // Appl(List(Constant("List.list.Cons"), Appl(List(Constant("HOL.eq"), Appl(List(Constant("Groups.times_class.times"), Variable("L"), Variable("q_0"))), Variable("c"))), Appl(List(Constant("List.list.Cons"), 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("List.list.Cons"), Appl(List(Constant("HOL.eq"), Variable("0"), Variable("c_4"))), Appl(List(Constant("List.list.Cons"), Appl(List(Constant("HOL.eq"), Variable("0"), Variable("c_3"))), Constant("List.list.Nil")))))))))
207 // println(math_string_of(ast)) //TODO scala.MatchError:Appl...
209 println("\\--END isac.gui.mawen.TestUseCases#testUC_engmath");
212 /* mmahringer-master.pdf \label{UC:if-then-else} */
213 def testUC_ifthenelse() {
214 println("/--BEGIN isac.gui.mawen.TestUseCases#testUC_ifthenelse");
216 //if 0 < n then fac n = n * fac (n - 1) else 1
217 //NOTE: Isabelle error messages indicates problems with termination
218 // Coercion inference failed:
221 // Cannot fulfil subtype constraints:
222 // bool <: ??'a from function Application If (0 < n) (fac n = n * fac (n - 1))
223 // ??'a <: ??'b from function Ast.Application
224 // if 0 < n then fac n = n * fac (n - 1) else 1
227 "Program Simplify t_t =" +
229 " Try (Rewrite_Set klammern_aufloesen False) @@" +
230 " Try (Rewrite_Set ordne_alphabetisch False) @@" +
231 " Try (Rewrite_Set fasse_zusammen False) @@" +
232 " Try (Rewrite_Set verschoenere False)) t_t"
233 //NOTE: pretty blocks have not yet been considered
234 var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
235 var form = DataTypes.xml_to_Formula_NEW(tree)
236 var ast = form.getTerm
238 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")))))
240 // assertEquals(term_str, math_string_of(ast)) ------ TODO math_string_of UNCOVERED CASE
242 println("\\--END isac.gui.mawen.TestUseCases#testUC_ifthenelse");