author | wenzelm |
Wed, 23 Jan 2002 16:58:05 +0100 | |
changeset 12838 | 093d9b8979f2 |
parent 12440 | fb5851b71a82 |
child 12933 | b85c62c4e826 |
permissions | -rw-r--r-- |
7032 | 1 |
(* Title: HOL/NatBin.thy |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
12838 | 5 |
*) |
7032 | 6 |
|
12838 | 7 |
header {* Binary arithmetic for the natural numbers *} |
7032 | 8 |
|
10574
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
9509
diff
changeset
|
9 |
theory NatBin = IntPower |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
9509
diff
changeset
|
10 |
files ("nat_bin.ML"): |
7032 | 11 |
|
12838 | 12 |
text {* |
13 |
This case is simply reduced to that for the non-negative integers. |
|
14 |
*} |
|
15 |
||
16 |
||
17 |
instance nat :: number .. |
|
18 |
||
19 |
defs (overloaded) |
|
20 |
nat_number_of_def: "(number_of::bin => nat) v == nat ((number_of :: bin => int) v)" |
|
21 |
||
22 |
use "nat_bin.ML" |
|
23 |
setup nat_bin_arith_setup |
|
24 |
||
25 |
lemma nat_number_of_Pls: "number_of Pls = (0::nat)" |
|
26 |
by (simp add: number_of_Pls nat_number_of_def) |
|
27 |
||
28 |
lemma nat_number_of_Min: "number_of Min = (0::nat)" |
|
29 |
apply (simp only: number_of_Min nat_number_of_def nat_zminus_int) |
|
30 |
apply (simp add: neg_nat) |
|
31 |
done |
|
7032 | 32 |
|
12838 | 33 |
lemma nat_number_of_BIT_True: |
34 |
"number_of (w BIT True) = |
|
35 |
(if neg (number_of w) then 0 |
|
36 |
else let n = number_of w in Suc (n + n))" |
|
37 |
apply (simp only: nat_number_of_def Let_def split: split_if) |
|
38 |
apply (intro conjI impI) |
|
39 |
apply (simp add: neg_nat neg_number_of_BIT) |
|
40 |
apply (rule int_int_eq [THEN iffD1]) |
|
41 |
apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms) |
|
42 |
apply (simp only: number_of_BIT if_True zadd_assoc) |
|
43 |
done |
|
7032 | 44 |
|
12838 | 45 |
lemma nat_number_of_BIT_False: |
46 |
"number_of (w BIT False) = (let n::nat = number_of w in n + n)" |
|
47 |
apply (simp only: nat_number_of_def Let_def) |
|
48 |
apply (cases "neg (number_of w)") |
|
49 |
apply (simp add: neg_nat neg_number_of_BIT) |
|
50 |
apply (rule int_int_eq [THEN iffD1]) |
|
51 |
apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms) |
|
52 |
apply (simp only: number_of_BIT if_False zadd_0 zadd_assoc) |
|
53 |
done |
|
54 |
||
55 |
lemmas nat_number_of = |
|
56 |
nat_number_of_Pls nat_number_of_Min |
|
57 |
nat_number_of_BIT_True nat_number_of_BIT_False |
|
58 |
||
59 |
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)" |
|
60 |
by (simp add: Let_def) |
|
10574
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
9509
diff
changeset
|
61 |
|
12440 | 62 |
|
63 |
subsection {* Configuration of the code generator *} |
|
64 |
||
65 |
types_code |
|
66 |
"int" ("int") |
|
67 |
||
68 |
lemmas [code] = int_0 int_Suc |
|
69 |
||
70 |
lemma [code]: "nat x = (if x <= 0 then 0 else Suc (nat (x - 1)))" |
|
71 |
by (simp add: Suc_nat_eq_nat_zadd1) |
|
72 |
||
73 |
consts_code |
|
74 |
"0" :: "int" ("0") |
|
75 |
"1" :: "int" ("1") |
|
76 |
"uminus" :: "int => int" ("~") |
|
77 |
"op +" :: "int => int => int" ("(_ +/ _)") |
|
78 |
"op *" :: "int => int => int" ("(_ */ _)") |
|
79 |
"neg" ("(_ < 0)") |
|
80 |
||
7032 | 81 |
end |