author | Christian Urban <urbanc@in.tum.de> |
Wed, 29 Feb 2012 04:56:06 +0000 | |
changeset 3128 | 4bad521e3b9e |
parent 3045 | d0ad264f8c4f |
child 3214 | 13ab4f0a0b0e |
permissions | -rw-r--r-- |
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
1 |
(* Title: nominal_thmdecls.ML |
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
2 |
Author: Christian Urban |
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
3 |
|
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
4 |
Infrastructure for the lemma collection "eqvts". |
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
5 |
|
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
6 |
Provides the attributes [eqvt] and [eqvt_raw], and the theorem |
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
7 |
lists eqvts and eqvts_raw. The first attribute will store the |
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
8 |
theorem in the eqvts list and also in the eqvts_raw list. For |
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
9 |
the latter the theorem is expected to be of the form |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
|
1811
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
11 |
p o (c x1 x2 ...) = c (p o x1) (p o x2) ... (1) |
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
12 |
|
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
13 |
or |
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
14 |
|
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
15 |
c x1 x2 ... ==> c (p o x1) (p o x2) ... (2) |
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
16 |
|
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
17 |
and it is stored in the form |
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
18 |
|
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
19 |
p o c == c |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
|
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
21 |
The [eqvt_raw] attribute just adds the theorem to eqvts_raw. |
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
22 |
|
1811
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
23 |
TODO: In case of the form in (2) one should also |
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
24 |
add the equational form to eqvts |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
*) |
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
|
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
signature NOMINAL_THMDECLS = |
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
sig |
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
val eqvt_add: attribute |
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
val eqvt_del: attribute |
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
31 |
val eqvt_raw_add: attribute |
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
32 |
val eqvt_raw_del: attribute |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
val setup: theory -> theory |
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
34 |
val get_eqvts_thms: Proof.context -> thm list |
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
35 |
val get_eqvts_raw_thms: Proof.context -> thm list |
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
36 |
val eqvt_transform: Proof.context -> thm -> thm |
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
37 |
val is_eqvt: Proof.context -> term -> bool |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
38 |
end; |
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
39 |
|
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
40 |
structure Nominal_ThmDecls: NOMINAL_THMDECLS = |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
struct |
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
|
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
43 |
structure EqvtData = Generic_Data |
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
44 |
( type T = thm Item_Net.T; |
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
45 |
val empty = Thm.full_rules; |
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
46 |
val extend = I; |
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
47 |
val merge = Item_Net.merge); |
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
48 |
|
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
49 |
structure EqvtRawData = Generic_Data |
2200
31f1ec832d39
fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents:
2123
diff
changeset
|
50 |
( type T = thm Termtab.table; |
31f1ec832d39
fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents:
2123
diff
changeset
|
51 |
val empty = Termtab.empty; |
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
52 |
val extend = I; |
2200
31f1ec832d39
fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents:
2123
diff
changeset
|
53 |
val merge = Termtab.merge (K true)); |
1059
090fa3f21380
restored the old behaviour of having an eqvts list; the transformed theorems are stored in eqvts_raw
Christian Urban <urbanc@in.tum.de>
parents:
1039
diff
changeset
|
54 |
|
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
55 |
val eqvts = Item_Net.content o EqvtData.get; |
2200
31f1ec832d39
fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents:
2123
diff
changeset
|
56 |
val eqvts_raw = map snd o Termtab.dest o EqvtRawData.get; |
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
57 |
|
1811
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
58 |
val get_eqvts_thms = eqvts o Context.Proof; |
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
59 |
val get_eqvts_raw_thms = eqvts_raw o Context.Proof; |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
|
2925
b4404b13f775
added a warning if a theorem is already declared as equivariant
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
61 |
fun checked_update key net = |
b4404b13f775
added a warning if a theorem is already declared as equivariant
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
62 |
(if Item_Net.member net key then |
b4404b13f775
added a warning if a theorem is already declared as equivariant
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
63 |
warning "Theorem already declared as equivariant." |
b4404b13f775
added a warning if a theorem is already declared as equivariant
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
64 |
else (); |
b4404b13f775
added a warning if a theorem is already declared as equivariant
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
65 |
Item_Net.update key net) |
b4404b13f775
added a warning if a theorem is already declared as equivariant
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
66 |
|
b4404b13f775
added a warning if a theorem is already declared as equivariant
Christian Urban <urbanc@in.tum.de>
parents:
2650
diff
changeset
|
67 |
val add_thm = EqvtData.map o checked_update; |
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
68 |
val del_thm = EqvtData.map o Item_Net.remove; |
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
69 |
|
1800
78fdc6b36a1c
changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents:
1774
diff
changeset
|
70 |
fun add_raw_thm thm = |
1811
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
71 |
case prop_of thm of |
2200
31f1ec832d39
fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents:
2123
diff
changeset
|
72 |
Const ("==", _) $ _ $ (c as Const _) => EqvtRawData.map (Termtab.update (c, thm)) |
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
73 |
| _ => raise THM ("Theorem must be a meta-equality where the right-hand side is a constant.", 0, [thm]) |
1800
78fdc6b36a1c
changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents:
1774
diff
changeset
|
74 |
|
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
75 |
fun del_raw_thm thm = |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
76 |
case prop_of thm of |
2200
31f1ec832d39
fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents:
2123
diff
changeset
|
77 |
Const ("==", _) $ _ $ (c as Const _) => EqvtRawData.map (Termtab.delete c) |
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
78 |
| _ => raise THM ("Theorem must be a meta-equality where the right-hand side is a constant.", 0, [thm]) |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
79 |
|
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
80 |
fun is_eqvt ctxt trm = |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
81 |
case trm of |
2200
31f1ec832d39
fixed bug where perm_simp 'forgets' how to prove equivariance for the empty set
Christian Urban <urbanc@in.tum.de>
parents:
2123
diff
changeset
|
82 |
(c as Const _) => Termtab.defined (EqvtRawData.get (Context.Proof ctxt)) c |
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
83 |
| _ => false (* raise TERM ("Term must be a constant.", [trm]) *) |
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
84 |
|
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
85 |
|
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
86 |
|
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
87 |
(** transformation of eqvt lemmas **) |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
88 |
|
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
89 |
fun get_perms trm = |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
90 |
case trm of |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
91 |
Const (@{const_name permute}, _) $ _ $ (Bound _) => |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
92 |
raise TERM ("get_perms called on bound", [trm]) |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
93 |
| Const (@{const_name permute}, _) $ p $ _ => [p] |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
94 |
| t $ u => get_perms t @ get_perms u |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
95 |
| Abs (_, _, t) => get_perms t |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
96 |
| _ => [] |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
97 |
|
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
98 |
fun add_perm p trm = |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
99 |
let |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
100 |
fun aux trm = |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
101 |
case trm of |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
102 |
Bound _ => trm |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
103 |
| Const _ => trm |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
104 |
| t $ u => aux t $ aux u |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
105 |
| Abs (x, ty, t) => Abs (x, ty, aux t) |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
106 |
| _ => mk_perm p trm |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
107 |
in |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
108 |
strip_comb trm |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
109 |
||> map aux |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
110 |
|> list_comb |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
111 |
end |
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
112 |
|
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
113 |
|
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
114 |
(* tests whether there is a disagreement between the permutations, |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
115 |
and that there is at least one permutation *) |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
116 |
fun is_bad_list [] = true |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
117 |
| is_bad_list [_] = false |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
118 |
| is_bad_list (p::q::ps) = if p = q then is_bad_list (q::ps) else true |
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
119 |
|
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
120 |
|
1947 | 121 |
(* transforms equations into the "p o c == c"-form |
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
122 |
from p o (c x1 ...xn) = c (p o x1) ... (p o xn) *) |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
123 |
|
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
124 |
fun eqvt_transform_eq_tac thm = |
1841
fcc660ece040
thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents:
1835
diff
changeset
|
125 |
let |
fcc660ece040
thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents:
1835
diff
changeset
|
126 |
val ss_thms = @{thms permute_minus_cancel permute_prod.simps split_paired_all} |
fcc660ece040
thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents:
1835
diff
changeset
|
127 |
in |
fcc660ece040
thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents:
1835
diff
changeset
|
128 |
REPEAT o FIRST' |
fcc660ece040
thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents:
1835
diff
changeset
|
129 |
[CHANGED o simp_tac (HOL_basic_ss addsimps ss_thms), |
fcc660ece040
thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents:
1835
diff
changeset
|
130 |
rtac (thm RS @{thm trans}), |
fcc660ece040
thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents:
1835
diff
changeset
|
131 |
rtac @{thm trans[OF permute_fun_def]} THEN' rtac @{thm ext}] |
fcc660ece040
thmdecls can deal with lemmas like alpha_gen which contain pairs or tuples
Christian Urban <urbanc@in.tum.de>
parents:
1835
diff
changeset
|
132 |
end |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
133 |
|
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
134 |
fun eqvt_transform_eq ctxt thm = |
2477 | 135 |
let |
136 |
val (lhs, rhs) = HOLogic.dest_eq (HOLogic.dest_Trueprop (prop_of thm)) |
|
137 |
handle TERM _ => error "Equivariance lemma must be an equality." |
|
138 |
val (p, t) = dest_perm lhs |
|
139 |
handle TERM _ => error "Equivariance lemma is not of the form p \<bullet> c... = c..." |
|
1947 | 140 |
|
2477 | 141 |
val ps = get_perms rhs handle TERM _ => [] |
142 |
val (c, c') = (head_of t, head_of rhs) |
|
143 |
val msg = "Equivariance lemma is not of the right form " |
|
144 |
in |
|
145 |
if c <> c' |
|
146 |
then error (msg ^ "(constants do not agree).") |
|
147 |
else if is_bad_list (p :: ps) |
|
148 |
then error (msg ^ "(permutations do not agree).") |
|
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
149 |
else if not (rhs aconv (add_perm p t)) |
2477 | 150 |
then error (msg ^ "(arguments do not agree).") |
151 |
else if is_Const t |
|
152 |
then safe_mk_equiv thm |
|
153 |
else |
|
154 |
let |
|
155 |
val goal = HOLogic.mk_Trueprop (HOLogic.mk_eq (mk_perm p c, c)) |
|
156 |
val ([goal', p'], ctxt') = Variable.import_terms false [goal, p] ctxt |
|
157 |
in |
|
158 |
Goal.prove ctxt [] [] goal' (fn _ => eqvt_transform_eq_tac thm 1) |
|
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:
2925
diff
changeset
|
159 |
|> singleton (Proof_Context.export ctxt' ctxt) |
2477 | 160 |
|> safe_mk_equiv |
161 |
|> zero_var_indexes |
|
162 |
end |
|
163 |
end |
|
1811
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
164 |
|
1947 | 165 |
(* transforms equations into the "p o c == c"-form |
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
166 |
from R x1 ...xn ==> R (p o x1) ... (p o xn) *) |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
167 |
|
1947 | 168 |
fun eqvt_transform_imp_tac ctxt p p' thm = |
2477 | 169 |
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:
2925
diff
changeset
|
170 |
val thy = Proof_Context.theory_of ctxt |
2477 | 171 |
val cp = Thm.cterm_of thy p |
172 |
val cp' = Thm.cterm_of thy (mk_minus p') |
|
173 |
val thm' = Drule.cterm_instantiate [(cp, cp')] thm |
|
174 |
val simp = HOL_basic_ss addsimps @{thms permute_minus_cancel(2)} |
|
175 |
in |
|
176 |
EVERY' [rtac @{thm iffI}, dtac @{thm permute_boolE}, rtac thm, atac, |
|
177 |
rtac @{thm permute_boolI}, dtac thm', full_simp_tac simp] |
|
178 |
end |
|
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
179 |
|
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
180 |
fun eqvt_transform_imp ctxt thm = |
2477 | 181 |
let |
182 |
val (prem, concl) = pairself HOLogic.dest_Trueprop (Logic.dest_implies (prop_of thm)) |
|
183 |
val (c, c') = (head_of prem, head_of concl) |
|
184 |
val ps = get_perms concl handle TERM _ => [] |
|
185 |
val p = try hd ps |
|
186 |
val msg = "Equivariance lemma is not of the right form " |
|
187 |
in |
|
188 |
if c <> c' |
|
189 |
then error (msg ^ "(constants do not agree).") |
|
190 |
else if is_bad_list ps |
|
191 |
then error (msg ^ "(permutations do not agree).") |
|
2650
e5fa8de0e4bd
derived equivariance for the function graph and function relation
Christian Urban <urbanc@in.tum.de>
parents:
2568
diff
changeset
|
192 |
else if not (concl aconv (add_perm (the p) prem)) |
2477 | 193 |
then error (msg ^ "(arguments do not agree).") |
194 |
else |
|
195 |
let |
|
196 |
val prem' = mk_perm (the p) prem |
|
197 |
val goal = HOLogic.mk_Trueprop (HOLogic.mk_eq (prem', concl)) |
|
198 |
val ([goal', p'], ctxt') = Variable.import_terms false [goal, the p] ctxt |
|
199 |
in |
|
200 |
Goal.prove ctxt' [] [] goal' |
|
201 |
(fn _ => eqvt_transform_imp_tac ctxt' (the p) p' thm 1) |
|
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:
2925
diff
changeset
|
202 |
|> singleton (Proof_Context.export ctxt' ctxt) |
2477 | 203 |
end |
204 |
end |
|
1811
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
205 |
|
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
206 |
fun eqvt_transform ctxt thm = |
2477 | 207 |
case (prop_of thm) of |
2478
9b673588244a
updated to Isabelle Sept 13
Christian Urban <urbanc@in.tum.de>
parents:
2477
diff
changeset
|
208 |
@{const "Trueprop"} $ (Const (@{const_name "HOL.eq"}, _) $ |
2477 | 209 |
(Const (@{const_name "permute"}, _) $ _ $ _) $ _) => |
210 |
eqvt_transform_eq ctxt thm |
|
211 |
| @{const "==>"} $ (@{const "Trueprop"} $ _) $ (@{const "Trueprop"} $ _) => |
|
212 |
eqvt_transform_imp ctxt thm |> eqvt_transform_eq ctxt |
|
213 |
| _ => raise error "Only _ = _ and _ ==> _ cases are implemented." |
|
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
214 |
|
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
215 |
|
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
216 |
(** attributes **) |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
217 |
|
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
218 |
val eqvt_add = Thm.declaration_attribute |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
219 |
(fn thm => fn context => |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
220 |
let |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
221 |
val thm' = eqvt_transform (Context.proof_of context) thm |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
222 |
in |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
223 |
context |> add_thm thm |> add_raw_thm thm' |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
224 |
end) |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
225 |
|
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
226 |
val eqvt_del = Thm.declaration_attribute |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
227 |
(fn thm => fn context => |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
228 |
let |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
229 |
val thm' = eqvt_transform (Context.proof_of context) thm |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
230 |
in |
1953
186d8486dfd5
rewrote eqvts_raw to be a symtab, that can be looked up
Christian Urban <urbanc@in.tum.de>
parents:
1947
diff
changeset
|
231 |
context |> del_thm thm |> del_raw_thm thm' |
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
232 |
end) |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
233 |
|
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
234 |
val eqvt_raw_add = Thm.declaration_attribute add_raw_thm; |
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
235 |
val eqvt_raw_del = Thm.declaration_attribute del_raw_thm; |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
236 |
|
1870
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
237 |
|
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
238 |
(** setup function **) |
55b2da92ff2f
tuned; transformation functions now take a context, a thm and return a thm
Christian Urban <urbanc@in.tum.de>
parents:
1846
diff
changeset
|
239 |
|
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
240 |
val setup = |
1037
2845e736dc1a
added a first eqvt_tac which pushes permutations inside terms
Christian Urban <urbanc@in.tum.de>
parents:
947
diff
changeset
|
241 |
Attrib.setup @{binding "eqvt"} (Attrib.add_del eqvt_add eqvt_del) |
1811
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
242 |
(cat_lines ["Declaration of equivariance lemmas - they will automtically be", |
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
243 |
"brought into the form p o c == c"]) #> |
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
244 |
Attrib.setup @{binding "eqvt_raw"} (Attrib.add_del eqvt_raw_add eqvt_raw_del) |
1811
ae176476b525
implemented in thmdecls the case where eqvt-lemmas are of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents:
1810
diff
changeset
|
245 |
(cat_lines ["Declaration of equivariance lemmas - no", |
1059
090fa3f21380
restored the old behaviour of having an eqvts list; the transformed theorems are stored in eqvts_raw
Christian Urban <urbanc@in.tum.de>
parents:
1039
diff
changeset
|
246 |
"transformation is performed"]) #> |
2484
594f3401605f
updated to Isabelle 22 Sept
Christian Urban <urbanc@in.tum.de>
parents:
2478
diff
changeset
|
247 |
Global_Theory.add_thms_dynamic (@{binding "eqvts"}, eqvts) #> |
594f3401605f
updated to Isabelle 22 Sept
Christian Urban <urbanc@in.tum.de>
parents:
2478
diff
changeset
|
248 |
Global_Theory.add_thms_dynamic (@{binding "eqvts_raw"}, eqvts_raw); |
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
249 |
|
1066
96651cddeba9
eqvts and eqvts_raw are separate thm-lists; otherwise permute_eqvt is problematic as it causes looks in eqvts
Christian Urban <urbanc@in.tum.de>
parents:
1059
diff
changeset
|
250 |
|
947
fa810f01f7b5
added an LamEx example together with the new nominal infrastructure
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
251 |
end; |