src/HOL/Library/Saturated.thy
author haftmann
Wed, 07 Sep 2011 23:55:40 +0200
changeset 44819 fe33d6655186
child 44848 f4d0b060c7ca
permissions -rw-r--r--
theory of saturated naturals contributed by Peter Gammie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44819
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     1
(* Author: Brian Huffman *)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     2
(* Author: Peter Gammie *)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     3
(* Author: Florian Haftmann *)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     4
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     5
header {* Saturated arithmetic *}
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     6
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     7
theory Saturated
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     8
imports Main "~~/src/HOL/Library/Numeral_Type" "~~/src/HOL/Word/Type_Length"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
     9
begin
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    10
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    11
subsection {* The type of saturated naturals *}
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    12
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    13
typedef (open) ('a::len) sat = "{.. len_of TYPE('a)}"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    14
  morphisms nat_of Abs_sat
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    15
  by auto
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    16
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    17
lemma sat_eqI:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    18
  "nat_of m = nat_of n \<Longrightarrow> m = n"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    19
  by (simp add: nat_of_inject)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    20
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    21
lemma sat_eq_iff:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    22
  "m = n \<longleftrightarrow> nat_of m = nat_of n"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    23
  by (simp add: nat_of_inject)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    24
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    25
lemma Abs_sa_nat_of [code abstype]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    26
  "Abs_sat (nat_of n) = n"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    27
  by (fact nat_of_inverse)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    28
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    29
definition Sat :: "nat \<Rightarrow> 'a::len sat" where
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    30
  "Sat n = Abs_sat (min (len_of TYPE('a)) n)"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    31
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    32
lemma nat_of_Sat [simp]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    33
  "nat_of (Sat n :: ('a::len) sat) = min (len_of TYPE('a)) n"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    34
  unfolding Sat_def by (rule Abs_sat_inverse) simp
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    35
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    36
lemma nat_of_le_len_of [simp]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    37
  "nat_of (n :: ('a::len) sat) \<le> len_of TYPE('a)"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    38
  using nat_of [where x = n] by simp
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    39
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    40
lemma min_len_of_nat_of [simp]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    41
  "min (len_of TYPE('a)) (nat_of (n::('a::len) sat)) = nat_of n"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    42
  by (rule min_max.inf_absorb2 [OF nat_of_le_len_of])
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    43
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    44
lemma min_nat_of_len_of [simp]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    45
  "min (nat_of (n::('a::len) sat)) (len_of TYPE('a)) = nat_of n"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    46
  by (subst min_max.inf.commute) simp
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    47
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    48
lemma Sat_nat_of [simp]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    49
  "Sat (nat_of n) = n"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    50
  by (simp add: Sat_def nat_of_inverse)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    51
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    52
instantiation sat :: (len) linorder
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    53
begin
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    54
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    55
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    56
  less_eq_sat_def: "x \<le> y \<longleftrightarrow> nat_of x \<le> nat_of y"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    57
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    58
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    59
  less_sat_def: "x < y \<longleftrightarrow> nat_of x < nat_of y"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    60
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    61
instance
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    62
by default (auto simp add: less_eq_sat_def less_sat_def not_le sat_eq_iff min_max.le_infI1 nat_mult_commute)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    63
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    64
end
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    65
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    66
instantiation sat :: (len) "{minus, comm_semiring_0, comm_semiring_1}"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    67
begin
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    68
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    69
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    70
  "0 = Sat 0"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    71
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    72
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    73
  "1 = Sat 1"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    74
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    75
lemma nat_of_zero_sat [simp, code abstract]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    76
  "nat_of 0 = 0"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    77
  by (simp add: zero_sat_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    78
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    79
lemma nat_of_one_sat [simp, code abstract]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    80
  "nat_of 1 = min 1 (len_of TYPE('a))"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    81
  by (simp add: one_sat_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    82
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    83
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    84
  "x + y = Sat (nat_of x + nat_of y)"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    85
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    86
lemma nat_of_plus_sat [simp, code abstract]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    87
  "nat_of (x + y) = min (nat_of x + nat_of y) (len_of TYPE('a))"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    88
  by (simp add: plus_sat_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    89
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    90
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    91
  "x - y = Sat (nat_of x - nat_of y)"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    92
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    93
lemma nat_of_minus_sat [simp, code abstract]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    94
  "nat_of (x - y) = nat_of x - nat_of y"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    95
proof -
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    96
  from nat_of_le_len_of [of x] have "nat_of x - nat_of y \<le> len_of TYPE('a)" by arith
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    97
  then show ?thesis by (simp add: minus_sat_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    98
qed
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
    99
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   100
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   101
  "x * y = Sat (nat_of x * nat_of y)"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   102
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   103
lemma nat_of_times_sat [simp, code abstract]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   104
  "nat_of (x * y) = min (nat_of x * nat_of y) (len_of TYPE('a))"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   105
  by (simp add: times_sat_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   106
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   107
instance proof
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   108
  fix a b c :: "('a::len) sat"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   109
  show "a * b * c = a * (b * c)"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   110
  proof(cases "a = 0")
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   111
    case True thus ?thesis by (simp add: sat_eq_iff)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   112
  next
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   113
    case False show ?thesis
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   114
    proof(cases "c = 0")
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   115
      case True thus ?thesis by (simp add: sat_eq_iff)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   116
    next
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   117
      case False with `a \<noteq> 0` show ?thesis
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   118
        by (simp add: sat_eq_iff nat_mult_min_left nat_mult_min_right mult_assoc min_max.inf_assoc min_max.inf_absorb2)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   119
    qed
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   120
  qed
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   121
next
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   122
  fix a :: "('a::len) sat"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   123
  show "1 * a = a"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   124
    apply (simp add: sat_eq_iff)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   125
    apply (metis One_nat_def len_gt_0 less_Suc0 less_zeroE linorder_not_less min_max.le_iff_inf min_nat_of_len_of nat_mult_1_right nat_mult_commute)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   126
    done
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   127
next
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   128
  fix a b c :: "('a::len) sat"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   129
  show "(a + b) * c = a * c + b * c"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   130
  proof(cases "c = 0")
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   131
    case True thus ?thesis by (simp add: sat_eq_iff)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   132
  next
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   133
    case False thus ?thesis
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   134
      by (simp add: sat_eq_iff nat_mult_min_left add_mult_distrib nat_add_min_left nat_add_min_right min_max.inf_assoc min_max.inf_absorb2)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   135
  qed
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   136
qed (simp_all add: sat_eq_iff mult.commute)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   137
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   138
end
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   139
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   140
instantiation sat :: (len) ordered_comm_semiring
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   141
begin
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   142
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   143
instance
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   144
by default (auto simp add: less_eq_sat_def less_sat_def not_le sat_eq_iff min_max.le_infI1 nat_mult_commute)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   145
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   146
end
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   147
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   148
instantiation sat :: (len) number
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   149
begin
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   150
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   151
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   152
  number_of_sat_def [code del]: "number_of = Sat \<circ> nat"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   153
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   154
instance ..
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   155
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   156
end
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   157
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   158
lemma [code abstract]:
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   159
  "nat_of (number_of n :: ('a::len) sat) = min (nat n) (len_of TYPE('a))"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   160
  unfolding number_of_sat_def by simp
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   161
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   162
instance sat :: (len) finite
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   163
proof
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   164
  show "finite (UNIV::'a sat set)"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   165
    unfolding type_definition.univ [OF type_definition_sat]
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   166
    using finite by simp
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   167
qed
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   168
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   169
instantiation sat :: (len) equal
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   170
begin
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   171
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   172
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   173
  "HOL.equal A B \<longleftrightarrow> nat_of A = nat_of B"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   174
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   175
instance proof
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   176
qed (simp add: equal_sat_def nat_of_inject)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   177
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   178
end
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   179
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   180
instantiation sat :: (len) "{bounded_lattice, distrib_lattice}"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   181
begin
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   182
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   183
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   184
  "(inf :: 'a sat \<Rightarrow> 'a sat \<Rightarrow> 'a sat) = min"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   185
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   186
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   187
  "(sup :: 'a sat \<Rightarrow> 'a sat \<Rightarrow> 'a sat) = max"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   188
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   189
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   190
  "bot = (0 :: 'a sat)"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   191
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   192
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   193
  "top = Sat (len_of TYPE('a))"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   194
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   195
instance proof
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   196
qed (simp_all add: inf_sat_def sup_sat_def bot_sat_def top_sat_def min_max.sup_inf_distrib1,
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   197
  simp_all add: less_eq_sat_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   198
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   199
end
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   200
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   201
instantiation sat :: (len) complete_lattice
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   202
begin
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   203
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   204
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   205
  "Inf (A :: 'a sat set) = fold min top A"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   206
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   207
definition
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   208
  "Sup (A :: 'a sat set) = fold max bot A"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   209
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   210
instance proof
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   211
  fix x :: "'a sat"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   212
  fix A :: "'a sat set"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   213
  note finite
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   214
  moreover assume "x \<in> A"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   215
  ultimately have "fold min top A \<le> min x top" by (rule min_max.fold_inf_le_inf)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   216
  then show "Inf A \<le> x" by (simp add: Inf_sat_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   217
next
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   218
  fix z :: "'a sat"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   219
  fix A :: "'a sat set"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   220
  note finite
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   221
  moreover assume z: "\<And>x. x \<in> A \<Longrightarrow> z \<le> x"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   222
  ultimately have "min z top \<le> fold min top A" by (blast intro: min_max.inf_le_fold_inf)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   223
  then show "z \<le> Inf A" by (simp add: Inf_sat_def min_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   224
next
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   225
  fix x :: "'a sat"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   226
  fix A :: "'a sat set"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   227
  note finite
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   228
  moreover assume "x \<in> A"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   229
  ultimately have "max x bot \<le> fold max bot A" by (rule min_max.sup_le_fold_sup)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   230
  then show "x \<le> Sup A" by (simp add: Sup_sat_def)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   231
next
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   232
  fix z :: "'a sat"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   233
  fix A :: "'a sat set"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   234
  note finite
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   235
  moreover assume z: "\<And>x. x \<in> A \<Longrightarrow> x \<le> z"
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   236
  ultimately have "fold max bot A \<le> max z bot" by (blast intro: min_max.fold_sup_le_sup)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   237
  then show "Sup A \<le> z" by (simp add: Sup_sat_def max_def bot_unique)
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   238
qed
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   239
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   240
end
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   241
fe33d6655186 theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff changeset
   242
end