author | traytel |
Thu, 08 Aug 2013 16:38:28 +0200 | |
changeset 52913 | 2d2d9d1de1a9 |
parent 52899 | 3ff23987f316 |
child 52923 | ec63c82551ae |
permissions | -rw-r--r-- |
51850
106afdf5806c
renamed a few FP-related files, to make it clear that these are not the sum of LFP + GFP but rather shared basic libraries
blanchet
parents:
51839
diff
changeset
|
1 |
(* Title: HOL/BNF/Tools/bnf_fp_util.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 |
51823
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
3 |
Author: Jasmin Blanchette, TU Muenchen |
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
4 |
Copyright 2012, 2013 |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
5 |
|
49389 | 6 |
Shared library for the datatype and codatatype constructions. |
48975
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 |
|
51850
106afdf5806c
renamed a few FP-related files, to make it clear that these are not the sum of LFP + GFP but rather shared basic libraries
blanchet
parents:
51839
diff
changeset
|
9 |
signature BNF_FP_UTIL = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
10 |
sig |
52207
21026c312cc3
tuning -- avoided unreadable true/false all over the place for LFP/GFP
blanchet
parents:
52031
diff
changeset
|
11 |
datatype fp_kind = Least_FP | Greatest_FP |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
12 |
val fp_case: fp_kind -> 'a -> 'a -> 'a |
52207
21026c312cc3
tuning -- avoided unreadable true/false all over the place for LFP/GFP
blanchet
parents:
52031
diff
changeset
|
13 |
|
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
14 |
type fp_result = |
51859 | 15 |
{Ts: typ list, |
16 |
bnfs: BNF_Def.bnf list, |
|
51839 | 17 |
ctors: term list, |
51819 | 18 |
dtors: term list, |
52328 | 19 |
xtor_co_iterss: term list list, |
52344 | 20 |
xtor_co_inducts: thm list, |
51819 | 21 |
dtor_ctors: thm list, |
22 |
ctor_dtors: thm list, |
|
23 |
ctor_injects: thm list, |
|
52314 | 24 |
xtor_map_thms: thm list, |
25 |
xtor_set_thmss: thm list list, |
|
26 |
xtor_rel_thms: thm list, |
|
52839 | 27 |
xtor_co_iter_thmss: thm list list, |
28 |
rel_co_induct_thm: thm} |
|
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
29 |
|
51823
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
30 |
val morph_fp_result: morphism -> fp_result -> fp_result |
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
31 |
val eq_fp_result: fp_result * fp_result -> bool |
52344 | 32 |
val co_induct_of: 'a list -> 'a |
52343 | 33 |
val strong_co_induct_of: 'a list -> 'a |
52330 | 34 |
val un_fold_of: 'a list -> 'a |
35 |
val co_rec_of: 'a list -> 'a |
|
51823
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
36 |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
37 |
val time: Timer.real_timer -> string -> Timer.real_timer |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
38 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
39 |
val IITN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
40 |
val LevN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
41 |
val algN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
42 |
val behN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
43 |
val bisN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
44 |
val carTN: string |
49338 | 45 |
val caseN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
46 |
val coN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
47 |
val coinductN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
48 |
val corecN: string |
49501 | 49 |
val ctorN: string |
50 |
val ctor_dtorN: string |
|
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
51 |
val ctor_dtor_corecN: string |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
52 |
val ctor_dtor_unfoldN: string |
49501 | 53 |
val ctor_exhaustN: string |
54 |
val ctor_induct2N: string |
|
55 |
val ctor_inductN: string |
|
56 |
val ctor_injectN: string |
|
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
57 |
val ctor_foldN: string |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
58 |
val ctor_fold_o_mapN: string |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
59 |
val ctor_fold_transferN: string |
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
60 |
val ctor_fold_uniqueN: string |
49541 | 61 |
val ctor_mapN: string |
49543
53b3c532a082
renamed low-level "map_unique" to have "ctor" or "dtor" in the name
blanchet
parents:
49542
diff
changeset
|
62 |
val ctor_map_uniqueN: string |
49501 | 63 |
val ctor_recN: string |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
64 |
val ctor_rec_o_mapN: string |
51739
3514b90d0a8b
(co)rec is (just as the (un)fold) the unique morphism;
traytel
parents:
49635
diff
changeset
|
65 |
val ctor_rec_uniqueN: string |
49518
b377da40244b
renamed LFP low-level rel property to have ctor not dtor in its name
blanchet
parents:
49516
diff
changeset
|
66 |
val ctor_relN: string |
49544
24094fa47e0d
renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents:
49543
diff
changeset
|
67 |
val ctor_set_inclN: string |
24094fa47e0d
renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents:
49543
diff
changeset
|
68 |
val ctor_set_set_inclN: string |
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
69 |
val disc_unfoldN: string |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
70 |
val disc_unfold_iffN: string |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
71 |
val disc_corecN: string |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
72 |
val disc_corec_iffN: string |
49501 | 73 |
val dtorN: string |
49582
557302525778
renamed "dtor_rel_coinduct" etc. to "dtor_coinduct"
blanchet
parents:
49581
diff
changeset
|
74 |
val dtor_coinductN: string |
49501 | 75 |
val dtor_corecN: string |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
76 |
val dtor_corec_o_mapN: string |
51739
3514b90d0a8b
(co)rec is (just as the (un)fold) the unique morphism;
traytel
parents:
49635
diff
changeset
|
77 |
val dtor_corec_uniqueN: string |
49518
b377da40244b
renamed LFP low-level rel property to have ctor not dtor in its name
blanchet
parents:
49516
diff
changeset
|
78 |
val dtor_ctorN: string |
49501 | 79 |
val dtor_exhaustN: string |
80 |
val dtor_injectN: string |
|
49545
8bb6e2d7346b
renamed coinduction principles to have "dtor" in the name
blanchet
parents:
49544
diff
changeset
|
81 |
val dtor_mapN: string |
49581
4e5bd3883429
renamed "dtor_coinduct" etc. to "dtor_map_coinduct"
blanchet
parents:
49545
diff
changeset
|
82 |
val dtor_map_coinductN: string |
4e5bd3883429
renamed "dtor_coinduct" etc. to "dtor_map_coinduct"
blanchet
parents:
49545
diff
changeset
|
83 |
val dtor_map_strong_coinductN: string |
49543
53b3c532a082
renamed low-level "map_unique" to have "ctor" or "dtor" in the name
blanchet
parents:
49542
diff
changeset
|
84 |
val dtor_map_uniqueN: string |
49545
8bb6e2d7346b
renamed coinduction principles to have "dtor" in the name
blanchet
parents:
49544
diff
changeset
|
85 |
val dtor_relN: string |
49544
24094fa47e0d
renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents:
49543
diff
changeset
|
86 |
val dtor_set_inclN: string |
24094fa47e0d
renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents:
49543
diff
changeset
|
87 |
val dtor_set_set_inclN: string |
49582
557302525778
renamed "dtor_rel_coinduct" etc. to "dtor_coinduct"
blanchet
parents:
49581
diff
changeset
|
88 |
val dtor_strong_coinductN: string |
49516
d4859efc1096
renamed "rel_simp" to "dtor_rel" and similarly for "srel"
blanchet
parents:
49510
diff
changeset
|
89 |
val dtor_unfoldN: string |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
90 |
val dtor_unfold_o_mapN: string |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
91 |
val dtor_unfold_transferN: string |
49516
d4859efc1096
renamed "rel_simp" to "dtor_rel" and similarly for "srel"
blanchet
parents:
49510
diff
changeset
|
92 |
val dtor_unfold_uniqueN: string |
49020
f379cf5d71bd
more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents:
49019
diff
changeset
|
93 |
val exhaustN: string |
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
94 |
val foldN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
95 |
val hsetN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
96 |
val hset_recN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
97 |
val inductN: string |
49019 | 98 |
val injectN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
99 |
val isNodeN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
100 |
val lsbisN: string |
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
101 |
val mapN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
102 |
val map_uniqueN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
103 |
val min_algN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
104 |
val morN: string |
49020
f379cf5d71bd
more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents:
49019
diff
changeset
|
105 |
val nchotomyN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
106 |
val recN: string |
51918 | 107 |
val rel_coinductN: string |
108 |
val rel_inductN: string |
|
49592
b859a02c1150
fixed "rels" + split them into injectivity and distinctness
blanchet
parents:
49591
diff
changeset
|
109 |
val rel_injectN: string |
b859a02c1150
fixed "rels" + split them into injectivity and distinctness
blanchet
parents:
49591
diff
changeset
|
110 |
val rel_distinctN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
111 |
val rvN: string |
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
112 |
val sel_corecN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
113 |
val set_inclN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
114 |
val set_set_inclN: string |
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
115 |
val sel_unfoldN: string |
49585
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49584
diff
changeset
|
116 |
val setsN: string |
49438 | 117 |
val simpsN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
118 |
val strTN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
119 |
val str_initN: string |
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
120 |
val strong_coinductN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
121 |
val sum_bdN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
122 |
val sum_bdTN: string |
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
123 |
val unfoldN: string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
124 |
val uniqueN: string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
125 |
|
49585
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49584
diff
changeset
|
126 |
(* TODO: Don't index set facts. Isabelle packages traditionally generate uniform names. *) |
49584
4339aa335355
use singular since there is always only one theorem
blanchet
parents:
49582
diff
changeset
|
127 |
val mk_ctor_setN: int -> string |
4339aa335355
use singular since there is always only one theorem
blanchet
parents:
49582
diff
changeset
|
128 |
val mk_dtor_setN: int -> string |
49542
b39354db8629
renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents:
49541
diff
changeset
|
129 |
val mk_dtor_set_inductN: int -> string |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
130 |
val mk_set_inductN: int -> string |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
131 |
|
52899 | 132 |
val co_prefix: fp_kind -> string |
51863 | 133 |
|
51858
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
134 |
val base_name_of_typ: typ -> string |
49498 | 135 |
val mk_common_name: string list -> string |
49327
541d818d2ff3
put an underscore between names, for compatibility with old package (and also because it makes sense)
blanchet
parents:
49308
diff
changeset
|
136 |
|
51858
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
137 |
val variant_types: string list -> sort list -> Proof.context -> |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
138 |
(string * sort) list * Proof.context |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
139 |
val variant_tfrees: string list -> Proof.context -> typ list * Proof.context |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
140 |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
141 |
val split_conj_thm: thm -> thm list |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
142 |
val split_conj_prems: int -> thm -> thm |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
143 |
|
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
144 |
val mk_sumTN: typ list -> typ |
49264 | 145 |
val mk_sumTN_balanced: typ list -> typ |
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
146 |
|
49368 | 147 |
val id_const: typ -> term |
148 |
||
49121 | 149 |
val Inl_const: typ -> typ -> term |
150 |
val Inr_const: typ -> typ -> term |
|
151 |
||
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
152 |
val mk_Inl: typ -> term -> term |
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
153 |
val mk_Inr: typ -> term -> term |
49121 | 154 |
val mk_InN: typ list -> term -> int -> term |
49264 | 155 |
val mk_InN_balanced: typ -> int -> term -> int -> term |
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
156 |
val mk_sum_case: term * term -> term |
49129 | 157 |
val mk_sum_caseN: term list -> term |
49264 | 158 |
val mk_sum_caseN_balanced: term list -> term |
49121 | 159 |
|
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
160 |
val dest_sumT: typ -> typ * typ |
49176 | 161 |
val dest_sumTN: int -> typ -> typ list |
49264 | 162 |
val dest_sumTN_balanced: int -> typ -> typ list |
49176 | 163 |
val dest_tupleT: int -> typ -> typ list |
164 |
||
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
165 |
val mk_Field: term -> term |
49275 | 166 |
val mk_If: term -> term -> term -> term |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
167 |
val mk_union: term * term -> term |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
168 |
|
49125 | 169 |
val mk_sumEN: int -> thm |
49264 | 170 |
val mk_sumEN_balanced: int -> thm |
49335 | 171 |
val mk_sumEN_tupled_balanced: int list -> thm |
49130
3c26e17b2849
implemented "mk_case_tac" -- and got rid of "cheat_tac"
blanchet
parents:
49129
diff
changeset
|
172 |
val mk_sum_casesN: int -> int -> thm |
49264 | 173 |
val mk_sum_casesN_balanced: int -> int -> thm |
49125 | 174 |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
175 |
val fixpoint: ('a * 'a -> bool) -> ('a list -> 'a list) -> 'a list -> 'a list |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
176 |
|
52505
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
177 |
val mk_rel_co_induct_thm: fp_kind -> term list -> term list -> term list -> term list -> |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
178 |
term list -> term list -> term list -> term list -> |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
179 |
({prems: thm list, context: Proof.context} -> tactic) -> Proof.context -> thm |
52731 | 180 |
val mk_un_fold_transfer_thms: fp_kind -> term list -> term list -> term list -> term list -> |
181 |
term list -> term list -> ({prems: thm list, context: Proof.context} -> tactic) -> |
|
182 |
Proof.context -> thm list |
|
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
183 |
val mk_xtor_un_fold_o_map_thms: fp_kind -> bool -> int -> thm -> thm list -> thm list -> |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
184 |
thm list -> thm list -> thm list |
52505
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
185 |
|
51867 | 186 |
val fp_bnf: (binding list -> (string * sort) list -> typ list * typ list list -> |
51868 | 187 |
BNF_Def.bnf list -> local_theory -> 'a) -> |
188 |
binding list -> (string * sort) list -> ((string * sort) * typ) list -> local_theory -> |
|
189 |
BNF_Def.bnf list * 'a |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
190 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
191 |
|
51850
106afdf5806c
renamed a few FP-related files, to make it clear that these are not the sum of LFP + GFP but rather shared basic libraries
blanchet
parents:
51839
diff
changeset
|
192 |
structure BNF_FP_Util : BNF_FP_UTIL = |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
193 |
struct |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
194 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
195 |
open BNF_Comp |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
196 |
open BNF_Def |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
197 |
open BNF_Util |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
198 |
|
52207
21026c312cc3
tuning -- avoided unreadable true/false all over the place for LFP/GFP
blanchet
parents:
52031
diff
changeset
|
199 |
datatype fp_kind = Least_FP | Greatest_FP; |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
200 |
fun fp_case Least_FP f1 _ = f1 |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
201 |
| fp_case Greatest_FP _ f2 = f2; |
52207
21026c312cc3
tuning -- avoided unreadable true/false all over the place for LFP/GFP
blanchet
parents:
52031
diff
changeset
|
202 |
|
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
203 |
type fp_result = |
51859 | 204 |
{Ts: typ list, |
205 |
bnfs: BNF_Def.bnf list, |
|
51839 | 206 |
ctors: term list, |
51819 | 207 |
dtors: term list, |
52328 | 208 |
xtor_co_iterss: term list list, |
52344 | 209 |
xtor_co_inducts: thm list, |
51819 | 210 |
dtor_ctors: thm list, |
211 |
ctor_dtors: thm list, |
|
212 |
ctor_injects: thm list, |
|
52314 | 213 |
xtor_map_thms: thm list, |
214 |
xtor_set_thmss: thm list list, |
|
215 |
xtor_rel_thms: thm list, |
|
52839 | 216 |
xtor_co_iter_thmss: thm list list, |
217 |
rel_co_induct_thm: thm}; |
|
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
218 |
|
52344 | 219 |
fun morph_fp_result phi {Ts, bnfs, ctors, dtors, xtor_co_iterss, xtor_co_inducts, dtor_ctors, |
52839 | 220 |
ctor_dtors, ctor_injects, xtor_map_thms, xtor_set_thmss, xtor_rel_thms, xtor_co_iter_thmss, |
221 |
rel_co_induct_thm} = |
|
51859 | 222 |
{Ts = map (Morphism.typ phi) Ts, |
223 |
bnfs = map (morph_bnf phi) bnfs, |
|
51839 | 224 |
ctors = map (Morphism.term phi) ctors, |
51823
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
225 |
dtors = map (Morphism.term phi) dtors, |
52328 | 226 |
xtor_co_iterss = map (map (Morphism.term phi)) xtor_co_iterss, |
52344 | 227 |
xtor_co_inducts = map (Morphism.thm phi) xtor_co_inducts, |
51823
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
228 |
dtor_ctors = map (Morphism.thm phi) dtor_ctors, |
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
229 |
ctor_dtors = map (Morphism.thm phi) ctor_dtors, |
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
230 |
ctor_injects = map (Morphism.thm phi) ctor_injects, |
52314 | 231 |
xtor_map_thms = map (Morphism.thm phi) xtor_map_thms, |
232 |
xtor_set_thmss = map (map (Morphism.thm phi)) xtor_set_thmss, |
|
233 |
xtor_rel_thms = map (Morphism.thm phi) xtor_rel_thms, |
|
52839 | 234 |
xtor_co_iter_thmss = map (map (Morphism.thm phi)) xtor_co_iter_thmss, |
235 |
rel_co_induct_thm = Morphism.thm phi rel_co_induct_thm}; |
|
51823
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
236 |
|
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
237 |
fun eq_fp_result ({bnfs = bnfs1, ...} : fp_result, {bnfs = bnfs2, ...} : fp_result) = |
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
238 |
eq_list eq_bnf (bnfs1, bnfs2); |
38996458bc5c
create data structure for storing (co)datatype information
blanchet
parents:
51819
diff
changeset
|
239 |
|
52344 | 240 |
fun co_induct_of (i :: _) = i; |
52343 | 241 |
fun strong_co_induct_of [_, s] = s; |
242 |
||
52330 | 243 |
fun un_fold_of [f, _] = f; |
244 |
fun co_rec_of [_, r] = r; |
|
245 |
||
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
246 |
val timing = true; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
247 |
fun time timer msg = (if timing |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51918
diff
changeset
|
248 |
then warning (msg ^ ": " ^ ATP_Util.string_of_time (Timer.checkRealTimer timer)) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
249 |
else (); Timer.startRealTimer ()); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
250 |
|
49223 | 251 |
val preN = "pre_" |
252 |
val rawN = "raw_" |
|
49218 | 253 |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
254 |
val coN = "co" |
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
255 |
val unN = "un" |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
256 |
val algN = "alg" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
257 |
val IITN = "IITN" |
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
258 |
val foldN = "fold" |
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
259 |
val unfoldN = unN ^ foldN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
260 |
val uniqueN = "_unique" |
52731 | 261 |
val transferN = "_transfer" |
49438 | 262 |
val simpsN = "simps" |
49501 | 263 |
val ctorN = "ctor" |
264 |
val dtorN = "dtor" |
|
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
265 |
val ctor_foldN = ctorN ^ "_" ^ foldN |
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
266 |
val dtor_unfoldN = dtorN ^ "_" ^ unfoldN |
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
267 |
val ctor_fold_uniqueN = ctor_foldN ^ uniqueN |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
268 |
val ctor_fold_o_mapN = ctor_foldN ^ "_o_" ^ mapN |
49504
df9b897fb254
renamed "iter"/"coiter" to "fold"/"unfold" (cf. Wadler)
blanchet
parents:
49502
diff
changeset
|
269 |
val dtor_unfold_uniqueN = dtor_unfoldN ^ uniqueN |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
270 |
val dtor_unfold_o_mapN = dtor_unfoldN ^ "_o_" ^ mapN |
52731 | 271 |
val ctor_fold_transferN = ctor_foldN ^ transferN |
272 |
val dtor_unfold_transferN = dtor_unfoldN ^ transferN |
|
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
273 |
val ctor_dtor_unfoldN = ctorN ^ "_" ^ dtor_unfoldN |
49541 | 274 |
val ctor_mapN = ctorN ^ "_" ^ mapN |
275 |
val dtor_mapN = dtorN ^ "_" ^ mapN |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
276 |
val map_uniqueN = mapN ^ uniqueN |
49543
53b3c532a082
renamed low-level "map_unique" to have "ctor" or "dtor" in the name
blanchet
parents:
49542
diff
changeset
|
277 |
val ctor_map_uniqueN = ctorN ^ "_" ^ map_uniqueN |
53b3c532a082
renamed low-level "map_unique" to have "ctor" or "dtor" in the name
blanchet
parents:
49542
diff
changeset
|
278 |
val dtor_map_uniqueN = dtorN ^ "_" ^ map_uniqueN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
279 |
val min_algN = "min_alg" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
280 |
val morN = "mor" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
281 |
val bisN = "bis" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
282 |
val lsbisN = "lsbis" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
283 |
val sum_bdTN = "sbdT" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
284 |
val sum_bdN = "sbd" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
285 |
val carTN = "carT" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
286 |
val strTN = "strT" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
287 |
val isNodeN = "isNode" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
288 |
val LevN = "Lev" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
289 |
val rvN = "recover" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
290 |
val behN = "beh" |
49585
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49584
diff
changeset
|
291 |
val setsN = "sets" |
49584
4339aa335355
use singular since there is always only one theorem
blanchet
parents:
49582
diff
changeset
|
292 |
val mk_ctor_setN = prefix (ctorN ^ "_") o mk_setN |
4339aa335355
use singular since there is always only one theorem
blanchet
parents:
49582
diff
changeset
|
293 |
val mk_dtor_setN = prefix (dtorN ^ "_") o mk_setN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
294 |
fun mk_set_inductN i = mk_setN i ^ "_induct" |
49542
b39354db8629
renamed low-level "set_simps" and "set_induct" to have "ctor" or "dtor" in the name
blanchet
parents:
49541
diff
changeset
|
295 |
val mk_dtor_set_inductN = prefix (dtorN ^ "_") o mk_set_inductN |
48975
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 str_initN = "str_init" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
298 |
val recN = "rec" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
299 |
val corecN = coN ^ recN |
49501 | 300 |
val ctor_recN = ctorN ^ "_" ^ recN |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
301 |
val ctor_rec_o_mapN = ctor_recN ^ "_o_" ^ mapN |
51739
3514b90d0a8b
(co)rec is (just as the (un)fold) the unique morphism;
traytel
parents:
49635
diff
changeset
|
302 |
val ctor_rec_uniqueN = ctor_recN ^ uniqueN |
49501 | 303 |
val dtor_corecN = dtorN ^ "_" ^ corecN |
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
304 |
val dtor_corec_o_mapN = dtor_corecN ^ "_o_" ^ mapN |
51739
3514b90d0a8b
(co)rec is (just as the (un)fold) the unique morphism;
traytel
parents:
49635
diff
changeset
|
305 |
val dtor_corec_uniqueN = dtor_corecN ^ uniqueN |
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
306 |
val ctor_dtor_corecN = ctorN ^ "_" ^ dtor_corecN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
307 |
|
49501 | 308 |
val ctor_dtorN = ctorN ^ "_" ^ dtorN |
309 |
val dtor_ctorN = dtorN ^ "_" ^ ctorN |
|
49020
f379cf5d71bd
more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents:
49019
diff
changeset
|
310 |
val nchotomyN = "nchotomy" |
49019 | 311 |
val injectN = "inject" |
49020
f379cf5d71bd
more work on BNF sugar -- up to derivation of nchotomy
blanchet
parents:
49019
diff
changeset
|
312 |
val exhaustN = "exhaust" |
49585
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49584
diff
changeset
|
313 |
val ctor_injectN = ctorN ^ "_" ^ injectN |
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49584
diff
changeset
|
314 |
val ctor_exhaustN = ctorN ^ "_" ^ exhaustN |
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49584
diff
changeset
|
315 |
val dtor_injectN = dtorN ^ "_" ^ injectN |
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49584
diff
changeset
|
316 |
val dtor_exhaustN = dtorN ^ "_" ^ exhaustN |
49545
8bb6e2d7346b
renamed coinduction principles to have "dtor" in the name
blanchet
parents:
49544
diff
changeset
|
317 |
val ctor_relN = ctorN ^ "_" ^ relN |
8bb6e2d7346b
renamed coinduction principles to have "dtor" in the name
blanchet
parents:
49544
diff
changeset
|
318 |
val dtor_relN = dtorN ^ "_" ^ relN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
319 |
val inductN = "induct" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
320 |
val coinductN = coN ^ inductN |
49501 | 321 |
val ctor_inductN = ctorN ^ "_" ^ inductN |
322 |
val ctor_induct2N = ctor_inductN ^ "2" |
|
49581
4e5bd3883429
renamed "dtor_coinduct" etc. to "dtor_map_coinduct"
blanchet
parents:
49545
diff
changeset
|
323 |
val dtor_map_coinductN = dtor_mapN ^ "_" ^ coinductN |
49582
557302525778
renamed "dtor_rel_coinduct" etc. to "dtor_coinduct"
blanchet
parents:
49581
diff
changeset
|
324 |
val dtor_coinductN = dtorN ^ "_" ^ coinductN |
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
325 |
val strong_coinductN = "strong_" ^ coinductN |
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
326 |
val dtor_map_strong_coinductN = dtor_mapN ^ "_" ^ strong_coinductN |
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
327 |
val dtor_strong_coinductN = dtorN ^ "_" ^ strong_coinductN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
328 |
val hsetN = "Hset" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
329 |
val hset_recN = hsetN ^ "_rec" |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
330 |
val set_inclN = "set_incl" |
49544
24094fa47e0d
renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents:
49543
diff
changeset
|
331 |
val ctor_set_inclN = ctorN ^ "_" ^ set_inclN |
24094fa47e0d
renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents:
49543
diff
changeset
|
332 |
val dtor_set_inclN = dtorN ^ "_" ^ set_inclN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
333 |
val set_set_inclN = "set_set_incl" |
49544
24094fa47e0d
renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents:
49543
diff
changeset
|
334 |
val ctor_set_set_inclN = ctorN ^ "_" ^ set_set_inclN |
24094fa47e0d
renamed "set_incl" etc. to have "ctor" or "dtor" in the name
blanchet
parents:
49543
diff
changeset
|
335 |
val dtor_set_set_inclN = dtorN ^ "_" ^ set_set_inclN |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
336 |
|
49338 | 337 |
val caseN = "case" |
49342 | 338 |
val discN = "disc" |
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
339 |
val disc_unfoldN = discN ^ "_" ^ unfoldN |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
340 |
val disc_corecN = discN ^ "_" ^ corecN |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
341 |
val iffN = "_iff" |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
342 |
val disc_unfold_iffN = discN ^ "_" ^ unfoldN ^ iffN |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
343 |
val disc_corec_iffN = discN ^ "_" ^ corecN ^ iffN |
49592
b859a02c1150
fixed "rels" + split them into injectivity and distinctness
blanchet
parents:
49591
diff
changeset
|
344 |
val distinctN = "distinct" |
b859a02c1150
fixed "rels" + split them into injectivity and distinctness
blanchet
parents:
49591
diff
changeset
|
345 |
val rel_distinctN = relN ^ "_" ^ distinctN |
b859a02c1150
fixed "rels" + split them into injectivity and distinctness
blanchet
parents:
49591
diff
changeset
|
346 |
val injectN = "inject" |
b859a02c1150
fixed "rels" + split them into injectivity and distinctness
blanchet
parents:
49591
diff
changeset
|
347 |
val rel_injectN = relN ^ "_" ^ injectN |
51918 | 348 |
val rel_coinductN = relN ^ "_" ^ coinductN |
349 |
val rel_inductN = relN ^ "_" ^ inductN |
|
49342 | 350 |
val selN = "sel" |
49594
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
351 |
val sel_unfoldN = selN ^ "_" ^ unfoldN |
55e798614c45
tweaked theorem names (in particular, dropped s's)
blanchet
parents:
49592
diff
changeset
|
352 |
val sel_corecN = selN ^ "_" ^ corecN |
49338 | 353 |
|
52899 | 354 |
fun co_prefix fp = (if fp = Greatest_FP then "co" else ""); |
51863 | 355 |
|
51858
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
356 |
fun add_components_of_typ (Type (s, Ts)) = |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
357 |
fold add_components_of_typ Ts #> cons (Long_Name.base_name s) |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
358 |
| add_components_of_typ _ = I; |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
359 |
|
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
360 |
fun base_name_of_typ T = space_implode "_" (add_components_of_typ T []); |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
361 |
|
49498 | 362 |
val mk_common_name = space_implode "_"; |
49327
541d818d2ff3
put an underscore between names, for compatibility with old package (and also because it makes sense)
blanchet
parents:
49308
diff
changeset
|
363 |
|
49264 | 364 |
fun dest_sumT (Type (@{type_name sum}, [T, T'])) = (T, T'); |
365 |
||
366 |
fun dest_sumTN 1 T = [T] |
|
367 |
| dest_sumTN n (Type (@{type_name sum}, [T, T'])) = T :: dest_sumTN (n - 1) T'; |
|
368 |
||
369 |
val dest_sumTN_balanced = Balanced_Tree.dest dest_sumT; |
|
370 |
||
371 |
(* TODO: move something like this to "HOLogic"? *) |
|
372 |
fun dest_tupleT 0 @{typ unit} = [] |
|
373 |
| dest_tupleT 1 T = [T] |
|
374 |
| dest_tupleT n (Type (@{type_name prod}, [T, T'])) = T :: dest_tupleT (n - 1) T'; |
|
375 |
||
376 |
val mk_sumTN = Library.foldr1 mk_sumT; |
|
377 |
val mk_sumTN_balanced = Balanced_Tree.make mk_sumT; |
|
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
378 |
|
49368 | 379 |
fun id_const T = Const (@{const_name id}, T --> T); |
380 |
||
49121 | 381 |
fun Inl_const LT RT = Const (@{const_name Inl}, LT --> mk_sumT (LT, RT)); |
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
382 |
fun mk_Inl RT t = Inl_const (fastype_of t) RT $ t; |
49121 | 383 |
|
384 |
fun Inr_const LT RT = Const (@{const_name Inr}, RT --> mk_sumT (LT, RT)); |
|
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
385 |
fun mk_Inr LT t = Inr_const LT (fastype_of t) $ t; |
49121 | 386 |
|
387 |
fun mk_InN [_] t 1 = t |
|
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
388 |
| mk_InN (_ :: Ts) t 1 = mk_Inl (mk_sumTN Ts) t |
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
389 |
| mk_InN (LT :: Ts) t m = mk_Inr LT (mk_InN Ts t (m - 1)) |
49121 | 390 |
| mk_InN Ts t _ = raise (TYPE ("mk_InN", Ts, [t])); |
391 |
||
49264 | 392 |
fun mk_InN_balanced sum_T n t k = |
393 |
let |
|
394 |
fun repair_types T (Const (s as @{const_name Inl}, _) $ t) = repair_inj_types T s fst t |
|
395 |
| repair_types T (Const (s as @{const_name Inr}, _) $ t) = repair_inj_types T s snd t |
|
396 |
| repair_types _ t = t |
|
397 |
and repair_inj_types T s get t = |
|
398 |
let val T' = get (dest_sumT T) in |
|
399 |
Const (s, T' --> T) $ repair_types T' t |
|
400 |
end; |
|
401 |
in |
|
402 |
Balanced_Tree.access {left = mk_Inl dummyT, right = mk_Inr dummyT, init = t} n k |
|
403 |
|> repair_types sum_T |
|
404 |
end; |
|
405 |
||
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
406 |
fun mk_sum_case (f, g) = |
49129 | 407 |
let |
408 |
val fT = fastype_of f; |
|
409 |
val gT = fastype_of g; |
|
410 |
in |
|
411 |
Const (@{const_name sum_case}, |
|
412 |
fT --> gT --> mk_sumT (domain_type fT, domain_type gT) --> range_type fT) $ f $ g |
|
413 |
end; |
|
414 |
||
49264 | 415 |
val mk_sum_caseN = Library.foldr1 mk_sum_case; |
416 |
val mk_sum_caseN_balanced = Balanced_Tree.make mk_sum_case; |
|
49176 | 417 |
|
49275 | 418 |
fun mk_If p t f = |
419 |
let val T = fastype_of t; |
|
420 |
in Const (@{const_name If}, HOLogic.boolT --> T --> T --> T) $ p $ t $ f end; |
|
421 |
||
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
422 |
fun mk_Field r = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
423 |
let val T = fst (dest_relT (fastype_of r)); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
424 |
in Const (@{const_name Field}, mk_relT (T, T) --> HOLogic.mk_setT T) $ r end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
425 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
426 |
val mk_union = HOLogic.mk_binop @{const_name sup}; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
427 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
428 |
(*dangerous; use with monotonic, converging functions only!*) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
429 |
fun fixpoint eq f X = if subset eq (f X, X) then X else fixpoint eq f (f X); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
430 |
|
51858
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
431 |
fun variant_types ss Ss ctxt = |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
432 |
let |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
433 |
val (tfrees, _) = |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
434 |
fold_map2 (fn s => fn S => Name.variant s #> apfst (rpair S)) ss Ss (Variable.names_of ctxt); |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
435 |
val ctxt' = fold (Variable.declare_constraints o Logic.mk_type o TFree) tfrees ctxt; |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
436 |
in (tfrees, ctxt') end; |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
437 |
|
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
438 |
fun variant_tfrees ss = |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
439 |
apfst (map TFree) o variant_types (map (prefix "'") ss) (replicate (length ss) HOLogic.typeS); |
7a08fe1e19b1
added and moved library functions (used in primrec code)
blanchet
parents:
51850
diff
changeset
|
440 |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
441 |
(* stolen from "~~/src/HOL/Tools/Datatype/datatype_aux.ML" *) |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
442 |
fun split_conj_thm th = |
49119 | 443 |
((th RS conjunct1) :: split_conj_thm (th RS conjunct2)) handle THM _ => [th]; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
444 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
445 |
fun split_conj_prems limit th = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
446 |
let |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
447 |
fun split n i th = |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
448 |
if i = n then th else split n (i + 1) (conjI RSN (i, th)) handle THM _ => th; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
449 |
in split limit 1 th end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
450 |
|
49255
2ecc533d6697
use balanced sums for constructors (to gracefully handle 100 constructors or more)
blanchet
parents:
49240
diff
changeset
|
451 |
fun mk_sumEN 1 = @{thm one_pointE} |
49240 | 452 |
| mk_sumEN 2 = @{thm sumE} |
453 |
| mk_sumEN n = |
|
52660 | 454 |
(fold (fn i => fn thm => @{thm obj_sumE_f} RSN (i, thm)) (2 upto n - 1) @{thm obj_sumE}) OF |
49240 | 455 |
replicate n (impI RS allI); |
49125 | 456 |
|
49335 | 457 |
fun mk_obj_sumEN_balanced n = |
458 |
Balanced_Tree.make (fn (thm1, thm2) => thm1 RSN (1, thm2 RSN (2, @{thm obj_sumE_f}))) |
|
459 |
(replicate n asm_rl); |
|
460 |
||
461 |
fun mk_sumEN_balanced' n all_impIs = mk_obj_sumEN_balanced n OF all_impIs RS @{thm obj_one_pointE}; |
|
462 |
||
463 |
fun mk_sumEN_balanced 1 = @{thm one_pointE} (*optimization*) |
|
49264 | 464 |
| mk_sumEN_balanced 2 = @{thm sumE} (*optimization*) |
49335 | 465 |
| mk_sumEN_balanced n = mk_sumEN_balanced' n (replicate n (impI RS allI)); |
466 |
||
467 |
fun mk_tupled_allIN 0 = @{thm unit_all_impI} |
|
468 |
| mk_tupled_allIN 1 = @{thm impI[THEN allI]} |
|
469 |
| mk_tupled_allIN 2 = @{thm prod_all_impI} (*optimization*) |
|
470 |
| mk_tupled_allIN n = mk_tupled_allIN (n - 1) RS @{thm prod_all_impI_step}; |
|
471 |
||
472 |
fun mk_sumEN_tupled_balanced ms = |
|
473 |
let val n = length ms in |
|
474 |
if forall (curry (op =) 1) ms then mk_sumEN_balanced n |
|
475 |
else mk_sumEN_balanced' n (map mk_tupled_allIN ms) |
|
476 |
end; |
|
49264 | 477 |
|
478 |
fun mk_sum_casesN 1 1 = refl |
|
49130
3c26e17b2849
implemented "mk_case_tac" -- and got rid of "cheat_tac"
blanchet
parents:
49129
diff
changeset
|
479 |
| mk_sum_casesN _ 1 = @{thm sum.cases(1)} |
3c26e17b2849
implemented "mk_case_tac" -- and got rid of "cheat_tac"
blanchet
parents:
49129
diff
changeset
|
480 |
| mk_sum_casesN 2 2 = @{thm sum.cases(2)} |
49264 | 481 |
| mk_sum_casesN n k = trans OF [@{thm sum_case_step(2)}, mk_sum_casesN (n - 1) (k - 1)]; |
482 |
||
483 |
fun mk_sum_step base step thm = |
|
484 |
if Thm.eq_thm_prop (thm, refl) then base else trans OF [step, thm]; |
|
485 |
||
486 |
fun mk_sum_casesN_balanced 1 1 = refl |
|
487 |
| mk_sum_casesN_balanced n k = |
|
488 |
Balanced_Tree.access {left = mk_sum_step @{thm sum.cases(1)} @{thm sum_case_step(1)}, |
|
489 |
right = mk_sum_step @{thm sum.cases(2)} @{thm sum_case_step(2)}, init = refl} n k; |
|
49130
3c26e17b2849
implemented "mk_case_tac" -- and got rid of "cheat_tac"
blanchet
parents:
49129
diff
changeset
|
490 |
|
52505
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
491 |
fun mk_rel_co_induct_thm fp pre_rels pre_phis rels phis xs ys xtors xtor's tac lthy = |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
492 |
let |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
493 |
val pre_relphis = map (fn rel => Term.list_comb (rel, phis @ pre_phis)) pre_rels; |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
494 |
val relphis = map (fn rel => Term.list_comb (rel, phis)) rels; |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
495 |
fun mk_xtor fp' xtor x = if fp = fp' then xtor $ x else x; |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
496 |
val dtor = mk_xtor Greatest_FP; |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
497 |
val ctor = mk_xtor Least_FP; |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
498 |
fun flip f x y = if fp = Greatest_FP then f y x else f x y; |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
499 |
|
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
500 |
fun mk_prem pre_relphi phi x y xtor xtor' = |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
501 |
HOLogic.mk_Trueprop (list_all_free [x, y] (flip (curry HOLogic.mk_imp) |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
502 |
(pre_relphi $ (dtor xtor x) $ (dtor xtor' y)) (phi $ (ctor xtor x) $ (ctor xtor' y)))); |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
503 |
val prems = map6 mk_prem pre_relphis pre_phis xs ys xtors xtor's; |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
504 |
|
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
505 |
val concl = HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
506 |
(map2 (flip mk_leq) relphis pre_phis)); |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
507 |
in |
52506 | 508 |
Goal.prove_sorry lthy (map (fst o dest_Free) (phis @ pre_phis)) prems concl tac |
52505
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
509 |
|> Thm.close_derivation |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
510 |
|> (fn thm => thm OF (replicate (length pre_rels) @{thm allI[OF allI[OF impI]]})) |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
511 |
end; |
e62f3fd2035e
share some code between codatatypes, datatypes and eventually prim(co)rec
traytel
parents:
52344
diff
changeset
|
512 |
|
52731 | 513 |
fun mk_un_fold_transfer_thms fp pre_rels pre_phis rels phis un_folds un_folds' tac lthy = |
514 |
let |
|
515 |
val pre_relphis = map (fn rel => Term.list_comb (rel, phis @ pre_phis)) pre_rels; |
|
516 |
val relphis = map (fn rel => Term.list_comb (rel, phis)) rels; |
|
517 |
fun flip f x y = if fp = Greatest_FP then f y x else f x y; |
|
518 |
||
519 |
val arg_rels = map2 (flip mk_fun_rel) pre_relphis pre_phis; |
|
520 |
fun mk_transfer relphi pre_phi un_fold un_fold' = |
|
521 |
fold_rev mk_fun_rel arg_rels (flip mk_fun_rel relphi pre_phi) $ un_fold $ un_fold'; |
|
522 |
val transfers = map4 mk_transfer relphis pre_phis un_folds un_folds'; |
|
523 |
||
524 |
val goal = fold_rev Logic.all (phis @ pre_phis) |
|
525 |
(HOLogic.mk_Trueprop (Library.foldr1 HOLogic.mk_conj transfers)); |
|
526 |
in |
|
527 |
Goal.prove_sorry lthy [] [] goal tac |
|
528 |
|> Thm.close_derivation |
|
529 |
|> split_conj_thm |
|
530 |
end; |
|
531 |
||
52913
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
532 |
fun mk_xtor_un_fold_o_map_thms fp is_rec m un_fold_unique xtor_maps xtor_un_folds sym_map_comps |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
533 |
map_cong0s = |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
534 |
let |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
535 |
val n = length sym_map_comps; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
536 |
val rewrite_comp_comp2 = fp_case fp @{thm rewriteR_comp_comp2} @{thm rewriteL_comp_comp2}; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
537 |
val rewrite_comp_comp = fp_case fp @{thm rewriteR_comp_comp} @{thm rewriteL_comp_comp}; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
538 |
val map_cong_passive_args1 = replicate m (fp_case fp @{thm id_o} @{thm o_id} RS fun_cong); |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
539 |
val map_cong_active_args1 = replicate n (if is_rec |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
540 |
then fp_case fp @{thm convol_o} @{thm o_sum_case} RS fun_cong |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
541 |
else refl); |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
542 |
val map_cong_passive_args2 = replicate m (fp_case fp @{thm o_id} @{thm id_o} RS fun_cong); |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
543 |
val map_cong_active_args2 = replicate n (if is_rec |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
544 |
then fp_case fp @{thm map_pair_o_convol_id} @{thm sum_case_o_sum_map_id} |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
545 |
else fp_case fp @{thm id_o} @{thm o_id} RS fun_cong); |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
546 |
fun mk_map_congs passive active = map (fn thm => thm OF (passive @ active) RS ext) map_cong0s; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
547 |
val map_cong1s = mk_map_congs map_cong_passive_args1 map_cong_active_args1; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
548 |
val map_cong2s = mk_map_congs map_cong_passive_args2 map_cong_active_args2; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
549 |
|
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
550 |
fun mk_rewrites map_congs = map2 (fn sym_map_comp => fn map_cong => |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
551 |
mk_trans sym_map_comp map_cong RS rewrite_comp_comp) sym_map_comps map_congs; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
552 |
val rewrite1s = mk_rewrites map_cong1s; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
553 |
val rewrite2s = mk_rewrites map_cong2s; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
554 |
val unique_prems = |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
555 |
map4 (fn xtor_map => fn un_fold => fn rewrite1 => fn rewrite2 => |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
556 |
mk_trans (rewrite_comp_comp2 OF [xtor_map, un_fold]) |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
557 |
(mk_trans rewrite1 (mk_sym rewrite2))) |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
558 |
xtor_maps xtor_un_folds rewrite1s rewrite2s; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
559 |
in |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
560 |
split_conj_thm (un_fold_unique OF map (fp_case fp I mk_sym) unique_prems) |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
561 |
end; |
2d2d9d1de1a9
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
traytel
parents:
52899
diff
changeset
|
562 |
|
51868 | 563 |
fun fp_bnf construct_fp bs resBs eqs lthy = |
564 |
let |
|
565 |
val timer = time (Timer.startRealTimer ()); |
|
566 |
val (lhss, rhss) = split_list eqs; |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
567 |
|
51868 | 568 |
(* FIXME: because of "@ lhss", the output could contain type variables that are not in the |
569 |
input; also, "fp_sort" should put the "resBs" first and in the order in which they appear *) |
|
570 |
fun fp_sort Ass = |
|
571 |
subtract (op =) lhss (filter (fn T => exists (fn Ts => member (op =) Ts T) Ass) resBs) @ lhss; |
|
572 |
||
573 |
fun raw_qualify b = Binding.qualify true (Binding.name_of (Binding.prefix_name rawN b)); |
|
574 |
||
575 |
val ((bnfs, (deadss, livess)), (unfold_set, lthy)) = apfst (apsnd split_list o split_list) |
|
576 |
(fold_map2 (fn b => bnf_of_typ Smart_Inline (raw_qualify b) fp_sort) bs rhss |
|
577 |
(empty_unfolds, lthy)); |
|
578 |
||
49498 | 579 |
val name = mk_common_name (map Binding.name_of bs); |
49425 | 580 |
fun qualify i = |
581 |
let val namei = name ^ nonzero_string_of_int i; |
|
582 |
in Binding.qualify true namei end; |
|
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
583 |
|
49132 | 584 |
val Ass = map (map dest_TFree) livess; |
51866 | 585 |
val resDs = fold (subtract (op =)) Ass resBs; |
49185
073d7d1b7488
respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents:
49176
diff
changeset
|
586 |
val Ds = fold (fold Term.add_tfreesT) deadss []; |
49132 | 587 |
|
49156 | 588 |
val _ = (case Library.inter (op =) Ds lhss of [] => () |
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49589
diff
changeset
|
589 |
| A :: _ => error ("Inadmissible type recursion (cannot take fixed point of dead type \ |
49132 | 590 |
\variable " ^ quote (Syntax.string_of_typ lthy (TFree A)) ^ ")")); |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
591 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
592 |
val timer = time (timer "Construction of BNFs"); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
593 |
|
49502 | 594 |
val ((kill_poss, _), (bnfs', (unfold_set', lthy'))) = |
51868 | 595 |
normalize_bnfs qualify Ass Ds fp_sort bnfs unfold_set lthy; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
596 |
|
49132 | 597 |
val Dss = map3 (append oo map o nth) livess kill_poss deadss; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
598 |
|
51865 | 599 |
val ((pre_bnfs, deadss), lthy'') = |
49502 | 600 |
fold_map3 (seal_bnf unfold_set') (map (Binding.prefix_name preN) bs) Dss bnfs' lthy' |
49185
073d7d1b7488
respect order of/additional type variables supplied by the user in fixed point constructions;
traytel
parents:
49176
diff
changeset
|
601 |
|>> split_list; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
602 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
603 |
val timer = time (timer "Normalization & sealing of BNFs"); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
604 |
|
51867 | 605 |
val res = construct_fp bs resBs (map TFree resDs, deadss) pre_bnfs lthy''; |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
606 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
607 |
val timer = time (timer "FP construction in total"); |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
608 |
in |
51865 | 609 |
timer; (pre_bnfs, res) |
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
610 |
end; |
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
611 |
|
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
612 |
end; |