author | webertj |
Fri, 10 Mar 2006 17:24:16 +0100 | |
changeset 19237 | f51301fafdc2 |
parent 19235 | 868129805da8 |
child 19238 | a2a4e6838bfc |
permissions | -rw-r--r-- |
19148 | 1 |
(* ID: $Id$ |
2 |
||
3 |
Temporary test of nbe module. |
|
4 |
*) |
|
5 |
||
6 |
theory nbe |
|
7 |
imports Main |
|
8 |
begin |
|
19202 | 9 |
|
19237 | 10 |
ML "reset quick_and_dirty" |
19148 | 11 |
|
19180 | 12 |
declare disj_assoc[code] |
13 |
||
14 |
norm_by_eval "(P | Q) | R" |
|
15 |
||
19202 | 16 |
(*lemma[code]: "(P \<longrightarrow> P) = True" by blast |
19180 | 17 |
norm_by_eval "P \<longrightarrow> P" |
19202 | 18 |
norm_by_eval "True \<longrightarrow> P"*) |
19180 | 19 |
|
20 |
||
21 |
datatype n = Z | S n |
|
22 |
consts |
|
23 |
add :: "n \<Rightarrow> n \<Rightarrow> n" |
|
24 |
add2 :: "n \<Rightarrow> n \<Rightarrow> n" |
|
25 |
mul :: "n \<Rightarrow> n \<Rightarrow> n" |
|
26 |
mul2 :: "n \<Rightarrow> n \<Rightarrow> n" |
|
27 |
exp :: "n \<Rightarrow> n \<Rightarrow> n" |
|
28 |
primrec |
|
29 |
"add Z = id" |
|
30 |
"add (S m) = S o add m" |
|
31 |
primrec |
|
32 |
"add2 Z n = n" |
|
33 |
"add2 (S m) n = S(add2 m n)" |
|
34 |
||
35 |
lemma [code]: "add2 (add2 n m) k = add2 n (add2 m k)" |
|
36 |
by(induct n, auto) |
|
37 |
lemma [code]: "add2 n (S m) = S(add2 n m)" |
|
38 |
by(induct n, auto) |
|
39 |
lemma [code]: "add2 n Z = n" |
|
40 |
by(induct n, auto) |
|
41 |
||
42 |
norm_by_eval "add2 (add2 n m) k" |
|
43 |
norm_by_eval "add2 (add2 (S n) (S m)) (S k)" |
|
44 |
norm_by_eval "add2 (add2 (S n)(add2 (S m) Z)) (S k)" |
|
45 |
||
46 |
primrec |
|
47 |
"mul Z = (%n. Z)" |
|
48 |
"mul (S m) = (%n. add (mul m n) n)" |
|
49 |
primrec |
|
50 |
"mul2 Z n = Z" |
|
51 |
"mul2 (S m) n = add2 n (mul2 m n)" |
|
52 |
primrec |
|
53 |
"exp m Z = S Z" |
|
54 |
"exp m (S n) = mul (exp m n) m" |
|
55 |
||
56 |
norm_by_eval "mul2 (S(S(S(S(S(S(S Z))))))) (S(S(S(S(S Z)))))" |
|
57 |
norm_by_eval "mul (S(S(S(S(S(S(S Z))))))) (S(S(S(S(S Z)))))" |
|
58 |
norm_by_eval "exp (S(S(S(S(S(S(S Z))))))) (S(S(S(S(S Z)))))" |
|
59 |
||
60 |
norm_by_eval "[] @ []" |
|
61 |
norm_by_eval "[] @ xs" |
|
62 |
norm_by_eval "[a,b,c] @ xs" |
|
63 |
norm_by_eval "[%a. a, %b. b, c] @ xs" |
|
64 |
norm_by_eval "[%a. a, %b. b, c] @ [u,v]" |
|
65 |
norm_by_eval "map f [x,y,z]" |
|
66 |
norm_by_eval "map (%f. f True) [id,g,Not]" |
|
67 |
norm_by_eval "map (%f. f True) ([id,g,Not] @ fs)" |
|
68 |
norm_by_eval "rev[a,b,c]" |
|
69 |
norm_by_eval "rev(a#b#cs)" |
|
70 |
norm_by_eval "map map [f,g,h]" |
|
71 |
norm_by_eval "map (%F. F [a,b,c]) (map map [f,g,h])" |
|
72 |
norm_by_eval "map (%F. F ([a,b,c] @ ds)) (map map ([f,g,h]@fs))" |
|
73 |
norm_by_eval "map (%F. F [Z,S Z,S(S Z)]) (map map [S,add (S Z),mul (S(S Z)),id])" |
|
74 |
norm_by_eval "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) [None, Some ()]" |
|
75 |
norm_by_eval "case xs of [] \<Rightarrow> True | x#xs \<Rightarrow> False" |
|
76 |
norm_by_eval "case Z of Z \<Rightarrow> True | S x \<Rightarrow> False" |
|
77 |
norm_by_eval "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) xs" |
|
78 |
norm_by_eval "let x = y in [x,x]" |
|
79 |
norm_by_eval "Let y (%x. [x,x])" |
|
80 |
norm_by_eval "case n of Z \<Rightarrow> True | S x \<Rightarrow> False" |
|
81 |
norm_by_eval "(%(x,y). add x y) (S z,S z)" |
|
82 |
norm_by_eval "filter (%x. x) ([True,False,x]@xs)" |
|
83 |
norm_by_eval "filter Not ([True,False,x]@xs)" |
|
84 |
||
19167
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
85 |
norm_by_eval "0 + (n::nat)" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
86 |
norm_by_eval "0 + Suc(n)" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
87 |
norm_by_eval "Suc(n) + Suc m" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
88 |
norm_by_eval "[] @ xs" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
89 |
norm_by_eval "(x#xs) @ ys" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
90 |
norm_by_eval "[x,y,z] @ [a,b,c]" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
91 |
norm_by_eval "%(xs, ys). xs @ ys" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
92 |
norm_by_eval "(%(xs, ys). xs @ ys) ([a, b, c], [d, e, f])" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
93 |
norm_by_eval "%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True" |
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19148
diff
changeset
|
94 |
norm_by_eval "map (%x. case x of None \<Rightarrow> False | Some y \<Rightarrow> True) [None, Some ()]" |
19177 | 95 |
norm_by_eval "rev [a, b, c]" |
19148 | 96 |
|
19180 | 97 |
norm_by_eval "case n of None \<Rightarrow> True | Some((x,y),(u,v)) \<Rightarrow> False" |
98 |
norm_by_eval "let ((x,y),(u,v)) = ((Z,Z),(Z,Z)) in add (add x y) (add u v)" |
|
99 |
norm_by_eval "(%((x,y),(u,v)). add (add x y) (add u v)) ((Z,Z),(Z,Z))" |
|
100 |
norm_by_eval "last[a,b,c]" |
|
19202 | 101 |
|
19237 | 102 |
(* |
19202 | 103 |
won't work since it relies on |
104 |
polymorphically used ad-hoc overloaded function: |
|
105 |
norm_by_eval "max 0 (0::nat)" |
|
19235 | 106 |
*) |
19180 | 107 |
|
19235 | 108 |
text (* |
19202 | 109 |
Numerals still take their time\<dots> |
19235 | 110 |
*) |
19202 | 111 |
|
112 |
end |