test/Tools/isac/BaseDefinitions/termC.sml
author wneuper <Walther.Neuper@jku.at>
Sun, 09 Oct 2022 07:44:22 +0200
changeset 60565 f92963a33fe3
parent 60477 4ac966aaa785
child 60581 f66543d75c0c
permissions -rw-r--r--
eliminate term2str in test/*
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
walther@60317
     6
"-----------------------------------------------------------------------------------------------";
walther@60317
     7
"table of contents -----------------------------------------------------------------------------";
walther@60317
     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 ------------------------------";
walther@60230
    13
"----------- fun TermC.matches --------------------------------";
Walther@60477
    14
"----------- fun TermC.parse, fun TermC.parse_patt, fun T_a2real -------------------------------";
Walther@60477
    15
"----------- fun TermC.vars_of ---------------------------------------------------------------";
walther@60317
    16
"----------- fun TermC.vars --------------------------------------------------------------------";
walther@59973
    17
"----------- *** Problem.prep_input: syntax error in '#Where' of [v";
neuper@38051
    18
"----------- check writeln, tracing for string markup ---";
walther@60230
    19
"----------- build fun TermC.is_bdv_subst ------------------------------------------------------------";
wneuper@59403
    20
"----------- fun str_of_int --------------------------------------------------------------------";
walther@60230
    21
"----------- fun TermC.scala_of_term -----------------------------------------------------------------";
walther@60230
    22
"----------- fun TermC.contains_Var ------------------------------------------------------------------";
walther@60317
    23
"----------- fun int_opt_of_string, fun is_num -------------------------------------------------";
walther@60230
    24
"----------- fun TermC.is_f_x ------------------------------------------------------------------------";
wneuper@59403
    25
"----------- fun list2isalist, fun isalist2list ------------------------------------------------";
walther@60230
    26
"----------- fun TermC.strip_imp_prems' --------------------------------------------------------------";
walther@60230
    27
"----------- fun TermC.ins_concl ---------------------------------------------------------------------";
wneuper@59403
    28
"----------- fun mk_factroot, fun mk_num_op_num, -----------------------------------------------";
walther@60230
    29
"----------- fun TermC.dest_binop_typ ----------------------------------------------------------------";
walther@60230
    30
"----------- fun TermC.is_list -----------------------------------------------------------------------";
wneuper@59403
    31
"----------- fun inst_abs ----------------------------------------------------------------------";
neuper@38025
    32
"--------------------------------------------------------";
neuper@38025
    33
"--------------------------------------------------------";
neuper@38025
    34
neuper@48886
    35
"----------- numerals in Isabelle2011/12/13 -------------";
neuper@48886
    36
"----------- numerals in Isabelle2011/12/13 -------------";
neuper@48886
    37
"----------- numerals in Isabelle2011/12/13 -------------";
neuper@48886
    38
"***Isabelle2011 ~= Isabelle2012 = Isabelle2013";
neuper@48886
    39
"***Isabelle2011**********************************************************************************";
neuper@48886
    40
@{term "0::nat"};
walther@60336
    41
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "Nat.nat")*)
neuper@48886
    42
@{term "1::nat"};
walther@60336
    43
(*Const (\<^const_name>\<open>one_class.one\<close>, "Nat.nat")*)
neuper@48886
    44
@{term "5::nat"};
neuper@48886
    45
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> Nat.nat") $
neuper@48886
    46
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    47
       (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    48
         (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    49
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
    50
@{term "0::int"};
walther@60336
    51
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "Int.int")*)
neuper@48886
    52
@{term "1::int"};
walther@60336
    53
(*Const (\<^const_name>\<open>one_class.one\<close>, "Int.int")*)
neuper@48886
    54
@{term "5::int"};
neuper@48886
    55
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    56
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    57
       (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    58
         (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    59
@{term "-5::int"};
neuper@48886
    60
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    61
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    62
       (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    63
         (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    64
@{term "- 5::int"};
walther@60336
    65
(*Const (\<^const_name>\<open>uminus\<close>, "Int.int \<Rightarrow> Int.int") $
neuper@48886
    66
     (Const ("Int.number_class.number_of", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    67
       (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    68
         (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    69
           (Const ("Int.Bit1...", "Int.int \<Rightarrow> Int.int") $ Const (...)))))*)
neuper@48886
    70
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
    71
@{term "0::real"};
walther@60336
    72
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "Real.real")*)
neuper@48886
    73
@{term "1::real"};
neuper@48886
    74
(**)
neuper@48886
    75
@{term "5::real"};
neuper@55279
    76
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> "Real.real") $
neuper@48886
    77
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    78
       (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    79
         (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    80
@{term "-5::real"};
neuper@55279
    81
(*Const ("Int.number_class.number_of", "Int.int \<Rightarrow> "Real.real") $
neuper@48886
    82
     (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    83
       (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    84
         (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $ Const ("...", "Int.int"))))*)
neuper@48886
    85
@{term "- 5::real"};
walther@60336
    86
(*Const (\<^const_name>\<open>uminus\<close>, "Real.real \<Rightarrow> "Real.real") $
neuper@55279
    87
     (Const ("Int.number_class.number_of", "Int.int \<Rightarrow> "Real.real") $
neuper@48886
    88
       (Const ("Int.Bit1", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    89
         (Const ("Int.Bit0", "Int.int \<Rightarrow> Int.int") $
neuper@48886
    90
           (Const ("Int.Bit1...", "Int.int \<Rightarrow> Int.int") $ Const (...)))))*)
neuper@48886
    91
"***Isabelle2012**********************************************************************************";
neuper@48886
    92
@{term "0::nat"};
walther@60336
    93
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "nat")*)
neuper@48886
    94
@{term "1::nat"};
walther@60336
    95
(*Const (\<^const_name>\<open>one_class.one\<close>, "nat")*)
neuper@48886
    96
@{term "5::nat"};
walther@60336
    97
(*Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> nat") $
walther@60336
    98
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
    99
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   100
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
   101
@{term "0::int"};
walther@60336
   102
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "int")*)
neuper@48886
   103
@{term "1::int"};
walther@60336
   104
(*Const (\<^const_name>\<open>one_class.one\<close>, "int")*)
neuper@48886
   105
@{term "5::int"};
walther@60336
   106
(*Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> int") $
walther@60336
   107
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   108
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   109
@{term "-5::int"};
neuper@48886
   110
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> int") $
walther@60336
   111
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   112
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   113
@{term "- 5::int"};
walther@60336
   114
(*Const (\<^const_name>\<open>uminus\<close>, "int \<Rightarrow> int") $
walther@60336
   115
     (Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> int") $
walther@60336
   116
       (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   117
         (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const ("...", "num"))))*)
neuper@48886
   118
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
   119
@{term "0::real"};
walther@60336
   120
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "real")*)
neuper@48886
   121
@{term "1::real"};
walther@60336
   122
(*Const (\<^const_name>\<open>one_class.one\<close>, "real")*)
neuper@48886
   123
@{term "5::real"};
walther@60336
   124
(*Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> real") $
walther@60336
   125
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   126
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   127
@{term "-5::real"};
neuper@48886
   128
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> real") $
walther@60336
   129
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   130
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   131
@{term "- 5::real"};
walther@60336
   132
(*Const (\<^const_name>\<open>uminus\<close>, "real \<Rightarrow> real") $
walther@60336
   133
     (Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> real") $
walther@60336
   134
       (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   135
         (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const ("...", "num"))))*)
neuper@48886
   136
"***Isabelle2013**********************************************************************************";
neuper@48886
   137
@{term "0::nat"};
walther@60336
   138
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "nat")*)
neuper@48886
   139
@{term "1::nat"};
walther@60336
   140
(*Const (\<^const_name>\<open>one_class.one\<close>, "nat")*)
neuper@48886
   141
@{term "5::nat"};
walther@60336
   142
(*Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> nat") $
walther@60336
   143
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   144
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   145
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
   146
@{term "0::int"};
walther@60336
   147
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "int")*)
neuper@48886
   148
@{term "1::int"};
walther@60336
   149
(*Const (\<^const_name>\<open>one_class.one\<close>, "int")*)
neuper@48886
   150
@{term "5::int"};
walther@60336
   151
(*Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> int") $
walther@60336
   152
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   153
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   154
@{term "-5::int"};
neuper@48886
   155
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> int") $
walther@60336
   156
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   157
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   158
@{term "- 5::int"};
walther@60336
   159
(*Const (\<^const_name>\<open>uminus\<close>, "int \<Rightarrow> int") $
walther@60336
   160
     (Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> int") $
walther@60336
   161
       (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   162
         (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const ("...", "num"))))*)
neuper@48886
   163
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
neuper@48886
   164
@{term "0::real"};
walther@60336
   165
(*Const (\<^const_name>\<open>zero_class.zero\<close>, "real")*)
neuper@48886
   166
@{term "1::real"};
walther@60336
   167
(*Const (\<^const_name>\<open>one_class.one\<close>, "real")*)
neuper@48886
   168
@{term "5::real"};
walther@60336
   169
(*Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> real") $
walther@60336
   170
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   171
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   172
@{term "-5::real"};
neuper@48886
   173
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> real") $
walther@60336
   174
     (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   175
       (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const (\<^const_name>\<open>num.One\<close>, "num")))*)
neuper@48886
   176
@{term "- 5::real"};
walther@60336
   177
(*Const (\<^const_name>\<open>uminus\<close>, "real \<Rightarrow> real") $
walther@60336
   178
     (Const (\<^const_name>\<open>numeral\<close>, "num \<Rightarrow> real") $
walther@60336
   179
       (Const (\<^const_name>\<open>num.Bit1\<close>, "num \<Rightarrow> num") $
walther@60336
   180
         (Const (\<^const_name>\<open>num.Bit0\<close>, "num \<Rightarrow> num") $ Const ("...", "num"))))*)
neuper@38025
   181
neuper@38025
   182
"----------- inst_bdv -----------------------------------";
neuper@38025
   183
"----------- inst_bdv -----------------------------------";
neuper@38025
   184
"----------- inst_bdv -----------------------------------";
walther@60337
   185
 if (UnparseC.term o Thm.prop_of) @{thm d1_isolate_add2} = 
walther@60317
   186
     "\<not> ?bdv occurs_in ?a \<Longrightarrow>\n(?a + ?bdv = 0) = (?bdv = - 1 * ?a)"
akargl@42145
   187
   then ()
akargl@42145
   188
   else error "termC.sml d1_isolate_add2";
Walther@60565
   189
 val subst = [(TermC.parse_test @{context} "bdv", TermC.parse_test @{context} "x")];
walther@60337
   190
 val t = (Eval.norm o Thm.prop_of)  @{thm d1_isolate_add2};
walther@60230
   191
 val t' = TermC.inst_bdv subst t;
walther@60317
   192
 if UnparseC.term t' = "\<not> x occurs_in ?a \<Longrightarrow> (?a + x = 0) = (x = - 1 * ?a)"
akargl@42145
   193
   then ()
akargl@42145
   194
   else error "termC.sml inst_bdv 1";
walther@60337
   195
if (UnparseC.term o Thm.prop_of) @{thm separate_bdvs_add} = 
walther@60317
   196
  "[] from [?bdv_1.0, ?bdv_2.0, ?bdv_3.0,\n         " ^
walther@60317
   197
  "?bdv_4.0] occur_exactly_in ?a \<Longrightarrow>\n(?a + ?b = ?c) = (?b = ?c + - (1::?'a) * ?a)"
neuper@42177
   198
then () else error "termC.sml separate_bdvs_add";
wneuper@59348
   199
(*default_print_depth 5;*)
neuper@38025
   200
neuper@42177
   201
val subst = 
Walther@60565
   202
  [(TermC.parse_test @{context} "bdv_1", TermC.parse_test @{context} "c"),
Walther@60565
   203
 	   (TermC.parse_test @{context} "bdv_2", TermC.parse_test @{context} "c_2"),
Walther@60565
   204
 	   (TermC.parse_test @{context} "bdv_3", TermC.parse_test @{context} "c_3"),
Walther@60565
   205
 	   (TermC.parse_test @{context} "bdv_4", TermC.parse_test @{context} "c_4")];
walther@60337
   206
val t = (Eval.norm o Thm.prop_of)  @{thm separate_bdvs_add};
walther@60230
   207
val t' = TermC.inst_bdv subst t;
neuper@42172
   208
walther@60317
   209
if UnparseC.term t' = "[] from [c, c_2, c_3, c_4] occur_exactly_in ?a \<Longrightarrow>\n" ^
walther@60317
   210
  "(?a + ?b = ?c) = (?b = ?c + - (1::?'a) * ?a)"
neuper@42177
   211
then () else error "termC.sml inst_bdv 2";
neuper@38025
   212
neuper@38025
   213
"----------- subst_atomic_all ---------------------------";
neuper@38025
   214
"----------- subst_atomic_all ---------------------------";
neuper@38025
   215
"----------- subst_atomic_all ---------------------------";
Walther@60565
   216
 val t = TermC.parse_test @{context} "(tl vs_vs) from vs_vs occur_exactly_in (NTH 1 (es_es::bool list))";
Walther@60565
   217
 val env = [(TermC.parse_test @{context} "vs_vs::real list", TermC.parse_test @{context} "[c, c_2]"),
Walther@60565
   218
 	   (TermC.parse_test @{context} "es_es::bool list", TermC.parse_test @{context} "[c_2 = 0, c + c_2 = 1]")];
walther@60230
   219
 val (all_Free_subst, t') = TermC.subst_atomic_all env t;
neuper@38025
   220
akargl@42145
   221
 if all_Free_subst andalso 
walther@59868
   222
    UnparseC.term t' = "tl [c, c_2] from [c, c_2] occur_exactly_in NTH 1 [c_2 = 0, c + c_2 = 1]"
akargl@42145
   223
   then ()
akargl@42145
   224
   else error "termC.sml subst_atomic_all should be 'true'";
neuper@38025
   225
walther@60230
   226
 val (all_Free_subst, t') = TermC.subst_atomic_all (tl env) t;
akargl@42145
   227
 if not all_Free_subst andalso 
walther@59868
   228
    UnparseC.term t' = "tl vs_vs from vs_vs occur_exactly_in NTH 1 [c_2 = 0, c + c_2 = 1]" then ()
walther@60230
   229
 else error "TermC.subst_atomic_all should be 'false'";
neuper@38025
   230
neuper@38025
   231
"----------- Pattern.match ------------------------------";
neuper@38025
   232
"----------- Pattern.match ------------------------------";
neuper@38025
   233
"----------- Pattern.match ------------------------------";
Walther@60565
   234
 val t = TermC.parse_test @{context} "3 * x\<up>2 = (1::real)";
Walther@60565
   235
 val pat = (TermC.free2var o TermC.parse_test @{context}) "a * b\<up>2 = (c::real)";
walther@60242
   236
 (*        ! \<up>  \<up> ^^!... necessary for Pattern.match, see Logic.varify_global below*)
wneuper@59592
   237
 val insts = Pattern.match @{theory "Isac_Knowledge"} (pat, t) (Vartab.empty, Vartab.empty);
wneuper@59348
   238
(*default_print_depth 3; 999*) insts; 
akargl@42145
   239
 (*val insts =
neuper@42179
   240
   ({}, 
neuper@55279
   241
    {(("a", 0), ("Real.real", Free ("3", "Real.real"))), 
neuper@55279
   242
     (("b", 0), ("Real.real", Free ("x", "Real.real"))),
neuper@55279
   243
     (("c", 0), ("Real.real", Free ("1", "Real.real")))})*)
neuper@38025
   244
akargl@42145
   245
 "----- throws exn MATCH...";
Walther@60565
   246
(* val t = TermC.parse_test @{context} "x";
wneuper@59592
   247
 (Pattern.match @{theory "Isac_Knowledge"} (pat, t) (Vartab.empty, Vartab.empty))
neuper@42179
   248
 handle MATCH => ???; *)
akargl@42145
   249
akargl@42145
   250
 val thy = @{theory "Complex_Main"};
akargl@42145
   251
 val PARSE = Syntax.read_term_global thy;
akargl@42145
   252
 val (pa, tm) = (PARSE "a + b::real", PARSE  "x + 2*z::real");
neuper@42179
   253
 val (tye, tme) = (Vartab.empty : Type.tyenv, Vartab.empty : Envir.tenv);
neuper@42179
   254
 val (tyenv, tenv) = Pattern.match thy (Logic.varify_global pa, tm) (tye, tme);
neuper@42179
   255
akargl@42145
   256
 Vartab.dest tenv;
akargl@42145
   257
walther@60230
   258
"----------- fun TermC.matches --------------------------------";
walther@60230
   259
"----------- fun TermC.matches --------------------------------";
walther@60230
   260
"----------- fun TermC.matches --------------------------------";
neuper@42179
   261
 (*examples see
neuper@42179
   262
   test/../Knowledge/polyeq.sml:     
walther@60242
   263
   Where=[Correct "matches (?a = 0) (-8 - 2 * x + x \<up> 2 = 0)"*)
walther@59967
   264
 (*test/../Specify/refine.sml:        
walther@60242
   265
   |\nmatches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x \<up> #2 + #8)"],*)
akargl@42145
   266
  val thy = @{theory "Complex_Main"}; 
neuper@38025
   267
neuper@38025
   268
"----- test 1: OK";
akargl@42145
   269
 val pa = Logic.varify_global @{term "a = (0::real)"}; (*<<<<<<<---------------*)
walther@60230
   270
 tracing "paIsa=..."; TermC.atomty pa; tracing "...=paIsa";
neuper@38025
   271
(*** 
neuper@38025
   272
*** Const (op =, real => real => bool)
neuper@38025
   273
*** . Var ((a, 0), real)
neuper@38025
   274
*** . Const (Groups.zero_class.zero, real)
neuper@38025
   275
***)
neuper@38025
   276
"----- test 1a true";
akargl@42145
   277
 val tm = @{term "-8 - 2 * x + x ^ 2 = (0::real)"};    (*<<<<<<<---------------*)
walther@60230
   278
 if TermC.matches thy tm pa then () 
walther@60230
   279
   else error "termC.sml diff.behav. in TermC.matches true 1";
neuper@38025
   280
"----- test 1b false";
akargl@42145
   281
 val tm = @{term "-8 - 2 * x + x ^ 2 = (3::real)"};    (*<<<<<<<---------------*)
walther@60230
   282
 if TermC.matches thy tm pa then error "termC.sml diff.behav. in TermC.matches false 1"
neuper@38025
   283
  else ();
neuper@38025
   284
neuper@38025
   285
"----- test 2: Nok";
Walther@60565
   286
 val pa = Logic.varify_global (TermC.parse_test @{context} "a = (0::real)");(*<<<<<<<-------------*)
walther@60230
   287
 tracing "paLo2=..."; TermC.atomty pa; tracing "...=paLo2";
neuper@38025
   288
(*** 
neuper@38025
   289
*** Const (op =, real => real => bool)
neuper@38025
   290
*** . Var ((a, 0), real)
neuper@38025
   291
*** . Var ((0, 0), real)
neuper@38025
   292
***)
neuper@38025
   293
"----- test 2a true";
Walther@60565
   294
 val tm = TermC.parse_test @{context} "-8 - 2 * x + x ^ 2 = (0::real)";     (*<<<<<<<-------------*)
walther@60230
   295
 if TermC.matches thy tm pa then () 
walther@60230
   296
   else error "termC.sml diff.behav. in TermC.matches true 2";
neuper@38025
   297
"----- test 2b false";
Walther@60565
   298
 val tm = TermC.parse_test @{context} "-8 - 2 * x + x ^ 2 = (3::real)";     (*<<<<<<<-------------*)
walther@60317
   299
 if TermC.matches thy tm pa then error "termC.sml diff.behav. in TermC.matches false 2"
walther@60317
   300
   else ();
neuper@38025
   301
(* i.e. !!!!!!!!!!!!!!!!! THIS KIND OF PATTERN IS NOT RELIABLE !!!!!!!!!!!!!!!!!
walther@60230
   302
if TermC.matches thy tm pa then error "termC.sml diff.behav. in TermC.matches false 2"
neuper@38025
   303
  else ();*)
neuper@38025
   304
neuper@38025
   305
"----- test 3: OK";
Walther@60565
   306
 val pa = TermC.free2var (TermC.parse_test @{context} "a = (0::real)");(*<<<<<<<-------------*)
walther@60230
   307
 tracing "paF2=..."; TermC.atomty pa; tracing "...=paF2";
neuper@38025
   308
(*** 
neuper@38025
   309
*** Const (op =, real => real => bool)
neuper@38025
   310
*** . Var ((a, 0), real)
neuper@38025
   311
*** . Free (0, real)
neuper@38025
   312
***)
neuper@38025
   313
"----- test 3a true";
Walther@60565
   314
 val tm = TermC.parse_test @{context} "-8 - 2 * x + x ^ 2 = (0::real)";     (*<<<<<<<-------------*)
walther@60230
   315
 if TermC.matches thy tm pa then () 
walther@60230
   316
   else error "termC.sml diff.behav. in TermC.matches true 3";
neuper@38025
   317
"----- test 3b false";
Walther@60565
   318
 val tm = TermC.parse_test @{context} "-8 - 2 * x + x ^ 2 = (3::real)";     (*<<<<<<<-------------*)
walther@60230
   319
 if TermC.matches thy tm pa then error "termC.sml diff.behav. in TermC.matches false 3"
akargl@42145
   320
   else ();
neuper@38025
   321
neuper@38025
   322
"----- test 4=3 with specific data";
Walther@60565
   323
 val pa = TermC.free2var (TermC.parse_test @{context} "M_b 0");
neuper@38025
   324
"----- test 4a true";
Walther@60565
   325
 val tm = TermC.parse_test @{context} "M_b 0";
walther@60230
   326
 if TermC.matches thy tm pa then () 
walther@60230
   327
   else error "termC.sml diff.behav. in TermC.matches true 4";
neuper@38025
   328
"----- test 4b false";
Walther@60565
   329
 val tm = TermC.parse_test @{context} "M_b x";
walther@60230
   330
 if TermC.matches thy tm pa then error "termC.sml diff.behav. in TermC.matches false 4"
akargl@42145
   331
   else ();
neuper@38025
   332
Walther@60477
   333
"----------- fun TermC.parse, fun TermC.parse_patt, fun T_a2real -------------------------------";
Walther@60477
   334
"----------- fun TermC.parse, fun TermC.parse_patt, fun T_a2real -------------------------------";
Walther@60477
   335
"----------- fun TermC.parse, fun TermC.parse_patt, fun T_a2real -------------------------------";
wneuper@59394
   336
(* added after Isabelle2015->17
walther@60242
   337
> val (SOME ct) = TermC.parse thy "(-#5)\<up>#3"; 
walther@60230
   338
> TermC.atomty (Thm.term_of ct);
wneuper@59394
   339
*** -------------
wneuper@59394
   340
*** Const ( Nat.op ^, ['a, nat] => 'a)
wneuper@59394
   341
***   Const ( uminus, 'a => 'a)
wneuper@59394
   342
***     Free ( #5, 'a)
wneuper@59394
   343
***   Free ( #3, nat)                
walther@60230
   344
> val (SOME ct) = TermC.parse thy "R=R"; 
walther@60230
   345
> TermC.atomty (Thm.term_of ct);
wneuper@59394
   346
*** -------------
wneuper@59394
   347
*** Const ( op =, [real, real] => bool)
wneuper@59394
   348
***   Free ( R, real)
wneuper@59394
   349
***   Free ( R, real)
wneuper@59394
   350
walther@60230
   351
THIS IS THE OUTPUT FOR VERSION (3) above at TermC.typ_a2real !!!!!
wneuper@59394
   352
*** -------------
wneuper@59394
   353
*** Const ( op =, [RealDef.real, RealDef.real] => bool)
wneuper@59394
   354
***   Free ( R, RealDef.real)
wneuper@59394
   355
***   Free ( R, RealDef.real)                  *)
akargl@42145
   356
 val thy = @{theory "Complex_Main"};
Walther@60424
   357
 val ctxt = (ThyC.id_to_ctxt "Isac_Knowledge")
akargl@42145
   358
 val str = "x + z";
Walther@60424
   359
 TermC.parseNEW' ctxt str;
Walther@60424
   360
neuper@38025
   361
"---------------";
walther@60340
   362
 val str = "x + 2*z";
walther@60340
   363
 val t =  Syntax.read_term_global thy str;
walther@60340
   364
 val t = TermC.typ_a2real (Syntax.read_term_global thy str);
walther@60340
   365
 Thm.global_cterm_of thy t;
Walther@60424
   366
 case TermC.parseNEW ctxt str of
walther@60340
   367
   SOME t' => t'
walther@60340
   368
 | NONE => error "termC.sml parsing 'x + 2*z' failed";
neuper@38025
   369
walther@60230
   370
"===== fun TermC.parse_patt caused error in fun T_a2real ===";
akargl@42145
   371
 val thy = @{theory "Poly"};
walther@60230
   372
 TermC.parse_patt thy "?p is_addUnordered";
walther@60230
   373
 TermC.parse_patt thy "?p :: real";
neuper@38025
   374
walther@60230
   375
"===== fun TermC.parse_patt caused error in fun T_a2real ===";
neuper@42179
   376
 val thy = @{theory "Poly"};
walther@60230
   377
 TermC.parse_patt thy "?p is_addUnordered";
walther@60230
   378
 TermC.parse_patt thy "?p :: real";
neuper@38051
   379
neuper@42201
   380
(* Christian Urban, 101001 
neuper@42201
   381
theory Test
neuper@42201
   382
imports Main Complex
neuper@42201
   383
begin
neuper@42201
   384
neuper@42201
   385
let
neuper@42201
   386
  val parser = Args.context -- Scan.lift Args.name_source
neuper@48761
   387
  fun term_pat (ctxt, str) = str |> Proof_Context.read_term_pattern ctxt
neuper@42201
   388
  |> ML_Syntax.print_term |> ML_Syntax.atomic
neuper@42201
   389
in
neuper@42201
   390
  ML_Antiquote.inline "term_pat" (parser >> term_pat)
neuper@42201
   391
end
neuper@42201
   392
neuper@42201
   393
  val t = @{term "a + b * x = (0 ::real)"};
neuper@42201
   394
  val pat = @{term_pat "?l = (?r ::real)"};
neuper@42201
   395
  val precond = @{term_pat "is_polynomial (?l::real)"};
neuper@42201
   396
  val inst = Pattern.match @{theory} (pat, t) (Vartab.empty, Vartab.empty);
neuper@42201
   397
neuper@42201
   398
  Envir.subst_term inst precond
neuper@42201
   399
  |> Syntax.string_of_term @{context}
neuper@42201
   400
  |> writeln
wneuper@59533
   401
end *)
neuper@42201
   402
Walther@60477
   403
"----------- fun TermC.vars_of ---------------------------------------------------------------";
Walther@60477
   404
"----------- fun TermC.vars_of ---------------------------------------------------------------";
Walther@60477
   405
"----------- fun TermC.vars_of ---------------------------------------------------------------";
wneuper@59533
   406
val thy = @{theory Partial_Fractions};
wneuper@59533
   407
val ctxt = Proof_Context.init_global @{theory}
neuper@42201
   408
walther@60242
   409
val SOME t = TermC.parseNEW ctxt "x \<up> 2 + -1 * x * y";
walther@60230
   410
case TermC.vars_of t of [Free ("x", _), Free ("y", _)] => ()
walther@60242
   411
| _ => error "TermC.vars_of (x \<up> 2 + -1 * x * y) ..changed";
wneuper@59533
   412
wneuper@59533
   413
val SOME t = TermC.parseNEW ctxt "3 = 3 * AA / 4";
walther@60278
   414
walther@60336
   415
case TermC.vars_of t of [Const (\<^const_name>\<open>AA\<close>, _), Const (\<^const_name>\<open>HOL.eq\<close>, _)] => ()
walther@60230
   416
| _ => error "TermC.vars_of (3 = 3 * AA / 4) ..changed (! use only for polynomials, not equations!)";
wneuper@59533
   417
neuper@42201
   418
walther@59973
   419
"----------- *** Problem.prep_input: syntax error in '#Where' of [v";
walther@59973
   420
"----------- *** Problem.prep_input: syntax error in '#Where' of [v";
walther@59973
   421
"----------- *** Problem.prep_input: syntax error in '#Where' of [v";
neuper@38037
   422
"===== deconstruct datatype typ ===";
akargl@42145
   423
 val str = "?a";
walther@60360
   424
 val t = (thy, str) |>> Proof_Context.init_global
walther@60337
   425
                    |-> Proof_Context.read_term_pattern;
akargl@42145
   426
 val Var (("a", 0), ty) = t;
akargl@42145
   427
 val TVar ((str, i), srt) = ty;
akargl@42145
   428
 if str = "'a" andalso i = 1 andalso srt = [] 
akargl@42145
   429
   then ()
akargl@42145
   430
   else error "termC.sml type-structure of \"?a\" changed";
neuper@38025
   431
neuper@38037
   432
"----- real type in pattern ---";
akargl@42145
   433
 val str = "?a :: real";
walther@60360
   434
 val t = (thy, str) |>> Proof_Context.init_global 
walther@60337
   435
                    |-> Proof_Context.read_term_pattern;
akargl@42145
   436
 val Var (("a", 0), ty) = t;
akargl@42145
   437
 val Type (str, tys) = ty;
wenzelm@60309
   438
 if str = \<^type_name>\<open>real\<close> andalso tys = [] andalso ty = HOLogic.realT
akargl@42145
   439
   then ()
akargl@42145
   440
   else error "termC.sml type-structure of \"?a :: real\" changed";
neuper@38037
   441
neuper@38037
   442
"===== Not (matchsub (?a + (?b + ?c)) t_t |... ===";
neuper@42179
   443
val (thy, str) = (thy, "Not (matchsub (?a + (?b + ?c)) t_t | " ^
akargl@42145
   444
	                "     matchsub (?a + (?b - ?c)) t_t | " ^
akargl@42145
   445
	                "     matchsub (?a - (?b + ?c)) t_t | " ^
akargl@42145
   446
	                "     matchsub (?a + (?b - ?c)) t_t )");
neuper@48761
   447
val ctxt = Proof_Context.init_global thy;
neuper@42179
   448
val ctxt = Config.put show_types true ctxt;
neuper@38037
   449
"----- read_term_pattern ---";
walther@60360
   450
val t = (thy, str) |>> Proof_Context.init_global 
walther@60337
   451
                    |-> Proof_Context.read_term_pattern;
walther@60230
   452
val t_real = TermC.typ_a2real t;
walther@59870
   453
if UnparseC.term_in_ctxt ctxt t_real =
wneuper@59357
   454
  "\<not> (matchsub ((?a::real) + ((?b::real) + (?c::real))) (t_t::real) \<or>\n        "
wneuper@59357
   455
  ^ "matchsub (?a + (?b - ?c)) t_t \<or>\n        "
wneuper@59357
   456
  ^ "matchsub (?a - (?b + ?c)) t_t \<or> matchsub (?a + (?b - ?c)) t_t)" then ()
wneuper@59357
   457
else error "matchsub";
neuper@38051
   458
neuper@38051
   459
"----------- check writeln, tracing for string markup ---";
neuper@38051
   460
"----------- check writeln, tracing for string markup ---";
neuper@38051
   461
"----------- check writeln, tracing for string markup ---";
akargl@42145
   462
 val t = @{term "x + 1"};
akargl@42145
   463
 val str_markup = (Syntax.string_of_term
walther@59879
   464
       (Proof_Context.init_global (ThyC.get_theory "Isac_Knowledge"))) t;
walther@59870
   465
 val str = UnparseC.term_by_thyID "Isac_Knowledge" t;
neuper@38051
   466
akargl@42145
   467
 writeln "----------------writeln str_markup---";
akargl@42145
   468
 writeln str_markup;
akargl@42145
   469
 writeln "----------------writeln str---";
akargl@42145
   470
 writeln str;
akargl@42145
   471
 writeln "----------------SAME output: no markup----";
neuper@38051
   472
akargl@42145
   473
 writeln "----------------writeln PolyML.makestring str_markup---";
wneuper@59348
   474
 writeln (@{make_string} str_markup);
akargl@42145
   475
 writeln "----------------writeln PolyML.makestring str---";
wneuper@59348
   476
 writeln (@{make_string} str);
akargl@42145
   477
 writeln "----------------DIFFERENT output----";
neuper@38051
   478
akargl@42145
   479
 tracing "----------------tracing str_markup---";
akargl@42145
   480
 tracing str_markup;
akargl@42145
   481
 tracing "----------------tracing str---";
akargl@42145
   482
 tracing str;
akargl@42145
   483
 tracing "----------------SAME output: no markup----";
neuper@38051
   484
akargl@42145
   485
 tracing "----------------writeln PolyML.makestring str_markup---";
wneuper@59348
   486
 tracing (@{make_string} str_markup);
akargl@42145
   487
 tracing "----------------writeln PolyML.makestring str---";
wneuper@59348
   488
 tracing (@{make_string} str);
akargl@42145
   489
 tracing "----------------DIFFERENT output----";
neuper@38051
   490
(*
neuper@42451
   491
 redirect_tracing "../../tmp/";
akargl@42145
   492
 tracing "----------------writeln str_markup---";
akargl@42145
   493
 tracing str_markup;
akargl@42145
   494
 tracing "----------------writeln str---";
akargl@42145
   495
 tracing str;
akargl@42145
   496
 tracing "----------------DIFFERENT output----";
neuper@38051
   497
*)
neuper@38051
   498
neuper@41924
   499
"----------- check writeln, tracing for string markup ---";
akargl@42145
   500
 val t = @{term "x + 1"};
akargl@42145
   501
 val str_markup = (Syntax.string_of_term
walther@59879
   502
       (Proof_Context.init_global (ThyC.get_theory "Isac_Knowledge"))) t;
walther@59870
   503
 val str = UnparseC.term_by_thyID "Isac_Knowledge" t;
neuper@41924
   504
akargl@42145
   505
 writeln "----------------writeln str_markup---";
akargl@42145
   506
 writeln str_markup;
akargl@42145
   507
 writeln "----------------writeln str---";
akargl@42145
   508
 writeln str;
akargl@42145
   509
 writeln "----------------SAME output: no markup----";
neuper@41924
   510
akargl@42145
   511
 writeln "----------------writeln PolyML.makestring str_markup---";
wneuper@59348
   512
 writeln (@{make_string} str_markup);
akargl@42145
   513
 writeln "----------------writeln PolyML.makestring str---";
wneuper@59348
   514
 writeln (@{make_string} str);
akargl@42145
   515
 writeln "----------------DIFFERENT output----";
neuper@41924
   516
akargl@42145
   517
 tracing "----------------tracing str_markup---";
akargl@42145
   518
 tracing str_markup;
akargl@42145
   519
 tracing "----------------tracing str---";
akargl@42145
   520
 tracing str;
akargl@42145
   521
 tracing "----------------SAME output: no markup----";
neuper@41924
   522
akargl@42145
   523
 tracing "----------------writeln PolyML.makestring str_markup---";
wneuper@59348
   524
 tracing (@{make_string} str_markup);
akargl@42145
   525
 tracing "----------------writeln PolyML.makestring str---";
wneuper@59348
   526
 tracing (@{make_string} str);
akargl@42145
   527
 tracing "----------------DIFFERENT output----";
neuper@41924
   528
(*
neuper@42451
   529
 redirect_tracing "../../tmp/";
akargl@42145
   530
 tracing "----------------writeln str_markup---";
akargl@42145
   531
 tracing str_markup;
akargl@42145
   532
 tracing "----------------writeln str---";
akargl@42145
   533
 tracing str;
akargl@42145
   534
 tracing "----------------DIFFERENT output----";
neuper@41924
   535
*)
neuper@42426
   536
walther@60230
   537
"----------- fun TermC.is_bdv_subst ------------------------------------------------------------------";
walther@60230
   538
"----------- fun TermC.is_bdv_subst ------------------------------------------------------------------";
walther@60230
   539
"----------- fun TermC.is_bdv_subst ------------------------------------------------------------------";
Walther@60565
   540
if TermC.is_bdv_subst (TermC.parse_test @{context} "[(''bdv'', v_v)]") then ()
walther@60230
   541
else error "TermC.is_bdv_subst canged 1";
neuper@42426
   542
Walther@60565
   543
if TermC.is_bdv_subst (TermC.parse_test @{context} "[(''bdv_1'', v_s1),(''bdv_2'', v_s2)]") then ()
walther@60230
   544
else error "TermC.is_bdv_subst canged 2";
neuper@42426
   545
wneuper@59403
   546
"----------- fun str_of_int --------------------------------------------------------------------";
wneuper@59403
   547
"----------- fun str_of_int --------------------------------------------------------------------";
wneuper@59403
   548
"----------- fun str_of_int --------------------------------------------------------------------";
walther@60230
   549
if TermC.str_of_int 1 = "1" then () else error "str_of_int 1";
walther@60230
   550
if TermC.str_of_int ~1 = "-1" then () else error "str_of_int -1";
wneuper@59392
   551
walther@60230
   552
"----------- fun TermC.scala_of_term -----------------------------------------------------------------";
walther@60230
   553
"----------- fun TermC.scala_of_term -----------------------------------------------------------------";
walther@60230
   554
"----------- fun TermC.scala_of_term -----------------------------------------------------------------";
wneuper@59403
   555
val t = @{term "aaa::real"};
walther@60230
   556
if TermC.scala_of_term t = "Free(\"aaa\", Type(\"Real.real\", List()))"
walther@60230
   557
then () else error "TermC.scala_of_term  aaa::real";
wneuper@59392
   558
wneuper@59403
   559
val t = @{term "aaa + bbb"};
walther@60335
   560
if TermC.scala_of_term t = "App(App(Const (\"Groups.plus_class.plus\", Type(\"fun\", List(TFree(\"'a\", List(\"Groups.plus\")), Type(\"fun\", List(TFree(\"'a\", List(\"Groups.plus\")), TFree(\"'a\", List(\"Groups.plus\"))))))), Free(\"aaa\", TFree(\"'a\", List(\"Groups.plus\")))), Free(\"bbb\", TFree(\"'a\", List(\"Groups.plus\"))))"
walther@60230
   561
then () else error "TermC.scala_of_term  aaa + bbb";
wneuper@59403
   562
walther@60230
   563
"----------- fun TermC.contains_Var ------------------------------------------------------------------";
walther@60230
   564
"----------- fun TermC.contains_Var ------------------------------------------------------------------";
walther@60230
   565
"----------- fun TermC.contains_Var ------------------------------------------------------------------";
walther@60230
   566
val t = TermC.parse_patt @{theory} "?z = 3";
walther@60230
   567
if TermC.contains_Var t = true then () else error "TermC.contains_Var  ?z = 3";
wneuper@59403
   568
walther@60230
   569
val t = TermC.parse_patt @{theory} "z = 3";
walther@60230
   570
if TermC.contains_Var t = false then () else error "TermC.contains_Var  ?z = 3";
wneuper@59403
   571
walther@60317
   572
"----------- fun int_opt_of_string, fun is_num -------------------------------------------------";
walther@60317
   573
"----------- fun int_opt_of_string, fun is_num -------------------------------------------------";
walther@60317
   574
"----------- fun int_opt_of_string, fun is_num -------------------------------------------------";
walther@59875
   575
case ThmC_Def.int_opt_of_string "123" of
walther@59875
   576
  SOME 123 => () | _ => raise error "ThmC_Def.int_opt_of_string  123  changed";
walther@59875
   577
case ThmC_Def.int_opt_of_string "(-123)" of
walther@59875
   578
  SOME ~123 => () | _ => raise error "ThmC_Def.int_opt_of_string  (-123)  changed";
walther@59875
   579
case ThmC_Def.int_opt_of_string "#123" of
walther@59875
   580
  NONE => () | _ => raise error "ThmC_Def.int_opt_of_string  #123  changed";
walther@59875
   581
case ThmC_Def.int_opt_of_string "-123" of
walther@59875
   582
  SOME ~123 => () | _ => raise error "ThmC_Def.int_opt_of_string  -123  changed";
wneuper@59403
   583
Walther@60565
   584
val t = TermC.parse_test @{context} "1";
walther@60230
   585
if TermC.is_num t = true then () else error "TermC.is_num   1";
wneuper@59403
   586
Walther@60565
   587
val t = TermC.parse_test @{context} "-1";
walther@60230
   588
if TermC.is_num t = true then () else error "TermC.is_num  -1";
wneuper@59403
   589
Walther@60565
   590
val t = TermC.parse_test @{context} "a123";
walther@60230
   591
if TermC.is_num t = false then () else error "TermC.is_num   a123";
wneuper@59403
   592
walther@60230
   593
"----------- fun TermC.is_f_x ------------------------------------------------------------------------";
walther@60230
   594
"----------- fun TermC.is_f_x ------------------------------------------------------------------------";
walther@60230
   595
"----------- fun TermC.is_f_x ------------------------------------------------------------------------";
Walther@60565
   596
val t = TermC.parse_test @{context} "q_0/2 * L * x";
walther@60230
   597
if TermC.is_f_x t = false then () else error "TermC.is_f_x   q_0/2 * L * x";
wneuper@59403
   598
Walther@60565
   599
val t = TermC.parse_test @{context} "M_b x";
walther@60230
   600
if TermC.is_f_x t = true then () else error "M_b x";
wneuper@59403
   601
wneuper@59392
   602
"----------- fun list2isalist, fun isalist2list ------------------------------------------------";
wneuper@59392
   603
"----------- fun list2isalist, fun isalist2list ------------------------------------------------";
wneuper@59392
   604
"----------- fun list2isalist, fun isalist2list ------------------------------------------------";
Walther@60565
   605
val t = TermC.parse_test @{context} "R=(R::real)";
wneuper@59403
   606
val T = type_of t;
walther@60230
   607
val ss = TermC.list2isalist T [t,t,t];
walther@59868
   608
if UnparseC.term ss = "[R = R, R = R, R = R]" then () else error "list2isalist 1";
wneuper@59392
   609
Walther@60565
   610
val t = TermC.parse_test @{context} "[a=b,c=d,e=f]";
walther@60230
   611
val il = TermC.isalist2list t;
walther@59997
   612
if UnparseC.terms il = "[\"a = b\", \"c = d\", \"e = f\"]" then () else error "isalist2list 2";
wneuper@59392
   613
Walther@60565
   614
val t = TermC.parse_test @{context} "[a=b,c=d,e=f]";
walther@60230
   615
val il = TermC.isalist2list t;
walther@59997
   616
if UnparseC.terms il = "[\"a = b\", \"c = d\", \"e = f\"]" then () else error "isalist2list 3";
wneuper@59392
   617
Walther@60565
   618
val t = TermC.parse_test @{context} "ss___s::bool list";
walther@60230
   619
(TermC.isalist2list t; error "isalist2list 1") handle TERM ("isalist2list applied to NON-list: ", _) =>();
wneuper@59392
   620
walther@60230
   621
"----------- fun TermC.strip_imp_prems', fun TermC.ins_concl -----------------------------------------------";
walther@60230
   622
"----------- fun TermC.strip_imp_prems', fun TermC.ins_concl -----------------------------------------------";
walther@60230
   623
"----------- fun TermC.strip_imp_prems', fun TermC.ins_concl -----------------------------------------------";
wenzelm@60203
   624
val prop = Thm.prop_of @{thm real_mult_div_cancel2};
walther@59868
   625
UnparseC.term prop = "?k \<noteq> 0 \<Longrightarrow> ?m * ?k / (?n * ?k) = ?m / ?n";
wenzelm@60309
   626
val t as Const (\<^const_name>\<open>Pure.imp\<close>, _) $
wenzelm@60309
   627
      (Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>Not\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Var (("k", 0), _) $ Const (\<^const_name>\<open>Groups.zero\<close>, _)))) $
wenzelm@60309
   628
      (Const (\<^const_name>\<open>Trueprop\<close>, _) $
wenzelm@60309
   629
        (Const (\<^const_name>\<open>HOL.eq\<close>, _) $
wenzelm@60309
   630
          (Const (\<^const_name>\<open>divide\<close>, _) $ (Const (\<^const_name>\<open>times\<close>, _) $ Var (("m", 0), _) $ Var (("k", 0), _)) $
wenzelm@60309
   631
            (Const (\<^const_name>\<open>times\<close>, _) $ Var (("n", 0), _) $ Var (("k", 0), _))) $
wenzelm@60309
   632
          (Const (\<^const_name>\<open>divide\<close>, _) $ Var (("m", 0), _) $ Var (("n", 0), _)))) = prop;
walther@60230
   633
val SOME t' = TermC.strip_imp_prems' t;
walther@60230
   634
if  UnparseC.term t' = "(\<Longrightarrow>) (?k \<noteq> 0)" then () else error "TermC.strip_imp_prems' changed";
wneuper@59403
   635
walther@60337
   636
val thm = @{thm frac_sym_conv};
wenzelm@60203
   637
val prop = Thm.prop_of thm;
wneuper@59403
   638
val concl = Logic.strip_imp_concl prop;
walther@60230
   639
val SOME prems = TermC.strip_imp_prems' prop;
walther@60230
   640
val prop' = TermC.ins_concl prems concl;
walther@60230
   641
if prop = prop' then () else error "TermC.ins_concl o strip_imp_concl";
wneuper@59403
   642
wneuper@59392
   643
"----------- fun mk_factroot, fun mk_num_op_num, -----------------------------------------------";
wneuper@59392
   644
"----------- fun mk_factroot, fun mk_num_op_num, -----------------------------------------------";
wneuper@59392
   645
"----------- fun mk_factroot, fun mk_num_op_num, -----------------------------------------------";
Walther@60424
   646
val T =  type_of (TermC.parseNEW' ctxt "12::real");
walther@60230
   647
val t = TermC.mk_factroot "SqRoot.sqrt" T 2 3;
walther@59868
   648
if UnparseC.term t = "2 * ??.SqRoot.sqrt 3" then () else error "mk_factroot";
wneuper@59403
   649
Walther@60565
   650
val t = TermC.parse_test @{context} "aaa + bbb";
wenzelm@60309
   651
val op_ as Const (\<^const_name>\<open>plus\<close>, Top) $ Free ("aaa", T1) $ Free ("bbb", T2) = t;
wenzelm@60309
   652
val t' = TermC.mk_num_op_num T1 T2 (\<^const_name>\<open>plus\<close>, Top) 2 3;
walther@59868
   653
if UnparseC.term t' = "2 + 3" then () else error "mk_num_op_num";
wneuper@59403
   654
walther@60230
   655
"----------- fun TermC.dest_binop_typ ----------------------------------------------------------------";
walther@60230
   656
"----------- fun TermC.dest_binop_typ ----------------------------------------------------------------";
walther@60230
   657
"----------- fun TermC.dest_binop_typ ----------------------------------------------------------------";
Walther@60424
   658
val t = TermC.parseNEW' ctxt "(3::real) ^ 4";
wneuper@59403
   659
val hT = type_of (head_of t);
walther@60340
   660
if (HOLogic.realT, HOLogic.natT, HOLogic.realT) = TermC.dest_binop_typ hT
walther@60230
   661
then () else error "TermC.dest_binop_typ";
wneuper@59403
   662
walther@60230
   663
"----------- fun TermC.is_list -----------------------------------------------------------------------";
walther@60230
   664
"----------- fun TermC.is_list -----------------------------------------------------------------------";
walther@60230
   665
"----------- fun TermC.is_list -----------------------------------------------------------------------";
Walther@60424
   666
val (SOME ct) = TermC.parseNEW ctxt "lll::real list";
Walther@60565
   667
val t = TermC.parse_test @{context} "lll::real list";
Walther@60424
   668
val ty = Term.type_of ct;
walther@60230
   669
if TermC.is_list t = false then () else error "TermC.is_list   lll::real list";
wneuper@59403
   670
Walther@60565
   671
val t = TermC.parse_test @{context} "[a, b, c]";
Walther@60424
   672
val ty = Term.type_of ct;
walther@60230
   673
if TermC.is_list t = true then () else error "TermC.is_list  [a, b, c]";
wneuper@59403
   674
walther@60317
   675
"----------- fun mk_frac, proper term with uminus ----------------------------------------------";
walther@60317
   676
"----------- fun mk_frac, proper term with uminus ----------------------------------------------";
walther@60317
   677
"----------- fun mk_frac, proper term with uminus ----------------------------------------------";
walther@60317
   678
     TermC.mk_frac: typ -> int * (int * int) -> term;
walther@60317
   679
     TermC.mk_frac HOLogic.realT (~1, (6, 8));
walther@60317
   680
"~~~~~ fun mk_frac , args:"; val (T, (sg, (i1, i2))) = (HOLogic.realT, (~1, (6, 8)));
walther@60336
   681
val xxx = (*return value*) Const (\<^const_name>\<open>divide\<close>, T --> T) $
walther@60317
   682
      mk_negative T (HOLogic.mk_number T i1) $ HOLogic.mk_number T i2;
walther@60317
   683
walther@60317
   684
val (T_div, T_uminus) =
walther@60317
   685
case xxx of
walther@60336
   686
  Const (\<^const_name>\<open>divide\<close>, T_div) $                                  (* divide *)
walther@60336
   687
    (Const (\<^const_name>\<open>uminus\<close>, T_uminus) $                           (* uminus *)
walther@60336
   688
      (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ _ ))) $
walther@60336
   689
    (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ _ )) 
walther@60317
   690
    => (T_div, T_uminus)
walther@60317
   691
| _ => error "mk_frac 6 / - 8 \<longrightarrow> - 3 / 4 CHANGED";
walther@60317
   692
walther@60317
   693
case T_div of
walther@60373
   694
  Type (\<^type_name>\<open>fun\<close>, [Type (\<^type_name>\<open>real\<close>, []), Type (\<^type_name>\<open>real\<close>, [])]) => ()
walther@60317
   695
| _ => error "T_div CHANGED in fun mk_frac";
walther@60317
   696
case T_uminus of
walther@60373
   697
  Type (\<^type_name>\<open>fun\<close>, [Type (\<^type_name>\<open>real\<close>, []), Type (\<^type_name>\<open>real\<close>, [])]) => ()
walther@60317
   698
| _ => error "T_uminus CHANGED in fun mk_frac";
walther@60317
   699
walther@60317
   700
(* IMproper term for "6 / - 8 = - 3 / (4::real)"
walther@60317
   701
walther@60336
   702
  (Const (\<^const_name>\<open>uminus\<close>, _) $                                    (* uminus *)
walther@60336
   703
    (Const (\<^const_name>\<open>divide\<close>, _) $                                   (* divide *)
walther@60336
   704
      (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ _ ))) $
walther@60336
   705
      (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ _ ) ))))
walther@60317
   706
*)