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