author | wenzelm |
Sun, 26 Jul 2009 18:57:11 +0200 | |
changeset 32202 | 443d5cfaba1b |
parent 32172 | c4e55f30d527 |
child 32952 | aeb1e44fbc19 |
permissions | -rw-r--r-- |
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
1 |
(* Title: HOL/Nominal/nominal_inductive.ML |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
2 |
Author: Stefan Berghofer, TU Muenchen |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
3 |
|
22530 | 4 |
Infrastructure for proving equivariance and strong induction theorems |
5 |
for inductive predicates involving nominal datatypes. |
|
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
6 |
*) |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
7 |
|
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
8 |
signature NOMINAL_INDUCTIVE = |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
9 |
sig |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
10 |
val prove_strong_ind: string -> (string * string list) list -> local_theory -> Proof.state |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
11 |
val prove_eqvt: string -> string list -> local_theory -> local_theory |
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
12 |
end |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
13 |
|
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
14 |
structure NominalInductive : NOMINAL_INDUCTIVE = |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
15 |
struct |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
16 |
|
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
17 |
val inductive_forall_name = "HOL.induct_forall"; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
18 |
val inductive_forall_def = thm "induct_forall_def"; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
19 |
val inductive_atomize = thms "induct_atomize"; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
20 |
val inductive_rulify = thms "induct_rulify"; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
21 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
22 |
fun rulify_term thy = MetaSimplifier.rewrite_term thy inductive_rulify []; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
23 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
24 |
val atomize_conv = |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
25 |
MetaSimplifier.rewrite_cterm (true, false, false) (K (K NONE)) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
26 |
(HOL_basic_ss addsimps inductive_atomize); |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
27 |
val atomize_intr = Conv.fconv_rule (Conv.prems_conv ~1 atomize_conv); |
24832 | 28 |
fun atomize_induct ctxt = Conv.fconv_rule (Conv.prems_conv ~1 |
26568 | 29 |
(Conv.params_conv ~1 (K (Conv.prems_conv ~1 atomize_conv)) ctxt)); |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
30 |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
31 |
fun preds_of ps t = gen_inter (op = o apfst dest_Free) (ps, Term.add_frees t []); |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
32 |
|
22530 | 33 |
val fresh_prod = thm "fresh_prod"; |
34 |
||
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
35 |
val perm_bool = mk_meta_eq (thm "perm_bool"); |
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
36 |
val perm_boolI = thm "perm_boolI"; |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
37 |
val (_, [perm_boolI_pi, _]) = Drule.strip_comb (snd (Thm.dest_comb |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
38 |
(Drule.strip_imp_concl (cprop_of perm_boolI)))); |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
39 |
|
25824 | 40 |
fun mk_perm_bool pi th = th RS Drule.cterm_instantiate |
41 |
[(perm_boolI_pi, pi)] perm_boolI; |
|
42 |
||
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
43 |
fun mk_perm_bool_simproc names = Simplifier.simproc_i |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
44 |
(theory_of_thm perm_bool) "perm_bool" [@{term "perm pi x"}] (fn thy => fn ss => |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
45 |
fn Const ("Nominal.perm", _) $ _ $ t => |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
46 |
if the_default "" (try (head_of #> dest_Const #> fst) t) mem names |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
47 |
then SOME perm_bool else NONE |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
48 |
| _ => NONE); |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
49 |
|
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
50 |
fun transp ([] :: _) = [] |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
51 |
| transp xs = map hd xs :: transp (map tl xs); |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
52 |
|
22530 | 53 |
fun add_binders thy i (t as (_ $ _)) bs = (case strip_comb t of |
54 |
(Const (s, T), ts) => (case strip_type T of |
|
55 |
(Ts, Type (tname, _)) => |
|
31938 | 56 |
(case NominalDatatype.get_nominal_datatype thy tname of |
22530 | 57 |
NONE => fold (add_binders thy i) ts bs |
58 |
| SOME {descr, index, ...} => (case AList.lookup op = |
|
59 |
(#3 (the (AList.lookup op = descr index))) s of |
|
60 |
NONE => fold (add_binders thy i) ts bs |
|
61 |
| SOME cargs => fst (fold (fn (xs, x) => fn (bs', cargs') => |
|
62 |
let val (cargs1, (u, _) :: cargs2) = chop (length xs) cargs' |
|
63 |
in (add_binders thy i u |
|
64 |
(fold (fn (u, T) => |
|
65 |
if exists (fn j => j < i) (loose_bnos u) then I |
|
66 |
else insert (op aconv o pairself fst) |
|
67 |
(incr_boundvars (~i) u, T)) cargs1 bs'), cargs2) |
|
68 |
end) cargs (bs, ts ~~ Ts)))) |
|
69 |
| _ => fold (add_binders thy i) ts bs) |
|
70 |
| (u, ts) => add_binders thy i u (fold (add_binders thy i) ts bs)) |
|
71 |
| add_binders thy i (Abs (_, _, t)) bs = add_binders thy (i + 1) t bs |
|
72 |
| add_binders thy i _ bs = bs; |
|
73 |
||
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
74 |
fun split_conj f names (Const ("op &", _) $ p $ q) _ = (case head_of p of |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
75 |
Const (name, _) => |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
76 |
if name mem names then SOME (f p q) else NONE |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
77 |
| _ => NONE) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
78 |
| split_conj _ _ _ _ = NONE; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
79 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
80 |
fun strip_all [] t = t |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
81 |
| strip_all (_ :: xs) (Const ("All", _) $ Abs (s, T, t)) = strip_all xs t; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
82 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
83 |
(*********************************************************************) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
84 |
(* maps R ... & (ALL pi_1 ... pi_n z. P z (pi_1 o ... o pi_n o t)) *) |
27722
d657036e26c5
- corrected bogus comment for function inst_conj_all
berghofe
parents:
27449
diff
changeset
|
85 |
(* or ALL pi_1 ... pi_n z. P z (pi_1 o ... o pi_n o t) *) |
d657036e26c5
- corrected bogus comment for function inst_conj_all
berghofe
parents:
27449
diff
changeset
|
86 |
(* to R ... & id (ALL z. P z (pi_1 o ... o pi_n o t)) *) |
d657036e26c5
- corrected bogus comment for function inst_conj_all
berghofe
parents:
27449
diff
changeset
|
87 |
(* or id (ALL z. P z (pi_1 o ... o pi_n o t)) *) |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
88 |
(* *) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
89 |
(* where "id" protects the subformula from simplification *) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
90 |
(*********************************************************************) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
91 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
92 |
fun inst_conj_all names ps pis (Const ("op &", _) $ p $ q) _ = |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
93 |
(case head_of p of |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
94 |
Const (name, _) => |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
95 |
if name mem names then SOME (HOLogic.mk_conj (p, |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
96 |
Const ("Fun.id", HOLogic.boolT --> HOLogic.boolT) $ |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
97 |
(subst_bounds (pis, strip_all pis q)))) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
98 |
else NONE |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
99 |
| _ => NONE) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
100 |
| inst_conj_all names ps pis t u = |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
101 |
if member (op aconv) ps (head_of u) then |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
102 |
SOME (Const ("Fun.id", HOLogic.boolT --> HOLogic.boolT) $ |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
103 |
(subst_bounds (pis, strip_all pis t))) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
104 |
else NONE |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
105 |
| inst_conj_all _ _ _ _ _ = NONE; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
106 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
107 |
fun inst_conj_all_tac k = EVERY |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
108 |
[TRY (EVERY [etac conjE 1, rtac conjI 1, atac 1]), |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
109 |
REPEAT_DETERM_N k (etac allE 1), |
26359 | 110 |
simp_tac (HOL_basic_ss addsimps [@{thm id_apply}]) 1]; |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
111 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
112 |
fun map_term f t u = (case f t u of |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
113 |
NONE => map_term' f t u | x => x) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
114 |
and map_term' f (t $ u) (t' $ u') = (case (map_term f t t', map_term f u u') of |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
115 |
(NONE, NONE) => NONE |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
116 |
| (SOME t'', NONE) => SOME (t'' $ u) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
117 |
| (NONE, SOME u'') => SOME (t $ u'') |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
118 |
| (SOME t'', SOME u'') => SOME (t'' $ u'')) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
119 |
| map_term' f (Abs (s, T, t)) (Abs (s', T', t')) = (case map_term f t t' of |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
120 |
NONE => NONE |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
121 |
| SOME t'' => SOME (Abs (s, T, t''))) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
122 |
| map_term' _ _ _ = NONE; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
123 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
124 |
(*********************************************************************) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
125 |
(* Prove F[f t] from F[t], where F is monotone *) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
126 |
(*********************************************************************) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
127 |
|
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
128 |
fun map_thm ctxt f tac monos opt th = |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
129 |
let |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
130 |
val prop = prop_of th; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
131 |
fun prove t = |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
132 |
Goal.prove ctxt [] [] t (fn _ => |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
133 |
EVERY [cut_facts_tac [th] 1, etac rev_mp 1, |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
134 |
REPEAT_DETERM (FIRSTGOAL (resolve_tac monos)), |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
135 |
REPEAT_DETERM (rtac impI 1 THEN (atac 1 ORELSE tac))]) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
136 |
in Option.map prove (map_term f prop (the_default prop opt)) end; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
137 |
|
27352
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
138 |
val eta_contract_cterm = Thm.dest_arg o Thm.cprop_of o Thm.eta_conversion; |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
139 |
|
25824 | 140 |
fun first_order_matchs pats objs = Thm.first_order_match |
27352
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
141 |
(eta_contract_cterm (Conjunction.mk_conjunction_balanced pats), |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
142 |
eta_contract_cterm (Conjunction.mk_conjunction_balanced objs)); |
25824 | 143 |
|
144 |
fun first_order_mrs ths th = ths MRS |
|
145 |
Thm.instantiate (first_order_matchs (cprems_of th) (map cprop_of ths)) th; |
|
146 |
||
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
147 |
fun prove_strong_ind s avoids ctxt = |
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
148 |
let |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
149 |
val thy = ProofContext.theory_of ctxt; |
25824 | 150 |
val ({names, ...}, {raw_induct, intrs, elims, ...}) = |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
151 |
Inductive.the_inductive ctxt (Sign.intern_const thy s); |
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
152 |
val ind_params = Inductive.params_of raw_induct; |
24832 | 153 |
val raw_induct = atomize_induct ctxt raw_induct; |
25824 | 154 |
val elims = map (atomize_induct ctxt) elims; |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
155 |
val monos = Inductive.get_monos ctxt; |
24571 | 156 |
val eqvt_thms = NominalThmDecls.get_eqvt_thms ctxt; |
29287 | 157 |
val _ = (case names \\ fold (Term.add_const_names o Thm.prop_of) eqvt_thms [] of |
22788
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
158 |
[] => () |
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
159 |
| xs => error ("Missing equivariance theorem for predicate(s): " ^ |
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
160 |
commas_quote xs)); |
22530 | 161 |
val induct_cases = map fst (fst (RuleCases.get (the |
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset
|
162 |
(Induct.lookup_inductP ctxt (hd names))))); |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
163 |
val ([raw_induct'], ctxt') = Variable.import_terms false [prop_of raw_induct] ctxt; |
22530 | 164 |
val concls = raw_induct' |> Logic.strip_imp_concl |> HOLogic.dest_Trueprop |> |
165 |
HOLogic.dest_conj |> map (HOLogic.dest_imp ##> strip_comb); |
|
166 |
val ps = map (fst o snd) concls; |
|
167 |
||
168 |
val _ = (case duplicates (op = o pairself fst) avoids of |
|
169 |
[] => () |
|
170 |
| xs => error ("Duplicate case names: " ^ commas_quote (map fst xs))); |
|
171 |
val _ = assert_all (null o duplicates op = o snd) avoids |
|
172 |
(fn (a, _) => error ("Duplicate variable names for case " ^ quote a)); |
|
173 |
val _ = (case map fst avoids \\ induct_cases of |
|
174 |
[] => () |
|
175 |
| xs => error ("No such case(s) in inductive definition: " ^ commas_quote xs)); |
|
25824 | 176 |
val avoids' = if null induct_cases then replicate (length intrs) ("", []) |
177 |
else map (fn name => |
|
178 |
(name, the_default [] (AList.lookup op = avoids name))) induct_cases; |
|
22530 | 179 |
fun mk_avoids params (name, ps) = |
180 |
let val k = length params - 1 |
|
181 |
in map (fn x => case find_index (equal x o fst) params of |
|
182 |
~1 => error ("No such variable in case " ^ quote name ^ |
|
183 |
" of inductive definition: " ^ quote x) |
|
184 |
| i => (Bound (k - i), snd (nth params i))) ps |
|
185 |
end; |
|
186 |
||
187 |
val prems = map (fn (prem, avoid) => |
|
188 |
let |
|
189 |
val prems = map (incr_boundvars 1) (Logic.strip_assums_hyp prem); |
|
190 |
val concl = incr_boundvars 1 (Logic.strip_assums_concl prem); |
|
191 |
val params = Logic.strip_params prem |
|
192 |
in |
|
193 |
(params, |
|
194 |
fold (add_binders thy 0) (prems @ [concl]) [] @ |
|
195 |
map (apfst (incr_boundvars 1)) (mk_avoids params avoid), |
|
196 |
prems, strip_comb (HOLogic.dest_Trueprop concl)) |
|
197 |
end) (Logic.strip_imp_prems raw_induct' ~~ avoids'); |
|
198 |
||
199 |
val atomTs = distinct op = (maps (map snd o #2) prems); |
|
200 |
val ind_sort = if null atomTs then HOLogic.typeS |
|
201 |
else Sign.certify_sort thy (map (fn T => Sign.intern_class thy |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
202 |
("fs_" ^ Long_Name.base_name (fst (dest_Type T)))) atomTs); |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
203 |
val ([fs_ctxt_tyname], _) = Name.variants ["'n"] (Variable.names_of ctxt'); |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
204 |
val ([fs_ctxt_name], ctxt'') = Variable.variant_fixes ["z"] ctxt'; |
22530 | 205 |
val fsT = TFree (fs_ctxt_tyname, ind_sort); |
206 |
||
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
207 |
val inductive_forall_def' = Drule.instantiate' |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
208 |
[SOME (ctyp_of thy fsT)] [] inductive_forall_def; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
209 |
|
22530 | 210 |
fun lift_pred' t (Free (s, T)) ts = |
211 |
list_comb (Free (s, fsT --> T), t :: ts); |
|
212 |
val lift_pred = lift_pred' (Bound 0); |
|
213 |
||
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
214 |
fun lift_prem (t as (f $ u)) = |
22530 | 215 |
let val (p, ts) = strip_comb t |
216 |
in |
|
217 |
if p mem ps then |
|
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
218 |
Const (inductive_forall_name, |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
219 |
(fsT --> HOLogic.boolT) --> HOLogic.boolT) $ |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
220 |
Abs ("z", fsT, lift_pred p (map (incr_boundvars 1) ts)) |
22530 | 221 |
else lift_prem f $ lift_prem u |
222 |
end |
|
223 |
| lift_prem (Abs (s, T, t)) = Abs (s, T, lift_prem t) |
|
224 |
| lift_prem t = t; |
|
225 |
||
226 |
fun mk_distinct [] = [] |
|
227 |
| mk_distinct ((x, T) :: xs) = List.mapPartial (fn (y, U) => |
|
228 |
if T = U then SOME (HOLogic.mk_Trueprop |
|
229 |
(HOLogic.mk_not (HOLogic.eq_const T $ x $ y))) |
|
230 |
else NONE) xs @ mk_distinct xs; |
|
231 |
||
232 |
fun mk_fresh (x, T) = HOLogic.mk_Trueprop |
|
31938 | 233 |
(NominalDatatype.fresh_const T fsT $ x $ Bound 0); |
22530 | 234 |
|
235 |
val (prems', prems'') = split_list (map (fn (params, bvars, prems, (p, ts)) => |
|
236 |
let |
|
237 |
val params' = params @ [("y", fsT)]; |
|
238 |
val prem = Logic.list_implies |
|
239 |
(map mk_fresh bvars @ mk_distinct bvars @ |
|
240 |
map (fn prem => |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
241 |
if null (preds_of ps prem) then prem |
22530 | 242 |
else lift_prem prem) prems, |
243 |
HOLogic.mk_Trueprop (lift_pred p ts)); |
|
29276 | 244 |
val vs = map (Var o apfst (rpair 0)) (Term.rename_wrt_term prem params') |
22530 | 245 |
in |
246 |
(list_all (params', prem), (rev vs, subst_bounds (vs, prem))) |
|
247 |
end) prems); |
|
248 |
||
249 |
val ind_vars = |
|
250 |
(DatatypeProp.indexify_names (replicate (length atomTs) "pi") ~~ |
|
251 |
map NominalAtoms.mk_permT atomTs) @ [("z", fsT)]; |
|
252 |
val ind_Ts = rev (map snd ind_vars); |
|
253 |
||
254 |
val concl = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
|
255 |
(map (fn (prem, (p, ts)) => HOLogic.mk_imp (prem, |
|
256 |
HOLogic.list_all (ind_vars, lift_pred p |
|
31938 | 257 |
(map (fold_rev (NominalDatatype.mk_perm ind_Ts) |
22530 | 258 |
(map Bound (length atomTs downto 1))) ts)))) concls)); |
259 |
||
260 |
val concl' = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
|
261 |
(map (fn (prem, (p, ts)) => HOLogic.mk_imp (prem, |
|
262 |
lift_pred' (Free (fs_ctxt_name, fsT)) p ts)) concls)); |
|
263 |
||
264 |
val vc_compat = map (fn (params, bvars, prems, (p, ts)) => |
|
265 |
map (fn q => list_all (params, incr_boundvars ~1 (Logic.list_implies |
|
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
266 |
(List.mapPartial (fn prem => |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
267 |
if null (preds_of ps prem) then SOME prem |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
268 |
else map_term (split_conj (K o I) names) prem prem) prems, q)))) |
22530 | 269 |
(mk_distinct bvars @ |
270 |
maps (fn (t, T) => map (fn (u, U) => HOLogic.mk_Trueprop |
|
31938 | 271 |
(NominalDatatype.fresh_const U T $ u $ t)) bvars) |
22530 | 272 |
(ts ~~ binder_types (fastype_of p)))) prems; |
273 |
||
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
274 |
val perm_pi_simp = PureThy.get_thms thy "perm_pi_simp"; |
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
275 |
val pt2_atoms = map (fn aT => PureThy.get_thm thy |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
276 |
("pt_" ^ Long_Name.base_name (fst (dest_Type aT)) ^ "2")) atomTs; |
27352
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
277 |
val eqvt_ss = Simplifier.theory_context thy HOL_basic_ss |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
278 |
addsimps (eqvt_thms @ perm_pi_simp @ pt2_atoms) |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
279 |
addsimprocs [mk_perm_bool_simproc ["Fun.id"], |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
280 |
NominalPermeq.perm_simproc_app, NominalPermeq.perm_simproc_fun]; |
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
281 |
val fresh_bij = PureThy.get_thms thy "fresh_bij"; |
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
282 |
val perm_bij = PureThy.get_thms thy "perm_bij"; |
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
283 |
val fs_atoms = map (fn aT => PureThy.get_thm thy |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
284 |
("fs_" ^ Long_Name.base_name (fst (dest_Type aT)) ^ "1")) atomTs; |
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
285 |
val exists_fresh' = PureThy.get_thms thy "exists_fresh'"; |
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
286 |
val fresh_atm = PureThy.get_thms thy "fresh_atm"; |
27449
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
287 |
val swap_simps = PureThy.get_thms thy "swap_simps"; |
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
288 |
val perm_fresh_fresh = PureThy.get_thms thy "perm_fresh_fresh"; |
22530 | 289 |
|
290 |
fun obtain_fresh_name ts T (freshs1, freshs2, ctxt) = |
|
291 |
let |
|
27722
d657036e26c5
- corrected bogus comment for function inst_conj_all
berghofe
parents:
27449
diff
changeset
|
292 |
(** protect terms to avoid that fresh_prod interferes with **) |
22530 | 293 |
(** pairs used in introduction rules of inductive predicate **) |
294 |
fun protect t = |
|
295 |
let val T = fastype_of t in Const ("Fun.id", T --> T) $ t end; |
|
296 |
val p = foldr1 HOLogic.mk_prod (map protect ts @ freshs1); |
|
297 |
val ex = Goal.prove ctxt [] [] (HOLogic.mk_Trueprop |
|
298 |
(HOLogic.exists_const T $ Abs ("x", T, |
|
31938 | 299 |
NominalDatatype.fresh_const T (fastype_of p) $ |
22530 | 300 |
Bound 0 $ p))) |
301 |
(fn _ => EVERY |
|
302 |
[resolve_tac exists_fresh' 1, |
|
27722
d657036e26c5
- corrected bogus comment for function inst_conj_all
berghofe
parents:
27449
diff
changeset
|
303 |
resolve_tac fs_atoms 1]); |
32202 | 304 |
val (([(_, cx)], ths), ctxt') = Obtain.result |
22530 | 305 |
(fn _ => EVERY |
306 |
[etac exE 1, |
|
307 |
full_simp_tac (HOL_ss addsimps (fresh_prod :: fresh_atm)) 1, |
|
26359 | 308 |
full_simp_tac (HOL_basic_ss addsimps [@{thm id_apply}]) 1, |
22530 | 309 |
REPEAT (etac conjE 1)]) |
310 |
[ex] ctxt |
|
311 |
in (freshs1 @ [term_of cx], freshs2 @ ths, ctxt') end; |
|
312 |
||
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
313 |
fun mk_ind_proof ctxt' thss = |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
314 |
Goal.prove ctxt' [] prems' concl' (fn {prems = ihyps, context = ctxt} => |
22530 | 315 |
let val th = Goal.prove ctxt [] [] concl (fn {context, ...} => |
316 |
rtac raw_induct 1 THEN |
|
317 |
EVERY (maps (fn ((((_, bvars, oprems, _), vc_compat_ths), ihyp), (vs, ihypt)) => |
|
318 |
[REPEAT (rtac allI 1), simp_tac eqvt_ss 1, |
|
319 |
SUBPROOF (fn {prems = gprems, params, concl, context = ctxt', ...} => |
|
320 |
let |
|
321 |
val (params', (pis, z)) = |
|
32202 | 322 |
chop (length params - length atomTs - 1) (map (term_of o #2) params) ||> |
22530 | 323 |
split_last; |
324 |
val bvars' = map |
|
325 |
(fn (Bound i, T) => (nth params' (length params' - i), T) |
|
326 |
| (t, T) => (t, T)) bvars; |
|
327 |
val pi_bvars = map (fn (t, _) => |
|
31938 | 328 |
fold_rev (NominalDatatype.mk_perm []) pis t) bvars'; |
22530 | 329 |
val (P, ts) = strip_comb (HOLogic.dest_Trueprop (term_of concl)); |
330 |
val (freshs1, freshs2, ctxt'') = fold |
|
331 |
(obtain_fresh_name (ts @ pi_bvars)) |
|
332 |
(map snd bvars') ([], [], ctxt'); |
|
31938 | 333 |
val freshs2' = NominalDatatype.mk_not_sym freshs2; |
334 |
val pis' = map NominalDatatype.perm_of_pair (pi_bvars ~~ freshs1); |
|
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
335 |
fun concat_perm pi1 pi2 = |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
336 |
let val T = fastype_of pi1 |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
337 |
in if T = fastype_of pi2 then |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
338 |
Const ("List.append", T --> T --> T) $ pi1 $ pi2 |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
339 |
else pi2 |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
340 |
end; |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
341 |
val pis'' = fold (concat_perm #> map) pis' pis; |
22530 | 342 |
val env = Pattern.first_order_match thy (ihypt, prop_of ihyp) |
343 |
(Vartab.empty, Vartab.empty); |
|
344 |
val ihyp' = Thm.instantiate ([], map (pairself (cterm_of thy)) |
|
32035 | 345 |
(map (Envir.subst_term env) vs ~~ |
31938 | 346 |
map (fold_rev (NominalDatatype.mk_perm []) |
22530 | 347 |
(rev pis' @ pis)) params' @ [z])) ihyp; |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
348 |
fun mk_pi th = |
26359 | 349 |
Simplifier.simplify (HOL_basic_ss addsimps [@{thm id_apply}] |
31938 | 350 |
addsimprocs [NominalDatatype.perm_simproc]) |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
351 |
(Simplifier.simplify eqvt_ss |
25824 | 352 |
(fold_rev (mk_perm_bool o cterm_of thy) |
353 |
(rev pis' @ pis) th)); |
|
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
354 |
val (gprems1, gprems2) = split_list |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
355 |
(map (fn (th, t) => |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
356 |
if null (preds_of ps t) then (SOME th, mk_pi th) |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
357 |
else |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
358 |
(map_thm ctxt (split_conj (K o I) names) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
359 |
(etac conjunct1 1) monos NONE th, |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
360 |
mk_pi (the (map_thm ctxt (inst_conj_all names ps (rev pis'')) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
361 |
(inst_conj_all_tac (length pis'')) monos (SOME t) th)))) |
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
362 |
(gprems ~~ oprems)) |>> List.mapPartial I; |
22530 | 363 |
val vc_compat_ths' = map (fn th => |
364 |
let |
|
25824 | 365 |
val th' = first_order_mrs gprems1 th; |
22530 | 366 |
val (bop, lhs, rhs) = (case concl_of th' of |
367 |
_ $ (fresh $ lhs $ rhs) => |
|
368 |
(fn t => fn u => fresh $ t $ u, lhs, rhs) |
|
369 |
| _ $ (_ $ (_ $ lhs $ rhs)) => |
|
370 |
(curry (HOLogic.mk_not o HOLogic.mk_eq), lhs, rhs)); |
|
371 |
val th'' = Goal.prove ctxt'' [] [] (HOLogic.mk_Trueprop |
|
31938 | 372 |
(bop (fold_rev (NominalDatatype.mk_perm []) pis lhs) |
373 |
(fold_rev (NominalDatatype.mk_perm []) pis rhs))) |
|
22530 | 374 |
(fn _ => simp_tac (HOL_basic_ss addsimps |
375 |
(fresh_bij @ perm_bij)) 1 THEN rtac th' 1) |
|
376 |
in Simplifier.simplify (eqvt_ss addsimps fresh_atm) th'' end) |
|
377 |
vc_compat_ths; |
|
31938 | 378 |
val vc_compat_ths'' = NominalDatatype.mk_not_sym vc_compat_ths'; |
27449
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
379 |
(** Since swap_simps simplifies (pi :: 'a prm) o (x :: 'b) to x **) |
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
380 |
(** we have to pre-simplify the rewrite rules **) |
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
381 |
val swap_simps_ss = HOL_ss addsimps swap_simps @ |
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
382 |
map (Simplifier.simplify (HOL_ss addsimps swap_simps)) |
22530 | 383 |
(vc_compat_ths'' @ freshs2'); |
384 |
val th = Goal.prove ctxt'' [] [] |
|
385 |
(HOLogic.mk_Trueprop (list_comb (P $ hd ts, |
|
31938 | 386 |
map (fold (NominalDatatype.mk_perm []) pis') (tl ts)))) |
22530 | 387 |
(fn _ => EVERY ([simp_tac eqvt_ss 1, rtac ihyp' 1, |
388 |
REPEAT_DETERM_N (nprems_of ihyp - length gprems) |
|
27449
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
389 |
(simp_tac swap_simps_ss 1), |
22530 | 390 |
REPEAT_DETERM_N (length gprems) |
27847
0dffedf9aff5
Changed proof of strong induction rule to avoid infinite loop
berghofe
parents:
27722
diff
changeset
|
391 |
(simp_tac (HOL_basic_ss |
0dffedf9aff5
Changed proof of strong induction rule to avoid infinite loop
berghofe
parents:
27722
diff
changeset
|
392 |
addsimps [inductive_forall_def'] |
31938 | 393 |
addsimprocs [NominalDatatype.perm_simproc]) 1 THEN |
27847
0dffedf9aff5
Changed proof of strong induction rule to avoid infinite loop
berghofe
parents:
27722
diff
changeset
|
394 |
resolve_tac gprems2 1)])); |
22530 | 395 |
val final = Goal.prove ctxt'' [] [] (term_of concl) |
396 |
(fn _ => cut_facts_tac [th] 1 THEN full_simp_tac (HOL_ss |
|
397 |
addsimps vc_compat_ths'' @ freshs2' @ |
|
398 |
perm_fresh_fresh @ fresh_atm) 1); |
|
399 |
val final' = ProofContext.export ctxt'' ctxt' [final]; |
|
400 |
in resolve_tac final' 1 end) context 1]) |
|
401 |
(prems ~~ thss ~~ ihyps ~~ prems''))) |
|
402 |
in |
|
403 |
cut_facts_tac [th] 1 THEN REPEAT (etac conjE 1) THEN |
|
404 |
REPEAT (REPEAT (resolve_tac [conjI, impI] 1) THEN |
|
27228
4f7976a6ffc3
allE_Nil: only one copy, proven in regular theory source;
wenzelm
parents:
27153
diff
changeset
|
405 |
etac impE 1 THEN atac 1 THEN REPEAT (etac @{thm allE_Nil} 1) THEN |
32149
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
32035
diff
changeset
|
406 |
asm_full_simp_tac (simpset_of ctxt) 1) |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
407 |
end) |> singleton (ProofContext.export ctxt' ctxt); |
22530 | 408 |
|
25824 | 409 |
(** strong case analysis rule **) |
410 |
||
411 |
val cases_prems = map (fn ((name, avoids), rule) => |
|
412 |
let |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
413 |
val ([rule'], ctxt') = Variable.import_terms false [prop_of rule] ctxt; |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
414 |
val prem :: prems = Logic.strip_imp_prems rule'; |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
415 |
val concl = Logic.strip_imp_concl rule' |
25824 | 416 |
in |
417 |
(prem, |
|
418 |
List.drop (snd (strip_comb (HOLogic.dest_Trueprop prem)), length ind_params), |
|
419 |
concl, |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
420 |
fold_map (fn (prem, (_, avoid)) => fn ctxt => |
25824 | 421 |
let |
422 |
val prems = Logic.strip_assums_hyp prem; |
|
423 |
val params = Logic.strip_params prem; |
|
424 |
val bnds = fold (add_binders thy 0) prems [] @ mk_avoids params avoid; |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
425 |
fun mk_subst (p as (s, T)) (i, j, ctxt, ps, qs, is, ts) = |
25824 | 426 |
if member (op = o apsnd fst) bnds (Bound i) then |
427 |
let |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
428 |
val ([s'], ctxt') = Variable.variant_fixes [s] ctxt; |
25824 | 429 |
val t = Free (s', T) |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
430 |
in (i + 1, j, ctxt', ps, (t, T) :: qs, i :: is, t :: ts) end |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
431 |
else (i + 1, j + 1, ctxt, p :: ps, qs, is, Bound j :: ts); |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
432 |
val (_, _, ctxt', ps, qs, is, ts) = fold_rev mk_subst params |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
433 |
(0, 0, ctxt, [], [], [], []) |
25824 | 434 |
in |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
435 |
((ps, qs, is, map (curry subst_bounds (rev ts)) prems), ctxt') |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
436 |
end) (prems ~~ avoids) ctxt') |
25824 | 437 |
end) |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
438 |
(Inductive.partition_rules' raw_induct (intrs ~~ avoids') ~~ |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
439 |
elims); |
25824 | 440 |
|
441 |
val cases_prems' = |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
442 |
map (fn (prem, args, concl, (prems, _)) => |
25824 | 443 |
let |
444 |
fun mk_prem (ps, [], _, prems) = |
|
445 |
list_all (ps, Logic.list_implies (prems, concl)) |
|
446 |
| mk_prem (ps, qs, _, prems) = |
|
447 |
list_all (ps, Logic.mk_implies |
|
448 |
(Logic.list_implies |
|
449 |
(mk_distinct qs @ |
|
450 |
maps (fn (t, T) => map (fn u => HOLogic.mk_Trueprop |
|
31938 | 451 |
(NominalDatatype.fresh_const T (fastype_of u) $ t $ u)) |
25824 | 452 |
args) qs, |
453 |
HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
|
454 |
(map HOLogic.dest_Trueprop prems))), |
|
455 |
concl)) |
|
456 |
in map mk_prem prems end) cases_prems; |
|
457 |
||
27352
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
458 |
val cases_eqvt_ss = Simplifier.theory_context thy HOL_ss |
27449
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
459 |
addsimps eqvt_thms @ swap_simps @ perm_pi_simp |
27352
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
460 |
addsimprocs [NominalPermeq.perm_simproc_app, |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
461 |
NominalPermeq.perm_simproc_fun]; |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
462 |
|
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
463 |
val simp_fresh_atm = map |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
464 |
(Simplifier.simplify (HOL_basic_ss addsimps fresh_atm)); |
25824 | 465 |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
466 |
fun mk_cases_proof ((((name, thss), elim), (prem, args, concl, (prems, ctxt'))), |
25824 | 467 |
prems') = |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
468 |
(name, Goal.prove ctxt' [] (prem :: prems') concl |
26711 | 469 |
(fn {prems = hyp :: hyps, context = ctxt1} => |
25824 | 470 |
EVERY (rtac (hyp RS elim) 1 :: |
471 |
map (fn (((_, vc_compat_ths), case_hyp), (_, qs, is, _)) => |
|
472 |
SUBPROOF (fn {prems = case_hyps, params, context = ctxt2, concl, ...} => |
|
473 |
if null qs then |
|
474 |
rtac (first_order_mrs case_hyps case_hyp) 1 |
|
475 |
else |
|
476 |
let |
|
32202 | 477 |
val params' = map (term_of o #2 o nth (rev params)) is; |
25824 | 478 |
val tab = params' ~~ map fst qs; |
479 |
val (hyps1, hyps2) = chop (length args) case_hyps; |
|
480 |
(* turns a = t and [x1 # t, ..., xn # t] *) |
|
481 |
(* into [x1 # a, ..., xn # a] *) |
|
482 |
fun inst_fresh th' ths = |
|
483 |
let val (ths1, ths2) = chop (length qs) ths |
|
484 |
in |
|
485 |
(map (fn th => |
|
486 |
let |
|
487 |
val (cf, ct) = |
|
488 |
Thm.dest_comb (Thm.dest_arg (cprop_of th)); |
|
489 |
val arg_cong' = Drule.instantiate' |
|
490 |
[SOME (ctyp_of_term ct)] |
|
491 |
[NONE, SOME ct, SOME cf] (arg_cong RS iffD2); |
|
492 |
val inst = Thm.first_order_match (ct, |
|
493 |
Thm.dest_arg (Thm.dest_arg (cprop_of th'))) |
|
494 |
in [th', th] MRS Thm.instantiate inst arg_cong' |
|
495 |
end) ths1, |
|
496 |
ths2) |
|
497 |
end; |
|
498 |
val (vc_compat_ths1, vc_compat_ths2) = |
|
499 |
chop (length vc_compat_ths - length args * length qs) |
|
500 |
(map (first_order_mrs hyps2) vc_compat_ths); |
|
501 |
val vc_compat_ths' = |
|
31938 | 502 |
NominalDatatype.mk_not_sym vc_compat_ths1 @ |
25824 | 503 |
flat (fst (fold_map inst_fresh hyps1 vc_compat_ths2)); |
504 |
val (freshs1, freshs2, ctxt3) = fold |
|
505 |
(obtain_fresh_name (args @ map fst qs @ params')) |
|
506 |
(map snd qs) ([], [], ctxt2); |
|
31938 | 507 |
val freshs2' = NominalDatatype.mk_not_sym freshs2; |
508 |
val pis = map (NominalDatatype.perm_of_pair) |
|
25824 | 509 |
((freshs1 ~~ map fst qs) @ (params' ~~ freshs1)); |
510 |
val mk_pis = fold_rev mk_perm_bool (map (cterm_of thy) pis); |
|
511 |
val obj = cterm_of thy (foldr1 HOLogic.mk_conj (map (map_aterms |
|
512 |
(fn x as Free _ => |
|
513 |
if x mem args then x |
|
514 |
else (case AList.lookup op = tab x of |
|
515 |
SOME y => y |
|
31938 | 516 |
| NONE => fold_rev (NominalDatatype.mk_perm []) pis x) |
25824 | 517 |
| x => x) o HOLogic.dest_Trueprop o prop_of) case_hyps)); |
518 |
val inst = Thm.first_order_match (Thm.dest_arg |
|
519 |
(Drule.strip_imp_concl (hd (cprems_of case_hyp))), obj); |
|
520 |
val th = Goal.prove ctxt3 [] [] (term_of concl) |
|
521 |
(fn {context = ctxt4, ...} => |
|
522 |
rtac (Thm.instantiate inst case_hyp) 1 THEN |
|
523 |
SUBPROOF (fn {prems = fresh_hyps, ...} => |
|
524 |
let |
|
31938 | 525 |
val fresh_hyps' = NominalDatatype.mk_not_sym fresh_hyps; |
27352
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
526 |
val case_ss = cases_eqvt_ss addsimps freshs2' @ |
8adeff7fd4bc
- Equivariance simpset used in proofs of strong induction and inversion
berghofe
parents:
27228
diff
changeset
|
527 |
simp_fresh_atm (vc_compat_ths' @ fresh_hyps'); |
25824 | 528 |
val fresh_fresh_ss = case_ss addsimps perm_fresh_fresh; |
529 |
val hyps1' = map |
|
530 |
(mk_pis #> Simplifier.simplify fresh_fresh_ss) hyps1; |
|
531 |
val hyps2' = map |
|
532 |
(mk_pis #> Simplifier.simplify case_ss) hyps2; |
|
27449
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
533 |
val case_hyps' = hyps1' @ hyps2' |
25824 | 534 |
in |
27449
4880da911af0
Rewrote code to use swap_simps rather than calc_atm (which tends to
berghofe
parents:
27353
diff
changeset
|
535 |
simp_tac case_ss 1 THEN |
25824 | 536 |
REPEAT_DETERM (TRY (rtac conjI 1) THEN |
537 |
resolve_tac case_hyps' 1) |
|
538 |
end) ctxt4 1) |
|
539 |
val final = ProofContext.export ctxt3 ctxt2 [th] |
|
540 |
in resolve_tac final 1 end) ctxt1 1) |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
541 |
(thss ~~ hyps ~~ prems))) |> |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
542 |
singleton (ProofContext.export ctxt' ctxt)) |
25824 | 543 |
|
22530 | 544 |
in |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
545 |
ctxt'' |> |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
546 |
Proof.theorem_i NONE (fn thss => fn ctxt => |
22530 | 547 |
let |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
548 |
val rec_name = space_implode "_" (map Long_Name.base_name names); |
30223
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
wenzelm
parents:
30087
diff
changeset
|
549 |
val rec_qualified = Binding.qualify false rec_name; |
22530 | 550 |
val ind_case_names = RuleCases.case_names induct_cases; |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
551 |
val induct_cases' = Inductive.partition_rules' raw_induct |
25824 | 552 |
(intrs ~~ induct_cases); |
553 |
val thss' = map (map atomize_intr) thss; |
|
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
554 |
val thsss = Inductive.partition_rules' raw_induct (intrs ~~ thss'); |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
555 |
val strong_raw_induct = |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
556 |
mk_ind_proof ctxt thss' |> Inductive.rulify; |
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
557 |
val strong_cases = map (mk_cases_proof ##> Inductive.rulify) |
25824 | 558 |
(thsss ~~ elims ~~ cases_prems ~~ cases_prems'); |
22530 | 559 |
val strong_induct = |
560 |
if length names > 1 then |
|
561 |
(strong_raw_induct, [ind_case_names, RuleCases.consumes 0]) |
|
562 |
else (strong_raw_induct RSN (2, rev_mp), |
|
563 |
[ind_case_names, RuleCases.consumes 1]); |
|
31177 | 564 |
val ((_, [strong_induct']), ctxt') = LocalTheory.note Thm.generatedK |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
565 |
((rec_qualified (Binding.name "strong_induct"), |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
566 |
map (Attrib.internal o K) (#2 strong_induct)), [#1 strong_induct]) |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
567 |
ctxt; |
22530 | 568 |
val strong_inducts = |
32172 | 569 |
Project_Rule.projects ctxt (1 upto length names) strong_induct' |
22530 | 570 |
in |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
571 |
ctxt' |> |
31177 | 572 |
LocalTheory.note Thm.generatedK |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
573 |
((rec_qualified (Binding.name "strong_inducts"), |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
574 |
[Attrib.internal (K ind_case_names), |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
575 |
Attrib.internal (K (RuleCases.consumes 1))]), |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
576 |
strong_inducts) |> snd |> |
31177 | 577 |
LocalTheory.notes Thm.generatedK (map (fn ((name, elim), (_, cases)) => |
30435
e62d6ecab6ad
explicit Binding.qualified_name -- prevents implicitly qualified bstring;
wenzelm
parents:
30364
diff
changeset
|
578 |
((Binding.qualified_name (Long_Name.qualify (Long_Name.base_name name) "strong_cases"), |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
579 |
[Attrib.internal (K (RuleCases.case_names (map snd cases))), |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
580 |
Attrib.internal (K (RuleCases.consumes 1))]), [([elim], [])])) |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
581 |
(strong_cases ~~ induct_cases')) |> snd |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
582 |
end) |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
583 |
(map (map (rulify_term thy #> rpair [])) vc_compat) |
22530 | 584 |
end; |
585 |
||
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
586 |
fun prove_eqvt s xatoms ctxt = |
22530 | 587 |
let |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
588 |
val thy = ProofContext.theory_of ctxt; |
22788
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
589 |
val ({names, ...}, {raw_induct, intrs, elims, ...}) = |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
590 |
Inductive.the_inductive ctxt (Sign.intern_const thy s); |
24832 | 591 |
val raw_induct = atomize_induct ctxt raw_induct; |
592 |
val elims = map (atomize_induct ctxt) elims; |
|
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
593 |
val intrs = map atomize_intr intrs; |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
594 |
val monos = Inductive.get_monos ctxt; |
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
595 |
val intrs' = Inductive.unpartition_rules intrs |
22788
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
596 |
(map (fn (((s, ths), (_, k)), th) => |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
597 |
(s, ths ~~ Inductive.infer_intro_vars th k ths)) |
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
598 |
(Inductive.partition_rules raw_induct intrs ~~ |
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
599 |
Inductive.arities_of raw_induct ~~ elims)); |
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31177
diff
changeset
|
600 |
val k = length (Inductive.params_of raw_induct); |
22730
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
601 |
val atoms' = NominalAtoms.atoms_of thy; |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
602 |
val atoms = |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
603 |
if null xatoms then atoms' else |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
604 |
let val atoms = map (Sign.intern_type thy) xatoms |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
605 |
in |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
606 |
(case duplicates op = atoms of |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
607 |
[] => () |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
608 |
| xs => error ("Duplicate atoms: " ^ commas xs); |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
609 |
case atoms \\ atoms' of |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
610 |
[] => () |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
611 |
| xs => error ("No such atoms: " ^ commas xs); |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
612 |
atoms) |
8bcc8809ed3b
nominal_inductive no longer proves equivariance.
berghofe
parents:
22544
diff
changeset
|
613 |
end; |
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26337
diff
changeset
|
614 |
val perm_pi_simp = PureThy.get_thms thy "perm_pi_simp"; |
26364
cb6f360ab425
Equivariance prover now uses permutation simprocs as well.
berghofe
parents:
26359
diff
changeset
|
615 |
val eqvt_ss = Simplifier.theory_context thy HOL_basic_ss addsimps |
24571 | 616 |
(NominalThmDecls.get_eqvt_thms ctxt @ perm_pi_simp) addsimprocs |
26364
cb6f360ab425
Equivariance prover now uses permutation simprocs as well.
berghofe
parents:
26359
diff
changeset
|
617 |
[mk_perm_bool_simproc names, |
cb6f360ab425
Equivariance prover now uses permutation simprocs as well.
berghofe
parents:
26359
diff
changeset
|
618 |
NominalPermeq.perm_simproc_app, NominalPermeq.perm_simproc_fun]; |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
619 |
val (([t], [pi]), ctxt') = ctxt |> |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
620 |
Variable.import_terms false [concl_of raw_induct] ||>> |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
621 |
Variable.variant_fixes ["pi"]; |
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
622 |
val ps = map (fst o HOLogic.dest_imp) |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
623 |
(HOLogic.dest_conj (HOLogic.dest_Trueprop t)); |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
624 |
fun eqvt_tac ctxt'' pi (intr, vs) st = |
22544 | 625 |
let |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
626 |
fun eqvt_err s = |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
627 |
let val ([t], ctxt''') = Variable.import_terms true [prop_of intr] ctxt |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
628 |
in error ("Could not prove equivariance for introduction rule\n" ^ |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
629 |
Syntax.string_of_term ctxt''' t ^ "\n" ^ s) |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
630 |
end; |
22788
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
631 |
val res = SUBPROOF (fn {prems, params, ...} => |
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
632 |
let |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
633 |
val prems' = map (fn th => the_default th (map_thm ctxt' |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
634 |
(split_conj (K I) names) (etac conjunct2 1) monos NONE th)) prems; |
25824 | 635 |
val prems'' = map (fn th => Simplifier.simplify eqvt_ss |
636 |
(mk_perm_bool (cterm_of thy pi) th)) prems'; |
|
22788
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
637 |
val intr' = Drule.cterm_instantiate (map (cterm_of thy) vs ~~ |
32202 | 638 |
map (cterm_of thy o NominalDatatype.mk_perm [] pi o term_of o #2) params) |
22788
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
639 |
intr |
24570
621b60b1df00
Generalized equivariance and nominal_inductive commands to
berghofe
parents:
23531
diff
changeset
|
640 |
in (rtac intr' THEN_ALL_NEW (TRY o resolve_tac prems'')) 1 |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
641 |
end) ctxt' 1 st |
22544 | 642 |
in |
643 |
case (Seq.pull res handle THM (s, _, _) => eqvt_err s) of |
|
644 |
NONE => eqvt_err ("Rule does not match goal\n" ^ |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
645 |
Syntax.string_of_term ctxt'' (hd (prems_of st))) |
22544 | 646 |
| SOME (th, _) => Seq.single th |
647 |
end; |
|
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
648 |
val thss = map (fn atom => |
25824 | 649 |
let val pi' = Free (pi, NominalAtoms.mk_permT (Type (atom, []))) |
22530 | 650 |
in map (fn th => zero_var_indexes (th RS mp)) |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
651 |
(DatatypeAux.split_conj_thm (Goal.prove ctxt' [] [] |
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
652 |
(HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj (map (fn p => |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
653 |
let |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
654 |
val (h, ts) = strip_comb p; |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
655 |
val (ts1, ts2) = chop k ts |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
656 |
in |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
657 |
HOLogic.mk_imp (p, list_comb (h, ts1 @ |
31938 | 658 |
map (NominalDatatype.mk_perm [] pi') ts2)) |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
659 |
end) ps))) |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
660 |
(fn {context, ...} => EVERY (rtac raw_induct 1 :: map (fn intr_vs => |
22788
3038bd211582
eqvt_tac now instantiates introduction rules before applying them.
berghofe
parents:
22755
diff
changeset
|
661 |
full_simp_tac eqvt_ss 1 THEN |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
662 |
eqvt_tac context pi' intr_vs) intrs')) |> |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
663 |
singleton (ProofContext.export ctxt' ctxt))) |
22544 | 664 |
end) atoms |
665 |
in |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
666 |
ctxt |> |
31177 | 667 |
LocalTheory.notes Thm.generatedK (map (fn (name, ths) => |
30435
e62d6ecab6ad
explicit Binding.qualified_name -- prevents implicitly qualified bstring;
wenzelm
parents:
30364
diff
changeset
|
668 |
((Binding.qualified_name (Long_Name.qualify (Long_Name.base_name name) "eqvt"), |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
669 |
[Attrib.internal (K NominalThmDecls.eqvt_add)]), [(ths, [])])) |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
670 |
(names ~~ transp thss)) |> snd |
22544 | 671 |
end; |
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
672 |
|
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
673 |
|
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
674 |
(* outer syntax *) |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
675 |
|
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
676 |
local structure P = OuterParse and K = OuterKeyword in |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
677 |
|
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27352
diff
changeset
|
678 |
val _ = OuterKeyword.keyword "avoids"; |
24867 | 679 |
|
680 |
val _ = |
|
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
681 |
OuterSyntax.local_theory_to_proof "nominal_inductive" |
22530 | 682 |
"prove equivariance and strong induction theorem for inductive predicate involving nominal datatypes" K.thy_goal |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
683 |
(P.xname -- Scan.optional (P.$$$ "avoids" |-- P.and_list1 (P.name -- |
22530 | 684 |
(P.$$$ ":" |-- Scan.repeat1 P.name))) [] >> (fn (name, avoids) => |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
685 |
prove_strong_ind name avoids)); |
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
686 |
|
24867 | 687 |
val _ = |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
688 |
OuterSyntax.local_theory "equivariance" |
22530 | 689 |
"prove equivariance for inductive predicate involving nominal datatypes" K.thy_decl |
30087
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
690 |
(P.xname -- Scan.optional (P.$$$ "[" |-- P.list1 P.name --| P.$$$ "]") [] >> |
a780642a9c9c
nominal_inductive and equivariance now work on local_theory.
berghofe
parents:
29585
diff
changeset
|
691 |
(fn (name, atoms) => prove_eqvt name atoms)); |
22530 | 692 |
|
22313
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
693 |
end; |
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
694 |
|
1a507b463f50
First steps towards strengthening of induction rules for
berghofe
parents:
diff
changeset
|
695 |
end |