| author | Cezary Kaliszyk <kaliszyk@in.tum.de> | 
| Wed, 13 Jul 2011 04:00:32 +0900 | |
| changeset 43799 | a72661ba7239 | 
| parent 41550 | efa734d9b221 | 
| child 44690 | b6d8b11ed399 | 
| permissions | -rw-r--r-- | 
| 14620 
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
 skalberg parents: 
14516diff
changeset | 1 | (* Title: HOL/Import/HOL4Compat.thy | 
| 
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
 skalberg parents: 
14516diff
changeset | 2 | Author: Sebastian Skalberg (TU Muenchen) | 
| 
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
 skalberg parents: 
14516diff
changeset | 3 | *) | 
| 
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
 skalberg parents: 
14516diff
changeset | 4 | |
| 30660 | 5 | theory HOL4Compat | 
| 41413 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 wenzelm parents: 
40607diff
changeset | 6 | imports | 
| 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 wenzelm parents: 
40607diff
changeset | 7 | HOL4Setup | 
| 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 wenzelm parents: 
40607diff
changeset | 8 | Complex_Main | 
| 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 wenzelm parents: 
40607diff
changeset | 9 | "~~/src/HOL/Old_Number_Theory/Primes" | 
| 
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
 wenzelm parents: 
40607diff
changeset | 10 | "~~/src/HOL/Library/ContNotDenum" | 
| 19064 | 11 | begin | 
| 14516 | 12 | |
| 37596 | 13 | abbreviation (input) mem (infixl "mem" 55) where "x mem xs \<equiv> List.member xs x" | 
| 30660 | 14 | no_notation differentiable (infixl "differentiable" 60) | 
| 15 | no_notation sums (infixr "sums" 80) | |
| 16 | ||
| 14516 | 17 | lemma EXISTS_UNIQUE_DEF: "(Ex1 P) = (Ex P & (ALL x y. P x & P y --> (x = y)))" | 
| 18 | by auto | |
| 19 | ||
| 20 | lemma COND_DEF:"(If b t f) = (@x. ((b = True) --> (x = t)) & ((b = False) --> (x = f)))" | |
| 21 | by auto | |
| 22 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 23 | definition LET :: "['a \<Rightarrow> 'b,'a] \<Rightarrow> 'b" where | 
| 14516 | 24 | "LET f s == f s" | 
| 25 | ||
| 26 | lemma [hol4rew]: "LET f s = Let s f" | |
| 27 | by (simp add: LET_def Let_def) | |
| 28 | ||
| 29 | lemmas [hol4rew] = ONE_ONE_rew | |
| 30 | ||
| 31 | lemma bool_case_DEF: "(bool_case x y b) = (if b then x else y)" | |
| 30660 | 32 | by simp | 
| 14516 | 33 | |
| 34 | lemma INR_INL_11: "(ALL y x. (Inl x = Inl y) = (x = y)) & (ALL y x. (Inr x = Inr y) = (x = y))" | |
| 35 | by safe | |
| 36 | ||
| 17188 | 37 | (*lemma INL_neq_INR: "ALL v1 v2. Sum_Type.Inr v2 ~= Sum_Type.Inl v1" | 
| 38 | by simp*) | |
| 39 | ||
| 39246 | 40 | primrec ISL :: "'a + 'b => bool" where | 
| 14516 | 41 | "ISL (Inl x) = True" | 
| 39246 | 42 | | "ISL (Inr x) = False" | 
| 14516 | 43 | |
| 39246 | 44 | primrec ISR :: "'a + 'b => bool" where | 
| 14516 | 45 | "ISR (Inl x) = False" | 
| 39246 | 46 | | "ISR (Inr x) = True" | 
| 14516 | 47 | |
| 48 | lemma ISL: "(ALL x. ISL (Inl x)) & (ALL y. ~ISL (Inr y))" | |
| 49 | by simp | |
| 50 | ||
| 51 | lemma ISR: "(ALL x. ISR (Inr x)) & (ALL y. ~ISR (Inl y))" | |
| 52 | by simp | |
| 53 | ||
| 39246 | 54 | primrec OUTL :: "'a + 'b => 'a" where | 
| 14516 | 55 | "OUTL (Inl x) = x" | 
| 56 | ||
| 39246 | 57 | primrec OUTR :: "'a + 'b => 'b" where | 
| 14516 | 58 | "OUTR (Inr x) = x" | 
| 59 | ||
| 60 | lemma OUTL: "OUTL (Inl x) = x" | |
| 61 | by simp | |
| 62 | ||
| 63 | lemma OUTR: "OUTR (Inr x) = x" | |
| 64 | by simp | |
| 65 | ||
| 66 | lemma sum_case_def: "(ALL f g x. sum_case f g (Inl x) = f x) & (ALL f g y. sum_case f g (Inr y) = g y)" | |
| 41550 | 67 | by simp | 
| 14516 | 68 | |
| 69 | lemma one: "ALL v. v = ()" | |
| 41550 | 70 | by simp | 
| 14516 | 71 | |
| 72 | lemma option_case_def: "(!u f. option_case u f None = u) & (!u f x. option_case u f (Some x) = f x)" | |
| 73 | by simp | |
| 74 | ||
| 30235 
58d147683393
Made Option a separate theory and renamed option_map to Option.map
 nipkow parents: 
29044diff
changeset | 75 | lemma OPTION_MAP_DEF: "(!f x. Option.map f (Some x) = Some (f x)) & (!f. Option.map f None = None)" | 
| 14516 | 76 | by simp | 
| 77 | ||
| 39246 | 78 | primrec IS_SOME :: "'a option => bool" where | 
| 14516 | 79 | "IS_SOME (Some x) = True" | 
| 39246 | 80 | | "IS_SOME None = False" | 
| 14516 | 81 | |
| 39246 | 82 | primrec IS_NONE :: "'a option => bool" where | 
| 14516 | 83 | "IS_NONE (Some x) = False" | 
| 39246 | 84 | | "IS_NONE None = True" | 
| 14516 | 85 | |
| 86 | lemma IS_NONE_DEF: "(!x. IS_NONE (Some x) = False) & (IS_NONE None = True)" | |
| 87 | by simp | |
| 88 | ||
| 89 | lemma IS_SOME_DEF: "(!x. IS_SOME (Some x) = True) & (IS_SOME None = False)" | |
| 90 | by simp | |
| 91 | ||
| 39246 | 92 | primrec OPTION_JOIN :: "'a option option => 'a option" where | 
| 14516 | 93 | "OPTION_JOIN None = None" | 
| 39246 | 94 | | "OPTION_JOIN (Some x) = x" | 
| 14516 | 95 | |
| 96 | lemma OPTION_JOIN_DEF: "(OPTION_JOIN None = None) & (ALL x. OPTION_JOIN (Some x) = x)" | |
| 39246 | 97 | by simp | 
| 14516 | 98 | |
| 99 | lemma PAIR: "(fst x,snd x) = x" | |
| 100 | by simp | |
| 101 | ||
| 40607 | 102 | lemma PAIR_MAP: "map_pair f g p = (f (fst p),g (snd p))" | 
| 103 | by (simp add: map_pair_def split_def) | |
| 14516 | 104 | |
| 105 | lemma pair_case_def: "split = split" | |
| 41550 | 106 | .. | 
| 14516 | 107 | |
| 108 | lemma LESS_OR_EQ: "m <= (n::nat) = (m < n | m = n)" | |
| 109 | by auto | |
| 110 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 111 | definition nat_gt :: "nat => nat => bool" where | 
| 14516 | 112 | "nat_gt == %m n. n < m" | 
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 113 | |
| 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 114 | definition nat_ge :: "nat => nat => bool" where | 
| 14516 | 115 | "nat_ge == %m n. nat_gt m n | m = n" | 
| 116 | ||
| 117 | lemma [hol4rew]: "nat_gt m n = (n < m)" | |
| 118 | by (simp add: nat_gt_def) | |
| 119 | ||
| 120 | lemma [hol4rew]: "nat_ge m n = (n <= m)" | |
| 121 | by (auto simp add: nat_ge_def nat_gt_def) | |
| 122 | ||
| 123 | lemma GREATER_DEF: "ALL m n. (n < m) = (n < m)" | |
| 124 | by simp | |
| 125 | ||
| 126 | lemma GREATER_OR_EQ: "ALL m n. n <= (m::nat) = (n < m | m = n)" | |
| 127 | by auto | |
| 128 | ||
| 129 | lemma LESS_DEF: "m < n = (? P. (!n. P (Suc n) --> P n) & P m & ~P n)" | |
| 130 | proof safe | |
| 41550 | 131 | assume 1: "m < n" | 
| 14516 | 132 | def P == "%n. n <= m" | 
| 133 | have "(!n. P (Suc n) \<longrightarrow> P n) & P m & ~P n" | |
| 134 | proof (auto simp add: P_def) | |
| 135 | assume "n <= m" | |
| 41550 | 136 | with 1 | 
| 14516 | 137 | show False | 
| 138 | by auto | |
| 139 | qed | |
| 140 | thus "? P. (!n. P (Suc n) \<longrightarrow> P n) & P m & ~P n" | |
| 141 | by auto | |
| 142 | next | |
| 143 | fix P | |
| 144 | assume alln: "!n. P (Suc n) \<longrightarrow> P n" | |
| 145 | assume pm: "P m" | |
| 146 | assume npn: "~P n" | |
| 147 | have "!k q. q + k = m \<longrightarrow> P q" | |
| 148 | proof | |
| 149 | fix k | |
| 150 | show "!q. q + k = m \<longrightarrow> P q" | |
| 151 | proof (induct k,simp_all) | |
| 23389 | 152 | show "P m" by fact | 
| 14516 | 153 | next | 
| 154 | fix k | |
| 155 | assume ind: "!q. q + k = m \<longrightarrow> P q" | |
| 156 | show "!q. Suc (q + k) = m \<longrightarrow> P q" | |
| 157 | proof (rule+) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 158 | fix q | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 159 | assume "Suc (q + k) = m" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 160 | hence "(Suc q) + k = m" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 161 | by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 162 | with ind | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 163 | have psq: "P (Suc q)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 164 | by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 165 | from alln | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 166 | have "P (Suc q) --> P q" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 167 | .. | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 168 | with psq | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 169 | show "P q" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 170 | by simp | 
| 14516 | 171 | qed | 
| 172 | qed | |
| 173 | qed | |
| 174 | hence "!q. q + (m - n) = m \<longrightarrow> P q" | |
| 175 | .. | |
| 176 | hence hehe: "n + (m - n) = m \<longrightarrow> P n" | |
| 177 | .. | |
| 178 | show "m < n" | |
| 179 | proof (rule classical) | |
| 180 | assume "~(m<n)" | |
| 181 | hence "n <= m" | |
| 182 | by simp | |
| 183 | with hehe | |
| 184 | have "P n" | |
| 185 | by simp | |
| 186 | with npn | |
| 187 | show "m < n" | |
| 188 | .. | |
| 189 | qed | |
| 41550 | 190 | qed | 
| 14516 | 191 | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 192 | definition FUNPOW :: "('a => 'a) => nat => 'a => 'a" where
 | 
| 30971 | 193 | "FUNPOW f n == f ^^ n" | 
| 14516 | 194 | |
| 30971 | 195 | lemma FUNPOW: "(ALL f x. (f ^^ 0) x = x) & | 
| 196 | (ALL f n x. (f ^^ Suc n) x = (f ^^ n) (f x))" | |
| 30952 
7ab2716dd93b
power operation on functions with syntax o^; power operation on relations with syntax ^^
 haftmann parents: 
30660diff
changeset | 197 | by (simp add: funpow_swap1) | 
| 14516 | 198 | |
| 30971 | 199 | lemma [hol4rew]: "FUNPOW f n = f ^^ n" | 
| 14516 | 200 | by (simp add: FUNPOW_def) | 
| 201 | ||
| 202 | lemma ADD: "(!n. (0::nat) + n = n) & (!m n. Suc m + n = Suc (m + n))" | |
| 203 | by simp | |
| 204 | ||
| 205 | lemma MULT: "(!n. (0::nat) * n = 0) & (!m n. Suc m * n = m * n + n)" | |
| 206 | by simp | |
| 207 | ||
| 208 | lemma SUB: "(!m. (0::nat) - m = 0) & (!m n. (Suc m) - n = (if m < n then 0 else Suc (m - n)))" | |
| 30952 
7ab2716dd93b
power operation on functions with syntax o^; power operation on relations with syntax ^^
 haftmann parents: 
30660diff
changeset | 209 | by (simp) arith | 
| 14516 | 210 | |
| 211 | lemma MAX_DEF: "max (m::nat) n = (if m < n then n else m)" | |
| 212 | by (simp add: max_def) | |
| 213 | ||
| 214 | lemma MIN_DEF: "min (m::nat) n = (if m < n then m else n)" | |
| 215 | by (simp add: min_def) | |
| 216 | ||
| 217 | lemma DIVISION: "(0::nat) < n --> (!k. (k = k div n * n + k mod n) & k mod n < n)" | |
| 218 | by simp | |
| 219 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 220 | definition ALT_ZERO :: nat where | 
| 14516 | 221 | "ALT_ZERO == 0" | 
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 222 | |
| 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 223 | definition NUMERAL_BIT1 :: "nat \<Rightarrow> nat" where | 
| 14516 | 224 | "NUMERAL_BIT1 n == n + (n + Suc 0)" | 
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 225 | |
| 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 226 | definition NUMERAL_BIT2 :: "nat \<Rightarrow> nat" where | 
| 14516 | 227 | "NUMERAL_BIT2 n == n + (n + Suc (Suc 0))" | 
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 228 | |
| 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 229 | definition NUMERAL :: "nat \<Rightarrow> nat" where | 
| 14516 | 230 | "NUMERAL x == x" | 
| 231 | ||
| 232 | lemma [hol4rew]: "NUMERAL ALT_ZERO = 0" | |
| 233 | by (simp add: ALT_ZERO_def NUMERAL_def) | |
| 234 | ||
| 235 | lemma [hol4rew]: "NUMERAL (NUMERAL_BIT1 ALT_ZERO) = 1" | |
| 236 | by (simp add: ALT_ZERO_def NUMERAL_BIT1_def NUMERAL_def) | |
| 237 | ||
| 238 | lemma [hol4rew]: "NUMERAL (NUMERAL_BIT2 ALT_ZERO) = 2" | |
| 239 | by (simp add: ALT_ZERO_def NUMERAL_BIT2_def NUMERAL_def) | |
| 240 | ||
| 241 | lemma EXP: "(!m. m ^ 0 = (1::nat)) & (!m n. m ^ Suc n = m * (m::nat) ^ n)" | |
| 242 | by auto | |
| 243 | ||
| 244 | lemma num_case_def: "(!b f. nat_case b f 0 = b) & (!b f n. nat_case b f (Suc n) = f n)" | |
| 41550 | 245 | by simp | 
| 14516 | 246 | |
| 247 | lemma divides_def: "(a::nat) dvd b = (? q. b = q * a)" | |
| 41550 | 248 | by (auto simp add: dvd_def) | 
| 14516 | 249 | |
| 250 | lemma list_case_def: "(!v f. list_case v f [] = v) & (!v f a0 a1. list_case v f (a0#a1) = f a0 a1)" | |
| 251 | by simp | |
| 252 | ||
| 39246 | 253 | primrec list_size :: "('a \<Rightarrow> nat) \<Rightarrow> 'a list \<Rightarrow> nat" where
 | 
| 254 | "list_size f [] = 0" | |
| 255 | | "list_size f (a0#a1) = 1 + (f a0 + list_size f a1)" | |
| 14516 | 256 | |
| 39246 | 257 | lemma list_size_def': "(!f. list_size f [] = 0) & | 
| 14516 | 258 | (!f a0 a1. list_size f (a0#a1) = 1 + (f a0 + list_size f a1))" | 
| 259 | by simp | |
| 260 | ||
| 261 | lemma list_case_cong: "! M M' v f. M = M' & (M' = [] \<longrightarrow> v = v') & | |
| 262 | (!a0 a1. (M' = a0#a1) \<longrightarrow> (f a0 a1 = f' a0 a1)) --> | |
| 263 | (list_case v f M = list_case v' f' M')" | |
| 264 | proof clarify | |
| 265 | fix M M' v f | |
| 41550 | 266 | assume 1: "M' = [] \<longrightarrow> v = v'" | 
| 267 | and 2: "!a0 a1. M' = a0 # a1 \<longrightarrow> f a0 a1 = f' a0 a1" | |
| 14516 | 268 | show "list_case v f M' = list_case v' f' M'" | 
| 269 | proof (rule List.list.case_cong) | |
| 270 | show "M' = M'" | |
| 271 | .. | |
| 272 | next | |
| 273 | assume "M' = []" | |
| 41550 | 274 | with 1 2 | 
| 14516 | 275 | show "v = v'" | 
| 276 | by auto | |
| 277 | next | |
| 278 | fix a0 a1 | |
| 279 | assume "M' = a0 # a1" | |
| 41550 | 280 | with 1 2 | 
| 14516 | 281 | show "f a0 a1 = f' a0 a1" | 
| 282 | by auto | |
| 283 | qed | |
| 284 | qed | |
| 285 | ||
| 286 | lemma list_Axiom: "ALL f0 f1. EX fn. (fn [] = f0) & (ALL a0 a1. fn (a0#a1) = f1 a0 a1 (fn a1))" | |
| 287 | proof safe | |
| 288 | fix f0 f1 | |
| 289 | def fn == "list_rec f0 f1" | |
| 290 | have "fn [] = f0 & (ALL a0 a1. fn (a0 # a1) = f1 a0 a1 (fn a1))" | |
| 291 | by (simp add: fn_def) | |
| 292 | thus "EX fn. fn [] = f0 & (ALL a0 a1. fn (a0 # a1) = f1 a0 a1 (fn a1))" | |
| 293 | by auto | |
| 294 | qed | |
| 295 | ||
| 296 | lemma list_Axiom_old: "EX! fn. (fn [] = x) & (ALL h t. fn (h#t) = f (fn t) h t)" | |
| 297 | proof safe | |
| 298 | def fn == "list_rec x (%h t r. f r h t)" | |
| 299 | have "fn [] = x & (ALL h t. fn (h # t) = f (fn t) h t)" | |
| 300 | by (simp add: fn_def) | |
| 301 | thus "EX fn. fn [] = x & (ALL h t. fn (h # t) = f (fn t) h t)" | |
| 302 | by auto | |
| 303 | next | |
| 304 | fix fn1 fn2 | |
| 41550 | 305 | assume 1: "ALL h t. fn1 (h # t) = f (fn1 t) h t" | 
| 306 | assume 2: "ALL h t. fn2 (h # t) = f (fn2 t) h t" | |
| 307 | assume 3: "fn2 [] = fn1 []" | |
| 14516 | 308 | show "fn1 = fn2" | 
| 309 | proof | |
| 310 | fix xs | |
| 311 | show "fn1 xs = fn2 xs" | |
| 41550 | 312 | by (induct xs) (simp_all add: 1 2 3) | 
| 14516 | 313 | qed | 
| 314 | qed | |
| 315 | ||
| 37596 | 316 | lemma NULL_DEF: "(List.null [] = True) & (!h t. List.null (h # t) = False)" | 
| 317 | by (simp add: null_def) | |
| 14516 | 318 | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 319 | definition sum :: "nat list \<Rightarrow> nat" where | 
| 14516 | 320 | "sum l == foldr (op +) l 0" | 
| 321 | ||
| 322 | lemma SUM: "(sum [] = 0) & (!h t. sum (h#t) = h + sum t)" | |
| 323 | by (simp add: sum_def) | |
| 324 | ||
| 325 | lemma APPEND: "(!l. [] @ l = l) & (!l1 l2 h. (h#l1) @ l2 = h# l1 @ l2)" | |
| 326 | by simp | |
| 327 | ||
| 328 | lemma FLAT: "(concat [] = []) & (!h t. concat (h#t) = h @ (concat t))" | |
| 329 | by simp | |
| 330 | ||
| 331 | lemma LENGTH: "(length [] = 0) & (!h t. length (h#t) = Suc (length t))" | |
| 332 | by simp | |
| 333 | ||
| 334 | lemma MAP: "(!f. map f [] = []) & (!f h t. map f (h#t) = f h#map f t)" | |
| 335 | by simp | |
| 336 | ||
| 37596 | 337 | lemma MEM: "(!x. List.member [] x = False) & (!x h t. List.member (h#t) x = ((x = h) | List.member t x))" | 
| 338 | by (simp add: member_def) | |
| 14516 | 339 | |
| 340 | lemma FILTER: "(!P. filter P [] = []) & (!P h t. | |
| 341 | filter P (h#t) = (if P h then h#filter P t else filter P t))" | |
| 342 | by simp | |
| 343 | ||
| 344 | lemma REPLICATE: "(ALL x. replicate 0 x = []) & | |
| 345 | (ALL n x. replicate (Suc n) x = x # replicate n x)" | |
| 346 | by simp | |
| 347 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 348 | definition FOLDR :: "[['a,'b]\<Rightarrow>'b,'b,'a list] \<Rightarrow> 'b" where | 
| 14516 | 349 | "FOLDR f e l == foldr f l e" | 
| 350 | ||
| 351 | lemma [hol4rew]: "FOLDR f e l = foldr f l e" | |
| 352 | by (simp add: FOLDR_def) | |
| 353 | ||
| 354 | lemma FOLDR: "(!f e. foldr f [] e = e) & (!f e x l. foldr f (x#l) e = f x (foldr f l e))" | |
| 355 | by simp | |
| 356 | ||
| 357 | lemma FOLDL: "(!f e. foldl f e [] = e) & (!f e x l. foldl f e (x#l) = foldl f (f e x) l)" | |
| 358 | by simp | |
| 359 | ||
| 360 | lemma EVERY_DEF: "(!P. list_all P [] = True) & (!P h t. list_all P (h#t) = (P h & list_all P t))" | |
| 361 | by simp | |
| 362 | ||
| 37596 | 363 | lemma list_exists_DEF: "(!P. list_ex P [] = False) & (!P h t. list_ex P (h#t) = (P h | list_ex P t))" | 
| 14516 | 364 | by simp | 
| 365 | ||
| 39246 | 366 | primrec map2 :: "[['a,'b]\<Rightarrow>'c,'a list,'b list] \<Rightarrow> 'c list" where | 
| 14516 | 367 | map2_Nil: "map2 f [] l2 = []" | 
| 39246 | 368 | | map2_Cons: "map2 f (x#xs) l2 = f x (hd l2) # map2 f xs (tl l2)" | 
| 14516 | 369 | |
| 370 | lemma MAP2: "(!f. map2 f [] [] = []) & (!f h1 t1 h2 t2. map2 f (h1#t1) (h2#t2) = f h1 h2#map2 f t1 t2)" | |
| 371 | by simp | |
| 372 | ||
| 373 | lemma list_INDUCT: "\<lbrakk> P [] ; !t. P t \<longrightarrow> (!h. P (h#t)) \<rbrakk> \<Longrightarrow> !l. P l" | |
| 374 | proof | |
| 375 | fix l | |
| 376 | assume "P []" | |
| 377 | assume allt: "!t. P t \<longrightarrow> (!h. P (h # t))" | |
| 378 | show "P l" | |
| 379 | proof (induct l) | |
| 23389 | 380 | show "P []" by fact | 
| 14516 | 381 | next | 
| 382 | fix h t | |
| 383 | assume "P t" | |
| 384 | with allt | |
| 385 | have "!h. P (h # t)" | |
| 386 | by auto | |
| 387 | thus "P (h # t)" | |
| 388 | .. | |
| 389 | qed | |
| 390 | qed | |
| 391 | ||
| 392 | lemma list_CASES: "(l = []) | (? t h. l = h#t)" | |
| 393 | by (induct l,auto) | |
| 394 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 395 | definition ZIP :: "'a list * 'b list \<Rightarrow> ('a * 'b) list" where
 | 
| 14516 | 396 | "ZIP == %(a,b). zip a b" | 
| 397 | ||
| 398 | lemma ZIP: "(zip [] [] = []) & | |
| 399 | (!x1 l1 x2 l2. zip (x1#l1) (x2#l2) = (x1,x2)#zip l1 l2)" | |
| 400 | by simp | |
| 401 | ||
| 402 | lemma [hol4rew]: "ZIP (a,b) = zip a b" | |
| 403 | by (simp add: ZIP_def) | |
| 404 | ||
| 39246 | 405 | primrec unzip :: "('a * 'b) list \<Rightarrow> 'a list * 'b list" where
 | 
| 14516 | 406 | unzip_Nil: "unzip [] = ([],[])" | 
| 39246 | 407 | | unzip_Cons: "unzip (xy#xys) = (let zs = unzip xys in (fst xy # fst zs,snd xy # snd zs))" | 
| 14516 | 408 | |
| 409 | lemma UNZIP: "(unzip [] = ([],[])) & | |
| 410 | (!x l. unzip (x#l) = (fst x#fst (unzip l),snd x#snd (unzip l)))" | |
| 411 | by (simp add: Let_def) | |
| 412 | ||
| 413 | lemma REVERSE: "(rev [] = []) & (!h t. rev (h#t) = (rev t) @ [h])" | |
| 41550 | 414 | by simp | 
| 14516 | 415 | |
| 416 | lemma REAL_SUP_ALLPOS: "\<lbrakk> ALL x. P (x::real) \<longrightarrow> 0 < x ; EX x. P x; EX z. ALL x. P x \<longrightarrow> x < z \<rbrakk> \<Longrightarrow> EX s. ALL y. (EX x. P x & y < x) = (y < s)" | |
| 417 | proof safe | |
| 418 | fix x z | |
| 419 | assume allx: "ALL x. P x \<longrightarrow> 0 < x" | |
| 420 | assume px: "P x" | |
| 421 | assume allx': "ALL x. P x \<longrightarrow> x < z" | |
| 422 | have "EX s. ALL y. (EX x : Collect P. y < x) = (y < s)" | |
| 423 | proof (rule posreal_complete) | |
| 424 | show "ALL x : Collect P. 0 < x" | |
| 425 | proof safe | |
| 426 | fix x | |
| 41550 | 427 | assume P: "P x" | 
| 14516 | 428 | from allx | 
| 429 | have "P x \<longrightarrow> 0 < x" | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32479diff
changeset | 430 | .. | 
| 41550 | 431 | with P show "0 < x" by simp | 
| 14516 | 432 | qed | 
| 433 | next | |
| 434 | from px | |
| 435 | show "EX x. x : Collect P" | |
| 436 | by auto | |
| 437 | next | |
| 438 | from allx' | |
| 439 | show "EX y. ALL x : Collect P. x < y" | |
| 440 | apply simp | |
| 441 | .. | |
| 442 | qed | |
| 443 | thus "EX s. ALL y. (EX x. P x & y < x) = (y < s)" | |
| 444 | by simp | |
| 445 | qed | |
| 446 | ||
| 447 | lemma REAL_10: "~((1::real) = 0)" | |
| 448 | by simp | |
| 449 | ||
| 450 | lemma REAL_ADD_ASSOC: "(x::real) + (y + z) = x + y + z" | |
| 451 | by simp | |
| 452 | ||
| 453 | lemma REAL_MUL_ASSOC: "(x::real) * (y * z) = x * y * z" | |
| 454 | by simp | |
| 455 | ||
| 456 | lemma REAL_ADD_LINV: "-x + x = (0::real)" | |
| 457 | by simp | |
| 458 | ||
| 459 | lemma REAL_MUL_LINV: "x ~= (0::real) ==> inverse x * x = 1" | |
| 460 | by simp | |
| 461 | ||
| 462 | lemma REAL_LT_TOTAL: "((x::real) = y) | x < y | y < x" | |
| 41550 | 463 | by auto | 
| 14516 | 464 | |
| 465 | lemma [hol4rew]: "real (0::nat) = 0" | |
| 466 | by simp | |
| 467 | ||
| 468 | lemma [hol4rew]: "real (1::nat) = 1" | |
| 469 | by simp | |
| 470 | ||
| 471 | lemma [hol4rew]: "real (2::nat) = 2" | |
| 472 | by simp | |
| 473 | ||
| 474 | lemma real_lte: "((x::real) <= y) = (~(y < x))" | |
| 475 | by auto | |
| 476 | ||
| 477 | lemma real_of_num: "((0::real) = 0) & (!n. real (Suc n) = real n + 1)" | |
| 478 | by (simp add: real_of_nat_Suc) | |
| 479 | ||
| 480 | lemma abs: "abs (x::real) = (if 0 <= x then x else -x)" | |
| 15003 | 481 | by (simp add: abs_if) | 
| 14516 | 482 | |
| 483 | lemma pow: "(!x::real. x ^ 0 = 1) & (!x::real. ALL n. x ^ (Suc n) = x * x ^ n)" | |
| 15003 | 484 | by simp | 
| 14516 | 485 | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 486 | definition real_gt :: "real => real => bool" where | 
| 14516 | 487 | "real_gt == %x y. y < x" | 
| 488 | ||
| 489 | lemma [hol4rew]: "real_gt x y = (y < x)" | |
| 490 | by (simp add: real_gt_def) | |
| 491 | ||
| 492 | lemma real_gt: "ALL x (y::real). (y < x) = (y < x)" | |
| 493 | by simp | |
| 494 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
32960diff
changeset | 495 | definition real_ge :: "real => real => bool" where | 
| 14516 | 496 | "real_ge x y == y <= x" | 
| 497 | ||
| 498 | lemma [hol4rew]: "real_ge x y = (y <= x)" | |
| 499 | by (simp add: real_ge_def) | |
| 500 | ||
| 501 | lemma real_ge: "ALL x y. (y <= x) = (y <= x)" | |
| 502 | by simp | |
| 503 | ||
| 504 | end |