author | wenzelm |
Sun, 01 Oct 2006 18:29:32 +0200 | |
changeset 20813 | 379ce56e5dc2 |
parent 20807 | bd3b60f9a343 |
child 20842 | f5f69a1059f4 |
permissions | -rw-r--r-- |
19829 | 1 |
(* ID: $Id$ |
2 |
Authors: Klaus Aehlig, Tobias Nipkow |
|
20807 | 3 |
*) |
19829 | 4 |
|
20807 | 5 |
header "Test of normalization function" |
19829 | 6 |
|
7 |
theory NormalForm |
|
8 |
imports Main |
|
9 |
begin |
|
10 |
||
19971 | 11 |
lemma "p \<longrightarrow> True" by normalization |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20352
diff
changeset
|
12 |
declare disj_assoc [code func] |
20595 | 13 |
lemma "((P | Q) | R) = (P | (Q | R))" by normalization |
19971 | 14 |
lemma "0 + (n::nat) = n" by normalization |
20595 | 15 |
lemma "0 + Suc n = Suc n" by normalization |
16 |
lemma "Suc n + Suc m = n + Suc (Suc m)" by normalization |
|
19971 | 17 |
lemma "~((0::nat) < (0::nat))" by normalization |
18 |
||
19 |
||
19829 | 20 |
datatype n = Z | S n |
21 |
consts |
|
22 |
add :: "n \<Rightarrow> n \<Rightarrow> n" |
|
23 |
add2 :: "n \<Rightarrow> n \<Rightarrow> n" |
|
24 |
mul :: "n \<Rightarrow> n \<Rightarrow> n" |
|
25 |
mul2 :: "n \<Rightarrow> n \<Rightarrow> n" |
|
26 |
exp :: "n \<Rightarrow> n \<Rightarrow> n" |
|
27 |
primrec |
|
28 |
"add Z = id" |
|
29 |
"add (S m) = S o add m" |
|
30 |
primrec |
|
31 |
"add2 Z n = n" |
|
32 |
"add2 (S m) n = S(add2 m n)" |
|
33 |
||
34 |
lemma [code]: "add2 (add2 n m) k = add2 n (add2 m k)" |
|
20807 | 35 |
by(induct n) auto |
19829 | 36 |
lemma [code]: "add2 n (S m) = S(add2 n m)" |
20807 | 37 |
by(induct n) auto |
19829 | 38 |
lemma [code]: "add2 n Z = n" |
20807 | 39 |
by(induct n) auto |
19971 | 40 |
|
41 |
lemma "add2 (add2 n m) k = add2 n (add2 m k)" by normalization |
|
42 |
lemma "add2 (add2 (S n) (S m)) (S k) = S(S(S(add2 n (add2 m k))))" by normalization |
|
43 |
lemma "add2 (add2 (S n) (add2 (S m) Z)) (S k) = S(S(S(add2 n (add2 m k))))" by normalization |
|
19829 | 44 |
|
45 |
primrec |
|
46 |
"mul Z = (%n. Z)" |
|
47 |
"mul (S m) = (%n. add (mul m n) n)" |
|
48 |
primrec |
|
49 |
"mul2 Z n = Z" |
|
50 |
"mul2 (S m) n = add2 n (mul2 m n)" |
|
51 |
primrec |
|
52 |
"exp m Z = S Z" |
|
53 |
"exp m (S n) = mul (exp m n) m" |
|
54 |
||
19971 | 55 |
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 |
56 |
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 |
|
57 |
lemma "exp (S(S Z)) (S(S(S(S Z)))) = exp (S(S(S(S Z)))) (S(S Z))" by normalization |
|
58 |
||
59 |
lemma "(let ((x,y),(u,v)) = ((Z,Z),(Z,Z)) in add (add x y) (add u v)) = Z" by normalization |
|
60 |
lemma "(%((x,y),(u,v)). add (add x y) (add u v)) ((Z,Z),(Z,Z)) = Z" by normalization |
|
61 |
||
62 |
lemma "case Z of Z \<Rightarrow> True | S x \<Rightarrow> False" by normalization |
|
19829 | 63 |
|
64 |
normal_form "[] @ []" |
|
65 |
normal_form "[] @ xs" |
|
66 |
normal_form "[a::'d,b,c] @ xs" |
|
67 |
normal_form "[%a::'x. a, %b. b, c] @ xs" |
|
68 |
normal_form "[%a::'x. a, %b. b, c] @ [u,v]" |
|
69 |
normal_form "map f (xs::'c list)" |
|
70 |
normal_form "map f [x,y,z::'x]" |
|
71 |
normal_form "map (%f. f True) [id,g,Not]" |
|
72 |
normal_form "map (%f. f True) ([id,g,Not] @ fs)" |
|
73 |
normal_form "rev[a,b,c]" |
|
74 |
normal_form "rev(a#b#cs)" |
|
75 |
normal_form "map map [f,g,h]" |
|
76 |
normal_form "map (%F. F [a,b,c::'x]) (map map [f,g,h])" |
|
77 |
normal_form "map (%F. F ([a,b,c] @ ds)) (map map ([f,g,h]@fs))" |
|
78 |
normal_form "map (%F. F [Z,S Z,S(S Z)]) (map map [S,add (S Z),mul (S(S Z)),id])" |
|
79 |
normal_form "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) [None, Some ()]" |
|
80 |
normal_form "case xs of [] \<Rightarrow> True | x#xs \<Rightarrow> False" |
|
81 |
normal_form "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) xs" |
|
82 |
normal_form "let x = y::'x in [x,x]" |
|
83 |
normal_form "Let y (%x. [x,x])" |
|
84 |
normal_form "case n of Z \<Rightarrow> True | S x \<Rightarrow> False" |
|
85 |
normal_form "(%(x,y). add x y) (S z,S z)" |
|
86 |
normal_form "filter (%x. x) ([True,False,x]@xs)" |
|
87 |
normal_form "filter Not ([True,False,x]@xs)" |
|
88 |
||
89 |
normal_form "[x,y,z] @ [a,b,c]" |
|
90 |
normal_form "%(xs, ys). xs @ ys" |
|
91 |
normal_form "(%(xs, ys). xs @ ys) ([a, b, c], [d, e, f])" |
|
92 |
normal_form "%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True" |
|
93 |
normal_form "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) [None, Some ()]" |
|
94 |
||
20595 | 95 |
normal_form "last [a, b, c]" |
96 |
normal_form "last ([a, b, c] @ xs)" |
|
19829 | 97 |
|
20352 | 98 |
normal_form "min 0 x" |
99 |
normal_form "min 0 (x::nat)" |
|
19829 | 100 |
|
20595 | 101 |
normal_form "(2::int) + 3 - 1 + (- k) * 2" |
102 |
normal_form "(4::int) * 2" |
|
103 |
normal_form "(-4::int) * 2" |
|
104 |
normal_form "abs ((-4::int) + 2 * 1)" |
|
105 |
normal_form "(2::int) + 3" |
|
106 |
normal_form "(2::int) + 3 * (- 4) * (- 1)" |
|
107 |
normal_form "(2::int) + 3 * (- 4) * 1 + 0" |
|
108 |
normal_form "(2::int) < 3" |
|
109 |
normal_form "(2::int) <= 3" |
|
110 |
normal_form "abs ((-4::int) + 2 * 1)" |
|
111 |
normal_form "4 - 42 * abs (3 + (-7\<Colon>int))" |
|
19829 | 112 |
|
113 |
end |