src/HOL/ex/Hex_Bin_Examples.thy
author wenzelm
Tue, 05 Nov 2019 14:16:16 +0100
changeset 71046 b8aeeedf7e68
parent 69597 ff784d5a5bfb
permissions -rw-r--r--
support for Linux user management;
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
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
     5
section \<open>Examples for hexadecimal and binary numerals\<close>
20866
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
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    15
text \<open>
20866
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
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    18
\<close>
20866
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
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    27
text \<open>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 61343
diff changeset
    28
  Hex and bin numerals are printed as decimal: \<^term>\<open>0b10\<close>
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    29
\<close>
20866
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
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    33
text \<open>
20866
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.
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    37
\<close>
20866
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