equal
deleted
inserted
replaced
6 *) |
6 *) |
7 |
7 |
8 theory Basic_BNF_Least_Fixpoints |
8 theory Basic_BNF_Least_Fixpoints |
9 imports BNF_Least_Fixpoint |
9 imports BNF_Least_Fixpoint |
10 begin |
10 begin |
11 |
|
12 subsection {* Size setup (TODO: Merge with rest of file) *} |
|
13 |
|
14 lemma size_bool[code]: "size (b\<Colon>bool) = 0" |
|
15 by (cases b) auto |
|
16 |
|
17 lemma size_nat[simp, code]: "size (n\<Colon>nat) = n" |
|
18 by (induct n) simp_all |
|
19 |
|
20 declare prod.size[no_atp] |
|
21 |
|
22 lemma size_sum_o_map: "size_sum g1 g2 \<circ> map_sum f1 f2 = size_sum (g1 \<circ> f1) (g2 \<circ> f2)" |
|
23 by (rule ext) (case_tac x, auto) |
|
24 |
|
25 lemma size_prod_o_map: "size_prod g1 g2 \<circ> map_prod f1 f2 = size_prod (g1 \<circ> f1) (g2 \<circ> f2)" |
|
26 by (rule ext) auto |
|
27 |
|
28 setup {* |
|
29 BNF_LFP_Size.register_size_global @{type_name sum} @{const_name size_sum} @{thms sum.size} |
|
30 @{thms size_sum_o_map} |
|
31 #> BNF_LFP_Size.register_size_global @{type_name prod} @{const_name size_prod} @{thms prod.size} |
|
32 @{thms size_prod_o_map} |
|
33 *} |
|
34 |
|
35 |
|
36 subsection {* FP sugar setup *} |
|
37 |
11 |
38 definition xtor :: "'a \<Rightarrow> 'a" where |
12 definition xtor :: "'a \<Rightarrow> 'a" where |
39 "xtor x = x" |
13 "xtor x = x" |
40 |
14 |
41 lemma xtor_map: "f (xtor x) = xtor (f x)" |
15 lemma xtor_map: "f (xtor x) = xtor (f x)" |
53 lemma xtor_xtor: "xtor (xtor x) = x" |
27 lemma xtor_xtor: "xtor (xtor x) = x" |
54 unfolding xtor_def by (rule refl) |
28 unfolding xtor_def by (rule refl) |
55 |
29 |
56 lemmas xtor_inject = xtor_rel[of "op ="] |
30 lemmas xtor_inject = xtor_rel[of "op ="] |
57 |
31 |
58 definition ctor_rec :: "'a \<Rightarrow> 'a" where |
|
59 "ctor_rec x = x" |
|
60 |
|
61 lemma ctor_rec: "g = id \<Longrightarrow> ctor_rec f (xtor x) = f ((id_bnf \<circ> g \<circ> id_bnf) x)" |
|
62 unfolding ctor_rec_def id_bnf_def xtor_def comp_def id_def by hypsubst (rule refl) |
|
63 |
|
64 lemma ctor_rec_o_map: "ctor_rec f \<circ> g = ctor_rec (f \<circ> (id_bnf \<circ> g \<circ> id_bnf))" |
|
65 unfolding ctor_rec_def id_bnf_def comp_def by (rule refl) |
|
66 |
|
67 lemma xtor_rel_induct: "(\<And>x y. vimage2p id_bnf id_bnf R x y \<Longrightarrow> IR (xtor x) (xtor y)) \<Longrightarrow> R \<le> IR" |
32 lemma xtor_rel_induct: "(\<And>x y. vimage2p id_bnf id_bnf R x y \<Longrightarrow> IR (xtor x) (xtor y)) \<Longrightarrow> R \<le> IR" |
68 unfolding xtor_def vimage2p_def id_bnf_def by default |
33 unfolding xtor_def vimage2p_def id_bnf_def by default |
69 |
34 |
70 lemma Inl_def_alt: "Inl \<equiv> (\<lambda>a. xtor (id_bnf (Inl a)))" |
35 lemma Inl_def_alt: "Inl \<equiv> (\<lambda>a. xtor (id_bnf (Inl a)))" |
71 unfolding xtor_def id_bnf_def by (rule reflexive) |
36 unfolding xtor_def id_bnf_def by (rule reflexive) |
74 unfolding xtor_def id_bnf_def by (rule reflexive) |
39 unfolding xtor_def id_bnf_def by (rule reflexive) |
75 |
40 |
76 lemma Pair_def_alt: "Pair \<equiv> (\<lambda>a b. xtor (id_bnf (a, b)))" |
41 lemma Pair_def_alt: "Pair \<equiv> (\<lambda>a b. xtor (id_bnf (a, b)))" |
77 unfolding xtor_def id_bnf_def by (rule reflexive) |
42 unfolding xtor_def id_bnf_def by (rule reflexive) |
78 |
43 |
|
44 definition ctor_rec :: "'a \<Rightarrow> 'a" where |
|
45 "ctor_rec x = x" |
|
46 |
|
47 lemma ctor_rec: "g = id \<Longrightarrow> ctor_rec f (xtor x) = f ((id_bnf \<circ> g \<circ> id_bnf) x)" |
|
48 unfolding ctor_rec_def id_bnf_def xtor_def comp_def id_def by hypsubst (rule refl) |
|
49 |
|
50 lemma ctor_rec_def_alt: "f = ctor_rec (f \<circ> id_bnf)" |
|
51 unfolding ctor_rec_def id_bnf_def comp_def by (rule refl) |
|
52 |
|
53 lemma ctor_rec_o_map: "ctor_rec f \<circ> g = ctor_rec (f \<circ> (id_bnf \<circ> g \<circ> id_bnf))" |
|
54 unfolding ctor_rec_def id_bnf_def comp_def by (rule refl) |
|
55 |
79 ML_file "Tools/BNF/bnf_lfp_basic_sugar.ML" |
56 ML_file "Tools/BNF/bnf_lfp_basic_sugar.ML" |
|
57 |
|
58 thm sum.rec_o_map |
|
59 thm sum.size_o_map |
|
60 |
|
61 thm prod.rec_o_map |
|
62 thm prod.size_o_map |
80 |
63 |
81 hide_const (open) xtor ctor_rec |
64 hide_const (open) xtor ctor_rec |
82 |
65 |
83 hide_fact (open) |
66 hide_fact (open) |
84 xtor_def xtor_map xtor_set xtor_rel xtor_induct xtor_xtor xtor_inject ctor_rec_def ctor_rec |
67 xtor_def xtor_map xtor_set xtor_rel xtor_induct xtor_xtor xtor_inject ctor_rec_def ctor_rec |
85 ctor_rec_o_map xtor_rel_induct Inl_def_alt Inr_def_alt Pair_def_alt |
68 ctor_rec_def_alt ctor_rec_o_map xtor_rel_induct Inl_def_alt Inr_def_alt Pair_def_alt |
86 |
69 |
87 end |
70 end |