author | wenzelm |
Fri, 21 Mar 2025 22:26:18 +0100 | |
changeset 82317 | 231b6d8231c6 |
parent 82246 | 3505a7b02fc2 |
permissions | -rw-r--r-- |
45692 | 1 |
(* Title: HOL/Library/Saturated.thy |
2 |
Author: Brian Huffman |
|
3 |
Author: Peter Gammie |
|
4 |
Author: Florian Haftmann |
|
5 |
*) |
|
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
6 |
|
60500 | 7 |
section \<open>Saturated arithmetic\<close> |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
8 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
9 |
theory Saturated |
63762 | 10 |
imports Numeral_Type Type_Length |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
11 |
begin |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
12 |
|
60500 | 13 |
subsection \<open>The type of saturated naturals\<close> |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
14 |
|
70185 | 15 |
typedef (overloaded) ('a::len) sat = "{.. LENGTH('a)}" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
16 |
morphisms nat_of Abs_sat |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
17 |
by auto |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
18 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
19 |
lemma sat_eqI: |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
20 |
"nat_of m = nat_of n \<Longrightarrow> m = n" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
21 |
by (simp add: nat_of_inject) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
22 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
23 |
lemma sat_eq_iff: |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
24 |
"m = n \<longleftrightarrow> nat_of m = nat_of n" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
25 |
by (simp add: nat_of_inject) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
26 |
|
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
27 |
lemma Abs_sat_nat_of [code abstype]: |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
28 |
"Abs_sat (nat_of n) = n" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
29 |
by (fact nat_of_inverse) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
30 |
|
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
31 |
definition Abs_sat' :: "nat \<Rightarrow> 'a::len sat" where |
70185 | 32 |
"Abs_sat' n = Abs_sat (min (LENGTH('a)) n)" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
33 |
|
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
34 |
lemma nat_of_Abs_sat' [simp]: |
70185 | 35 |
"nat_of (Abs_sat' n :: ('a::len) sat) = min (LENGTH('a)) n" |
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
36 |
unfolding Abs_sat'_def by (rule Abs_sat_inverse) simp |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
37 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
38 |
lemma nat_of_le_len_of [simp]: |
70185 | 39 |
"nat_of (n :: ('a::len) sat) \<le> LENGTH('a)" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
40 |
using nat_of [where x = n] by simp |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
41 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
42 |
lemma min_len_of_nat_of [simp]: |
70185 | 43 |
"min (LENGTH('a)) (nat_of (n::('a::len) sat)) = nat_of n" |
54863
82acc20ded73
prefer more canonical names for lemmas on min/max
haftmann
parents:
52729
diff
changeset
|
44 |
by (rule min.absorb2 [OF nat_of_le_len_of]) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
45 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
46 |
lemma min_nat_of_len_of [simp]: |
70185 | 47 |
"min (nat_of (n::('a::len) sat)) (LENGTH('a)) = nat_of n" |
51540
eea5c4ca4a0e
explicit sublocale dependency for Min/Max yields more appropriate Min/Max prefix for a couple of facts
haftmann
parents:
51489
diff
changeset
|
48 |
by (subst min.commute) simp |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
49 |
|
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
50 |
lemma Abs_sat'_nat_of [simp]: |
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
51 |
"Abs_sat' (nat_of n) = n" |
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
52 |
by (simp add: Abs_sat'_def nat_of_inverse) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
53 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
54 |
instantiation sat :: (len) linorder |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
55 |
begin |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
56 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
57 |
definition |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
58 |
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
|
59 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
60 |
definition |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
61 |
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
|
62 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
63 |
instance |
60679 | 64 |
by standard |
65 |
(auto simp add: less_eq_sat_def less_sat_def not_le sat_eq_iff min.coboundedI1 mult.commute) |
|
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
66 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
67 |
end |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
68 |
|
44849
41fddafe20d5
Library/Saturated.thy: number_semiring class instance
huffman
parents:
44848
diff
changeset
|
69 |
instantiation sat :: (len) "{minus, comm_semiring_1}" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
70 |
begin |
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 |
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
73 |
"0 = Abs_sat' 0" |
44819
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 |
definition |
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
76 |
"1 = Abs_sat' 1" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
77 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
78 |
lemma nat_of_zero_sat [simp, code abstract]: |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
79 |
"nat_of 0 = 0" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
80 |
by (simp add: zero_sat_def) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
81 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
82 |
lemma nat_of_one_sat [simp, code abstract]: |
70185 | 83 |
"nat_of 1 = min 1 (LENGTH('a))" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
84 |
by (simp add: one_sat_def) |
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 |
definition |
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
87 |
"x + y = Abs_sat' (nat_of x + nat_of y)" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
88 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
89 |
lemma nat_of_plus_sat [simp, code abstract]: |
70185 | 90 |
"nat_of (x + y) = min (nat_of x + nat_of y) (LENGTH('a))" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
91 |
by (simp add: plus_sat_def) |
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 |
definition |
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
94 |
"x - y = Abs_sat' (nat_of x - nat_of y)" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
95 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
96 |
lemma nat_of_minus_sat [simp, code abstract]: |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
97 |
"nat_of (x - y) = nat_of x - nat_of y" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
98 |
proof - |
70185 | 99 |
from nat_of_le_len_of [of x] have "nat_of x - nat_of y \<le> LENGTH('a)" by arith |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
100 |
then show ?thesis by (simp add: minus_sat_def) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
101 |
qed |
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 |
definition |
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
104 |
"x * y = Abs_sat' (nat_of x * nat_of y)" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
105 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
106 |
lemma nat_of_times_sat [simp, code abstract]: |
70185 | 107 |
"nat_of (x * y) = min (nat_of x * nat_of y) (LENGTH('a))" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
108 |
by (simp add: times_sat_def) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
109 |
|
60679 | 110 |
instance |
111 |
proof |
|
112 |
fix a b c :: "'a::len sat" |
|
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
113 |
show "a * b * c = a * (b * c)" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
114 |
proof(cases "a = 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 show ?thesis |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
118 |
proof(cases "c = 0") |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
119 |
case True thus ?thesis by (simp add: sat_eq_iff) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
120 |
next |
60500 | 121 |
case False with \<open>a \<noteq> 0\<close> show ?thesis |
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
54863
diff
changeset
|
122 |
by (simp add: sat_eq_iff nat_mult_min_left nat_mult_min_right mult.assoc min.assoc min.absorb2) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
123 |
qed |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
124 |
qed |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
125 |
show "1 * a = a" |
73793
26c0ccf17f31
more accurate export morphism enables proper instantiation by interpretation
haftmann
parents:
70185
diff
changeset
|
126 |
by (simp add: sat_eq_iff min_def not_le not_less) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
127 |
show "(a + b) * c = a * c + b * c" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
128 |
proof(cases "c = 0") |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
129 |
case True thus ?thesis by (simp add: sat_eq_iff) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
130 |
next |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
131 |
case False thus ?thesis |
82246 | 132 |
by (simp add: sat_eq_iff nat_mult_min_left add_mult_distrib min_add_distrib_left min_add_distrib_right min.assoc) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
133 |
qed |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
134 |
qed (simp_all add: sat_eq_iff mult.commute) |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
135 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
136 |
end |
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 |
instantiation sat :: (len) ordered_comm_semiring |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
139 |
begin |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
140 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
141 |
instance |
60679 | 142 |
by standard |
143 |
(auto simp add: less_eq_sat_def less_sat_def not_le sat_eq_iff min.coboundedI1 mult.commute) |
|
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
144 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
145 |
end |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
146 |
|
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
147 |
lemma Abs_sat'_eq_of_nat: "Abs_sat' n = of_nat n" |
44849
41fddafe20d5
Library/Saturated.thy: number_semiring class instance
huffman
parents:
44848
diff
changeset
|
148 |
by (rule sat_eqI, induct n, simp_all) |
41fddafe20d5
Library/Saturated.thy: number_semiring class instance
huffman
parents:
44848
diff
changeset
|
149 |
|
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
150 |
abbreviation Sat :: "nat \<Rightarrow> 'a::len sat" where |
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
151 |
"Sat \<equiv> of_nat" |
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
152 |
|
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
153 |
lemma nat_of_Sat [simp]: |
70185 | 154 |
"nat_of (Sat n :: ('a::len) sat) = min (LENGTH('a)) n" |
44883
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
155 |
by (rule nat_of_Abs_sat' [unfolded Abs_sat'_eq_of_nat]) |
a7f9c97378b3
Library/Saturated.thy: 'Sat' abbreviates 'of_nat'
huffman
parents:
44849
diff
changeset
|
156 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45994
diff
changeset
|
157 |
lemma [code_abbrev]: |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45994
diff
changeset
|
158 |
"of_nat (numeral k) = (numeral k :: 'a::len sat)" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45994
diff
changeset
|
159 |
by simp |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
160 |
|
60011 | 161 |
context |
162 |
begin |
|
163 |
||
164 |
qualified definition sat_of_nat :: "nat \<Rightarrow> ('a::len) sat" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45994
diff
changeset
|
165 |
where [code_abbrev]: "sat_of_nat = of_nat" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
166 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
167 |
lemma [code abstract]: |
70185 | 168 |
"nat_of (sat_of_nat n :: ('a::len) sat) = min (LENGTH('a)) n" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45994
diff
changeset
|
169 |
by (simp add: sat_of_nat_def) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
170 |
|
60011 | 171 |
end |
172 |
||
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
173 |
instance sat :: (len) finite |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
174 |
proof |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
175 |
show "finite (UNIV::'a sat set)" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
176 |
unfolding type_definition.univ [OF type_definition_sat] |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
177 |
using finite by simp |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
178 |
qed |
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) equal |
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 |
|
60679 | 183 |
definition "HOL.equal A B \<longleftrightarrow> nat_of A = nat_of B" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
184 |
|
60679 | 185 |
instance |
186 |
by standard (simp add: equal_sat_def nat_of_inject) |
|
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
187 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
188 |
end |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
189 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
190 |
instantiation sat :: (len) "{bounded_lattice, distrib_lattice}" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
191 |
begin |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
192 |
|
60679 | 193 |
definition "(inf :: 'a sat \<Rightarrow> 'a sat \<Rightarrow> 'a sat) = min" |
194 |
definition "(sup :: 'a sat \<Rightarrow> 'a sat \<Rightarrow> 'a sat) = max" |
|
195 |
definition "bot = (0 :: 'a sat)" |
|
70185 | 196 |
definition "top = Sat (LENGTH('a))" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
197 |
|
60679 | 198 |
instance |
199 |
by standard |
|
200 |
(simp_all add: inf_sat_def sup_sat_def bot_sat_def top_sat_def max_min_distrib2, |
|
201 |
simp_all add: less_eq_sat_def) |
|
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
202 |
|
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
203 |
end |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
204 |
|
51489 | 205 |
instantiation sat :: (len) "{Inf, Sup}" |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
206 |
begin |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
207 |
|
73793
26c0ccf17f31
more accurate export morphism enables proper instantiation by interpretation
haftmann
parents:
70185
diff
changeset
|
208 |
global_interpretation Inf_sat: semilattice_neutr_set min \<open>top :: 'a sat\<close> |
26c0ccf17f31
more accurate export morphism enables proper instantiation by interpretation
haftmann
parents:
70185
diff
changeset
|
209 |
defines Inf_sat = Inf_sat.F |
26c0ccf17f31
more accurate export morphism enables proper instantiation by interpretation
haftmann
parents:
70185
diff
changeset
|
210 |
by standard (simp add: min_def) |
26c0ccf17f31
more accurate export morphism enables proper instantiation by interpretation
haftmann
parents:
70185
diff
changeset
|
211 |
|
26c0ccf17f31
more accurate export morphism enables proper instantiation by interpretation
haftmann
parents:
70185
diff
changeset
|
212 |
global_interpretation Sup_sat: semilattice_neutr_set max \<open>bot :: 'a sat\<close> |
26c0ccf17f31
more accurate export morphism enables proper instantiation by interpretation
haftmann
parents:
70185
diff
changeset
|
213 |
defines Sup_sat = Sup_sat.F |
26c0ccf17f31
more accurate export morphism enables proper instantiation by interpretation
haftmann
parents:
70185
diff
changeset
|
214 |
by standard (simp add: max_def bot.extremum_unique) |
51489 | 215 |
|
216 |
instance .. |
|
217 |
||
218 |
end |
|
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
219 |
|
51489 | 220 |
instance sat :: (len) complete_lattice |
221 |
proof |
|
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
222 |
fix x :: "'a sat" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
223 |
fix A :: "'a sat set" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
224 |
note finite |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
225 |
moreover assume "x \<in> A" |
51489 | 226 |
ultimately show "Inf A \<le> x" |
54863
82acc20ded73
prefer more canonical names for lemmas on min/max
haftmann
parents:
52729
diff
changeset
|
227 |
by (induct A) (auto intro: min.coboundedI2) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
228 |
next |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
229 |
fix z :: "'a sat" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
230 |
fix A :: "'a sat set" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
231 |
note finite |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
232 |
moreover assume z: "\<And>x. x \<in> A \<Longrightarrow> z \<le> x" |
51489 | 233 |
ultimately show "z \<le> Inf A" by (induct A) simp_all |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
234 |
next |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
235 |
fix x :: "'a sat" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
236 |
fix A :: "'a sat set" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
237 |
note finite |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
238 |
moreover assume "x \<in> A" |
51489 | 239 |
ultimately show "x \<le> Sup A" |
54863
82acc20ded73
prefer more canonical names for lemmas on min/max
haftmann
parents:
52729
diff
changeset
|
240 |
by (induct A) (auto intro: max.coboundedI2) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
241 |
next |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
242 |
fix z :: "'a sat" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
243 |
fix A :: "'a sat set" |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
244 |
note finite |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
245 |
moreover assume z: "\<And>x. x \<in> A \<Longrightarrow> x \<le> z" |
51489 | 246 |
ultimately show "Sup A \<le> z" by (induct A) auto |
52729
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
51545
diff
changeset
|
247 |
next |
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
51545
diff
changeset
|
248 |
show "Inf {} = (top::'a sat)" |
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
51545
diff
changeset
|
249 |
by (auto simp: top_sat_def) |
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
51545
diff
changeset
|
250 |
show "Sup {} = (bot::'a sat)" |
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
51545
diff
changeset
|
251 |
by (auto simp: bot_sat_def) |
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
252 |
qed |
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
253 |
|
82246 | 254 |
|
255 |
subsection \<open>Enumeration\<close> |
|
256 |
||
257 |
lemma inj_on_sat_of_nat: |
|
258 |
shows "inj_on (of_nat :: nat \<Rightarrow> 'a::len sat) {0..<LENGTH('a)}" |
|
259 |
by (rule inj_onI) (simp add: sat_eq_iff) |
|
260 |
||
261 |
lemma UNIV_sat_eq_of_nat: |
|
262 |
shows "(UNIV :: 'a::len sat set) = of_nat ` {0..LENGTH('a)}" (is "?lhs = ?rhs") |
|
263 |
proof - |
|
264 |
have "x \<in> ?rhs" for x :: "'a sat" |
|
265 |
by (simp add: image_eqI[where x="nat_of x"] sat_eq_iff) |
|
266 |
then show ?thesis |
|
267 |
by blast |
|
268 |
qed |
|
269 |
||
270 |
instantiation sat :: (len) enum |
|
271 |
begin |
|
272 |
||
273 |
definition enum_sat :: "'a sat list" where |
|
274 |
"enum_sat = map of_nat [0..<Suc(LENGTH('a))]" |
|
275 |
||
276 |
definition enum_all_sat :: "('a sat \<Rightarrow> bool) \<Rightarrow> bool" where |
|
277 |
"enum_all_sat = All" |
|
278 |
||
279 |
definition enum_ex_sat :: "('a sat \<Rightarrow> bool) \<Rightarrow> bool" where |
|
280 |
"enum_ex_sat = Ex" |
|
281 |
||
282 |
instance |
|
283 |
proof intro_classes |
|
284 |
show "UNIV = set (enum_class.enum :: 'a sat list)" |
|
285 |
by (simp only: enum_sat_def UNIV_sat_eq_of_nat set_map flip: atLeastAtMost_upt) |
|
286 |
show "distinct (enum_class.enum :: 'a sat list)" |
|
287 |
by (clarsimp simp: enum_sat_def distinct_map inj_on_sat_of_nat sat_eq_iff) |
|
288 |
qed (simp_all add: enum_all_sat_def enum_ex_sat_def) |
|
289 |
||
44819
fe33d6655186
theory of saturated naturals contributed by Peter Gammie
haftmann
parents:
diff
changeset
|
290 |
end |
82246 | 291 |
|
292 |
lemma enum_sat_code [code]: |
|
293 |
fixes P :: "'a::len sat \<Rightarrow> bool" |
|
294 |
shows "Enum.enum_all P \<longleftrightarrow> list_all P Enum.enum" |
|
295 |
and "Enum.enum_ex P \<longleftrightarrow> list_ex P Enum.enum" |
|
296 |
by (simp_all add: enum_all_sat_def enum_ex_sat_def enum_UNIV list_all_iff list_ex_iff) |
|
297 |
||
298 |
end |