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