src/HOL/Numeral.thy
author obua
Tue, 18 May 2004 10:01:44 +0200
changeset 14754 a080eeeaec14
parent 14443 75910c7557c5
child 14800 50581f2b2c0e
permissions -rw-r--r--
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Numeral.thy
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
     3
    Author:     Larry Paulson and Markus Wenzel
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
     4
9410
612ee826a409 removed selector syntax -- improper tuples are broken beyond repair :-(
wenzelm
parents: 9358
diff changeset
     5
Generic numerals represented as twos-complement bit strings.
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
     6
*)
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
     7
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
     8
theory Numeral = Datatype
9035
371f023d3dbd removed explicit terminator (";");
wenzelm
parents: 6988
diff changeset
     9
files "Tools/numeral_syntax.ML":
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    10
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    11
text{* The file @{text numeral_syntax.ML} hides the constructors Pls and Min.
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    12
   Only qualified access bin.Pls and bin.Min is allowed.
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    13
   We do not hide Bit because we need the BIT infix syntax.*}
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    14
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    15
text{*A number can have multiple representations, namely leading Falses with
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    16
sign @{term Pls} and leading Trues with sign @{term Min}.
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    17
See @{text "ZF/Integ/twos-compl.ML"}, function @{text int_of_binary},
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    18
for the numerical interpretation.
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    19
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    20
The representation expects that @{text "(m mod 2)"} is 0 or 1,
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    21
even if m is negative;
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    22
For instance, @{text "-5 div 2 = -3"} and @{text "-5 mod 2 = 1"}; thus
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    23
@{text "-5 = (-3)*2 + 1"}.
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    24
*}
13490
44bdc150211b Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents: 12738
diff changeset
    25
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    26
datatype
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    27
  bin = Pls  --{*Plus: Stands for an infinite string of leading Falses*}
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    28
      | Min --{*Minus: Stands for an infinite string of leading Trues*}
9358
973672495414 added syntax for proper / improper selector functions;
wenzelm
parents: 9035
diff changeset
    29
      | Bit bin bool    (infixl "BIT" 90)
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    30
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    31
axclass
12338
de0f4a63baa5 renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents: 12098
diff changeset
    32
  number < type  -- {* for numeric types: nat, int, real, \dots *}
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    33
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    34
consts
9035
371f023d3dbd removed explicit terminator (";");
wenzelm
parents: 6988
diff changeset
    35
  number_of :: "bin => 'a::number"
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    36
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    37
syntax
12098
784fe681ba26 use num_const of Pure;
wenzelm
parents: 11868
diff changeset
    38
  "_Numeral" :: "num_const => 'a"    ("_")
11699
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    39
  Numeral0 :: 'a
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    40
  Numeral1 :: 'a
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    41
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    42
translations
13490
44bdc150211b Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents: 12738
diff changeset
    43
  "Numeral0" == "number_of bin.Pls"
44bdc150211b Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents: 12738
diff changeset
    44
  "Numeral1" == "number_of (bin.Pls BIT True)"
11488
4ff900551340 constify numeral tokens in order to allow translations;
wenzelm
parents: 9410
diff changeset
    45
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    46
9035
371f023d3dbd removed explicit terminator (";");
wenzelm
parents: 6988
diff changeset
    47
setup NumeralSyntax.setup
6905
9bc05ec3497b added Numeral.thy, Tools/numeral_syntax.ML;
wenzelm
parents:
diff changeset
    48
12738
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    49
syntax (xsymbols)
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    50
  "_square" :: "'a => 'a"  ("(_\<twosuperior>)" [1000] 999)
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    51
syntax (HTML output)
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    52
  "_square" :: "'a => 'a"  ("(_\<twosuperior>)" [1000] 999)
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    53
syntax (output)
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    54
  "_square" :: "'a => 'a"  ("(_ ^/ 2)" [81] 80)
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    55
translations
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    56
  "x\<twosuperior>" == "x^2"
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    57
  "x\<twosuperior>" <= "x^(2::nat)"
11699
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    58
12738
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    59
11699
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    60
lemma Let_number_of [simp]: "Let (number_of v) f == f (number_of v)"
12738
9d80e3746eb0 symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents: 12338
diff changeset
    61
  -- {* Unfold all @{text let}s involving constants *}
11699
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    62
  by (simp add: Let_def)
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    63
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    64
lemma Let_0 [simp]: "Let 0 f == f 0"
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    65
  by (simp add: Let_def)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    66
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    67
lemma Let_1 [simp]: "Let 1 f == f 1"
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    68
  by (simp add: Let_def)
11699
c7df55158574 "num" syntax;
wenzelm
parents: 11488
diff changeset
    69
14288
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13490
diff changeset
    70
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    71
consts
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    72
  NCons     :: "[bin,bool]=>bin"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    73
  bin_succ  :: "bin=>bin"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    74
  bin_pred  :: "bin=>bin"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    75
  bin_minus :: "bin=>bin"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    76
  bin_add   :: "[bin,bin]=>bin"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    77
  bin_mult  :: "[bin,bin]=>bin"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    78
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    79
text{*@{term NCons} inserts a bit, suppressing leading 0s and 1s*}
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    80
primrec
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    81
  NCons_Pls:  "NCons bin.Pls b = (if b then (bin.Pls BIT b) else bin.Pls)"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    82
  NCons_Min:  "NCons bin.Min b = (if b then bin.Min else (bin.Min BIT b))"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    83
  NCons_BIT:  "NCons (w BIT x) b = (w BIT x) BIT b"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    84
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    85
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    86
primrec
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    87
  bin_succ_Pls: "bin_succ bin.Pls = bin.Pls BIT True"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    88
  bin_succ_Min: "bin_succ bin.Min = bin.Pls"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    89
  bin_succ_BIT: "bin_succ(w BIT x) =
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    90
  	            (if x then bin_succ w BIT False
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    91
	                  else NCons w True)"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    92
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    93
primrec
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    94
  bin_pred_Pls: "bin_pred bin.Pls = bin.Min"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    95
  bin_pred_Min: "bin_pred bin.Min = bin.Min BIT False"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    96
  bin_pred_BIT: "bin_pred(w BIT x) =
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    97
	            (if x then NCons w False
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    98
		          else (bin_pred w) BIT True)"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
    99
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   100
primrec
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   101
  bin_minus_Pls: "bin_minus bin.Pls = bin.Pls"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   102
  bin_minus_Min: "bin_minus bin.Min = bin.Pls BIT True"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   103
  bin_minus_BIT: "bin_minus(w BIT x) =
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   104
	             (if x then bin_pred (NCons (bin_minus w) False)
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   105
		           else bin_minus w BIT False)"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   106
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   107
primrec
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   108
  bin_add_Pls: "bin_add bin.Pls w = w"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   109
  bin_add_Min: "bin_add bin.Min w = bin_pred w"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   110
  bin_add_BIT:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   111
    "bin_add (v BIT x) w =
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   112
       (case w of Pls => v BIT x
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   113
                | Min => bin_pred (v BIT x)
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   114
                | (w BIT y) =>
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   115
      	            NCons (bin_add v (if (x & y) then bin_succ w else w))
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   116
	                  (x~=y))"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   117
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   118
primrec
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   119
  bin_mult_Pls: "bin_mult bin.Pls w = bin.Pls"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   120
  bin_mult_Min: "bin_mult bin.Min w = bin_minus w"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   121
  bin_mult_BIT: "bin_mult (v BIT x) w =
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   122
	            (if x then (bin_add (NCons (bin_mult v w) False) w)
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   123
	                  else (NCons (bin_mult v w) False))"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   124
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   125
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   126
subsection{*Extra rules for @{term bin_succ}, @{term bin_pred}, 
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   127
  @{term bin_add} and @{term bin_mult}*}
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   128
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   129
lemma NCons_Pls_0: "NCons bin.Pls False = bin.Pls"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   130
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   131
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   132
lemma NCons_Pls_1: "NCons bin.Pls True = bin.Pls BIT True"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   133
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   134
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   135
lemma NCons_Min_0: "NCons bin.Min False = bin.Min BIT False"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   136
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   137
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   138
lemma NCons_Min_1: "NCons bin.Min True = bin.Min"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   139
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   140
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   141
lemma bin_succ_1: "bin_succ(w BIT True) = (bin_succ w) BIT False"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   142
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   143
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   144
lemma bin_succ_0: "bin_succ(w BIT False) =  NCons w True"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   145
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   146
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   147
lemma bin_pred_1: "bin_pred(w BIT True) = NCons w False"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   148
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   149
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   150
lemma bin_pred_0: "bin_pred(w BIT False) = (bin_pred w) BIT True"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   151
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   152
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   153
lemma bin_minus_1: "bin_minus(w BIT True) = bin_pred (NCons (bin_minus w) False)"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   154
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   155
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   156
lemma bin_minus_0: "bin_minus(w BIT False) = (bin_minus w) BIT False"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   157
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   158
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   159
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   160
subsection{*Binary Addition and Multiplication:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   161
         @{term bin_add} and @{term bin_mult}*}
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   162
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   163
lemma bin_add_BIT_11:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   164
     "bin_add (v BIT True) (w BIT True) =
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   165
     NCons (bin_add v (bin_succ w)) False"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   166
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   167
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   168
lemma bin_add_BIT_10:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   169
     "bin_add (v BIT True) (w BIT False) = NCons (bin_add v w) True"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   170
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   171
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   172
lemma bin_add_BIT_0:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   173
     "bin_add (v BIT False) (w BIT y) = NCons (bin_add v w) y"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   174
by auto
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   175
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   176
lemma bin_add_Pls_right: "bin_add w bin.Pls = w"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   177
by (induct_tac "w", auto)
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   178
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   179
lemma bin_add_Min_right: "bin_add w bin.Min = bin_pred w"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   180
by (induct_tac "w", auto)
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   181
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   182
lemma bin_add_BIT_BIT:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   183
     "bin_add (v BIT x) (w BIT y) =
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   184
     NCons(bin_add v (if x & y then (bin_succ w) else w)) (x~= y)"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   185
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   186
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   187
lemma bin_mult_1:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   188
     "bin_mult (v BIT True) w = bin_add (NCons (bin_mult v w) False) w"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   189
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   190
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   191
lemma bin_mult_0: "bin_mult (v BIT False) w = NCons (bin_mult v w) False"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   192
by simp
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   193
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14288
diff changeset
   194
9035
371f023d3dbd removed explicit terminator (";");
wenzelm
parents: 6988
diff changeset
   195
end