author | huffman |
Fri, 01 Jun 2012 11:55:06 +0200 | |
changeset 48065 | 8aa05d38299a |
parent 48064 | 7bd9e18ce058 |
child 48066 | c6783c9b87bf |
permissions | -rw-r--r-- |
47325 | 1 |
(* Title: HOL/Tools/transfer.ML |
2 |
Author: Brian Huffman, TU Muenchen |
|
3 |
||
4 |
Generic theorem transfer method. |
|
5 |
*) |
|
6 |
||
7 |
signature TRANSFER = |
|
8 |
sig |
|
9 |
val prep_conv: conv |
|
47503 | 10 |
val get_relator_eq: Proof.context -> thm list |
47325 | 11 |
val transfer_add: attribute |
12 |
val transfer_del: attribute |
|
47803
2e3821e13d67
allow transfer tactic to leave extra unsolved subgoals if transfer rules are missing
huffman
parents:
47789
diff
changeset
|
13 |
val transfer_rule_of_term: Proof.context -> term -> thm |
47658
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
huffman
parents:
47635
diff
changeset
|
14 |
val transfer_tac: bool -> Proof.context -> int -> tactic |
47635
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
15 |
val transfer_prover_tac: Proof.context -> int -> tactic |
47325 | 16 |
val setup: theory -> theory |
17 |
end |
|
18 |
||
19 |
structure Transfer : TRANSFER = |
|
20 |
struct |
|
21 |
||
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
22 |
(** Theory Data **) |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
23 |
|
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
24 |
structure Data = Generic_Data |
47325 | 25 |
( |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
26 |
type T = |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
27 |
{ transfer_raw : thm Item_Net.T, |
48065
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
28 |
known_frees : (string * typ) list, |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
29 |
relator_eq : thm Item_Net.T } |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
30 |
val empty = |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
31 |
{ transfer_raw = Thm.full_rules, |
48065
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
32 |
known_frees = [], |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
33 |
relator_eq = Thm.full_rules } |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
34 |
val extend = I |
48065
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
35 |
fun merge ({transfer_raw = t1, known_frees = k1, relator_eq = r1}, |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
36 |
{transfer_raw = t2, known_frees = k2, relator_eq = r2}) = |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
37 |
{ transfer_raw = Item_Net.merge (t1, t2), |
48065
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
38 |
known_frees = Library.merge (op =) (k1, k2), |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
39 |
relator_eq = Item_Net.merge (r1, r2) } |
47325 | 40 |
) |
41 |
||
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
42 |
fun get_relator_eq ctxt = ctxt |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
43 |
|> (Item_Net.content o #relator_eq o Data.get o Context.Proof) |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
44 |
|> map (Thm.symmetric o mk_meta_eq) |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
45 |
|
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
46 |
fun get_transfer_raw ctxt = ctxt |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
47 |
|> (Item_Net.content o #transfer_raw o Data.get o Context.Proof) |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
48 |
|
48065
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
49 |
fun get_known_frees ctxt = ctxt |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
50 |
|> (#known_frees o Data.get o Context.Proof) |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
51 |
|
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
52 |
fun map_data f1 f2 f3 {transfer_raw, known_frees, relator_eq} = |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
53 |
{ transfer_raw = f1 transfer_raw, |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
54 |
known_frees = f2 known_frees, |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
55 |
relator_eq = f3 relator_eq } |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
56 |
|
48065
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
57 |
fun map_transfer_raw f = map_data f I I |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
58 |
fun map_known_frees f = map_data I f I |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
59 |
fun map_relator_eq f = map_data I I f |
47503 | 60 |
|
48065
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
61 |
fun add_transfer_thm thm = Data.map |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
62 |
(map_transfer_raw (Item_Net.update thm) o |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
63 |
map_known_frees (Term.add_frees (Thm.concl_of thm))) |
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
64 |
|
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
65 |
fun del_transfer_thm thm = Data.map (map_transfer_raw (Item_Net.remove thm)) |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
66 |
|
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
67 |
val relator_eq_setup = |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
68 |
let |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
69 |
val name = @{binding relator_eq} |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
70 |
fun add_thm thm = Data.map (map_relator_eq (Item_Net.update thm)) |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
71 |
fun del_thm thm = Data.map (map_relator_eq (Item_Net.remove thm)) |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
72 |
val add = Thm.declaration_attribute add_thm |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
73 |
val del = Thm.declaration_attribute del_thm |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
74 |
val text = "declaration of relator equality rule (used by transfer method)" |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
75 |
val content = Item_Net.content o #relator_eq o Data.get |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
76 |
in |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
77 |
Attrib.setup name (Attrib.add_del add del) text |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
78 |
#> Global_Theory.add_thms_dynamic (name, content) |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
79 |
end |
47503 | 80 |
|
47325 | 81 |
(** Conversions **) |
82 |
||
83 |
val Rel_rule = Thm.symmetric @{thm Rel_def} |
|
84 |
||
85 |
fun dest_funcT cT = |
|
86 |
(case Thm.dest_ctyp cT of [T, U] => (T, U) |
|
87 |
| _ => raise TYPE ("dest_funcT", [Thm.typ_of cT], [])) |
|
88 |
||
89 |
fun Rel_conv ct = |
|
90 |
let val (cT, cT') = dest_funcT (Thm.ctyp_of_term ct) |
|
91 |
val (cU, _) = dest_funcT cT' |
|
92 |
in Drule.instantiate' [SOME cT, SOME cU] [SOME ct] Rel_rule end |
|
93 |
||
94 |
fun Trueprop_conv cv ct = |
|
95 |
(case Thm.term_of ct of |
|
96 |
Const (@{const_name Trueprop}, _) $ _ => Conv.arg_conv cv ct |
|
97 |
| _ => raise CTERM ("Trueprop_conv", [ct])) |
|
98 |
||
47635
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
99 |
(* Conversion to preprocess a transfer rule *) |
47325 | 100 |
fun prep_conv ct = ( |
101 |
Conv.implies_conv Conv.all_conv prep_conv |
|
102 |
else_conv |
|
103 |
Trueprop_conv (Conv.fun_conv (Conv.fun_conv Rel_conv)) |
|
104 |
else_conv |
|
105 |
Conv.all_conv) ct |
|
106 |
||
107 |
(** Transfer proof method **) |
|
108 |
||
109 |
fun RelT (Const (@{const_name Rel}, _) $ _ $ _ $ y) = fastype_of y |
|
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
110 |
| RelT t = raise TERM ("RelT", [t]) |
47325 | 111 |
|
112 |
(* Tactic to correspond a value to itself *) |
|
113 |
fun eq_tac ctxt = SUBGOAL (fn (t, i) => |
|
114 |
let |
|
115 |
val T = RelT (HOLogic.dest_Trueprop (Logic.strip_assums_concl t)) |
|
116 |
val cT = ctyp_of (Proof_Context.theory_of ctxt) T |
|
47503 | 117 |
val rews = get_relator_eq ctxt |
47325 | 118 |
val thm1 = Drule.instantiate' [SOME cT] [] @{thm Rel_eq_refl} |
119 |
val thm2 = Raw_Simplifier.rewrite_rule rews thm1 |
|
120 |
in |
|
121 |
rtac thm2 i |
|
122 |
end handle Match => no_tac | TERM _ => no_tac) |
|
123 |
||
47355
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47327
diff
changeset
|
124 |
val post_simps = |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
125 |
@{thms transfer_forall_eq [symmetric] |
47355
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47327
diff
changeset
|
126 |
transfer_implies_eq [symmetric] transfer_bforall_unfold} |
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47327
diff
changeset
|
127 |
|
47356
19fb95255ec9
transfer method generalizes over free variables in goal
huffman
parents:
47355
diff
changeset
|
128 |
fun gen_frees_tac keepers ctxt = SUBGOAL (fn (t, i) => |
19fb95255ec9
transfer method generalizes over free variables in goal
huffman
parents:
47355
diff
changeset
|
129 |
let |
48065
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
huffman
parents:
48064
diff
changeset
|
130 |
val keepers = keepers @ get_known_frees ctxt |
47356
19fb95255ec9
transfer method generalizes over free variables in goal
huffman
parents:
47355
diff
changeset
|
131 |
val vs = rev (Term.add_frees t []) |
47568
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
huffman
parents:
47523
diff
changeset
|
132 |
val vs' = filter_out (member (op =) keepers) vs |
47356
19fb95255ec9
transfer method generalizes over free variables in goal
huffman
parents:
47355
diff
changeset
|
133 |
in |
19fb95255ec9
transfer method generalizes over free variables in goal
huffman
parents:
47355
diff
changeset
|
134 |
Induct.arbitrary_tac ctxt 0 vs' i |
19fb95255ec9
transfer method generalizes over free variables in goal
huffman
parents:
47355
diff
changeset
|
135 |
end) |
19fb95255ec9
transfer method generalizes over free variables in goal
huffman
parents:
47355
diff
changeset
|
136 |
|
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
137 |
(* create a lambda term of the same shape as the given term *) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
138 |
fun skeleton (Bound i) ctxt = (Bound i, ctxt) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
139 |
| skeleton (Abs (x, _, t)) ctxt = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
140 |
let |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
141 |
val (t', ctxt) = skeleton t ctxt |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
142 |
in |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
143 |
(Abs (x, dummyT, t'), ctxt) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
144 |
end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
145 |
| skeleton (t $ u) ctxt = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
146 |
let |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
147 |
val (t', ctxt) = skeleton t ctxt |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
148 |
val (u', ctxt) = skeleton u ctxt |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
149 |
in |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
150 |
(t' $ u', ctxt) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
151 |
end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
152 |
| skeleton _ ctxt = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
153 |
let |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
154 |
val (c, ctxt) = yield_singleton Variable.variant_fixes "a" ctxt |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
155 |
in |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
156 |
(Free (c, dummyT), ctxt) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
157 |
end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
158 |
|
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
159 |
fun mk_relT (T, U) = T --> U --> HOLogic.boolT |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
160 |
|
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
161 |
fun mk_Rel t = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
162 |
let val T = fastype_of t |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
163 |
in Const (@{const_name Transfer.Rel}, T --> T) $ t end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
164 |
|
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
165 |
fun transfer_rule_of_terms ctxt tab t u = |
47580
d99c883cdf2c
use simpler method for preserving bound variable names in transfer tactic
huffman
parents:
47568
diff
changeset
|
166 |
let |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
167 |
val thy = Proof_Context.theory_of ctxt |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
168 |
(* precondition: T must consist of only TFrees and function space *) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
169 |
fun rel (T as TFree (a, _)) U = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
170 |
Free (the (AList.lookup (op =) tab a), mk_relT (T, U)) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
171 |
| rel (T as Type ("fun", [T1, T2])) (U as Type ("fun", [U1, U2])) = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
172 |
let |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
173 |
val r1 = rel T1 U1 |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
174 |
val r2 = rel T2 U2 |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
175 |
val rT = fastype_of r1 --> fastype_of r2 --> mk_relT (T, U) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
176 |
in |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
177 |
Const (@{const_name fun_rel}, rT) $ r1 $ r2 |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
178 |
end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
179 |
| rel T U = raise TYPE ("rel", [T, U], []) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
180 |
fun zip _ thms (Bound i) (Bound _) = (nth thms i, []) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
181 |
| zip ctxt thms (Abs (x, T, t)) (Abs (y, U, u)) = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
182 |
let |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
183 |
val ([x', y'], ctxt') = Variable.variant_fixes [x, y] ctxt |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
184 |
val prop = mk_Rel (rel T U) $ Free (x', T) $ Free (y', U) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
185 |
val cprop = Thm.cterm_of thy (HOLogic.mk_Trueprop prop) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
186 |
val thm0 = Thm.assume cprop |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
187 |
val (thm1, hyps) = zip ctxt' (thm0 :: thms) t u |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
188 |
val ((r1, x), y) = apfst Thm.dest_comb (Thm.dest_comb (Thm.dest_arg cprop)) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
189 |
val r2 = Thm.dest_fun2 (Thm.dest_arg (cprop_of thm1)) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
190 |
val (a1, (b1, _)) = apsnd dest_funcT (dest_funcT (ctyp_of_term r1)) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
191 |
val (a2, (b2, _)) = apsnd dest_funcT (dest_funcT (ctyp_of_term r2)) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
192 |
val tinsts = [SOME a1, SOME b1, SOME a2, SOME b2] |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
193 |
val insts = [SOME (Thm.dest_arg r1), SOME (Thm.dest_arg r2)] |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
194 |
val rule = Drule.instantiate' tinsts insts @{thm Rel_abs} |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
195 |
val thm2 = Thm.forall_intr x (Thm.forall_intr y (Thm.implies_intr cprop thm1)) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
196 |
in |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
197 |
(thm2 COMP rule, hyps) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
198 |
end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
199 |
| zip ctxt thms (f $ t) (g $ u) = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
200 |
let |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
201 |
val (thm1, hyps1) = zip ctxt thms f g |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
202 |
val (thm2, hyps2) = zip ctxt thms t u |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
203 |
in |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
204 |
(thm2 RS (thm1 RS @{thm Rel_app}), hyps1 @ hyps2) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
205 |
end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
206 |
| zip _ _ (t as Free (_, T)) u = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
207 |
let |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
208 |
val U = fastype_of u |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
209 |
val prop = mk_Rel (rel T U) $ t $ u |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
210 |
val cprop = Thm.cterm_of thy (HOLogic.mk_Trueprop prop) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
211 |
in |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
212 |
(Thm.assume cprop, [cprop]) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
213 |
end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
214 |
| zip _ _ t u = raise TERM ("zip_relterm", [t, u]) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
215 |
val r = mk_Rel (rel (fastype_of t) (fastype_of u)) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
216 |
val goal = HOLogic.mk_Trueprop (r $ t $ u) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
217 |
val rename = Thm.trivial (cterm_of thy goal) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
218 |
val (thm, hyps) = zip ctxt [] t u |
47580
d99c883cdf2c
use simpler method for preserving bound variable names in transfer tactic
huffman
parents:
47568
diff
changeset
|
219 |
in |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
220 |
Drule.implies_intr_list hyps (thm RS rename) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
221 |
end |
47580
d99c883cdf2c
use simpler method for preserving bound variable names in transfer tactic
huffman
parents:
47568
diff
changeset
|
222 |
|
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
223 |
fun transfer_rule_of_term ctxt t = |
47325 | 224 |
let |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
225 |
val s = skeleton t ctxt |> fst |> Syntax.check_term ctxt |> |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
226 |
map_types (map_type_tfree (fn (a, _) => TFree (a, HOLogic.typeS))) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
227 |
val frees = map fst (Term.add_frees s []) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
228 |
val tfrees = map fst (Term.add_tfrees s []) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
229 |
fun prep a = "R" ^ Library.unprefix "'" a |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
230 |
val (rnames, ctxt') = Variable.variant_fixes (map prep tfrees) ctxt |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
231 |
val thm = transfer_rule_of_terms ctxt' (tfrees ~~ rnames) s t |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
232 |
in |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
233 |
Thm.generalize (tfrees, rnames @ frees) (Thm.maxidx_of thm + 1) thm |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
234 |
end |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
235 |
|
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
236 |
fun transfer_tac equiv ctxt i = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
237 |
let |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
238 |
val pre_simps = @{thms transfer_forall_eq transfer_implies_eq} |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
239 |
val start_rule = |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
240 |
if equiv then @{thm transfer_start} else @{thm transfer_start'} |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
241 |
val rules = get_transfer_raw ctxt |
47803
2e3821e13d67
allow transfer tactic to leave extra unsolved subgoals if transfer rules are missing
huffman
parents:
47789
diff
changeset
|
242 |
(* allow unsolved subgoals only for standard transfer method, not for transfer' *) |
2e3821e13d67
allow transfer tactic to leave extra unsolved subgoals if transfer rules are missing
huffman
parents:
47789
diff
changeset
|
243 |
val end_tac = if equiv then K all_tac else K no_tac |
47325 | 244 |
in |
245 |
EVERY |
|
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
246 |
[rewrite_goal_tac pre_simps i THEN |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
247 |
SUBGOAL (fn (t, i) => |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
248 |
rtac start_rule i THEN |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
249 |
(rtac (transfer_rule_of_term ctxt (HOLogic.dest_Trueprop t)) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
250 |
THEN_ALL_NEW |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
251 |
(SOLVED' (REPEAT_ALL_NEW (resolve_tac rules)) |
47803
2e3821e13d67
allow transfer tactic to leave extra unsolved subgoals if transfer rules are missing
huffman
parents:
47789
diff
changeset
|
252 |
ORELSE' eq_tac ctxt ORELSE' end_tac)) (i + 1)) i, |
47325 | 253 |
(* FIXME: rewrite_goal_tac does unwanted eta-contraction *) |
47355
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents:
47327
diff
changeset
|
254 |
rewrite_goal_tac post_simps i, |
47325 | 255 |
rtac @{thm _} i] |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
256 |
end |
47325 | 257 |
|
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
258 |
fun transfer_prover_tac ctxt = SUBGOAL (fn (t, i) => |
47325 | 259 |
let |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
260 |
val rhs = (snd o Term.dest_comb o HOLogic.dest_Trueprop) t |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
261 |
val rule1 = transfer_rule_of_term ctxt rhs |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
262 |
val rules = get_transfer_raw ctxt |
47325 | 263 |
in |
264 |
EVERY |
|
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
265 |
[CONVERSION prep_conv i, |
47635
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
266 |
rtac @{thm transfer_prover_start} i, |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
267 |
(rtac rule1 THEN_ALL_NEW |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
268 |
REPEAT_ALL_NEW |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
269 |
(resolve_tac rules ORELSE' eq_tac ctxt)) (i+1), |
47618
1568dadd598a
make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
huffman
parents:
47580
diff
changeset
|
270 |
rtac @{thm refl} i] |
47789
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
271 |
end) |
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
272 |
|
71a526ee569a
implement transfer tactic with more scalable forward proof methods
huffman
parents:
47658
diff
changeset
|
273 |
(** Methods and attributes **) |
47325 | 274 |
|
47568
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
huffman
parents:
47523
diff
changeset
|
275 |
val free = Args.context -- Args.term >> (fn (_, Free v) => v | (ctxt, t) => |
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
huffman
parents:
47523
diff
changeset
|
276 |
error ("Bad free variable: " ^ Syntax.string_of_term ctxt t)) |
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
huffman
parents:
47523
diff
changeset
|
277 |
|
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
huffman
parents:
47523
diff
changeset
|
278 |
val fixing = Scan.optional (Scan.lift (Args.$$$ "fixing" -- Args.colon) |
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
huffman
parents:
47523
diff
changeset
|
279 |
|-- Scan.repeat free) [] |
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
huffman
parents:
47523
diff
changeset
|
280 |
|
47658
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
huffman
parents:
47635
diff
changeset
|
281 |
fun transfer_method equiv : (Proof.context -> Method.method) context_parser = |
47568
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
huffman
parents:
47523
diff
changeset
|
282 |
fixing >> (fn vs => fn ctxt => |
47658
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
huffman
parents:
47635
diff
changeset
|
283 |
SIMPLE_METHOD' (gen_frees_tac vs ctxt THEN' transfer_tac equiv ctxt)) |
47325 | 284 |
|
47635
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
285 |
val transfer_prover_method : (Proof.context -> Method.method) context_parser = |
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
286 |
Scan.succeed (fn ctxt => SIMPLE_METHOD' (transfer_prover_tac ctxt)) |
47325 | 287 |
|
47635
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
288 |
(* Attribute for transfer rules *) |
47325 | 289 |
|
290 |
val prep_rule = Conv.fconv_rule prep_conv |
|
291 |
||
292 |
val transfer_add = |
|
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
293 |
Thm.declaration_attribute (add_transfer_thm o prep_rule) |
47325 | 294 |
|
295 |
val transfer_del = |
|
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
296 |
Thm.declaration_attribute (del_transfer_thm o prep_rule) |
47325 | 297 |
|
298 |
val transfer_attribute = |
|
299 |
Attrib.add_del transfer_add transfer_del |
|
300 |
||
301 |
(* Theory setup *) |
|
302 |
||
303 |
val setup = |
|
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
304 |
relator_eq_setup |
47325 | 305 |
#> Attrib.setup @{binding transfer_rule} transfer_attribute |
47635
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
306 |
"transfer rule for transfer method" |
48064
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
307 |
#> Global_Theory.add_thms_dynamic |
7bd9e18ce058
unify theory-data structures for transfer package
huffman
parents:
47803
diff
changeset
|
308 |
(@{binding transfer_raw}, Item_Net.content o #transfer_raw o Data.get) |
47658
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
huffman
parents:
47635
diff
changeset
|
309 |
#> Method.setup @{binding transfer} (transfer_method true) |
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
huffman
parents:
47635
diff
changeset
|
310 |
"generic theorem transfer method" |
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
huffman
parents:
47635
diff
changeset
|
311 |
#> Method.setup @{binding transfer'} (transfer_method false) |
47325 | 312 |
"generic theorem transfer method" |
47635
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
313 |
#> Method.setup @{binding transfer_prover} transfer_prover_method |
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
huffman
parents:
47618
diff
changeset
|
314 |
"for proving transfer rules" |
47325 | 315 |
|
316 |
end |