src/HOL/ex/BinEx.thy
author wenzelm
Fri, 28 Sep 2001 20:09:10 +0200
changeset 11637 647e6c84323c
parent 11024 23bf8d787b04
child 11701 3d51fbf81c17
permissions -rw-r--r--
inductive: no collective atts;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
     1
(*  Title:      HOL/ex/BinEx.thy
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
     2
    ID:         $Id$
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
     4
    Copyright   1998  University of Cambridge
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
     5
*)
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
     6
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
     7
header {* Binary arithmetic examples *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
     8
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
     9
theory BinEx = Main:
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    10
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    11
subsection {* The Integers *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    12
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    13
text {* Addition *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    14
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    15
lemma "(#13::int) + #19 = #32"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    16
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    17
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    18
lemma "(#1234::int) + #5678 = #6912"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    19
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    20
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    21
lemma "(#1359::int) + #-2468 = #-1109"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    22
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    23
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    24
lemma "(#93746::int) + #-46375 = #47371"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    25
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    26
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    27
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    28
text {* \medskip Negation *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    29
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    30
lemma "- (#65745::int) = #-65745"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    31
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    32
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    33
lemma "- (#-54321::int) = #54321"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    34
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    35
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    36
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    37
text {* \medskip Multiplication *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    38
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    39
lemma "(#13::int) * #19 = #247"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    40
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    41
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    42
lemma "(#-84::int) * #51 = #-4284"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    43
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    44
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    45
lemma "(#255::int) * #255 = #65025"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    46
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    47
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    48
lemma "(#1359::int) * #-2468 = #-3354012"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    49
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    50
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    51
lemma "(#89::int) * #10 \<noteq> #889"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    52
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    53
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    54
lemma "(#13::int) < #18 - #4"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    55
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    56
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    57
lemma "(#-345::int) < #-242 + #-100"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    58
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    59
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    60
lemma "(#13557456::int) < #18678654"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    61
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    62
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    63
lemma "(#999999::int) \<le> (#1000001 + #1) - #2"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    64
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    65
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    66
lemma "(#1234567::int) \<le> #1234567"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    67
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    68
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    69
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    70
text {* \medskip Quotient and Remainder *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    71
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    72
lemma "(#10::int) div #3 = #3"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    73
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    74
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    75
lemma "(#10::int) mod #3 = #1"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    76
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    77
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    78
text {* A negative divisor *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    79
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    80
lemma "(#10::int) div #-3 = #-4"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    81
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    82
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    83
lemma "(#10::int) mod #-3 = #-2"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    84
  by simp
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
    85
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    86
text {*
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    87
  A negative dividend\footnote{The definition agrees with mathematical
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    88
  convention but not with the hardware of most computers}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    89
*}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    90
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    91
lemma "(#-10::int) div #3 = #-4"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    92
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    93
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    94
lemma "(#-10::int) mod #3 = #2"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    95
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    96
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    97
text {* A negative dividend \emph{and} divisor *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    98
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
    99
lemma "(#-10::int) div #-3 = #3"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   100
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   101
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   102
lemma "(#-10::int) mod #-3 = #-1"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   103
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   104
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   105
text {* A few bigger examples *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   106
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   107
lemma "(#8452::int) mod #3 = #1"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   108
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   109
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   110
lemma "(#59485::int) div #434 = #137"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   111
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   112
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   113
lemma "(#1000006::int) mod #10 = #6"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   114
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   115
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   116
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   117
text {* \medskip Division by shifting *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   118
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   119
lemma "#10000000 div #2 = (#5000000::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   120
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   121
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   122
lemma "#10000001 mod #2 = (#1::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   123
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   124
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   125
lemma "#10000055 div #32 = (#312501::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   126
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   127
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   128
lemma "#10000055 mod #32 = (#23::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   129
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   130
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   131
lemma "#100094 div #144 = (#695::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   132
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   133
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   134
lemma "#100094 mod #144 = (#14::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   135
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   136
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   137
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   138
subsection {* The Natural Numbers *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   139
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   140
text {* Successor *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   141
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   142
lemma "Suc #99999 = #100000"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   143
  by (simp add: Suc_nat_number_of)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   144
    -- {* not a default rewrite since sometimes we want to have @{text "Suc #nnn"} *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   145
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   146
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   147
text {* \medskip Addition *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   148
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   149
lemma "(#13::nat) + #19 = #32"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   150
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   151
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   152
lemma "(#1234::nat) + #5678 = #6912"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   153
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   154
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   155
lemma "(#973646::nat) + #6475 = #980121"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   156
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   157
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   158
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   159
text {* \medskip Subtraction *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   160
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   161
lemma "(#32::nat) - #14 = #18"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   162
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   163
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   164
lemma "(#14::nat) - #15 = #0"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   165
  by simp
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
   166
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   167
lemma "(#14::nat) - #1576644 = #0"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   168
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   169
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   170
lemma "(#48273776::nat) - #3873737 = #44400039"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   171
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   172
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   173
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   174
text {* \medskip Multiplication *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   175
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   176
lemma "(#12::nat) * #11 = #132"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   177
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   178
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   179
lemma "(#647::nat) * #3643 = #2357021"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   180
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   181
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   182
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   183
text {* \medskip Quotient and Remainder *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   184
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   185
lemma "(#10::nat) div #3 = #3"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   186
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   187
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   188
lemma "(#10::nat) mod #3 = #1"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   189
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   190
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   191
lemma "(#10000::nat) div #9 = #1111"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   192
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   193
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   194
lemma "(#10000::nat) mod #9 = #1"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   195
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   196
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   197
lemma "(#10000::nat) div #16 = #625"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   198
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   199
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   200
lemma "(#10000::nat) mod #16 = #0"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   201
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   202
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
   203
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   204
text {* \medskip Testing the cancellation of complementary terms *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   205
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   206
lemma "y + (x + -x) = (#0::int) + y"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   207
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   208
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   209
lemma "y + (-x + (- y + x)) = (#0::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   210
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   211
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   212
lemma "-x + (y + (- y + x)) = (#0::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   213
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   214
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   215
lemma "x + (x + (- x + (- x + (- y + - z)))) = (#0::int) - y - z"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   216
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   217
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   218
lemma "x + x - x - x - y - z = (#0::int) - y - z"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   219
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   220
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   221
lemma "x + y + z - (x + z) = y - (#0::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   222
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   223
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   224
lemma "x + (y + (y + (y + (-x + -x)))) = (#0::int) + y - x + y + y"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   225
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   226
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   227
lemma "x + (y + (y + (y + (-y + -x)))) = y + (#0::int) + y"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   228
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   229
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   230
lemma "x + y - x + z - x - y - z + x < (#1::int)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   231
  by simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   232
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   233
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   234
subsection {* Normal form of bit strings *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   235
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   236
text {*
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   237
  Definition of normal form for proving that binary arithmetic on
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   238
  normalized operands yields normalized results.  Normal means no
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   239
  leading 0s on positive numbers and no leading 1s on negatives.
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   240
*}
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
   241
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   242
consts normal :: "bin set"
11637
647e6c84323c inductive: no collective atts;
wenzelm
parents: 11024
diff changeset
   243
inductive normal
647e6c84323c inductive: no collective atts;
wenzelm
parents: 11024
diff changeset
   244
  intros
647e6c84323c inductive: no collective atts;
wenzelm
parents: 11024
diff changeset
   245
    Pls [simp]: "Pls: normal"
647e6c84323c inductive: no collective atts;
wenzelm
parents: 11024
diff changeset
   246
    Min [simp]: "Min: normal"
647e6c84323c inductive: no collective atts;
wenzelm
parents: 11024
diff changeset
   247
    BIT_F [simp]: "w: normal ==> w \<noteq> Pls ==> w BIT False : normal"
647e6c84323c inductive: no collective atts;
wenzelm
parents: 11024
diff changeset
   248
    BIT_T [simp]: "w: normal ==> w \<noteq> Min ==> w BIT True : normal"
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   249
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   250
text {*
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   251
  \medskip Binary arithmetic on normalized operands yields normalized
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   252
  results.
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   253
*}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   254
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   255
lemma normal_BIT_I [simp]: "w BIT b \<in> normal ==> w BIT b BIT c \<in> normal"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   256
  apply (case_tac c)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   257
   apply auto
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   258
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   259
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   260
lemma normal_BIT_D: "w BIT b \<in> normal ==> w \<in> normal"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   261
  apply (erule normal.cases)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   262
     apply auto
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   263
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   264
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   265
lemma NCons_normal [simp]: "w \<in> normal ==> NCons w b \<in> normal"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   266
  apply (induct w)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   267
    apply (auto simp add: NCons_Pls NCons_Min)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   268
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   269
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   270
lemma NCons_True: "NCons w True \<noteq> Pls"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   271
  apply (induct w)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   272
    apply auto
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   273
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   274
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   275
lemma NCons_False: "NCons w False \<noteq> Min"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   276
  apply (induct w)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   277
    apply auto
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   278
  done
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
   279
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   280
lemma bin_succ_normal [simp]: "w \<in> normal ==> bin_succ w \<in> normal"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   281
  apply (erule normal.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   282
     apply (case_tac [4] w)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   283
  apply (auto simp add: NCons_True bin_succ_BIT)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   284
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   285
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   286
lemma bin_pred_normal [simp]: "w \<in> normal ==> bin_pred w \<in> normal"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   287
  apply (erule normal.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   288
     apply (case_tac [3] w)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   289
  apply (auto simp add: NCons_False bin_pred_BIT)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   290
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   291
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   292
lemma bin_add_normal [rule_format]:
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   293
  "w \<in> normal --> (\<forall>z. z \<in> normal --> bin_add w z \<in> normal)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   294
  apply (induct w)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   295
    apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   296
   apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   297
  apply (rule impI)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   298
  apply (rule allI)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   299
  apply (induct_tac z)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   300
    apply (simp_all add: bin_add_BIT)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   301
  apply (safe dest!: normal_BIT_D)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   302
    apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   303
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   304
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   305
lemma normal_Pls_eq_0: "w \<in> normal ==> (w = Pls) = (number_of w = (#0::int))"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   306
  apply (erule normal.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   307
     apply auto
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   308
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   309
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   310
lemma bin_minus_normal: "w \<in> normal ==> bin_minus w \<in> normal"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   311
  apply (erule normal.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   312
     apply (simp_all add: bin_minus_BIT)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   313
  apply (rule normal.intros)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   314
  apply assumption
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   315
  apply (simp add: normal_Pls_eq_0)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   316
  apply (simp only: number_of_minus iszero_def zminus_equation [of _ "int 0"])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   317
  apply (rule not_sym)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   318
  apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   319
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   320
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   321
lemma bin_mult_normal [rule_format]:
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   322
    "w \<in> normal ==> z \<in> normal --> bin_mult w z \<in> normal"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   323
  apply (erule normal.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   324
     apply (simp_all add: bin_minus_normal bin_mult_BIT)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   325
  apply (safe dest!: normal_BIT_D)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   326
  apply (simp add: bin_add_normal)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 9297
diff changeset
   327
  done
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
   328
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5199
diff changeset
   329
end