author | Christian Urban <urbanc@in.tum.de> |
Tue, 01 Jun 2010 15:48:25 +0200 | |
changeset 2204 | 54eea17575e6 |
parent 2163 | 5dc48e1af733 |
child 2288 | 3b83960f9544 |
permissions | -rw-r--r-- |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
1 |
theory Perm |
1774
c34347ec7ab3
separated general nominal theory into separate folder
Christian Urban <urbanc@in.tum.de>
parents:
1683
diff
changeset
|
2 |
imports "../Nominal-General/Nominal2_Atoms" |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
3 |
begin |
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
4 |
|
1910 | 5 |
(* definitions of the permute function for raw nominal datatypes *) |
1903 | 6 |
|
1683
f78c820f67c3
Automatically lift theorems and constants only using the new quotient types. Requires new Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1503
diff
changeset
|
7 |
|
f78c820f67c3
Automatically lift theorems and constants only using the new quotient types. Requires new Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1503
diff
changeset
|
8 |
ML {* |
1910 | 9 |
(* returns the type of the nth datatype *) |
2163
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
10 |
fun nth_dtyp descr sorts n = |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
11 |
Datatype_Aux.typ_of_dtyp descr sorts (Datatype_Aux.DtRec n); |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
12 |
|
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
13 |
(* returns the constructors of the nth datatype *) |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
14 |
fun nth_dtyp_constrs descr n = |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
15 |
let |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
16 |
val (_, (_, _, constrs)) = nth descr n |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
17 |
in |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
18 |
constrs |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
19 |
end |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
20 |
|
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
21 |
(* returns the types of the constructors of the nth datatype *) |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
22 |
fun nth_dtyp_constr_typs descr sorts n = |
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
23 |
map (map (Datatype_Aux.typ_of_dtyp descr sorts) o snd) (nth_dtyp_constrs descr n) |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
24 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
25 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
26 |
ML {* |
1971
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents:
1966
diff
changeset
|
27 |
(* generates for every datatype a name str ^ dt_name |
8daf6ff5e11a
simpliied and moved the remaining lemmas about the atom-function to Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents:
1966
diff
changeset
|
28 |
plus and index for multiple occurences of a string *) |
2163
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
29 |
fun prefix_dt_names descr sorts str = |
1966
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
30 |
let |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
31 |
fun get_nth_name (i, _) = |
2163
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
32 |
Datatype_Aux.name_of_typ (nth_dtyp descr sorts i) |
1966
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
33 |
in |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
34 |
Datatype_Prop.indexify_names |
2163
5dc48e1af733
added comments about pottiers work
Christian Urban <urbanc@in.tum.de>
parents:
2144
diff
changeset
|
35 |
(map (prefix str o get_nth_name) descr) |
1966
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
36 |
end |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
37 |
*} |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
38 |
|
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
39 |
|
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
40 |
ML {* |
1900
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
41 |
(* permutation function for one argument |
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
42 |
|
1901
93dfd5a10e92
removed dead code (nominal cannot deal with argument types of constructors that are functions)
Christian Urban <urbanc@in.tum.de>
parents:
1900
diff
changeset
|
43 |
- in case the argument is recursive it returns |
93dfd5a10e92
removed dead code (nominal cannot deal with argument types of constructors that are functions)
Christian Urban <urbanc@in.tum.de>
parents:
1900
diff
changeset
|
44 |
|
93dfd5a10e92
removed dead code (nominal cannot deal with argument types of constructors that are functions)
Christian Urban <urbanc@in.tum.de>
parents:
1900
diff
changeset
|
45 |
permute_fn p arg |
93dfd5a10e92
removed dead code (nominal cannot deal with argument types of constructors that are functions)
Christian Urban <urbanc@in.tum.de>
parents:
1900
diff
changeset
|
46 |
|
2035
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
47 |
- in case the argument is non-recursive it will return |
1900
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
48 |
|
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
49 |
p o arg |
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
50 |
|
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
51 |
*) |
2038 | 52 |
fun perm_arg permute_fn_frees p (arg_dty, arg) = |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
53 |
if Datatype_Aux.is_rec_type arg_dty |
2038 | 54 |
then (nth permute_fn_frees (Datatype_Aux.body_index arg_dty)) $ p $ arg |
2035
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
55 |
else mk_perm p arg |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
56 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
57 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
58 |
ML {* |
2035
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
59 |
(* generates the equation for the permutation function for one constructor; |
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
60 |
i is the index of the corresponding datatype *) |
2038 | 61 |
fun perm_eq_constr dt_descr sorts permute_fn_frees i (cnstr_name, dts) = |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
62 |
let |
2035
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
63 |
val p = Free ("p", @{typ perm}) |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
64 |
val arg_tys = map (Datatype_Aux.typ_of_dtyp dt_descr sorts) dts |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
65 |
val arg_names = Name.variant_list ["p"] (Datatype_Prop.make_tnames arg_tys) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
66 |
val args = map Free (arg_names ~~ arg_tys) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
67 |
val cnstr = Const (cnstr_name, arg_tys ---> (nth_dtyp dt_descr sorts i)) |
2038 | 68 |
val lhs = (nth permute_fn_frees i) $ p $ list_comb (cnstr, args) |
69 |
val rhs = list_comb (cnstr, map (perm_arg permute_fn_frees p) (dts ~~ args)) |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
70 |
val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
71 |
in |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
72 |
(Attrib.empty_binding, eq) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
73 |
end |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
74 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
75 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
76 |
ML {* |
2106
409ecb7284dd
properly exported defined bn-functions
Christian Urban <urbanc@in.tum.de>
parents:
2047
diff
changeset
|
77 |
(* proves the two pt-type class properties *) |
1910 | 78 |
fun prove_permute_zero lthy induct perm_defs perm_fns = |
79 |
let |
|
80 |
val perm_types = map (body_type o fastype_of) perm_fns |
|
81 |
val perm_indnames = Datatype_Prop.make_tnames perm_types |
|
82 |
||
83 |
fun single_goal ((perm_fn, T), x) = |
|
84 |
HOLogic.mk_eq (perm_fn $ @{term "0::perm"} $ Free (x, T), Free (x, T)) |
|
85 |
||
86 |
val goals = |
|
87 |
HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
|
88 |
(map single_goal (perm_fns ~~ perm_types ~~ perm_indnames))) |
|
89 |
||
90 |
val simps = HOL_basic_ss addsimps (@{thm permute_zero} :: perm_defs) |
|
91 |
||
92 |
val tac = (Datatype_Aux.indtac induct perm_indnames |
|
93 |
THEN_ALL_NEW asm_simp_tac simps) 1 |
|
94 |
in |
|
95 |
Goal.prove lthy perm_indnames [] goals (K tac) |
|
96 |
|> Datatype_Aux.split_conj_thm |
|
97 |
end |
|
98 |
*} |
|
99 |
||
100 |
ML {* |
|
101 |
fun prove_permute_plus lthy induct perm_defs perm_fns = |
|
102 |
let |
|
2038 | 103 |
val p = Free ("p", @{typ perm}) |
104 |
val q = Free ("q", @{typ perm}) |
|
1910 | 105 |
val perm_types = map (body_type o fastype_of) perm_fns |
106 |
val perm_indnames = Datatype_Prop.make_tnames perm_types |
|
107 |
||
2038 | 108 |
fun single_goal ((perm_fn, T), x) = HOLogic.mk_eq |
109 |
(perm_fn $ (mk_plus p q) $ Free (x, T), perm_fn $ p $ (perm_fn $ q $ Free (x, T))) |
|
1910 | 110 |
|
111 |
val goals = |
|
112 |
HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
|
113 |
(map single_goal (perm_fns ~~ perm_types ~~ perm_indnames))) |
|
114 |
||
115 |
val simps = HOL_basic_ss addsimps (@{thm permute_plus} :: perm_defs) |
|
116 |
||
117 |
val tac = (Datatype_Aux.indtac induct perm_indnames |
|
118 |
THEN_ALL_NEW asm_simp_tac simps) 1 |
|
119 |
in |
|
120 |
Goal.prove lthy ("p" :: "q" :: perm_indnames) [] goals (K tac) |
|
121 |
|> Datatype_Aux.split_conj_thm |
|
122 |
end |
|
123 |
*} |
|
124 |
||
125 |
ML {* |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
126 |
(* defines the permutation functions for raw datatypes and |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
127 |
proves that they are instances of pt |
1910 | 128 |
|
2037
205ac2d13339
roll back of the last commit (there was a difference)
Christian Urban <urbanc@in.tum.de>
parents:
2036
diff
changeset
|
129 |
user_dt_nos refers to the number of "un-unfolded" datatypes |
1910 | 130 |
given by the user |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
131 |
*) |
2047
31ba33a199c7
fixed my error with define_raw_fv
Christian Urban <urbanc@in.tum.de>
parents:
2038
diff
changeset
|
132 |
fun define_raw_perms dt_descr sorts induct_thm user_dt_nos thy = |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
133 |
let |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
134 |
val all_full_tnames = map (fn (_, (n, _, _)) => n) dt_descr; |
2037
205ac2d13339
roll back of the last commit (there was a difference)
Christian Urban <urbanc@in.tum.de>
parents:
2036
diff
changeset
|
135 |
val user_full_tnames = List.take (all_full_tnames, user_dt_nos); |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
136 |
|
1966
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
137 |
val perm_fn_names = prefix_dt_names dt_descr sorts "permute_" |
2038 | 138 |
val perm_fn_types = map (fn (i, _) => perm_ty (nth_dtyp dt_descr sorts i)) dt_descr |
139 |
val perm_fn_frees = map Free (perm_fn_names ~~ perm_fn_types) |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
140 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
141 |
fun perm_eq (i, (_, _, constrs)) = |
2038 | 142 |
map (perm_eq_constr dt_descr sorts perm_fn_frees i) constrs; |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
143 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
144 |
val perm_eqs = maps perm_eq dt_descr; |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
145 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
146 |
val lthy = |
2037
205ac2d13339
roll back of the last commit (there was a difference)
Christian Urban <urbanc@in.tum.de>
parents:
2036
diff
changeset
|
147 |
Theory_Target.instantiation (user_full_tnames, [], @{sort pt}) thy; |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
148 |
|
2038 | 149 |
val ((perm_funs, perm_eq_thms), lthy') = |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
150 |
Primrec.add_primrec |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
151 |
(map (fn s => (Binding.name s, NONE, NoSyn)) perm_fn_names) perm_eqs lthy; |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
152 |
|
2047
31ba33a199c7
fixed my error with define_raw_fv
Christian Urban <urbanc@in.tum.de>
parents:
2038
diff
changeset
|
153 |
val perm_zero_thms = prove_permute_zero lthy' induct_thm perm_eq_thms perm_funs |
31ba33a199c7
fixed my error with define_raw_fv
Christian Urban <urbanc@in.tum.de>
parents:
2038
diff
changeset
|
154 |
val perm_plus_thms = prove_permute_plus lthy' induct_thm perm_eq_thms perm_funs |
2037
205ac2d13339
roll back of the last commit (there was a difference)
Christian Urban <urbanc@in.tum.de>
parents:
2036
diff
changeset
|
155 |
val perm_zero_thms' = List.take (perm_zero_thms, user_dt_nos); |
205ac2d13339
roll back of the last commit (there was a difference)
Christian Urban <urbanc@in.tum.de>
parents:
2036
diff
changeset
|
156 |
val perm_plus_thms' = List.take (perm_plus_thms, user_dt_nos) |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
157 |
val perms_name = space_implode "_" perm_fn_names |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
158 |
val perms_zero_bind = Binding.name (perms_name ^ "_zero") |
1902
c68a154adca4
renamed "_empty" and "_append" to "_zero" and "_plus"
Christian Urban <urbanc@in.tum.de>
parents:
1901
diff
changeset
|
159 |
val perms_plus_bind = Binding.name (perms_name ^ "_plus") |
1903 | 160 |
|
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2106
diff
changeset
|
161 |
fun tac _ (_, _, simps) = |
1910 | 162 |
Class.intro_classes_tac [] THEN ALLGOALS (resolve_tac simps) |
1903 | 163 |
|
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2106
diff
changeset
|
164 |
fun morphism phi (fvs, dfs, simps) = |
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2106
diff
changeset
|
165 |
(map (Morphism.term phi) fvs, map (Morphism.thm phi) dfs, map (Morphism.thm phi) simps); |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
166 |
in |
1910 | 167 |
lthy' |
168 |
|> snd o (Local_Theory.note ((perms_zero_bind, []), perm_zero_thms')) |
|
169 |
|> snd o (Local_Theory.note ((perms_plus_bind, []), perm_plus_thms')) |
|
170 |
|> Class_Target.prove_instantiation_exit_result morphism tac |
|
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
parents:
2106
diff
changeset
|
171 |
(perm_funs, perm_eq_thms, perm_zero_thms' @ perm_plus_thms') |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
172 |
end |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
173 |
*} |
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
174 |
|
2035
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
175 |
|
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
176 |
|
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
177 |
|
3622cae9b10e
to my best knowledge the number of datatypes is equal to the length of the dt_descr; so we can save one argument in define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1971
diff
changeset
|
178 |
|
1910 | 179 |
(* permutations for quotient types *) |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
180 |
|
2144 | 181 |
ML {* Class_Target.prove_instantiation_exit_result *} |
182 |
||
1253 | 183 |
ML {* |
1903 | 184 |
fun quotient_lift_consts_export qtys spec ctxt = |
185 |
let |
|
186 |
val (result, ctxt') = fold_map (Quotient_Def.quotient_lift_const qtys) spec ctxt; |
|
187 |
val (ts_loc, defs_loc) = split_list result; |
|
188 |
val morphism = ProofContext.export_morphism ctxt' ctxt; |
|
189 |
val ts = map (Morphism.term morphism) ts_loc |
|
190 |
val defs = Morphism.fact morphism defs_loc |
|
191 |
in |
|
192 |
(ts, defs, ctxt') |
|
193 |
end |
|
194 |
*} |
|
195 |
||
196 |
ML {* |
|
1683
f78c820f67c3
Automatically lift theorems and constants only using the new quotient types. Requires new Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1503
diff
changeset
|
197 |
fun define_lifted_perms qtys full_tnames name_term_pairs thms thy = |
1253 | 198 |
let |
199 |
val lthy = |
|
200 |
Theory_Target.instantiation (full_tnames, [], @{sort pt}) thy; |
|
1683
f78c820f67c3
Automatically lift theorems and constants only using the new quotient types. Requires new Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1503
diff
changeset
|
201 |
val (_, _, lthy') = quotient_lift_consts_export qtys name_term_pairs lthy; |
f78c820f67c3
Automatically lift theorems and constants only using the new quotient types. Requires new Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1503
diff
changeset
|
202 |
val lifted_thms = map (Quotient_Tacs.lifted qtys lthy') thms; |
1253 | 203 |
fun tac _ = |
204 |
Class.intro_classes_tac [] THEN |
|
205 |
(ALLGOALS (resolve_tac lifted_thms)) |
|
206 |
val lthy'' = Class.prove_instantiation_instance tac lthy' |
|
207 |
in |
|
208 |
Local_Theory.exit_global lthy'' |
|
209 |
end |
|
210 |
*} |
|
211 |
||
1342 | 212 |
ML {* |
213 |
fun neq_to_rel r neq = |
|
214 |
let |
|
215 |
val neq = HOLogic.dest_Trueprop (prop_of neq) |
|
216 |
val eq = HOLogic.dest_not neq |
|
217 |
val (lhs, rhs) = HOLogic.dest_eq eq |
|
218 |
val rel = r $ lhs $ rhs |
|
219 |
val nrel = HOLogic.mk_not rel |
|
220 |
in |
|
221 |
HOLogic.mk_Trueprop nrel |
|
222 |
end |
|
223 |
*} |
|
224 |
||
225 |
ML {* |
|
226 |
fun neq_to_rel_tac cases distinct = |
|
227 |
rtac notI THEN' eresolve_tac cases THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps distinct) |
|
228 |
*} |
|
229 |
||
230 |
ML {* |
|
231 |
fun distinct_rel ctxt cases (dists, rel) = |
|
232 |
let |
|
233 |
val ((_, thms), ctxt') = Variable.import false dists ctxt |
|
234 |
val terms = map (neq_to_rel rel) thms |
|
235 |
val nrels = map (fn t => Goal.prove ctxt' [] [] t (fn _ => neq_to_rel_tac cases dists 1)) terms |
|
236 |
in |
|
237 |
Variable.export ctxt' ctxt nrels |
|
238 |
end |
|
239 |
*} |
|
240 |
||
241 |
||
242 |
||
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
243 |
(* Test *) |
1910 | 244 |
(* |
245 |
atom_decl name |
|
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
246 |
|
1896
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents:
1871
diff
changeset
|
247 |
datatype trm = |
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents:
1871
diff
changeset
|
248 |
Var "name" |
1910 | 249 |
| App "trm" "(trm list) list" |
1896
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents:
1871
diff
changeset
|
250 |
| Lam "name" "trm" |
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents:
1871
diff
changeset
|
251 |
| Let "bp" "trm" "trm" |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
252 |
and bp = |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
253 |
BUnit |
1896
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents:
1871
diff
changeset
|
254 |
| BVar "name" |
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents:
1871
diff
changeset
|
255 |
| BPair "bp" "bp" |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
256 |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
257 |
setup {* fn thy => |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
258 |
let |
1910 | 259 |
val info = Datatype.the_info thy "Perm.trm" |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
260 |
in |
1910 | 261 |
define_raw_perms info 2 thy |> snd |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
262 |
end |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
263 |
*} |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
264 |
|
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
265 |
print_theorems |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
266 |
*) |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
267 |
|
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
268 |
end |