author | blanchet |
Wed, 26 Sep 2012 10:00:59 +0200 | |
changeset 49586 | d5e342ffe91e |
parent 49585 | 5c4a12550491 |
child 49630 | 9f6ca87ab405 |
permissions | -rw-r--r-- |
49509
163914705f8d
renamed top-level theory from "Codatatype" to "BNF"
blanchet
parents:
49507
diff
changeset
|
1 |
(* Title: HOL/BNF/Tools/bnf_comp.ML |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
2 |
Author: Dmitriy Traytel, TU Muenchen |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
3 |
Author: Jasmin Blanchette, TU Muenchen |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
4 |
Copyright 2012 |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
5 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
6 |
Composition of bounded natural functors. |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
7 |
*) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
8 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
9 |
signature BNF_COMP = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
10 |
sig |
49585
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49538
diff
changeset
|
11 |
val ID_bnf: BNF_Def.BNF |
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49538
diff
changeset
|
12 |
val DEADID_bnf: BNF_Def.BNF |
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49538
diff
changeset
|
13 |
|
49502 | 14 |
type unfold_set |
15 |
val empty_unfolds: unfold_set |
|
16 |
val map_unfolds_of: unfold_set -> thm list |
|
49507 | 17 |
val rel_unfolds_of: unfold_set -> thm list |
49502 | 18 |
val set_unfoldss_of: unfold_set -> thm list list |
49506 | 19 |
val srel_unfolds_of: unfold_set -> thm list |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
20 |
|
49425 | 21 |
val bnf_of_typ: BNF_Def.const_policy -> (binding -> binding) -> |
49502 | 22 |
((string * sort) list list -> (string * sort) list) -> typ -> unfold_set * Proof.context -> |
23 |
(BNF_Def.BNF * (typ list * typ list)) * (unfold_set * Proof.context) |
|
49014 | 24 |
val default_comp_sort: (string * sort) list list -> (string * sort) list |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
25 |
val normalize_bnfs: (int -> binding -> binding) -> ''a list list -> ''a list -> |
49502 | 26 |
(''a list list -> ''a list) -> BNF_Def.BNF list -> unfold_set -> Proof.context -> |
27 |
(int list list * ''a list) * (BNF_Def.BNF list * (unfold_set * Proof.context)) |
|
28 |
val seal_bnf: unfold_set -> binding -> typ list -> BNF_Def.BNF -> Proof.context -> |
|
49185
073d7d1b7488
respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents:
49155
diff
changeset
|
29 |
(BNF_Def.BNF * typ list) * local_theory |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
30 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
31 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
32 |
structure BNF_Comp : BNF_COMP = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
33 |
struct |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
34 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
35 |
open BNF_Def |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
36 |
open BNF_Util |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
37 |
open BNF_Tactics |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
38 |
open BNF_Comp_Tactics |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
39 |
|
49585
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49538
diff
changeset
|
40 |
val ID_bnf = the (bnf_of @{context} "Basic_BNFs.ID"); |
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49538
diff
changeset
|
41 |
val DEADID_bnf = the (bnf_of @{context} "Basic_BNFs.DEADID"); |
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49538
diff
changeset
|
42 |
|
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49538
diff
changeset
|
43 |
(* TODO: Replace by "BNF_Defs.defs list" *) |
49502 | 44 |
type unfold_set = { |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
45 |
map_unfolds: thm list, |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
46 |
set_unfoldss: thm list list, |
49507 | 47 |
rel_unfolds: thm list, |
49506 | 48 |
srel_unfolds: thm list |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
49 |
}; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
50 |
|
49507 | 51 |
val empty_unfolds = {map_unfolds = [], set_unfoldss = [], rel_unfolds = [], srel_unfolds = []}; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
52 |
|
49503 | 53 |
fun add_to_thms thms new = thms |> not (Thm.is_reflexive new) ? insert Thm.eq_thm new; |
54 |
fun adds_to_thms thms news = insert (eq_set Thm.eq_thm) (no_reflexive news) thms; |
|
55 |
||
49507 | 56 |
fun add_to_unfolds map sets rel srel |
57 |
{map_unfolds, set_unfoldss, rel_unfolds, srel_unfolds} = |
|
49503 | 58 |
{map_unfolds = add_to_thms map_unfolds map, |
59 |
set_unfoldss = adds_to_thms set_unfoldss sets, |
|
49507 | 60 |
rel_unfolds = add_to_thms rel_unfolds rel, |
49506 | 61 |
srel_unfolds = add_to_thms srel_unfolds srel}; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
62 |
|
49503 | 63 |
fun add_bnf_to_unfolds bnf = |
49507 | 64 |
add_to_unfolds (map_def_of_bnf bnf) (set_defs_of_bnf bnf) (rel_def_of_bnf bnf) |
49506 | 65 |
(srel_def_of_bnf bnf); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
66 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
67 |
val map_unfolds_of = #map_unfolds; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
68 |
val set_unfoldss_of = #set_unfoldss; |
49507 | 69 |
val rel_unfolds_of = #rel_unfolds; |
49506 | 70 |
val srel_unfolds_of = #srel_unfolds; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
71 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
72 |
val bdTN = "bdT"; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
73 |
|
49425 | 74 |
fun mk_killN n = "_kill" ^ string_of_int n; |
75 |
fun mk_liftN n = "_lift" ^ string_of_int n; |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
76 |
fun mk_permuteN src dest = |
49425 | 77 |
"_permute_" ^ implode (map string_of_int src) ^ "_" ^ implode (map string_of_int dest); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
78 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
79 |
(*copied from Envir.expand_term_free*) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
80 |
fun expand_term_const defs = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
81 |
let |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
82 |
val eqs = map ((fn ((x, U), u) => (x, (U, u))) o apfst dest_Const) defs; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
83 |
val get = fn Const (x, _) => AList.lookup (op =) eqs x | _ => NONE; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
84 |
in Envir.expand_term get end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
85 |
|
49502 | 86 |
fun clean_compose_bnf const_policy qualify b outer inners (unfold_set, lthy) = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
87 |
let |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
88 |
val olive = live_of_bnf outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
89 |
val onwits = nwits_of_bnf outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
90 |
val odead = dead_of_bnf outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
91 |
val inner = hd inners; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
92 |
val ilive = live_of_bnf inner; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
93 |
val ideads = map dead_of_bnf inners; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
94 |
val inwitss = map nwits_of_bnf inners; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
95 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
96 |
(* TODO: check olive = length inners > 0, |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
97 |
forall inner from inners. ilive = live, |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
98 |
forall inner from inners. idead = dead *) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
99 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
100 |
val (oDs, lthy1) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
101 |
(Variable.invent_types (replicate odead HOLogic.typeS) lthy); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
102 |
val (Dss, lthy2) = apfst (map (map TFree)) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
103 |
(fold_map Variable.invent_types (map (fn n => replicate n HOLogic.typeS) ideads) lthy1); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
104 |
val (Ass, lthy3) = apfst (replicate ilive o map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
105 |
(Variable.invent_types (replicate ilive HOLogic.typeS) lthy2); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
106 |
val As = if ilive > 0 then hd Ass else []; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
107 |
val Ass_repl = replicate olive As; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
108 |
val (Bs, _(*lthy4*)) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
109 |
(Variable.invent_types (replicate ilive HOLogic.typeS) lthy3); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
110 |
val Bss_repl = replicate olive Bs; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
111 |
|
49463 | 112 |
val ((((fs', Qs'), Asets), xs), _(*names_lthy*)) = lthy |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
113 |
|> apfst snd o mk_Frees' "f" (map2 (curry (op -->)) As Bs) |
49463 | 114 |
||>> apfst snd o mk_Frees' "Q" (map2 mk_pred2T As Bs) |
49456 | 115 |
||>> mk_Frees "A" (map HOLogic.mk_setT As) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
116 |
||>> mk_Frees "x" As; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
117 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
118 |
val CAs = map3 mk_T_of_bnf Dss Ass_repl inners; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
119 |
val CCA = mk_T_of_bnf oDs CAs outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
120 |
val CBs = map3 mk_T_of_bnf Dss Bss_repl inners; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
121 |
val outer_sets = mk_sets_of_bnf (replicate olive oDs) (replicate olive CAs) outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
122 |
val inner_setss = map3 mk_sets_of_bnf (map (replicate ilive) Dss) (replicate olive Ass) inners; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
123 |
val inner_bds = map3 mk_bd_of_bnf Dss Ass_repl inners; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
124 |
val outer_bd = mk_bd_of_bnf oDs CAs outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
125 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
126 |
(*%f1 ... fn. outer.map (inner_1.map f1 ... fn) ... (inner_m.map f1 ... fn)*) |
49303 | 127 |
val mapx = fold_rev Term.abs fs' |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
128 |
(Term.list_comb (mk_map_of_bnf oDs CAs CBs outer, |
49463 | 129 |
map2 (fn Ds => (fn f => Term.list_comb (f, map Bound (ilive - 1 downto 0))) o |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
130 |
mk_map_of_bnf Ds As Bs) Dss inners)); |
49507 | 131 |
(*%Q1 ... Qn. outer.rel (inner_1.rel Q1 ... Qn) ... (inner_m.rel Q1 ... Qn)*) |
132 |
val rel = fold_rev Term.abs Qs' |
|
133 |
(Term.list_comb (mk_rel_of_bnf oDs CAs CBs outer, |
|
49463 | 134 |
map2 (fn Ds => (fn f => Term.list_comb (f, map Bound (ilive - 1 downto 0))) o |
49507 | 135 |
mk_rel_of_bnf Ds As Bs) Dss inners)); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
136 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
137 |
(*Union o collect {outer.set_1 ... outer.set_m} o outer.map inner_1.set_i ... inner_m.set_i*) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
138 |
(*Union o collect {image inner_1.set_i o outer.set_1 ... image inner_m.set_i o outer.set_m}*) |
49303 | 139 |
fun mk_set i = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
140 |
let |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
141 |
val (setTs, T) = `(replicate olive o HOLogic.mk_setT) (nth As i); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
142 |
val outer_set = mk_collect |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
143 |
(mk_sets_of_bnf (replicate olive oDs) (replicate olive setTs) outer) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
144 |
(mk_T_of_bnf oDs setTs outer --> HOLogic.mk_setT T); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
145 |
val inner_sets = map (fn sets => nth sets i) inner_setss; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
146 |
val outer_map = mk_map_of_bnf oDs CAs setTs outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
147 |
val map_inner_sets = Term.list_comb (outer_map, inner_sets); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
148 |
val collect_image = mk_collect |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
149 |
(map2 (fn f => fn set => HOLogic.mk_comp (mk_image f, set)) inner_sets outer_sets) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
150 |
(CCA --> HOLogic.mk_setT T); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
151 |
in |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
152 |
(Library.foldl1 HOLogic.mk_comp [mk_Union T, outer_set, map_inner_sets], |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
153 |
HOLogic.mk_comp (mk_Union T, collect_image)) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
154 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
155 |
|
49303 | 156 |
val (sets, sets_alt) = map_split mk_set (0 upto ilive - 1); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
157 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
158 |
(*(inner_1.bd +c ... +c inner_m.bd) *c outer.bd*) |
49303 | 159 |
val bd = Term.absdummy CCA (mk_cprod (Library.foldr1 (uncurry mk_csum) inner_bds) outer_bd); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
160 |
|
49303 | 161 |
fun map_id_tac {context = ctxt, ...} = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
162 |
let |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
163 |
(*order the theorems by reverse size to prevent bad interaction with nonconfluent rewrite |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
164 |
rules*) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
165 |
val thms = (map map_id_of_bnf inners |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
166 |
|> map (`(Term.size_of_term o Thm.prop_of)) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
167 |
|> sort (rev_order o int_ord o pairself fst) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
168 |
|> map snd) @ [map_id_of_bnf outer]; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
169 |
in |
49586 | 170 |
(EVERY' (map (fn thm => subst_tac ctxt NONE [thm]) thms) THEN' rtac refl) 1 |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
171 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
172 |
|
49303 | 173 |
fun map_comp_tac _ = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
174 |
mk_comp_map_comp_tac (map_comp_of_bnf outer) (map_cong_of_bnf outer) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
175 |
(map map_comp_of_bnf inners); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
176 |
|
49303 | 177 |
fun mk_single_set_natural_tac i _ = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
178 |
mk_comp_set_natural_tac (map_comp_of_bnf outer) (map_cong_of_bnf outer) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
179 |
(collect_set_natural_of_bnf outer) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
180 |
(map ((fn thms => nth thms i) o set_natural_of_bnf) inners); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
181 |
|
49303 | 182 |
val set_natural_tacs = map mk_single_set_natural_tac (0 upto ilive - 1); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
183 |
|
49303 | 184 |
fun bd_card_order_tac _ = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
185 |
mk_comp_bd_card_order_tac (map bd_card_order_of_bnf inners) (bd_card_order_of_bnf outer); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
186 |
|
49303 | 187 |
fun bd_cinfinite_tac _ = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
188 |
mk_comp_bd_cinfinite_tac (bd_cinfinite_of_bnf inner) (bd_cinfinite_of_bnf outer); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
189 |
|
49303 | 190 |
val set_alt_thms = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
191 |
if ! quick_and_dirty then |
49456 | 192 |
[] |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
193 |
else |
49109
0e5b859e1c91
no more aliases for Local_Theory.note; use Thm.close_derivation in internal theorems;
traytel
parents:
49019
diff
changeset
|
194 |
map (fn goal => |
0e5b859e1c91
no more aliases for Local_Theory.note; use Thm.close_derivation in internal theorems;
traytel
parents:
49019
diff
changeset
|
195 |
Skip_Proof.prove lthy [] [] goal |
0e5b859e1c91
no more aliases for Local_Theory.note; use Thm.close_derivation in internal theorems;
traytel
parents:
49019
diff
changeset
|
196 |
(fn {context, ...} => (mk_comp_set_alt_tac context (collect_set_natural_of_bnf outer))) |
0e5b859e1c91
no more aliases for Local_Theory.note; use Thm.close_derivation in internal theorems;
traytel
parents:
49019
diff
changeset
|
197 |
|> Thm.close_derivation) |
49303 | 198 |
(map2 (curry (HOLogic.mk_Trueprop o HOLogic.mk_eq)) sets sets_alt); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
199 |
|
49303 | 200 |
fun map_cong_tac _ = |
201 |
mk_comp_map_cong_tac set_alt_thms (map_cong_of_bnf outer) (map map_cong_of_bnf inners); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
202 |
|
49303 | 203 |
val set_bd_tacs = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
204 |
if ! quick_and_dirty then |
49303 | 205 |
replicate (length set_alt_thms) (K all_tac) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
206 |
else |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
207 |
let |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
208 |
val outer_set_bds = set_bd_of_bnf outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
209 |
val inner_set_bdss = map set_bd_of_bnf inners; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
210 |
val inner_bd_Card_orders = map bd_Card_order_of_bnf inners; |
49303 | 211 |
fun single_set_bd_thm i j = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
212 |
@{thm comp_single_set_bd} OF [nth inner_bd_Card_orders j, nth (nth inner_set_bdss j) i, |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
213 |
nth outer_set_bds j] |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
214 |
val single_set_bd_thmss = |
49303 | 215 |
map ((fn f => map f (0 upto olive - 1)) o single_set_bd_thm) (0 upto ilive - 1); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
216 |
in |
49303 | 217 |
map2 (fn set_alt => fn single_set_bds => fn {context, ...} => |
218 |
mk_comp_set_bd_tac context set_alt single_set_bds) |
|
219 |
set_alt_thms single_set_bd_thmss |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
220 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
221 |
|
49303 | 222 |
val in_alt_thm = |
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
223 |
let |
49303 | 224 |
val inx = mk_in Asets sets CCA; |
225 |
val in_alt = mk_in (map2 (mk_in Asets) inner_setss CAs) outer_sets CCA; |
|
226 |
val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt)); |
|
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
227 |
in |
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
228 |
Skip_Proof.prove lthy [] [] goal |
49303 | 229 |
(fn {context, ...} => mk_comp_in_alt_tac context set_alt_thms) |
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
230 |
|> Thm.close_derivation |
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
231 |
end; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
232 |
|
49303 | 233 |
fun in_bd_tac _ = |
234 |
mk_comp_in_bd_tac in_alt_thm (map in_bd_of_bnf inners) (in_bd_of_bnf outer) |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
235 |
(map bd_Cinfinite_of_bnf inners) (bd_Card_order_of_bnf outer); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
236 |
|
49303 | 237 |
fun map_wpull_tac _ = |
238 |
mk_map_wpull_tac in_alt_thm (map map_wpull_of_bnf inners) (map_wpull_of_bnf outer); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
239 |
|
49506 | 240 |
fun srel_O_Gr_tac _ = |
49456 | 241 |
let |
49463 | 242 |
val basic_thms = @{thms mem_Collect_eq fst_conv snd_conv}; (*TODO: tune*) |
49506 | 243 |
val outer_srel_Gr = srel_Gr_of_bnf outer RS sym; |
244 |
val outer_srel_cong = srel_cong_of_bnf outer; |
|
49463 | 245 |
val thm = |
49512 | 246 |
(trans OF [in_alt_thm RS @{thm O_Gr_cong}, |
49463 | 247 |
trans OF [@{thm arg_cong2[of _ _ _ _ relcomp]} OF |
49506 | 248 |
[trans OF [outer_srel_Gr RS @{thm arg_cong[of _ _ converse]}, |
249 |
srel_converse_of_bnf outer RS sym], outer_srel_Gr], |
|
250 |
trans OF [srel_O_of_bnf outer RS sym, outer_srel_cong OF |
|
251 |
(map (fn bnf => srel_O_Gr_of_bnf bnf RS sym) inners)]]] RS sym) |
|
252 |
|> unfold_thms lthy (basic_thms @ srel_def_of_bnf outer :: map srel_def_of_bnf inners); |
|
49456 | 253 |
in |
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49503
diff
changeset
|
254 |
unfold_thms_tac lthy basic_thms THEN rtac thm 1 |
49463 | 255 |
end; |
49456 | 256 |
|
49460
4dd451a075ce
fixed infinite loop with trivial rel_O_Gr + tuning
blanchet
parents:
49459
diff
changeset
|
257 |
val tacs = zip_axioms map_id_tac map_comp_tac map_cong_tac set_natural_tacs bd_card_order_tac |
49506 | 258 |
bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac srel_O_Gr_tac; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
259 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
260 |
val outer_wits = mk_wits_of_bnf (replicate onwits oDs) (replicate onwits CAs) outer; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
261 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
262 |
val inner_witss = map (map (fn (I, wit) => Term.list_comb (wit, map (nth xs) I))) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
263 |
(map3 (fn Ds => fn n => mk_wits_of_bnf (replicate n Ds) (replicate n As)) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
264 |
Dss inwitss inners); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
265 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
266 |
val inner_witsss = map (map (nth inner_witss) o fst) outer_wits; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
267 |
|
49303 | 268 |
val wits = (inner_witsss, (map (single o snd) outer_wits)) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
269 |
|-> map2 (fold (map_product (fn iwit => fn owit => owit $ iwit))) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
270 |
|> flat |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
271 |
|> map (`(fn t => Term.add_frees t [])) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
272 |
|> minimize_wits |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
273 |
|> map (fn (frees, t) => fold absfree frees t); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
274 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
275 |
fun wit_tac {context = ctxt, ...} = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
276 |
mk_comp_wit_tac ctxt (wit_thms_of_bnf outer) (collect_set_natural_of_bnf outer) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
277 |
(maps wit_thms_of_bnf inners); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
278 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
279 |
val (bnf', lthy') = |
49538 | 280 |
bnf_def const_policy (K Dont_Note) qualify tacs wit_tac (SOME (oDs @ flat Dss)) |
49507 | 281 |
(((((b, mapx), sets), bd), wits), SOME rel) lthy; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
282 |
in |
49503 | 283 |
(bnf', (add_bnf_to_unfolds bnf' unfold_set, lthy')) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
284 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
285 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
286 |
(* Killing live variables *) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
287 |
|
49502 | 288 |
fun kill_bnf qualify n bnf (unfold_set, lthy) = if n = 0 then (bnf, (unfold_set, lthy)) else |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
289 |
let |
49425 | 290 |
val b = Binding.suffix_name (mk_killN n) (name_of_bnf bnf); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
291 |
val live = live_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
292 |
val dead = dead_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
293 |
val nwits = nwits_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
294 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
295 |
(* TODO: check 0 < n <= live *) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
296 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
297 |
val (Ds, lthy1) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
298 |
(Variable.invent_types (replicate dead HOLogic.typeS) lthy); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
299 |
val ((killedAs, As), lthy2) = apfst (`(take n) o map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
300 |
(Variable.invent_types (replicate live HOLogic.typeS) lthy1); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
301 |
val (Bs, _(*lthy3*)) = apfst (append killedAs o map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
302 |
(Variable.invent_types (replicate (live - n) HOLogic.typeS) lthy2); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
303 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
304 |
val ((Asets, lives), _(*names_lthy*)) = lthy |
49456 | 305 |
|> mk_Frees "A" (map HOLogic.mk_setT (drop n As)) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
306 |
||>> mk_Frees "x" (drop n As); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
307 |
val xs = map (fn T => HOLogic.choice_const T $ absdummy T @{term True}) killedAs @ lives; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
308 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
309 |
val T = mk_T_of_bnf Ds As bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
310 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
311 |
(*bnf.map id ... id*) |
49303 | 312 |
val mapx = Term.list_comb (mk_map_of_bnf Ds As Bs bnf, map HOLogic.id_const killedAs); |
49507 | 313 |
(*bnf.rel (op =) ... (op =)*) |
314 |
val rel = Term.list_comb (mk_rel_of_bnf Ds As Bs bnf, map HOLogic.eq_const killedAs); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
315 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
316 |
val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf; |
49303 | 317 |
val sets = drop n bnf_sets; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
318 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
319 |
(*(|UNIV :: A1 set| +c ... +c |UNIV :: An set|) *c bnf.bd*) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
320 |
val bnf_bd = mk_bd_of_bnf Ds As bnf; |
49303 | 321 |
val bd = mk_cprod |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
322 |
(Library.foldr1 (uncurry mk_csum) (map (mk_card_of o HOLogic.mk_UNIV) killedAs)) bnf_bd; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
323 |
|
49303 | 324 |
fun map_id_tac _ = rtac (map_id_of_bnf bnf) 1; |
325 |
fun map_comp_tac {context, ...} = |
|
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49503
diff
changeset
|
326 |
unfold_thms_tac context ((map_comp_of_bnf bnf RS sym) :: @{thms o_assoc id_o o_id}) THEN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
327 |
rtac refl 1; |
49303 | 328 |
fun map_cong_tac {context, ...} = |
49304 | 329 |
mk_kill_map_cong_tac context n (live - n) (map_cong_of_bnf bnf); |
49303 | 330 |
val set_natural_tacs = map (fn thm => fn _ => rtac thm 1) (drop n (set_natural_of_bnf bnf)); |
49304 | 331 |
fun bd_card_order_tac _ = mk_kill_bd_card_order_tac n (bd_card_order_of_bnf bnf); |
332 |
fun bd_cinfinite_tac _ = mk_kill_bd_cinfinite_tac (bd_Cinfinite_of_bnf bnf); |
|
49303 | 333 |
val set_bd_tacs = |
49304 | 334 |
map (fn thm => fn _ => mk_kill_set_bd_tac (bd_Card_order_of_bnf bnf) thm) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
335 |
(drop n (set_bd_of_bnf bnf)); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
336 |
|
49303 | 337 |
val in_alt_thm = |
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
338 |
let |
49303 | 339 |
val inx = mk_in Asets sets T; |
340 |
val in_alt = mk_in (map HOLogic.mk_UNIV killedAs @ Asets) bnf_sets T; |
|
341 |
val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt)); |
|
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
342 |
in |
49304 | 343 |
Skip_Proof.prove lthy [] [] goal (K kill_in_alt_tac) |> Thm.close_derivation |
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
344 |
end; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
345 |
|
49303 | 346 |
fun in_bd_tac _ = |
49304 | 347 |
mk_kill_in_bd_tac n (live > n) in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf) |
49303 | 348 |
(bd_Cinfinite_of_bnf bnf) (bd_Cnotzero_of_bnf bnf); |
349 |
fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
350 |
|
49506 | 351 |
fun srel_O_Gr_tac _ = |
49456 | 352 |
let |
49506 | 353 |
val srel_Gr = srel_Gr_of_bnf bnf RS sym |
49463 | 354 |
val thm = |
49512 | 355 |
(trans OF [in_alt_thm RS @{thm O_Gr_cong}, |
49463 | 356 |
trans OF [@{thm arg_cong2[of _ _ _ _ relcomp]} OF |
49506 | 357 |
[trans OF [srel_Gr RS @{thm arg_cong[of _ _ converse]}, |
358 |
srel_converse_of_bnf bnf RS sym], srel_Gr], |
|
359 |
trans OF [srel_O_of_bnf bnf RS sym, srel_cong_of_bnf bnf OF |
|
49463 | 360 |
(replicate n @{thm trans[OF Gr_UNIV_id[OF refl] Id_alt[symmetric]]} @ |
361 |
replicate (live - n) @{thm Gr_fst_snd})]]] RS sym) |
|
49506 | 362 |
|> unfold_thms lthy (srel_def_of_bnf bnf :: @{thms Id_def' mem_Collect_eq split_conv}); |
49456 | 363 |
in |
49463 | 364 |
rtac thm 1 |
49456 | 365 |
end; |
366 |
||
49460
4dd451a075ce
fixed infinite loop with trivial rel_O_Gr + tuning
blanchet
parents:
49459
diff
changeset
|
367 |
val tacs = zip_axioms map_id_tac map_comp_tac map_cong_tac set_natural_tacs bd_card_order_tac |
49506 | 368 |
bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac srel_O_Gr_tac; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
369 |
|
49303 | 370 |
val bnf_wits = mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
371 |
|
49303 | 372 |
val wits = map (fn t => fold absfree (Term.add_frees t []) t) |
373 |
(map (fn (I, wit) => Term.list_comb (wit, map (nth xs) I)) bnf_wits); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
374 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
375 |
fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
376 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
377 |
val (bnf', lthy') = |
49538 | 378 |
bnf_def Smart_Inline (K Dont_Note) qualify tacs wit_tac (SOME (killedAs @ Ds)) |
49507 | 379 |
(((((b, mapx), sets), Term.absdummy T bd), wits), SOME rel) lthy; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
380 |
in |
49503 | 381 |
(bnf', (add_bnf_to_unfolds bnf' unfold_set, lthy')) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
382 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
383 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
384 |
(* Adding dummy live variables *) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
385 |
|
49502 | 386 |
fun lift_bnf qualify n bnf (unfold_set, lthy) = if n = 0 then (bnf, (unfold_set, lthy)) else |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
387 |
let |
49425 | 388 |
val b = Binding.suffix_name (mk_liftN n) (name_of_bnf bnf); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
389 |
val live = live_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
390 |
val dead = dead_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
391 |
val nwits = nwits_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
392 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
393 |
(* TODO: check 0 < n *) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
394 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
395 |
val (Ds, lthy1) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
396 |
(Variable.invent_types (replicate dead HOLogic.typeS) lthy); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
397 |
val ((newAs, As), lthy2) = apfst (chop n o map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
398 |
(Variable.invent_types (replicate (n + live) HOLogic.typeS) lthy1); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
399 |
val ((newBs, Bs), _(*lthy3*)) = apfst (chop n o map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
400 |
(Variable.invent_types (replicate (n + live) HOLogic.typeS) lthy2); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
401 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
402 |
val (Asets, _(*names_lthy*)) = lthy |
49456 | 403 |
|> mk_Frees "A" (map HOLogic.mk_setT (newAs @ As)); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
404 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
405 |
val T = mk_T_of_bnf Ds As bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
406 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
407 |
(*%f1 ... fn. bnf.map*) |
49303 | 408 |
val mapx = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
409 |
fold_rev Term.absdummy (map2 (curry (op -->)) newAs newBs) (mk_map_of_bnf Ds As Bs bnf); |
49507 | 410 |
(*%Q1 ... Qn. bnf.rel*) |
411 |
val rel = fold_rev Term.absdummy (map2 mk_pred2T newAs newBs) (mk_rel_of_bnf Ds As Bs bnf); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
412 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
413 |
val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf; |
49303 | 414 |
val sets = map (fn A => absdummy T (HOLogic.mk_set A [])) newAs @ bnf_sets; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
415 |
|
49303 | 416 |
val bd = mk_bd_of_bnf Ds As bnf; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
417 |
|
49303 | 418 |
fun map_id_tac _ = rtac (map_id_of_bnf bnf) 1; |
419 |
fun map_comp_tac {context, ...} = |
|
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49503
diff
changeset
|
420 |
unfold_thms_tac context ((map_comp_of_bnf bnf RS sym) :: @{thms o_assoc id_o o_id}) THEN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
421 |
rtac refl 1; |
49303 | 422 |
fun map_cong_tac {context, ...} = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
423 |
rtac (map_cong_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac context 1); |
49303 | 424 |
val set_natural_tacs = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
425 |
if ! quick_and_dirty then |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
426 |
replicate (n + live) (K all_tac) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
427 |
else |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
428 |
replicate n (K empty_natural_tac) @ |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
429 |
map (fn thm => fn _ => rtac thm 1) (set_natural_of_bnf bnf); |
49303 | 430 |
fun bd_card_order_tac _ = rtac (bd_card_order_of_bnf bnf) 1; |
431 |
fun bd_cinfinite_tac _ = rtac (bd_cinfinite_of_bnf bnf) 1; |
|
432 |
val set_bd_tacs = |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
433 |
if ! quick_and_dirty then |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
434 |
replicate (n + live) (K all_tac) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
435 |
else |
49304 | 436 |
replicate n (K (mk_lift_set_bd_tac (bd_Card_order_of_bnf bnf))) @ |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
437 |
(map (fn thm => fn _ => rtac thm 1) (set_bd_of_bnf bnf)); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
438 |
|
49303 | 439 |
val in_alt_thm = |
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
440 |
let |
49303 | 441 |
val inx = mk_in Asets sets T; |
442 |
val in_alt = mk_in (drop n Asets) bnf_sets T; |
|
443 |
val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt)); |
|
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
444 |
in |
49304 | 445 |
Skip_Proof.prove lthy [] [] goal (K lift_in_alt_tac) |> Thm.close_derivation |
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
446 |
end; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
447 |
|
49304 | 448 |
fun in_bd_tac _ = mk_lift_in_bd_tac n in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf); |
49303 | 449 |
fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
450 |
|
49506 | 451 |
fun srel_O_Gr_tac _ = |
452 |
mk_simple_srel_O_Gr_tac lthy (srel_def_of_bnf bnf) (srel_O_Gr_of_bnf bnf) in_alt_thm; |
|
49456 | 453 |
|
49460
4dd451a075ce
fixed infinite loop with trivial rel_O_Gr + tuning
blanchet
parents:
49459
diff
changeset
|
454 |
val tacs = zip_axioms map_id_tac map_comp_tac map_cong_tac set_natural_tacs bd_card_order_tac |
49506 | 455 |
bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac srel_O_Gr_tac; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
456 |
|
49303 | 457 |
val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
458 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
459 |
fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
460 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
461 |
val (bnf', lthy') = |
49538 | 462 |
bnf_def Smart_Inline (K Dont_Note) qualify tacs wit_tac (SOME Ds) |
49507 | 463 |
(((((b, mapx), sets), Term.absdummy T bd), wits), SOME rel) lthy; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
464 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
465 |
in |
49503 | 466 |
(bnf', (add_bnf_to_unfolds bnf' unfold_set, lthy')) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
467 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
468 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
469 |
(* Changing the order of live variables *) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
470 |
|
49502 | 471 |
fun permute_bnf qualify src dest bnf (unfold_set, lthy) = |
472 |
if src = dest then (bnf, (unfold_set, lthy)) else |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
473 |
let |
49425 | 474 |
val b = Binding.suffix_name (mk_permuteN src dest) (name_of_bnf bnf); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
475 |
val live = live_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
476 |
val dead = dead_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
477 |
val nwits = nwits_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
478 |
fun permute xs = mk_permute src dest xs; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
479 |
fun permute_rev xs = mk_permute dest src xs; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
480 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
481 |
val (Ds, lthy1) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
482 |
(Variable.invent_types (replicate dead HOLogic.typeS) lthy); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
483 |
val (As, lthy2) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
484 |
(Variable.invent_types (replicate live HOLogic.typeS) lthy1); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
485 |
val (Bs, _(*lthy3*)) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
486 |
(Variable.invent_types (replicate live HOLogic.typeS) lthy2); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
487 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
488 |
val (Asets, _(*names_lthy*)) = lthy |
49456 | 489 |
|> mk_Frees "A" (map HOLogic.mk_setT (permute As)); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
490 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
491 |
val T = mk_T_of_bnf Ds As bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
492 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
493 |
(*%f(1) ... f(n). bnf.map f\<sigma>(1) ... f\<sigma>(n)*) |
49303 | 494 |
val mapx = fold_rev Term.absdummy (permute (map2 (curry op -->) As Bs)) |
49463 | 495 |
(Term.list_comb (mk_map_of_bnf Ds As Bs bnf, permute_rev (map Bound (live - 1 downto 0)))); |
49507 | 496 |
(*%Q(1) ... Q(n). bnf.rel Q\<sigma>(1) ... Q\<sigma>(n)*) |
497 |
val rel = fold_rev Term.absdummy (permute (map2 mk_pred2T As Bs)) |
|
498 |
(Term.list_comb (mk_rel_of_bnf Ds As Bs bnf, permute_rev (map Bound (live - 1 downto 0)))); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
499 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
500 |
val bnf_sets = mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf; |
49303 | 501 |
val sets = permute bnf_sets; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
502 |
|
49303 | 503 |
val bd = mk_bd_of_bnf Ds As bnf; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
504 |
|
49303 | 505 |
fun map_id_tac _ = rtac (map_id_of_bnf bnf) 1; |
506 |
fun map_comp_tac _ = rtac (map_comp_of_bnf bnf) 1; |
|
507 |
fun map_cong_tac {context, ...} = |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
508 |
rtac (map_cong_of_bnf bnf) 1 THEN REPEAT_DETERM_N live (Goal.assume_rule_tac context 1); |
49303 | 509 |
val set_natural_tacs = permute (map (fn thm => fn _ => rtac thm 1) (set_natural_of_bnf bnf)); |
510 |
fun bd_card_order_tac _ = rtac (bd_card_order_of_bnf bnf) 1; |
|
511 |
fun bd_cinfinite_tac _ = rtac (bd_cinfinite_of_bnf bnf) 1; |
|
512 |
val set_bd_tacs = permute (map (fn thm => fn _ => rtac thm 1) (set_bd_of_bnf bnf)); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
513 |
|
49303 | 514 |
val in_alt_thm = |
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
515 |
let |
49303 | 516 |
val inx = mk_in Asets sets T; |
517 |
val in_alt = mk_in (permute_rev Asets) bnf_sets T; |
|
518 |
val goal = fold_rev Logic.all Asets (mk_Trueprop_eq (inx, in_alt)); |
|
49155
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
519 |
in |
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
520 |
Skip_Proof.prove lthy [] [] goal (K (mk_permute_in_alt_tac src dest)) |
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
521 |
|> Thm.close_derivation |
f51ab68f882f
do not trivialize important internal theorem in quick_and_dirty mode
traytel
parents:
49123
diff
changeset
|
522 |
end; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
523 |
|
49303 | 524 |
fun in_bd_tac _ = |
525 |
mk_permute_in_bd_tac src dest in_alt_thm (in_bd_of_bnf bnf) (bd_Card_order_of_bnf bnf); |
|
526 |
fun map_wpull_tac _ = mk_map_wpull_tac in_alt_thm [] (map_wpull_of_bnf bnf); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
527 |
|
49506 | 528 |
fun srel_O_Gr_tac _ = |
529 |
mk_simple_srel_O_Gr_tac lthy (srel_def_of_bnf bnf) (srel_O_Gr_of_bnf bnf) in_alt_thm; |
|
49456 | 530 |
|
49460
4dd451a075ce
fixed infinite loop with trivial rel_O_Gr + tuning
blanchet
parents:
49459
diff
changeset
|
531 |
val tacs = zip_axioms map_id_tac map_comp_tac map_cong_tac set_natural_tacs bd_card_order_tac |
49506 | 532 |
bd_cinfinite_tac set_bd_tacs in_bd_tac map_wpull_tac srel_O_Gr_tac; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
533 |
|
49303 | 534 |
val wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
535 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
536 |
fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
537 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
538 |
val (bnf', lthy') = |
49538 | 539 |
bnf_def Smart_Inline (K Dont_Note) qualify tacs wit_tac (SOME Ds) |
49507 | 540 |
(((((b, mapx), sets), Term.absdummy T bd), wits), SOME rel) lthy; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
541 |
in |
49503 | 542 |
(bnf', (add_bnf_to_unfolds bnf' unfold_set, lthy')) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
543 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
544 |
|
49014 | 545 |
(* Composition pipeline *) |
546 |
||
547 |
fun permute_and_kill qualify n src dest bnf = |
|
548 |
bnf |
|
549 |
|> permute_bnf qualify src dest |
|
49304 | 550 |
#> uncurry (kill_bnf qualify n); |
49014 | 551 |
|
552 |
fun lift_and_permute qualify n src dest bnf = |
|
553 |
bnf |
|
49304 | 554 |
|> lift_bnf qualify n |
49014 | 555 |
#> uncurry (permute_bnf qualify src dest); |
556 |
||
49502 | 557 |
fun normalize_bnfs qualify Ass Ds sort bnfs unfold_set lthy = |
49014 | 558 |
let |
559 |
val before_kill_src = map (fn As => 0 upto (length As - 1)) Ass; |
|
560 |
val kill_poss = map (find_indices Ds) Ass; |
|
561 |
val live_poss = map2 (subtract (op =)) kill_poss before_kill_src; |
|
562 |
val before_kill_dest = map2 append kill_poss live_poss; |
|
563 |
val kill_ns = map length kill_poss; |
|
49502 | 564 |
val (inners', (unfold_set', lthy')) = |
49014 | 565 |
fold_map5 (fn i => permute_and_kill (qualify i)) |
566 |
(if length bnfs = 1 then [0] else (1 upto length bnfs)) |
|
49502 | 567 |
kill_ns before_kill_src before_kill_dest bnfs (unfold_set, lthy); |
49014 | 568 |
|
569 |
val Ass' = map2 (map o nth) Ass live_poss; |
|
570 |
val As = sort Ass'; |
|
571 |
val after_lift_dest = replicate (length Ass') (0 upto (length As - 1)); |
|
572 |
val old_poss = map (map (fn x => find_index (fn y => x = y) As)) Ass'; |
|
573 |
val new_poss = map2 (subtract (op =)) old_poss after_lift_dest; |
|
574 |
val after_lift_src = map2 append new_poss old_poss; |
|
575 |
val lift_ns = map (fn xs => length As - length xs) Ass'; |
|
576 |
in |
|
577 |
((kill_poss, As), fold_map5 (fn i => lift_and_permute (qualify i)) |
|
578 |
(if length bnfs = 1 then [0] else (1 upto length bnfs)) |
|
49502 | 579 |
lift_ns after_lift_src after_lift_dest inners' (unfold_set', lthy')) |
49014 | 580 |
end; |
581 |
||
582 |
fun default_comp_sort Ass = |
|
583 |
Library.sort (Term_Ord.typ_ord o pairself TFree) (fold (fold (insert (op =))) Ass []); |
|
584 |
||
49502 | 585 |
fun compose_bnf const_policy qualify sort outer inners oDs Dss tfreess (unfold_set, lthy) = |
49014 | 586 |
let |
49425 | 587 |
val b = name_of_bnf outer; |
49014 | 588 |
|
49121 | 589 |
val Ass = map (map Term.dest_TFree) tfreess; |
49014 | 590 |
val Ds = fold (fold Term.add_tfreesT) (oDs :: Dss) []; |
591 |
||
49502 | 592 |
val ((kill_poss, As), (inners', (unfold_set', lthy'))) = |
593 |
normalize_bnfs qualify Ass Ds sort inners unfold_set lthy; |
|
49014 | 594 |
|
595 |
val Ds = oDs @ flat (map3 (append oo map o nth) tfreess kill_poss Dss); |
|
596 |
val As = map TFree As; |
|
597 |
in |
|
49425 | 598 |
apfst (rpair (Ds, As)) |
49502 | 599 |
(clean_compose_bnf const_policy (qualify 0) b outer inners' (unfold_set', lthy')) |
49014 | 600 |
end; |
601 |
||
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
602 |
(* Hide the type of the bound (optimization) and unfold the definitions (nicer to the user) *) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
603 |
|
49502 | 604 |
fun seal_bnf unfold_set b Ds bnf lthy = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
605 |
let |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
606 |
val live = live_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
607 |
val nwits = nwits_of_bnf bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
608 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
609 |
val (As, lthy1) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
610 |
(Variable.invent_types (replicate live HOLogic.typeS) (fold Variable.declare_typ Ds lthy)); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
611 |
val (Bs, _) = apfst (map TFree) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
612 |
(Variable.invent_types (replicate live HOLogic.typeS) lthy1); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
613 |
|
49502 | 614 |
val map_unfolds = map_unfolds_of unfold_set; |
615 |
val set_unfoldss = set_unfoldss_of unfold_set; |
|
49507 | 616 |
val rel_unfolds = rel_unfolds_of unfold_set; |
49506 | 617 |
val srel_unfolds = srel_unfolds_of unfold_set; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
618 |
|
49507 | 619 |
val expand_maps = |
620 |
fold expand_term_const (map (single o Logic.dest_equals o Thm.prop_of) map_unfolds); |
|
621 |
val expand_sets = |
|
622 |
fold expand_term_const (map (map (Logic.dest_equals o Thm.prop_of)) set_unfoldss); |
|
623 |
val expand_rels = |
|
624 |
fold expand_term_const (map (single o Logic.dest_equals o Thm.prop_of) rel_unfolds); |
|
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49503
diff
changeset
|
625 |
val unfold_maps = fold (unfold_thms lthy o single) map_unfolds; |
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49503
diff
changeset
|
626 |
val unfold_sets = fold (unfold_thms lthy) set_unfoldss; |
49507 | 627 |
val unfold_rels = unfold_thms lthy rel_unfolds; |
49506 | 628 |
val unfold_srels = unfold_thms lthy srel_unfolds; |
49507 | 629 |
val unfold_all = unfold_sets o unfold_maps o unfold_rels o unfold_srels; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
630 |
val bnf_map = expand_maps (mk_map_of_bnf Ds As Bs bnf); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
631 |
val bnf_sets = map (expand_maps o expand_sets) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
632 |
(mk_sets_of_bnf (replicate live Ds) (replicate live As) bnf); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
633 |
val bnf_bd = mk_bd_of_bnf Ds As bnf; |
49507 | 634 |
val bnf_rel = expand_rels (mk_rel_of_bnf Ds As Bs bnf); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
635 |
val T = mk_T_of_bnf Ds As bnf; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
636 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
637 |
(*bd should only depend on dead type variables!*) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
638 |
val bd_repT = fst (dest_relT (fastype_of bnf_bd)); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
639 |
val bdT_bind = Binding.suffix_name ("_" ^ bdTN) b; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
640 |
val params = fold Term.add_tfreesT Ds []; |
49185
073d7d1b7488
respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents:
49155
diff
changeset
|
641 |
val deads = map TFree params; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
642 |
|
49228 | 643 |
val ((bdT_name, (bdT_glob_info, bdT_loc_info)), lthy) = |
644 |
typedef false NONE (bdT_bind, params, NoSyn) |
|
645 |
(HOLogic.mk_UNIV bd_repT) NONE (EVERY' [rtac exI, rtac UNIV_I] 1) lthy; |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
646 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
647 |
val bnf_bd' = mk_dir_image bnf_bd |
49185
073d7d1b7488
respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents:
49155
diff
changeset
|
648 |
(Const (#Abs_name bdT_glob_info, bd_repT --> Type (bdT_name, deads))) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
649 |
|
49228 | 650 |
val Abs_bdT_inj = mk_Abs_inj_thm (#Abs_inject bdT_loc_info); |
651 |
val Abs_bdT_bij = mk_Abs_bij_thm lthy Abs_bdT_inj (#Abs_cases bdT_loc_info); |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
652 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
653 |
val bd_ordIso = @{thm dir_image} OF [Abs_bdT_inj, bd_Card_order_of_bnf bnf]; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
654 |
val bd_card_order = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
655 |
@{thm card_order_dir_image} OF [Abs_bdT_bij, bd_card_order_of_bnf bnf]; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
656 |
val bd_cinfinite = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
657 |
(@{thm Cinfinite_cong} OF [bd_ordIso, bd_Cinfinite_of_bnf bnf]) RS conjunct1; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
658 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
659 |
val set_bds = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
660 |
map (fn thm => @{thm ordLeq_ordIso_trans} OF [thm, bd_ordIso]) (set_bd_of_bnf bnf); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
661 |
val in_bd = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
662 |
@{thm ordLeq_ordIso_trans} OF [in_bd_of_bnf bnf, |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
663 |
@{thm cexp_cong2_Cnotzero} OF [bd_ordIso, if live = 0 then |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
664 |
@{thm ctwo_Cnotzero} else @{thm ctwo_Cnotzero} RS @{thm csum_Cnotzero2}, |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
665 |
bd_Card_order_of_bnf bnf]]; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
666 |
|
49463 | 667 |
fun mk_tac thm {context = ctxt, prems = _} = |
668 |
(rtac (unfold_all thm) THEN' |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
669 |
SOLVE o REPEAT_DETERM o (atac ORELSE' Goal.assume_rule_tac ctxt)) 1; |
49456 | 670 |
|
49460
4dd451a075ce
fixed infinite loop with trivial rel_O_Gr + tuning
blanchet
parents:
49459
diff
changeset
|
671 |
val tacs = zip_axioms (mk_tac (map_id_of_bnf bnf)) (mk_tac (map_comp_of_bnf bnf)) |
49456 | 672 |
(mk_tac (map_cong_of_bnf bnf)) (map mk_tac (set_natural_of_bnf bnf)) |
673 |
(K (rtac bd_card_order 1)) (K (rtac bd_cinfinite 1)) (map mk_tac set_bds) (mk_tac in_bd) |
|
49463 | 674 |
(mk_tac (map_wpull_of_bnf bnf)) |
49506 | 675 |
(mk_tac (unfold_thms lthy [srel_def_of_bnf bnf] (srel_O_Gr_of_bnf bnf))); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
676 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
677 |
val bnf_wits = map snd (mk_wits_of_bnf (replicate nwits Ds) (replicate nwits As) bnf); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
678 |
|
49463 | 679 |
fun wit_tac _ = mk_simple_wit_tac (map unfold_all (wit_thms_of_bnf bnf)); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
680 |
|
49538 | 681 |
val (bnf', lthy') = bnf_def Hardly_Inline (user_policy Dont_Note) I tacs wit_tac (SOME deads) |
49507 | 682 |
(((((b, bnf_map), bnf_sets), Term.absdummy T bnf_bd'), bnf_wits), SOME bnf_rel) lthy; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
683 |
in |
49456 | 684 |
((bnf', deads), lthy') |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
685 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
686 |
|
49456 | 687 |
fun bnf_of_typ _ _ _ (T as TFree _) accum = ((ID_bnf, ([], [T])), accum) |
49425 | 688 |
| bnf_of_typ _ _ _ (TVar _) _ = error "Unexpected schematic variable" |
49502 | 689 |
| bnf_of_typ const_policy qualify' sort (T as Type (C, Ts)) (unfold_set, lthy) = |
49186
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
690 |
let |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
691 |
val tfrees = Term.add_tfreesT T []; |
49236 | 692 |
val bnf_opt = if null tfrees then NONE else bnf_of lthy C; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
693 |
in |
49186
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
694 |
(case bnf_opt of |
49502 | 695 |
NONE => ((DEADID_bnf, ([T], [])), (unfold_set, lthy)) |
49186
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
696 |
| SOME bnf => |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
697 |
if forall (can Term.dest_TFree) Ts andalso length Ts = length tfrees then |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
698 |
let |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
699 |
val T' = T_of_bnf bnf; |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
700 |
val deads = deads_of_bnf bnf; |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
701 |
val lives = lives_of_bnf bnf; |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
702 |
val tvars' = Term.add_tvarsT T' []; |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
703 |
val deads_lives = |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
704 |
pairself (map (Term.typ_subst_TVars (map fst tvars' ~~ map TFree tfrees))) |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
705 |
(deads, lives); |
49502 | 706 |
in ((bnf, deads_lives), (unfold_set, lthy)) end |
49186
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
707 |
else |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
708 |
let |
49425 | 709 |
val name = Long_Name.base_name C; |
710 |
fun qualify i = |
|
711 |
let val namei = name ^ nonzero_string_of_int i; |
|
712 |
in qualify' o Binding.qualify true namei end; |
|
49186
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
713 |
val odead = dead_of_bnf bnf; |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
714 |
val olive = live_of_bnf bnf; |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
715 |
val oDs_pos = find_indices [TFree ("dead", [])] (snd (Term.dest_Type |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
716 |
(mk_T_of_bnf (replicate odead (TFree ("dead", []))) (replicate olive dummyT) bnf))); |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
717 |
val oDs = map (nth Ts) oDs_pos; |
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
718 |
val Ts' = map (nth Ts) (subtract (op =) oDs_pos (0 upto length Ts - 1)); |
49502 | 719 |
val ((inners, (Dss, Ass)), (unfold_set', lthy')) = |
49186
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
720 |
apfst (apsnd split_list o split_list) |
49425 | 721 |
(fold_map2 (fn i => bnf_of_typ Smart_Inline (qualify i) sort) |
49502 | 722 |
(if length Ts' = 1 then [0] else (1 upto length Ts')) Ts' (unfold_set, lthy)); |
49186
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
723 |
in |
49502 | 724 |
compose_bnf const_policy qualify sort bnf inners oDs Dss Ass (unfold_set', lthy') |
49186
4b5fa9d5e330
handle type constructors not known to be a BNF using the DEADID BNF
traytel
parents:
49185
diff
changeset
|
725 |
end) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
726 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
727 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
728 |
end; |