src/HOL/ex/NormalForm.thy
author haftmann
Tue Oct 31 09:29:08 2006 +0100 (2006-10-31)
changeset 21117 e8657a20a52f
parent 21059 361e62500ab7
child 21156 17f144c6e2f2
permissions -rw-r--r--
*** empty log message ***
nipkow@19829
     1
(*  ID:         $Id$
nipkow@19829
     2
    Authors:    Klaus Aehlig, Tobias Nipkow
wenzelm@20807
     3
*)
nipkow@19829
     4
haftmann@21059
     5
header {* Test of normalization function *}
nipkow@19829
     6
nipkow@19829
     7
theory NormalForm
nipkow@19829
     8
imports Main
nipkow@19829
     9
begin
nipkow@19829
    10
haftmann@21117
    11
lemma "True" by normalization
haftmann@21117
    12
lemma "x = x" by normalization
nipkow@19971
    13
lemma "p \<longrightarrow> True" by normalization
krauss@20523
    14
declare disj_assoc [code func]
haftmann@20595
    15
lemma "((P | Q) | R) = (P | (Q | R))" by normalization
haftmann@21059
    16
declare disj_assoc [code nofunc]
nipkow@19971
    17
lemma "0 + (n::nat) = n" by normalization
haftmann@20595
    18
lemma "0 + Suc n = Suc n" by normalization
haftmann@20595
    19
lemma "Suc n + Suc m = n + Suc (Suc m)" by normalization
nipkow@19971
    20
lemma "~((0::nat) < (0::nat))" by normalization
nipkow@19971
    21
nipkow@19829
    22
datatype n = Z | S n
nipkow@19829
    23
consts
haftmann@20842
    24
  add :: "n \<Rightarrow> n \<Rightarrow> n"
haftmann@20842
    25
  add2 :: "n \<Rightarrow> n \<Rightarrow> n"
haftmann@20842
    26
  mul :: "n \<Rightarrow> n \<Rightarrow> n"
haftmann@20842
    27
  mul2 :: "n \<Rightarrow> n \<Rightarrow> n"
haftmann@20842
    28
  exp :: "n \<Rightarrow> n \<Rightarrow> n"
nipkow@19829
    29
primrec
haftmann@20842
    30
  "add Z = id"
haftmann@20842
    31
  "add (S m) = S o add m"
nipkow@19829
    32
primrec
haftmann@20842
    33
  "add2 Z n = n"
haftmann@20842
    34
  "add2 (S m) n = S(add2 m n)"
nipkow@19829
    35
nipkow@19829
    36
lemma [code]: "add2 (add2 n m) k = add2 n (add2 m k)"
haftmann@20842
    37
  by(induct n) auto
haftmann@20842
    38
lemma [code]: "add2 n (S m) =  S (add2 n m)"
haftmann@20842
    39
  by(induct n) auto
nipkow@19829
    40
lemma [code]: "add2 n Z = n"
haftmann@20842
    41
  by(induct n) auto
nipkow@19971
    42
nipkow@19971
    43
lemma "add2 (add2 n m) k = add2 n (add2 m k)" by normalization
nipkow@19971
    44
lemma "add2 (add2 (S n) (S m)) (S k) = S(S(S(add2 n (add2 m k))))" by normalization
nipkow@19971
    45
lemma "add2 (add2 (S n) (add2 (S m) Z)) (S k) = S(S(S(add2 n (add2 m k))))" by normalization
nipkow@19829
    46
nipkow@19829
    47
primrec
haftmann@20842
    48
  "mul Z = (%n. Z)"
haftmann@20842
    49
  "mul (S m) = (%n. add (mul m n) n)"
nipkow@19829
    50
primrec
haftmann@20842
    51
  "mul2 Z n = Z"
haftmann@20842
    52
  "mul2 (S m) n = add2 n (mul2 m n)"
nipkow@19829
    53
primrec
haftmann@20842
    54
  "exp m Z = S Z"
haftmann@20842
    55
  "exp m (S n) = mul (exp m n) m"
nipkow@19829
    56
nipkow@19971
    57
lemma "mul2 (S(S(S(S(S Z))))) (S(S(S Z))) = S(S(S(S(S(S(S(S(S(S(S(S(S(S(S Z))))))))))))))" by normalization
nipkow@19971
    58
lemma "mul (S(S(S(S(S Z))))) (S(S(S Z))) = S(S(S(S(S(S(S(S(S(S(S(S(S(S(S Z))))))))))))))" by normalization
nipkow@19971
    59
lemma "exp (S(S Z)) (S(S(S(S Z)))) = exp (S(S(S(S Z)))) (S(S Z))" by normalization
nipkow@19971
    60
nipkow@19971
    61
lemma "(let ((x,y),(u,v)) = ((Z,Z),(Z,Z)) in add (add x y) (add u v)) = Z" by normalization
haftmann@20842
    62
lemma "split (%x y. x) (a, b) = a" by normalization
nipkow@19971
    63
lemma "(%((x,y),(u,v)). add (add x y) (add u v)) ((Z,Z),(Z,Z)) = Z" by normalization
nipkow@19971
    64
nipkow@19971
    65
lemma "case Z of Z \<Rightarrow> True | S x \<Rightarrow> False" by normalization
nipkow@19829
    66
haftmann@20842
    67
lemma "[] @ [] = []" by normalization
haftmann@20842
    68
lemma "[] @ xs = xs" by normalization
haftmann@21117
    69
lemma "[a, b, c] @ xs = a # b # c # xs" by normalization
haftmann@20842
    70
lemma "[%a::'x. a, %b. b, c] @ xs = (%x. x) # (%x. x) # c # xs" by normalization
haftmann@21117
    71
lemma "[%a::'x. a, %b. b, c] @ [u, v] = [%x. x, %x. x, c, u, v]" by normalization
haftmann@20842
    72
lemma "map f [x,y,z::'x] = [f x, f y, f z]" by normalization
haftmann@21117
    73
lemma "map (%f. f True) [id, g, Not] = [True, g True, False]" by normalization
haftmann@21117
    74
lemma "map (%f. f True) ([id, g, Not] @ fs) = [True, g True, False] @ map (%f. f True) fs" by normalization
haftmann@21117
    75
lemma "rev [a, b, c] = [c, b, a]" by normalization
haftmann@21117
    76
(*normal_form "rev (a#b#cs)"
haftmann@21117
    77
normal_form "rev cs @ [b, a]"*)
haftmann@21117
    78
(*lemma "rev (a#b#cs) = rev cs @ [b, a]" by normalization*)
haftmann@21117
    79
lemma "map map [f, g, h] = [map f, map g, map h]" by normalization
nipkow@19829
    80
normal_form "map (%F. F [a,b,c::'x]) (map map [f,g,h])"
nipkow@19829
    81
normal_form "map (%F. F ([a,b,c] @ ds)) (map map ([f,g,h]@fs))"
nipkow@19829
    82
normal_form "map (%F. F [Z,S Z,S(S Z)]) (map map [S,add (S Z),mul (S(S Z)),id])"
nipkow@19829
    83
normal_form "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) [None, Some ()]"
nipkow@19829
    84
normal_form "case xs of [] \<Rightarrow> True | x#xs \<Rightarrow> False"
nipkow@19829
    85
normal_form "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) xs"
nipkow@19829
    86
normal_form "let x = y::'x in [x,x]"
nipkow@19829
    87
normal_form "Let y (%x. [x,x])"
nipkow@19829
    88
normal_form "case n of Z \<Rightarrow> True | S x \<Rightarrow> False"
nipkow@19829
    89
normal_form "(%(x,y). add x y) (S z,S z)"
nipkow@19829
    90
normal_form "filter (%x. x) ([True,False,x]@xs)"
nipkow@19829
    91
normal_form "filter Not ([True,False,x]@xs)"
nipkow@19829
    92
haftmann@20842
    93
lemma "[x,y,z] @ [a,b,c] = [x, y, z, a, b ,c]" by normalization
haftmann@21117
    94
lemma "(%(xs, ys). xs @ ys) = split op @" by normalization
haftmann@21117
    95
lemma "(%(xs, ys). xs @ ys) ([a, b, c], [d, e, f]) = [a, b, c, d, e, f]" by normalization
nipkow@19829
    96
normal_form "%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True"
haftmann@21117
    97
lemma "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) [None, Some ()] = [False, True]"
haftmann@21117
    98
  by normalization
nipkow@19829
    99
haftmann@20842
   100
lemma "last [a, b, c] = c"
haftmann@20842
   101
  by normalization
haftmann@20842
   102
lemma "last ([a, b, c] @ xs) = (if null xs then c else last xs)"
haftmann@20842
   103
  by normalization
nipkow@19829
   104
haftmann@20842
   105
lemma "(2::int) + 3 - 1 + (- k) * 2 = 4 + - k * 2" by normalization
haftmann@20842
   106
lemma "(-4::int) * 2 = -8" by normalization
haftmann@20842
   107
lemma "abs ((-4::int) + 2 * 1) = 2" by normalization
haftmann@20842
   108
lemma "(2::int) + 3 = 5" by normalization
haftmann@20842
   109
lemma "(2::int) + 3 * (- 4) * (- 1) = 14" by normalization
haftmann@20842
   110
lemma "(2::int) + 3 * (- 4) * 1 + 0 = -10" by normalization
haftmann@20842
   111
lemma "(2::int) < 3" by normalization
haftmann@20842
   112
lemma "(2::int) <= 3" by normalization
haftmann@20842
   113
lemma "abs ((-4::int) + 2 * 1) = 2" by normalization
haftmann@20842
   114
lemma "4 - 42 * abs (3 + (-7\<Colon>int)) = -164" by normalization
haftmann@20352
   115
normal_form "min 0 x"
haftmann@20352
   116
normal_form "min 0 (x::nat)"
haftmann@20842
   117
lemma "(if (0\<Colon>nat) \<le> (x\<Colon>nat) then 0\<Colon>nat else x) = 0" by normalization
nipkow@19829
   118
haftmann@21059
   119
lemma "nat 4 = Suc (Suc (Suc (Suc 0)))" by normalization
nipkow@20922
   120
haftmann@21059
   121
normal_form "Suc 0 \<in> set ms"
nipkow@20922
   122
nipkow@19829
   123
end