author | Christian Urban <urbanc@in.tum.de> |
Tue, 20 Apr 2010 08:57:13 +0200 | |
changeset 1901 | 93dfd5a10e92 |
parent 1900 | 57db4ff0893b |
child 1902 | c68a154adca4 |
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 |
|
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
5 |
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
|
6 |
fun quotient_lift_consts_export qtys spec ctxt = |
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 |
let |
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 |
val (result, ctxt') = fold_map (Quotient_Def.quotient_lift_const qtys) spec ctxt; |
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
|
9 |
val (ts_loc, defs_loc) = split_list result; |
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
|
10 |
val morphism = ProofContext.export_morphism ctxt' ctxt; |
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
|
11 |
val ts = map (Morphism.term morphism) ts_loc |
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
|
12 |
val defs = Morphism.fact morphism defs_loc |
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
|
13 |
in |
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
|
14 |
(ts, defs, ctxt') |
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
|
15 |
end |
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
|
16 |
*} |
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
|
17 |
|
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
|
18 |
ML {* |
1248
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
19 |
fun prove_perm_empty lthy induct perm_def perm_frees = |
1247
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
20 |
let |
1248
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
21 |
val perm_types = map fastype_of perm_frees; |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
22 |
val perm_indnames = Datatype_Prop.make_tnames (map body_type perm_types); |
1256
6c938f84880c
Restructuring the code in Perm
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1253
diff
changeset
|
23 |
fun glc ((perm, T), x) = |
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
|
24 |
HOLogic.mk_eq (perm $ @{term "0::perm"} $ Free (x, T), Free (x, T)) |
1247
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
25 |
val gl = |
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
26 |
HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
1256
6c938f84880c
Restructuring the code in Perm
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1253
diff
changeset
|
27 |
(map glc (perm_frees ~~ map body_type perm_types ~~ perm_indnames))); |
1247
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
28 |
fun tac _ = |
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
29 |
EVERY [ |
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
|
30 |
Datatype_Aux.indtac induct perm_indnames 1, |
1247
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
31 |
ALLGOALS (asm_full_simp_tac (HOL_ss addsimps (@{thm permute_zero} :: perm_def))) |
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
32 |
]; |
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
33 |
in |
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
|
34 |
Datatype_Aux.split_conj_thm (Goal.prove lthy perm_indnames [] gl tac) |
1247
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
35 |
end; |
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
36 |
*} |
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
37 |
|
1248
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
38 |
ML {* |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
39 |
fun prove_perm_append lthy induct perm_def perm_frees = |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
40 |
let |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
41 |
val pi1 = Free ("pi1", @{typ perm}); |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
42 |
val pi2 = Free ("pi2", @{typ perm}); |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
43 |
val perm_types = map fastype_of perm_frees |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
44 |
val perm_indnames = Datatype_Prop.make_tnames (map body_type perm_types); |
1256
6c938f84880c
Restructuring the code in Perm
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1253
diff
changeset
|
45 |
fun glc ((perm, T), x) = |
6c938f84880c
Restructuring the code in Perm
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1253
diff
changeset
|
46 |
HOLogic.mk_eq ( |
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
|
47 |
perm $ (mk_plus pi1 pi2) $ Free (x, T), |
1256
6c938f84880c
Restructuring the code in Perm
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1253
diff
changeset
|
48 |
perm $ pi1 $ (perm $ pi2 $ Free (x, T))) |
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
|
49 |
val goal = |
1248
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
50 |
(HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj |
1256
6c938f84880c
Restructuring the code in Perm
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1253
diff
changeset
|
51 |
(map glc (perm_frees ~~ map body_type perm_types ~~ perm_indnames)))) |
1248
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
52 |
fun tac _ = |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
53 |
EVERY [ |
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
|
54 |
Datatype_Aux.indtac induct perm_indnames 1, |
1248
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
55 |
ALLGOALS (asm_full_simp_tac (HOL_ss addsimps (@{thm permute_plus} :: perm_def))) |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
56 |
] |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
57 |
in |
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
|
58 |
Datatype_Aux.split_conj_thm (Goal.prove lthy ("pi1" :: "pi2" :: perm_indnames) [] goal tac) |
1248
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
59 |
end; |
705afaaf6fb4
More refactoring and removed references to the global simpset in Perm.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1247
diff
changeset
|
60 |
*} |
1247
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
61 |
|
1899
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 |
(* definitions of the permute function for a raw nominal datatype *) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
64 |
|
1247
a728e199851d
Factor-out 'prove_perm_empty'; I plan to use it in defining permutations on the lifted type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1189
diff
changeset
|
65 |
ML {* |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
69 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
70 |
ML {* |
1900
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
71 |
(* permutation function for one argument |
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
72 |
|
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
|
73 |
- 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
|
74 |
|
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
|
75 |
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
|
76 |
|
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
|
77 |
- 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
|
78 |
|
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
79 |
p o arg |
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
80 |
|
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
81 |
*) |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
else mk_perm pi arg |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
86 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
87 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
88 |
ML {* |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
89 |
(* equation for permutation function for one constructor *) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
90 |
fun perm_eq_constr thy dt_descr sorts permute_fns i (cnstr_name, dts) = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
91 |
let |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
92 |
val pi = Free ("p", @{typ perm}) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
in |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
101 |
(Attrib.empty_binding, eq) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
102 |
end |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
103 |
*} |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
104 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
105 |
ML {* |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
106 |
(* 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
|
107 |
proves that they are instances of pt |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
108 |
*) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
109 |
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
|
110 |
let |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
115 |
val perm_fn_names = Datatype_Prop.indexify_names (map (fn (i, _) => |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
116 |
"permute_" ^ Datatype_Aux.name_of_typ (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
|
117 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
118 |
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
|
119 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
120 |
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
|
121 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
122 |
fun perm_eq (i, (_, _, constrs)) = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
123 |
map (perm_eq_constr thy dt_descr sorts permute_fns i) constrs; |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
124 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
125 |
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
|
126 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
127 |
val lthy = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
128 |
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
|
129 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
130 |
val ((perm_frees, perm_ldef), lthy') = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
131 |
Primrec.add_primrec |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
132 |
(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
|
133 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
134 |
val perm_empty_thms = List.take (prove_perm_empty lthy' induct perm_ldef perm_frees, dt_nos); |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
135 |
val perm_append_thms = List.take (prove_perm_append lthy' induct perm_ldef perm_frees, dt_nos) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
136 |
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
|
137 |
val perms_zero_bind = Binding.name (perms_name ^ "_zero") |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
138 |
val perms_append_bind = Binding.name (perms_name ^ "_append") |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
139 |
fun tac _ (_, simps, _) = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
140 |
(Class.intro_classes_tac []) THEN (ALLGOALS (resolve_tac simps)); |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
141 |
fun morphism phi (dfs, simps, fvs) = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
142 |
(map (Morphism.thm phi) dfs, map (Morphism.thm phi) simps, map (Morphism.term phi) fvs); |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
143 |
in |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
144 |
lthy' |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
145 |
|> snd o (Local_Theory.note ((perms_zero_bind, []), perm_empty_thms)) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
146 |
|> snd o (Local_Theory.note ((perms_append_bind, []), perm_append_thms)) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
147 |
|> Class_Target.prove_instantiation_exit_result morphism tac |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
148 |
(perm_ldef, (perm_empty_thms @ perm_append_thms), perm_frees) |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
149 |
end |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
150 |
*} |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
151 |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
152 |
(* Test *) |
1900
57db4ff0893b
added comment about abstraction in raw permuations
Christian Urban <urbanc@in.tum.de>
parents:
1899
diff
changeset
|
153 |
(*atom_decl name |
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
154 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
155 |
datatype trm = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
156 |
Var "name" |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
157 |
| App "trm" "trm list" |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
158 |
| Lam "name" "trm" |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
159 |
| Let "bp" "trm" "trm" |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
160 |
and bp = |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
161 |
BUnit |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
162 |
| BVar "name" |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
163 |
| BPair "bp" "bp" |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
164 |
|
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
165 |
setup {* fn thy => |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
166 |
let |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
167 |
val info = Datatype.the_info thy "Perm.trm" |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
168 |
in |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
169 |
define_raw_perms info 2 thy |> snd |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
170 |
end |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
171 |
*} |
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
172 |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
173 |
print_theorems |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
174 |
*) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
175 |
|
1253 | 176 |
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
|
177 |
fun define_lifted_perms qtys full_tnames name_term_pairs thms thy = |
1253 | 178 |
let |
179 |
val lthy = |
|
180 |
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
|
181 |
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
|
182 |
val lifted_thms = map (Quotient_Tacs.lifted qtys lthy') thms; |
1253 | 183 |
fun tac _ = |
184 |
Class.intro_classes_tac [] THEN |
|
185 |
(ALLGOALS (resolve_tac lifted_thms)) |
|
186 |
val lthy'' = Class.prove_instantiation_instance tac lthy' |
|
187 |
in |
|
188 |
Local_Theory.exit_global lthy'' |
|
189 |
end |
|
190 |
*} |
|
191 |
||
1342 | 192 |
ML {* |
193 |
fun neq_to_rel r neq = |
|
194 |
let |
|
195 |
val neq = HOLogic.dest_Trueprop (prop_of neq) |
|
196 |
val eq = HOLogic.dest_not neq |
|
197 |
val (lhs, rhs) = HOLogic.dest_eq eq |
|
198 |
val rel = r $ lhs $ rhs |
|
199 |
val nrel = HOLogic.mk_not rel |
|
200 |
in |
|
201 |
HOLogic.mk_Trueprop nrel |
|
202 |
end |
|
203 |
*} |
|
204 |
||
205 |
ML {* |
|
206 |
fun neq_to_rel_tac cases distinct = |
|
207 |
rtac notI THEN' eresolve_tac cases THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps distinct) |
|
208 |
*} |
|
209 |
||
210 |
ML {* |
|
211 |
fun distinct_rel ctxt cases (dists, rel) = |
|
212 |
let |
|
213 |
val ((_, thms), ctxt') = Variable.import false dists ctxt |
|
214 |
val terms = map (neq_to_rel rel) thms |
|
215 |
val nrels = map (fn t => Goal.prove ctxt' [] [] t (fn _ => neq_to_rel_tac cases dists 1)) terms |
|
216 |
in |
|
217 |
Variable.export ctxt' ctxt nrels |
|
218 |
end |
|
219 |
*} |
|
220 |
||
221 |
||
222 |
||
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
223 |
(* Test *) |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
224 |
(*atom_decl name |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
225 |
|
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
|
226 |
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
|
227 |
Var "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
|
228 |
| App "trm" "trm list" |
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
|
229 |
| 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
|
230 |
| Let "bp" "trm" "trm" |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
231 |
and bp = |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
232 |
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
|
233 |
| 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
|
234 |
| BPair "bp" "bp" |
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
235 |
|
1899
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
236 |
setup {* fn thy => |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
237 |
let |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
238 |
val inf = Datatype.the_info thy "Perm.trm" |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
239 |
in |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
240 |
define_raw_perms inf 2 thy |> snd |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
241 |
end |
8e0bfb14f6bf
optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents:
1896
diff
changeset
|
242 |
*} |
1170
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
243 |
|
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
244 |
print_theorems |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
245 |
*) |
a7b4160ef463
Wrapped the permutation code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1164
diff
changeset
|
246 |
|
1159
3c6bee89d826
Ported Stefan's permutation code, still needs some localizing.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
247 |
end |