src/HOL/MicroJava/Comp/NatCanonify.thy
author haftmann
Tue, 24 Nov 2009 14:37:23 +0100
changeset 33954 1bc3b688548c
parent 16417 9bc16273c2d4
child 41589 bbd861837ebc
permissions -rwxr-xr-x
backported parts of abstract byte code verifier from AFP/Jinja
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/Comp/NatCanonify.thy
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     2
    ID:         $Id$
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     3
    Author:     Martin Strecker
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     4
*)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     5
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 14981
diff changeset
     6
theory NatCanonify imports Main begin
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     7
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     8
(************************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     9
  (* Canonizer for converting nat to int *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    10
(************************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    11
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    12
lemma nat_add_canonify: "(n1::nat) + n2 = nat ((int n1) + (int n2))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    13
by (simp add: nat_add_distrib)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    14
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    15
lemma nat_mult_canonify: "(n1::nat) * n2 = nat ((int n1) * (int n2))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    16
by (simp add: nat_mult_distrib)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    17
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    18
lemma nat_diff_canonify: "(n1::nat) - n2 = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    19
  nat (if (int n1) \<le> (int n2) then 0 else (int n1) - (int n2))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    20
by (simp add: zdiff_int nat_int)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    21
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    22
lemma nat_le_canonify: "((n1::nat) \<le> n2) = ((int n1) \<le> (int n2))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    23
by arith
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    24
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    25
lemma nat_less_canonify: "((n1::nat) < n2) = ((int n1) < (int n2))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    26
by arith
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    27
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    28
lemma nat_eq_canonify: "((n1::nat) = n2) = ((int n1) = (int n2))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    29
by arith
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    30
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    31
lemma nat_if_canonify: "(if b then (n1::nat) else n2) =
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    32
  nat (if b then (int n1) else (int n2))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    33
by simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    34
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    35
lemma int_nat_canonify: "(int (nat n)) = (if 0 \<le> n then n else 0)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    36
by simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    37
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    38
lemmas nat_canonify = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    39
  nat_add_canonify nat_mult_canonify nat_diff_canonify 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    40
  nat_le_canonify nat_less_canonify nat_eq_canonify nat_if_canonify 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    41
  int_nat_canonify nat_int
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    42
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    43
end