src/HOL/Basic_BNFs.thy
author traytel
Tue, 16 Feb 2016 22:28:19 +0100
changeset 62324 ae44f16dcea5
parent 61681 ca53150406c9
child 62335 e85c42f4f30a
permissions -rw-r--r--
make predicator a first-class bnf citizen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55075
b3d0a02a756d dissolved BNF session
blanchet
parents: 55062
diff changeset
     1
(*  Title:      HOL/Basic_BNFs.thy
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     3
    Author:     Andrei Popescu, TU Muenchen
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     4
    Author:     Jasmin Blanchette, TU Muenchen
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     5
    Copyright   2012
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     6
49309
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49236
diff changeset
     7
Registration of basic types as bounded natural functors.
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     8
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     9
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 58916
diff changeset
    10
section \<open>Registration of Basic Types as Bounded Natural Functors\<close>
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    11
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    12
theory Basic_BNFs
49310
6e30078de4f0 renamed "Ordinals_and_Cardinals" to "Cardinals"
blanchet
parents: 49309
diff changeset
    13
imports BNF_Def
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    14
begin
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    15
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    16
inductive_set setl :: "'a + 'b \<Rightarrow> 'a set" for s :: "'a + 'b" where
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    17
  "s = Inl x \<Longrightarrow> x \<in> setl s"
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    18
inductive_set setr :: "'a + 'b \<Rightarrow> 'b set" for s :: "'a + 'b" where
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    19
  "s = Inr x \<Longrightarrow> x \<in> setr s"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    20
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    21
lemma sum_set_defs[code]:
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    22
  "setl = (\<lambda>x. case x of Inl z => {z} | _ => {})"
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    23
  "setr = (\<lambda>x. case x of Inr z => {z} | _ => {})"
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    24
  by (auto simp: fun_eq_iff intro: setl.intros setr.intros elim: setl.cases setr.cases split: sum.splits)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    25
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    26
lemma rel_sum_simps[code, simp]:
55943
5c2df04e97d1 renamed 'sum_rel' to 'rel_sum'
blanchet
parents: 55935
diff changeset
    27
  "rel_sum R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
5c2df04e97d1 renamed 'sum_rel' to 'rel_sum'
blanchet
parents: 55935
diff changeset
    28
  "rel_sum R1 R2 (Inl a1) (Inr b2) = False"
5c2df04e97d1 renamed 'sum_rel' to 'rel_sum'
blanchet
parents: 55935
diff changeset
    29
  "rel_sum R1 R2 (Inr a2) (Inl b1) = False"
5c2df04e97d1 renamed 'sum_rel' to 'rel_sum'
blanchet
parents: 55935
diff changeset
    30
  "rel_sum R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    31
  by (auto intro: rel_sum.intros elim: rel_sum.cases)
55083
0a689157e3ce move BNF_LFP up the dependency chain
blanchet
parents: 55075
diff changeset
    32
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    33
inductive
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    34
   pred_sum :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> bool" for P1 P2
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    35
where
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    36
  "P1 a \<Longrightarrow> pred_sum P1 P2 (Inl a)"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    37
| "P2 b \<Longrightarrow> pred_sum P1 P2 (Inr b)"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    38
54421
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
    39
bnf "'a + 'b"
55931
62156e694f3d renamed 'map_sum' to 'sum_map'
blanchet
parents: 55811
diff changeset
    40
  map: map_sum
54421
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
    41
  sets: setl setr
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
    42
  bd: natLeq
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
    43
  wits: Inl Inr
55943
5c2df04e97d1 renamed 'sum_rel' to 'rel_sum'
blanchet
parents: 55935
diff changeset
    44
  rel: rel_sum
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    45
  pred: pred_sum
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    46
proof -
55931
62156e694f3d renamed 'map_sum' to 'sum_map'
blanchet
parents: 55811
diff changeset
    47
  show "map_sum id id = id" by (rule map_sum.id)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    48
next
54486
d8d276c922f2 tuned proofs
blanchet
parents: 54485
diff changeset
    49
  fix f1 :: "'o \<Rightarrow> 's" and f2 :: "'p \<Rightarrow> 't" and g1 :: "'s \<Rightarrow> 'q" and g2 :: "'t \<Rightarrow> 'r"
55931
62156e694f3d renamed 'map_sum' to 'sum_map'
blanchet
parents: 55811
diff changeset
    50
  show "map_sum (g1 o f1) (g2 o f2) = map_sum g1 g2 o map_sum f1 f2"
62156e694f3d renamed 'map_sum' to 'sum_map'
blanchet
parents: 55811
diff changeset
    51
    by (rule map_sum.comp[symmetric])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    52
next
54486
d8d276c922f2 tuned proofs
blanchet
parents: 54485
diff changeset
    53
  fix x and f1 :: "'o \<Rightarrow> 'q" and f2 :: "'p \<Rightarrow> 'r" and g1 g2
49451
7a28d22c33c6 renamed "sum_setl" to "setl" and similarly for r
blanchet
parents: 49450
diff changeset
    54
  assume a1: "\<And>z. z \<in> setl x \<Longrightarrow> f1 z = g1 z" and
7a28d22c33c6 renamed "sum_setl" to "setl" and similarly for r
blanchet
parents: 49450
diff changeset
    55
         a2: "\<And>z. z \<in> setr x \<Longrightarrow> f2 z = g2 z"
55931
62156e694f3d renamed 'map_sum' to 'sum_map'
blanchet
parents: 55811
diff changeset
    56
  thus "map_sum f1 f2 x = map_sum g1 g2 x"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    57
  proof (cases x)
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    58
    case Inl thus ?thesis using a1 by (clarsimp simp: sum_set_defs(1))
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    59
  next
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    60
    case Inr thus ?thesis using a2 by (clarsimp simp: sum_set_defs(2))
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    61
  qed
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    62
next
54486
d8d276c922f2 tuned proofs
blanchet
parents: 54485
diff changeset
    63
  fix f1 :: "'o \<Rightarrow> 'q" and f2 :: "'p \<Rightarrow> 'r"
55931
62156e694f3d renamed 'map_sum' to 'sum_map'
blanchet
parents: 55811
diff changeset
    64
  show "setl o map_sum f1 f2 = image f1 o setl"
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    65
    by (rule ext, unfold o_apply) (simp add: sum_set_defs(1) split: sum.split)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    66
next
54486
d8d276c922f2 tuned proofs
blanchet
parents: 54485
diff changeset
    67
  fix f1 :: "'o \<Rightarrow> 'q" and f2 :: "'p \<Rightarrow> 'r"
55931
62156e694f3d renamed 'map_sum' to 'sum_map'
blanchet
parents: 55811
diff changeset
    68
  show "setr o map_sum f1 f2 = image f2 o setr"
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    69
    by (rule ext, unfold o_apply) (simp add: sum_set_defs(2) split: sum.split)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    70
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    71
  show "card_order natLeq" by (rule natLeq_card_order)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    72
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    73
  show "cinfinite natLeq" by (rule natLeq_cinfinite)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    74
next
54486
d8d276c922f2 tuned proofs
blanchet
parents: 54485
diff changeset
    75
  fix x :: "'o + 'p"
49451
7a28d22c33c6 renamed "sum_setl" to "setl" and similarly for r
blanchet
parents: 49450
diff changeset
    76
  show "|setl x| \<le>o natLeq"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    77
    apply (rule ordLess_imp_ordLeq)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    78
    apply (rule finite_iff_ordLess_natLeq[THEN iffD1])
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    79
    by (simp add: sum_set_defs(1) split: sum.split)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    80
next
54486
d8d276c922f2 tuned proofs
blanchet
parents: 54485
diff changeset
    81
  fix x :: "'o + 'p"
49451
7a28d22c33c6 renamed "sum_setl" to "setl" and similarly for r
blanchet
parents: 49450
diff changeset
    82
  show "|setr x| \<le>o natLeq"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    83
    apply (rule ordLess_imp_ordLeq)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    84
    apply (rule finite_iff_ordLess_natLeq[THEN iffD1])
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    85
    by (simp add: sum_set_defs(2) split: sum.split)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    86
next
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54581
diff changeset
    87
  fix R1 R2 S1 S2
55943
5c2df04e97d1 renamed 'sum_rel' to 'rel_sum'
blanchet
parents: 55935
diff changeset
    88
  show "rel_sum R1 R2 OO rel_sum S1 S2 \<le> rel_sum (R1 OO S1) (R2 OO S2)"
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    89
    by (force elim: rel_sum.cases)
49453
ff0e540d8758 add rel as first-class citizen of BNF
blanchet
parents: 49451
diff changeset
    90
next
ff0e540d8758 add rel as first-class citizen of BNF
blanchet
parents: 49451
diff changeset
    91
  fix R S
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    92
  show "rel_sum R S = (\<lambda>x y.
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    93
    \<exists>z. (setl z \<subseteq> {(x, y). R x y} \<and> setr z \<subseteq> {(x, y). S x y}) \<and>
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    94
    map_sum fst fst z = x \<and> map_sum snd snd z = y)"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    95
  unfolding sum_set_defs relcompp.simps conversep.simps fun_eq_iff
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    96
  by (fastforce elim: rel_sum.cases split: sum.splits)
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
    97
qed (auto simp: sum_set_defs fun_eq_iff pred_sum.simps split: sum.splits)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    98
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
    99
inductive_set fsts :: "'a \<times> 'b \<Rightarrow> 'a set" for p :: "'a \<times> 'b" where
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   100
  "fst p \<in> fsts p"
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   101
inductive_set snds :: "'a \<times> 'b \<Rightarrow> 'b set" for p :: "'a \<times> 'b" where
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   102
  "snd p \<in> snds p"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   103
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   104
lemma prod_set_defs[code]: "fsts = (\<lambda>p. {fst p})" "snds = (\<lambda>p. {snd p})"
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   105
  by (auto intro: fsts.intros snds.intros elim: fsts.cases snds.cases)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   106
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   107
inductive
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   108
  rel_prod :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('c \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a \<times> 'c \<Rightarrow> 'b \<times> 'd \<Rightarrow> bool" for R1 R2
55083
0a689157e3ce move BNF_LFP up the dependency chain
blanchet
parents: 55075
diff changeset
   109
where
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   110
  "\<lbrakk>R1 a b; R2 c d\<rbrakk> \<Longrightarrow> rel_prod R1 R2 (a, c) (b, d)"
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   111
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   112
inductive
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   113
  pred_prod :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a \<times> 'b \<Rightarrow> bool" for P1 P2
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   114
where
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   115
  "\<lbrakk>P1 a; P2 b\<rbrakk> \<Longrightarrow> pred_prod P1 P2 (a, b)"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   116
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   117
lemma rel_prod_apply [code, simp]:
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   118
  "rel_prod R1 R2 (a, b) (c, d) \<longleftrightarrow> R1 a c \<and> R2 b d"
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   119
  by (auto intro: rel_prod.intros elim: rel_prod.cases)
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   120
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   121
lemma pred_prod_apply [code, simp]:
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   122
  "pred_prod P1 P2 (a, b) \<longleftrightarrow> P1 a \<and> P2 b"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   123
  by (auto intro: pred_prod.intros elim: pred_prod.cases)
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   124
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   125
lemma rel_prod_conv:
55944
7ab8f003fe41 renamed 'prod_rel' to 'rel_prod'
blanchet
parents: 55943
diff changeset
   126
  "rel_prod R1 R2 = (\<lambda>(a, b) (c, d). R1 a c \<and> R2 b d)"
58916
229765cc3414 more complete fp_sugars for sum and prod;
traytel
parents: 58889
diff changeset
   127
  by (rule ext, rule ext) auto
55083
0a689157e3ce move BNF_LFP up the dependency chain
blanchet
parents: 55075
diff changeset
   128
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   129
definition
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   130
  pred_fun :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   131
where
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   132
  "pred_fun A B = (\<lambda>f. \<forall>x. A x \<longrightarrow> B (f x))"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   133
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   134
lemma pred_funI: "(\<And>x. A x \<Longrightarrow> B (f x)) \<Longrightarrow> pred_fun A B f"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   135
  unfolding pred_fun_def by simp
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   136
54421
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
   137
bnf "'a \<times> 'b"
55932
68c5104d2204 renamed 'map_pair' to 'map_prod'
blanchet
parents: 55931
diff changeset
   138
  map: map_prod
54421
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
   139
  sets: fsts snds
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
   140
  bd: natLeq
55944
7ab8f003fe41 renamed 'prod_rel' to 'rel_prod'
blanchet
parents: 55943
diff changeset
   141
  rel: rel_prod
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   142
  pred: pred_prod
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   143
proof (unfold prod_set_defs)
55932
68c5104d2204 renamed 'map_pair' to 'map_prod'
blanchet
parents: 55931
diff changeset
   144
  show "map_prod id id = id" by (rule map_prod.id)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   145
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   146
  fix f1 f2 g1 g2
55932
68c5104d2204 renamed 'map_pair' to 'map_prod'
blanchet
parents: 55931
diff changeset
   147
  show "map_prod (g1 o f1) (g2 o f2) = map_prod g1 g2 o map_prod f1 f2"
68c5104d2204 renamed 'map_pair' to 'map_prod'
blanchet
parents: 55931
diff changeset
   148
    by (rule map_prod.comp[symmetric])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   149
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   150
  fix x f1 f2 g1 g2
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   151
  assume "\<And>z. z \<in> {fst x} \<Longrightarrow> f1 z = g1 z" "\<And>z. z \<in> {snd x} \<Longrightarrow> f2 z = g2 z"
55932
68c5104d2204 renamed 'map_pair' to 'map_prod'
blanchet
parents: 55931
diff changeset
   152
  thus "map_prod f1 f2 x = map_prod g1 g2 x" by (cases x) simp
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   153
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   154
  fix f1 f2
55932
68c5104d2204 renamed 'map_pair' to 'map_prod'
blanchet
parents: 55931
diff changeset
   155
  show "(\<lambda>x. {fst x}) o map_prod f1 f2 = image f1 o (\<lambda>x. {fst x})"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   156
    by (rule ext, unfold o_apply) simp
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   157
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   158
  fix f1 f2
55932
68c5104d2204 renamed 'map_pair' to 'map_prod'
blanchet
parents: 55931
diff changeset
   159
  show "(\<lambda>x. {snd x}) o map_prod f1 f2 = image f2 o (\<lambda>x. {snd x})"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   160
    by (rule ext, unfold o_apply) simp
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   161
next
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 52545
diff changeset
   162
  show "card_order natLeq" by (rule natLeq_card_order)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   163
next
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 52545
diff changeset
   164
  show "cinfinite natLeq" by (rule natLeq_cinfinite)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   165
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   166
  fix x
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 52545
diff changeset
   167
  show "|{fst x}| \<le>o natLeq"
55811
aa1acc25126b load Metis a little later
traytel
parents: 55707
diff changeset
   168
    by (rule ordLess_imp_ordLeq) (simp add: finite_iff_ordLess_natLeq[symmetric])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   169
next
52635
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 52545
diff changeset
   170
  fix x
4f84b730c489 got rid of in_bd BNF property (derivable from set_bd+map_cong+map_comp+map_id)
traytel
parents: 52545
diff changeset
   171
  show "|{snd x}| \<le>o natLeq"
55811
aa1acc25126b load Metis a little later
traytel
parents: 55707
diff changeset
   172
    by (rule ordLess_imp_ordLeq) (simp add: finite_iff_ordLess_natLeq[symmetric])
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   173
next
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54581
diff changeset
   174
  fix R1 R2 S1 S2
55944
7ab8f003fe41 renamed 'prod_rel' to 'rel_prod'
blanchet
parents: 55943
diff changeset
   175
  show "rel_prod R1 R2 OO rel_prod S1 S2 \<le> rel_prod (R1 OO S1) (R2 OO S2)" by auto
49453
ff0e540d8758 add rel as first-class citizen of BNF
blanchet
parents: 49451
diff changeset
   176
next
ff0e540d8758 add rel as first-class citizen of BNF
blanchet
parents: 49451
diff changeset
   177
  fix R S
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   178
  show "rel_prod R S = (\<lambda>x y.
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   179
    \<exists>z. ({fst z} \<subseteq> {(x, y). R x y} \<and> {snd z} \<subseteq> {(x, y). S x y}) \<and>
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   180
      map_prod fst fst z = x \<and> map_prod snd snd z = y)"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   181
  unfolding prod_set_defs rel_prod_apply relcompp.simps conversep.simps fun_eq_iff
49453
ff0e540d8758 add rel as first-class citizen of BNF
blanchet
parents: 49451
diff changeset
   182
  by auto
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   183
qed auto
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   184
54421
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
   185
bnf "'a \<Rightarrow> 'b"
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
   186
  map: "op \<circ>"
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
   187
  sets: range
632be352a5a3 more explicit syntax for defining a bnf
traytel
parents: 54191
diff changeset
   188
  bd: "natLeq +c |UNIV :: 'a set|"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55944
diff changeset
   189
  rel: "rel_fun op ="
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   190
  pred: "pred_fun (\<lambda>_. True)"
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   191
proof
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   192
  fix f show "id \<circ> f = id f" by simp
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   193
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   194
  fix f g show "op \<circ> (g \<circ> f) = op \<circ> g \<circ> op \<circ> f"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   195
  unfolding comp_def[abs_def] ..
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   196
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   197
  fix x f g
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   198
  assume "\<And>z. z \<in> range x \<Longrightarrow> f z = g z"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   199
  thus "f \<circ> x = g \<circ> x" by auto
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   200
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   201
  fix f show "range \<circ> op \<circ> f = op ` f \<circ> range"
56077
d397030fb27e tuned proofs
haftmann
parents: 55945
diff changeset
   202
    by (auto simp add: fun_eq_iff)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   203
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   204
  show "card_order (natLeq +c |UNIV| )" (is "_ (_ +c ?U)")
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   205
  apply (rule card_order_csum)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   206
  apply (rule natLeq_card_order)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   207
  by (rule card_of_card_order_on)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   208
(*  *)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   209
  show "cinfinite (natLeq +c ?U)"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   210
    apply (rule cinfinite_csum)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   211
    apply (rule disjI1)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   212
    by (rule natLeq_cinfinite)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   213
next
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   214
  fix f :: "'d => 'a"
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   215
  have "|range f| \<le>o | (UNIV::'d set) |" (is "_ \<le>o ?U") by (rule card_of_image)
54486
d8d276c922f2 tuned proofs
blanchet
parents: 54485
diff changeset
   216
  also have "?U \<le>o natLeq +c ?U" by (rule ordLeq_csum2) (rule card_of_Card_order)
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   217
  finally show "|range f| \<le>o natLeq +c ?U" .
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   218
next
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54581
diff changeset
   219
  fix R S
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55944
diff changeset
   220
  show "rel_fun op = R OO rel_fun op = S \<le> rel_fun op = (R OO S)" by (auto simp: rel_fun_def)
49453
ff0e540d8758 add rel as first-class citizen of BNF
blanchet
parents: 49451
diff changeset
   221
next
49463
83ac281bcdc2 provide predicator, define relator
blanchet
parents: 49455
diff changeset
   222
  fix R
62324
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   223
  show "rel_fun op = R = (\<lambda>x y.
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   224
    \<exists>z. range z \<subseteq> {(x, y). R x y} \<and> fst \<circ> z = x \<and> snd \<circ> z = y)"
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   225
  unfolding rel_fun_def subset_iff by (force simp: fun_eq_iff[symmetric])
ae44f16dcea5 make predicator a first-class bnf citizen
traytel
parents: 61681
diff changeset
   226
qed (auto simp: pred_fun_def)
54191
7fba375a7e7d removed junk
traytel
parents: 54189
diff changeset
   227
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   228
end