test/Tools/isac/ProgLang/termC.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 02 Sep 2013 16:16:08 +0200
changeset 52101 c3f399ce32af
parent 52070 77138c64f4f6
child 55279 130688f277ba
permissions -rw-r--r--
Test_Isac works again, almost ..

4 files raise errors:
# Interpret/solve.sml: "solve.sml: interSteps on norm_Rational 2"
# Interpret/inform.sml: "inform.sml: [rational,simplification] 2"
# Knowledge/partial_fractions.sml: "autoCalculate for met_partial_fraction changed: final result"
# Knowledge/eqsystem.sml: "eqsystem.sml: exp 7.70 normalize 4x4 by rewrite changed"

The chunk of changes is due to the fact, that Isac's code still is unstable.
The changes are accumulated since e8f46493af82.
neuper@38025
     1
(* Title: tests on ProgLang/termC.sml
neuper@38025
     2
   Author: Walther Neuper 051006,
neuper@38025
     3
   (c) due to copyright terms
neuper@38025
     4
*)
akargl@42145
     5
neuper@38025
     6
"--------------------------------------------------------";
neuper@38025
     7
"table of contents --------------------------------------";
neuper@38025
     8
"--------------------------------------------------------";
neuper@48886
     9
"----------- numerals in Isabelle2011/12/13 -------------";
neuper@38025
    10
"----------- inst_bdv -----------------------------------";
neuper@38025
    11
"----------- subst_atomic_all ---------------------------";
neuper@38025
    12
"----------- Pattern.match ------------------------------";
neuper@38025
    13
"----------- fun matches --------------------------------";
neuper@38037
    14
"----------- fun parse, fun parse_patt, fun T_a2real ----";
neuper@38025
    15
"----------- uminus_to_string ---------------------------";
neuper@38037
    16
"----------- *** prep_pbt: syntax error in '#Where' of [v";
neuper@38051
    17
"----------- check writeln, tracing for string markup ---";
neuper@42426
    18
"-------- build fun is_bdv_subst ---------------------------------";
neuper@38025
    19
"--------------------------------------------------------";
neuper@38025
    20
"--------------------------------------------------------";
neuper@38025
    21
neuper@48886
    22
"----------- numerals in Isabelle2011/12/13 -------------";
neuper@48886
    23
"----------- numerals in Isabelle2011/12/13 -------------";
neuper@48886
    24
"----------- numerals in Isabelle2011/12/13 -------------";
neuper@48886
    25
"***Isabelle2011 ~= Isabelle2012 = Isabelle2013";
neuper@48886
    26
"***Isabelle2011**********************************************************************************";
neuper@48886
    27
@{term "0::nat"};
neuper@48886
    28
(*Const ("Groups.zero_class.zero", "Nat.nat")*)
neuper@48886
    29
@{term "1::nat"};
neuper@48886
    30
(*Const ("Groups.one_class.one", "Nat.nat")*)
neuper@48886
    31
@{term "5::nat"};
neuper@48886
    32
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> Nat.nat") $
neuper@48886
    33
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    34
       (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    35
         (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    36
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
    37
@{term "0::int"};
neuper@48886
    38
(*Const ("Groups.zero_class.zero", "Int.int")*)
neuper@48886
    39
@{term "1::int"};
neuper@48886
    40
(*Const ("Groups.one_class.one", "Int.int")*)
neuper@48886
    41
@{term "5::int"};
neuper@48886
    42
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    43
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    44
       (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    45
         (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    46
@{term "-5::int"};
neuper@48886
    47
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    48
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    49
       (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    50
         (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    51
@{term "- 5::int"};
neuper@48886
    52
(*Const ("Groups.uminus_class.uminus", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    53
     (Const ("Int.number_class.number_of", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    54
       (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    55
         (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    56
           (Const ("Int.Bit1...", "Int.int \<Rightarrow> Int.int") $ Const (...)))))*)
neuper@48886
    57
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
    58
@{term "0::real"};
neuper@48886
    59
(*Const ("Groups.zero_class.zero", "RealDef.real")*)
neuper@48886
    60
@{term "1::real"};
neuper@48886
    61
(**)
neuper@48886
    62
@{term "5::real"};
neuper@48886
    63
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> RealDef.real") $
neuper@48886
    64
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    65
       (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    66
         (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    67
@{term "-5::real"};
neuper@48886
    68
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> RealDef.real") $
neuper@48886
    69
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    70
       (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    71
         (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    72
@{term "- 5::real"};
neuper@48886
    73
(*Const ("Groups.uminus_class.uminus", "RealDef.real \<Rightarrow> RealDef.real") $
neuper@48886
    74
     (Const ("Int.number_class.number_of", "Int.int \<Rightarrow> RealDef.real") $
neuper@48886
    75
       (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    76
         (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    77
           (Const ("Int.Bit1...", "Int.int \<Rightarrow> Int.int") $ Const (...)))))*)
neuper@48886
    78
"***Isabelle2012**********************************************************************************";
neuper@48886
    79
@{term "0::nat"};
neuper@48886
    80
(*Const ("Groups.zero_class.zero", "nat")*)
neuper@48886
    81
@{term "1::nat"};
neuper@48886
    82
(*Const ("Groups.one_class.one", "nat")*)
neuper@48886
    83
@{term "5::nat"};
neuper@48886
    84
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> nat") $
neuper@48886
    85
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
    86
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
    87
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
    88
@{term "0::int"};
neuper@48886
    89
(*Const ("Groups.zero_class.zero", "int")*)
neuper@48886
    90
@{term "1::int"};
neuper@48886
    91
(*Const ("Groups.one_class.one", "int")*)
neuper@48886
    92
@{term "5::int"};
neuper@48886
    93
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> int") $
neuper@48886
    94
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
    95
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
    96
@{term "-5::int"};
neuper@48886
    97
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> int") $
neuper@48886
    98
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
    99
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
   100
@{term "- 5::int"};
neuper@48886
   101
(*Const ("Groups.uminus_class.uminus", "int \<Rightarrow> int") $
neuper@48886
   102
     (Const ("Num.numeral_class.numeral", "num \<Rightarrow> int") $
neuper@48886
   103
       (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   104
         (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("...", "num"))))*)
neuper@48886
   105
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
   106
@{term "0::real"};
neuper@48886
   107
(*Const ("Groups.zero_class.zero", "real")*)
neuper@48886
   108
@{term "1::real"};
neuper@48886
   109
(*Const ("Groups.one_class.one", "real")*)
neuper@48886
   110
@{term "5::real"};
neuper@48886
   111
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> real") $
neuper@48886
   112
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   113
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
   114
@{term "-5::real"};
neuper@48886
   115
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> real") $
neuper@48886
   116
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   117
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
   118
@{term "- 5::real"};
neuper@48886
   119
(*Const ("Groups.uminus_class.uminus", "real \<Rightarrow> real") $
neuper@48886
   120
     (Const ("Num.numeral_class.numeral", "num \<Rightarrow> real") $
neuper@48886
   121
       (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   122
         (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("...", "num"))))*)
neuper@48886
   123
"***Isabelle2013**********************************************************************************";
neuper@48886
   124
@{term "0::nat"};
neuper@48886
   125
(*Const ("Groups.zero_class.zero", "nat")*)
neuper@48886
   126
@{term "1::nat"};
neuper@48886
   127
(*Const ("Groups.one_class.one", "nat")*)
neuper@48886
   128
@{term "5::nat"};
neuper@48886
   129
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> nat") $
neuper@48886
   130
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   131
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
   132
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
   133
@{term "0::int"};
neuper@48886
   134
(*Const ("Groups.zero_class.zero", "int")*)
neuper@48886
   135
@{term "1::int"};
neuper@48886
   136
(*Const ("Groups.one_class.one", "int")*)
neuper@48886
   137
@{term "5::int"};
neuper@48886
   138
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> int") $
neuper@48886
   139
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   140
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
   141
@{term "-5::int"};
neuper@48886
   142
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> int") $
neuper@48886
   143
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   144
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
   145
@{term "- 5::int"};
neuper@48886
   146
(*Const ("Groups.uminus_class.uminus", "int \<Rightarrow> int") $
neuper@48886
   147
     (Const ("Num.numeral_class.numeral", "num \<Rightarrow> int") $
neuper@48886
   148
       (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   149
         (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("...", "num"))))*)
neuper@48886
   150
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
   151
@{term "0::real"};
neuper@48886
   152
(*Const ("Groups.zero_class.zero", "real")*)
neuper@48886
   153
@{term "1::real"};
neuper@48886
   154
(*Const ("Groups.one_class.one", "real")*)
neuper@48886
   155
@{term "5::real"};
neuper@48886
   156
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> real") $
neuper@48886
   157
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   158
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
   159
@{term "-5::real"};
neuper@48886
   160
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> real") $
neuper@48886
   161
     (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   162
       (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
neuper@48886
   163
@{term "- 5::real"};
neuper@48886
   164
(*Const ("Groups.uminus_class.uminus", "real \<Rightarrow> real") $
neuper@48886
   165
     (Const ("Num.numeral_class.numeral", "num \<Rightarrow> real") $
neuper@48886
   166
       (Const ("Num.num.Bit1", "num \<Rightarrow> num") $
neuper@48886
   167
         (Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("...", "num"))))*)
neuper@38025
   168
neuper@38025
   169
"----------- inst_bdv -----------------------------------";
neuper@38025
   170
"----------- inst_bdv -----------------------------------";
neuper@38025
   171
"----------- inst_bdv -----------------------------------";
akargl@42145
   172
 if (term2str o prop_of o num_str) @{thm d1_isolate_add2} = 
akargl@42145
   173
     "~ ?bdv occurs_in ?a ==> (?a + ?bdv = 0) = (?bdv = -1 * ?a)" 
akargl@42145
   174
   then ()
akargl@42145
   175
   else error "termC.sml d1_isolate_add2";
akargl@42145
   176
 val subst = [(str2term "bdv", str2term "x")];
akargl@42145
   177
 val t = (norm o #prop o rep_thm) (num_str @{thm d1_isolate_add2});
akargl@42145
   178
 val t' = inst_bdv subst t;
akargl@42145
   179
 if term2str t' = "~ x occurs_in ?a ==> (?a + x = 0) = (x = -1 * ?a)" 
akargl@42145
   180
   then ()
akargl@42145
   181
   else error "termC.sml inst_bdv 1";
neuper@42177
   182
if (term2str o prop_of o num_str) @{thm separate_bdvs_add} = 
neuper@42177
   183
  "[] from [?bdv_1.0, ?bdv_2.0, ?bdv_3.0, ?bdv_4.0] occur_exactly_in ?a\n==>" ^
neuper@42177
   184
  " (?a + ?b = ?c) = (?b = ?c + -1 * ?a)"
neuper@42177
   185
then () else error "termC.sml separate_bdvs_add";
neuper@42177
   186
print_depth 5; 
neuper@38025
   187
neuper@42177
   188
val subst = 
neuper@42177
   189
  [(str2term "bdv_1", str2term "c"),
neuper@42177
   190
 	   (str2term "bdv_2", str2term "c_2"),
neuper@42177
   191
 	   (str2term "bdv_3", str2term "c_3"),
neuper@42177
   192
 	   (str2term "bdv_4", str2term "c_4")];
neuper@42177
   193
val t = (norm o #prop o rep_thm) (num_str @{thm separate_bdvs_add});
neuper@42177
   194
val t' = inst_bdv subst t;
neuper@42172
   195
neuper@42177
   196
if term2str t' = "[] from [c, c_2, c_3, c_4] occur_exactly_in ?a\n\
akargl@42145
   197
 		 \==> (?a + ?b = ?c) = (?b = ?c + -1 * ?a)" 
neuper@42177
   198
then () else error "termC.sml inst_bdv 2";
neuper@38025
   199
neuper@38025
   200
"----------- subst_atomic_all ---------------------------";
neuper@38025
   201
"----------- subst_atomic_all ---------------------------";
neuper@38025
   202
"----------- subst_atomic_all ---------------------------";
neuper@42179
   203
 val t = str2term "(tl vs_vs) from vs_vs occur_exactly_in (NTH 1 (es_es::bool list))";
akargl@42145
   204
 val env = [(str2term "vs_vs::real list", str2term "[c, c_2]"),
akargl@42145
   205
 	   (str2term "es_es::bool list", str2term "[c_2 = 0, c + c_2 = 1]")];
akargl@42145
   206
 val (all_Free_subst, t') = subst_atomic_all env t;
neuper@38025
   207
akargl@42145
   208
 if all_Free_subst andalso 
neuper@42179
   209
    term2str t' = "tl [c, c_2] from [c, c_2] occur_exactly_in NTH 1 [c_2 = 0, c + c_2 = 1]"
akargl@42145
   210
   then ()
akargl@42145
   211
   else error "termC.sml subst_atomic_all should be 'true'";
neuper@38025
   212
akargl@42145
   213
 val (all_Free_subst, t') = subst_atomic_all (tl env) t;
akargl@42145
   214
 if not all_Free_subst andalso 
neuper@42179
   215
    term2str t' = "tl vs_vs from vs_vs occur_exactly_in NTH 1 [c_2 = 0, c + c_2 = 1]" then ()
akargl@42145
   216
 else error "termC.sml subst_atomic_all should be 'false'";
neuper@38025
   217
neuper@38025
   218
"----------- Pattern.match ------------------------------";
neuper@38025
   219
"----------- Pattern.match ------------------------------";
neuper@38025
   220
"----------- Pattern.match ------------------------------";
neuper@42179
   221
 val t = (term_of o the o (parse thy)) "3 * x^^^2 = (1::real)";
neuper@42179
   222
 val pat = (free2var o term_of o the o (parse thy)) "a * b^^^2 = (c::real)";
neuper@42179
   223
 (*        !^^^^^^^^!... necessary for Pattern.match, see Logic.varify_global below*)
neuper@42179
   224
 val insts = Pattern.match @{theory "Isac"} (pat, t) (Vartab.empty, Vartab.empty);
neuper@52101
   225
print_depth 3; (*999*) insts; 
akargl@42145
   226
 (*val insts =
neuper@42179
   227
   ({}, 
neuper@42179
   228
    {(("a", 0), ("RealDef.real", Free ("3", "RealDef.real"))), 
neuper@42179
   229
     (("b", 0), ("RealDef.real", Free ("x", "RealDef.real"))),
neuper@42179
   230
     (("c", 0), ("RealDef.real", Free ("1", "RealDef.real")))})*)
neuper@38025
   231
akargl@42145
   232
 "----- throws exn MATCH...";
neuper@42179
   233
(* val t = str2term "x";
neuper@42179
   234
 (Pattern.match @{theory "Isac"} (pat, t) (Vartab.empty, Vartab.empty))
neuper@42179
   235
 handle MATCH => ???; *)
akargl@42145
   236
akargl@42145
   237
 val thy = @{theory "Complex_Main"};
akargl@42145
   238
 val PARSE = Syntax.read_term_global thy;
akargl@42145
   239
 val (pa, tm) = (PARSE "a + b::real", PARSE  "x + 2*z::real");
neuper@42179
   240
 val (tye, tme) = (Vartab.empty : Type.tyenv, Vartab.empty : Envir.tenv);
neuper@42179
   241
 val (tyenv, tenv) = Pattern.match thy (Logic.varify_global pa, tm) (tye, tme);
neuper@42179
   242
akargl@42145
   243
 Vartab.dest tenv;
akargl@42145
   244
neuper@38025
   245
"----------- fun matches --------------------------------";
neuper@38025
   246
"----------- fun matches --------------------------------";
neuper@38025
   247
"----------- fun matches --------------------------------";
neuper@42179
   248
 (*examples see
neuper@42179
   249
   test/../Knowledge/polyeq.sml:     
akargl@42145
   250
   Where=[Correct "matches (?a = 0) (-8 - 2 * x + x ^^^ 2 = 0)"*)
akargl@42145
   251
 (*test/../Interpret/ptyps.sml:        
akargl@42145
   252
   |\nmatches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],*)
akargl@42145
   253
  val thy = @{theory "Complex_Main"}; 
neuper@38025
   254
neuper@38025
   255
"----- test 1: OK";
akargl@42145
   256
 val pa = Logic.varify_global @{term "a = (0::real)"}; (*<<<<<<<---------------*)
akargl@42145
   257
 tracing "paIsa=..."; atomty pa; tracing "...=paIsa";
neuper@38025
   258
(*** 
neuper@38025
   259
*** Const (op =, real => real => bool)
neuper@38025
   260
*** . Var ((a, 0), real)
neuper@38025
   261
*** . Const (Groups.zero_class.zero, real)
neuper@38025
   262
***)
neuper@38025
   263
"----- test 1a true";
akargl@42145
   264
 val tm = @{term "-8 - 2 * x + x ^ 2 = (0::real)"};    (*<<<<<<<---------------*)
akargl@42145
   265
 if matches thy tm pa then () 
akargl@42145
   266
   else error "termC.sml diff.behav. in matches true 1";
neuper@38025
   267
"----- test 1b false";
akargl@42145
   268
 val tm = @{term "-8 - 2 * x + x ^ 2 = (3::real)"};    (*<<<<<<<---------------*)
akargl@42145
   269
 if matches thy tm pa then error "termC.sml diff.behav. in matches false 1"
neuper@38025
   270
  else ();
neuper@38025
   271
neuper@38025
   272
"----- test 2: Nok";
akargl@42145
   273
 val pa = Logic.varify_global (str2term "a = (0::real)");(*<<<<<<<-------------*)
akargl@42145
   274
 tracing "paLo2=..."; atomty pa; tracing "...=paLo2";
neuper@38025
   275
(*** 
neuper@38025
   276
*** Const (op =, real => real => bool)
neuper@38025
   277
*** . Var ((a, 0), real)
neuper@38025
   278
*** . Var ((0, 0), real)
neuper@38025
   279
***)
neuper@38025
   280
"----- test 2a true";
akargl@42145
   281
 val tm = str2term "-8 - 2 * x + x ^ 2 = (0::real)";     (*<<<<<<<-------------*)
akargl@42145
   282
 if matches thy tm pa then () 
akargl@42145
   283
   else error "termC.sml diff.behav. in matches true 2";
neuper@38025
   284
"----- test 2b false";
akargl@42145
   285
 val tm = str2term "-8 - 2 * x + x ^ 2 = (3::real)";     (*<<<<<<<-------------*)
akargl@42145
   286
 if matches thy tm pa then () 
akargl@42145
   287
   else error "termC.sml diff.behav. in matches false 2";
neuper@38025
   288
(* i.e. !!!!!!!!!!!!!!!!! THIS KIND OF PATTERN IS NOT RELIABLE !!!!!!!!!!!!!!!!!
neuper@38025
   289
if matches thy tm pa then error "termC.sml diff.behav. in matches false 2"
neuper@38025
   290
  else ();*)
neuper@38025
   291
neuper@38025
   292
"----- test 3: OK";
akargl@42145
   293
 val pa = free2var (str2term "a = (0::real)");(*<<<<<<<-------------*)
akargl@42145
   294
 tracing "paF2=..."; atomty pa; tracing "...=paF2";
neuper@38025
   295
(*** 
neuper@38025
   296
*** Const (op =, real => real => bool)
neuper@38025
   297
*** . Var ((a, 0), real)
neuper@38025
   298
*** . Free (0, real)
neuper@38025
   299
***)
neuper@38025
   300
"----- test 3a true";
akargl@42145
   301
 val tm = str2term "-8 - 2 * x + x ^ 2 = (0::real)";     (*<<<<<<<-------------*)
akargl@42145
   302
 if matches thy tm pa then () 
akargl@42145
   303
   else error "termC.sml diff.behav. in matches true 3";
neuper@38025
   304
"----- test 3b false";
akargl@42145
   305
 val tm = str2term "-8 - 2 * x + x ^ 2 = (3::real)";     (*<<<<<<<-------------*)
akargl@42145
   306
 if matches thy tm pa then error "termC.sml diff.behav. in matches false 3"
akargl@42145
   307
   else ();
neuper@38025
   308
neuper@38025
   309
"----- test 4=3 with specific data";
akargl@42145
   310
 val pa = free2var (str2term "M_b 0");
neuper@38025
   311
"----- test 4a true";
akargl@42145
   312
 val tm = str2term "M_b 0";
akargl@42145
   313
 if matches thy tm pa then () 
akargl@42145
   314
   else error "termC.sml diff.behav. in matches true 4";
neuper@38025
   315
"----- test 4b false";
akargl@42145
   316
 val tm = str2term "M_b x";
akargl@42145
   317
 if matches thy tm pa then error "termC.sml diff.behav. in matches false 4"
akargl@42145
   318
   else ();
neuper@38025
   319
neuper@38025
   320
neuper@38037
   321
"----------- fun parse, fun parse_patt, fun T_a2real ----";
neuper@38037
   322
"----------- fun parse, fun parse_patt, fun T_a2real ----";
neuper@38037
   323
"----------- fun parse, fun parse_patt, fun T_a2real ----";
akargl@42145
   324
 val thy = @{theory "Complex_Main"};
akargl@42145
   325
 val str = "x + z";
akargl@42145
   326
 parse thy str;
neuper@38025
   327
"---------------";
akargl@42145
   328
 val str = "x + 2*z";
akargl@42145
   329
 val t = (Syntax.read_term_global thy str);
akargl@42145
   330
 val t = numbers_to_string (Syntax.read_term_global thy str);
akargl@42145
   331
 val t = (typ_a2real o numbers_to_string) (Syntax.read_term_global thy str);
akargl@42145
   332
 cterm_of thy t;
akargl@42145
   333
 val t = (the (parse thy str)) handle _ => error "termC.sml parsing 'x + 2*z' failed";
neuper@38025
   334
neuper@38037
   335
"===== fun parse_patt caused error in fun T_a2real ===";
akargl@42145
   336
 val thy = @{theory "Poly"};
akargl@42145
   337
 parse_patt thy "?p is_addUnordered";
akargl@42145
   338
 parse_patt thy "?p :: real";
neuper@38025
   339
neuper@42179
   340
 val str = "x + z";
neuper@42179
   341
 parse thy str;
neuper@42179
   342
"---------------";
neuper@42179
   343
 val str = "x + 2*z";
neuper@42179
   344
 val t = (Syntax.read_term_global thy str);
neuper@42179
   345
 val t = numbers_to_string (Syntax.read_term_global thy str);
neuper@42179
   346
 val t = (typ_a2real o numbers_to_string) (Syntax.read_term_global thy str);
neuper@42179
   347
 cterm_of thy t;
neuper@42179
   348
 val t = (the (parse thy str)) handle _ => error "termC.sml parsing 'x + 2*z' failed";
neuper@42179
   349
neuper@42179
   350
"===== fun parse_patt caused error in fun T_a2real ===";
neuper@42179
   351
 val thy = @{theory "Poly"};
neuper@42179
   352
 parse_patt thy "?p is_addUnordered";
neuper@42179
   353
 parse_patt thy "?p :: real";
neuper@38051
   354
neuper@42201
   355
(* Christian Urban, 101001 
neuper@42201
   356
theory Test
neuper@42201
   357
imports Main Complex
neuper@42201
   358
begin
neuper@42201
   359
neuper@42201
   360
let
neuper@42201
   361
  val parser = Args.context -- Scan.lift Args.name_source
neuper@48761
   362
  fun term_pat (ctxt, str) = str |> Proof_Context.read_term_pattern ctxt
neuper@42201
   363
  |> ML_Syntax.print_term |> ML_Syntax.atomic
neuper@42201
   364
in
neuper@42201
   365
  ML_Antiquote.inline "term_pat" (parser >> term_pat)
neuper@42201
   366
end
neuper@42201
   367
neuper@42201
   368
  val t = @{term "a + b * x = (0 ::real)"};
neuper@42201
   369
  val pat = @{term_pat "?l = (?r ::real)"};
neuper@42201
   370
  val precond = @{term_pat "is_polynomial (?l::real)"};
neuper@42201
   371
  val inst = Pattern.match @{theory} (pat, t) (Vartab.empty, Vartab.empty);
neuper@42201
   372
neuper@42201
   373
  Envir.subst_term inst precond
neuper@42201
   374
  |> Syntax.string_of_term @{context}
neuper@42201
   375
  |> writeln
neuper@42201
   376
neuper@42201
   377
neuper@42201
   378
end *)
neuper@42201
   379
neuper@38025
   380
"----------- uminus_to_string ---------------------------";
neuper@38025
   381
"----------- uminus_to_string ---------------------------";
neuper@38025
   382
"----------- uminus_to_string ---------------------------";
akargl@42145
   383
 val t1 = numbers_to_string @{term "-2::real"};
akargl@42145
   384
 val t2 = numbers_to_string @{term "- 2::real"};
akargl@42145
   385
 if uminus_to_string t2 = t1 
akargl@42145
   386
   then ()
akargl@42145
   387
   else error "termC.sml diff.behav. in uminus_to_string";
neuper@38025
   388
neuper@38037
   389
"----------- *** prep_pbt: syntax error in '#Where' of [v";
neuper@38037
   390
"----------- *** prep_pbt: syntax error in '#Where' of [v";
neuper@38037
   391
"----------- *** prep_pbt: syntax error in '#Where' of [v";
neuper@38037
   392
"===== deconstruct datatype typ ===";
akargl@42145
   393
 val str = "?a";
akargl@42145
   394
 val t = (thy, str) |>> thy2ctxt 
neuper@48761
   395
                    |-> Proof_Context.read_term_pattern
akargl@42145
   396
                    |> numbers_to_string;
akargl@42145
   397
 val Var (("a", 0), ty) = t;
akargl@42145
   398
 val TVar ((str, i), srt) = ty;
akargl@42145
   399
 if str = "'a" andalso i = 1 andalso srt = [] 
akargl@42145
   400
   then ()
akargl@42145
   401
   else error "termC.sml type-structure of \"?a\" changed";
neuper@38025
   402
neuper@38037
   403
"----- real type in pattern ---";
akargl@42145
   404
 val str = "?a :: real";
akargl@42145
   405
 val t = (thy, str) |>> thy2ctxt 
neuper@48761
   406
                    |-> Proof_Context.read_term_pattern
akargl@42145
   407
                    |> numbers_to_string;
akargl@42145
   408
 val Var (("a", 0), ty) = t;
akargl@42145
   409
 val Type (str, tys) = ty;
akargl@42145
   410
 if str = "RealDef.real" andalso tys = [] andalso ty = HOLogic.realT
akargl@42145
   411
   then ()
akargl@42145
   412
   else error "termC.sml type-structure of \"?a :: real\" changed";
neuper@38037
   413
neuper@38037
   414
"===== Not (matchsub (?a + (?b + ?c)) t_t |... ===";
neuper@42179
   415
val (thy, str) = (thy, "Not (matchsub (?a + (?b + ?c)) t_t | " ^
akargl@42145
   416
	                "     matchsub (?a + (?b - ?c)) t_t | " ^
akargl@42145
   417
	                "     matchsub (?a - (?b + ?c)) t_t | " ^
akargl@42145
   418
	                "     matchsub (?a + (?b - ?c)) t_t )");
neuper@48761
   419
val ctxt = Proof_Context.init_global thy;
neuper@42179
   420
val ctxt = Config.put show_types true ctxt;
neuper@38037
   421
"----- read_term_pattern ---";
neuper@42179
   422
val t = (thy, str) |>> thy2ctxt 
neuper@48761
   423
                    |-> Proof_Context.read_term_pattern
akargl@42145
   424
                    |> numbers_to_string;
neuper@42179
   425
val t_real = typ_a2real t;
neuper@52070
   426
if term_to_string' ctxt t_real =
neuper@42179
   427
"~ (matchsub ((?a::real) + ((?b::real) + (?c::real))) (t_t::real) |\n   matchsub (?a + (?b - ?c))" ^
neuper@42179
   428
" t_t |\n   matchsub (?a - (?b + ?c)) t_t | matchsub (?a + (?b - ?c)) t_t)" then ()
neuper@42179
   429
else error "";
neuper@38051
   430
neuper@38051
   431
"----------- check writeln, tracing for string markup ---";
neuper@38051
   432
"----------- check writeln, tracing for string markup ---";
neuper@38051
   433
"----------- check writeln, tracing for string markup ---";
akargl@42145
   434
 val t = @{term "x + 1"};
akargl@42145
   435
 val str_markup = (Syntax.string_of_term
neuper@48761
   436
       (Proof_Context.init_global (Thy_Info.get_theory "Isac"))) t;
neuper@52070
   437
 val str = term_to_string'' "Isac" t;
neuper@38051
   438
akargl@42145
   439
 writeln "----------------writeln str_markup---";
akargl@42145
   440
 writeln str_markup;
akargl@42145
   441
 writeln "----------------writeln str---";
akargl@42145
   442
 writeln str;
akargl@42145
   443
 writeln "----------------SAME output: no markup----";
neuper@38051
   444
akargl@42145
   445
 writeln "----------------writeln PolyML.makestring str_markup---";
akargl@42145
   446
 writeln (PolyML.makestring str_markup);
akargl@42145
   447
 writeln "----------------writeln PolyML.makestring str---";
akargl@42145
   448
 writeln (PolyML.makestring str);
akargl@42145
   449
 writeln "----------------DIFFERENT output----";
neuper@38051
   450
akargl@42145
   451
 tracing "----------------tracing str_markup---";
akargl@42145
   452
 tracing str_markup;
akargl@42145
   453
 tracing "----------------tracing str---";
akargl@42145
   454
 tracing str;
akargl@42145
   455
 tracing "----------------SAME output: no markup----";
neuper@38051
   456
akargl@42145
   457
 tracing "----------------writeln PolyML.makestring str_markup---";
akargl@42145
   458
 tracing (PolyML.makestring str_markup);
akargl@42145
   459
 tracing "----------------writeln PolyML.makestring str---";
akargl@42145
   460
 tracing (PolyML.makestring str);
akargl@42145
   461
 tracing "----------------DIFFERENT output----";
neuper@38051
   462
(*
neuper@42451
   463
 redirect_tracing "../../tmp/";
akargl@42145
   464
 tracing "----------------writeln str_markup---";
akargl@42145
   465
 tracing str_markup;
akargl@42145
   466
 tracing "----------------writeln str---";
akargl@42145
   467
 tracing str;
akargl@42145
   468
 tracing "----------------DIFFERENT output----";
neuper@38051
   469
*)
neuper@38051
   470
neuper@41924
   471
"----------- check writeln, tracing for string markup ---";
akargl@42145
   472
 val t = @{term "x + 1"};
akargl@42145
   473
 val str_markup = (Syntax.string_of_term
neuper@48761
   474
       (Proof_Context.init_global (Thy_Info.get_theory "Isac"))) t;
neuper@52070
   475
 val str = term_to_string'' "Isac" t;
neuper@41924
   476
akargl@42145
   477
 writeln "----------------writeln str_markup---";
akargl@42145
   478
 writeln str_markup;
akargl@42145
   479
 writeln "----------------writeln str---";
akargl@42145
   480
 writeln str;
akargl@42145
   481
 writeln "----------------SAME output: no markup----";
neuper@41924
   482
akargl@42145
   483
 writeln "----------------writeln PolyML.makestring str_markup---";
akargl@42145
   484
 writeln (PolyML.makestring str_markup);
akargl@42145
   485
 writeln "----------------writeln PolyML.makestring str---";
akargl@42145
   486
 writeln (PolyML.makestring str);
akargl@42145
   487
 writeln "----------------DIFFERENT output----";
neuper@41924
   488
akargl@42145
   489
 tracing "----------------tracing str_markup---";
akargl@42145
   490
 tracing str_markup;
akargl@42145
   491
 tracing "----------------tracing str---";
akargl@42145
   492
 tracing str;
akargl@42145
   493
 tracing "----------------SAME output: no markup----";
neuper@41924
   494
akargl@42145
   495
 tracing "----------------writeln PolyML.makestring str_markup---";
akargl@42145
   496
 tracing (PolyML.makestring str_markup);
akargl@42145
   497
 tracing "----------------writeln PolyML.makestring str---";
akargl@42145
   498
 tracing (PolyML.makestring str);
akargl@42145
   499
 tracing "----------------DIFFERENT output----";
neuper@41924
   500
(*
neuper@42451
   501
 redirect_tracing "../../tmp/";
akargl@42145
   502
 tracing "----------------writeln str_markup---";
akargl@42145
   503
 tracing str_markup;
akargl@42145
   504
 tracing "----------------writeln str---";
akargl@42145
   505
 tracing str;
akargl@42145
   506
 tracing "----------------DIFFERENT output----";
neuper@41924
   507
*)
neuper@42426
   508
neuper@42426
   509
"-------- build fun is_bdv_subst ---------------------------------";
neuper@42426
   510
"-------- build fun is_bdv_subst ---------------------------------";
neuper@42426
   511
"-------- build fun is_bdv_subst ---------------------------------";
neuper@42426
   512
fun is_bdv_subst (Const ("List.list.Cons", _) $
neuper@42426
   513
      (Const ("Product_Type.Pair", _) $ Free (str, _) $ _) $ _) = is_bdv str
neuper@42426
   514
  | is_bdv_subst _ = false;
neuper@42426
   515
neuper@42426
   516
if is_bdv_subst (str2term "[(bdv, v_v)]") then ()
neuper@42426
   517
else error "is_bdv_subst canged 1";
neuper@42426
   518
neuper@42426
   519
if is_bdv_subst (str2term "[(bdv_1, v_s1),(bdv_2, v_s2)]") then ()
neuper@42426
   520
else error "is_bdv_subst canged 2";
neuper@42426
   521