author | Christian Urban <urbanc@in.tum.de> |
Sat, 26 Nov 2011 09:48:14 +0000 | |
changeset 3053 | 324b148fc6b5 |
parent 3045 | d0ad264f8c4f |
child 3090 | 19f5e7afad89 |
permissions | -rw-r--r-- |
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
(* Title: nominal_eqvt.ML |
1835
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
2 |
Author: Stefan Berghofer (original code) |
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
Author: Christian Urban |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
Automatic proofs for equivariance of inductive predicates. |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
*) |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
|
2765
7ac5e5c86c7d
introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
8 |
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
signature NOMINAL_EQVT = |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
sig |
2868
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
11 |
val raw_equivariance: term list -> thm -> thm list -> Proof.context -> thm list |
2107
5686d83db1f9
ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents:
2081
diff
changeset
|
12 |
val equivariance_cmd: string -> Proof.context -> local_theory |
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
end |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
structure Nominal_Eqvt : NOMINAL_EQVT = |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
struct |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
17 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
open Nominal_Permeq; |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
open Nominal_ThmDecls; |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
21 |
val atomize_conv = |
2620
81921f8ad245
updated to Isabelle 22 December
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
22 |
Raw_Simplifier.rewrite_cterm (true, false, false) (K (K NONE)) |
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
(HOL_basic_ss addsimps @{thms induct_atomize}); |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
val atomize_intr = Conv.fconv_rule (Conv.prems_conv ~1 atomize_conv); |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
fun atomize_induct ctxt = Conv.fconv_rule (Conv.prems_conv ~1 |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
(Conv.params_conv ~1 (K (Conv.prems_conv ~1 atomize_conv)) ctxt)); |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
|
1835
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
28 |
|
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
29 |
(** equivariance tactics **) |
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
30 |
|
1866
6d4e4bf9bce6
automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents:
1861
diff
changeset
|
31 |
val perm_boolE = @{thm permute_boolE} |
6d4e4bf9bce6
automatic proofs for equivariance of alphas
Christian Urban <urbanc@in.tum.de>
parents:
1861
diff
changeset
|
32 |
|
1948 | 33 |
fun eqvt_rel_single_case_tac ctxt pred_names pi intro = |
2477 | 34 |
let |
3045
d0ad264f8c4f
updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents:
2885
diff
changeset
|
35 |
val thy = Proof_Context.theory_of ctxt |
2477 | 36 |
val cpi = Thm.cterm_of thy (mk_minus pi) |
37 |
val pi_intro_rule = Drule.instantiate' [] [SOME cpi] perm_boolE |
|
38 |
val simps1 = HOL_basic_ss addsimps @{thms permute_fun_def minus_minus split_paired_all} |
|
39 |
val simps2 = HOL_basic_ss addsimps @{thms permute_bool_def} |
|
2765
7ac5e5c86c7d
introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
40 |
val eqvt_sconfig = |
7ac5e5c86c7d
introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
41 |
eqvt_strict_config addpres @{thms permute_minus_cancel(2)} addexcls pred_names |
2477 | 42 |
in |
2765
7ac5e5c86c7d
introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
43 |
eqvt_tac ctxt (eqvt_strict_config addexcls pred_names) THEN' |
2477 | 44 |
SUBPROOF (fn {prems, context as ctxt, ...} => |
45 |
let |
|
46 |
val prems' = map (transform_prem2 ctxt pred_names) prems |
|
47 |
val tac1 = resolve_tac prems' |
|
48 |
val tac2 = EVERY' [ rtac pi_intro_rule, |
|
2765
7ac5e5c86c7d
introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
49 |
eqvt_tac ctxt eqvt_sconfig, resolve_tac prems' ] |
2477 | 50 |
val tac3 = EVERY' [ rtac pi_intro_rule, |
2765
7ac5e5c86c7d
introduced framework for finetuning eqvt-rules; this solves problem with permute_pure called in nominal_inductive
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
51 |
eqvt_tac ctxt eqvt_sconfig, simp_tac simps1, |
2477 | 52 |
simp_tac simps2, resolve_tac prems'] |
53 |
in |
|
54 |
(rtac intro THEN_ALL_NEW FIRST' [tac1, tac2, tac3]) 1 |
|
55 |
end) ctxt |
|
56 |
end |
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
|
1835
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
58 |
fun eqvt_rel_tac ctxt pred_names pi induct intros = |
2477 | 59 |
let |
60 |
val cases = map (eqvt_rel_single_case_tac ctxt pred_names pi) intros |
|
61 |
in |
|
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
62 |
EVERY' ((DETERM o rtac induct) :: cases) |
2477 | 63 |
end |
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
|
1835
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
65 |
|
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
66 |
(** equivariance procedure *) |
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
67 |
|
2107
5686d83db1f9
ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents:
2081
diff
changeset
|
68 |
fun prepare_goal pi pred = |
2477 | 69 |
let |
70 |
val (c, xs) = strip_comb pred; |
|
71 |
in |
|
72 |
HOLogic.mk_imp (pred, list_comb (c, map (mk_perm pi) xs)) |
|
73 |
end |
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
|
1835
636de31888a6
tuned and removed dead code
Christian Urban <urbanc@in.tum.de>
parents:
1833
diff
changeset
|
75 |
(* stores thm under name.eqvt and adds [eqvt]-attribute *) |
2477 | 76 |
|
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
77 |
fun get_name (Const (a, _)) = a |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
78 |
| get_name (Free (a, _)) = a |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
79 |
|
2868
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
80 |
fun raw_equivariance pred_trms raw_induct intrs ctxt = |
2477 | 81 |
let |
82 |
val is_already_eqvt = |
|
83 |
filter (is_eqvt ctxt) pred_trms |
|
84 |
|> map (Syntax.string_of_term ctxt) |
|
85 |
val _ = if null is_already_eqvt then () |
|
86 |
else error ("Already equivariant: " ^ commas is_already_eqvt) |
|
2117
b3a5bda07007
added a test whether some of the constants already equivariant (then the procedure has to fail).
Christian Urban <urbanc@in.tum.de>
parents:
2110
diff
changeset
|
87 |
|
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
88 |
val pred_names = map get_name pred_trms |
2477 | 89 |
val raw_induct' = atomize_induct ctxt raw_induct |
90 |
val intrs' = map atomize_intr intrs |
|
91 |
||
92 |
val (([raw_concl], [raw_pi]), ctxt') = |
|
93 |
ctxt |
|
94 |
|> Variable.import_terms false [concl_of raw_induct'] |
|
95 |
||>> Variable.variant_fixes ["p"] |
|
96 |
val pi = Free (raw_pi, @{typ perm}) |
|
97 |
||
98 |
val preds = map (fst o HOLogic.dest_imp) |
|
99 |
(HOLogic.dest_conj (HOLogic.dest_Trueprop raw_concl)); |
|
100 |
||
101 |
val goal = HOLogic.mk_Trueprop |
|
2868
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
102 |
(foldr1 HOLogic.mk_conj (map (prepare_goal pi) preds)) |
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
103 |
in |
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
104 |
Goal.prove ctxt' [] [] goal |
2477 | 105 |
(fn {context,...} => eqvt_rel_tac context pred_names pi raw_induct' intrs' 1) |
106 |
|> Datatype_Aux.split_conj_thm |
|
3045
d0ad264f8c4f
updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents:
2885
diff
changeset
|
107 |
|> Proof_Context.export ctxt' ctxt |
2477 | 108 |
|> map (fn th => th RS mp) |
109 |
|> map zero_var_indexes |
|
110 |
end |
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
|
2885
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
parents:
2868
diff
changeset
|
112 |
|
2868
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
113 |
fun note_named_thm (name, thm) ctxt = |
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
114 |
let |
2868
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
115 |
val thm_name = Binding.qualified_name |
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
116 |
(Long_Name.qualify (Long_Name.base_name name) "eqvt") |
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
117 |
val attr = Attrib.internal (K eqvt_add) |
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
118 |
val ((_, [thm']), ctxt') = Local_Theory.note ((thm_name, [attr]), [thm]) ctxt |
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
119 |
in |
2868
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
120 |
(thm', ctxt') |
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
121 |
end |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2620
diff
changeset
|
122 |
|
2107
5686d83db1f9
ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents:
2081
diff
changeset
|
123 |
fun equivariance_cmd pred_name ctxt = |
2477 | 124 |
let |
3045
d0ad264f8c4f
updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents:
2885
diff
changeset
|
125 |
val thy = Proof_Context.theory_of ctxt |
2868
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
126 |
val ({names, ...}, {preds, raw_induct, intrs, ...}) = |
2477 | 127 |
Inductive.the_inductive ctxt (Sign.intern_const thy pred_name) |
2885
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
parents:
2868
diff
changeset
|
128 |
val thms = raw_equivariance preds raw_induct intrs ctxt |
2477 | 129 |
in |
2868
2b8e387d2dfc
got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents:
2778
diff
changeset
|
130 |
fold_map note_named_thm (names ~~ thms) ctxt |> snd |
2477 | 131 |
end |
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
|
2168 | 133 |
local structure P = Parse and K = Keyword in |
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
134 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
135 |
val _ = |
2168 | 136 |
Outer_Syntax.local_theory "equivariance" |
1948 | 137 |
"Proves equivariance for inductive predicate involving nominal datatypes." |
2107
5686d83db1f9
ingnored parameters in equivariance; added a proper interface to be called from ML
Christian Urban <urbanc@in.tum.de>
parents:
2081
diff
changeset
|
138 |
K.thy_decl (P.xname >> equivariance_cmd); |
2477 | 139 |
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
140 |
end; |
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
141 |
|
2069
2b6ba4d4e19a
Fixes for new isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
2064
diff
changeset
|
142 |
end (* structure *) |