author | blanchet |
Sun, 06 Oct 2013 20:24:06 +0200 | |
changeset 54068 | 447354985f6a |
parent 54067 | 7be49e2bfccc |
child 54069 | 3fd3b1683d2b |
permissions | -rw-r--r-- |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
1 |
(* Title: HOL/BNF/Tools/bnf_fp_rec_sugar_util.ML |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
2 |
Author: Lorenz Panny, TU Muenchen |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
3 |
Author: Jasmin Blanchette, TU Muenchen |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
4 |
Copyright 2013 |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
5 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
6 |
Library for recursor and corecursor sugar. |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
7 |
*) |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
8 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
9 |
signature BNF_FP_REC_SUGAR_UTIL = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
10 |
sig |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
11 |
datatype rec_call = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
12 |
No_Rec of int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
13 |
Direct_Rec of int (*before*) * int (*after*) | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
14 |
Indirect_Rec of int |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
15 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
16 |
datatype corec_call = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
17 |
Dummy_No_Corec of int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
18 |
No_Corec of int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
19 |
Direct_Corec of int (*stop?*) * int (*end*) * int (*continue*) | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
20 |
Indirect_Corec of int |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
21 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
22 |
type rec_ctr_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
23 |
{ctr: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
24 |
offset: int, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
25 |
calls: rec_call list, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
26 |
rec_thm: thm} |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
27 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
28 |
type corec_ctr_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
29 |
{ctr: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
30 |
disc: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
31 |
sels: term list, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
32 |
pred: int option, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
33 |
calls: corec_call list, |
53705 | 34 |
discI: thm, |
35 |
sel_thms: thm list, |
|
53475 | 36 |
collapse: thm, |
37 |
corec_thm: thm, |
|
38 |
disc_corec: thm, |
|
39 |
sel_corecs: thm list} |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
40 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
41 |
type rec_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
42 |
{recx: term, |
53329 | 43 |
nested_map_idents: thm list, |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
44 |
nested_map_comps: thm list, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
45 |
ctr_specs: rec_ctr_spec list} |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
46 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
47 |
type corec_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
48 |
{corec: term, |
53475 | 49 |
nested_maps: thm list, |
50 |
nested_map_idents: thm list, |
|
51 |
nested_map_comps: thm list, |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
52 |
ctr_specs: corec_ctr_spec list} |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
53 |
|
54067 | 54 |
val s_not: term -> term |
55 |
val s_not_conj: term list -> term list |
|
54068 | 56 |
val s_conjs: term list -> term |
57 |
val s_disjs: term list -> term |
|
58 |
val s_dnf: term list list -> term list |
|
53878 | 59 |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
60 |
val massage_indirect_rec_call: Proof.context -> (term -> bool) -> (typ -> typ -> term -> term) -> |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
61 |
typ list -> term -> term -> term -> term |
53890 | 62 |
val massage_direct_corec_call: Proof.context -> (term -> bool) -> (typ list -> term -> term) -> |
63 |
typ list -> term -> term |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
64 |
val massage_indirect_corec_call: Proof.context -> (term -> bool) -> |
53890 | 65 |
(typ list -> typ -> typ -> term -> term) -> typ list -> typ -> term -> term |
53727
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
66 |
val expand_corec_code_rhs: Proof.context -> (term -> bool) -> typ list -> term -> term |
53890 | 67 |
val massage_corec_code_rhs: Proof.context -> (typ list -> term -> term list -> term) -> |
68 |
typ list -> term -> term |
|
53871 | 69 |
val fold_rev_corec_code_rhs: Proof.context -> (term list -> term -> term list -> 'a -> 'a) -> |
70 |
typ list -> term -> 'a -> 'a |
|
53909 | 71 |
val case_thms_of_term: Proof.context -> typ list -> term -> |
53925 | 72 |
thm list * thm list * thm list * thm list |
53878 | 73 |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
74 |
val rec_specs_of: binding list -> typ list -> typ list -> (term -> int list) -> |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
75 |
((term * term list list) list) list -> local_theory -> |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
76 |
(bool * rec_spec list * typ list * thm * thm list) * local_theory |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
77 |
val corec_specs_of: binding list -> typ list -> typ list -> (term -> int list) -> |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
78 |
((term * term list list) list) list -> local_theory -> |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
79 |
(bool * corec_spec list * typ list * thm * thm * thm list * thm list) * local_theory |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
80 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
81 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
82 |
structure BNF_FP_Rec_Sugar_Util : BNF_FP_REC_SUGAR_UTIL = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
83 |
struct |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
84 |
|
54006 | 85 |
open Ctr_Sugar |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
86 |
open BNF_Util |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
87 |
open BNF_Def |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
88 |
open BNF_FP_Util |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
89 |
open BNF_FP_Def_Sugar |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
90 |
open BNF_FP_N2M_Sugar |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
91 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
92 |
datatype rec_call = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
93 |
No_Rec of int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
94 |
Direct_Rec of int * int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
95 |
Indirect_Rec of int; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
96 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
97 |
datatype corec_call = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
98 |
Dummy_No_Corec of int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
99 |
No_Corec of int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
100 |
Direct_Corec of int * int * int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
101 |
Indirect_Corec of int; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
102 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
103 |
type rec_ctr_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
104 |
{ctr: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
105 |
offset: int, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
106 |
calls: rec_call list, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
107 |
rec_thm: thm}; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
108 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
109 |
type corec_ctr_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
110 |
{ctr: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
111 |
disc: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
112 |
sels: term list, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
113 |
pred: int option, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
114 |
calls: corec_call list, |
53705 | 115 |
discI: thm, |
116 |
sel_thms: thm list, |
|
53475 | 117 |
collapse: thm, |
118 |
corec_thm: thm, |
|
119 |
disc_corec: thm, |
|
120 |
sel_corecs: thm list}; |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
121 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
122 |
type rec_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
123 |
{recx: term, |
53329 | 124 |
nested_map_idents: thm list, |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
125 |
nested_map_comps: thm list, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
126 |
ctr_specs: rec_ctr_spec list}; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
127 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
128 |
type corec_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
129 |
{corec: term, |
53475 | 130 |
nested_maps: thm list, |
131 |
nested_map_idents: thm list, |
|
132 |
nested_map_comps: thm list, |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
133 |
ctr_specs: corec_ctr_spec list}; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
134 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
135 |
val id_def = @{thm id_def}; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
136 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
137 |
exception AINT_NO_MAP of term; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
138 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
139 |
fun ill_formed_rec_call ctxt t = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
140 |
error ("Ill-formed recursive call: " ^ quote (Syntax.string_of_term ctxt t)); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
141 |
fun ill_formed_corec_call ctxt t = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
142 |
error ("Ill-formed corecursive call: " ^ quote (Syntax.string_of_term ctxt t)); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
143 |
fun invalid_map ctxt t = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
144 |
error ("Invalid map function in " ^ quote (Syntax.string_of_term ctxt t)); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
145 |
fun unexpected_rec_call ctxt t = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
146 |
error ("Unexpected recursive call: " ^ quote (Syntax.string_of_term ctxt t)); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
147 |
fun unexpected_corec_call ctxt t = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
148 |
error ("Unexpected corecursive call: " ^ quote (Syntax.string_of_term ctxt t)); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
149 |
|
53878 | 150 |
val mk_conjs = try (foldr1 HOLogic.mk_conj) #> the_default @{const True}; |
151 |
val mk_disjs = try (foldr1 HOLogic.mk_disj) #> the_default @{const False}; |
|
152 |
||
54067 | 153 |
val conjuncts_s = filter_out (curry (op =) @{const True}) o HOLogic.conjuncts; |
53878 | 154 |
|
54067 | 155 |
fun s_not @{const True} = @{const False} |
156 |
| s_not @{const False} = @{const True} |
|
157 |
| s_not (@{const Not} $ t) = t |
|
158 |
| s_not (@{const conj} $ t $ u) = @{const disj} $ s_not t $ s_not u |
|
159 |
| s_not (@{const disj} $ t $ u) = @{const conj} $ s_not t $ s_not u |
|
160 |
| s_not (@{const implies} $ t $ u) = @{const conj} $ t $ s_not u |
|
161 |
| s_not t = @{const Not} $ t; |
|
53878 | 162 |
|
54067 | 163 |
val s_not_conj = conjuncts_s o s_not o mk_conjs; |
53878 | 164 |
|
54068 | 165 |
fun s_conj c @{const True} = c |
166 |
| s_conj c d = HOLogic.mk_conj (c, d); |
|
167 |
||
168 |
fun propagate_unit_pos u cs = if member (op aconv) cs u then [@{const False}] else cs; |
|
169 |
||
170 |
fun propagate_unit_neg not_u cs = remove (op aconv) not_u cs; |
|
171 |
||
172 |
fun propagate_units css = |
|
173 |
(case List.partition (can the_single) css of |
|
174 |
([], _) => css |
|
175 |
| ([u] :: uss, css') => |
|
176 |
[u] :: propagate_units (map (propagate_unit_neg (s_not u)) |
|
177 |
(map (propagate_unit_pos u) (uss @ css')))); |
|
178 |
||
179 |
fun s_conjs cs = |
|
180 |
if member (op aconv) cs @{const False} then @{const False} |
|
181 |
else mk_conjs (remove (op aconv) @{const True} cs); |
|
182 |
||
183 |
fun s_disjs ds = |
|
184 |
if member (op aconv) ds @{const True} then @{const True} |
|
185 |
else mk_disjs (remove (op aconv) @{const False} ds); |
|
186 |
||
187 |
fun s_dnf css0 = |
|
188 |
let val css = propagate_units css0 in |
|
189 |
if null css then |
|
190 |
[@{const False}] |
|
191 |
else if exists null css then |
|
192 |
[] |
|
193 |
else |
|
194 |
map (fn c :: cs => (c, cs)) css |
|
195 |
|> AList.coalesce (op =) |
|
196 |
|> map (fn (c, css) => c :: s_dnf css) |
|
197 |
|> (fn [cs] => cs | css => [s_disjs (map s_conjs css)]) |
|
198 |
end; |
|
199 |
||
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
200 |
fun factor_out_types ctxt massage destU U T = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
201 |
(case try destU U of |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
202 |
SOME (U1, U2) => if U1 = T then massage T U2 else invalid_map ctxt |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
203 |
| NONE => invalid_map ctxt); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
204 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
205 |
fun map_flattened_map_args ctxt s map_args fs = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
206 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
207 |
val flat_fs = flatten_type_args_of_bnf (the (bnf_of ctxt s)) Term.dummy fs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
208 |
val flat_fs' = map_args flat_fs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
209 |
in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
210 |
permute_like (op aconv) flat_fs fs flat_fs' |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
211 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
212 |
|
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
213 |
fun massage_indirect_rec_call ctxt has_call raw_massage_fun bound_Ts y y' = |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
214 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
215 |
val typof = curry fastype_of1 bound_Ts; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
216 |
val build_map_fst = build_map ctxt (fst_const o fst); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
217 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
218 |
val yT = typof y; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
219 |
val yU = typof y'; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
220 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
221 |
fun y_of_y' () = build_map_fst (yU, yT) $ y'; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
222 |
val elim_y = Term.map_aterms (fn t => if t = y then y_of_y' () else t); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
223 |
|
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
224 |
fun massage_direct_fun U T t = |
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
225 |
if has_call t then factor_out_types ctxt raw_massage_fun HOLogic.dest_prodT U T t |
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
226 |
else HOLogic.mk_comp (t, build_map_fst (U, T)); |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
227 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
228 |
fun massage_map (Type (_, Us)) (Type (s, Ts)) t = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
229 |
(case try (dest_map ctxt s) t of |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
230 |
SOME (map0, fs) => |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
231 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
232 |
val Type (_, ran_Ts) = range_type (typof t); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
233 |
val map' = mk_map (length fs) Us ran_Ts map0; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
234 |
val fs' = map_flattened_map_args ctxt s (map3 massage_map_or_map_arg Us Ts) fs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
235 |
in |
53870 | 236 |
Term.list_comb (map', fs') |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
237 |
end |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
238 |
| NONE => raise AINT_NO_MAP t) |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
239 |
| massage_map _ _ t = raise AINT_NO_MAP t |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
240 |
and massage_map_or_map_arg U T t = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
241 |
if T = U then |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
242 |
if has_call t then unexpected_rec_call ctxt t else t |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
243 |
else |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
244 |
massage_map U T t |
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
245 |
handle AINT_NO_MAP _ => massage_direct_fun U T t; |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
246 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
247 |
fun massage_call (t as t1 $ t2) = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
248 |
if t2 = y then |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
249 |
massage_map yU yT (elim_y t1) $ y' |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
250 |
handle AINT_NO_MAP t' => invalid_map ctxt t' |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
251 |
else |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
252 |
ill_formed_rec_call ctxt t |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
253 |
| massage_call t = if t = y then y_of_y' () else ill_formed_rec_call ctxt t; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
254 |
in |
53724 | 255 |
massage_call |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
256 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
257 |
|
53909 | 258 |
fun fold_rev_let_if_case ctxt f bound_Ts t = |
53866 | 259 |
let |
53870 | 260 |
val thy = Proof_Context.theory_of ctxt; |
261 |
||
53871 | 262 |
fun fld conds t = |
53866 | 263 |
(case Term.strip_comb t of |
53871 | 264 |
(Const (@{const_name Let}, _), [arg1, arg2]) => fld conds (betapply (arg2, arg1)) |
265 |
| (Const (@{const_name If}, _), [cond, then_branch, else_branch]) => |
|
54067 | 266 |
fld (conds @ conjuncts_s cond) then_branch |
267 |
o fld (conds @ s_not_conj [cond]) else_branch |
|
53896 | 268 |
| (Const (c, _), args as _ :: _ :: _) => |
269 |
let val n = num_binder_types (Sign.the_const_type thy c) - 1 in |
|
53924 | 270 |
if n >= 0 andalso n < length args then |
53896 | 271 |
(case fastype_of1 (bound_Ts, nth args n) of |
272 |
Type (s, Ts) => |
|
273 |
(case dest_case ctxt s Ts t of |
|
53909 | 274 |
NONE => apsnd (f conds t) |
53896 | 275 |
| SOME (conds', branches) => |
53909 | 276 |
apfst (cons s) o fold_rev (uncurry fld) |
54067 | 277 |
(map (append conds o conjuncts_s) conds' ~~ branches)) |
53909 | 278 |
| _ => apsnd (f conds t)) |
53896 | 279 |
else |
53909 | 280 |
apsnd (f conds t) |
53866 | 281 |
end |
53909 | 282 |
| _ => apsnd (f conds t)) |
53866 | 283 |
in |
53909 | 284 |
fld [] t o pair [] |
53866 | 285 |
end; |
286 |
||
53870 | 287 |
fun case_of ctxt = ctr_sugar_of ctxt #> Option.map (fst o dest_Const o #casex); |
288 |
||
53890 | 289 |
fun massage_let_if_case ctxt has_call massage_leaf = |
53723 | 290 |
let |
53888 | 291 |
val thy = Proof_Context.theory_of ctxt; |
292 |
||
293 |
fun check_no_call t = if has_call t then unexpected_corec_call ctxt t else (); |
|
53835
687116951569
started adding support for "nat_case" as case study for all "case" constructs
blanchet
parents:
53833
diff
changeset
|
294 |
|
53895 | 295 |
fun massage_abs bound_Ts (Abs (s, T, t)) = Abs (s, T, massage_abs (T :: bound_Ts) t) |
53893 | 296 |
| massage_abs bound_Ts t = massage_rec bound_Ts t |
297 |
and massage_rec bound_Ts t = |
|
53890 | 298 |
let val typof = curry fastype_of1 bound_Ts in |
299 |
(case Term.strip_comb t of |
|
300 |
(Const (@{const_name Let}, _), [arg1, arg2]) => |
|
301 |
massage_rec bound_Ts (betapply (arg2, arg1)) |
|
53893 | 302 |
| (Const (@{const_name If}, _), obj :: (branches as [_, _])) => |
53890 | 303 |
let val branches' = map (massage_rec bound_Ts) branches in |
304 |
Term.list_comb (If_const (typof (hd branches')) $ tap check_no_call obj, branches') |
|
305 |
end |
|
53896 | 306 |
| (Const (c, _), args as _ :: _ :: _) => |
307 |
let |
|
308 |
val gen_T = Sign.the_const_type thy c; |
|
309 |
val (gen_branch_Ts, gen_body_fun_T) = strip_fun_type gen_T; |
|
310 |
val n = length gen_branch_Ts; |
|
311 |
in |
|
53924 | 312 |
if n < length args then |
53896 | 313 |
(case gen_body_fun_T of |
314 |
Type (_, [Type (T_name, _), _]) => |
|
315 |
if case_of ctxt T_name = SOME c then |
|
53891 | 316 |
let |
317 |
val (branches, obj_leftovers) = chop n args; |
|
53893 | 318 |
val branches' = map (massage_abs bound_Ts o Envir.eta_long bound_Ts) branches; |
53896 | 319 |
val branch_Ts' = map typof branches'; |
320 |
val casex' = Const (c, branch_Ts' ---> map typof obj_leftovers ---> |
|
321 |
snd (strip_typeN (num_binder_types (hd gen_branch_Ts)) (hd branch_Ts'))); |
|
53891 | 322 |
in |
53895 | 323 |
Term.list_comb (casex', branches' @ tap (List.app check_no_call) obj_leftovers) |
53891 | 324 |
end |
325 |
else |
|
326 |
massage_leaf bound_Ts t |
|
327 |
| _ => massage_leaf bound_Ts t) |
|
328 |
else |
|
329 |
massage_leaf bound_Ts t |
|
53890 | 330 |
end |
331 |
| _ => massage_leaf bound_Ts t) |
|
332 |
end |
|
53723 | 333 |
in |
334 |
massage_rec |
|
335 |
end; |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
336 |
|
53866 | 337 |
val massage_direct_corec_call = massage_let_if_case; |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
338 |
|
54016
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
339 |
fun curried_type (Type (@{type_name fun}, [Type (@{type_name prod}, Ts), T])) = Ts ---> T; |
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
340 |
|
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
341 |
fun massage_indirect_corec_call ctxt has_call raw_massage_call bound_Ts U t = |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
342 |
let |
53411 | 343 |
val build_map_Inl = build_map ctxt (uncurry Inl_const o dest_sumT o snd) |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
344 |
|
53890 | 345 |
fun massage_direct_call bound_Ts U T t = |
346 |
if has_call t then factor_out_types ctxt (raw_massage_call bound_Ts) dest_sumT U T t |
|
53411 | 347 |
else build_map_Inl (T, U) $ t; |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
348 |
|
53890 | 349 |
fun massage_direct_fun bound_Ts U T t = |
350 |
let |
|
351 |
val var = Var ((Name.uu, Term.maxidx_of_term t + 1), |
|
352 |
domain_type (fastype_of1 (bound_Ts, t))); |
|
353 |
in |
|
354 |
Term.lambda var (massage_direct_call bound_Ts U T (t $ var)) |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
355 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
356 |
|
53890 | 357 |
fun massage_map bound_Ts (Type (_, Us)) (Type (s, Ts)) t = |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
358 |
(case try (dest_map ctxt s) t of |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
359 |
SOME (map0, fs) => |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
360 |
let |
53890 | 361 |
val Type (_, dom_Ts) = domain_type (fastype_of1 (bound_Ts, t)); |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
362 |
val map' = mk_map (length fs) dom_Ts Us map0; |
53890 | 363 |
val fs' = |
364 |
map_flattened_map_args ctxt s (map3 (massage_map_or_map_arg bound_Ts) Us Ts) fs; |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
365 |
in |
53870 | 366 |
Term.list_comb (map', fs') |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
367 |
end |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
368 |
| NONE => raise AINT_NO_MAP t) |
53890 | 369 |
| massage_map _ _ _ t = raise AINT_NO_MAP t |
370 |
and massage_map_or_map_arg bound_Ts U T t = |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
371 |
if T = U then |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
372 |
if has_call t then unexpected_corec_call ctxt t else t |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
373 |
else |
53890 | 374 |
massage_map bound_Ts U T t |
375 |
handle AINT_NO_MAP _ => massage_direct_fun bound_Ts U T t; |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
376 |
|
53890 | 377 |
fun massage_call bound_Ts U T = |
378 |
massage_let_if_case ctxt has_call (fn bound_Ts => fn t => |
|
53732
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
379 |
if has_call t then |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
380 |
(case U of |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
381 |
Type (s, Us) => |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
382 |
(case try (dest_ctr ctxt s) t of |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
383 |
SOME (f, args) => |
53890 | 384 |
let |
385 |
val typof = curry fastype_of1 bound_Ts; |
|
386 |
val f' = mk_ctr Us f |
|
387 |
val f'_T = typof f'; |
|
388 |
val arg_Ts = map typof args; |
|
389 |
in |
|
390 |
Term.list_comb (f', map3 (massage_call bound_Ts) (binder_types f'_T) arg_Ts args) |
|
53732
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
391 |
end |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
392 |
| NONE => |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
393 |
(case t of |
54016
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
394 |
Const (@{const_name prod_case}, _) $ t' => |
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
395 |
let |
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
396 |
val U' = curried_type U; |
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
397 |
val T' = curried_type T; |
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
398 |
in |
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
399 |
Const (@{const_name prod_case}, U' --> U) $ massage_call bound_Ts U' T' t' |
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
400 |
end |
769fcbdf2918
allow uncurried lambda-abstractions on rhs of "primcorec"
blanchet
parents:
54009
diff
changeset
|
401 |
| t1 $ t2 => |
53732
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
402 |
(if has_call t2 then |
53890 | 403 |
massage_direct_call bound_Ts U T t |
53732
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
404 |
else |
53890 | 405 |
massage_map bound_Ts U T t1 $ t2 |
406 |
handle AINT_NO_MAP _ => massage_direct_call bound_Ts U T t) |
|
407 |
| Abs (s, T', t') => |
|
408 |
Abs (s, T', massage_call (T' :: bound_Ts) (range_type U) (range_type T) t') |
|
409 |
| _ => massage_direct_call bound_Ts U T t)) |
|
53732
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
410 |
| _ => ill_formed_corec_call ctxt t) |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
411 |
else |
53889 | 412 |
build_map_Inl (T, U) $ t) bound_Ts; |
53960 | 413 |
|
414 |
val T = fastype_of1 (bound_Ts, t); |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
415 |
in |
53960 | 416 |
if has_call t then massage_call bound_Ts U T t else build_map_Inl (T, U) $ t |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
417 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
418 |
|
53727
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
419 |
fun expand_ctr_term ctxt s Ts t = |
53867
8ad44ecc0d15
keep a database of free constructor type information
blanchet
parents:
53866
diff
changeset
|
420 |
(case ctr_sugar_of ctxt s of |
53870 | 421 |
SOME {ctrs, casex, ...} => |
422 |
Term.list_comb (mk_case Ts (Type (s, Ts)) casex, map (mk_ctr Ts) ctrs) $ t |
|
53727
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
423 |
| NONE => raise Fail "expand_ctr_term"); |
53726
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
424 |
|
53727
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
425 |
fun expand_corec_code_rhs ctxt has_call bound_Ts t = |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
426 |
(case fastype_of1 (bound_Ts, t) of |
53889 | 427 |
Type (s, Ts) => |
53893 | 428 |
massage_let_if_case ctxt has_call (fn _ => fn t => |
53892 | 429 |
if can (dest_ctr ctxt s) t then t else expand_ctr_term ctxt s Ts t) bound_Ts t |
53727
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
430 |
| _ => raise Fail "expand_corec_code_rhs"); |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
431 |
|
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
432 |
fun massage_corec_code_rhs ctxt massage_ctr = |
53890 | 433 |
massage_let_if_case ctxt (K false) |
434 |
(fn bound_Ts => uncurry (massage_ctr bound_Ts) o Term.strip_comb); |
|
53865 | 435 |
|
53871 | 436 |
fun fold_rev_corec_code_rhs ctxt f = |
53909 | 437 |
snd ooo fold_rev_let_if_case ctxt (fn conds => uncurry (f conds) o Term.strip_comb); |
438 |
||
439 |
fun case_thms_of_term ctxt bound_Ts t = |
|
440 |
let |
|
441 |
val (caseT_names, _) = fold_rev_let_if_case ctxt (K (K I)) bound_Ts t (); |
|
442 |
val ctr_sugars = map (the o ctr_sugar_of ctxt) caseT_names; |
|
443 |
in |
|
53925 | 444 |
(maps #distincts ctr_sugars, maps #discIs ctr_sugars, maps #sel_splits ctr_sugars, |
445 |
maps #sel_split_asms ctr_sugars) |
|
53909 | 446 |
end; |
53731 | 447 |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
448 |
fun indexed xs h = let val h' = h + length xs in (h upto h' - 1, h') end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
449 |
fun indexedd xss = fold_map indexed xss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
450 |
fun indexeddd xsss = fold_map indexedd xsss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
451 |
fun indexedddd xssss = fold_map indexeddd xssss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
452 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
453 |
fun find_index_eq hs h = find_index (curry (op =) h) hs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
454 |
|
53476
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
455 |
(*FIXME: remove special cases for products and sum once they are registered as datatypes*) |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
456 |
fun map_thms_of_typ ctxt (Type (s, _)) = |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
457 |
if s = @{type_name prod} then |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
458 |
@{thms map_pair_simp} |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
459 |
else if s = @{type_name sum} then |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
460 |
@{thms sum_map.simps} |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
461 |
else |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
462 |
(case fp_sugar_of ctxt s of |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
463 |
SOME {index, mapss, ...} => nth mapss index |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
464 |
| NONE => []) |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
465 |
| map_thms_of_typ _ _ = []; |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
466 |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
467 |
fun rec_specs_of bs arg_Ts res_Ts get_indices callssss0 lthy = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
468 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
469 |
val thy = Proof_Context.theory_of lthy; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
470 |
|
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
471 |
val ((missing_arg_Ts, perm0_kks, |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
472 |
fp_sugars as {nested_bnfs, fp_res = {xtor_co_iterss = ctor_iters1 :: _, ...}, |
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
473 |
co_inducts = [induct_thm], ...} :: _, (lfp_sugar_thms, _)), lthy') = |
54009 | 474 |
nested_to_mutual_fps Least_FP bs arg_Ts get_indices callssss0 lthy; |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
475 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
476 |
val perm_fp_sugars = sort (int_ord o pairself #index) fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
477 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
478 |
val indices = map #index fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
479 |
val perm_indices = map #index perm_fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
480 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
481 |
val perm_ctrss = map (#ctrs o of_fp_sugar #ctr_sugars) perm_fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
482 |
val perm_ctr_Tsss = map (map (binder_types o fastype_of)) perm_ctrss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
483 |
val perm_fpTs = map (body_type o fastype_of o hd) perm_ctrss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
484 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
485 |
val nn0 = length arg_Ts; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
486 |
val nn = length perm_fpTs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
487 |
val kks = 0 upto nn - 1; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
488 |
val perm_ns = map length perm_ctr_Tsss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
489 |
val perm_mss = map (map length) perm_ctr_Tsss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
490 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
491 |
val perm_Cs = map (body_type o fastype_of o co_rec_of o of_fp_sugar (#xtor_co_iterss o #fp_res)) |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
492 |
perm_fp_sugars; |
53592
5a7bf8c859f6
made non-co case more robust as well (cf. b6e2993fd0d3)
blanchet
parents:
53591
diff
changeset
|
493 |
val perm_fun_arg_Tssss = |
5a7bf8c859f6
made non-co case more robust as well (cf. b6e2993fd0d3)
blanchet
parents:
53591
diff
changeset
|
494 |
mk_iter_fun_arg_types perm_ctr_Tsss perm_ns perm_mss (co_rec_of ctor_iters1); |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
495 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
496 |
fun unpermute0 perm0_xs = permute_like (op =) perm0_kks kks perm0_xs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
497 |
fun unpermute perm_xs = permute_like (op =) perm_indices indices perm_xs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
498 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
499 |
val induct_thms = unpermute0 (conj_dests nn induct_thm); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
500 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
501 |
val fpTs = unpermute perm_fpTs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
502 |
val Cs = unpermute perm_Cs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
503 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
504 |
val As_rho = tvar_subst thy (take nn0 fpTs) arg_Ts; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
505 |
val Cs_rho = map (fst o dest_TVar) Cs ~~ pad_list HOLogic.unitT nn res_Ts; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
506 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
507 |
val substA = Term.subst_TVars As_rho; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
508 |
val substAT = Term.typ_subst_TVars As_rho; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
509 |
val substCT = Term.typ_subst_TVars Cs_rho; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
510 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
511 |
val perm_Cs' = map substCT perm_Cs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
512 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
513 |
fun offset_of_ctr 0 _ = 0 |
53974 | 514 |
| offset_of_ctr n (({ctrs, ...} : ctr_sugar) :: ctr_sugars) = |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
515 |
length ctrs + offset_of_ctr (n - 1) ctr_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
516 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
517 |
fun call_of [i] [T] = (if exists_subtype_in Cs T then Indirect_Rec else No_Rec) i |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
518 |
| call_of [i, i'] _ = Direct_Rec (i, i'); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
519 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
520 |
fun mk_ctr_spec ctr offset fun_arg_Tss rec_thm = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
521 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
522 |
val (fun_arg_hss, _) = indexedd fun_arg_Tss 0; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
523 |
val fun_arg_hs = flat_rec_arg_args fun_arg_hss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
524 |
val fun_arg_iss = map (map (find_index_eq fun_arg_hs)) fun_arg_hss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
525 |
in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
526 |
{ctr = substA ctr, offset = offset, calls = map2 call_of fun_arg_iss fun_arg_Tss, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
527 |
rec_thm = rec_thm} |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
528 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
529 |
|
53974 | 530 |
fun mk_ctr_specs index (ctr_sugars : ctr_sugar list) iter_thmsss = |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
531 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
532 |
val ctrs = #ctrs (nth ctr_sugars index); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
533 |
val rec_thmss = co_rec_of (nth iter_thmsss index); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
534 |
val k = offset_of_ctr index ctr_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
535 |
val n = length ctrs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
536 |
in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
537 |
map4 mk_ctr_spec ctrs (k upto k + n - 1) (nth perm_fun_arg_Tssss index) rec_thmss |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
538 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
539 |
|
53974 | 540 |
fun mk_spec ({T, index, ctr_sugars, co_iterss = iterss, co_iter_thmsss = iter_thmsss, ...} |
541 |
: fp_sugar) = |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
542 |
{recx = mk_co_iter thy Least_FP (substAT T) perm_Cs' (co_rec_of (nth iterss index)), |
53329 | 543 |
nested_map_idents = map (unfold_thms lthy [id_def] o map_id0_of_bnf) nested_bnfs, |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
544 |
nested_map_comps = map map_comp_of_bnf nested_bnfs, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
545 |
ctr_specs = mk_ctr_specs index ctr_sugars iter_thmsss}; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
546 |
in |
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
547 |
((is_some lfp_sugar_thms, map mk_spec fp_sugars, missing_arg_Ts, induct_thm, induct_thms), |
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
548 |
lthy') |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
549 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
550 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
551 |
fun corec_specs_of bs arg_Ts res_Ts get_indices callssss0 lthy = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
552 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
553 |
val thy = Proof_Context.theory_of lthy; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
554 |
|
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
555 |
val ((missing_res_Ts, perm0_kks, |
53475 | 556 |
fp_sugars as {nested_bnfs, fp_res = {xtor_co_iterss = dtor_coiters1 :: _, ...}, |
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
557 |
co_inducts = coinduct_thms, ...} :: _, (_, gfp_sugar_thms)), lthy') = |
54009 | 558 |
nested_to_mutual_fps Greatest_FP bs res_Ts get_indices callssss0 lthy; |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
559 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
560 |
val perm_fp_sugars = sort (int_ord o pairself #index) fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
561 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
562 |
val indices = map #index fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
563 |
val perm_indices = map #index perm_fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
564 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
565 |
val perm_ctrss = map (#ctrs o of_fp_sugar #ctr_sugars) perm_fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
566 |
val perm_ctr_Tsss = map (map (binder_types o fastype_of)) perm_ctrss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
567 |
val perm_fpTs = map (body_type o fastype_of o hd) perm_ctrss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
568 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
569 |
val nn0 = length res_Ts; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
570 |
val nn = length perm_fpTs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
571 |
val kks = 0 upto nn - 1; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
572 |
val perm_ns = map length perm_ctr_Tsss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
573 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
574 |
val perm_Cs = map (domain_type o body_fun_type o fastype_of o co_rec_of o |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
575 |
of_fp_sugar (#xtor_co_iterss o #fp_res)) perm_fp_sugars; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
576 |
val (perm_p_Tss, (perm_q_Tssss, _, perm_f_Tssss, _)) = |
53591 | 577 |
mk_coiter_fun_arg_types perm_ctr_Tsss perm_Cs perm_ns (co_rec_of dtor_coiters1); |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
578 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
579 |
val (perm_p_hss, h) = indexedd perm_p_Tss 0; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
580 |
val (perm_q_hssss, h') = indexedddd perm_q_Tssss h; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
581 |
val (perm_f_hssss, _) = indexedddd perm_f_Tssss h'; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
582 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
583 |
val fun_arg_hs = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
584 |
flat (map3 flat_corec_preds_predsss_gettersss perm_p_hss perm_q_hssss perm_f_hssss); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
585 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
586 |
fun unpermute0 perm0_xs = permute_like (op =) perm0_kks kks perm0_xs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
587 |
fun unpermute perm_xs = permute_like (op =) perm_indices indices perm_xs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
588 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
589 |
val coinduct_thmss = map (unpermute0 o conj_dests nn) coinduct_thms; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
590 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
591 |
val p_iss = map (map (find_index_eq fun_arg_hs)) (unpermute perm_p_hss); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
592 |
val q_issss = map (map (map (map (find_index_eq fun_arg_hs)))) (unpermute perm_q_hssss); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
593 |
val f_issss = map (map (map (map (find_index_eq fun_arg_hs)))) (unpermute perm_f_hssss); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
594 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
595 |
val f_Tssss = unpermute perm_f_Tssss; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
596 |
val fpTs = unpermute perm_fpTs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
597 |
val Cs = unpermute perm_Cs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
598 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
599 |
val As_rho = tvar_subst thy (take nn0 fpTs) res_Ts; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
600 |
val Cs_rho = map (fst o dest_TVar) Cs ~~ pad_list HOLogic.unitT nn arg_Ts; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
601 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
602 |
val substA = Term.subst_TVars As_rho; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
603 |
val substAT = Term.typ_subst_TVars As_rho; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
604 |
val substCT = Term.typ_subst_TVars Cs_rho; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
605 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
606 |
val perm_Cs' = map substCT perm_Cs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
607 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
608 |
fun call_of nullary [] [g_i] [Type (@{type_name fun}, [_, T])] = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
609 |
(if exists_subtype_in Cs T then Indirect_Corec |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
610 |
else if nullary then Dummy_No_Corec |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
611 |
else No_Corec) g_i |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
612 |
| call_of _ [q_i] [g_i, g_i'] _ = Direct_Corec (q_i, g_i, g_i'); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
613 |
|
53705 | 614 |
fun mk_ctr_spec ctr disc sels p_ho q_iss f_iss f_Tss discI sel_thms collapse corec_thm |
615 |
disc_corec sel_corecs = |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
616 |
let val nullary = not (can dest_funT (fastype_of ctr)) in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
617 |
{ctr = substA ctr, disc = substA disc, sels = map substA sels, pred = p_ho, |
53705 | 618 |
calls = map3 (call_of nullary) q_iss f_iss f_Tss, discI = discI, sel_thms = sel_thms, |
619 |
collapse = collapse, corec_thm = corec_thm, disc_corec = disc_corec, |
|
620 |
sel_corecs = sel_corecs} |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
621 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
622 |
|
53974 | 623 |
fun mk_ctr_specs index (ctr_sugars : ctr_sugar list) p_is q_isss f_isss f_Tsss |
624 |
coiter_thmsss disc_coitersss sel_coiterssss = |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
625 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
626 |
val ctrs = #ctrs (nth ctr_sugars index); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
627 |
val discs = #discs (nth ctr_sugars index); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
628 |
val selss = #selss (nth ctr_sugars index); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
629 |
val p_ios = map SOME p_is @ [NONE]; |
53705 | 630 |
val discIs = #discIs (nth ctr_sugars index); |
631 |
val sel_thmss = #sel_thmss (nth ctr_sugars index); |
|
53475 | 632 |
val collapses = #collapses (nth ctr_sugars index); |
633 |
val corec_thms = co_rec_of (nth coiter_thmsss index); |
|
53741
c9068aade859
killed exceptional code that is anyway no longer needed, now that the 'simp' attribute has been taken away -- this solves issues in 'primcorec'
blanchet
parents:
53734
diff
changeset
|
634 |
val disc_corecs = co_rec_of (nth disc_coitersss index); |
53475 | 635 |
val sel_corecss = co_rec_of (nth sel_coiterssss index); |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
636 |
in |
53705 | 637 |
map13 mk_ctr_spec ctrs discs selss p_ios q_isss f_isss f_Tsss discIs sel_thmss collapses |
638 |
corec_thms disc_corecs sel_corecss |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
639 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
640 |
|
53974 | 641 |
fun mk_spec ({T, index, ctr_sugars, co_iterss = coiterss, co_iter_thmsss = coiter_thmsss, |
642 |
disc_co_itersss = disc_coitersss, sel_co_iterssss = sel_coiterssss, ...} : fp_sugar) |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
643 |
p_is q_isss f_isss f_Tsss = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
644 |
{corec = mk_co_iter thy Greatest_FP (substAT T) perm_Cs' (co_rec_of (nth coiterss index)), |
53476
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
645 |
nested_maps = maps (map_thms_of_typ lthy o T_of_bnf) nested_bnfs, |
53475 | 646 |
nested_map_idents = map (unfold_thms lthy [id_def] o map_id0_of_bnf) nested_bnfs, |
647 |
nested_map_comps = map map_comp_of_bnf nested_bnfs, |
|
648 |
ctr_specs = mk_ctr_specs index ctr_sugars p_is q_isss f_isss f_Tsss coiter_thmsss |
|
649 |
disc_coitersss sel_coiterssss}; |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
650 |
in |
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
651 |
((is_some gfp_sugar_thms, map5 mk_spec fp_sugars p_iss q_issss f_issss f_Tssss, missing_res_Ts, |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
652 |
co_induct_of coinduct_thms, strong_co_induct_of coinduct_thms, co_induct_of coinduct_thmss, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
653 |
strong_co_induct_of coinduct_thmss), lthy') |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
654 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
655 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
656 |
end; |