author | blanchet |
Mon, 08 Sep 2014 23:04:18 +0200 | |
changeset 58239 | 1c5bc387bd4c |
parent 58114 | 4e5a43b0e7dd |
child 58242 | 3fb224b61995 |
permissions | -rw-r--r-- |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
1 |
(* Title: HOL/Tools/Old_Datatype/old_datatype.ML |
11539 | 2 |
Author: Stefan Berghofer, TU Muenchen |
5177 | 3 |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
4 |
Datatype package: definitional introduction of datatypes |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
5 |
with proof of characteristic theorems: injectivity / distinctness |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
6 |
of constructors and induction. Main interface to datatypes |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
7 |
after full bootstrap of datatype package. |
5177 | 8 |
*) |
9 |
||
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
10 |
signature OLD_DATATYPE = |
6360 | 11 |
sig |
58114 | 12 |
include OLD_DATATYPE_COMMON |
13 |
||
45909 | 14 |
val distinct_lemma: thm |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
15 |
type spec_cmd = |
58114 | 16 |
(binding * (string * string option) list * mixfix) * (binding * string list * mixfix) list |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
17 |
val read_specs: spec_cmd list -> theory -> spec list * Proof.context |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
18 |
val check_specs: spec list -> theory -> spec list * Proof.context |
58114 | 19 |
val add_datatype: config -> spec list -> theory -> string list * theory |
20 |
val add_datatype_cmd: config -> spec_cmd list -> theory -> string list * theory |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
21 |
val spec_cmd: spec_cmd parser |
32717
0e787c721fa3
re-established reasonable inner outline for module
haftmann
parents:
32712
diff
changeset
|
22 |
end; |
0e787c721fa3
re-established reasonable inner outline for module
haftmann
parents:
32712
diff
changeset
|
23 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
24 |
structure Old_Datatype : OLD_DATATYPE = |
33963
977b94b64905
renamed former datatype.ML to datatype_data.ML; datatype.ML provides uniform view on datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33959
diff
changeset
|
25 |
struct |
5177 | 26 |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
27 |
(** auxiliary **) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
28 |
|
45909 | 29 |
val distinct_lemma = @{lemma "f x \<noteq> f y ==> x \<noteq> y" by iprover}; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
30 |
val (_ $ (_ $ (_ $ (distinct_f $ _) $ _))) = hd (prems_of distinct_lemma); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
31 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
32 |
fun exh_thm_of (dt_info : Old_Datatype_Aux.info Symtab.table) tname = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
33 |
#exhaust (the (Symtab.lookup dt_info tname)); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
34 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
35 |
val In0_inject = @{thm In0_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
36 |
val In1_inject = @{thm In1_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
37 |
val Scons_inject = @{thm Scons_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
38 |
val Leaf_inject = @{thm Leaf_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
39 |
val In0_eq = @{thm In0_eq}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
40 |
val In1_eq = @{thm In1_eq}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
41 |
val In0_not_In1 = @{thm In0_not_In1}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
42 |
val In1_not_In0 = @{thm In1_not_In0}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
43 |
val Lim_inject = @{thm Lim_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
44 |
val Inl_inject = @{thm Inl_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
45 |
val Inr_inject = @{thm Inr_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
46 |
val Suml_inject = @{thm Suml_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
47 |
val Sumr_inject = @{thm Sumr_inject}; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
48 |
|
40719 | 49 |
val datatype_injI = |
50 |
@{lemma "(!!x. ALL y. f x = f y --> x = y) ==> inj f" by (simp add: inj_on_def)}; |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
51 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
52 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
53 |
(** proof of characteristic theorems **) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
54 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
55 |
fun representation_proofs (config : Old_Datatype_Aux.config) |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
56 |
(dt_info : Old_Datatype_Aux.info Symtab.table) descr types_syntax constr_syntax case_names_induct |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
57 |
thy = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
58 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
59 |
val descr' = flat descr; |
45701 | 60 |
val new_type_names = map (Binding.name_of o fst) types_syntax; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
61 |
val big_name = space_implode "_" new_type_names; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
62 |
val thy1 = Sign.add_path big_name thy; |
55408
479a779b89a6
use names like 'rec_mytype' and 'case_mytype' in old datatype package as well, to avoid a mixture
blanchet
parents:
54742
diff
changeset
|
63 |
val big_rec_name = "rep_set_" ^ big_name; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
64 |
val rep_set_names' = |
45743 | 65 |
if length descr' = 1 then [big_rec_name] |
45821 | 66 |
else map (prefix (big_rec_name ^ "_") o string_of_int) (1 upto length descr'); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
67 |
val rep_set_names = map (Sign.full_bname thy1) rep_set_names'; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
68 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
69 |
val tyvars = map (fn (_, (_, Ts, _)) => map Old_Datatype_Aux.dest_DtTFree Ts) (hd descr); |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
70 |
val leafTs' = Old_Datatype_Aux.get_nonrec_types descr'; |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
71 |
val branchTs = Old_Datatype_Aux.get_branching_types descr'; |
45700 | 72 |
val branchT = |
73 |
if null branchTs then HOLogic.unitT |
|
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
36960
diff
changeset
|
74 |
else Balanced_Tree.make (fn (T, U) => Type (@{type_name Sum_Type.sum}, [T, U])) branchTs; |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
75 |
val arities = remove (op =) 0 (Old_Datatype_Aux.get_arities descr'); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
76 |
val unneeded_vars = |
45822 | 77 |
subtract (op =) (fold Term.add_tfreesT (leafTs' @ branchTs) []) (hd tyvars); |
78 |
val leafTs = leafTs' @ map TFree unneeded_vars; |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
79 |
val recTs = Old_Datatype_Aux.get_rec_types descr'; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
80 |
val (newTs, oldTs) = chop (length (hd descr)) recTs; |
45700 | 81 |
val sumT = |
82 |
if null leafTs then HOLogic.unitT |
|
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
36960
diff
changeset
|
83 |
else Balanced_Tree.make (fn (T, U) => Type (@{type_name Sum_Type.sum}, [T, U])) leafTs; |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
84 |
val Univ_elT = HOLogic.mk_setT (Type (@{type_name Old_Datatype.node}, [sumT, branchT])); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
85 |
val UnivT = HOLogic.mk_setT Univ_elT; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
86 |
val UnivT' = Univ_elT --> HOLogic.boolT; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
87 |
val Collect = Const (@{const_name Collect}, UnivT' --> UnivT); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
88 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
89 |
val In0 = Const (@{const_name Old_Datatype.In0}, Univ_elT --> Univ_elT); |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
90 |
val In1 = Const (@{const_name Old_Datatype.In1}, Univ_elT --> Univ_elT); |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
91 |
val Leaf = Const (@{const_name Old_Datatype.Leaf}, sumT --> Univ_elT); |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
92 |
val Lim = Const (@{const_name Old_Datatype.Lim}, (branchT --> Univ_elT) --> Univ_elT); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
93 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
94 |
(* make injections needed for embedding types in leaves *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
95 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
96 |
fun mk_inj T' x = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
97 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
98 |
fun mk_inj' T n i = |
45700 | 99 |
if n = 1 then x |
100 |
else |
|
101 |
let |
|
102 |
val n2 = n div 2; |
|
103 |
val Type (_, [T1, T2]) = T; |
|
104 |
in |
|
105 |
if i <= n2 |
|
45821 | 106 |
then Const (@{const_name Inl}, T1 --> T) $ mk_inj' T1 n2 i |
107 |
else Const (@{const_name Inr}, T2 --> T) $ mk_inj' T2 (n - n2) (i - n2) |
|
45700 | 108 |
end; |
109 |
in mk_inj' sumT (length leafTs) (1 + find_index (fn T'' => T'' = T') leafTs) end; |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
110 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
111 |
(* make injections for constructors *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
112 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
113 |
fun mk_univ_inj ts = Balanced_Tree.access |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
114 |
{left = fn t => In0 $ t, |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
115 |
right = fn t => In1 $ t, |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
116 |
init = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
117 |
if ts = [] then Const (@{const_name undefined}, Univ_elT) |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
118 |
else foldr1 (HOLogic.mk_binop @{const_name Old_Datatype.Scons}) ts}; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
119 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
120 |
(* function spaces *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
121 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
122 |
fun mk_fun_inj T' x = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
123 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
124 |
fun mk_inj T n i = |
45700 | 125 |
if n = 1 then x |
126 |
else |
|
127 |
let |
|
128 |
val n2 = n div 2; |
|
129 |
val Type (_, [T1, T2]) = T; |
|
130 |
fun mkT U = (U --> Univ_elT) --> T --> Univ_elT; |
|
131 |
in |
|
45878 | 132 |
if i <= n2 then Const (@{const_name Sum_Type.Suml}, mkT T1) $ mk_inj T1 n2 i |
133 |
else Const (@{const_name Sum_Type.Sumr}, mkT T2) $ mk_inj T2 (n - n2) (i - n2) |
|
45700 | 134 |
end; |
135 |
in mk_inj branchT (length branchTs) (1 + find_index (fn T'' => T'' = T') branchTs) end; |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
136 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
137 |
fun mk_lim t Ts = fold_rev (fn T => fn t => Lim $ mk_fun_inj T (Abs ("x", T, t))) Ts t; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
138 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
139 |
(************** generate introduction rules for representing set **********) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
140 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
141 |
val _ = Old_Datatype_Aux.message config "Constructing representing sets ..."; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
142 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
143 |
(* make introduction rule for a single constructor *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
144 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
145 |
fun make_intr s n (i, (_, cargs)) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
146 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
147 |
fun mk_prem dt (j, prems, ts) = |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
148 |
(case Old_Datatype_Aux.strip_dtyp dt of |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
149 |
(dts, Old_Datatype_Aux.DtRec k) => |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
150 |
let |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
151 |
val Ts = map (Old_Datatype_Aux.typ_of_dtyp descr') dts; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
152 |
val free_t = |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
153 |
Old_Datatype_Aux.app_bnds (Old_Datatype_Aux.mk_Free "x" (Ts ---> Univ_elT) j) |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
154 |
(length Ts) |
45700 | 155 |
in |
46218
ecf6375e2abb
renamed Term.list_all to Logic.list_all, in accordance to HOLogic.list_all;
wenzelm
parents:
45910
diff
changeset
|
156 |
(j + 1, Logic.list_all (map (pair "x") Ts, |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
157 |
HOLogic.mk_Trueprop |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
158 |
(Free (nth rep_set_names' k, UnivT') $ free_t)) :: prems, |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
159 |
mk_lim free_t Ts :: ts) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
160 |
end |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
161 |
| _ => |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
162 |
let val T = Old_Datatype_Aux.typ_of_dtyp descr' dt |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
163 |
in (j + 1, prems, (Leaf $ mk_inj T (Old_Datatype_Aux.mk_Free "x" T j)) :: ts) end); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
164 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
165 |
val (_, prems, ts) = fold_rev mk_prem cargs (1, [], []); |
45700 | 166 |
val concl = HOLogic.mk_Trueprop (Free (s, UnivT') $ mk_univ_inj ts n i); |
167 |
in Logic.list_implies (prems, concl) end; |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
168 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
169 |
val intr_ts = maps (fn ((_, (_, _, constrs)), rep_set_name) => |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
170 |
map (make_intr rep_set_name (length constrs)) |
45821 | 171 |
((1 upto length constrs) ~~ constrs)) (descr' ~~ rep_set_names'); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
172 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
173 |
val ({raw_induct = rep_induct, intrs = rep_intrs, ...}, thy2) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
174 |
thy1 |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
175 |
|> Sign.map_naming Name_Space.conceal |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
176 |
|> Inductive.add_inductive_global |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
177 |
{quiet_mode = #quiet config, verbose = false, alt_name = Binding.name big_rec_name, |
49170
03bee3a6a1b7
discontinued obsolete fork_mono to loosen some brakes -- NB: TTY interaction has Goal.future_proofs disabled due to missing Future.worker_task;
wenzelm
parents:
46961
diff
changeset
|
178 |
coind = false, no_elim = true, no_ind = false, skip_mono = true} |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
179 |
(map (fn s => ((Binding.name s, UnivT'), NoSyn)) rep_set_names') [] |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
180 |
(map (fn x => (Attrib.empty_binding, x)) intr_ts) [] |
52788 | 181 |
||> Sign.restore_naming thy1; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
182 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
183 |
(********************************* typedef ********************************) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
184 |
|
45701 | 185 |
val (typedefs, thy3) = thy2 |
186 |
|> Sign.parent_path |
|
187 |
|> fold_map |
|
188 |
(fn (((name, mx), tvs), c) => |
|
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
58114
diff
changeset
|
189 |
Typedef.add_typedef_global false (name, tvs, mx) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
190 |
(Collect $ Const (c, UnivT')) NONE |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
191 |
(rtac exI 1 THEN rtac CollectI 1 THEN |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
192 |
QUIET_BREADTH_FIRST (has_fewer_prems 1) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
193 |
(resolve_tac rep_intrs 1))) |
45878 | 194 |
(types_syntax ~~ tyvars ~~ take (length newTs) rep_set_names) |
45701 | 195 |
||> Sign.add_path big_name; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
196 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
197 |
(*********************** definition of constructors ***********************) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
198 |
|
45878 | 199 |
val big_rep_name = big_name ^ "_Rep_"; |
45701 | 200 |
val rep_names' = map (fn i => big_rep_name ^ string_of_int i) (1 upto length (flat (tl descr))); |
201 |
val all_rep_names = |
|
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
202 |
map (#Rep_name o #1 o #2) typedefs @ |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
203 |
map (Sign.full_bname thy3) rep_names'; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
204 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
205 |
(* isomorphism declarations *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
206 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
207 |
val iso_decls = map (fn (T, s) => (Binding.name s, T --> Univ_elT, NoSyn)) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
208 |
(oldTs ~~ rep_names'); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
209 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
210 |
(* constructor definitions *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
211 |
|
45889 | 212 |
fun make_constr_def (typedef: Typedef.info) T n |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
213 |
((cname, cargs), (cname', mx)) (thy, defs, eqns, i) = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
214 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
215 |
fun constr_arg dt (j, l_args, r_args) = |
41423 | 216 |
let |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
217 |
val T = Old_Datatype_Aux.typ_of_dtyp descr' dt; |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
218 |
val free_t = Old_Datatype_Aux.mk_Free "x" T j; |
45700 | 219 |
in |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
220 |
(case (Old_Datatype_Aux.strip_dtyp dt, strip_type T) of |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
221 |
((_, Old_Datatype_Aux.DtRec m), (Us, U)) => |
45700 | 222 |
(j + 1, free_t :: l_args, mk_lim |
223 |
(Const (nth all_rep_names m, U --> Univ_elT) $ |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
224 |
Old_Datatype_Aux.app_bnds free_t (length Us)) Us :: r_args) |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
225 |
| _ => (j + 1, free_t :: l_args, (Leaf $ mk_inj T free_t) :: r_args)) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
226 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
227 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
228 |
val (_, l_args, r_args) = fold_rev constr_arg cargs (1, [], []); |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
229 |
val constrT = map (Old_Datatype_Aux.typ_of_dtyp descr') cargs ---> T; |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
230 |
val ({Abs_name, Rep_name, ...}, _) = typedef; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
231 |
val lhs = list_comb (Const (cname, constrT), l_args); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
232 |
val rhs = mk_univ_inj r_args n i; |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
233 |
val def = Logic.mk_equals (lhs, Const (Abs_name, Univ_elT --> T) $ rhs); |
46909 | 234 |
val def_name = Thm.def_name (Long_Name.base_name cname); |
45821 | 235 |
val eqn = |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
236 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (Const (Rep_name, T --> Univ_elT) $ lhs, rhs)); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
237 |
val ([def_thm], thy') = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
238 |
thy |
56239 | 239 |
|> Sign.add_consts [(cname', constrT, mx)] |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39302
diff
changeset
|
240 |
|> (Global_Theory.add_defs false o map Thm.no_attributes) [(Binding.name def_name, def)]; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
241 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
242 |
in (thy', defs @ [def_thm], eqns @ [eqn], i + 1) end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
243 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
244 |
(* constructor definitions for datatype *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
245 |
|
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
246 |
fun dt_constr_defs (((((_, (_, _, constrs)), tname), typedef: Typedef.info), T), constr_syntax) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
247 |
(thy, defs, eqns, rep_congs, dist_lemmas) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
248 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
249 |
val _ $ (_ $ (cong_f $ _) $ _) = concl_of arg_cong; |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
250 |
val rep_const = cterm_of thy (Const (#Rep_name (#1 typedef), T --> Univ_elT)); |
45910
566c34b64f70
eliminated Drule.export_without_context which is not really required here;
wenzelm
parents:
45909
diff
changeset
|
251 |
val cong' = cterm_instantiate [(cterm_of thy cong_f, rep_const)] arg_cong; |
566c34b64f70
eliminated Drule.export_without_context which is not really required here;
wenzelm
parents:
45909
diff
changeset
|
252 |
val dist = cterm_instantiate [(cterm_of thy distinct_f, rep_const)] distinct_lemma; |
45700 | 253 |
val (thy', defs', eqns', _) = |
45889 | 254 |
fold (make_constr_def typedef T (length constrs)) |
45700 | 255 |
(constrs ~~ constr_syntax) (Sign.add_path tname thy, defs, [], 1); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
256 |
in |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
257 |
(Sign.parent_path thy', defs', eqns @ [eqns'], |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
258 |
rep_congs @ [cong'], dist_lemmas @ [dist]) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
259 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
260 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
261 |
val (thy4, constr_defs, constr_rep_eqns, rep_congs, dist_lemmas) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
262 |
fold dt_constr_defs |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
263 |
(hd descr ~~ new_type_names ~~ map #2 typedefs ~~ newTs ~~ constr_syntax) |
56239 | 264 |
(thy3 |> Sign.add_consts iso_decls |> Sign.parent_path, [], [], [], []); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
265 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
266 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
267 |
(*********** isomorphisms for new types (introduced by typedef) ***********) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
268 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
269 |
val _ = Old_Datatype_Aux.message config "Proving isomorphism properties ..."; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
270 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
271 |
val collect_simp = rewrite_rule (Proof_Context.init_global thy4) [mk_meta_eq mem_Collect_eq]; |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
272 |
|
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
273 |
val newT_iso_axms = typedefs |> map (fn (_, (_, {Abs_inverse, Rep_inverse, Rep, ...})) => |
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
274 |
(collect_simp Abs_inverse, Rep_inverse, collect_simp Rep)); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
275 |
|
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
276 |
val newT_iso_inj_thms = typedefs |> map (fn (_, (_, {Abs_inject, Rep_inject, ...})) => |
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
277 |
(collect_simp Abs_inject RS iffD1, Rep_inject RS iffD1)); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
278 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
279 |
(********* isomorphisms between existing types and "unfolded" types *******) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
280 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
281 |
(*---------------------------------------------------------------------*) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
282 |
(* isomorphisms are defined using primrec-combinators: *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
283 |
(* generate appropriate functions for instantiating primrec-combinator *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
284 |
(* *) |
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55408
diff
changeset
|
285 |
(* e.g. Rep_dt_i = list_rec ... (%h t y. In1 (Scons (Leaf h) y)) *) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
286 |
(* *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
287 |
(* also generate characteristic equations for isomorphisms *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
288 |
(* *) |
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55408
diff
changeset
|
289 |
(* e.g. Rep_dt_i (cons h t) = In1 (Scons (Rep_dt_j h) (Rep_dt_i t)) *) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
290 |
(*---------------------------------------------------------------------*) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
291 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
292 |
fun make_iso_def k ks n (cname, cargs) (fs, eqns, i) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
293 |
let |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
294 |
val argTs = map (Old_Datatype_Aux.typ_of_dtyp descr') cargs; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
295 |
val T = nth recTs k; |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
296 |
val rep_const = Const (nth all_rep_names k, T --> Univ_elT); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
297 |
val constr = Const (cname, argTs ---> T); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
298 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
299 |
fun process_arg ks' dt (i2, i2', ts, Ts) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
300 |
let |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
301 |
val T' = Old_Datatype_Aux.typ_of_dtyp descr' dt; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
302 |
val (Us, U) = strip_type T' |
45700 | 303 |
in |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
304 |
(case Old_Datatype_Aux.strip_dtyp dt of |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
305 |
(_, Old_Datatype_Aux.DtRec j) => |
45700 | 306 |
if member (op =) ks' j then |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
307 |
(i2 + 1, i2' + 1, ts @ [mk_lim (Old_Datatype_Aux.app_bnds |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
308 |
(Old_Datatype_Aux.mk_Free "y" (Us ---> Univ_elT) i2') (length Us)) Us], |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
309 |
Ts @ [Us ---> Univ_elT]) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
310 |
else |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
311 |
(i2 + 1, i2', ts @ [mk_lim |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
312 |
(Const (nth all_rep_names j, U --> Univ_elT) $ |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
313 |
Old_Datatype_Aux.app_bnds |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
314 |
(Old_Datatype_Aux.mk_Free "x" T' i2) (length Us)) Us], Ts) |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
315 |
| _ => (i2 + 1, i2', ts @ [Leaf $ mk_inj T' (Old_Datatype_Aux.mk_Free "x" T' i2)], Ts)) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
316 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
317 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
318 |
val (i2, i2', ts, Ts) = fold (process_arg ks) cargs (1, 1, [], []); |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
319 |
val xs = map (uncurry (Old_Datatype_Aux.mk_Free "x")) (argTs ~~ (1 upto (i2 - 1))); |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
320 |
val ys = map (uncurry (Old_Datatype_Aux.mk_Free "y")) (Ts ~~ (1 upto (i2' - 1))); |
45878 | 321 |
val f = fold_rev lambda (xs @ ys) (mk_univ_inj ts n i); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
322 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
323 |
val (_, _, ts', _) = fold (process_arg []) cargs (1, 1, [], []); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
324 |
val eqn = HOLogic.mk_Trueprop (HOLogic.mk_eq |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
325 |
(rep_const $ list_comb (constr, xs), mk_univ_inj ts' n i)) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
326 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
327 |
in (fs @ [f], eqns @ [eqn], i + 1) end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
328 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
329 |
(* define isomorphisms for all mutually recursive datatypes in list ds *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
330 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
331 |
fun make_iso_defs ds (thy, char_thms) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
332 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
333 |
val ks = map fst ds; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
334 |
val (_, (tname, _, _)) = hd ds; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
335 |
val {rec_rewrites, rec_names, ...} = the (Symtab.lookup dt_info tname); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
336 |
|
45878 | 337 |
fun process_dt (k, (_, _, constrs)) (fs, eqns, isos) = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
338 |
let |
45700 | 339 |
val (fs', eqns', _) = fold (make_iso_def k ks (length constrs)) constrs (fs, eqns, 1); |
340 |
val iso = (nth recTs k, nth all_rep_names k); |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
341 |
in (fs', eqns', isos @ [iso]) end; |
45700 | 342 |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
343 |
val (fs, eqns, isos) = fold process_dt ds ([], [], []); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
344 |
val fTs = map fastype_of fs; |
45700 | 345 |
val defs = |
346 |
map (fn (rec_name, (T, iso_name)) => |
|
46909 | 347 |
(Binding.name (Thm.def_name (Long_Name.base_name iso_name)), |
45700 | 348 |
Logic.mk_equals (Const (iso_name, T --> Univ_elT), |
349 |
list_comb (Const (rec_name, fTs @ [T] ---> Univ_elT), fs)))) (rec_names ~~ isos); |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
350 |
val (def_thms, thy') = |
52788 | 351 |
(Global_Theory.add_defs false o map Thm.no_attributes) defs thy; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
352 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
353 |
(* prove characteristic equations *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
354 |
|
45878 | 355 |
val rewrites = def_thms @ map mk_meta_eq rec_rewrites; |
45700 | 356 |
val char_thms' = |
51551 | 357 |
map (fn eqn => Goal.prove_sorry_global thy' [] [] eqn |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
358 |
(fn {context = ctxt, ...} => EVERY [rewrite_goals_tac ctxt rewrites, rtac refl 1])) eqns; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
359 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
360 |
in (thy', char_thms' @ char_thms) end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
361 |
|
45700 | 362 |
val (thy5, iso_char_thms) = |
52788 | 363 |
fold_rev make_iso_defs (tl descr) (Sign.add_path big_name thy4, []); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
364 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
365 |
(* prove isomorphism properties *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
366 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
367 |
fun mk_funs_inv thy thm = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
368 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
369 |
val prop = Thm.prop_of thm; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
370 |
val _ $ (_ $ ((S as Const (_, Type (_, [U, _]))) $ _ )) $ |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
371 |
(_ $ (_ $ (r $ (a $ _)) $ _)) = Type.legacy_freeze prop; |
45738 | 372 |
val used = Term.add_tfree_names a []; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
373 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
374 |
fun mk_thm i = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
375 |
let |
56254 | 376 |
val Ts = map (TFree o rpair @{sort type}) (Name.variant_list used (replicate i "'t")); |
45700 | 377 |
val f = Free ("f", Ts ---> U); |
378 |
in |
|
51551 | 379 |
Goal.prove_sorry_global thy [] [] |
45700 | 380 |
(Logic.mk_implies |
381 |
(HOLogic.mk_Trueprop (HOLogic.list_all |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
382 |
(map (pair "x") Ts, S $ Old_Datatype_Aux.app_bnds f i)), |
46219
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
wenzelm
parents:
46218
diff
changeset
|
383 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (fold_rev (Term.abs o pair "x") Ts |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
384 |
(r $ (a $ Old_Datatype_Aux.app_bnds f i)), f)))) |
55990 | 385 |
(fn _ => EVERY [REPEAT_DETERM_N i (rtac @{thm ext} 1), |
45700 | 386 |
REPEAT (etac allE 1), rtac thm 1, atac 1]) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
387 |
end |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
388 |
in map (fn r => r RS subst) (thm :: map mk_thm arities) end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
389 |
|
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55408
diff
changeset
|
390 |
(* prove inj Rep_dt_i and Rep_dt_i x : rep_set_dt_i *) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
391 |
|
45700 | 392 |
val fun_congs = |
393 |
map (fn T => make_elim (Drule.instantiate' [SOME (ctyp_of thy5 T)] [] fun_cong)) branchTs; |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
394 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
395 |
fun prove_iso_thms ds (inj_thms, elem_thms) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
396 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
397 |
val (_, (tname, _, _)) = hd ds; |
45700 | 398 |
val induct = #induct (the (Symtab.lookup dt_info tname)); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
399 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
400 |
fun mk_ind_concl (i, _) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
401 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
402 |
val T = nth recTs i; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
403 |
val Rep_t = Const (nth all_rep_names i, T --> Univ_elT); |
45700 | 404 |
val rep_set_name = nth rep_set_names i; |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
405 |
val concl1 = |
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
406 |
HOLogic.all_const T $ Abs ("y", T, HOLogic.imp $ |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
407 |
HOLogic.mk_eq (Rep_t $ Old_Datatype_Aux.mk_Free "x" T i, Rep_t $ Bound 0) $ |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
408 |
HOLogic.mk_eq (Old_Datatype_Aux.mk_Free "x" T i, Bound 0)); |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
409 |
val concl2 = Const (rep_set_name, UnivT') $ (Rep_t $ Old_Datatype_Aux.mk_Free "x" T i); |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
410 |
in (concl1, concl2) end; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
411 |
|
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
412 |
val (ind_concl1, ind_concl2) = split_list (map mk_ind_concl ds); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
413 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
414 |
val rewrites = map mk_meta_eq iso_char_thms; |
45700 | 415 |
val inj_thms' = map snd newT_iso_inj_thms @ map (fn r => r RS @{thm injD}) inj_thms; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
416 |
|
45700 | 417 |
val inj_thm = |
51551 | 418 |
Goal.prove_sorry_global thy5 [] [] |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
419 |
(HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj ind_concl1)) |
51798 | 420 |
(fn {context = ctxt, ...} => EVERY |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
421 |
[(Old_Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1, |
45700 | 422 |
REPEAT (EVERY |
423 |
[rtac allI 1, rtac impI 1, |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
424 |
Old_Datatype_Aux.exh_tac (exh_thm_of dt_info) 1, |
45700 | 425 |
REPEAT (EVERY |
51798 | 426 |
[hyp_subst_tac ctxt 1, |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
427 |
rewrite_goals_tac ctxt rewrites, |
45700 | 428 |
REPEAT (dresolve_tac [In0_inject, In1_inject] 1), |
429 |
(eresolve_tac [In0_not_In1 RS notE, In1_not_In0 RS notE] 1) |
|
430 |
ORELSE (EVERY |
|
431 |
[REPEAT (eresolve_tac (Scons_inject :: |
|
432 |
map make_elim [Leaf_inject, Inl_inject, Inr_inject]) 1), |
|
433 |
REPEAT (cong_tac 1), rtac refl 1, |
|
434 |
REPEAT (atac 1 ORELSE (EVERY |
|
55990 | 435 |
[REPEAT (rtac @{thm ext} 1), |
45700 | 436 |
REPEAT (eresolve_tac (mp :: allE :: |
437 |
map make_elim (Suml_inject :: Sumr_inject :: |
|
438 |
Lim_inject :: inj_thms') @ fun_congs) 1), |
|
439 |
atac 1]))])])])]); |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
440 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
441 |
val inj_thms'' = map (fn r => r RS datatype_injI) (Old_Datatype_Aux.split_conj_thm inj_thm); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
442 |
|
45700 | 443 |
val elem_thm = |
51551 | 444 |
Goal.prove_sorry_global thy5 [] [] |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
445 |
(HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj ind_concl2)) |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
446 |
(fn {context = ctxt, ...} => |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
447 |
EVERY [ |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
448 |
(Old_Datatype_Aux.ind_tac induct [] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1, |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
449 |
rewrite_goals_tac ctxt rewrites, |
45700 | 450 |
REPEAT ((resolve_tac rep_intrs THEN_ALL_NEW |
451 |
((REPEAT o etac allE) THEN' ares_tac elem_thms)) 1)]); |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
452 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
453 |
in (inj_thms'' @ inj_thms, elem_thms @ Old_Datatype_Aux.split_conj_thm elem_thm) end; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
454 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
455 |
val (iso_inj_thms_unfolded, iso_elem_thms) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
456 |
fold_rev prove_iso_thms (tl descr) ([], map #3 newT_iso_axms); |
45700 | 457 |
val iso_inj_thms = |
458 |
map snd newT_iso_inj_thms @ map (fn r => r RS @{thm injD}) iso_inj_thms_unfolded; |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
459 |
|
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55408
diff
changeset
|
460 |
(* prove rep_set_dt_i x --> x : range Rep_dt_i *) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
461 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
462 |
fun mk_iso_t (((set_name, iso_name), i), T) = |
45700 | 463 |
let val isoT = T --> Univ_elT in |
464 |
HOLogic.imp $ |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
465 |
(Const (set_name, UnivT') $ Old_Datatype_Aux.mk_Free "x" Univ_elT i) $ |
45740 | 466 |
(if i < length newTs then @{term True} |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
467 |
else HOLogic.mk_mem (Old_Datatype_Aux.mk_Free "x" Univ_elT i, |
45700 | 468 |
Const (@{const_name image}, isoT --> HOLogic.mk_setT T --> UnivT) $ |
469 |
Const (iso_name, isoT) $ Const (@{const_abbrev UNIV}, HOLogic.mk_setT T))) |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
470 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
471 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
472 |
val iso_t = HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj (map mk_iso_t |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
473 |
(rep_set_names ~~ all_rep_names ~~ (0 upto (length descr' - 1)) ~~ recTs))); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
474 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
475 |
(* all the theorems are proved by one single simultaneous induction *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
476 |
|
45700 | 477 |
val range_eqs = map (fn r => mk_meta_eq (r RS @{thm range_ex1_eq})) iso_inj_thms_unfolded; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
478 |
|
45700 | 479 |
val iso_thms = |
480 |
if length descr = 1 then [] |
|
481 |
else |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
482 |
drop (length newTs) (Old_Datatype_Aux.split_conj_thm |
51798 | 483 |
(Goal.prove_sorry_global thy5 [] [] iso_t (fn {context = ctxt, ...} => EVERY |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
484 |
[(Old_Datatype_Aux.ind_tac rep_induct [] THEN_ALL_NEW |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
485 |
Object_Logic.atomize_prems_tac ctxt) 1, |
45700 | 486 |
REPEAT (rtac TrueI 1), |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
487 |
rewrite_goals_tac ctxt (mk_meta_eq @{thm choice_eq} :: |
45700 | 488 |
Thm.symmetric (mk_meta_eq @{thm fun_eq_iff}) :: range_eqs), |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
489 |
rewrite_goals_tac ctxt (map Thm.symmetric range_eqs), |
45700 | 490 |
REPEAT (EVERY |
55990 | 491 |
[REPEAT (eresolve_tac ([rangeE, @{thm ex1_implies_ex} RS exE] @ |
45700 | 492 |
maps (mk_funs_inv thy5 o #1) newT_iso_axms) 1), |
51798 | 493 |
TRY (hyp_subst_tac ctxt 1), |
45700 | 494 |
rtac (sym RS range_eqI) 1, |
495 |
resolve_tac iso_char_thms 1])]))); |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
496 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
497 |
val Abs_inverse_thms' = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
498 |
map #1 newT_iso_axms @ |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
499 |
map2 (fn r_inj => fn r => @{thm f_the_inv_into_f} OF [r_inj, r RS mp]) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
500 |
iso_inj_thms_unfolded iso_thms; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
501 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
502 |
val Abs_inverse_thms = maps (mk_funs_inv thy5) Abs_inverse_thms'; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
503 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
504 |
(******************* freeness theorems for constructors *******************) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
505 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
506 |
val _ = Old_Datatype_Aux.message config "Proving freeness of constructors ..."; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
507 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
508 |
(* prove theorem Rep_i (Constr_j ...) = Inj_j ... *) |
45700 | 509 |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
510 |
fun prove_constr_rep_thm eqn = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
511 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
512 |
val inj_thms = map fst newT_iso_inj_thms; |
45878 | 513 |
val rewrites = @{thm o_def} :: constr_defs @ map (mk_meta_eq o #2) newT_iso_axms; |
45700 | 514 |
in |
51551 | 515 |
Goal.prove_sorry_global thy5 [] [] eqn |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
516 |
(fn {context = ctxt, ...} => EVERY |
45700 | 517 |
[resolve_tac inj_thms 1, |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52788
diff
changeset
|
518 |
rewrite_goals_tac ctxt rewrites, |
45700 | 519 |
rtac refl 3, |
520 |
resolve_tac rep_intrs 2, |
|
521 |
REPEAT (resolve_tac iso_elem_thms 1)]) |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
522 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
523 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
524 |
(*--------------------------------------------------------------*) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
525 |
(* constr_rep_thms and rep_congs are used to prove distinctness *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
526 |
(* of constructors. *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
527 |
(*--------------------------------------------------------------*) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
528 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
529 |
val constr_rep_thms = map (map prove_constr_rep_thm) constr_rep_eqns; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
530 |
|
45700 | 531 |
val dist_rewrites = |
532 |
map (fn (rep_thms, dist_lemma) => |
|
45878 | 533 |
dist_lemma :: (rep_thms @ [In0_eq, In1_eq, In0_not_In1, In1_not_In0])) |
45700 | 534 |
(constr_rep_thms ~~ dist_lemmas); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
535 |
|
45889 | 536 |
fun prove_distinct_thms dist_rewrites' = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
537 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
538 |
fun prove [] = [] |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
539 |
| prove (t :: ts) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
540 |
let |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51551
diff
changeset
|
541 |
val dist_thm = Goal.prove_sorry_global thy5 [] [] t (fn {context = ctxt, ...} => |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51551
diff
changeset
|
542 |
EVERY [simp_tac (put_simpset HOL_ss ctxt addsimps dist_rewrites') 1]) |
45910
566c34b64f70
eliminated Drule.export_without_context which is not really required here;
wenzelm
parents:
45909
diff
changeset
|
543 |
in dist_thm :: Drule.zero_var_indexes (dist_thm RS not_sym) :: prove ts end; |
45889 | 544 |
in prove end; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
545 |
|
45700 | 546 |
val distinct_thms = |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
547 |
map2 (prove_distinct_thms) dist_rewrites (Old_Datatype_Prop.make_distincts descr); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
548 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
549 |
(* prove injectivity of constructors *) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
550 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
551 |
fun prove_constr_inj_thm rep_thms t = |
45700 | 552 |
let |
553 |
val inj_thms = Scons_inject :: |
|
554 |
map make_elim |
|
555 |
(iso_inj_thms @ |
|
556 |
[In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject, |
|
557 |
Lim_inject, Suml_inject, Sumr_inject]) |
|
558 |
in |
|
51551 | 559 |
Goal.prove_sorry_global thy5 [] [] t |
51798 | 560 |
(fn {context = ctxt, ...} => EVERY |
45700 | 561 |
[rtac iffI 1, |
51798 | 562 |
REPEAT (etac conjE 2), hyp_subst_tac ctxt 2, rtac refl 2, |
55990 | 563 |
dresolve_tac rep_congs 1, dtac @{thm box_equals} 1, |
45700 | 564 |
REPEAT (resolve_tac rep_thms 1), |
565 |
REPEAT (eresolve_tac inj_thms 1), |
|
55990 | 566 |
REPEAT (ares_tac [conjI] 1 ORELSE (EVERY [REPEAT (rtac @{thm ext} 1), |
45700 | 567 |
REPEAT (eresolve_tac (make_elim fun_cong :: inj_thms) 1), |
568 |
atac 1]))]) |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
569 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
570 |
|
45700 | 571 |
val constr_inject = |
572 |
map (fn (ts, thms) => map (prove_constr_inj_thm thms) ts) |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
573 |
(Old_Datatype_Prop.make_injs descr ~~ constr_rep_thms); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
574 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
575 |
val ((constr_inject', distinct_thms'), thy6) = |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
576 |
thy5 |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
577 |
|> Sign.parent_path |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
578 |
|> Old_Datatype_Aux.store_thmss "inject" new_type_names constr_inject |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
579 |
||>> Old_Datatype_Aux.store_thmss "distinct" new_type_names distinct_thms; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
580 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
581 |
(*************************** induction theorem ****************************) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
582 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
583 |
val _ = Old_Datatype_Aux.message config "Proving induction rule for datatypes ..."; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
584 |
|
45700 | 585 |
val Rep_inverse_thms = |
586 |
map (fn (_, iso, _) => iso RS subst) newT_iso_axms @ |
|
587 |
map (fn r => r RS @{thm the_inv_f_f} RS subst) iso_inj_thms_unfolded; |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
588 |
val Rep_inverse_thms' = map (fn r => r RS @{thm the_inv_f_f}) iso_inj_thms_unfolded; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
589 |
|
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
590 |
fun mk_indrule_lemma (i, _) T = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
591 |
let |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
592 |
val Rep_t = Const (nth all_rep_names i, T --> Univ_elT) $ Old_Datatype_Aux.mk_Free "x" T i; |
45700 | 593 |
val Abs_t = |
594 |
if i < length newTs then |
|
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
595 |
Const (#Abs_name (#1 (#2 (nth typedefs i))), Univ_elT --> T) |
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
596 |
else |
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
597 |
Const (@{const_name the_inv_into}, |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
598 |
[HOLogic.mk_setT T, T --> Univ_elT, Univ_elT] ---> T) $ |
45700 | 599 |
HOLogic.mk_UNIV T $ Const (nth all_rep_names i, T --> Univ_elT); |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
600 |
val prem = |
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
601 |
HOLogic.imp $ |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
602 |
(Const (nth rep_set_names i, UnivT') $ Rep_t) $ |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
603 |
(Old_Datatype_Aux.mk_Free "P" (T --> HOLogic.boolT) (i + 1) $ (Abs_t $ Rep_t)); |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
604 |
val concl = |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
605 |
Old_Datatype_Aux.mk_Free "P" (T --> HOLogic.boolT) (i + 1) $ |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
606 |
Old_Datatype_Aux.mk_Free "x" T i; |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
607 |
in (prem, concl) end; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
608 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
609 |
val (indrule_lemma_prems, indrule_lemma_concls) = |
45879
71b8d0d170b1
avoid fragile Sign.intern_const -- pass internal names directly;
wenzelm
parents:
45878
diff
changeset
|
610 |
split_list (map2 mk_indrule_lemma descr' recTs); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
611 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
612 |
val cert = cterm_of thy6; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
613 |
|
45700 | 614 |
val indrule_lemma = |
51551 | 615 |
Goal.prove_sorry_global thy6 [] [] |
45700 | 616 |
(Logic.mk_implies |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
617 |
(HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj indrule_lemma_prems), |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
618 |
HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj indrule_lemma_concls))) |
45700 | 619 |
(fn _ => |
620 |
EVERY |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
621 |
[REPEAT (etac conjE 1), |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
622 |
REPEAT (EVERY |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
623 |
[TRY (rtac conjI 1), resolve_tac Rep_inverse_thms 1, |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
624 |
etac mp 1, resolve_tac iso_elem_thms 1])]); |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
625 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
626 |
val Ps = map head_of (HOLogic.dest_conj (HOLogic.dest_Trueprop (concl_of indrule_lemma))); |
45700 | 627 |
val frees = |
628 |
if length Ps = 1 then [Free ("P", snd (dest_Var (hd Ps)))] |
|
629 |
else map (Free o apfst fst o dest_Var) Ps; |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
630 |
val indrule_lemma' = cterm_instantiate (map cert Ps ~~ map cert frees) indrule_lemma; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
631 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
632 |
val dt_induct_prop = Old_Datatype_Prop.make_ind descr; |
45700 | 633 |
val dt_induct = |
51551 | 634 |
Goal.prove_sorry_global thy6 [] |
45700 | 635 |
(Logic.strip_imp_prems dt_induct_prop) |
636 |
(Logic.strip_imp_concl dt_induct_prop) |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51551
diff
changeset
|
637 |
(fn {context = ctxt, prems, ...} => |
45700 | 638 |
EVERY |
639 |
[rtac indrule_lemma' 1, |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
640 |
(Old_Datatype_Aux.ind_tac rep_induct [] THEN_ALL_NEW |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
641 |
Object_Logic.atomize_prems_tac ctxt) 1, |
45700 | 642 |
EVERY (map (fn (prem, r) => (EVERY |
643 |
[REPEAT (eresolve_tac Abs_inverse_thms 1), |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51551
diff
changeset
|
644 |
simp_tac (put_simpset HOL_basic_ss ctxt |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51551
diff
changeset
|
645 |
addsimps (Thm.symmetric r :: Rep_inverse_thms')) 1, |
45700 | 646 |
DEPTH_SOLVE_1 (ares_tac [prem] 1 ORELSE etac allE 1)])) |
45878 | 647 |
(prems ~~ (constr_defs @ map mk_meta_eq iso_char_thms)))]); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
648 |
|
45901
cea7cd0c7e99
eliminated old-fashioned Global_Theory.add_thms(s);
wenzelm
parents:
45890
diff
changeset
|
649 |
val ([(_, [dt_induct'])], thy7) = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
650 |
thy6 |
45901
cea7cd0c7e99
eliminated old-fashioned Global_Theory.add_thms(s);
wenzelm
parents:
45890
diff
changeset
|
651 |
|> Global_Theory.note_thmss "" |
cea7cd0c7e99
eliminated old-fashioned Global_Theory.add_thms(s);
wenzelm
parents:
45890
diff
changeset
|
652 |
[((Binding.qualify true big_name (Binding.name "induct"), [case_names_induct]), |
52788 | 653 |
[([dt_induct], [])])]; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
654 |
in |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
655 |
((constr_inject', distinct_thms', dt_induct'), thy7) |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
656 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
657 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
658 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
659 |
|
45701 | 660 |
(** datatype definition **) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
661 |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
662 |
(* specifications *) |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
663 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
664 |
type spec_cmd = |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
665 |
(binding * (string * string option) list * mixfix) * (binding * string list * mixfix) list; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
666 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
667 |
local |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
668 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
669 |
fun parse_spec ctxt ((b, args, mx), constrs) = |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
670 |
((b, map (apsnd (Typedecl.read_constraint ctxt)) args, mx), |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
671 |
constrs |> map (fn (c, Ts, mx') => (c, map (Syntax.parse_typ ctxt) Ts, mx'))); |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
672 |
|
58114 | 673 |
fun check_specs ctxt (specs: Old_Datatype_Aux.spec list) = |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
674 |
let |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
675 |
fun prep_spec ((tname, args, mx), constrs) tys = |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
676 |
let |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
677 |
val (args', tys1) = chop (length args) tys; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
678 |
val (constrs', tys3) = (constrs, tys1) |-> fold_map (fn (cname, cargs, mx') => fn tys2 => |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
679 |
let val (cargs', tys3) = chop (length cargs) tys2; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
680 |
in ((cname, cargs', mx'), tys3) end); |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
681 |
in (((tname, map dest_TFree args', mx), constrs'), tys3) end; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
682 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
683 |
val all_tys = |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
684 |
specs |> maps (fn ((_, args, _), cs) => map TFree args @ maps #2 cs) |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
685 |
|> Syntax.check_typs ctxt; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
686 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
687 |
in #1 (fold_map prep_spec specs all_tys) end; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
688 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
689 |
fun prep_specs parse raw_specs thy = |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
690 |
let |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
691 |
val ctxt = thy |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
692 |
|> Sign.add_types_global (map (fn ((b, args, mx), _) => (b, length args, mx)) raw_specs) |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
693 |
|> Proof_Context.init_global |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
694 |
|> fold (fn ((_, args, _), _) => fold (fn (a, _) => |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
695 |
Variable.declare_typ (TFree (a, dummyS))) args) raw_specs; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
696 |
val specs = check_specs ctxt (map (parse ctxt) raw_specs); |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
697 |
in (specs, ctxt) end; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
698 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
699 |
in |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
700 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
701 |
val read_specs = prep_specs parse_spec; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
702 |
val check_specs = prep_specs (K I); |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
703 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
704 |
end; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
705 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
706 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
707 |
(* main commands *) |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
708 |
|
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
709 |
fun gen_add_datatype prep_specs config raw_specs thy = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
710 |
let |
56249 | 711 |
val _ = Theory.requires thy (Context.theory_name @{theory}) "datatype definitions"; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
712 |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
713 |
val (dts, spec_ctxt) = prep_specs raw_specs thy; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
714 |
val ((_, tyvars, _), _) :: _ = dts; |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
715 |
val string_of_tyvar = Syntax.string_of_typ spec_ctxt o TFree; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
716 |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
717 |
val (new_dts, types_syntax) = dts |> map (fn ((tname, tvs, mx), _) => |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
718 |
let val full_tname = Sign.full_name thy tname in |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
719 |
(case duplicates (op =) tvs of |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
720 |
[] => |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
721 |
if eq_set (op =) (tyvars, tvs) then ((full_tname, tvs), (tname, mx)) |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
722 |
else error "Mutually recursive datatypes must have same type parameters" |
45700 | 723 |
| dups => |
724 |
error ("Duplicate parameter(s) for datatype " ^ Binding.print tname ^ |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
725 |
" : " ^ commas (map string_of_tyvar dups))) |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
726 |
end) |> split_list; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
727 |
val dt_names = map fst new_dts; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
728 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
729 |
val _ = |
45701 | 730 |
(case duplicates (op =) (map fst new_dts) of |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
731 |
[] => () |
45822 | 732 |
| dups => error ("Duplicate datatypes: " ^ commas_quote dups)); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
733 |
|
45889 | 734 |
fun prep_dt_spec ((tname, tvs, _), constrs) (dts', constr_syntax, i) = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
735 |
let |
45889 | 736 |
fun prep_constr (cname, cargs, mx) (constrs, constr_syntax') = |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
737 |
let |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
738 |
val _ = |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
739 |
(case subtract (op =) tvs (fold Term.add_tfreesT cargs []) of |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
740 |
[] => () |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
741 |
| vs => error ("Extra type variables on rhs: " ^ commas (map string_of_tyvar vs))); |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
742 |
val c = Sign.full_name_path thy (Binding.name_of tname) cname; |
35129 | 743 |
in |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
744 |
(constrs @ [(c, map (Old_Datatype_Aux.dtyp_of_typ new_dts) cargs)], |
45889 | 745 |
constr_syntax' @ [(cname, mx)]) |
45700 | 746 |
end handle ERROR msg => |
747 |
cat_error msg ("The error above occurred in constructor " ^ Binding.print cname ^ |
|
748 |
" of datatype " ^ Binding.print tname); |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
749 |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
750 |
val (constrs', constr_syntax') = fold prep_constr constrs ([], []); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
751 |
in |
45700 | 752 |
(case duplicates (op =) (map fst constrs') of |
35129 | 753 |
[] => |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
754 |
(dts' @ [(i, (Sign.full_name thy tname, map Old_Datatype_Aux.DtTFree tvs, constrs'))], |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
755 |
constr_syntax @ [constr_syntax'], i + 1) |
42381
309ec68442c6
added Binding.print convenience, which includes quote already;
wenzelm
parents:
42375
diff
changeset
|
756 |
| dups => |
45822 | 757 |
error ("Duplicate constructors " ^ commas_quote dups ^ |
758 |
" in datatype " ^ Binding.print tname)) |
|
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
759 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
760 |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
761 |
val (dts', constr_syntax, i) = fold prep_dt_spec dts ([], [], 0); |
45822 | 762 |
|
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
763 |
val dt_info = Old_Datatype_Data.get_all thy; |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
764 |
val (descr, _) = Old_Datatype_Aux.unfold_datatypes spec_ctxt dts' dt_info dts' i; |
41423 | 765 |
val _ = |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
766 |
Old_Datatype_Aux.check_nonempty descr |
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
767 |
handle (exn as Old_Datatype_Aux.Datatype_Empty s) => |
45822 | 768 |
if #strict config then error ("Nonemptiness check failed for datatype " ^ quote s) |
41423 | 769 |
else reraise exn; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
770 |
|
45701 | 771 |
val _ = |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
772 |
Old_Datatype_Aux.message config |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
773 |
("Constructing datatype(s) " ^ commas_quote (map (Binding.name_of o #1 o #1) dts)); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
774 |
in |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
775 |
thy |
45822 | 776 |
|> representation_proofs config dt_info descr types_syntax constr_syntax |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
777 |
(Old_Datatype_Data.mk_case_names_induct (flat descr)) |
45700 | 778 |
|-> (fn (inject, distinct, induct) => |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
779 |
Old_Rep_Datatype.derive_datatype_props config dt_names descr induct inject distinct) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
780 |
end; |
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
781 |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
782 |
val add_datatype = gen_add_datatype check_specs; |
45863 | 783 |
val add_datatype_cmd = gen_add_datatype read_specs; |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
784 |
|
45701 | 785 |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
786 |
(* outer syntax *) |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
787 |
|
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
788 |
val spec_cmd = |
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
789 |
Parse.type_args_constrained -- Parse.binding -- Parse.opt_mixfix -- |
46949 | 790 |
(@{keyword "="} |-- Parse.enum1 "|" (Parse.binding -- Scan.repeat Parse.typ -- Parse.opt_mixfix)) |
45839
43a5b86bc102
'datatype' specifications allow explicit sort constraints;
wenzelm
parents:
45822
diff
changeset
|
791 |
>> (fn (((vs, t), mx), cons) => ((t, vs, mx), map Parse.triple1 cons)); |
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
792 |
|
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
793 |
val _ = |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
794 |
Outer_Syntax.command @{command_spec "datatype"} "define inductive datatypes" |
45863 | 795 |
(Parse.and_list1 spec_cmd |
58112
8081087096ad
renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents:
58111
diff
changeset
|
796 |
>> (Toplevel.theory o (snd oo add_datatype_cmd Old_Datatype_Aux.default_config))); |
41423 | 797 |
|
58114 | 798 |
open Old_Datatype_Aux; |
799 |
||
33968
f94fb13ecbb3
modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents:
33963
diff
changeset
|
800 |
end; |