src/HOL/BNF/BNF_Def.thy
author traytel
Tue, 07 May 2013 14:22:54 +0200
changeset 51893 596baae88a88
parent 51836 4d6dcd51dd52
child 51909 eb3169abcbd5
permissions -rw-r--r--
got rid of the set based relator---use (binary) predicate based relator instead
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49509
163914705f8d renamed top-level theory from "Codatatype" to "BNF"
blanchet
parents: 49495
diff changeset
     1
(*  Title:      HOL/BNF/BNF_Def.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
    Copyright   2012
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     4
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     5
Definition of bounded natural functors.
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     6
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     7
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     8
header {* Definition of Bounded Natural Functors *}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     9
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    10
theory BNF_Def
49282
c057e1b39f16 renamed "BNF_Library" to "BNF_Util"
blanchet
parents: 48975
diff changeset
    11
imports BNF_Util
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    12
keywords
49286
dde4967c9233 added "defaults" option
blanchet
parents: 49284
diff changeset
    13
  "print_bnfs" :: diag and
51836
4d6dcd51dd52 renamed "bnf_def" keyword to "bnf" (since it's not a definition, but rather a registration)
blanchet
parents: 49537
diff changeset
    14
  "bnf" :: thy_goal
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    15
begin
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    16
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    17
lemma collect_o: "collect F o g = collect ((\<lambda>f. f o g) ` F)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    18
by (rule ext) (auto simp only: o_apply collect_def)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    19
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    20
lemma converse_mono:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    21
"R1 ^-1 \<subseteq> R2 ^-1 \<longleftrightarrow> R1 \<subseteq> R2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    22
unfolding converse_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    23
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    24
lemma conversep_mono:
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    25
"R1 ^--1 \<le> R2 ^--1 \<longleftrightarrow> R1 \<le> R2"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    26
unfolding conversep.simps by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    27
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    28
lemma converse_shift:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    29
"R1 \<subseteq> R2 ^-1 \<Longrightarrow> R1 ^-1 \<subseteq> R2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    30
unfolding converse_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    31
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    32
lemma conversep_shift:
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    33
"R1 \<le> R2 ^--1 \<Longrightarrow> R1 ^--1 \<le> R2"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    34
unfolding conversep.simps by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    35
49495
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    36
definition convol ("<_ , _>") where
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    37
"<f , g> \<equiv> %a. (f a, g a)"
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    38
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    39
lemma fst_convol:
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    40
"fst o <f , g> = f"
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    41
apply(rule ext)
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    42
unfolding convol_def by simp
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    43
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    44
lemma snd_convol:
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    45
"snd o <f , g> = g"
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    46
apply(rule ext)
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    47
unfolding convol_def by simp
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    48
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    49
lemma convol_memI:
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    50
"\<lbrakk>f x = f' x; g x = g' x; P x\<rbrakk> \<Longrightarrow> <f , g> x \<in> {(f' a, g' a) |a. P a}"
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    51
unfolding convol_def by auto
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    52
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    53
lemma convol_mem_GrpI:
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    54
"\<lbrakk>g x = g' x; x \<in> A\<rbrakk> \<Longrightarrow> <id , g> x \<in> (Collect (split (Grp A g)))"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    55
unfolding convol_def Grp_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
    56
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    57
definition csquare where
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    58
"csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    59
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    60
(* The pullback of sets *)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    61
definition thePull where
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    62
"thePull B1 B2 f1 f2 = {(b1,b2). b1 \<in> B1 \<and> b2 \<in> B2 \<and> f1 b1 = f2 b2}"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    63
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    64
lemma wpull_thePull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    65
"wpull (thePull B1 B2 f1 f2) B1 B2 f1 f2 fst snd"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    66
unfolding wpull_def thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    67
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    68
lemma wppull_thePull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    69
assumes "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    70
shows
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    71
"\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    72
   j a' \<in> A \<and>
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    73
   e1 (p1 (j a')) = e1 (fst a') \<and> e2 (p2 (j a')) = e2 (snd a')"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    74
(is "\<exists> j. \<forall> a' \<in> ?A'. ?phi a' (j a')")
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    75
proof(rule bchoice[of ?A' ?phi], default)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    76
  fix a' assume a': "a' \<in> ?A'"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    77
  hence "fst a' \<in> B1" unfolding thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    78
  moreover
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    79
  from a' have "snd a' \<in> B2" unfolding thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    80
  moreover have "f1 (fst a') = f2 (snd a')"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    81
  using a' unfolding csquare_def thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    82
  ultimately show "\<exists> ja'. ?phi a' ja'"
49325
blanchet
parents: 49312
diff changeset
    83
  using assms unfolding wppull_def by blast
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    84
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    85
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    86
lemma wpull_wppull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    87
assumes wp: "wpull A' B1 B2 f1 f2 p1' p2'" and
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    88
1: "\<forall> a' \<in> A'. j a' \<in> A \<and> e1 (p1 (j a')) = e1 (p1' a') \<and> e2 (p2 (j a')) = e2 (p2' a')"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    89
shows "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    90
unfolding wppull_def proof safe
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    91
  fix b1 b2
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    92
  assume b1: "b1 \<in> B1" and b2: "b2 \<in> B2" and f: "f1 b1 = f2 b2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    93
  then obtain a' where a': "a' \<in> A'" and b1: "b1 = p1' a'" and b2: "b2 = p2' a'"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    94
  using wp unfolding wpull_def by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    95
  show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
49325
blanchet
parents: 49312
diff changeset
    96
  apply (rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    97
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    98
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    99
lemma wppull_id: "\<lbrakk>wpull UNIV UNIV UNIV f1 f2 p1 p2; e1 = id; e2 = id\<rbrakk> \<Longrightarrow>
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   100
   wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   101
by (erule wpull_wppull) auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   102
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   103
lemma Id_alt: "Id = Gr UNIV id"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   104
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   105
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   106
lemma eq_alt: "op = = Grp UNIV id"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   107
unfolding Grp_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   108
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   109
lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   110
  by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   111
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   112
lemma eq_OOI: "R = op = \<Longrightarrow> R = R OO R"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   113
  by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   114
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   115
lemma Gr_UNIV_id: "f = id \<Longrightarrow> (Gr UNIV f)^-1 O Gr UNIV f = Gr UNIV f"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   116
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   117
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   118
lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   119
unfolding Grp_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   120
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   121
lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   122
unfolding Grp_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   123
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   124
lemma Gr_mono: "A \<subseteq> B \<Longrightarrow> Gr A f \<subseteq> Gr B f"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   125
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   126
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   127
lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   128
unfolding Grp_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   129
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   130
lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   131
unfolding Grp_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   132
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   133
lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   134
unfolding Grp_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   135
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   136
lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   137
unfolding Grp_def o_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   138
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   139
lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   140
unfolding Grp_def o_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   141
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   142
lemma wpull_Gr:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   143
"wpull (Gr A f) A (f ` A) f id fst snd"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   144
unfolding wpull_def Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   145
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   146
lemma wpull_Grp:
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   147
"wpull (Collect (split (Grp A f))) A (f ` A) f id fst snd"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   148
unfolding wpull_def Grp_def by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   149
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   150
definition "pick_middle P Q a c = (SOME b. (a,b) \<in> P \<and> (b,c) \<in> Q)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   151
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   152
definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   153
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   154
lemma pick_middle:
49325
blanchet
parents: 49312
diff changeset
   155
"(a,c) \<in> P O Q \<Longrightarrow> (a, pick_middle P Q a c) \<in> P \<and> (pick_middle P Q a c, c) \<in> Q"
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   156
unfolding pick_middle_def apply(rule someI_ex) by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   157
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   158
lemma pick_middlep:
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   159
"(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   160
unfolding pick_middlep_def apply(rule someI_ex) by auto
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   161
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   162
definition fstO where "fstO P Q ac = (fst ac, pick_middle P Q (fst ac) (snd ac))"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   163
definition sndO where "sndO P Q ac = (pick_middle P Q (fst ac) (snd ac), snd ac)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   164
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   165
definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   166
definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   167
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   168
lemma fstO_in: "ac \<in> P O Q \<Longrightarrow> fstO P Q ac \<in> P"
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   169
unfolding fstO_def by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct1])
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   170
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   171
lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   172
unfolding fstOp_def mem_Collect_eq
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   173
by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct1])
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   174
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   175
lemma fst_fstO: "fst bc = (fst \<circ> fstO P Q) bc"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   176
unfolding comp_def fstO_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   177
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   178
lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   179
unfolding comp_def fstOp_def by simp
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   180
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   181
lemma snd_sndO: "snd bc = (snd \<circ> sndO P Q) bc"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   182
unfolding comp_def sndO_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   183
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   184
lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   185
unfolding comp_def sndOp_def by simp
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   186
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   187
lemma sndO_in: "ac \<in> P O Q \<Longrightarrow> sndO P Q ac \<in> Q"
49325
blanchet
parents: 49312
diff changeset
   188
unfolding sndO_def
blanchet
parents: 49312
diff changeset
   189
by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct2])
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   190
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   191
lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   192
unfolding sndOp_def mem_Collect_eq
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   193
by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct2])
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   194
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   195
lemma csquare_fstO_sndO:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   196
"csquare (P O Q) snd fst (fstO P Q) (sndO P Q)"
49325
blanchet
parents: 49312
diff changeset
   197
unfolding csquare_def fstO_def sndO_def using pick_middle by simp
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   198
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   199
lemma csquare_fstOp_sndOp:
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   200
"csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   201
unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   202
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   203
lemma wppull_fstO_sndO:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   204
shows "wppull (P O Q) P Q snd fst fst snd (fstO P Q) (sndO P Q)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   205
using pick_middle unfolding wppull_def fstO_def sndO_def relcomp_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   206
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   207
lemma wppull_fstOp_sndOp:
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   208
shows "wppull (Collect (split (P OO Q))) (Collect (split P)) (Collect (split Q)) snd fst fst snd (fstOp P Q) (sndOp P Q)"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   209
using pick_middlep unfolding wppull_def fstOp_def sndOp_def relcompp.simps by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   210
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   211
lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   212
by (simp split: prod.split)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   213
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   214
lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   215
by (simp split: prod.split)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   216
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   217
lemma flip_rel: "A \<subseteq> (R ^-1) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> R"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   218
by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   219
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   220
lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   221
by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   222
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   223
lemma pointfreeE: "f o g = f' o g' \<Longrightarrow> f (g x) = f' (g' x)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   224
unfolding o_def fun_eq_iff by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   225
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   226
lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   227
  by auto
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   228
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   229
lemma predicate2_cong: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   230
by metis
49537
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   231
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   232
lemma fun_cong_pair: "f = g \<Longrightarrow> f {(a, b). R a b} = g {(a, b). R a b}"
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   233
by (rule fun_cong)
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   234
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   235
lemma flip_as_converse: "{(a, b). R b a} = converse {(a, b). R a b}"
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   236
unfolding converse_def mem_Collect_eq prod.cases
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   237
apply (rule arg_cong[of _ _ "\<lambda>x. Collect (prod_case x)"])
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   238
apply (rule ext)+
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   239
apply (unfold conversep_iff)
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   240
by (rule refl)
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   241
49309
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49286
diff changeset
   242
ML_file "Tools/bnf_def_tactics.ML"
49537
fe1deee434b6 generate "rel_as_srel" and "rel_flip" properties
blanchet
parents: 49510
diff changeset
   243
ML_file "Tools/bnf_def.ML"
49309
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49286
diff changeset
   244
51893
596baae88a88 got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents: 51836
diff changeset
   245
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   246
end