src/HOL/ex/Hex_Bin_Examples.thy
author huffman
Wed, 09 Nov 2011 11:44:42 +0100
changeset 45436 62bc9474d04b
parent 41460 ea56b98aee83
child 58889 5b7a9633cfa8
permissions -rw-r--r--
use simproc_setup for some nat_numeral simprocs; add simproc tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20866
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     1
(*  Title:      HOL/ex/Hex_Bin_Examples.thy
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     2
    Author:     Gerwin Klein, NICTA
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     3
*)
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     4
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     5
header {* Examples for hexadecimal and binary numerals *}
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     6
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     7
theory Hex_Bin_Examples imports Main 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     8
begin
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
     9
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    10
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    11
text "Hex and bin numerals can be used like normal decimal numerals in input"
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    12
lemma "0xFF = 255" by (rule refl)
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    13
lemma "0xF = 0b1111" by (rule refl)
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    14
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    15
text {* 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    16
  Just like decimal numeral they are polymorphic, for arithmetic 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    17
  they need to be constrained
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    18
*}
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    19
lemma "0x0A + 0x10 = (0x1A :: nat)" by simp
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    20
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    21
text "The number of leading zeros is irrelevant"
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    22
lemma "0b00010000 = 0x10" by (rule refl) 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    23
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    24
text "Unary minus works as for decimal numerals"
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    25
lemma "- 0x0A = - 10" by (rule refl)
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    26
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    27
text {*
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    28
  Hex and bin numerals are printed as decimal: @{term "0b10"}
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    29
*}
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    30
term "0b10"
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    31
term "0x0A"
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    32
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    33
text {* 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    34
  The numerals 0 and 1 are syntactically different from the 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    35
  constants 0 and 1. For the usual numeric types, their values 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    36
  are the same, though.
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    37
*}
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    38
lemma "0x01 = 1" oops 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    39
lemma "0x00 = 0" oops 
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    40
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    41
lemma "0x01 = (1::nat)" by simp
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    42
lemma "0b0000 = (0::int)" by simp
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    43
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    44
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    45
end
bc366b4b6ea4 examples for hex and bin numerals
kleing
parents:
diff changeset
    46