src/HOL/Tools/ComputeNumeral.thy
author haftmann
Tue, 15 Jan 2008 16:19:23 +0100
changeset 25919 8b1c0d434824
parent 23664 9c486517354a
child 26075 815f3ccc0b45
permissions -rw-r--r--
joined theories IntDef, Numeral, IntArith to theory Int
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
     1
theory ComputeNumeral
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
     2
imports ComputeHOL Float
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
     3
begin
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
     4
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
     5
(* normalization of bit strings *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
     6
lemmas bitnorm = Pls_0_eq Min_1_eq
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
     7
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
     8
(* neg for bit strings *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
     9
lemma neg1: "neg Int.Pls = False" by (simp add: Int.Pls_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    10
lemma neg2: "neg Int.Min = True" apply (subst Int.Min_def) by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    11
lemma neg3: "neg (x BIT Int.B0) = neg x" apply (simp add: neg_def) apply (subst Bit_def) by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    12
lemma neg4: "neg (x BIT Int.B1) = neg x" apply (simp add: neg_def) apply (subst Bit_def) by auto  
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    13
lemmas bitneg = neg1 neg2 neg3 neg4
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    14
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    15
(* iszero for bit strings *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    16
lemma iszero1: "iszero Int.Pls = True" by (simp add: Int.Pls_def iszero_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    17
lemma iszero2: "iszero Int.Min = False" apply (subst Int.Min_def) apply (subst iszero_def) by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    18
lemma iszero3: "iszero (x BIT Int.B0) = iszero x" apply (subst Int.Bit_def) apply (subst iszero_def)+ by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    19
lemma iszero4: "iszero (x BIT Int.B1) = False" apply (subst Int.Bit_def) apply (subst iszero_def)+  apply simp by arith
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    20
lemmas bitiszero = iszero1 iszero2 iszero3 iszero4
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    21
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    22
(* lezero for bit strings *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    23
constdefs
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    24
  "lezero x == (x \<le> 0)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    25
lemma lezero1: "lezero Int.Pls = True" unfolding Int.Pls_def lezero_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    26
lemma lezero2: "lezero Int.Min = True" unfolding Int.Min_def lezero_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    27
lemma lezero3: "lezero (x BIT Int.B0) = lezero x" unfolding Int.Bit_def lezero_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    28
lemma lezero4: "lezero (x BIT Int.B1) = neg x" unfolding Int.Bit_def lezero_def neg_def by auto
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    29
lemmas bitlezero = lezero1 lezero2 lezero3 lezero4
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    30
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    31
(* equality for bit strings *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    32
lemma biteq1: "(Int.Pls = Int.Pls) = True" by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    33
lemma biteq2: "(Int.Min = Int.Min) = True" by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    34
lemma biteq3: "(Int.Pls = Int.Min) = False" unfolding Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    35
lemma biteq4: "(Int.Min = Int.Pls) = False" unfolding Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    36
lemma biteq5: "(x BIT Int.B0 = y BIT Int.B0) = (x = y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    37
lemma biteq6: "(x BIT Int.B1 = y BIT Int.B1) = (x = y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    38
lemma biteq7: "(x BIT Int.B0 = y BIT Int.B1) = False" unfolding Bit_def by (simp, arith) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    39
lemma biteq8: "(x BIT Int.B1 = y BIT Int.B0) = False" unfolding Bit_def by (simp, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    40
lemma biteq9: "(Int.Pls = x BIT Int.B0) = (Int.Pls = x)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    41
lemma biteq10: "(Int.Pls = x BIT Int.B1) = False" unfolding Bit_def Pls_def by (simp, arith) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    42
lemma biteq11: "(Int.Min = x BIT Int.B0) = False" unfolding Bit_def Min_def by (simp, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    43
lemma biteq12: "(Int.Min = x BIT Int.B1) = (Int.Min = x)" unfolding Bit_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    44
lemma biteq13: "(x BIT Int.B0 = Int.Pls) = (x = Int.Pls)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    45
lemma biteq14: "(x BIT Int.B1 = Int.Pls) = False" unfolding Bit_def Pls_def by (simp, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    46
lemma biteq15: "(x BIT Int.B0 = Int.Min) = False" unfolding Bit_def Pls_def Min_def by (simp, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    47
lemma biteq16: "(x BIT Int.B1 = Int.Min) = (x = Int.Min)" unfolding Bit_def Min_def by (simp, arith)
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    48
lemmas biteq = biteq1 biteq2 biteq3 biteq4 biteq5 biteq6 biteq7 biteq8 biteq9 biteq10 biteq11 biteq12 biteq13 biteq14 biteq15 biteq16
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    49
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    50
(* x < y for bit strings *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    51
lemma bitless1: "(Int.Pls < Int.Min) = False" unfolding Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    52
lemma bitless2: "(Int.Pls < Int.Pls) = False" by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    53
lemma bitless3: "(Int.Min < Int.Pls) = True" unfolding Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    54
lemma bitless4: "(Int.Min < Int.Min) = False" unfolding Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    55
lemma bitless5: "(x BIT Int.B0 < y BIT Int.B0) = (x < y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    56
lemma bitless6: "(x BIT Int.B1 < y BIT Int.B1) = (x < y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    57
lemma bitless7: "(x BIT Int.B0 < y BIT Int.B1) = (x \<le> y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    58
lemma bitless8: "(x BIT Int.B1 < y BIT Int.B0) = (x < y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    59
lemma bitless9: "(Int.Pls < x BIT Int.B0) = (Int.Pls < x)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    60
lemma bitless10: "(Int.Pls < x BIT Int.B1) = (Int.Pls \<le> x)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    61
lemma bitless11: "(Int.Min < x BIT Int.B0) = (Int.Pls \<le> x)" unfolding Bit_def Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    62
lemma bitless12: "(Int.Min < x BIT Int.B1) = (Int.Min < x)" unfolding Bit_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    63
lemma bitless13: "(x BIT Int.B0 < Int.Pls) = (x < Int.Pls)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    64
lemma bitless14: "(x BIT Int.B1 < Int.Pls) = (x < Int.Pls)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    65
lemma bitless15: "(x BIT Int.B0 < Int.Min) = (x < Int.Pls)" unfolding Bit_def Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    66
lemma bitless16: "(x BIT Int.B1 < Int.Min) = (x < Int.Min)" unfolding Bit_def Min_def by auto
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    67
lemmas bitless = bitless1 bitless2 bitless3 bitless4 bitless5 bitless6 bitless7 bitless8 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    68
                 bitless9 bitless10 bitless11 bitless12 bitless13 bitless14 bitless15 bitless16
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    69
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    70
(* x \<le> y for bit strings *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    71
lemma bitle1: "(Int.Pls \<le> Int.Min) = False" unfolding Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    72
lemma bitle2: "(Int.Pls \<le> Int.Pls) = True" by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    73
lemma bitle3: "(Int.Min \<le> Int.Pls) = True" unfolding Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    74
lemma bitle4: "(Int.Min \<le> Int.Min) = True" unfolding Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    75
lemma bitle5: "(x BIT Int.B0 \<le> y BIT Int.B0) = (x \<le> y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    76
lemma bitle6: "(x BIT Int.B1 \<le> y BIT Int.B1) = (x \<le> y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    77
lemma bitle7: "(x BIT Int.B0 \<le> y BIT Int.B1) = (x \<le> y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    78
lemma bitle8: "(x BIT Int.B1 \<le> y BIT Int.B0) = (x < y)" unfolding Bit_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    79
lemma bitle9: "(Int.Pls \<le> x BIT Int.B0) = (Int.Pls \<le> x)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    80
lemma bitle10: "(Int.Pls \<le> x BIT Int.B1) = (Int.Pls \<le> x)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    81
lemma bitle11: "(Int.Min \<le> x BIT Int.B0) = (Int.Pls \<le> x)" unfolding Bit_def Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    82
lemma bitle12: "(Int.Min \<le> x BIT Int.B1) = (Int.Min \<le> x)" unfolding Bit_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    83
lemma bitle13: "(x BIT Int.B0 \<le> Int.Pls) = (x \<le> Int.Pls)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    84
lemma bitle14: "(x BIT Int.B1 \<le> Int.Pls) = (x < Int.Pls)" unfolding Bit_def Pls_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    85
lemma bitle15: "(x BIT Int.B0 \<le> Int.Min) = (x < Int.Pls)" unfolding Bit_def Pls_def Min_def by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
    86
lemma bitle16: "(x BIT Int.B1 \<le> Int.Min) = (x \<le> Int.Min)" unfolding Bit_def Min_def by auto
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    87
lemmas bitle = bitle1 bitle2 bitle3 bitle4 bitle5 bitle6 bitle7 bitle8 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    88
                 bitle9 bitle10 bitle11 bitle12 bitle13 bitle14 bitle15 bitle16
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    89
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    90
(* succ for bit strings *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    91
lemmas bitsucc = succ_Pls succ_Min succ_1 succ_0
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    92
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    93
(* pred for bit strings *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    94
lemmas bitpred = pred_Pls pred_Min pred_1 pred_0
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    95
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    96
(* unary minus for bit strings *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    97
lemmas bituminus = minus_Pls minus_Min minus_1 minus_0 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    98
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
    99
(* addition for bit strings *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   100
lemmas bitadd = add_Pls add_Pls_right add_Min add_Min_right add_BIT_11 add_BIT_10 add_BIT_0[where b="Int.B0"] add_BIT_0[where b="Int.B1"]
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   101
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   102
(* multiplication for bit strings *) 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   103
lemma mult_Pls_right: "x * Int.Pls = Int.Pls" by (simp add: Pls_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   104
lemma mult_Min_right: "x * Int.Min = - x" by (subst mult_commute, simp add: mult_Min)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   105
lemma multb0x: "(x BIT Int.B0) * y = (x * y) BIT Int.B0" unfolding Bit_def by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   106
lemma multxb0: "x * (y BIT Int.B0) = (x * y) BIT Int.B0" unfolding Bit_def by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   107
lemma multb1: "(x BIT Int.B1) * (y BIT Int.B1) = (((x * y) BIT Int.B0) + x + y) BIT Int.B1"
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   108
  unfolding Bit_def by (simp add: ring_simps)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   109
lemmas bitmul = mult_Pls mult_Min mult_Pls_right mult_Min_right multb0x multxb0 multb1
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   110
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   111
lemmas bitarith = bitnorm bitiszero bitneg bitlezero biteq bitless bitle bitsucc bitpred bituminus bitadd bitmul 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   112
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   113
constdefs 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   114
  "nat_norm_number_of (x::nat) == x"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   115
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   116
lemma nat_norm_number_of: "nat_norm_number_of (number_of w) = (if lezero w then 0 else number_of w)"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   117
  apply (simp add: nat_norm_number_of_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   118
  unfolding lezero_def iszero_def neg_def
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   119
  apply (simp add: number_of_is_id)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   120
  done
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   121
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   122
(* Normalization of nat literals *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   123
lemma natnorm0: "(0::nat) = number_of (Int.Pls)" by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   124
lemma natnorm1: "(1 :: nat) = number_of (Int.Pls BIT Int.B1)"  by auto 
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   125
lemmas natnorm = natnorm0 natnorm1 nat_norm_number_of
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   126
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   127
(* Suc *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   128
lemma natsuc: "Suc (number_of x) = (if neg x then 1 else number_of (Int.succ x))" by (auto simp add: number_of_is_id)
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   129
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   130
(* Addition for nat *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   131
lemma natadd: "number_of x + ((number_of y)::nat) = (if neg x then (number_of y) else (if neg y then number_of x else (number_of (x + y))))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   132
  by (auto simp add: number_of_is_id)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   133
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   134
(* Subtraction for nat *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   135
lemma natsub: "(number_of x) - ((number_of y)::nat) = 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   136
  (if neg x then 0 else (if neg y then number_of x else (nat_norm_number_of (number_of (x + (- y))))))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   137
  unfolding nat_norm_number_of
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   138
  by (auto simp add: number_of_is_id neg_def lezero_def iszero_def Let_def nat_number_of_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   139
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   140
(* Multiplication for nat *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   141
lemma natmul: "(number_of x) * ((number_of y)::nat) = 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   142
  (if neg x then 0 else (if neg y then 0 else number_of (x * y)))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   143
  apply (auto simp add: number_of_is_id neg_def iszero_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   144
  apply (case_tac "x > 0")
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   145
  apply auto
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   146
  apply (simp add: mult_strict_left_mono[where a=y and b=0 and c=x, simplified])
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   147
  done
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   148
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   149
lemma nateq: "(((number_of x)::nat) = (number_of y)) = ((lezero x \<and> lezero y) \<or> (x = y))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   150
  by (auto simp add: iszero_def lezero_def neg_def number_of_is_id)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   151
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   152
lemma natless: "(((number_of x)::nat) < (number_of y)) = ((x < y) \<and> (\<not> (lezero y)))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   153
  by (auto simp add: number_of_is_id neg_def lezero_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   154
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   155
lemma natle: "(((number_of x)::nat) \<le> (number_of y)) = (y < x \<longrightarrow> lezero x)"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   156
  by (auto simp add: number_of_is_id lezero_def nat_number_of_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   157
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   158
fun natfac :: "nat \<Rightarrow> nat"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   159
where
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   160
   "natfac n = (if n = 0 then 1 else n * (natfac (n - 1)))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   161
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   162
lemmas compute_natarith = bitarith natnorm natsuc natadd natsub natmul nateq natless natle natfac.simps
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   163
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   164
lemma number_eq: "(((number_of x)::'a::{number_ring, ordered_idom}) = (number_of y)) = (x = y)"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   165
  unfolding number_of_eq
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   166
  apply simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   167
  done
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   168
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   169
lemma number_le: "(((number_of x)::'a::{number_ring, ordered_idom}) \<le>  (number_of y)) = (x \<le> y)"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   170
  unfolding number_of_eq
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   171
  apply simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   172
  done
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   173
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   174
lemma number_less: "(((number_of x)::'a::{number_ring, ordered_idom}) <  (number_of y)) = (x < y)"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   175
  unfolding number_of_eq 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   176
  apply simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   177
  done
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   178
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   179
lemma number_diff: "((number_of x)::'a::{number_ring, ordered_idom}) - number_of y = number_of (x + (- y))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   180
  apply (subst diff_number_of_eq)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   181
  apply simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   182
  done
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   183
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   184
lemmas number_norm = number_of_Pls[symmetric] numeral_1_eq_1[symmetric]
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   185
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   186
lemmas compute_numberarith = number_of_minus[symmetric] number_of_add[symmetric] number_diff number_of_mult[symmetric] number_norm number_eq number_le number_less
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   187
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   188
lemma compute_real_of_nat_number_of: "real ((number_of v)::nat) = (if neg v then 0 else number_of v)"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   189
  by (simp only: real_of_nat_number_of number_of_is_id)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   190
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   191
lemma compute_nat_of_int_number_of: "nat ((number_of v)::int) = (number_of v)"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   192
  by simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   193
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   194
lemmas compute_num_conversions = compute_real_of_nat_number_of compute_nat_of_int_number_of real_number_of
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   195
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   196
lemmas zpowerarith = zpower_number_of_even
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   197
  zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring]
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   198
  zpower_Pls zpower_Min
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   199
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   200
(* div, mod *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   201
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   202
lemma adjust: "adjust b (q, r) = (if 0 \<le> r - b then (2 * q + 1, r - b) else (2 * q, r))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   203
  by (auto simp only: adjust_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   204
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   205
lemma negateSnd: "negateSnd (q, r) = (q, -r)" 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   206
  by (auto simp only: negateSnd_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   207
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   208
lemma divAlg: "divAlg (a, b) = (if 0\<le>a then
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   209
                  if 0\<le>b then posDivAlg a b
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   210
                  else if a=0 then (0, 0)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   211
                       else negateSnd (negDivAlg (-a) (-b))
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   212
               else 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   213
                  if 0<b then negDivAlg a b
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   214
                  else negateSnd (posDivAlg (-a) (-b)))"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   215
  by (auto simp only: divAlg_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   216
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   217
lemmas compute_div_mod = div_def mod_def divAlg adjust negateSnd posDivAlg.simps negDivAlg.simps
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   218
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   219
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   220
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   221
(* collecting all the theorems *)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   222
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   223
lemma even_Pls: "even (Int.Pls) = True"
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   224
  apply (unfold Pls_def even_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   225
  by simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   226
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   227
lemma even_Min: "even (Int.Min) = False"
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   228
  apply (unfold Min_def even_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   229
  by simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   230
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   231
lemma even_B0: "even (x BIT Int.B0) = True"
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   232
  apply (unfold Bit_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   233
  by simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   234
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 23664
diff changeset
   235
lemma even_B1: "even (x BIT Int.B1) = False"
23664
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   236
  apply (unfold Bit_def)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   237
  by simp
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   238
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   239
lemma even_number_of: "even ((number_of w)::int) = even w"
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   240
  by (simp only: number_of_is_id)
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   241
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   242
lemmas compute_even = even_Pls even_Min even_B0 even_B1 even_number_of
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   243
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   244
lemmas compute_numeral = compute_if compute_let compute_pair compute_bool 
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   245
                         compute_natarith compute_numberarith max_def min_def compute_num_conversions zpowerarith compute_div_mod compute_even
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   246
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   247
end
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   248
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   249
9c486517354a added computing oracle support for HOL and numerals
obua
parents:
diff changeset
   250