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 --------------------------------";
|
wneuper@59394
|
14 |
"----------- fun parse, fun parse_patt, fun T_a2real -------------------------------------------";
|
wneuper@59533
|
15 |
"----------- fun vars_of -----------------------------------------------------------------------";
|
neuper@38025
|
16 |
"----------- uminus_to_string ---------------------------";
|
neuper@38037
|
17 |
"----------- *** prep_pbt: syntax error in '#Where' of [v";
|
neuper@38051
|
18 |
"----------- check writeln, tracing for string markup ---";
|
wneuper@59403
|
19 |
"----------- build fun is_bdv_subst ------------------------------------------------------------";
|
wneuper@59403
|
20 |
"----------- fun str_of_int --------------------------------------------------------------------";
|
wneuper@59403
|
21 |
"----------- fun scala_of_term -----------------------------------------------------------------";
|
wneuper@59403
|
22 |
"----------- fun contains_Var ------------------------------------------------------------------";
|
wneuper@59403
|
23 |
"----------- fun int_of_str_opt, fun is_num ----------------------------------------------------";
|
wneuper@59403
|
24 |
"----------- fun is_f_x ------------------------------------------------------------------------";
|
wneuper@59403
|
25 |
"----------- fun list2isalist, fun isalist2list ------------------------------------------------";
|
wneuper@59403
|
26 |
"----------- fun strip_imp_prems' --------------------------------------------------------------";
|
wneuper@59403
|
27 |
"----------- fun ins_concl ---------------------------------------------------------------------";
|
wneuper@59403
|
28 |
"----------- fun mk_factroot, fun mk_num_op_num, -----------------------------------------------";
|
wneuper@59403
|
29 |
"----------- fun dest_binop_typ ----------------------------------------------------------------";
|
wneuper@59403
|
30 |
"----------- fun 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"};
|
neuper@48886
|
41 |
(*Const ("Groups.zero_class.zero", "Nat.nat")*)
|
neuper@48886
|
42 |
@{term "1::nat"};
|
neuper@48886
|
43 |
(*Const ("Groups.one_class.one", "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"};
|
neuper@48886
|
51 |
(*Const ("Groups.zero_class.zero", "Int.int")*)
|
neuper@48886
|
52 |
@{term "1::int"};
|
neuper@48886
|
53 |
(*Const ("Groups.one_class.one", "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"};
|
neuper@48886
|
65 |
(*Const ("Groups.uminus_class.uminus", "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"};
|
neuper@55279
|
72 |
(*Const ("Groups.zero_class.zero", "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"};
|
neuper@55279
|
86 |
(*Const ("Groups.uminus_class.uminus", "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"};
|
neuper@48886
|
93 |
(*Const ("Groups.zero_class.zero", "nat")*)
|
neuper@48886
|
94 |
@{term "1::nat"};
|
neuper@48886
|
95 |
(*Const ("Groups.one_class.one", "nat")*)
|
neuper@48886
|
96 |
@{term "5::nat"};
|
neuper@48886
|
97 |
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> nat") $
|
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 |
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
|
neuper@48886
|
101 |
@{term "0::int"};
|
neuper@48886
|
102 |
(*Const ("Groups.zero_class.zero", "int")*)
|
neuper@48886
|
103 |
@{term "1::int"};
|
neuper@48886
|
104 |
(*Const ("Groups.one_class.one", "int")*)
|
neuper@48886
|
105 |
@{term "5::int"};
|
neuper@48886
|
106 |
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> int") $
|
neuper@48886
|
107 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
108 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
|
neuper@48886
|
109 |
@{term "-5::int"};
|
neuper@48886
|
110 |
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> int") $
|
neuper@48886
|
111 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
112 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
|
neuper@48886
|
113 |
@{term "- 5::int"};
|
neuper@48886
|
114 |
(*Const ("Groups.uminus_class.uminus", "int \<Rightarrow> int") $
|
neuper@48886
|
115 |
(Const ("Num.numeral_class.numeral", "num \<Rightarrow> int") $
|
neuper@48886
|
116 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
117 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("...", "num"))))*)
|
neuper@48886
|
118 |
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
|
neuper@48886
|
119 |
@{term "0::real"};
|
neuper@48886
|
120 |
(*Const ("Groups.zero_class.zero", "real")*)
|
neuper@48886
|
121 |
@{term "1::real"};
|
neuper@48886
|
122 |
(*Const ("Groups.one_class.one", "real")*)
|
neuper@48886
|
123 |
@{term "5::real"};
|
neuper@48886
|
124 |
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> real") $
|
neuper@48886
|
125 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
126 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
|
neuper@48886
|
127 |
@{term "-5::real"};
|
neuper@48886
|
128 |
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> real") $
|
neuper@48886
|
129 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
130 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
|
neuper@48886
|
131 |
@{term "- 5::real"};
|
neuper@48886
|
132 |
(*Const ("Groups.uminus_class.uminus", "real \<Rightarrow> real") $
|
neuper@48886
|
133 |
(Const ("Num.numeral_class.numeral", "num \<Rightarrow> real") $
|
neuper@48886
|
134 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
135 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("...", "num"))))*)
|
neuper@48886
|
136 |
"***Isabelle2013**********************************************************************************";
|
neuper@48886
|
137 |
@{term "0::nat"};
|
neuper@48886
|
138 |
(*Const ("Groups.zero_class.zero", "nat")*)
|
neuper@48886
|
139 |
@{term "1::nat"};
|
neuper@48886
|
140 |
(*Const ("Groups.one_class.one", "nat")*)
|
neuper@48886
|
141 |
@{term "5::nat"};
|
neuper@48886
|
142 |
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> nat") $
|
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 |
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
|
neuper@48886
|
146 |
@{term "0::int"};
|
neuper@48886
|
147 |
(*Const ("Groups.zero_class.zero", "int")*)
|
neuper@48886
|
148 |
@{term "1::int"};
|
neuper@48886
|
149 |
(*Const ("Groups.one_class.one", "int")*)
|
neuper@48886
|
150 |
@{term "5::int"};
|
neuper@48886
|
151 |
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> int") $
|
neuper@48886
|
152 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
153 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
|
neuper@48886
|
154 |
@{term "-5::int"};
|
neuper@48886
|
155 |
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> int") $
|
neuper@48886
|
156 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
157 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
|
neuper@48886
|
158 |
@{term "- 5::int"};
|
neuper@48886
|
159 |
(*Const ("Groups.uminus_class.uminus", "int \<Rightarrow> int") $
|
neuper@48886
|
160 |
(Const ("Num.numeral_class.numeral", "num \<Rightarrow> int") $
|
neuper@48886
|
161 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
162 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("...", "num"))))*)
|
neuper@48886
|
163 |
(*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*)
|
neuper@48886
|
164 |
@{term "0::real"};
|
neuper@48886
|
165 |
(*Const ("Groups.zero_class.zero", "real")*)
|
neuper@48886
|
166 |
@{term "1::real"};
|
neuper@48886
|
167 |
(*Const ("Groups.one_class.one", "real")*)
|
neuper@48886
|
168 |
@{term "5::real"};
|
neuper@48886
|
169 |
(*Const ("Num.numeral_class.numeral", "num \<Rightarrow> real") $
|
neuper@48886
|
170 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
171 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
|
neuper@48886
|
172 |
@{term "-5::real"};
|
neuper@48886
|
173 |
(*Const ("Num.neg_numeral_class.neg_numeral", "num \<Rightarrow> real") $
|
neuper@48886
|
174 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
175 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("Num.num.One", "num")))*)
|
neuper@48886
|
176 |
@{term "- 5::real"};
|
neuper@48886
|
177 |
(*Const ("Groups.uminus_class.uminus", "real \<Rightarrow> real") $
|
neuper@48886
|
178 |
(Const ("Num.numeral_class.numeral", "num \<Rightarrow> real") $
|
neuper@48886
|
179 |
(Const ("Num.num.Bit1", "num \<Rightarrow> num") $
|
neuper@48886
|
180 |
(Const ("Num.num.Bit0", "num \<Rightarrow> num") $ Const ("...", "num"))))*)
|
neuper@38025
|
181 |
|
neuper@38025
|
182 |
"----------- inst_bdv -----------------------------------";
|
neuper@38025
|
183 |
"----------- inst_bdv -----------------------------------";
|
neuper@38025
|
184 |
"----------- inst_bdv -----------------------------------";
|
wneuper@59188
|
185 |
if (term2str o Thm.prop_of o num_str) @{thm d1_isolate_add2} =
|
wneuper@59357
|
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";
|
akargl@42145
|
189 |
val subst = [(str2term "bdv", str2term "x")];
|
wneuper@59188
|
190 |
val t = (norm o #prop o Thm.rep_thm) (num_str @{thm d1_isolate_add2});
|
akargl@42145
|
191 |
val t' = inst_bdv subst t;
|
wneuper@59357
|
192 |
if term2str 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";
|
wneuper@59188
|
195 |
if (term2str o Thm.prop_of o num_str) @{thm separate_bdvs_add} =
|
wneuper@59357
|
196 |
"[] from [?bdv_1.0, ?bdv_2.0, ?bdv_3.0,\n "
|
wneuper@59357
|
197 |
^ "?bdv_4.0] occur_exactly_in ?a \<Longrightarrow>\n(?a + ?b = ?c) = (?b = ?c + -1 * ?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 =
|
neuper@42177
|
202 |
[(str2term "bdv_1", str2term "c"),
|
neuper@42177
|
203 |
(str2term "bdv_2", str2term "c_2"),
|
neuper@42177
|
204 |
(str2term "bdv_3", str2term "c_3"),
|
neuper@42177
|
205 |
(str2term "bdv_4", str2term "c_4")];
|
wneuper@59188
|
206 |
val t = (norm o #prop o Thm.rep_thm) (num_str @{thm separate_bdvs_add});
|
neuper@42177
|
207 |
val t' = inst_bdv subst t;
|
neuper@42172
|
208 |
|
wneuper@59357
|
209 |
if term2str t' = "[] from [c, c_2, c_3, c_4] occur_exactly_in ?a \<Longrightarrow>\n"
|
wneuper@59357
|
210 |
^ "(?a + ?b = ?c) = (?b = ?c + -1 * ?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 ---------------------------";
|
neuper@42179
|
216 |
val t = str2term "(tl vs_vs) from vs_vs occur_exactly_in (NTH 1 (es_es::bool list))";
|
akargl@42145
|
217 |
val env = [(str2term "vs_vs::real list", str2term "[c, c_2]"),
|
akargl@42145
|
218 |
(str2term "es_es::bool list", str2term "[c_2 = 0, c + c_2 = 1]")];
|
akargl@42145
|
219 |
val (all_Free_subst, t') = subst_atomic_all env t;
|
neuper@38025
|
220 |
|
akargl@42145
|
221 |
if all_Free_subst andalso
|
neuper@42179
|
222 |
term2str 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 |
|
akargl@42145
|
226 |
val (all_Free_subst, t') = subst_atomic_all (tl env) t;
|
akargl@42145
|
227 |
if not all_Free_subst andalso
|
neuper@42179
|
228 |
term2str t' = "tl vs_vs from vs_vs occur_exactly_in NTH 1 [c_2 = 0, c + c_2 = 1]" then ()
|
akargl@42145
|
229 |
else error "termC.sml subst_atomic_all should be 'false'";
|
neuper@38025
|
230 |
|
neuper@38025
|
231 |
"----------- Pattern.match ------------------------------";
|
neuper@38025
|
232 |
"----------- Pattern.match ------------------------------";
|
neuper@38025
|
233 |
"----------- Pattern.match ------------------------------";
|
wneuper@59188
|
234 |
val t = (Thm.term_of o the o (parse thy)) "3 * x^^^2 = (1::real)";
|
wneuper@59188
|
235 |
val pat = (free2var o Thm.term_of o the o (parse thy)) "a * b^^^2 = (c::real)";
|
neuper@42179
|
236 |
(* !^^^^^^^^!... necessary for Pattern.match, see Logic.varify_global below*)
|
neuper@42179
|
237 |
val insts = Pattern.match @{theory "Isac"} (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...";
|
neuper@42179
|
246 |
(* val t = str2term "x";
|
neuper@42179
|
247 |
(Pattern.match @{theory "Isac"} (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 |
|
neuper@38025
|
258 |
"----------- fun matches --------------------------------";
|
neuper@38025
|
259 |
"----------- fun matches --------------------------------";
|
neuper@38025
|
260 |
"----------- fun matches --------------------------------";
|
neuper@42179
|
261 |
(*examples see
|
neuper@42179
|
262 |
test/../Knowledge/polyeq.sml:
|
akargl@42145
|
263 |
Where=[Correct "matches (?a = 0) (-8 - 2 * x + x ^^^ 2 = 0)"*)
|
akargl@42145
|
264 |
(*test/../Interpret/ptyps.sml:
|
akargl@42145
|
265 |
|\nmatches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #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)"}; (*<<<<<<<---------------*)
|
akargl@42145
|
270 |
tracing "paIsa=..."; 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)"}; (*<<<<<<<---------------*)
|
akargl@42145
|
278 |
if matches thy tm pa then ()
|
akargl@42145
|
279 |
else error "termC.sml diff.behav. in matches true 1";
|
neuper@38025
|
280 |
"----- test 1b false";
|
akargl@42145
|
281 |
val tm = @{term "-8 - 2 * x + x ^ 2 = (3::real)"}; (*<<<<<<<---------------*)
|
akargl@42145
|
282 |
if matches thy tm pa then error "termC.sml diff.behav. in matches false 1"
|
neuper@38025
|
283 |
else ();
|
neuper@38025
|
284 |
|
neuper@38025
|
285 |
"----- test 2: Nok";
|
akargl@42145
|
286 |
val pa = Logic.varify_global (str2term "a = (0::real)");(*<<<<<<<-------------*)
|
akargl@42145
|
287 |
tracing "paLo2=..."; 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";
|
akargl@42145
|
294 |
val tm = str2term "-8 - 2 * x + x ^ 2 = (0::real)"; (*<<<<<<<-------------*)
|
akargl@42145
|
295 |
if matches thy tm pa then ()
|
akargl@42145
|
296 |
else error "termC.sml diff.behav. in matches true 2";
|
neuper@38025
|
297 |
"----- test 2b false";
|
akargl@42145
|
298 |
val tm = str2term "-8 - 2 * x + x ^ 2 = (3::real)"; (*<<<<<<<-------------*)
|
akargl@42145
|
299 |
if matches thy tm pa then ()
|
akargl@42145
|
300 |
else error "termC.sml diff.behav. in matches false 2";
|
neuper@38025
|
301 |
(* i.e. !!!!!!!!!!!!!!!!! THIS KIND OF PATTERN IS NOT RELIABLE !!!!!!!!!!!!!!!!!
|
neuper@38025
|
302 |
if matches thy tm pa then error "termC.sml diff.behav. in matches false 2"
|
neuper@38025
|
303 |
else ();*)
|
neuper@38025
|
304 |
|
neuper@38025
|
305 |
"----- test 3: OK";
|
akargl@42145
|
306 |
val pa = free2var (str2term "a = (0::real)");(*<<<<<<<-------------*)
|
akargl@42145
|
307 |
tracing "paF2=..."; 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";
|
akargl@42145
|
314 |
val tm = str2term "-8 - 2 * x + x ^ 2 = (0::real)"; (*<<<<<<<-------------*)
|
akargl@42145
|
315 |
if matches thy tm pa then ()
|
akargl@42145
|
316 |
else error "termC.sml diff.behav. in matches true 3";
|
neuper@38025
|
317 |
"----- test 3b false";
|
akargl@42145
|
318 |
val tm = str2term "-8 - 2 * x + x ^ 2 = (3::real)"; (*<<<<<<<-------------*)
|
akargl@42145
|
319 |
if matches thy tm pa then error "termC.sml diff.behav. in matches false 3"
|
akargl@42145
|
320 |
else ();
|
neuper@38025
|
321 |
|
neuper@38025
|
322 |
"----- test 4=3 with specific data";
|
akargl@42145
|
323 |
val pa = free2var (str2term "M_b 0");
|
neuper@38025
|
324 |
"----- test 4a true";
|
akargl@42145
|
325 |
val tm = str2term "M_b 0";
|
akargl@42145
|
326 |
if matches thy tm pa then ()
|
akargl@42145
|
327 |
else error "termC.sml diff.behav. in matches true 4";
|
neuper@38025
|
328 |
"----- test 4b false";
|
akargl@42145
|
329 |
val tm = str2term "M_b x";
|
akargl@42145
|
330 |
if matches thy tm pa then error "termC.sml diff.behav. in matches false 4"
|
akargl@42145
|
331 |
else ();
|
neuper@38025
|
332 |
|
wneuper@59392
|
333 |
"----------- fun matches, repair 'Handler catches all exceptions' ------------------------------";
|
wneuper@59392
|
334 |
"----------- fun matches, repair 'Handler catches all exceptions' ------------------------------";
|
wneuper@59392
|
335 |
"----------- fun matches, repair 'Handler catches all exceptions' ------------------------------";
|
wneuper@59392
|
336 |
|
wneuper@59392
|
337 |
|
wneuper@59392
|
338 |
|
neuper@38025
|
339 |
|
wneuper@59394
|
340 |
"----------- fun parse, fun parse_patt, fun T_a2real -------------------------------------------";
|
wneuper@59394
|
341 |
"----------- fun parse, fun parse_patt, fun T_a2real -------------------------------------------";
|
wneuper@59394
|
342 |
"----------- fun parse, fun parse_patt, fun T_a2real -------------------------------------------";
|
wneuper@59394
|
343 |
(* added after Isabelle2015->17
|
wneuper@59394
|
344 |
> val (SOME ct) = parse thy "(-#5)^^^#3";
|
wneuper@59394
|
345 |
> atomty (Thm.term_of ct);
|
wneuper@59394
|
346 |
*** -------------
|
wneuper@59394
|
347 |
*** Const ( Nat.op ^, ['a, nat] => 'a)
|
wneuper@59394
|
348 |
*** Const ( uminus, 'a => 'a)
|
wneuper@59394
|
349 |
*** Free ( #5, 'a)
|
wneuper@59394
|
350 |
*** Free ( #3, nat)
|
wneuper@59394
|
351 |
> val (SOME ct) = parse thy "R=R";
|
wneuper@59394
|
352 |
> atomty (Thm.term_of ct);
|
wneuper@59394
|
353 |
*** -------------
|
wneuper@59394
|
354 |
*** Const ( op =, [real, real] => bool)
|
wneuper@59394
|
355 |
*** Free ( R, real)
|
wneuper@59394
|
356 |
*** Free ( R, real)
|
wneuper@59394
|
357 |
|
wneuper@59394
|
358 |
THIS IS THE OUTPUT FOR VERSION (3) above at typ_a2real !!!!!
|
wneuper@59394
|
359 |
*** -------------
|
wneuper@59394
|
360 |
*** Const ( op =, [RealDef.real, RealDef.real] => bool)
|
wneuper@59394
|
361 |
*** Free ( R, RealDef.real)
|
wneuper@59394
|
362 |
*** Free ( R, RealDef.real) *)
|
akargl@42145
|
363 |
val thy = @{theory "Complex_Main"};
|
akargl@42145
|
364 |
val str = "x + z";
|
akargl@42145
|
365 |
parse thy str;
|
neuper@38025
|
366 |
"---------------";
|
akargl@42145
|
367 |
val str = "x + 2*z";
|
akargl@42145
|
368 |
val t = (Syntax.read_term_global thy str);
|
akargl@42145
|
369 |
val t = numbers_to_string (Syntax.read_term_global thy str);
|
akargl@42145
|
370 |
val t = (typ_a2real o numbers_to_string) (Syntax.read_term_global thy str);
|
wneuper@59188
|
371 |
Thm.global_cterm_of thy t;
|
akargl@42145
|
372 |
val t = (the (parse thy str)) handle _ => error "termC.sml parsing 'x + 2*z' failed";
|
neuper@38025
|
373 |
|
neuper@38037
|
374 |
"===== fun parse_patt caused error in fun T_a2real ===";
|
akargl@42145
|
375 |
val thy = @{theory "Poly"};
|
akargl@42145
|
376 |
parse_patt thy "?p is_addUnordered";
|
akargl@42145
|
377 |
parse_patt thy "?p :: real";
|
neuper@38025
|
378 |
|
neuper@42179
|
379 |
val str = "x + z";
|
neuper@42179
|
380 |
parse thy str;
|
neuper@42179
|
381 |
"---------------";
|
neuper@42179
|
382 |
val str = "x + 2*z";
|
neuper@42179
|
383 |
val t = (Syntax.read_term_global thy str);
|
neuper@42179
|
384 |
val t = numbers_to_string (Syntax.read_term_global thy str);
|
neuper@42179
|
385 |
val t = (typ_a2real o numbers_to_string) (Syntax.read_term_global thy str);
|
wneuper@59188
|
386 |
Thm.global_cterm_of thy t;
|
neuper@42179
|
387 |
val t = (the (parse thy str)) handle _ => error "termC.sml parsing 'x + 2*z' failed";
|
neuper@42179
|
388 |
|
neuper@42179
|
389 |
"===== fun parse_patt caused error in fun T_a2real ===";
|
neuper@42179
|
390 |
val thy = @{theory "Poly"};
|
neuper@42179
|
391 |
parse_patt thy "?p is_addUnordered";
|
neuper@42179
|
392 |
parse_patt thy "?p :: real";
|
neuper@38051
|
393 |
|
neuper@42201
|
394 |
(* Christian Urban, 101001
|
neuper@42201
|
395 |
theory Test
|
neuper@42201
|
396 |
imports Main Complex
|
neuper@42201
|
397 |
begin
|
neuper@42201
|
398 |
|
neuper@42201
|
399 |
let
|
neuper@42201
|
400 |
val parser = Args.context -- Scan.lift Args.name_source
|
neuper@48761
|
401 |
fun term_pat (ctxt, str) = str |> Proof_Context.read_term_pattern ctxt
|
neuper@42201
|
402 |
|> ML_Syntax.print_term |> ML_Syntax.atomic
|
neuper@42201
|
403 |
in
|
neuper@42201
|
404 |
ML_Antiquote.inline "term_pat" (parser >> term_pat)
|
neuper@42201
|
405 |
end
|
neuper@42201
|
406 |
|
neuper@42201
|
407 |
val t = @{term "a + b * x = (0 ::real)"};
|
neuper@42201
|
408 |
val pat = @{term_pat "?l = (?r ::real)"};
|
neuper@42201
|
409 |
val precond = @{term_pat "is_polynomial (?l::real)"};
|
neuper@42201
|
410 |
val inst = Pattern.match @{theory} (pat, t) (Vartab.empty, Vartab.empty);
|
neuper@42201
|
411 |
|
neuper@42201
|
412 |
Envir.subst_term inst precond
|
neuper@42201
|
413 |
|> Syntax.string_of_term @{context}
|
neuper@42201
|
414 |
|> writeln
|
wneuper@59533
|
415 |
end *)
|
neuper@42201
|
416 |
|
wneuper@59533
|
417 |
"----------- fun vars_of -----------------------------------------------------------------------";
|
wneuper@59533
|
418 |
"----------- fun vars_of -----------------------------------------------------------------------";
|
wneuper@59533
|
419 |
"----------- fun vars_of -----------------------------------------------------------------------";
|
wneuper@59533
|
420 |
val thy = @{theory Partial_Fractions};
|
wneuper@59533
|
421 |
val ctxt = Proof_Context.init_global @{theory}
|
neuper@42201
|
422 |
|
wneuper@59533
|
423 |
val SOME t = TermC.parseNEW ctxt "x ^^^ 2 + -1 * x * y";
|
wneuper@59533
|
424 |
case vars_of t of [Free ("x", _), Free ("y", _)] => ()
|
wneuper@59533
|
425 |
| _ => error "vars_of (x ^^^ 2 + -1 * x * y) ..changed";
|
wneuper@59533
|
426 |
|
wneuper@59533
|
427 |
val SOME t = TermC.parseNEW ctxt "3 = 3 * AA / 4";
|
wneuper@59533
|
428 |
|
wneuper@59533
|
429 |
case vars_of t of [Const ("Partial_Fractions.AA", _), Const ("HOL.eq", _)] => ()
|
wneuper@59533
|
430 |
| _ => error "vars_of (3 = 3 * AA / 4) ..changed (! use only for polynomials, not equations!)";
|
wneuper@59533
|
431 |
|
neuper@42201
|
432 |
|
neuper@38025
|
433 |
"----------- uminus_to_string ---------------------------";
|
neuper@38025
|
434 |
"----------- uminus_to_string ---------------------------";
|
neuper@38025
|
435 |
"----------- uminus_to_string ---------------------------";
|
akargl@42145
|
436 |
val t1 = numbers_to_string @{term "-2::real"};
|
akargl@42145
|
437 |
val t2 = numbers_to_string @{term "- 2::real"};
|
akargl@42145
|
438 |
if uminus_to_string t2 = t1
|
akargl@42145
|
439 |
then ()
|
akargl@42145
|
440 |
else error "termC.sml diff.behav. in uminus_to_string";
|
neuper@38025
|
441 |
|
neuper@38037
|
442 |
"----------- *** prep_pbt: syntax error in '#Where' of [v";
|
neuper@38037
|
443 |
"----------- *** prep_pbt: syntax error in '#Where' of [v";
|
neuper@38037
|
444 |
"----------- *** prep_pbt: syntax error in '#Where' of [v";
|
neuper@38037
|
445 |
"===== deconstruct datatype typ ===";
|
akargl@42145
|
446 |
val str = "?a";
|
akargl@42145
|
447 |
val t = (thy, str) |>> thy2ctxt
|
neuper@48761
|
448 |
|-> Proof_Context.read_term_pattern
|
akargl@42145
|
449 |
|> numbers_to_string;
|
akargl@42145
|
450 |
val Var (("a", 0), ty) = t;
|
akargl@42145
|
451 |
val TVar ((str, i), srt) = ty;
|
akargl@42145
|
452 |
if str = "'a" andalso i = 1 andalso srt = []
|
akargl@42145
|
453 |
then ()
|
akargl@42145
|
454 |
else error "termC.sml type-structure of \"?a\" changed";
|
neuper@38025
|
455 |
|
neuper@38037
|
456 |
"----- real type in pattern ---";
|
akargl@42145
|
457 |
val str = "?a :: real";
|
akargl@42145
|
458 |
val t = (thy, str) |>> thy2ctxt
|
neuper@48761
|
459 |
|-> Proof_Context.read_term_pattern
|
akargl@42145
|
460 |
|> numbers_to_string;
|
akargl@42145
|
461 |
val Var (("a", 0), ty) = t;
|
akargl@42145
|
462 |
val Type (str, tys) = ty;
|
neuper@55279
|
463 |
if str = "Real.real" andalso tys = [] andalso ty = HOLogic.realT
|
akargl@42145
|
464 |
then ()
|
akargl@42145
|
465 |
else error "termC.sml type-structure of \"?a :: real\" changed";
|
neuper@38037
|
466 |
|
neuper@38037
|
467 |
"===== Not (matchsub (?a + (?b + ?c)) t_t |... ===";
|
neuper@42179
|
468 |
val (thy, str) = (thy, "Not (matchsub (?a + (?b + ?c)) t_t | " ^
|
akargl@42145
|
469 |
" matchsub (?a + (?b - ?c)) t_t | " ^
|
akargl@42145
|
470 |
" matchsub (?a - (?b + ?c)) t_t | " ^
|
akargl@42145
|
471 |
" matchsub (?a + (?b - ?c)) t_t )");
|
neuper@48761
|
472 |
val ctxt = Proof_Context.init_global thy;
|
neuper@42179
|
473 |
val ctxt = Config.put show_types true ctxt;
|
neuper@38037
|
474 |
"----- read_term_pattern ---";
|
neuper@42179
|
475 |
val t = (thy, str) |>> thy2ctxt
|
neuper@48761
|
476 |
|-> Proof_Context.read_term_pattern
|
akargl@42145
|
477 |
|> numbers_to_string;
|
neuper@42179
|
478 |
val t_real = typ_a2real t;
|
neuper@52070
|
479 |
if term_to_string' ctxt t_real =
|
wneuper@59357
|
480 |
"\<not> (matchsub ((?a::real) + ((?b::real) + (?c::real))) (t_t::real) \<or>\n "
|
wneuper@59357
|
481 |
^ "matchsub (?a + (?b - ?c)) t_t \<or>\n "
|
wneuper@59357
|
482 |
^ "matchsub (?a - (?b + ?c)) t_t \<or> matchsub (?a + (?b - ?c)) t_t)" then ()
|
wneuper@59357
|
483 |
else error "matchsub";
|
neuper@38051
|
484 |
|
neuper@38051
|
485 |
"----------- check writeln, tracing for string markup ---";
|
neuper@38051
|
486 |
"----------- check writeln, tracing for string markup ---";
|
neuper@38051
|
487 |
"----------- check writeln, tracing for string markup ---";
|
akargl@42145
|
488 |
val t = @{term "x + 1"};
|
akargl@42145
|
489 |
val str_markup = (Syntax.string_of_term
|
wneuper@59357
|
490 |
(Proof_Context.init_global (Thy_Info_get_theory "Isac"))) t;
|
neuper@52070
|
491 |
val str = term_to_string'' "Isac" t;
|
neuper@38051
|
492 |
|
akargl@42145
|
493 |
writeln "----------------writeln str_markup---";
|
akargl@42145
|
494 |
writeln str_markup;
|
akargl@42145
|
495 |
writeln "----------------writeln str---";
|
akargl@42145
|
496 |
writeln str;
|
akargl@42145
|
497 |
writeln "----------------SAME output: no markup----";
|
neuper@38051
|
498 |
|
akargl@42145
|
499 |
writeln "----------------writeln PolyML.makestring str_markup---";
|
wneuper@59348
|
500 |
writeln (@{make_string} str_markup);
|
akargl@42145
|
501 |
writeln "----------------writeln PolyML.makestring str---";
|
wneuper@59348
|
502 |
writeln (@{make_string} str);
|
akargl@42145
|
503 |
writeln "----------------DIFFERENT output----";
|
neuper@38051
|
504 |
|
akargl@42145
|
505 |
tracing "----------------tracing str_markup---";
|
akargl@42145
|
506 |
tracing str_markup;
|
akargl@42145
|
507 |
tracing "----------------tracing str---";
|
akargl@42145
|
508 |
tracing str;
|
akargl@42145
|
509 |
tracing "----------------SAME output: no markup----";
|
neuper@38051
|
510 |
|
akargl@42145
|
511 |
tracing "----------------writeln PolyML.makestring str_markup---";
|
wneuper@59348
|
512 |
tracing (@{make_string} str_markup);
|
akargl@42145
|
513 |
tracing "----------------writeln PolyML.makestring str---";
|
wneuper@59348
|
514 |
tracing (@{make_string} str);
|
akargl@42145
|
515 |
tracing "----------------DIFFERENT output----";
|
neuper@38051
|
516 |
(*
|
neuper@42451
|
517 |
redirect_tracing "../../tmp/";
|
akargl@42145
|
518 |
tracing "----------------writeln str_markup---";
|
akargl@42145
|
519 |
tracing str_markup;
|
akargl@42145
|
520 |
tracing "----------------writeln str---";
|
akargl@42145
|
521 |
tracing str;
|
akargl@42145
|
522 |
tracing "----------------DIFFERENT output----";
|
neuper@38051
|
523 |
*)
|
neuper@38051
|
524 |
|
neuper@41924
|
525 |
"----------- check writeln, tracing for string markup ---";
|
akargl@42145
|
526 |
val t = @{term "x + 1"};
|
akargl@42145
|
527 |
val str_markup = (Syntax.string_of_term
|
wneuper@59357
|
528 |
(Proof_Context.init_global (Thy_Info_get_theory "Isac"))) t;
|
neuper@52070
|
529 |
val str = term_to_string'' "Isac" t;
|
neuper@41924
|
530 |
|
akargl@42145
|
531 |
writeln "----------------writeln str_markup---";
|
akargl@42145
|
532 |
writeln str_markup;
|
akargl@42145
|
533 |
writeln "----------------writeln str---";
|
akargl@42145
|
534 |
writeln str;
|
akargl@42145
|
535 |
writeln "----------------SAME output: no markup----";
|
neuper@41924
|
536 |
|
akargl@42145
|
537 |
writeln "----------------writeln PolyML.makestring str_markup---";
|
wneuper@59348
|
538 |
writeln (@{make_string} str_markup);
|
akargl@42145
|
539 |
writeln "----------------writeln PolyML.makestring str---";
|
wneuper@59348
|
540 |
writeln (@{make_string} str);
|
akargl@42145
|
541 |
writeln "----------------DIFFERENT output----";
|
neuper@41924
|
542 |
|
akargl@42145
|
543 |
tracing "----------------tracing str_markup---";
|
akargl@42145
|
544 |
tracing str_markup;
|
akargl@42145
|
545 |
tracing "----------------tracing str---";
|
akargl@42145
|
546 |
tracing str;
|
akargl@42145
|
547 |
tracing "----------------SAME output: no markup----";
|
neuper@41924
|
548 |
|
akargl@42145
|
549 |
tracing "----------------writeln PolyML.makestring str_markup---";
|
wneuper@59348
|
550 |
tracing (@{make_string} str_markup);
|
akargl@42145
|
551 |
tracing "----------------writeln PolyML.makestring str---";
|
wneuper@59348
|
552 |
tracing (@{make_string} str);
|
akargl@42145
|
553 |
tracing "----------------DIFFERENT output----";
|
neuper@41924
|
554 |
(*
|
neuper@42451
|
555 |
redirect_tracing "../../tmp/";
|
akargl@42145
|
556 |
tracing "----------------writeln str_markup---";
|
akargl@42145
|
557 |
tracing str_markup;
|
akargl@42145
|
558 |
tracing "----------------writeln str---";
|
akargl@42145
|
559 |
tracing str;
|
akargl@42145
|
560 |
tracing "----------------DIFFERENT output----";
|
neuper@41924
|
561 |
*)
|
neuper@42426
|
562 |
|
wneuper@59494
|
563 |
"----------- fun is_bdv_subst ------------------------------------------------------------------";
|
wneuper@59494
|
564 |
"----------- fun is_bdv_subst ------------------------------------------------------------------";
|
wneuper@59494
|
565 |
"----------- fun is_bdv_subst ------------------------------------------------------------------";
|
wneuper@59494
|
566 |
if is_bdv_subst (str2term "[(''bdv'', v_v)]") then ()
|
neuper@42426
|
567 |
else error "is_bdv_subst canged 1";
|
neuper@42426
|
568 |
|
wneuper@59494
|
569 |
if is_bdv_subst (str2term "[(''bdv_1'', v_s1),(''bdv_2'', v_s2)]") then ()
|
neuper@42426
|
570 |
else error "is_bdv_subst canged 2";
|
neuper@42426
|
571 |
|
wneuper@59403
|
572 |
"----------- fun str_of_int --------------------------------------------------------------------";
|
wneuper@59403
|
573 |
"----------- fun str_of_int --------------------------------------------------------------------";
|
wneuper@59403
|
574 |
"----------- fun str_of_int --------------------------------------------------------------------";
|
wneuper@59403
|
575 |
if str_of_int 1 = "1" then () else error "str_of_int 1";
|
wneuper@59403
|
576 |
if str_of_int ~1 = "-1" then () else error "str_of_int -1";
|
wneuper@59392
|
577 |
|
wneuper@59403
|
578 |
"----------- fun scala_of_term -----------------------------------------------------------------";
|
wneuper@59403
|
579 |
"----------- fun scala_of_term -----------------------------------------------------------------";
|
wneuper@59403
|
580 |
"----------- fun scala_of_term -----------------------------------------------------------------";
|
wneuper@59403
|
581 |
val t = @{term "aaa::real"};
|
wneuper@59403
|
582 |
if scala_of_term t = "Free(\"aaa\", Type(\"Real.real\", List()))"
|
wneuper@59403
|
583 |
then () else error "scala_of_term aaa::real";
|
wneuper@59392
|
584 |
|
wneuper@59403
|
585 |
val t = @{term "aaa + bbb"};
|
wneuper@59403
|
586 |
if 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\"))))"
|
wneuper@59403
|
587 |
then () else error "scala_of_term aaa + bbb";
|
wneuper@59403
|
588 |
|
wneuper@59392
|
589 |
"----------- fun contains_Var ------------------------------------------------------------------";
|
wneuper@59392
|
590 |
"----------- fun contains_Var ------------------------------------------------------------------";
|
wneuper@59392
|
591 |
"----------- fun contains_Var ------------------------------------------------------------------";
|
wneuper@59403
|
592 |
val t = parse_patt @{theory} "?z = 3";
|
wneuper@59403
|
593 |
if contains_Var t = true then () else error "contains_Var ?z = 3";
|
wneuper@59403
|
594 |
|
wneuper@59403
|
595 |
val t = parse_patt @{theory} "z = 3";
|
wneuper@59403
|
596 |
if contains_Var t = false then () else error "contains_Var ?z = 3";
|
wneuper@59403
|
597 |
|
wneuper@59392
|
598 |
"----------- fun int_of_str_opt, fun is_num ----------------------------------------------------";
|
wneuper@59392
|
599 |
"----------- fun int_of_str_opt, fun is_num ----------------------------------------------------";
|
wneuper@59392
|
600 |
"----------- fun int_of_str_opt, fun is_num ----------------------------------------------------";
|
wneuper@59392
|
601 |
case int_of_str_opt "123" of
|
wneuper@59392
|
602 |
SOME 123 => () | _ => raise error "int_of_str_opt 123 changed";
|
wneuper@59392
|
603 |
case int_of_str_opt "(-123)" of
|
wneuper@59392
|
604 |
SOME ~123 => () | _ => raise error "int_of_str_opt (-123) changed";
|
wneuper@59392
|
605 |
case int_of_str_opt "#123" of
|
wneuper@59392
|
606 |
NONE => () | _ => raise error "int_of_str_opt #123 changed";
|
wneuper@59392
|
607 |
case int_of_str_opt "-123" of
|
wneuper@59392
|
608 |
SOME ~123 => () | _ => raise error "int_of_str_opt -123 changed";
|
wneuper@59403
|
609 |
|
wneuper@59403
|
610 |
val t = str2term "1";
|
wneuper@59403
|
611 |
if is_num t = true then () else error "is_num 1";
|
wneuper@59403
|
612 |
|
wneuper@59403
|
613 |
val t = str2term "-1";
|
wneuper@59403
|
614 |
if is_num t = true then () else error "is_num -1";
|
wneuper@59403
|
615 |
|
wneuper@59403
|
616 |
val t = str2term "a123";
|
wneuper@59403
|
617 |
if is_num t = false then () else error "is_num a123";
|
wneuper@59403
|
618 |
|
wneuper@59392
|
619 |
"----------- fun is_f_x ------------------------------------------------------------------------";
|
wneuper@59392
|
620 |
"----------- fun is_f_x ------------------------------------------------------------------------";
|
wneuper@59392
|
621 |
"----------- fun is_f_x ------------------------------------------------------------------------";
|
wneuper@59403
|
622 |
val t = str2term "q_0/2 * L * x";
|
wneuper@59403
|
623 |
if is_f_x t = false then () else error "is_f_x q_0/2 * L * x";
|
wneuper@59403
|
624 |
|
wneuper@59403
|
625 |
val t = str2term "M_b x";
|
wneuper@59403
|
626 |
if is_f_x t = true then () else error "M_b x";
|
wneuper@59403
|
627 |
|
wneuper@59392
|
628 |
"----------- fun list2isalist, fun isalist2list ------------------------------------------------";
|
wneuper@59392
|
629 |
"----------- fun list2isalist, fun isalist2list ------------------------------------------------";
|
wneuper@59392
|
630 |
"----------- fun list2isalist, fun isalist2list ------------------------------------------------";
|
wneuper@59403
|
631 |
val t = str2term "R=(R::real)";
|
wneuper@59403
|
632 |
val T = type_of t;
|
wneuper@59403
|
633 |
val ss = list2isalist T [t,t,t];
|
wneuper@59403
|
634 |
if term2str ss = "[R = R, R = R, R = R]" then () else error "list2isalist 1";
|
wneuper@59392
|
635 |
|
wneuper@59403
|
636 |
val t = str2term "[a=b,c=d,e=f]";
|
wneuper@59403
|
637 |
val il = isalist2list t;
|
wneuper@59403
|
638 |
if terms2str il = "[\"a = b\",\"c = d\",\"e = f\"]" then () else error "isalist2list 2";
|
wneuper@59392
|
639 |
|
wneuper@59403
|
640 |
val t = str2term "[a=b,c=d,e=f]";
|
wneuper@59403
|
641 |
val il = isalist2list t;
|
wneuper@59403
|
642 |
if terms2str il = "[\"a = b\",\"c = d\",\"e = f\"]" then () else error "isalist2list 2";
|
wneuper@59392
|
643 |
|
wneuper@59403
|
644 |
val t = str2term "ss___s::bool list";
|
wneuper@59403
|
645 |
(isalist2list t; error "isalist2list 1") handle TERM ("isalist2list applied to NON-list: ", _) =>();
|
wneuper@59392
|
646 |
|
wneuper@59403
|
647 |
"----------- fun strip_imp_prems', fun ins_concl -----------------------------------------------";
|
wneuper@59403
|
648 |
"----------- fun strip_imp_prems', fun ins_concl -----------------------------------------------";
|
wneuper@59403
|
649 |
"----------- fun strip_imp_prems', fun ins_concl -----------------------------------------------";
|
wneuper@59403
|
650 |
val prop = (#prop o Thm.rep_thm) @{thm real_mult_div_cancel2};
|
wneuper@59403
|
651 |
term2str prop = "?k \<noteq> 0 \<Longrightarrow> ?m * ?k / (?n * ?k) = ?m / ?n";
|
wneuper@59403
|
652 |
val t as Const ("Pure.imp", _) $
|
wneuper@59403
|
653 |
(Const ("HOL.Trueprop", _) $ (Const ("HOL.Not", _) $ (Const ("HOL.eq", _) $ Var (("k", 0), _) $ Const ("Groups.zero_class.zero", _)))) $
|
wneuper@59403
|
654 |
(Const ("HOL.Trueprop", _) $
|
wneuper@59403
|
655 |
(Const ("HOL.eq", _) $
|
wneuper@59403
|
656 |
(Const ("Rings.divide_class.divide", _) $ (Const ("Groups.times_class.times", _) $ Var (("m", 0), _) $ Var (("k", 0), _)) $
|
wneuper@59403
|
657 |
(Const ("Groups.times_class.times", _) $ Var (("n", 0), _) $ Var (("k", 0), _))) $
|
wneuper@59403
|
658 |
(Const ("Rings.divide_class.divide", _) $ Var (("m", 0), _) $ Var (("n", 0), _)))) = prop;
|
wneuper@59403
|
659 |
val SOME t' = strip_imp_prems' t;
|
wneuper@59462
|
660 |
if term2str t' = "(\<Longrightarrow>) (?k \<noteq> 0)" then () else error "strip_imp_prems' changed";
|
wneuper@59403
|
661 |
|
wneuper@59403
|
662 |
val thm = TermC.num_str @{thm frac_sym_conv};
|
wneuper@59403
|
663 |
val prop = (#prop o Thm.rep_thm) thm;
|
wneuper@59403
|
664 |
val concl = Logic.strip_imp_concl prop;
|
wneuper@59403
|
665 |
val SOME prems = strip_imp_prems' prop;
|
wneuper@59403
|
666 |
val prop' = ins_concl prems concl;
|
wneuper@59403
|
667 |
if prop = prop' then () else error "ins_concl o strip_imp_concl";
|
wneuper@59403
|
668 |
|
wneuper@59392
|
669 |
"----------- fun mk_factroot, fun mk_num_op_num, -----------------------------------------------";
|
wneuper@59392
|
670 |
"----------- fun mk_factroot, fun mk_num_op_num, -----------------------------------------------";
|
wneuper@59392
|
671 |
"----------- fun mk_factroot, fun mk_num_op_num, -----------------------------------------------";
|
wneuper@59403
|
672 |
val T = (type_of o Thm.term_of o the) (parse thy "12::real");
|
wneuper@59392
|
673 |
val t = mk_factroot "SqRoot.sqrt" T 2 3;
|
wneuper@59403
|
674 |
if term2str t = "2 * ??.SqRoot.sqrt 3" then () else error "mk_factroot";
|
wneuper@59403
|
675 |
|
wneuper@59403
|
676 |
val t = str2term "aaa + bbb";
|
wneuper@59403
|
677 |
val op_ as Const ("Groups.plus_class.plus", Top) $ Free ("aaa", T1) $ Free ("bbb", T2) = t;
|
wneuper@59403
|
678 |
val t' = mk_num_op_num T1 T2 ("Groups.plus_class.plus", Top) 2 3;
|
wneuper@59403
|
679 |
if term2str t' = "2 + 3" then () else error "mk_num_op_num";
|
wneuper@59403
|
680 |
|
wneuper@59392
|
681 |
"----------- fun dest_binop_typ ----------------------------------------------------------------";
|
wneuper@59392
|
682 |
"----------- fun dest_binop_typ ----------------------------------------------------------------";
|
wneuper@59392
|
683 |
"----------- fun dest_binop_typ ----------------------------------------------------------------";
|
wneuper@59403
|
684 |
val t = (Thm.term_of o the o (parse thy)) "3 ^ 4";
|
wneuper@59403
|
685 |
val hT = type_of (head_of t);
|
wneuper@59403
|
686 |
if (HOLogic.realT, HOLogic.natT, HOLogic.realT) = dest_binop_typ hT
|
wneuper@59403
|
687 |
then () else error "dest_binop_typ";
|
wneuper@59403
|
688 |
|
wneuper@59392
|
689 |
"----------- fun is_list -----------------------------------------------------------------------";
|
wneuper@59392
|
690 |
"----------- fun is_list -----------------------------------------------------------------------";
|
wneuper@59392
|
691 |
"----------- fun is_list -----------------------------------------------------------------------";
|
wneuper@59403
|
692 |
val (SOME ct) = parse thy "lll::real list";
|
wneuper@59403
|
693 |
val t = str2term "lll::real list";
|
wneuper@59403
|
694 |
val ty = (Term.type_of o Thm.term_of) ct;
|
wneuper@59403
|
695 |
if is_list t = false then () else error "is_list lll::real list";
|
wneuper@59403
|
696 |
|
wneuper@59403
|
697 |
val t = str2term "[a, b, c]";
|
wneuper@59403
|
698 |
val ty = (Term.type_of o Thm.term_of) ct;
|
wneuper@59403
|
699 |
if is_list t = true then () else error "is_list [a, b, c]";
|
wneuper@59403
|
700 |
|
wneuper@59394
|
701 |
"----------- fun inst_abs ----------------------------------------------------------------------";
|
wneuper@59394
|
702 |
"----------- fun inst_abs ----------------------------------------------------------------------";
|
wneuper@59394
|
703 |
"----------- fun inst_abs ----------------------------------------------------------------------";
|
wneuper@59403
|
704 |
(* cp from Biegelinie.thy*)
|
wneuper@59403
|
705 |
val scr = str2term
|
wneuper@59403
|
706 |
("Script Function2Equality (fu_n::bool) (su_b::bool) =" ^
|
wneuper@59403
|
707 |
" (let fu_n = Take fu_n; " ^
|
wneuper@59403
|
708 |
" bd_v = argument_in (lhs fu_n); " ^
|
wneuper@59403
|
709 |
" va_l = argument_in (lhs su_b); " ^
|
wneuper@59403
|
710 |
" eq_u = (Substitute [bd_v = va_l]) fu_n; " ^
|
wneuper@59403
|
711 |
" eq_u = (Substitute [su_b]) eq_u " ^
|
wneuper@59490
|
712 |
" in (Rewrite_Set ''norm_Rational'' False) eq_u) ")
|
wneuper@59403
|
713 |
val Const ("Equation.Function2Equality", _) $ Free ("fu_n", _) $ Free ("su_b", _) $
|
wneuper@59403
|
714 |
(Const ("HOL.Let", _) $ (Const ("Script.Take", _) $ Free ("fu_n", _)) $
|
wneuper@59403
|
715 |
Abs ("fu_n", _, (* <-- ID taken from here ------------------------------*)
|
wneuper@59403
|
716 |
Const ("HOL.Let", _) $
|
wneuper@59403
|
717 |
(Const ("Atools.argument'_in", _) $ (Const ("Tools.lhs", _) $
|
wneuper@59403
|
718 |
Bound 0)) $ (* difference --vvv ------------------------------------*)
|
wneuper@59403
|
719 |
Abs _)) = scr;
|
wneuper@59392
|
720 |
|
wneuper@59403
|
721 |
val scr' = inst_abs scr;
|
wneuper@59403
|
722 |
val Const ("Equation.Function2Equality", _) $ Free ("fu_n", _) $ Free ("su_b", _) $
|
wneuper@59403
|
723 |
(Const ("HOL.Let", _) $ (Const ("Script.Take", _) $ Free ("fu_n", _)) $
|
wneuper@59403
|
724 |
Abs ("fu_n", _,
|
wneuper@59403
|
725 |
Const ("HOL.Let", _) $
|
wneuper@59403
|
726 |
(Const ("Atools.argument'_in", _) $ (Const ("Tools.lhs", _) $
|
wneuper@59403
|
727 |
Free ("fu_n", _))) $ (* difference --^^^ -----------------------------------*)
|
wneuper@59403
|
728 |
Abs _)) = scr';
|
wneuper@59403
|
729 |
if term2str scr' = (* see the ugly IDs ...*)
|
wneuper@59403
|
730 |
("Script Function2Equality fu_n su_b =\n " ^
|
wneuper@59403
|
731 |
"let fu_na = Take fu_n; " ^
|
wneuper@59403
|
732 |
"bd_va = argument_in lhs fu_n;\n " ^
|
wneuper@59403
|
733 |
"va_la = argument_in lhs su_b; " ^
|
wneuper@59403
|
734 |
"eq_ua = Substitute [bd_v = va_l] fu_n;\n " ^
|
wneuper@59403
|
735 |
"eq_ua = Substitute [su_b] eq_u\n " ^
|
wneuper@59490
|
736 |
"in (Rewrite_Set ''norm_Rational'' False) eq_u")
|
wneuper@59403
|
737 |
then () else error "inst_abs changed";
|
wneuper@59392
|
738 |
|
wneuper@59403
|
739 |
val {scr = Prog original, ...} = get_met ["Equation","fromFunction"];
|
wneuper@59546
|
740 |
val Const ("Equation.Function2Equality", _) $ Free ("fu_n", _) $ Free ("su_b", _) $ scr'_body = scr'
|
wneuper@59546
|
741 |
;
|
wneuper@59549
|
742 |
if scr'_body = LTool.body_of original then () else error "inst_abs changed";
|