author | Christian Urban <urbanc@in.tum.de> |
Wed, 28 Apr 2010 08:22:20 +0200 | |
changeset 1971 | 8daf6ff5e11a |
parent 1966 | b6b3374a402d |
child 2035 | 3622cae9b10e |
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 *) |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
10 |
fun nth_dtyp dt_descr sorts i = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
11 |
Datatype_Aux.typ_of_dtyp dt_descr sorts (Datatype_Aux.DtRec i); |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
12 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
13 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
14 |
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
|
15 |
(* 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
|
16 |
plus and index for multiple occurences of a string *) |
1966
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
17 |
fun prefix_dt_names dt_descr sorts str = |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
18 |
let |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
19 |
fun get_nth_name (i, _) = |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
20 |
Datatype_Aux.name_of_typ (nth_dtyp dt_descr sorts i) |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
21 |
in |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
22 |
Datatype_Prop.indexify_names |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
23 |
(map (prefix str o get_nth_name) dt_descr) |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
24 |
end |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
25 |
*} |
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
26 |
|
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
27 |
|
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
28 |
ML {* |
1900
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
29 |
(* permutation function for one argument |
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
30 |
|
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
|
31 |
- 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
|
32 |
|
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
|
33 |
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
|
34 |
|
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
|
35 |
- in case the argument is non-recursive it will build |
1900
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
36 |
|
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
37 |
p o arg |
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
38 |
|
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
39 |
*) |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
40 |
fun perm_arg permute_fns pi (arg_dty, arg) = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
41 |
if Datatype_Aux.is_rec_type arg_dty |
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
|
42 |
then Free (nth permute_fns (Datatype_Aux.body_index arg_dty)) $ pi $ arg |
1900
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
43 |
else mk_perm pi arg |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
44 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
45 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
46 |
ML {* |
1902
c68a154adca4
renamed "_empty" and "_append" to "_zero" and "_plus"
Christian Urban <urbanc@in.tum.de>
parents:
1901
diff
changeset
|
47 |
(* equation for permutation function for one constructor; |
c68a154adca4
renamed "_empty" and "_append" to "_zero" and "_plus"
Christian Urban <urbanc@in.tum.de>
parents:
1901
diff
changeset
|
48 |
i is the index of the correspodning datatype *) |
c68a154adca4
renamed "_empty" and "_append" to "_zero" and "_plus"
Christian Urban <urbanc@in.tum.de>
parents:
1901
diff
changeset
|
49 |
fun perm_eq_constr dt_descr sorts permute_fns i (cnstr_name, dts) = |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
50 |
let |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
51 |
val pi = Free ("p", @{typ perm}) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
val cnstr = Const (cnstr_name, arg_tys ---> (nth_dtyp dt_descr sorts i)) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
56 |
val lhs = Free (nth permute_fns i) $ pi $ list_comb (cnstr, args) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
57 |
val rhs = list_comb (cnstr, map (perm_arg permute_fns pi) (dts ~~ args)) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
58 |
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
|
59 |
in |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
60 |
(Attrib.empty_binding, eq) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
61 |
end |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
62 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
63 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
64 |
ML {* |
1910 | 65 |
fun prove_permute_zero lthy induct perm_defs perm_fns = |
66 |
let |
|
67 |
val perm_types = map (body_type o fastype_of) perm_fns |
|
68 |
val perm_indnames = Datatype_Prop.make_tnames perm_types |
|
69 |
||
70 |
fun single_goal ((perm_fn, T), x) = |
|
71 |
HOLogic.mk_eq (perm_fn $ @{term "0::perm"} $ Free (x, T), Free (x, T)) |
|
72 |
||
73 |
val goals = |
|
74 |
HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
|
75 |
(map single_goal (perm_fns ~~ perm_types ~~ perm_indnames))) |
|
76 |
||
77 |
val simps = HOL_basic_ss addsimps (@{thm permute_zero} :: perm_defs) |
|
78 |
||
79 |
val tac = (Datatype_Aux.indtac induct perm_indnames |
|
80 |
THEN_ALL_NEW asm_simp_tac simps) 1 |
|
81 |
in |
|
82 |
Goal.prove lthy perm_indnames [] goals (K tac) |
|
83 |
|> Datatype_Aux.split_conj_thm |
|
84 |
end |
|
85 |
*} |
|
86 |
||
87 |
ML {* |
|
88 |
fun prove_permute_plus lthy induct perm_defs perm_fns = |
|
89 |
let |
|
90 |
val pi1 = Free ("p", @{typ perm}) |
|
91 |
val pi2 = Free ("q", @{typ perm}) |
|
92 |
val perm_types = map (body_type o fastype_of) perm_fns |
|
93 |
val perm_indnames = Datatype_Prop.make_tnames perm_types |
|
94 |
||
95 |
fun single_goal ((perm, T), x) = HOLogic.mk_eq |
|
96 |
(perm $ (mk_plus pi1 pi2) $ Free (x, T), perm $ pi1 $ (perm $ pi2 $ Free (x, T))) |
|
97 |
||
98 |
val goals = |
|
99 |
HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
|
100 |
(map single_goal (perm_fns ~~ perm_types ~~ perm_indnames))) |
|
101 |
||
102 |
val simps = HOL_basic_ss addsimps (@{thm permute_plus} :: perm_defs) |
|
103 |
||
104 |
val tac = (Datatype_Aux.indtac induct perm_indnames |
|
105 |
THEN_ALL_NEW asm_simp_tac simps) 1 |
|
106 |
in |
|
107 |
Goal.prove lthy ("p" :: "q" :: perm_indnames) [] goals (K tac) |
|
108 |
|> Datatype_Aux.split_conj_thm |
|
109 |
end |
|
110 |
*} |
|
111 |
||
112 |
ML {* |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
113 |
(* 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
|
114 |
proves that they are instances of pt |
1910 | 115 |
|
116 |
dt_nos refers to the number of "un-unfolded" datatypes |
|
117 |
given by the user |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
118 |
*) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
119 |
fun define_raw_perms (dt_info : Datatype_Aux.info) dt_nos thy = |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
120 |
let |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
121 |
val {descr as dt_descr, induct, sorts, ...} = dt_info; |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
122 |
val all_full_tnames = map (fn (_, (n, _, _)) => n) dt_descr; |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
123 |
val full_tnames = List.take (all_full_tnames, dt_nos); |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
124 |
|
1966
b6b3374a402d
factured out common functionality of prefixing the dt-names with a string
Christian Urban <urbanc@in.tum.de>
parents:
1910
diff
changeset
|
125 |
val perm_fn_names = prefix_dt_names dt_descr sorts "permute_" |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
126 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
127 |
val perm_types = map (fn (i, _) => perm_ty (nth_dtyp dt_descr sorts i)) dt_descr |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
128 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
129 |
val permute_fns = perm_fn_names ~~ perm_types |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
130 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
131 |
fun perm_eq (i, (_, _, constrs)) = |
1902
c68a154adca4
renamed "_empty" and "_append" to "_zero" and "_plus"
Christian Urban <urbanc@in.tum.de>
parents:
1901
diff
changeset
|
132 |
map (perm_eq_constr dt_descr sorts permute_fns i) constrs; |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
133 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
134 |
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
|
135 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
136 |
val lthy = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
137 |
Theory_Target.instantiation (full_tnames, [], @{sort pt}) thy; |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
138 |
|
1910 | 139 |
val ((perm_fns, perm_ldef), lthy') = |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
140 |
Primrec.add_primrec |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
141 |
(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
|
142 |
|
1910 | 143 |
val perm_zero_thms = prove_permute_zero lthy' induct perm_ldef perm_fns |
144 |
val perm_plus_thms = prove_permute_plus lthy' induct perm_ldef perm_fns |
|
1903 | 145 |
val perm_zero_thms' = List.take (perm_zero_thms, dt_nos); |
146 |
val perm_plus_thms' = List.take (perm_plus_thms, dt_nos) |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
147 |
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
|
148 |
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
|
149 |
val perms_plus_bind = Binding.name (perms_name ^ "_plus") |
1903 | 150 |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
151 |
fun tac _ (_, simps, _) = |
1910 | 152 |
Class.intro_classes_tac [] THEN ALLGOALS (resolve_tac simps) |
1903 | 153 |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
154 |
fun morphism phi (dfs, simps, fvs) = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
155 |
(map (Morphism.thm phi) dfs, map (Morphism.thm phi) simps, map (Morphism.term phi) fvs); |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
156 |
in |
1910 | 157 |
lthy' |
158 |
|> snd o (Local_Theory.note ((perms_zero_bind, []), perm_zero_thms')) |
|
159 |
|> snd o (Local_Theory.note ((perms_plus_bind, []), perm_plus_thms')) |
|
160 |
|> Class_Target.prove_instantiation_exit_result morphism tac |
|
161 |
(perm_ldef, perm_zero_thms' @ perm_plus_thms', perm_fns) |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
162 |
end |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
163 |
*} |
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
164 |
|
1910 | 165 |
(* permutations for quotient types *) |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
166 |
|
1253 | 167 |
ML {* |
1903 | 168 |
fun quotient_lift_consts_export qtys spec ctxt = |
169 |
let |
|
170 |
val (result, ctxt') = fold_map (Quotient_Def.quotient_lift_const qtys) spec ctxt; |
|
171 |
val (ts_loc, defs_loc) = split_list result; |
|
172 |
val morphism = ProofContext.export_morphism ctxt' ctxt; |
|
173 |
val ts = map (Morphism.term morphism) ts_loc |
|
174 |
val defs = Morphism.fact morphism defs_loc |
|
175 |
in |
|
176 |
(ts, defs, ctxt') |
|
177 |
end |
|
178 |
*} |
|
179 |
||
180 |
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
|
181 |
fun define_lifted_perms qtys full_tnames name_term_pairs thms thy = |
1253 | 182 |
let |
183 |
val lthy = |
|
184 |
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
|
185 |
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
|
186 |
val lifted_thms = map (Quotient_Tacs.lifted qtys lthy') thms; |
1253 | 187 |
fun tac _ = |
188 |
Class.intro_classes_tac [] THEN |
|
189 |
(ALLGOALS (resolve_tac lifted_thms)) |
|
190 |
val lthy'' = Class.prove_instantiation_instance tac lthy' |
|
191 |
in |
|
192 |
Local_Theory.exit_global lthy'' |
|
193 |
end |
|
194 |
*} |
|
195 |
||
1342 | 196 |
ML {* |
197 |
fun neq_to_rel r neq = |
|
198 |
let |
|
199 |
val neq = HOLogic.dest_Trueprop (prop_of neq) |
|
200 |
val eq = HOLogic.dest_not neq |
|
201 |
val (lhs, rhs) = HOLogic.dest_eq eq |
|
202 |
val rel = r $ lhs $ rhs |
|
203 |
val nrel = HOLogic.mk_not rel |
|
204 |
in |
|
205 |
HOLogic.mk_Trueprop nrel |
|
206 |
end |
|
207 |
*} |
|
208 |
||
209 |
ML {* |
|
210 |
fun neq_to_rel_tac cases distinct = |
|
211 |
rtac notI THEN' eresolve_tac cases THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps distinct) |
|
212 |
*} |
|
213 |
||
214 |
ML {* |
|
215 |
fun distinct_rel ctxt cases (dists, rel) = |
|
216 |
let |
|
217 |
val ((_, thms), ctxt') = Variable.import false dists ctxt |
|
218 |
val terms = map (neq_to_rel rel) thms |
|
219 |
val nrels = map (fn t => Goal.prove ctxt' [] [] t (fn _ => neq_to_rel_tac cases dists 1)) terms |
|
220 |
in |
|
221 |
Variable.export ctxt' ctxt nrels |
|
222 |
end |
|
223 |
*} |
|
224 |
||
225 |
||
226 |
||
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
227 |
(* Test *) |
1910 | 228 |
(* |
229 |
atom_decl name |
|
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
230 |
|
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
|
231 |
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
|
232 |
Var "name" |
1910 | 233 |
| 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
|
234 |
| 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
|
235 |
| Let "bp" "trm" "trm" |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
236 |
and bp = |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
237 |
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
|
238 |
| 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
|
239 |
| BPair "bp" "bp" |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
240 |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
241 |
setup {* fn thy => |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
242 |
let |
1910 | 243 |
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
|
244 |
in |
1910 | 245 |
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
|
246 |
end |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
247 |
*} |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
248 |
|
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
249 |
print_theorems |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
250 |
*) |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
251 |
|
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
252 |
end |