src/HOL/Import/HOL4Compat.thy
 author haftmann Fri Apr 24 17:45:15 2009 +0200 (2009-04-24) changeset 30971 7fbebf75b3ef parent 30952 7ab2716dd93b child 32479 521cc9bf2958 permissions -rw-r--r--
funpow and relpow with shared "^^" syntax
1 (*  Title:      HOL/Import/HOL4Compat.thy
2     Author:     Sebastian Skalberg (TU Muenchen)
3 *)
5 theory HOL4Compat
6 imports HOL4Setup Complex_Main Primes ContNotDenum
7 begin
9 no_notation differentiable (infixl "differentiable" 60)
10 no_notation sums (infixr "sums" 80)
12 lemma EXISTS_UNIQUE_DEF: "(Ex1 P) = (Ex P & (ALL x y. P x & P y --> (x = y)))"
13   by auto
15 lemma COND_DEF:"(If b t f) = (@x. ((b = True) --> (x = t)) & ((b = False) --> (x = f)))"
16   by auto
18 constdefs
19   LET :: "['a \<Rightarrow> 'b,'a] \<Rightarrow> 'b"
20   "LET f s == f s"
22 lemma [hol4rew]: "LET f s = Let s f"
23   by (simp add: LET_def Let_def)
25 lemmas [hol4rew] = ONE_ONE_rew
27 lemma bool_case_DEF: "(bool_case x y b) = (if b then x else y)"
28   by simp
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
33 (*lemma INL_neq_INR: "ALL v1 v2. Sum_Type.Inr v2 ~= Sum_Type.Inl v1"
34   by simp*)
36 consts
37   ISL :: "'a + 'b => bool"
38   ISR :: "'a + 'b => bool"
40 primrec ISL_def:
41   "ISL (Inl x) = True"
42   "ISL (Inr x) = False"
44 primrec ISR_def:
45   "ISR (Inl x) = False"
46   "ISR (Inr x) = True"
48 lemma ISL: "(ALL x. ISL (Inl x)) & (ALL y. ~ISL (Inr y))"
49   by simp
51 lemma ISR: "(ALL x. ISR (Inr x)) & (ALL y. ~ISR (Inl y))"
52   by simp
54 consts
55   OUTL :: "'a + 'b => 'a"
56   OUTR :: "'a + 'b => 'b"
58 primrec OUTL_def:
59   "OUTL (Inl x) = x"
61 primrec OUTR_def:
62   "OUTR (Inr x) = x"
64 lemma OUTL: "OUTL (Inl x) = x"
65   by simp
67 lemma OUTR: "OUTR (Inr x) = x"
68   by simp
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;
73 lemma one: "ALL v. v = ()"
74   by simp;
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
79 lemma OPTION_MAP_DEF: "(!f x. Option.map f (Some x) = Some (f x)) & (!f. Option.map f None = None)"
80   by simp
82 consts
83   IS_SOME :: "'a option => bool"
84   IS_NONE :: "'a option => bool"
86 primrec IS_SOME_def:
87   "IS_SOME (Some x) = True"
88   "IS_SOME None = False"
90 primrec IS_NONE_def:
91   "IS_NONE (Some x) = False"
92   "IS_NONE None = True"
94 lemma IS_NONE_DEF: "(!x. IS_NONE (Some x) = False) & (IS_NONE None = True)"
95   by simp
97 lemma IS_SOME_DEF: "(!x. IS_SOME (Some x) = True) & (IS_SOME None = False)"
98   by simp
100 consts
101   OPTION_JOIN :: "'a option option => 'a option"
103 primrec OPTION_JOIN_def:
104   "OPTION_JOIN None = None"
105   "OPTION_JOIN (Some x) = x"
107 lemma OPTION_JOIN_DEF: "(OPTION_JOIN None = None) & (ALL x. OPTION_JOIN (Some x) = x)"
108   by simp;
110 lemma PAIR: "(fst x,snd x) = x"
111   by simp
113 lemma PAIR_MAP: "prod_fun f g p = (f (fst p),g (snd p))"
114   by (simp add: prod_fun_def split_def)
116 lemma pair_case_def: "split = split"
117   ..;
119 lemma LESS_OR_EQ: "m <= (n::nat) = (m < n | m = n)"
120   by auto
122 constdefs
123   nat_gt :: "nat => nat => bool"
124   "nat_gt == %m n. n < m"
125   nat_ge :: "nat => nat => bool"
126   "nat_ge == %m n. nat_gt m n | m = n"
128 lemma [hol4rew]: "nat_gt m n = (n < m)"
131 lemma [hol4rew]: "nat_ge m n = (n <= m)"
132   by (auto simp add: nat_ge_def nat_gt_def)
134 lemma GREATER_DEF: "ALL m n. (n < m) = (n < m)"
135   by simp
137 lemma GREATER_OR_EQ: "ALL m n. n <= (m::nat) = (n < m | m = n)"
138   by auto
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)
163       show "P m" by fact
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+)
169 	fix q
170 	assume "Suc (q + k) = m"
171 	hence "(Suc q) + k = m"
172 	  by simp
173 	with ind
174 	have psq: "P (Suc q)"
175 	  by simp
176 	from alln
177 	have "P (Suc q) --> P q"
178 	  ..
179 	with psq
180 	show "P q"
181 	  by simp
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;
203 constdefs
204   FUNPOW :: "('a => 'a) => nat => 'a => 'a"
205   "FUNPOW f n == f ^^ n"
207 lemma FUNPOW: "(ALL f x. (f ^^ 0) x = x) &
208   (ALL f n x. (f ^^ Suc n) x = (f ^^ n) (f x))"
211 lemma [hol4rew]: "FUNPOW f n = f ^^ n"
214 lemma ADD: "(!n. (0::nat) + n = n) & (!m n. Suc m + n = Suc (m + n))"
215   by simp
217 lemma MULT: "(!n. (0::nat) * n = 0) & (!m n. Suc m * n = m * n + n)"
218   by simp
220 lemma SUB: "(!m. (0::nat) - m = 0) & (!m n. (Suc m) - n = (if m < n then 0 else Suc (m - n)))"
221   by (simp) arith
223 lemma MAX_DEF: "max (m::nat) n = (if m < n then n else m)"
226 lemma MIN_DEF: "min (m::nat) n = (if m < n then m else n)"
229 lemma DIVISION: "(0::nat) < n --> (!k. (k = k div n * n + k mod n) & k mod n < n)"
230   by simp
232 constdefs
233   ALT_ZERO :: nat
234   "ALT_ZERO == 0"
235   NUMERAL_BIT1 :: "nat \<Rightarrow> nat"
236   "NUMERAL_BIT1 n == n + (n + Suc 0)"
237   NUMERAL_BIT2 :: "nat \<Rightarrow> nat"
238   "NUMERAL_BIT2 n == n + (n + Suc (Suc 0))"
239   NUMERAL :: "nat \<Rightarrow> nat"
240   "NUMERAL x == x"
242 lemma [hol4rew]: "NUMERAL ALT_ZERO = 0"
243   by (simp add: ALT_ZERO_def NUMERAL_def)
245 lemma [hol4rew]: "NUMERAL (NUMERAL_BIT1 ALT_ZERO) = 1"
246   by (simp add: ALT_ZERO_def NUMERAL_BIT1_def NUMERAL_def)
248 lemma [hol4rew]: "NUMERAL (NUMERAL_BIT2 ALT_ZERO) = 2"
249   by (simp add: ALT_ZERO_def NUMERAL_BIT2_def NUMERAL_def)
251 lemma EXP: "(!m. m ^ 0 = (1::nat)) & (!m n. m ^ Suc n = m * (m::nat) ^ n)"
252   by auto
254 lemma num_case_def: "(!b f. nat_case b f 0 = b) & (!b f n. nat_case b f (Suc n) = f n)"
255   by simp;
257 lemma divides_def: "(a::nat) dvd b = (? q. b = q * a)"
258   by (auto simp add: dvd_def);
260 lemma list_case_def: "(!v f. list_case v f [] = v) & (!v f a0 a1. list_case v f (a0#a1) = f a0 a1)"
261   by simp
263 consts
264   list_size :: "('a \<Rightarrow> nat) \<Rightarrow> 'a list \<Rightarrow> nat"
266 primrec
267   "list_size f [] = 0"
268   "list_size f (a0#a1) = 1 + (f a0 + list_size f a1)"
270 lemma list_size_def: "(!f. list_size f [] = 0) &
271          (!f a0 a1. list_size f (a0#a1) = 1 + (f a0 + list_size f a1))"
272   by simp
274 lemma list_case_cong: "! M M' v f. M = M' & (M' = [] \<longrightarrow>  v = v') &
275            (!a0 a1. (M' = a0#a1) \<longrightarrow> (f a0 a1 = f' a0 a1)) -->
276            (list_case v f M = list_case v' f' M')"
277 proof clarify
278   fix M M' v f
279   assume "M' = [] \<longrightarrow> v = v'"
280     and "!a0 a1. M' = a0 # a1 \<longrightarrow> f a0 a1 = f' a0 a1"
281   show "list_case v f M' = list_case v' f' M'"
282   proof (rule List.list.case_cong)
283     show "M' = M'"
284       ..
285   next
286     assume "M' = []"
287     with prems
288     show "v = v'"
289       by auto
290   next
291     fix a0 a1
292     assume "M' = a0 # a1"
293     with prems
294     show "f a0 a1 = f' a0 a1"
295       by auto
296   qed
297 qed
299 lemma list_Axiom: "ALL f0 f1. EX fn. (fn [] = f0) & (ALL a0 a1. fn (a0#a1) = f1 a0 a1 (fn a1))"
300 proof safe
301   fix f0 f1
302   def fn == "list_rec f0 f1"
303   have "fn [] = f0 & (ALL a0 a1. fn (a0 # a1) = f1 a0 a1 (fn a1))"
305   thus "EX fn. fn [] = f0 & (ALL a0 a1. fn (a0 # a1) = f1 a0 a1 (fn a1))"
306     by auto
307 qed
309 lemma list_Axiom_old: "EX! fn. (fn [] = x) & (ALL h t. fn (h#t) = f (fn t) h t)"
310 proof safe
311   def fn == "list_rec x (%h t r. f r h t)"
312   have "fn [] = x & (ALL h t. fn (h # t) = f (fn t) h t)"
314   thus "EX fn. fn [] = x & (ALL h t. fn (h # t) = f (fn t) h t)"
315     by auto
316 next
317   fix fn1 fn2
318   assume "ALL h t. fn1 (h # t) = f (fn1 t) h t"
319   assume "ALL h t. fn2 (h # t) = f (fn2 t) h t"
320   assume "fn2 [] = fn1 []"
321   show "fn1 = fn2"
322   proof
323     fix xs
324     show "fn1 xs = fn2 xs"
325       by (induct xs,simp_all add: prems)
326   qed
327 qed
329 lemma NULL_DEF: "(null [] = True) & (!h t. null (h # t) = False)"
330   by simp
332 constdefs
333   sum :: "nat list \<Rightarrow> nat"
334   "sum l == foldr (op +) l 0"
336 lemma SUM: "(sum [] = 0) & (!h t. sum (h#t) = h + sum t)"
339 lemma APPEND: "(!l. [] @ l = l) & (!l1 l2 h. (h#l1) @ l2 = h# l1 @ l2)"
340   by simp
342 lemma FLAT: "(concat [] = []) & (!h t. concat (h#t) = h @ (concat t))"
343   by simp
345 lemma LENGTH: "(length [] = 0) & (!h t. length (h#t) = Suc (length t))"
346   by simp
348 lemma MAP: "(!f. map f [] = []) & (!f h t. map f (h#t) = f h#map f t)"
349   by simp
351 lemma MEM: "(!x. x mem [] = False) & (!x h t. x mem (h#t) = ((x = h) | x mem t))"
352   by auto
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
358 lemma REPLICATE: "(ALL x. replicate 0 x = []) &
359   (ALL n x. replicate (Suc n) x = x # replicate n x)"
360   by simp
362 constdefs
363   FOLDR :: "[['a,'b]\<Rightarrow>'b,'b,'a list] \<Rightarrow> 'b"
364   "FOLDR f e l == foldr f l e"
366 lemma [hol4rew]: "FOLDR f e l = foldr f l e"
369 lemma FOLDR: "(!f e. foldr f [] e = e) & (!f e x l. foldr f (x#l) e = f x (foldr f l e))"
370   by simp
372 lemma FOLDL: "(!f e. foldl f e [] = e) & (!f e x l. foldl f e (x#l) = foldl f (f e x) l)"
373   by simp
375 lemma EVERY_DEF: "(!P. list_all P [] = True) & (!P h t. list_all P (h#t) = (P h & list_all P t))"
376   by simp
378 consts
379   list_exists :: "['a \<Rightarrow> bool,'a list] \<Rightarrow> bool"
381 primrec
382   list_exists_Nil: "list_exists P Nil = False"
383   list_exists_Cons: "list_exists P (x#xs) = (if P x then True else list_exists P xs)"
385 lemma list_exists_DEF: "(!P. list_exists P [] = False) &
386          (!P h t. list_exists P (h#t) = (P h | list_exists P t))"
387   by simp
389 consts
390   map2 :: "[['a,'b]\<Rightarrow>'c,'a list,'b list] \<Rightarrow> 'c list"
392 primrec
393   map2_Nil: "map2 f [] l2 = []"
394   map2_Cons: "map2 f (x#xs) l2 = f x (hd l2) # map2 f xs (tl l2)"
396 lemma MAP2: "(!f. map2 f [] [] = []) & (!f h1 t1 h2 t2. map2 f (h1#t1) (h2#t2) = f h1 h2#map2 f t1 t2)"
397   by simp
399 lemma list_INDUCT: "\<lbrakk> P [] ; !t. P t \<longrightarrow> (!h. P (h#t)) \<rbrakk> \<Longrightarrow> !l. P l"
400 proof
401   fix l
402   assume "P []"
403   assume allt: "!t. P t \<longrightarrow> (!h. P (h # t))"
404   show "P l"
405   proof (induct l)
406     show "P []" by fact
407   next
408     fix h t
409     assume "P t"
410     with allt
411     have "!h. P (h # t)"
412       by auto
413     thus "P (h # t)"
414       ..
415   qed
416 qed
418 lemma list_CASES: "(l = []) | (? t h. l = h#t)"
419   by (induct l,auto)
421 constdefs
422   ZIP :: "'a list * 'b list \<Rightarrow> ('a * 'b) list"
423   "ZIP == %(a,b). zip a b"
425 lemma ZIP: "(zip [] [] = []) &
426   (!x1 l1 x2 l2. zip (x1#l1) (x2#l2) = (x1,x2)#zip l1 l2)"
427   by simp
429 lemma [hol4rew]: "ZIP (a,b) = zip a b"
432 consts
433   unzip :: "('a * 'b) list \<Rightarrow> 'a list * 'b list"
435 primrec
436   unzip_Nil: "unzip [] = ([],[])"
437   unzip_Cons: "unzip (xy#xys) = (let zs = unzip xys in (fst xy # fst zs,snd xy # snd zs))"
439 lemma UNZIP: "(unzip [] = ([],[])) &
440          (!x l. unzip (x#l) = (fst x#fst (unzip l),snd x#snd (unzip l)))"
443 lemma REVERSE: "(rev [] = []) & (!h t. rev (h#t) = (rev t) @ [h])"
444   by simp;
446 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)"
447 proof safe
448   fix x z
449   assume allx: "ALL x. P x \<longrightarrow> 0 < x"
450   assume px: "P x"
451   assume allx': "ALL x. P x \<longrightarrow> x < z"
452   have "EX s. ALL y. (EX x : Collect P. y < x) = (y < s)"
453   proof (rule posreal_complete)
454     show "ALL x : Collect P. 0 < x"
455     proof safe
456       fix x
457       assume "P x"
458       from allx
459       have "P x \<longrightarrow> 0 < x"
460 	..
461       thus "0 < x"
463     qed
464   next
465     from px
466     show "EX x. x : Collect P"
467       by auto
468   next
469     from allx'
470     show "EX y. ALL x : Collect P. x < y"
471       apply simp
472       ..
473   qed
474   thus "EX s. ALL y. (EX x. P x & y < x) = (y < s)"
475     by simp
476 qed
478 lemma REAL_10: "~((1::real) = 0)"
479   by simp
481 lemma REAL_ADD_ASSOC: "(x::real) + (y + z) = x + y + z"
482   by simp
484 lemma REAL_MUL_ASSOC: "(x::real) * (y * z) = x * y * z"
485   by simp
487 lemma REAL_ADD_LINV:  "-x + x = (0::real)"
488   by simp
490 lemma REAL_MUL_LINV: "x ~= (0::real) ==> inverse x * x = 1"
491   by simp
493 lemma REAL_LT_TOTAL: "((x::real) = y) | x < y | y < x"
494   by auto;
496 lemma [hol4rew]: "real (0::nat) = 0"
497   by simp
499 lemma [hol4rew]: "real (1::nat) = 1"
500   by simp
502 lemma [hol4rew]: "real (2::nat) = 2"
503   by simp
505 lemma real_lte: "((x::real) <= y) = (~(y < x))"
506   by auto
508 lemma real_of_num: "((0::real) = 0) & (!n. real (Suc n) = real n + 1)"
511 lemma abs: "abs (x::real) = (if 0 <= x then x else -x)"
514 lemma pow: "(!x::real. x ^ 0 = 1) & (!x::real. ALL n. x ^ (Suc n) = x * x ^ n)"
515   by simp
517 constdefs
518   real_gt :: "real => real => bool"
519   "real_gt == %x y. y < x"
521 lemma [hol4rew]: "real_gt x y = (y < x)"