author | blanchet |
Fri, 20 Sep 2013 11:44:30 +0200 | |
changeset 53746 | bd038e48526d |
parent 53741 | c9068aade859 |
child 53832 | bde758ba3029 |
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 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
54 |
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
|
55 |
typ list -> term -> term -> term -> term |
53725 | 56 |
val massage_direct_corec_call: Proof.context -> (term -> bool) -> (term -> term) -> typ -> term -> |
57 |
term |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
58 |
val massage_indirect_corec_call: Proof.context -> (term -> bool) -> |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
59 |
(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
|
60 |
val expand_corec_code_rhs: Proof.context -> (term -> bool) -> typ list -> term -> term |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
61 |
val massage_corec_code_rhs: Proof.context -> (term -> term list -> term) -> typ -> term -> term |
53731 | 62 |
val fold_rev_corec_code_rhs: (term -> term list -> 'a -> 'a) -> term -> 'a -> 'a |
53729
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
63 |
val simplify_bool_ifs: theory -> term -> term list |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
64 |
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
|
65 |
((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
|
66 |
(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
|
67 |
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
|
68 |
((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
|
69 |
(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
|
70 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
71 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
72 |
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
|
73 |
struct |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
74 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
75 |
open BNF_Util |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
76 |
open BNF_Def |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
77 |
open BNF_Ctr_Sugar |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
78 |
open BNF_FP_Util |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
82 |
datatype rec_call = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
83 |
No_Rec of int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
84 |
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
|
85 |
Indirect_Rec of int; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
86 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
87 |
datatype corec_call = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
88 |
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
|
89 |
No_Corec of int | |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
90 |
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
|
91 |
Indirect_Corec of int; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
92 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
93 |
type rec_ctr_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
94 |
{ctr: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
95 |
offset: int, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
96 |
calls: rec_call list, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
97 |
rec_thm: thm}; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
98 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
99 |
type corec_ctr_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
100 |
{ctr: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
101 |
disc: term, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
102 |
sels: term list, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
103 |
pred: int option, |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
104 |
calls: corec_call list, |
53705 | 105 |
discI: thm, |
106 |
sel_thms: thm list, |
|
53475 | 107 |
collapse: thm, |
108 |
corec_thm: thm, |
|
109 |
disc_corec: thm, |
|
110 |
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
|
111 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
112 |
type rec_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
113 |
{recx: term, |
53329 | 114 |
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
|
115 |
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
|
116 |
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
|
117 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
118 |
type corec_spec = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
119 |
{corec: term, |
53475 | 120 |
nested_maps: thm list, |
121 |
nested_map_idents: thm list, |
|
122 |
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
|
123 |
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
|
124 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
125 |
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
|
126 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
127 |
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
|
128 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
140 |
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
|
141 |
(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
|
142 |
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
|
143 |
| NONE => invalid_map ctxt); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
144 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
145 |
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
|
146 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
147 |
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
|
148 |
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
|
149 |
in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
150 |
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
|
151 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
152 |
|
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
153 |
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
|
154 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
155 |
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
|
156 |
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
|
157 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
158 |
val yT = typof y; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
159 |
val yU = typof y'; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
160 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
161 |
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
|
162 |
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
|
163 |
|
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
164 |
fun massage_direct_fun U T t = |
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
165 |
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
|
166 |
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
|
167 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
168 |
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
|
169 |
(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
|
170 |
SOME (map0, fs) => |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
171 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
176 |
list_comb (map', fs') |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
177 |
end |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
178 |
| 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
|
179 |
| 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
|
180 |
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
|
181 |
if T = U then |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
182 |
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
|
183 |
else |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
184 |
massage_map U T t |
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
185 |
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
|
186 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
187 |
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
|
188 |
if t2 = y then |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
189 |
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
|
190 |
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
|
191 |
else |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
192 |
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
|
193 |
| 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
|
194 |
in |
53724 | 195 |
massage_call |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
196 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
197 |
|
53726
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
198 |
fun massage_let_and_if ctxt has_call massage_leaf U = |
53723 | 199 |
let |
53726
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
200 |
val check_cond = ((not o has_call) orf unexpected_corec_call ctxt); |
53725 | 201 |
fun massage_rec t = |
53723 | 202 |
(case Term.strip_comb t of |
53725 | 203 |
(Const (@{const_name Let}, _), [arg1, arg2]) => massage_rec (betapply (arg2, arg1)) |
53723 | 204 |
| (Const (@{const_name If}, _), arg :: args) => |
53725 | 205 |
list_comb (If_const U $ tap check_cond arg, map massage_rec args) |
206 |
| _ => massage_leaf t) |
|
53723 | 207 |
in |
208 |
massage_rec |
|
209 |
end; |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
210 |
|
53731 | 211 |
fun fold_rev_let_and_if f = |
212 |
let |
|
213 |
fun fld t = |
|
214 |
(case Term.strip_comb t of |
|
215 |
(Const (@{const_name Let}, _), [arg1, arg2]) => fld (betapply (arg2, arg1)) |
|
216 |
| (Const (@{const_name If}, _), _ :: args) => fold_rev fld args |
|
217 |
| _ => f t) |
|
218 |
in |
|
219 |
fld |
|
220 |
end; |
|
221 |
||
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
222 |
fun massage_direct_corec_call ctxt has_call raw_massage_call U t = |
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
223 |
massage_let_and_if ctxt has_call raw_massage_call U t; |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
224 |
|
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
225 |
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
|
226 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
227 |
val typof = curry fastype_of1 bound_Ts; |
53411 | 228 |
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
|
229 |
|
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
230 |
fun massage_direct_call U T t = |
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
231 |
if has_call t then factor_out_types ctxt raw_massage_call dest_sumT U T t |
53411 | 232 |
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
|
233 |
|
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
234 |
fun 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
|
235 |
let val var = Var ((Name.uu, Term.maxidx_of_term t + 1), domain_type (typof t)) in |
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
236 |
Term.lambda var (massage_direct_call 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
|
237 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
238 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
239 |
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
|
240 |
(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
|
241 |
SOME (map0, fs) => |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
242 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
243 |
val Type (_, dom_Ts) = domain_type (typof t); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
244 |
val map' = mk_map (length fs) dom_Ts Us map0; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
245 |
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
|
246 |
in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
247 |
list_comb (map', fs') |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
248 |
end |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
249 |
| 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
|
250 |
| 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
|
251 |
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
|
252 |
if T = U then |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
253 |
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
|
254 |
else |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
255 |
massage_map U T t |
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
256 |
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
|
257 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
258 |
fun massage_call U T = |
53726
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
259 |
massage_let_and_if ctxt has_call (fn t => |
53732
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
260 |
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
|
261 |
(case U of |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
262 |
Type (s, Us) => |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
263 |
(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
|
264 |
SOME (f, args) => |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
265 |
let val f' = mk_ctr Us f in |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
266 |
list_comb (f', map3 massage_call (binder_types (typof f')) (map typof args) args) |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
267 |
end |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
268 |
| NONE => |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
269 |
(case t of |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
270 |
t1 $ t2 => |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
271 |
(if has_call t2 then |
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
272 |
massage_direct_call 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
|
273 |
else |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
274 |
massage_map U T t1 $ t2 |
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
275 |
handle AINT_NO_MAP _ => massage_direct_call 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
|
276 |
| Abs (s, T', t') => Abs (s, T', massage_call (range_type U) (range_type T) t') |
53734
7613573f023a
avoid infinite loop for unapplied terms + tuning
blanchet
parents:
53732
diff
changeset
|
277 |
| _ => massage_direct_call 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
|
278 |
| _ => 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
|
279 |
else |
e2c0d0426d2b
give lambda abstractions a chance, as an alternative to function composition, for corecursion via "fun"
blanchet
parents:
53731
diff
changeset
|
280 |
build_map_Inl (T, U) $ t) U |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
281 |
in |
53725 | 282 |
massage_call U (typof t) t |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
283 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
284 |
|
53727
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
285 |
fun expand_ctr_term ctxt s Ts t = |
53726
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
286 |
(case fp_sugar_of ctxt s of |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
287 |
SOME fp_sugar => |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
288 |
let |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
289 |
val T = Type (s, Ts); |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
290 |
val x = Bound 0; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
291 |
val {ctrs = ctrs0, discs = discs0, selss = selss0, ...} = of_fp_sugar #ctr_sugars fp_sugar; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
292 |
val ctrs = map (mk_ctr Ts) ctrs0; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
293 |
val discs = map (mk_disc_or_sel Ts) discs0; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
294 |
val selss = map (map (mk_disc_or_sel Ts)) selss0; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
295 |
val xdiscs = map (rapp x) discs; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
296 |
val xselss = map (map (rapp x)) selss; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
297 |
val xsel_ctrs = map2 (curry Term.list_comb) ctrs xselss; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
298 |
val xif = mk_IfN T xdiscs xsel_ctrs; |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
299 |
in |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
300 |
Const (@{const_name Let}, T --> (T --> T) --> T) $ t $ Abs (Name.uu, T, xif) |
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
301 |
end |
53727
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
302 |
| NONE => raise Fail "expand_ctr_term"); |
53726
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
303 |
|
53727
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
304 |
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
|
305 |
(case fastype_of1 (bound_Ts, t) of |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
306 |
T as Type (s, Ts) => |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
307 |
massage_let_and_if ctxt has_call (fn t => |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
308 |
if can (dest_ctr ctxt s) t then t |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
309 |
else massage_let_and_if ctxt has_call I T (expand_ctr_term ctxt s Ts t)) T t |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
310 |
| _ => raise Fail "expand_corec_code_rhs"); |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
311 |
|
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
312 |
fun massage_corec_code_rhs ctxt massage_ctr = |
1d88a7ee4e3e
split functionality into two functions to avoid redoing work over and over
blanchet
parents:
53726
diff
changeset
|
313 |
massage_let_and_if ctxt (K false) (uncurry massage_ctr o Term.strip_comb); |
53726
d41a30db83d9
added massaging function for primcorec code equations
blanchet
parents:
53725
diff
changeset
|
314 |
|
53731 | 315 |
fun fold_rev_corec_code_rhs f = fold_rev_let_and_if (uncurry f o Term.strip_comb); |
316 |
||
53729
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
317 |
fun add_conjuncts (Const (@{const_name conj}, _) $ t $ t') = add_conjuncts t o add_conjuncts t' |
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
318 |
| add_conjuncts t = cons t; |
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
319 |
|
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
320 |
fun conjuncts t = add_conjuncts t []; |
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
321 |
|
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
322 |
fun simplify_bool_ifs thy = |
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
323 |
Raw_Simplifier.rewrite_term thy @{thms bool_if_simps[THEN eq_reflection]} [] |
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
324 |
#> conjuncts #> (fn [@{term True}] => [] | ts => ts); |
b9d727a767ea
added helper function for code equations in primcorec
blanchet
parents:
53727
diff
changeset
|
325 |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
331 |
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
|
332 |
|
53476
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
333 |
(*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
|
334 |
fun map_thms_of_typ ctxt (Type (s, _)) = |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
335 |
if s = @{type_name prod} then |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
336 |
@{thms map_pair_simp} |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
337 |
else if s = @{type_name sum} then |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
338 |
@{thms sum_map.simps} |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
339 |
else |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
340 |
(case fp_sugar_of ctxt s of |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
341 |
SOME {index, mapss, ...} => nth mapss index |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
342 |
| NONE => []) |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
343 |
| map_thms_of_typ _ _ = []; |
eb3865c3ee58
include map theorems in datastructure for "primcorec"
blanchet
parents:
53475
diff
changeset
|
344 |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
345 |
val lose_co_rec = false (*FIXME: try true?*); |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
346 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
347 |
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
|
348 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
349 |
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
|
350 |
|
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
351 |
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
|
352 |
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
|
353 |
co_inducts = [induct_thm], ...} :: _, (lfp_sugar_thms, _)), lthy') = |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
354 |
nested_to_mutual_fps lose_co_rec Least_FP bs arg_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
|
355 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
356 |
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
|
357 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
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
|
370 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
371 |
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
|
372 |
perm_fp_sugars; |
53592
5a7bf8c859f6
made non-co case more robust as well (cf. b6e2993fd0d3)
blanchet
parents:
53591
diff
changeset
|
373 |
val perm_fun_arg_Tssss = |
5a7bf8c859f6
made non-co case more robust as well (cf. b6e2993fd0d3)
blanchet
parents:
53591
diff
changeset
|
374 |
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
|
375 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
376 |
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
|
377 |
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
|
378 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
379 |
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
|
380 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
381 |
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
|
382 |
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
|
383 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
384 |
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
|
385 |
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
|
386 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
387 |
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
|
388 |
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
|
389 |
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
|
390 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
391 |
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
|
392 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
393 |
fun offset_of_ctr 0 _ = 0 |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
394 |
| offset_of_ctr n ({ctrs, ...} :: ctr_sugars) = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
395 |
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
|
396 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
397 |
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
|
398 |
| 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
|
399 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
400 |
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
|
401 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
406 |
{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
|
407 |
rec_thm = rec_thm} |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
408 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
409 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
410 |
fun 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
|
411 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
412 |
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
|
413 |
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
|
414 |
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
|
415 |
val n = length ctrs; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
416 |
in |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
417 |
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
|
418 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
419 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
420 |
fun mk_spec {T, index, ctr_sugars, co_iterss = iterss, co_iter_thmsss = iter_thmsss, ...} = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
421 |
{recx = mk_co_iter thy Least_FP (substAT T) perm_Cs' (co_rec_of (nth iterss index)), |
53329 | 422 |
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
|
423 |
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
|
424 |
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
|
425 |
in |
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
426 |
((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
|
427 |
lthy') |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
428 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
429 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
430 |
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
|
431 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
432 |
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
|
433 |
|
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
434 |
val ((missing_res_Ts, perm0_kks, |
53475 | 435 |
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
|
436 |
co_inducts = coinduct_thms, ...} :: _, (_, gfp_sugar_thms)), lthy') = |
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
437 |
nested_to_mutual_fps lose_co_rec Greatest_FP bs 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
|
438 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
439 |
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
|
440 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
441 |
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
|
442 |
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
|
443 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
448 |
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
|
449 |
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
|
450 |
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
|
451 |
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
|
452 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
453 |
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
|
454 |
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
|
455 |
val (perm_p_Tss, (perm_q_Tssss, _, perm_f_Tssss, _)) = |
53591 | 456 |
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
|
457 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
458 |
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
|
459 |
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
|
460 |
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
|
461 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
462 |
val fun_arg_hs = |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
463 |
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
|
464 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
465 |
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
|
466 |
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
|
467 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
468 |
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
|
469 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
470 |
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
|
471 |
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
|
472 |
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
|
473 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
474 |
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
|
475 |
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
|
476 |
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
|
477 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
478 |
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
|
479 |
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
|
480 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
485 |
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
|
486 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
487 |
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
|
488 |
(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
|
489 |
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
|
490 |
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
|
491 |
| 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
|
492 |
|
53705 | 493 |
fun mk_ctr_spec ctr disc sels p_ho q_iss f_iss f_Tss discI sel_thms collapse corec_thm |
494 |
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
|
495 |
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
|
496 |
{ctr = substA ctr, disc = substA disc, sels = map substA sels, pred = p_ho, |
53705 | 497 |
calls = map3 (call_of nullary) q_iss f_iss f_Tss, discI = discI, sel_thms = sel_thms, |
498 |
collapse = collapse, corec_thm = corec_thm, disc_corec = disc_corec, |
|
499 |
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
|
500 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
501 |
|
53475 | 502 |
fun mk_ctr_specs index ctr_sugars p_is q_isss f_isss f_Tsss coiter_thmsss disc_coitersss |
503 |
sel_coiterssss = |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
504 |
let |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
505 |
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
|
506 |
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
|
507 |
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
|
508 |
val p_ios = map SOME p_is @ [NONE]; |
53705 | 509 |
val discIs = #discIs (nth ctr_sugars index); |
510 |
val sel_thmss = #sel_thmss (nth ctr_sugars index); |
|
53475 | 511 |
val collapses = #collapses (nth ctr_sugars index); |
512 |
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
|
513 |
val disc_corecs = co_rec_of (nth disc_coitersss index); |
53475 | 514 |
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
|
515 |
in |
53705 | 516 |
map13 mk_ctr_spec ctrs discs selss p_ios q_isss f_isss f_Tsss discIs sel_thmss collapses |
517 |
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
|
518 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
519 |
|
53475 | 520 |
fun mk_spec {T, index, ctr_sugars, co_iterss = coiterss, co_iter_thmsss = coiter_thmsss, |
521 |
disc_co_itersss = disc_coitersss, sel_co_iterssss = sel_coiterssss, ...} |
|
53303
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
522 |
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
|
523 |
{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
|
524 |
nested_maps = maps (map_thms_of_typ lthy o T_of_bnf) nested_bnfs, |
53475 | 525 |
nested_map_idents = map (unfold_thms lthy [id_def] o map_id0_of_bnf) nested_bnfs, |
526 |
nested_map_comps = map map_comp_of_bnf nested_bnfs, |
|
527 |
ctr_specs = mk_ctr_specs index ctr_sugars p_is q_isss f_isss f_Tsss coiter_thmsss |
|
528 |
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
|
529 |
in |
53746
bd038e48526d
have "datatype_new_compat" register induction and recursion theorems in nested case
blanchet
parents:
53741
diff
changeset
|
530 |
((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
|
531 |
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
|
532 |
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
|
533 |
end; |
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
534 |
|
ae49b835ca01
moved files related to "primrec_new", "primcorec", and "datatype_compat" from bitbucket co-rec repository
blanchet
parents:
diff
changeset
|
535 |
end; |