src/HOL/ex/Hex_Bin_Examples.thy
author wenzelm
Sat, 23 Nov 2013 17:07:36 +0100
changeset 54566 5f3e9baa8f13
parent 41460 ea56b98aee83
child 58889 5b7a9633cfa8
permissions -rw-r--r--
more accurate goal context;
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