author | bulwahn |
Sat, 24 Oct 2009 16:55:42 +0200 | |
changeset 33124 | 5378e61add1a |
parent 33123 | 3c7c4372f9ad |
child 33125 | 2fef4f9429f7 |
permissions | -rw-r--r-- |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
1 |
(* Author: Lukas Bulwahn, TU Muenchen |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
2 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
3 |
Auxilary functions for predicate compiler |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
4 |
*) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
5 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
6 |
structure Predicate_Compile_Aux = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
7 |
struct |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
8 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
9 |
(* syntactic functions *) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
10 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
11 |
fun is_equationlike_term (Const ("==", _) $ _ $ _) = true |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
12 |
| is_equationlike_term (Const ("Trueprop", _) $ (Const ("op =", _) $ _ $ _)) = true |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
13 |
| is_equationlike_term _ = false |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
14 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
15 |
val is_equationlike = is_equationlike_term o prop_of |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
16 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
17 |
fun is_pred_equation_term (Const ("==", _) $ u $ v) = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
18 |
(fastype_of u = @{typ bool}) andalso (fastype_of v = @{typ bool}) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
19 |
| is_pred_equation_term _ = false |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
20 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
21 |
val is_pred_equation = is_pred_equation_term o prop_of |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
22 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
23 |
fun is_intro_term constname t = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
24 |
case fst (strip_comb (HOLogic.dest_Trueprop (Logic.strip_imp_concl t))) of |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
25 |
Const (c, _) => c = constname |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
26 |
| _ => false |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
27 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
28 |
fun is_intro constname t = is_intro_term constname (prop_of t) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
29 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
30 |
fun is_pred thy constname = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
31 |
let |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
32 |
val T = (Sign.the_const_type thy constname) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
33 |
in body_type T = @{typ "bool"} end; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
34 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
35 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
36 |
fun is_predT (T as Type("fun", [_, _])) = (snd (strip_type T) = HOLogic.boolT) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
37 |
| is_predT _ = false |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
38 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
39 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
40 |
(*** check if a term contains only constructor functions ***) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
41 |
fun is_constrt thy = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
42 |
let |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
43 |
val cnstrs = flat (maps |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
44 |
(map (fn (_, (Tname, _, cs)) => map (apsnd (rpair Tname o length)) cs) o #descr o snd) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
45 |
(Symtab.dest (Datatype.get_all thy))); |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
46 |
fun check t = (case strip_comb t of |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
47 |
(Free _, []) => true |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
48 |
| (Const (s, T), ts) => (case (AList.lookup (op =) cnstrs s, body_type T) of |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
49 |
(SOME (i, Tname), Type (Tname', _)) => length ts = i andalso Tname = Tname' andalso forall check ts |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
50 |
| _ => false) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
51 |
| _ => false) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
52 |
in check end; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
53 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
54 |
fun strip_ex (Const ("Ex", _) $ Abs (x, T, t)) = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
55 |
let |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
56 |
val (xTs, t') = strip_ex t |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
57 |
in |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
58 |
((x, T) :: xTs, t') |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
59 |
end |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
60 |
| strip_ex t = ([], t) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
61 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
62 |
fun focus_ex t nctxt = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
63 |
let |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
64 |
val ((xs, Ts), t') = apfst split_list (strip_ex t) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
65 |
val (xs', nctxt') = Name.variants xs nctxt; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
66 |
val ps' = xs' ~~ Ts; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
67 |
val vs = map Free ps'; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
68 |
val t'' = Term.subst_bounds (rev vs, t'); |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
69 |
in ((ps', t''), nctxt') end; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
70 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
71 |
|
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
72 |
(* introduction rule combinators *) |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
73 |
|
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
74 |
(* combinators to apply a function to all literals of an introduction rules *) |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
75 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
76 |
(* |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
77 |
fun map_atoms f intro = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
78 |
*) |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
79 |
|
33113 | 80 |
fun fold_atoms f intro s = |
81 |
let |
|
82 |
val (literals, head) = Logic.strip_horn intro |
|
83 |
fun appl t s = (case t of |
|
84 |
(@{term "Not"} $ t') => f t' s |
|
85 |
| _ => f t s) |
|
86 |
in fold appl (map HOLogic.dest_Trueprop literals) s end |
|
87 |
||
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
88 |
fun fold_map_atoms f intro s = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
89 |
let |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
90 |
val (literals, head) = Logic.strip_horn intro |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
91 |
fun appl t s = (case t of |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
92 |
(@{term "Not"} $ t') => |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
93 |
let |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
94 |
val (t'', s') = f t' s |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
95 |
in (@{term "Not"} $ t'', s') end |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
96 |
| _ => f t s) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
97 |
val (literals', s') = fold_map appl (map HOLogic.dest_Trueprop literals) s |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
98 |
in |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
99 |
(Logic.list_implies (map HOLogic.mk_Trueprop literals', head), s') |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
100 |
end; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
101 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
102 |
(* |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
103 |
fun equals_conv lhs_cv rhs_cv ct = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
104 |
case Thm.term_of ct of |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
105 |
Const ("==", _) $ _ $ _ => Conv.arg_conv cv ct |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
106 |
| _ => error "equals_conv" |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
107 |
*) |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
108 |
|
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
109 |
(* Different options for compiler *) |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
110 |
|
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
111 |
datatype options = Options of { |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
112 |
(*check_modes : (string * int list list) list,*) |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
113 |
show_steps : bool, |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
114 |
show_mode_inference : bool, |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
115 |
|
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
116 |
(* |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
117 |
inductify_functions : bool, |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
118 |
*) |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
119 |
inductify : bool, |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
120 |
rpred : bool |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
121 |
}; |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
122 |
|
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
123 |
fun is_show_steps (Options opt) = #show_steps opt |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
124 |
fun is_inductify (Options opt) = #inductify opt |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
125 |
fun is_rpred (Options opt) = #rpred opt |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
126 |
|
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
127 |
|
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
128 |
val default_options = Options { |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
129 |
show_steps = false, |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
130 |
show_mode_inference = false, |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
131 |
inductify = false, |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
132 |
rpred = false |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
133 |
} |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
134 |
|
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
135 |
|
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
136 |
fun print_step options s = |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
137 |
if is_show_steps options then tracing s else () |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33113
diff
changeset
|
138 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
139 |
|
33124
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
140 |
(* tuple processing *) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
141 |
|
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
142 |
fun expand_tuples thy intro = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
143 |
let |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
144 |
fun rewrite_args [] (pats, intro_t, ctxt) = (pats, intro_t, ctxt) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
145 |
| rewrite_args (arg::args) (pats, intro_t, ctxt) = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
146 |
(case HOLogic.strip_tupleT (fastype_of arg) of |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
147 |
(Ts as _ :: _ :: _) => |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
148 |
let |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
149 |
fun rewrite_arg' (Const ("Pair", _) $ _ $ t2, Type ("*", [_, T2])) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
150 |
(args, (pats, intro_t, ctxt)) = rewrite_arg' (t2, T2) (args, (pats, intro_t, ctxt)) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
151 |
| rewrite_arg' (t, Type ("*", [T1, T2])) (args, (pats, intro_t, ctxt)) = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
152 |
let |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
153 |
val ([x, y], ctxt') = Variable.variant_fixes ["x", "y"] ctxt |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
154 |
val pat = (t, HOLogic.mk_prod (Free (x, T1), Free (y, T2))) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
155 |
val intro_t' = Pattern.rewrite_term thy [pat] [] intro_t |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
156 |
val args' = map (Pattern.rewrite_term thy [pat] []) args |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
157 |
in |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
158 |
rewrite_arg' (Free (y, T2), T2) (args', (pat::pats, intro_t', ctxt')) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
159 |
end |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
160 |
| rewrite_arg' _ (args, (pats, intro_t, ctxt)) = (args, (pats, intro_t, ctxt)) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
161 |
val (args', (pats, intro_t', ctxt')) = rewrite_arg' (arg, fastype_of arg) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
162 |
(args, (pats, intro_t, ctxt)) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
163 |
in |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
164 |
rewrite_args args' (pats, intro_t', ctxt') |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
165 |
end |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
166 |
| _ => rewrite_args args (pats, intro_t, ctxt)) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
167 |
fun rewrite_prem atom = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
168 |
let |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
169 |
val (_, args) = strip_comb atom |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
170 |
in rewrite_args args end |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
171 |
val ctxt = ProofContext.init thy |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
172 |
val (((T_insts, t_insts), [intro']), ctxt1) = Variable.import false [intro] ctxt |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
173 |
val intro_t = prop_of intro' |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
174 |
val concl = Logic.strip_imp_concl intro_t |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
175 |
val (p, args) = strip_comb (HOLogic.dest_Trueprop concl) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
176 |
val (pats', intro_t', ctxt2) = rewrite_args args ([], intro_t, ctxt1) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
177 |
val (pats', intro_t', ctxt3) = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
178 |
fold_atoms rewrite_prem intro_t' (pats', intro_t', ctxt2) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
179 |
fun rewrite_pat (ct1, ct2) = |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
180 |
(ct1, cterm_of thy (Pattern.rewrite_term thy pats' [] (term_of ct2))) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
181 |
val t_insts' = map rewrite_pat t_insts |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
182 |
val intro'' = Thm.instantiate (T_insts, t_insts') intro |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
183 |
val [intro'''] = Variable.export ctxt3 ctxt [intro''] |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
184 |
val intro'''' = Simplifier.full_simplify |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
185 |
(HOL_basic_ss addsimps [@{thm fst_conv}, @{thm snd_conv}, @{thm Pair_eq}]) |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
186 |
intro''' |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
187 |
in |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
188 |
intro'''' |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
189 |
end |
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
190 |
|
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
191 |
|
5378e61add1a
continued cleaning up; moved tuple expanding to core
bulwahn
parents:
33123
diff
changeset
|
192 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
193 |
end; |