src/HOL/Predicate.thy
author haftmann
Wed, 30 Sep 2009 17:23:00 +0200
changeset 32782 faf347097852
parent 32779 371c7f74282d
child 32883 7cbd93dacef3
permissions -rw-r--r--
moved lemmas about sup on bool to Lattices.thy
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
32779
371c7f74282d tuned headings
haftmann
parents: 32705
diff changeset
    22
subsubsection {* Equality *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    23
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
    24
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
    25
  by (simp add: mem_def)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    26
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    27
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
    28
  by (simp add: expand_fun_eq mem_def)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    29
32779
371c7f74282d tuned headings
haftmann
parents: 32705
diff changeset
    30
371c7f74282d tuned headings
haftmann
parents: 32705
diff changeset
    31
subsubsection {* Order relation *}
371c7f74282d tuned headings
haftmann
parents: 32705
diff changeset
    32
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
    33
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
    34
  by (simp add: mem_def)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    35
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    36
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
    37
  by fast
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    38
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    39
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    40
subsubsection {* Top and bottom elements *}
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    41
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    42
lemma top1I [intro!]: "top x"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    43
  by (simp add: top_fun_eq top_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    44
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    45
lemma top2I [intro!]: "top x y"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    46
  by (simp add: top_fun_eq top_bool_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    47
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    48
lemma bot1E [elim!]: "bot x \<Longrightarrow> P"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    49
  by (simp add: bot_fun_eq bot_bool_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    50
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    51
lemma bot2E [elim!]: "bot x y \<Longrightarrow> P"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    52
  by (simp add: bot_fun_eq bot_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    53
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    54
lemma bot_empty_eq: "bot = (\<lambda>x. x \<in> {})"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    55
  by (auto simp add: expand_fun_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 bot_empty_eq2: "bot = (\<lambda>x y. (x, y) \<in> {})"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    58
  by (auto simp add: expand_fun_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    59
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    60
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
    61
subsubsection {* Binary union *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    62
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    63
lemma sup1_iff: "sup A B x \<longleftrightarrow> A x | B x"
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    64
  by (simp add: sup_fun_eq sup_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    65
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    66
lemma sup2_iff: "sup A B x y \<longleftrightarrow> A x y | B x y"
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    67
  by (simp add: sup_fun_eq sup_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    68
32703
7f9e05b3d0fb removed potentially dangerous rules from pred_set_conv
haftmann
parents: 32601
diff changeset
    69
lemma sup_Un_eq: "sup (\<lambda>x. x \<in> R) (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<union> S)"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    70
  by (simp add: sup1_iff expand_fun_eq)
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    71
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    72
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)"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    73
  by (simp add: sup2_iff expand_fun_eq)
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    74
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    75
lemma sup1I1 [elim?]: "A x \<Longrightarrow> sup A B x"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    76
  by (simp add: sup1_iff)
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 sup2I1 [elim?]: "A x y \<Longrightarrow> sup A B x y"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    79
  by (simp add: sup2_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    80
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
    81
lemma sup1I2 [elim?]: "B x \<Longrightarrow> sup A B x"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    82
  by (simp add: sup1_iff)
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 sup2I2 [elim?]: "B x y \<Longrightarrow> sup A B x y"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    85
  by (simp add: sup2_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    86
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    87
text {*
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    88
  \medskip Classical introduction rule: no commitment to @{text A} vs
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    89
  @{text B}.
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    90
*}
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    91
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    92
lemma sup1CI [intro!]: "(~ B x ==> A x) ==> sup A B x"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    93
  by (auto simp add: sup1_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    94
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    95
lemma sup2CI [intro!]: "(~ B x y ==> A x y) ==> sup A B x y"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    96
  by (auto simp add: sup2_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
    97
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
    98
lemma sup1E [elim!]: "sup A B x ==> (A x ==> P) ==> (B x ==> P) ==> P"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
    99
  by (simp add: sup1_iff) iprover
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   100
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   101
lemma sup2E [elim!]: "sup A B x y ==> (A x y ==> P) ==> (B x y ==> P) ==> P"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   102
  by (simp add: sup2_iff) iprover
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   103
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   104
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   105
subsubsection {* Binary intersection *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   106
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   107
lemma inf1_iff: "inf A B x \<longleftrightarrow> A x \<and> B x"
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   108
  by (simp add: inf_fun_eq inf_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   109
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   110
lemma inf2_iff: "inf A B x y \<longleftrightarrow> A x y \<and> B x y"
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   111
  by (simp add: inf_fun_eq inf_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   112
32703
7f9e05b3d0fb removed potentially dangerous rules from pred_set_conv
haftmann
parents: 32601
diff changeset
   113
lemma inf_Int_eq: "inf (\<lambda>x. x \<in> R) (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<inter> S)"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   114
  by (simp add: inf1_iff expand_fun_eq)
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   115
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   116
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)"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   117
  by (simp add: inf2_iff expand_fun_eq)
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   118
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   119
lemma inf1I [intro!]: "A x ==> B x ==> inf A B x"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   120
  by (simp add: inf1_iff)
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 inf2I [intro!]: "A x y ==> B x y ==> inf A B x y"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   123
  by (simp add: inf2_iff)
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 inf1D1: "inf A B x ==> A x"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   126
  by (simp add: inf1_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   127
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   128
lemma inf2D1: "inf A B x y ==> A x y"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   129
  by (simp add: inf2_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   130
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   131
lemma inf1D2: "inf A B x ==> B x"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   132
  by (simp add: inf1_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   133
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   134
lemma inf2D2: "inf A B x y ==> B x y"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   135
  by (simp add: inf2_iff)
22259
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 inf1E [elim!]: "inf A B x ==> (A x ==> B x ==> P) ==> P"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   138
  by (simp add: inf1_iff)
22259
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 inf2E [elim!]: "inf A B x y ==> (A x y ==> B x y ==> P) ==> P"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   141
  by (simp add: inf2_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   142
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   143
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   144
subsubsection {* Unions of families *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   145
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   146
lemma SUP1_iff: "(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
   147
  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
   148
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   149
lemma SUP2_iff: "(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
   150
  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
   151
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   152
lemma SUP1_I [intro]: "a : A ==> B a b ==> (SUP x:A. B x) b"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   153
  by (auto simp add: SUP1_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   154
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   155
lemma SUP2_I [intro]: "a : A ==> B a b c ==> (SUP x:A. B x) b c"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   156
  by (auto simp add: SUP2_iff)
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   157
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   158
lemma SUP1_E [elim!]: "(SUP x:A. B x) b ==> (!!x. x : A ==> B x b ==> R) ==> R"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   159
  by (auto simp add: SUP1_iff)
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   160
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   161
lemma SUP2_E [elim!]: "(SUP x:A. B x) b c ==> (!!x. x : A ==> B x b c ==> R) ==> R"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   162
  by (auto simp add: SUP2_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   163
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   164
lemma SUP_UN_eq: "(SUP i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (UN i. r i))"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   165
  by (simp add: SUP1_iff expand_fun_eq)
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   166
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   167
lemma SUP_UN_eq2: "(SUP i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (UN i. r i))"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   168
  by (simp add: SUP2_iff expand_fun_eq)
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   169
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   170
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   171
subsubsection {* Intersections of families *}
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   172
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   173
lemma INF1_iff: "(INF x:A. B x) b = (ALL x:A. B x b)"
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   174
  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
   175
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   176
lemma INF2_iff: "(INF x:A. B x) b c = (ALL x:A. B x b c)"
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   177
  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
   178
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   179
lemma INF1_I [intro!]: "(!!x. x : A ==> B x b) ==> (INF x:A. B x) b"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   180
  by (auto simp add: INF1_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   181
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   182
lemma INF2_I [intro!]: "(!!x. x : A ==> B x b c) ==> (INF x:A. B x) b c"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   183
  by (auto simp add: INF2_iff)
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   184
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   185
lemma INF1_D [elim]: "(INF x:A. B x) b ==> a : A ==> B a b"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   186
  by (auto simp add: INF1_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   187
22430
6a56bf1b3a64 Generalized version of SUP and INF (with index set).
berghofe
parents: 22422
diff changeset
   188
lemma INF2_D [elim]: "(INF x:A. B x) b c ==> a : A ==> B a b c"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   189
  by (auto simp add: INF2_iff)
22430
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 INF1_E [elim]: "(INF x:A. B x) b ==> (B a b ==> R) ==> (a ~: A ==> R) ==> R"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   192
  by (auto simp add: INF1_iff)
22430
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 INF2_E [elim]: "(INF x:A. B x) b c ==> (B a b c ==> R) ==> (a ~: A ==> R) ==> R"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   195
  by (auto simp add: INF2_iff)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   196
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   197
lemma INF_INT_eq: "(INF i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (INT i. r i))"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   198
  by (simp add: INF1_iff expand_fun_eq)
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   199
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   200
lemma INF_INT_eq2: "(INF i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (INT i. r i))"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   201
  by (simp add: INF2_iff expand_fun_eq)
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   202
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   203
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   204
subsection {* Predicates as relations *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   205
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   206
subsubsection {* Composition  *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   207
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   208
inductive
32235
8f9b8d14fc9f "more standard" argument order of relation composition (op O)
krauss
parents: 31932
diff changeset
   209
  pred_comp  :: "['a => 'b => bool, 'b => 'c => bool] => 'a => 'c => bool"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   210
    (infixr "OO" 75)
32235
8f9b8d14fc9f "more standard" argument order of relation composition (op O)
krauss
parents: 31932
diff changeset
   211
  for r :: "'a => 'b => bool" and s :: "'b => 'c => bool"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   212
where
32235
8f9b8d14fc9f "more standard" argument order of relation composition (op O)
krauss
parents: 31932
diff changeset
   213
  pred_compI [intro]: "r a b ==> s b c ==> (r OO s) a c"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   214
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   215
inductive_cases pred_compE [elim!]: "(r OO s) a c"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   216
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   217
lemma pred_comp_rel_comp_eq [pred_set_conv]:
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   218
  "((\<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
   219
  by (auto simp add: expand_fun_eq elim: pred_compE)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   220
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   221
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   222
subsubsection {* Converse *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   223
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   224
inductive
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   225
  conversep :: "('a => 'b => bool) => 'b => 'a => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   226
    ("(_^--1)" [1000] 1000)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   227
  for r :: "'a => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   228
where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   229
  conversepI: "r a b ==> r^--1 b a"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   230
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   231
notation (xsymbols)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   232
  conversep  ("(_\<inverse>\<inverse>)" [1000] 1000)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   233
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   234
lemma conversepD:
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   235
  assumes ab: "r^--1 a b"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   236
  shows "r b a" using ab
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   237
  by cases simp
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   238
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   239
lemma conversep_iff [iff]: "r^--1 a b = r b a"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   240
  by (iprover intro: conversepI dest: conversepD)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   241
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   242
lemma conversep_converse_eq [pred_set_conv]:
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   243
  "(\<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
   244
  by (auto simp add: expand_fun_eq)
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
lemma conversep_conversep [simp]: "(r^--1)^--1 = r"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   247
  by (iprover intro: order_antisym conversepI dest: conversepD)
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 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
   250
  by (iprover intro: order_antisym conversepI pred_compI
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   251
    elim: pred_compE dest: conversepD)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   252
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   253
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
   254
  by (simp add: inf_fun_eq inf_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   255
    (iprover intro: conversepI ext dest: conversepD)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   256
22422
ee19cdb07528 stepping towards uniform lattice theory development in HOL
haftmann
parents: 22259
diff changeset
   257
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
   258
  by (simp add: sup_fun_eq sup_bool_eq)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   259
    (iprover intro: conversepI ext dest: conversepD)
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_noteq [simp]: "(op ~=)^--1 = op ~="
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   262
  by (auto simp add: expand_fun_eq)
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 conversep_eq [simp]: "(op =)^--1 = op ="
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   265
  by (auto simp add: expand_fun_eq)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   266
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   267
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   268
subsubsection {* Domain *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   269
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   270
inductive
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   271
  DomainP :: "('a => 'b => bool) => 'a => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   272
  for r :: "'a => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   273
where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   274
  DomainPI [intro]: "r a b ==> DomainP r a"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   275
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   276
inductive_cases DomainPE [elim!]: "DomainP r a"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   277
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   278
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
   279
  by (blast intro!: Orderings.order_antisym predicate1I)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   280
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   281
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   282
subsubsection {* Range *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   283
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   284
inductive
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   285
  RangeP :: "('a => 'b => bool) => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   286
  for r :: "'a => 'b => bool"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   287
where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   288
  RangePI [intro]: "r a b ==> RangeP r b"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   289
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   290
inductive_cases RangePE [elim!]: "RangeP r b"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   291
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   292
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
   293
  by (blast intro!: Orderings.order_antisym predicate1I)
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   294
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   295
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   296
subsubsection {* Inverse image *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   297
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   298
definition
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   299
  inv_imagep :: "('b => 'b => bool) => ('a => 'b) => 'a => 'a => bool" where
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   300
  "inv_imagep r f == %x y. r (f x) (f y)"
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   301
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   302
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
   303
  by (simp add: inv_image_def inv_imagep_def)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   304
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   305
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
   306
  by (simp add: inv_imagep_def)
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   307
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   308
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   309
subsubsection {* Powerset *}
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   310
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   311
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
   312
  "Powp A == \<lambda>B. \<forall>x \<in> B. A x"
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   313
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   314
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
   315
  by (auto simp add: Powp_def expand_fun_eq)
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   316
26797
a6cb51c314f2 - Added mem_def and predicate1I in some of the proofs
berghofe
parents: 24345
diff changeset
   317
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
   318
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   319
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   320
subsubsection {* Properties of relations *}
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   321
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   322
abbreviation antisymP :: "('a => 'a => bool) => bool" where
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   323
  "antisymP r == antisym {(x, y). r x y}"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   324
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   325
abbreviation transP :: "('a => 'a => bool) => bool" where
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   326
  "transP r == trans {(x, y). r x y}"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   327
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   328
abbreviation single_valuedP :: "('a => 'b => bool) => bool" where
23741
1801a921df13 - Moved infrastructure for converting between sets and predicates
berghofe
parents: 23708
diff changeset
   329
  "single_valuedP r == single_valued {(x, y). r x y}"
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   330
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   331
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   332
subsection {* Predicates as enumerations *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   333
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   334
subsubsection {* The type of predicate enumerations (a monad) *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   335
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   336
datatype 'a pred = Pred "'a \<Rightarrow> bool"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   337
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   338
primrec eval :: "'a pred \<Rightarrow> 'a \<Rightarrow> bool" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   339
  eval_pred: "eval (Pred f) = f"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   340
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   341
lemma Pred_eval [simp]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   342
  "Pred (eval x) = x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   343
  by (cases x) simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   344
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   345
lemma eval_inject: "eval x = eval y \<longleftrightarrow> x = y"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   346
  by (cases x) auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   347
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   348
definition single :: "'a \<Rightarrow> 'a pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   349
  "single x = Pred ((op =) x)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   350
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   351
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
   352
  "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
   353
32578
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   354
instantiation pred :: (type) "{complete_lattice, boolean_algebra}"
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   355
begin
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   356
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   357
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   358
  "P \<le> Q \<longleftrightarrow> eval P \<le> eval Q"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   359
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   360
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   361
  "P < Q \<longleftrightarrow> eval P < eval Q"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   362
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   363
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   364
  "\<bottom> = Pred \<bottom>"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   365
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   366
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   367
  "\<top> = Pred \<top>"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   368
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   369
definition
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   370
  "P \<sqinter> Q = Pred (eval P \<sqinter> eval Q)"
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 \<squnion> Q = Pred (eval P \<squnion> 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
31932
685e7b450ab5 avoid useless code equations
haftmann
parents: 31222
diff changeset
   376
  [code del]: "\<Sqinter>A = Pred (INFI A eval)"
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   377
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   378
definition
31932
685e7b450ab5 avoid useless code equations
haftmann
parents: 31222
diff changeset
   379
  [code del]: "\<Squnion>A = Pred (SUPR A eval)"
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   380
32578
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   381
definition
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   382
  "- P = Pred (- eval P)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   383
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   384
definition
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   385
  "P - Q = Pred (eval P - eval Q)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   386
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   387
instance proof
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   388
qed (auto simp add: less_eq_pred_def less_pred_def
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   389
    inf_pred_def sup_pred_def bot_pred_def top_pred_def
32578
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   390
    Inf_pred_def Sup_pred_def uminus_pred_def minus_pred_def fun_Compl_def bool_Compl_def,
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   391
    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
   392
    eval_inject mem_def)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   393
22259
476604be7d88 New theory for converting between predicates and sets.
berghofe
parents:
diff changeset
   394
end
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   395
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   396
lemma bind_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   397
  "(P \<guillemotright>= Q) \<guillemotright>= R = P \<guillemotright>= (\<lambda>x. Q x \<guillemotright>= R)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   398
  by (auto simp add: bind_def expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   399
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   400
lemma bind_single:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   401
  "P \<guillemotright>= single = P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   402
  by (simp add: bind_def single_def)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   403
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   404
lemma single_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   405
  "single x \<guillemotright>= P = P x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   406
  by (simp add: bind_def single_def)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   407
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   408
lemma bottom_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   409
  "\<bottom> \<guillemotright>= P = \<bottom>"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   410
  by (auto simp add: bot_pred_def bind_def expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   411
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   412
lemma sup_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   413
  "(P \<squnion> Q) \<guillemotright>= R = P \<guillemotright>= R \<squnion> Q \<guillemotright>= R"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   414
  by (auto simp add: bind_def sup_pred_def expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   415
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   416
lemma Sup_bind: "(\<Squnion>A \<guillemotright>= f) = \<Squnion>((\<lambda>x. x \<guillemotright>= f) ` A)"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   417
  by (auto simp add: bind_def Sup_pred_def SUP1_iff expand_fun_eq)
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   418
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   419
lemma pred_iffI:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   420
  assumes "\<And>x. eval A x \<Longrightarrow> eval B x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   421
  and "\<And>x. eval B x \<Longrightarrow> eval A x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   422
  shows "A = B"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   423
proof -
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   424
  from assms have "\<And>x. eval A x \<longleftrightarrow> eval B x" by blast
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   425
  then show ?thesis by (cases A, cases B) (simp add: expand_fun_eq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   426
qed
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   427
  
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   428
lemma singleI: "eval (single x) x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   429
  unfolding single_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   430
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   431
lemma singleI_unit: "eval (single ()) x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   432
  by simp (rule singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   433
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   434
lemma singleE: "eval (single x) y \<Longrightarrow> (y = x \<Longrightarrow> P) \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   435
  unfolding single_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   436
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   437
lemma singleE': "eval (single x) y \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   438
  by (erule singleE) simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   439
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   440
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
   441
  unfolding bind_def by auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   442
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   443
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
   444
  unfolding bind_def by auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   445
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   446
lemma botE: "eval \<bottom> x \<Longrightarrow> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   447
  unfolding bot_pred_def by auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   448
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   449
lemma supI1: "eval A x \<Longrightarrow> eval (A \<squnion> B) x"
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   450
  unfolding sup_pred_def by (simp add: sup1_iff)
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   451
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   452
lemma supI2: "eval B x \<Longrightarrow> eval (A \<squnion> B) x" 
32601
47d0c967c64e be more cautious wrt. simp rules: sup1_iff, sup2_iff, inf1_iff, inf2_iff, SUP1_iff, SUP2_iff, INF1_iff, INF2_iff are no longer simp by default
haftmann
parents: 32582
diff changeset
   453
  unfolding sup_pred_def by (simp add: sup1_iff)
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   454
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   455
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
   456
  unfolding sup_pred_def by auto
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   457
32578
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   458
lemma single_not_bot [simp]:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   459
  "single x \<noteq> \<bottom>"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   460
  by (auto simp add: single_def bot_pred_def expand_fun_eq)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   461
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   462
lemma not_bot:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   463
  assumes "A \<noteq> \<bottom>"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   464
  obtains x where "eval A x"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   465
using assms by (cases A)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   466
  (auto simp add: bot_pred_def, auto simp add: mem_def)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   467
  
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   468
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   469
subsubsection {* Emptiness check and definite choice *}
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   470
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   471
definition is_empty :: "'a pred \<Rightarrow> bool" where
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   472
  "is_empty A \<longleftrightarrow> A = \<bottom>"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   473
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   474
lemma is_empty_bot:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   475
  "is_empty \<bottom>"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   476
  by (simp add: is_empty_def)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   477
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   478
lemma not_is_empty_single:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   479
  "\<not> is_empty (single x)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   480
  by (auto simp add: is_empty_def single_def bot_pred_def expand_fun_eq)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   481
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   482
lemma is_empty_sup:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   483
  "is_empty (A \<squnion> B) \<longleftrightarrow> is_empty A \<and> is_empty B"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   484
  by (auto simp add: is_empty_def intro: sup_eq_bot_eq1 sup_eq_bot_eq2)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   485
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   486
definition singleton :: "'a pred \<Rightarrow> 'a" where
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   487
  "singleton A = (if \<exists>!x. eval A x then THE x. eval A x else undefined)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   488
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   489
lemma singleton_eqI:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   490
  "\<exists>!x. eval A x \<Longrightarrow> eval A x \<Longrightarrow> singleton A = x"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   491
  by (auto simp add: singleton_def)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   492
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   493
lemma eval_singletonI:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   494
  "\<exists>!x. eval A x \<Longrightarrow> eval A (singleton A)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   495
proof -
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   496
  assume assm: "\<exists>!x. eval A x"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   497
  then obtain x where "eval A x" ..
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   498
  moreover with assm have "singleton A = x" by (rule singleton_eqI)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   499
  ultimately show ?thesis by simp 
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   500
qed
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   501
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   502
lemma single_singleton:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   503
  "\<exists>!x. eval A x \<Longrightarrow> single (singleton A) = A"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   504
proof -
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   505
  assume assm: "\<exists>!x. eval A x"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   506
  then have "eval A (singleton A)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   507
    by (rule eval_singletonI)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   508
  moreover from assm have "\<And>x. eval A x \<Longrightarrow> singleton A = x"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   509
    by (rule singleton_eqI)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   510
  ultimately have "eval (single (singleton A)) = eval A"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   511
    by (simp (no_asm_use) add: single_def expand_fun_eq) blast
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   512
  then show ?thesis by (simp add: eval_inject)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   513
qed
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   514
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   515
lemma singleton_undefinedI:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   516
  "\<not> (\<exists>!x. eval A x) \<Longrightarrow> singleton A = undefined"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   517
  by (simp add: singleton_def)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   518
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   519
lemma singleton_bot:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   520
  "singleton \<bottom> = undefined"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   521
  by (auto simp add: bot_pred_def intro: singleton_undefinedI)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   522
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   523
lemma singleton_single:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   524
  "singleton (single x) = x"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   525
  by (auto simp add: intro: singleton_eqI singleI elim: singleE)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   526
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   527
lemma singleton_sup_single_single:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   528
  "singleton (single x \<squnion> single y) = (if x = y then x else undefined)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   529
proof (cases "x = y")
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   530
  case True then show ?thesis by (simp add: singleton_single)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   531
next
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   532
  case False
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   533
  have "eval (single x \<squnion> single y) x"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   534
    and "eval (single x \<squnion> single y) y"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   535
  by (auto intro: supI1 supI2 singleI)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   536
  with False have "\<not> (\<exists>!z. eval (single x \<squnion> single y) z)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   537
    by blast
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   538
  then have "singleton (single x \<squnion> single y) = undefined"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   539
    by (rule singleton_undefinedI)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   540
  with False show ?thesis by simp
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   541
qed
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   542
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   543
lemma singleton_sup_aux:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   544
  "singleton (A \<squnion> B) = (if A = \<bottom> then singleton B
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   545
    else if B = \<bottom> then singleton A
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   546
    else singleton
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   547
      (single (singleton A) \<squnion> single (singleton B)))"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   548
proof (cases "(\<exists>!x. eval A x) \<and> (\<exists>!y. eval B y)")
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   549
  case True then show ?thesis by (simp add: single_singleton)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   550
next
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   551
  case False
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   552
  from False have A_or_B:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   553
    "singleton A = undefined \<or> singleton B = undefined"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   554
    by (auto intro!: singleton_undefinedI)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   555
  then have rhs: "singleton
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   556
    (single (singleton A) \<squnion> single (singleton B)) = undefined"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   557
    by (auto simp add: singleton_sup_single_single singleton_single)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   558
  from False have not_unique:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   559
    "\<not> (\<exists>!x. eval A x) \<or> \<not> (\<exists>!y. eval B y)" by simp
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   560
  show ?thesis proof (cases "A \<noteq> \<bottom> \<and> B \<noteq> \<bottom>")
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   561
    case True
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   562
    then obtain a b where a: "eval A a" and b: "eval B b"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   563
      by (blast elim: not_bot)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   564
    with True not_unique have "\<not> (\<exists>!x. eval (A \<squnion> B) x)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   565
      by (auto simp add: sup_pred_def bot_pred_def)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   566
    then have "singleton (A \<squnion> B) = undefined" by (rule singleton_undefinedI)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   567
    with True rhs show ?thesis by simp
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   568
  next
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   569
    case False then show ?thesis by auto
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   570
  qed
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   571
qed
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   572
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   573
lemma singleton_sup:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   574
  "singleton (A \<squnion> B) = (if A = \<bottom> then singleton B
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   575
    else if B = \<bottom> then singleton A
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   576
    else if singleton A = singleton B then singleton A else undefined)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   577
using singleton_sup_aux [of A B] by (simp only: singleton_sup_single_single)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   578
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   579
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   580
subsubsection {* Derived operations *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   581
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   582
definition if_pred :: "bool \<Rightarrow> unit pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   583
  if_pred_eq: "if_pred b = (if b then single () else \<bottom>)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   584
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   585
definition not_pred :: "unit pred \<Rightarrow> unit pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   586
  not_pred_eq: "not_pred P = (if eval P () then \<bottom> else single ())"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   587
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   588
lemma if_predI: "P \<Longrightarrow> eval (if_pred P) ()"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   589
  unfolding if_pred_eq by (auto intro: singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   590
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   591
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
   592
  unfolding if_pred_eq by (cases b) (auto elim: botE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   593
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   594
lemma not_predI: "\<not> P \<Longrightarrow> eval (not_pred (Pred (\<lambda>u. P))) ()"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   595
  unfolding not_pred_eq eval_pred by (auto intro: singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   596
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   597
lemma not_predI': "\<not> eval P () \<Longrightarrow> eval (not_pred P) ()"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   598
  unfolding not_pred_eq by (auto intro: singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   599
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   600
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
   601
  unfolding not_pred_eq
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   602
  by (auto split: split_if_asm elim: botE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   603
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   604
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
   605
  unfolding not_pred_eq
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   606
  by (auto split: split_if_asm elim: botE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   607
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   608
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   609
subsubsection {* Implementation *}
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   610
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   611
datatype 'a seq = Empty | Insert "'a" "'a pred" | Join "'a pred" "'a seq"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   612
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   613
primrec pred_of_seq :: "'a seq \<Rightarrow> 'a pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   614
    "pred_of_seq Empty = \<bottom>"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   615
  | "pred_of_seq (Insert x P) = single x \<squnion> P"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   616
  | "pred_of_seq (Join P xq) = P \<squnion> pred_of_seq xq"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   617
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   618
definition Seq :: "(unit \<Rightarrow> 'a seq) \<Rightarrow> 'a pred" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   619
  "Seq f = pred_of_seq (f ())"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   620
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   621
code_datatype Seq
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   622
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   623
primrec member :: "'a seq \<Rightarrow> 'a \<Rightarrow> bool"  where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   624
  "member Empty x \<longleftrightarrow> False"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   625
  | "member (Insert y P) x \<longleftrightarrow> x = y \<or> eval P x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   626
  | "member (Join P xq) x \<longleftrightarrow> eval P x \<or> member xq x"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   627
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   628
lemma eval_member:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   629
  "member xq = eval (pred_of_seq xq)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   630
proof (induct xq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   631
  case Empty show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   632
  by (auto simp add: expand_fun_eq elim: botE)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   633
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   634
  case Insert show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   635
  by (auto simp add: expand_fun_eq elim: supE singleE intro: supI1 supI2 singleI)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   636
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   637
  case Join then show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   638
  by (auto simp add: expand_fun_eq elim: supE intro: supI1 supI2)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   639
qed
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   640
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   641
lemma eval_code [code]: "eval (Seq f) = member (f ())"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   642
  unfolding Seq_def by (rule sym, rule eval_member)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   643
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   644
lemma single_code [code]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   645
  "single x = Seq (\<lambda>u. Insert x \<bottom>)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   646
  unfolding Seq_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   647
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   648
primrec "apply" :: "('a \<Rightarrow> 'b Predicate.pred) \<Rightarrow> 'a seq \<Rightarrow> 'b seq" where
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   649
    "apply f Empty = Empty"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   650
  | "apply f (Insert x P) = Join (f x) (Join (P \<guillemotright>= f) Empty)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   651
  | "apply f (Join P xq) = Join (P \<guillemotright>= f) (apply f xq)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   652
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   653
lemma apply_bind:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   654
  "pred_of_seq (apply f xq) = pred_of_seq xq \<guillemotright>= f"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   655
proof (induct xq)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   656
  case Empty show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   657
    by (simp add: bottom_bind)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   658
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   659
  case Insert show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   660
    by (simp add: single_bind sup_bind)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   661
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   662
  case Join then show ?case
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   663
    by (simp add: sup_bind)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   664
qed
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   665
  
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   666
lemma bind_code [code]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   667
  "Seq g \<guillemotright>= f = Seq (\<lambda>u. apply f (g ()))"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   668
  unfolding Seq_def by (rule sym, rule apply_bind)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   669
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   670
lemma bot_set_code [code]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   671
  "\<bottom> = Seq (\<lambda>u. Empty)"
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   672
  unfolding Seq_def by simp
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   673
30376
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   674
primrec adjunct :: "'a pred \<Rightarrow> 'a seq \<Rightarrow> 'a seq" where
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   675
    "adjunct P Empty = Join P Empty"
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   676
  | "adjunct P (Insert x Q) = Insert x (Q \<squnion> P)"
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   677
  | "adjunct P (Join Q xq) = Join Q (adjunct P xq)"
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   678
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   679
lemma adjunct_sup:
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   680
  "pred_of_seq (adjunct P xq) = P \<squnion> pred_of_seq xq"
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   681
  by (induct xq) (simp_all add: sup_assoc sup_commute sup_left_commute)
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   682
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   683
lemma sup_code [code]:
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   684
  "Seq f \<squnion> Seq g = Seq (\<lambda>u. case f ()
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   685
    of Empty \<Rightarrow> g ()
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   686
     | Insert x P \<Rightarrow> Insert x (P \<squnion> Seq g)
30376
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   687
     | Join P xq \<Rightarrow> adjunct (Seq g) (Join P xq))"
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   688
proof (cases "f ()")
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   689
  case Empty
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   690
  thus ?thesis
30376
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   691
    unfolding Seq_def by (simp add: sup_commute [of "\<bottom>"]  sup_bot)
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   692
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   693
  case Insert
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   694
  thus ?thesis
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   695
    unfolding Seq_def by (simp add: sup_assoc)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   696
next
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   697
  case Join
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   698
  thus ?thesis
30376
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   699
    unfolding Seq_def
e8cc806a3755 refined enumeration implementation
haftmann
parents: 30328
diff changeset
   700
    by (simp add: adjunct_sup sup_assoc sup_commute sup_left_commute)
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   701
qed
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   702
30430
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   703
primrec contained :: "'a seq \<Rightarrow> 'a pred \<Rightarrow> bool" where
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   704
    "contained Empty Q \<longleftrightarrow> True"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   705
  | "contained (Insert x P) Q \<longleftrightarrow> eval Q x \<and> P \<le> Q"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   706
  | "contained (Join P xq) Q \<longleftrightarrow> P \<le> Q \<and> contained xq Q"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   707
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   708
lemma single_less_eq_eval:
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   709
  "single x \<le> P \<longleftrightarrow> eval P x"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   710
  by (auto simp add: single_def less_eq_pred_def mem_def)
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   711
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   712
lemma contained_less_eq:
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   713
  "contained xq Q \<longleftrightarrow> pred_of_seq xq \<le> Q"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   714
  by (induct xq) (simp_all add: single_less_eq_eval)
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   715
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   716
lemma less_eq_pred_code [code]:
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   717
  "Seq f \<le> Q = (case f ()
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   718
   of Empty \<Rightarrow> True
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   719
    | Insert x P \<Rightarrow> eval Q x \<and> P \<le> Q
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   720
    | Join P xq \<Rightarrow> P \<le> Q \<and> contained xq Q)"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   721
  by (cases "f ()")
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   722
    (simp_all add: Seq_def single_less_eq_eval contained_less_eq)
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   723
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   724
lemma eq_pred_code [code]:
31133
a9f728dc5c8e dropped sort constraint on predicate equality
haftmann
parents: 31122
diff changeset
   725
  fixes P Q :: "'a pred"
30430
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   726
  shows "eq_class.eq P Q \<longleftrightarrow> P \<le> Q \<and> Q \<le> P"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   727
  unfolding eq by auto
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   728
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   729
lemma [code]:
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   730
  "pred_case f P = f (eval P)"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   731
  by (cases P) simp
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   732
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   733
lemma [code]:
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   734
  "pred_rec f P = f (eval P)"
42ea5d85edcc explicit code equations for some rarely used pred operations
haftmann
parents: 30378
diff changeset
   735
  by (cases P) simp
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   736
31105
95f66b234086 added general preprocessing of equality in predicates for code generation
bulwahn
parents: 30430
diff changeset
   737
inductive eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" where "eq x x"
95f66b234086 added general preprocessing of equality in predicates for code generation
bulwahn
parents: 30430
diff changeset
   738
95f66b234086 added general preprocessing of equality in predicates for code generation
bulwahn
parents: 30430
diff changeset
   739
lemma eq_is_eq: "eq x y \<equiv> (x = y)"
31108
haftmann
parents: 31106 30959
diff changeset
   740
  by (rule eq_reflection) (auto intro: eq.intros elim: eq.cases)
30948
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   741
31216
29da4d396e1f added Predicate.map
haftmann
parents: 31133
diff changeset
   742
definition map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a pred \<Rightarrow> 'b pred" where
29da4d396e1f added Predicate.map
haftmann
parents: 31133
diff changeset
   743
  "map f P = P \<guillemotright>= (single o f)"
29da4d396e1f added Predicate.map
haftmann
parents: 31133
diff changeset
   744
32578
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   745
primrec null :: "'a seq \<Rightarrow> bool" where
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   746
    "null Empty \<longleftrightarrow> True"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   747
  | "null (Insert x P) \<longleftrightarrow> False"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   748
  | "null (Join P xq) \<longleftrightarrow> is_empty P \<and> null xq"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   749
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   750
lemma null_is_empty:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   751
  "null xq \<longleftrightarrow> is_empty (pred_of_seq xq)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   752
  by (induct xq) (simp_all add: is_empty_bot not_is_empty_single is_empty_sup)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   753
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   754
lemma is_empty_code [code]:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   755
  "is_empty (Seq f) \<longleftrightarrow> null (f ())"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   756
  by (simp add: null_is_empty Seq_def)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   757
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   758
primrec the_only :: "'a seq \<Rightarrow> 'a" where
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   759
  [code del]: "the_only Empty = undefined"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   760
  | "the_only (Insert x P) = (if is_empty P then x else let y = singleton P in if x = y then x else undefined)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   761
  | "the_only (Join P xq) = (if is_empty P then the_only xq else if null xq then singleton P
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   762
       else let x = singleton P; y = the_only xq in
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   763
       if x = y then x else undefined)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   764
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   765
lemma the_only_singleton:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   766
  "the_only xq = singleton (pred_of_seq xq)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   767
  by (induct xq)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   768
    (auto simp add: singleton_bot singleton_single is_empty_def
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   769
    null_is_empty Let_def singleton_sup)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   770
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   771
lemma singleton_code [code]:
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   772
  "singleton (Seq f) = (case f ()
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   773
   of Empty \<Rightarrow> undefined
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   774
    | Insert x P \<Rightarrow> if is_empty P then x
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   775
        else let y = singleton P in
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   776
          if x = y then x else undefined
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   777
    | Join P xq \<Rightarrow> if is_empty P then the_only xq
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   778
        else if null xq then singleton P
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   779
        else let x = singleton P; y = the_only xq in
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   780
          if x = y then x else undefined)"
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   781
  by (cases "f ()")
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   782
   (auto simp add: Seq_def the_only_singleton is_empty_def
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   783
      null_is_empty singleton_bot singleton_single singleton_sup Let_def)
22117a76f943 added emptiness check predicate and singleton projection
haftmann
parents: 32372
diff changeset
   784
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32601
diff changeset
   785
lemma meta_fun_cong:
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32601
diff changeset
   786
"f == g ==> f x == g x"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32601
diff changeset
   787
by simp
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32601
diff changeset
   788
30948
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   789
ML {*
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   790
signature PREDICATE =
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   791
sig
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   792
  datatype 'a pred = Seq of (unit -> 'a seq)
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   793
  and 'a seq = Empty | Insert of 'a * 'a pred | Join of 'a pred * 'a seq
30959
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   794
  val yield: 'a pred -> ('a * 'a pred) option
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   795
  val yieldn: int -> 'a pred -> 'a list * 'a pred
31222
4a84ae57b65f added Predicate.map in SML environment
haftmann
parents: 31216
diff changeset
   796
  val map: ('a -> 'b) -> 'a pred -> 'b pred
30948
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   797
end;
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   798
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   799
structure Predicate : PREDICATE =
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   800
struct
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   801
30959
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   802
@{code_datatype pred = Seq};
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   803
@{code_datatype seq = Empty | Insert | Join};
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   804
32372
b0d2b49bfaed formally stylized
haftmann
parents: 32235
diff changeset
   805
fun yield (@{code Seq} f) = next (f ())
30959
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   806
and next @{code Empty} = NONE
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   807
  | next (@{code Insert} (x, P)) = SOME (x, P)
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   808
  | next (@{code Join} (P, xq)) = (case yield P
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   809
     of NONE => next xq
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   810
      | SOME (x, Q) => SOME (x, @{code Seq} (fn _ => @{code Join} (Q, xq))))
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   811
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   812
fun anamorph f k x = (if k = 0 then ([], x)
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   813
  else case f x
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   814
   of NONE => ([], x)
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   815
    | SOME (v, y) => let
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   816
        val (vs, z) = anamorph f (k - 1) y
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   817
      in (v :: vs, z) end)
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   818
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   819
fun yieldn P = anamorph yield P;
30948
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   820
31222
4a84ae57b65f added Predicate.map in SML environment
haftmann
parents: 31216
diff changeset
   821
fun map f = @{code map} f;
4a84ae57b65f added Predicate.map in SML environment
haftmann
parents: 31216
diff changeset
   822
30948
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   823
end;
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   824
*}
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   825
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   826
code_reserved Eval Predicate
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   827
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   828
code_type pred and seq
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   829
  (Eval "_/ Predicate.pred" and "_/ Predicate.seq")
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   830
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   831
code_const Seq and Empty and Insert and Join
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   832
  (Eval "Predicate.Seq" and "Predicate.Empty" and "Predicate.Insert/ (_,/ _)" and "Predicate.Join/ (_,/ _)")
7f699568a877 static compilation of enumeration type
haftmann
parents: 30430
diff changeset
   833
31122
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   834
text {* dummy setup for @{text code_pred} and @{text values} keywords *}
31108
haftmann
parents: 31106 30959
diff changeset
   835
haftmann
parents: 31106 30959
diff changeset
   836
ML {*
31122
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   837
local
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   838
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   839
structure P = OuterParse;
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   840
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   841
val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   842
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   843
in
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   844
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   845
val _ = OuterSyntax.local_theory_to_proof "code_pred" "sets up goal for cases rule from given introduction rules and compiles predicate"
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   846
  OuterKeyword.thy_goal (P.term_group >> (K (Proof.theorem_i NONE (K I) [[]])));
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   847
31216
29da4d396e1f added Predicate.map
haftmann
parents: 31133
diff changeset
   848
val _ = OuterSyntax.improper_command "values" "enumerate and print comprehensions"
31122
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   849
  OuterKeyword.diag ((opt_modes -- P.term)
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   850
    >> (fn (modes, t) => Toplevel.no_timing o Toplevel.keep
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   851
        (K ())));
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   852
3ef6f93180ef added dummy values keyword
haftmann
parents: 31109
diff changeset
   853
end
31108
haftmann
parents: 31106 30959
diff changeset
   854
*}
30959
458e55fd0a33 fixed compilation of predicate types in ML environment
haftmann
parents: 30948
diff changeset
   855
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   856
no_notation
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   857
  inf (infixl "\<sqinter>" 70) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   858
  sup (infixl "\<squnion>" 65) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   859
  Inf ("\<Sqinter>_" [900] 900) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   860
  Sup ("\<Squnion>_" [900] 900) and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   861
  top ("\<top>") and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   862
  bot ("\<bottom>") and
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   863
  bind (infixl "\<guillemotright>=" 70)
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   864
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   865
hide (open) type pred seq
32582
a382876d3290 hide new constants
haftmann
parents: 32578
diff changeset
   866
hide (open) const Pred eval single bind is_empty singleton if_pred not_pred
a382876d3290 hide new constants
haftmann
parents: 32578
diff changeset
   867
  Empty Insert Join Seq member pred_of_seq "apply" adjunct null the_only eq map
30328
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   868
ab47f43f7581 added enumeration of predicates
haftmann
parents: 26797
diff changeset
   869
end