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