src/HOL/Predicate.thy
author haftmann
Fri, 06 Mar 2009 20:30:17 +0100
changeset 30328 ab47f43f7581
parent 26797 a6cb51c314f2
child 30376 e8cc806a3755
permissions -rw-r--r--
added enumeration of predicates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/Predicate.thy
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
     2
    Author:     Stefan Berghofer and Lukas Bulwahn and Florian Haftmann, TU Muenchen
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
     3
*)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
     4
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
     5
header {* Predicates as relations and enumerations *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
     6
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
     7
theory Predicate
23708
b5eb0b4dd17d clarified import
haftmann
parents: 23389
diff changeset
     8
imports Inductive Relation
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
     9
begin
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    10
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    11
notation
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    12
  inf (infixl "\<sqinter>" 70) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    13
  sup (infixl "\<squnion>" 65) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    14
  Inf ("\<Sqinter>_" [900] 900) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    15
  Sup ("\<Squnion>_" [900] 900) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    16
  top ("\<top>") and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    17
  bot ("\<bottom>")
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    18
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    19
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    20
subsection {* Predicates as (complete) lattices *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    21
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    22
subsubsection {* @{const sup} on @{typ bool} *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    23
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    24
lemma sup_boolI1:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    25
  "P \<Longrightarrow> P \<squnion> Q"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    26
  by (simp add: sup_bool_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    27
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    28
lemma sup_boolI2:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    29
  "Q \<Longrightarrow> P \<squnion> Q"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    30
  by (simp add: sup_bool_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    31
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    32
lemma sup_boolE:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    33
  "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    34
  by (auto simp add: sup_bool_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    35
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    36
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    37
subsubsection {* Equality and Subsets *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    38
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
    39
lemma pred_equals_eq: "((\<lambda>x. x \<in> R) = (\<lambda>x. x \<in> S)) = (R = S)"
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
    40
  by (simp add: mem_def)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    41
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    42
lemma pred_equals_eq2 [pred_set_conv]: "((\<lambda>x y. (x, y) \<in> R) = (\<lambda>x y. (x, y) \<in> S)) = (R = S)"
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
    43
  by (simp add: expand_fun_eq mem_def)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    44
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
    45
lemma pred_subset_eq: "((\<lambda>x. x \<in> R) <= (\<lambda>x. x \<in> S)) = (R <= S)"
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
    46
  by (simp add: mem_def)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    47
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    48
lemma pred_subset_eq2 [pred_set_conv]: "((\<lambda>x y. (x, y) \<in> R) <= (\<lambda>x y. (x, y) \<in> S)) = (R <= S)"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    49
  by fast
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    50
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    51
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    52
subsubsection {* Top and bottom elements *}
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    53
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    54
lemma top1I [intro!]: "top x"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    55
  by (simp add: top_fun_eq top_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    56
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    57
lemma top2I [intro!]: "top x y"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    58
  by (simp add: top_fun_eq top_bool_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    59
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    60
lemma bot1E [elim!]: "bot x \<Longrightarrow> P"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    61
  by (simp add: bot_fun_eq bot_bool_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    62
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    63
lemma bot2E [elim!]: "bot x y \<Longrightarrow> P"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    64
  by (simp add: bot_fun_eq bot_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    65
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    66
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    67
subsubsection {* The empty set *}
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    68
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    69
lemma bot_empty_eq: "bot = (\<lambda>x. x \<in> {})"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    70
  by (auto simp add: expand_fun_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    71
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    72
lemma bot_empty_eq2: "bot = (\<lambda>x y. (x, y) \<in> {})"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    73
  by (auto simp add: expand_fun_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    74
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    75
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    76
subsubsection {* Binary union *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    77
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    78
lemma sup1_iff [simp]: "sup A B x \<longleftrightarrow> A x | B x"
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    79
  by (simp add: sup_fun_eq sup_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    80
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    81
lemma sup2_iff [simp]: "sup A B x y \<longleftrightarrow> A x y | B x y"
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    82
  by (simp add: sup_fun_eq sup_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    83
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    84
lemma sup_Un_eq [pred_set_conv]: "sup (\<lambda>x. x \<in> R) (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<union> S)"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    85
  by (simp add: expand_fun_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    86
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    87
lemma sup_Un_eq2 [pred_set_conv]: "sup (\<lambda>x y. (x, y) \<in> R) (\<lambda>x y. (x, y) \<in> S) = (\<lambda>x y. (x, y) \<in> R \<union> S)"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    88
  by (simp add: expand_fun_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    89
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    90
lemma sup1I1 [elim?]: "A x \<Longrightarrow> sup A B x"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    91
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    92
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    93
lemma sup2I1 [elim?]: "A x y \<Longrightarrow> sup A B x y"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    94
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    95
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    96
lemma sup1I2 [elim?]: "B x \<Longrightarrow> sup A B x"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    97
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    98
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    99
lemma sup2I2 [elim?]: "B x y \<Longrightarrow> sup A B x y"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   100
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   101
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   102
text {*
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   103
  \medskip Classical introduction rule: no commitment to @{text A} vs
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   104
  @{text B}.
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   105
*}
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   106
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   107
lemma sup1CI [intro!]: "(~ B x ==> A x) ==> sup A B x"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   108
  by auto
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   109
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   110
lemma sup2CI [intro!]: "(~ B x y ==> A x y) ==> sup A B x y"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   111
  by auto
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   112
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   113
lemma sup1E [elim!]: "sup A B x ==> (A x ==> P) ==> (B x ==> P) ==> P"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   114
  by simp iprover
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   115
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   116
lemma sup2E [elim!]: "sup A B x y ==> (A x y ==> P) ==> (B x y ==> P) ==> P"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   117
  by simp iprover
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   118
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   119
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   120
subsubsection {* Binary intersection *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   121
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   122
lemma inf1_iff [simp]: "inf A B x \<longleftrightarrow> A x \<and> B x"
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   123
  by (simp add: inf_fun_eq inf_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   124
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   125
lemma inf2_iff [simp]: "inf A B x y \<longleftrightarrow> A x y \<and> B x y"
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   126
  by (simp add: inf_fun_eq inf_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   127
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   128
lemma inf_Int_eq [pred_set_conv]: "inf (\<lambda>x. x \<in> R) (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<inter> S)"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   129
  by (simp add: expand_fun_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   130
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   131
lemma inf_Int_eq2 [pred_set_conv]: "inf (\<lambda>x y. (x, y) \<in> R) (\<lambda>x y. (x, y) \<in> S) = (\<lambda>x y. (x, y) \<in> R \<inter> S)"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   132
  by (simp add: expand_fun_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   133
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   134
lemma inf1I [intro!]: "A x ==> B x ==> inf A B x"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   135
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   136
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   137
lemma inf2I [intro!]: "A x y ==> B x y ==> inf A B x y"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   138
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   139
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   140
lemma inf1D1: "inf A B x ==> A x"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   141
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   142
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   143
lemma inf2D1: "inf A B x y ==> A x y"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   144
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   145
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   146
lemma inf1D2: "inf A B x ==> B x"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   147
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   148
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   149
lemma inf2D2: "inf A B x y ==> B x y"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   150
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   151
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   152
lemma inf1E [elim!]: "inf A B x ==> (A x ==> B x ==> P) ==> P"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   153
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   154
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   155
lemma inf2E [elim!]: "inf A B x y ==> (A x y ==> B x y ==> P) ==> P"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   156
  by simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   157
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   158
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   159
subsubsection {* Unions of families *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   160
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   161
lemma SUP1_iff [simp]: "(SUP x:A. B x) b = (EX x:A. B x b)"
24345
86a3557a9ebb Sup now explicit parameter of complete_lattice
haftmann
parents: 23741
diff changeset
   162
  by (simp add: SUPR_def Sup_fun_def Sup_bool_def) blast
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   163
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   164
lemma SUP2_iff [simp]: "(SUP x:A. B x) b c = (EX x:A. B x b c)"
24345
86a3557a9ebb Sup now explicit parameter of complete_lattice
haftmann
parents: 23741
diff changeset
   165
  by (simp add: SUPR_def Sup_fun_def Sup_bool_def) blast
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   166
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   167
lemma SUP1_I [intro]: "a : A ==> B a b ==> (SUP x:A. B x) b"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   168
  by auto
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   169
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   170
lemma SUP2_I [intro]: "a : A ==> B a b c ==> (SUP x:A. B x) b c"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   171
  by auto
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   172
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   173
lemma SUP1_E [elim!]: "(SUP x:A. B x) b ==> (!!x. x : A ==> B x b ==> R) ==> R"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   174
  by auto
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   175
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   176
lemma SUP2_E [elim!]: "(SUP x:A. B x) b c ==> (!!x. x : A ==> B x b c ==> R) ==> R"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   177
  by auto
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   178
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   179
lemma SUP_UN_eq: "(SUP i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (UN i. r i))"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   180
  by (simp add: expand_fun_eq)
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   181
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   182
lemma SUP_UN_eq2: "(SUP i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (UN i. r i))"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   183
  by (simp add: expand_fun_eq)
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   184
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   185
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   186
subsubsection {* Intersections of families *}
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   187
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   188
lemma INF1_iff [simp]: "(INF x:A. B x) b = (ALL x:A. B x b)"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   189
  by (simp add: INFI_def Inf_fun_def Inf_bool_def) blast
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   190
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   191
lemma INF2_iff [simp]: "(INF x:A. B x) b c = (ALL x:A. B x b c)"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   192
  by (simp add: INFI_def Inf_fun_def Inf_bool_def) blast
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   193
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   194
lemma INF1_I [intro!]: "(!!x. x : A ==> B x b) ==> (INF x:A. B x) b"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   195
  by auto
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   196
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   197
lemma INF2_I [intro!]: "(!!x. x : A ==> B x b c) ==> (INF x:A. B x) b c"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   198
  by auto
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   199
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   200
lemma INF1_D [elim]: "(INF x:A. B x) b ==> a : A ==> B a b"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   201
  by auto
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   202
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   203
lemma INF2_D [elim]: "(INF x:A. B x) b c ==> a : A ==> B a b c"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   204
  by auto
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   205
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   206
lemma INF1_E [elim]: "(INF x:A. B x) b ==> (B a b ==> R) ==> (a ~: A ==> R) ==> R"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   207
  by auto
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   208
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   209
lemma INF2_E [elim]: "(INF x:A. B x) b c ==> (B a b c ==> R) ==> (a ~: A ==> R) ==> R"
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   210
  by auto
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   211
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   212
lemma INF_INT_eq: "(INF i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (INT i. r i))"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   213
  by (simp add: expand_fun_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   214
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   215
lemma INF_INT_eq2: "(INF i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (INT i. r i))"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   216
  by (simp add: expand_fun_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   217
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   218
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   219
subsection {* Predicates as relations *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   220
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   221
subsubsection {* Composition  *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   222
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   223
inductive
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   224
  pred_comp  :: "['b => 'c => bool, 'a => 'b => bool] => 'a => 'c => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   225
    (infixr "OO" 75)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   226
  for r :: "'b => 'c => bool" and s :: "'a => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   227
where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   228
  pred_compI [intro]: "s a b ==> r b c ==> (r OO s) a c"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   229
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   230
inductive_cases pred_compE [elim!]: "(r OO s) a c"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   231
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   232
lemma pred_comp_rel_comp_eq [pred_set_conv]:
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   233
  "((\<lambda>x y. (x, y) \<in> r) OO (\<lambda>x y. (x, y) \<in> s)) = (\<lambda>x y. (x, y) \<in> r O s)"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   234
  by (auto simp add: expand_fun_eq elim: pred_compE)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   235
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   236
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   237
subsubsection {* Converse *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   238
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   239
inductive
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   240
  conversep :: "('a => 'b => bool) => 'b => 'a => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   241
    ("(_^--1)" [1000] 1000)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   242
  for r :: "'a => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   243
where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   244
  conversepI: "r a b ==> r^--1 b a"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   245
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   246
notation (xsymbols)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   247
  conversep  ("(_\<inverse>\<inverse>)" [1000] 1000)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   248
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   249
lemma conversepD:
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   250
  assumes ab: "r^--1 a b"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   251
  shows "r b a" using ab
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   252
  by cases simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   253
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   254
lemma conversep_iff [iff]: "r^--1 a b = r b a"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   255
  by (iprover intro: conversepI dest: conversepD)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   256
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   257
lemma conversep_converse_eq [pred_set_conv]:
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   258
  "(\<lambda>x y. (x, y) \<in> r)^--1 = (\<lambda>x y. (x, y) \<in> r^-1)"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   259
  by (auto simp add: expand_fun_eq)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   260
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   261
lemma conversep_conversep [simp]: "(r^--1)^--1 = r"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   262
  by (iprover intro: order_antisym conversepI dest: conversepD)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   263
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   264
lemma converse_pred_comp: "(r OO s)^--1 = s^--1 OO r^--1"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   265
  by (iprover intro: order_antisym conversepI pred_compI
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   266
    elim: pred_compE dest: conversepD)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   267
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   268
lemma converse_meet: "(inf r s)^--1 = inf r^--1 s^--1"
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   269
  by (simp add: inf_fun_eq inf_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   270
    (iprover intro: conversepI ext dest: conversepD)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   271
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   272
lemma converse_join: "(sup r s)^--1 = sup r^--1 s^--1"
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   273
  by (simp add: sup_fun_eq sup_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   274
    (iprover intro: conversepI ext dest: conversepD)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   275
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   276
lemma conversep_noteq [simp]: "(op ~=)^--1 = op ~="
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   277
  by (auto simp add: expand_fun_eq)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   278
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   279
lemma conversep_eq [simp]: "(op =)^--1 = op ="
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   280
  by (auto simp add: expand_fun_eq)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   281
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   282
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   283
subsubsection {* Domain *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   284
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   285
inductive
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   286
  DomainP :: "('a => 'b => bool) => 'a => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   287
  for r :: "'a => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   288
where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   289
  DomainPI [intro]: "r a b ==> DomainP r a"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   290
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   291
inductive_cases DomainPE [elim!]: "DomainP r a"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   292
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   293
lemma DomainP_Domain_eq [pred_set_conv]: "DomainP (\<lambda>x y. (x, y) \<in> r) = (\<lambda>x. x \<in> Domain r)"
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
   294
  by (blast intro!: Orderings.order_antisym predicate1I)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   295
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   296
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   297
subsubsection {* Range *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   298
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   299
inductive
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   300
  RangeP :: "('a => 'b => bool) => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   301
  for r :: "'a => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   302
where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   303
  RangePI [intro]: "r a b ==> RangeP r b"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   304
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   305
inductive_cases RangePE [elim!]: "RangeP r b"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   306
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   307
lemma RangeP_Range_eq [pred_set_conv]: "RangeP (\<lambda>x y. (x, y) \<in> r) = (\<lambda>x. x \<in> Range r)"
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
   308
  by (blast intro!: Orderings.order_antisym predicate1I)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   309
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   310
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   311
subsubsection {* Inverse image *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   312
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   313
definition
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   314
  inv_imagep :: "('b => 'b => bool) => ('a => 'b) => 'a => 'a => bool" where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   315
  "inv_imagep r f == %x y. r (f x) (f y)"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   316
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   317
lemma [pred_set_conv]: "inv_imagep (\<lambda>x y. (x, y) \<in> r) f = (\<lambda>x y. (x, y) \<in> inv_image r f)"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   318
  by (simp add: inv_image_def inv_imagep_def)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   319
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   320
lemma in_inv_imagep [simp]: "inv_imagep r f x y = r (f x) (f y)"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   321
  by (simp add: inv_imagep_def)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   322
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   323
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   324
subsubsection {* Powerset *}
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   325
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   326
definition Powp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool" where
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   327
  "Powp A == \<lambda>B. \<forall>x \<in> B. A x"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   328
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   329
lemma Powp_Pow_eq [pred_set_conv]: "Powp (\<lambda>x. x \<in> A) = (\<lambda>x. x \<in> Pow A)"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   330
  by (auto simp add: Powp_def expand_fun_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   331
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
   332
lemmas Powp_mono [mono] = Pow_mono [to_pred pred_subset_eq]
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
   333
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   334
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   335
subsubsection {* Properties of relations *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   336
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   337
abbreviation antisymP :: "('a => 'a => bool) => bool" where
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   338
  "antisymP r == antisym {(x, y). r x y}"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   339
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   340
abbreviation transP :: "('a => 'a => bool) => bool" where
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   341
  "transP r == trans {(x, y). r x y}"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   342
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   343
abbreviation single_valuedP :: "('a => 'b => bool) => bool" where
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   344
  "single_valuedP r == single_valued {(x, y). r x y}"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   345
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   346
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   347
subsection {* Predicates as enumerations *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   348
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   349
subsubsection {* The type of predicate enumerations (a monad) *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   350
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   351
datatype 'a pred = Pred "'a \<Rightarrow> bool"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   352
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   353
primrec eval :: "'a pred \<Rightarrow> 'a \<Rightarrow> bool" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   354
  eval_pred: "eval (Pred f) = f"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   355
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   356
lemma Pred_eval [simp]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   357
  "Pred (eval x) = x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   358
  by (cases x) simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   359
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   360
lemma eval_inject: "eval x = eval y \<longleftrightarrow> x = y"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   361
  by (cases x) auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   362
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   363
definition single :: "'a \<Rightarrow> 'a pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   364
  "single x = Pred ((op =) x)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   365
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   366
definition bind :: "'a pred \<Rightarrow> ('a \<Rightarrow> 'b pred) \<Rightarrow> 'b pred" (infixl "\<guillemotright>=" 70) where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   367
  "P \<guillemotright>= f = Pred (\<lambda>x. (\<exists>y. eval P y \<and> eval (f y) x))"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   368
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   369
instantiation pred :: (type) complete_lattice
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   370
begin
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   371
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   372
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   373
  "P \<le> Q \<longleftrightarrow> eval P \<le> eval Q"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   374
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   375
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   376
  "P < Q \<longleftrightarrow> eval P < eval Q"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   377
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   378
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   379
  "\<bottom> = Pred \<bottom>"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   380
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   381
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   382
  "\<top> = Pred \<top>"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   383
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   384
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   385
  "P \<sqinter> Q = Pred (eval P \<sqinter> eval Q)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   386
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   387
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   388
  "P \<squnion> Q = Pred (eval P \<squnion> eval Q)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   389
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   390
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   391
  "\<Sqinter>A = Pred (INFI A eval)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   392
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   393
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   394
  "\<Squnion>A = Pred (SUPR A eval)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   395
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   396
instance by default
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   397
  (auto simp add: less_eq_pred_def less_pred_def
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   398
    inf_pred_def sup_pred_def bot_pred_def top_pred_def
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   399
    Inf_pred_def Sup_pred_def,
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   400
    auto simp add: le_fun_def less_fun_def le_bool_def less_bool_def
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   401
    eval_inject mem_def)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   402
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   403
end
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   404
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   405
lemma bind_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   406
  "(P \<guillemotright>= Q) \<guillemotright>= R = P \<guillemotright>= (\<lambda>x. Q x \<guillemotright>= R)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   407
  by (auto simp add: bind_def expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   408
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   409
lemma bind_single:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   410
  "P \<guillemotright>= single = P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   411
  by (simp add: bind_def single_def)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   412
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   413
lemma single_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   414
  "single x \<guillemotright>= P = P x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   415
  by (simp add: bind_def single_def)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   416
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   417
lemma bottom_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   418
  "\<bottom> \<guillemotright>= P = \<bottom>"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   419
  by (auto simp add: bot_pred_def bind_def expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   420
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   421
lemma sup_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   422
  "(P \<squnion> Q) \<guillemotright>= R = P \<guillemotright>= R \<squnion> Q \<guillemotright>= R"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   423
  by (auto simp add: bind_def sup_pred_def expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   424
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   425
lemma Sup_bind: "(\<Squnion>A \<guillemotright>= f) = \<Squnion>((\<lambda>x. x \<guillemotright>= f) ` A)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   426
  by (auto simp add: bind_def Sup_pred_def expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   427
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   428
lemma pred_iffI:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   429
  assumes "\<And>x. eval A x \<Longrightarrow> eval B x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   430
  and "\<And>x. eval B x \<Longrightarrow> eval A x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   431
  shows "A = B"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   432
proof -
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   433
  from assms have "\<And>x. eval A x \<longleftrightarrow> eval B x" by blast
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   434
  then show ?thesis by (cases A, cases B) (simp add: expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   435
qed
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   436
  
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   437
lemma singleI: "eval (single x) x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   438
  unfolding single_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   439
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   440
lemma singleI_unit: "eval (single ()) x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   441
  by simp (rule singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   442
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   443
lemma singleE: "eval (single x) y \<Longrightarrow> (y = x \<Longrightarrow> P) \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   444
  unfolding single_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   445
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   446
lemma singleE': "eval (single x) y \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   447
  by (erule singleE) simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   448
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   449
lemma bindI: "eval P x \<Longrightarrow> eval (Q x) y \<Longrightarrow> eval (P \<guillemotright>= Q) y"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   450
  unfolding bind_def by auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   451
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   452
lemma bindE: "eval (R \<guillemotright>= Q) y \<Longrightarrow> (\<And>x. eval R x \<Longrightarrow> eval (Q x) y \<Longrightarrow> P) \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   453
  unfolding bind_def by auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   454
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   455
lemma botE: "eval \<bottom> x \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   456
  unfolding bot_pred_def by auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   457
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   458
lemma supI1: "eval A x \<Longrightarrow> eval (A \<squnion> B) x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   459
  unfolding sup_pred_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   460
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   461
lemma supI2: "eval B x \<Longrightarrow> eval (A \<squnion> B) x" 
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   462
  unfolding sup_pred_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   463
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   464
lemma supE: "eval (A \<squnion> B) x \<Longrightarrow> (eval A x \<Longrightarrow> P) \<Longrightarrow> (eval B x \<Longrightarrow> P) \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   465
  unfolding sup_pred_def by auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   466
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   467
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   468
subsubsection {* Derived operations *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   469
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   470
definition if_pred :: "bool \<Rightarrow> unit pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   471
  if_pred_eq: "if_pred b = (if b then single () else \<bottom>)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   472
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   473
definition eq_pred :: "'a \<Rightarrow> 'a \<Rightarrow> unit pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   474
  eq_pred_eq: "eq_pred a b = if_pred (a = b)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   475
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   476
definition not_pred :: "unit pred \<Rightarrow> unit pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   477
  not_pred_eq: "not_pred P = (if eval P () then \<bottom> else single ())"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   478
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   479
lemma if_predI: "P \<Longrightarrow> eval (if_pred P) ()"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   480
  unfolding if_pred_eq by (auto intro: singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   481
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   482
lemma if_predE: "eval (if_pred b) x \<Longrightarrow> (b \<Longrightarrow> x = () \<Longrightarrow> P) \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   483
  unfolding if_pred_eq by (cases b) (auto elim: botE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   484
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   485
lemma eq_predI: "eval (eq_pred a a) ()"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   486
  unfolding eq_pred_eq if_pred_eq by (auto intro: singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   487
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   488
lemma eq_predE: "eval (eq_pred a b) x \<Longrightarrow> (a = b \<Longrightarrow> x = () \<Longrightarrow> P) \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   489
  unfolding eq_pred_eq by (erule if_predE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   490
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   491
lemma not_predI: "\<not> P \<Longrightarrow> eval (not_pred (Pred (\<lambda>u. P))) ()"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   492
  unfolding not_pred_eq eval_pred by (auto intro: singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   493
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   494
lemma not_predI': "\<not> eval P () \<Longrightarrow> eval (not_pred P) ()"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   495
  unfolding not_pred_eq by (auto intro: singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   496
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   497
lemma not_predE: "eval (not_pred (Pred (\<lambda>u. P))) x \<Longrightarrow> (\<not> P \<Longrightarrow> thesis) \<Longrightarrow> thesis"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   498
  unfolding not_pred_eq
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   499
  by (auto split: split_if_asm elim: botE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   500
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   501
lemma not_predE': "eval (not_pred P) x \<Longrightarrow> (\<not> eval P x \<Longrightarrow> thesis) \<Longrightarrow> thesis"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   502
  unfolding not_pred_eq
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   503
  by (auto split: split_if_asm elim: botE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   504
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   505
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   506
subsubsection {* Implementation *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   507
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   508
datatype 'a seq = Empty | Insert "'a" "'a pred" | Join "'a pred" "'a seq"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   509
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   510
primrec pred_of_seq :: "'a seq \<Rightarrow> 'a pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   511
    "pred_of_seq Empty = \<bottom>"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   512
  | "pred_of_seq (Insert x P) = single x \<squnion> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   513
  | "pred_of_seq (Join P xq) = P \<squnion> pred_of_seq xq"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   514
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   515
definition Seq :: "(unit \<Rightarrow> 'a seq) \<Rightarrow> 'a pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   516
  "Seq f = pred_of_seq (f ())"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   517
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   518
code_datatype Seq
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   519
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   520
primrec member :: "'a seq \<Rightarrow> 'a \<Rightarrow> bool"  where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   521
  "member Empty x \<longleftrightarrow> False"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   522
  | "member (Insert y P) x \<longleftrightarrow> x = y \<or> eval P x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   523
  | "member (Join P xq) x \<longleftrightarrow> eval P x \<or> member xq x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   524
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   525
lemma eval_member:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   526
  "member xq = eval (pred_of_seq xq)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   527
proof (induct xq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   528
  case Empty show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   529
  by (auto simp add: expand_fun_eq elim: botE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   530
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   531
  case Insert show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   532
  by (auto simp add: expand_fun_eq elim: supE singleE intro: supI1 supI2 singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   533
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   534
  case Join then show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   535
  by (auto simp add: expand_fun_eq elim: supE intro: supI1 supI2)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   536
qed
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   537
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   538
lemma eval_code [code]: "eval (Seq f) = member (f ())"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   539
  unfolding Seq_def by (rule sym, rule eval_member)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   540
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   541
lemma single_code [code]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   542
  "single x = Seq (\<lambda>u. Insert x \<bottom>)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   543
  unfolding Seq_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   544
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   545
primrec "apply" :: "('a \<Rightarrow> 'b Predicate.pred) \<Rightarrow> 'a seq \<Rightarrow> 'b seq" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   546
    "apply f Empty = Empty"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   547
  | "apply f (Insert x P) = Join (f x) (Join (P \<guillemotright>= f) Empty)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   548
  | "apply f (Join P xq) = Join (P \<guillemotright>= f) (apply f xq)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   549
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   550
lemma apply_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   551
  "pred_of_seq (apply f xq) = pred_of_seq xq \<guillemotright>= f"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   552
proof (induct xq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   553
  case Empty show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   554
    by (simp add: bottom_bind)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   555
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   556
  case Insert show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   557
    by (simp add: single_bind sup_bind)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   558
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   559
  case Join then show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   560
    by (simp add: sup_bind)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   561
qed
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   562
  
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   563
lemma bind_code [code]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   564
  "Seq g \<guillemotright>= f = Seq (\<lambda>u. apply f (g ()))"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   565
  unfolding Seq_def by (rule sym, rule apply_bind)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   566
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   567
lemma bot_set_code [code]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   568
  "\<bottom> = Seq (\<lambda>u. Empty)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   569
  unfolding Seq_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   570
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   571
lemma sup_code [code]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   572
  "Seq f \<squnion> Seq g = Seq (\<lambda>u. case f ()
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   573
    of Empty \<Rightarrow> g ()
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   574
     | Insert x P \<Rightarrow> Insert x (P \<squnion> Seq g)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   575
     | Join P xq \<Rightarrow> Join (Seq g) (Join P xq))" (*FIXME order!?*)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   576
proof (cases "f ()")
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   577
  case Empty
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   578
  thus ?thesis
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   579
    unfolding Seq_def by (simp add: sup_commute [of "\<bottom>"] sup_bot)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   580
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   581
  case Insert
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   582
  thus ?thesis
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   583
    unfolding Seq_def by (simp add: sup_assoc)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   584
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   585
  case Join
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   586
  thus ?thesis
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   587
    unfolding Seq_def by (simp add: sup_commute [of "pred_of_seq (g ())"] sup_assoc)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   588
qed
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   589
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   590
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   591
declare eq_pred_def [code, code del]
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   592
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   593
no_notation
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   594
  inf (infixl "\<sqinter>" 70) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   595
  sup (infixl "\<squnion>" 65) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   596
  Inf ("\<Sqinter>_" [900] 900) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   597
  Sup ("\<Squnion>_" [900] 900) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   598
  top ("\<top>") and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   599
  bot ("\<bottom>") and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   600
  bind (infixl "\<guillemotright>=" 70)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   601
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   602
hide (open) type pred seq
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   603
hide (open) const Pred eval single bind if_pred eq_pred not_pred
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   604
  Empty Insert Join Seq member "apply"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   605
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   606
end