src/HOL/Int.thy
author haftmann
Tue, 28 Apr 2009 15:50:29 +0200
changeset 31015 555f4033cd97
parent 31010 aabad7789183
child 31021 53642251a04f
permissions -rw-r--r--
reorganization of power lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     1
(*  Title:      Int.thy
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     3
                Tobias Nipkow, Florian Haftmann, TU Muenchen
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     4
    Copyright   1994  University of Cambridge
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     5
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     6
*)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     7
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     8
header {* The Integers as Equivalence Classes over Pairs of Natural Numbers *} 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     9
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    10
theory Int
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26732
diff changeset
    11
imports Equiv_Relations Nat Wellfounded
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    12
uses
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    13
  ("Tools/numeral.ML")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    14
  ("Tools/numeral_syntax.ML")
30796
126701134811 no longer delay loading of assoc_fold.ML
huffman
parents: 30652
diff changeset
    15
  "~~/src/Provers/Arith/assoc_fold.ML"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    16
  "~~/src/Provers/Arith/cancel_numerals.ML"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    17
  "~~/src/Provers/Arith/combine_numerals.ML"
28952
15a4b2cf8c34 made repository layout more coherent with logical distribution structure; stripped some $Id$s
haftmann
parents: 28724
diff changeset
    18
  ("Tools/int_arith.ML")
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    19
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    20
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    21
subsection {* The equivalence relation underlying the integers *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    22
28661
a287d0e8aa9d slightly tuned
haftmann
parents: 28562
diff changeset
    23
definition intrel :: "((nat \<times> nat) \<times> (nat \<times> nat)) set" where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    24
  [code del]: "intrel = {((x, y), (u, v)) | x y u v. x + v = u +y }"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    25
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    26
typedef (Integ)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    27
  int = "UNIV//intrel"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    28
  by (auto simp add: quotient_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    29
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    30
instantiation int :: "{zero, one, plus, minus, uminus, times, ord, abs, sgn}"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    31
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    32
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    33
definition
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    34
  Zero_int_def [code del]: "0 = Abs_Integ (intrel `` {(0, 0)})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    35
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    36
definition
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    37
  One_int_def [code del]: "1 = Abs_Integ (intrel `` {(1, 0)})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    38
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    39
definition
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    40
  add_int_def [code del]: "z + w = Abs_Integ
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    41
    (\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u, v) \<in> Rep_Integ w.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    42
      intrel `` {(x + u, y + v)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    43
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    44
definition
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    45
  minus_int_def [code del]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    46
    "- z = Abs_Integ (\<Union>(x, y) \<in> Rep_Integ z. intrel `` {(y, x)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    47
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    48
definition
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    49
  diff_int_def [code del]:  "z - w = z + (-w \<Colon> int)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    50
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    51
definition
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    52
  mult_int_def [code del]: "z * w = Abs_Integ
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    53
    (\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u,v ) \<in> Rep_Integ w.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    54
      intrel `` {(x*u + y*v, x*v + y*u)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    55
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    56
definition
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    57
  le_int_def [code del]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    58
   "z \<le> w \<longleftrightarrow> (\<exists>x y u v. x+v \<le> u+y \<and> (x, y) \<in> Rep_Integ z \<and> (u, v) \<in> Rep_Integ w)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    59
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    60
definition
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
    61
  less_int_def [code del]: "(z\<Colon>int) < w \<longleftrightarrow> z \<le> w \<and> z \<noteq> w"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    62
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    63
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    64
  zabs_def: "\<bar>i\<Colon>int\<bar> = (if i < 0 then - i else i)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    65
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    66
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    67
  zsgn_def: "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    68
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    69
instance ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    70
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    71
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    72
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    73
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    74
subsection{*Construction of the Integers*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    75
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    76
lemma intrel_iff [simp]: "(((x,y),(u,v)) \<in> intrel) = (x+v = u+y)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    77
by (simp add: intrel_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    78
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    79
lemma equiv_intrel: "equiv UNIV intrel"
30198
922f944f03b2 name changes
nipkow
parents: 30079
diff changeset
    80
by (simp add: intrel_def equiv_def refl_on_def sym_def trans_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    81
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    82
text{*Reduces equality of equivalence classes to the @{term intrel} relation:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    83
  @{term "(intrel `` {x} = intrel `` {y}) = ((x,y) \<in> intrel)"} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    84
lemmas equiv_intrel_iff [simp] = eq_equiv_class_iff [OF equiv_intrel UNIV_I UNIV_I]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    85
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    86
text{*All equivalence classes belong to set of representatives*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    87
lemma [simp]: "intrel``{(x,y)} \<in> Integ"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    88
by (auto simp add: Integ_def intrel_def quotient_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    89
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    90
text{*Reduces equality on abstractions to equality on representatives:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    91
  @{prop "\<lbrakk>x \<in> Integ; y \<in> Integ\<rbrakk> \<Longrightarrow> (Abs_Integ x = Abs_Integ y) = (x=y)"} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    92
declare Abs_Integ_inject [simp,noatp]  Abs_Integ_inverse [simp,noatp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    93
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    94
text{*Case analysis on the representation of an integer as an equivalence
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    95
      class of pairs of naturals.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    96
lemma eq_Abs_Integ [case_names Abs_Integ, cases type: int]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    97
     "(!!x y. z = Abs_Integ(intrel``{(x,y)}) ==> P) ==> P"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    98
apply (rule Abs_Integ_cases [of z]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    99
apply (auto simp add: Integ_def quotient_def) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   100
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   101
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   102
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   103
subsection {* Arithmetic Operations *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   104
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   105
lemma minus: "- Abs_Integ(intrel``{(x,y)}) = Abs_Integ(intrel `` {(y,x)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   106
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   107
  have "(\<lambda>(x,y). intrel``{(y,x)}) respects intrel"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   108
    by (simp add: congruent_def) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   109
  thus ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   110
    by (simp add: minus_int_def UN_equiv_class [OF equiv_intrel])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   111
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   112
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   113
lemma add:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   114
     "Abs_Integ (intrel``{(x,y)}) + Abs_Integ (intrel``{(u,v)}) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   115
      Abs_Integ (intrel``{(x+u, y+v)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   116
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   117
  have "(\<lambda>z w. (\<lambda>(x,y). (\<lambda>(u,v). intrel `` {(x+u, y+v)}) w) z) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   118
        respects2 intrel"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   119
    by (simp add: congruent2_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   120
  thus ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   121
    by (simp add: add_int_def UN_UN_split_split_eq
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   122
                  UN_equiv_class2 [OF equiv_intrel equiv_intrel])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   123
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   124
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   125
text{*Congruence property for multiplication*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   126
lemma mult_congruent2:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   127
     "(%p1 p2. (%(x,y). (%(u,v). intrel``{(x*u + y*v, x*v + y*u)}) p2) p1)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   128
      respects2 intrel"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   129
apply (rule equiv_intrel [THEN congruent2_commuteI])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   130
 apply (force simp add: mult_ac, clarify) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   131
apply (simp add: congruent_def mult_ac)  
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   132
apply (rename_tac u v w x y z)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   133
apply (subgoal_tac "u*y + x*y = w*y + v*y  &  u*z + x*z = w*z + v*z")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   134
apply (simp add: mult_ac)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   135
apply (simp add: add_mult_distrib [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   136
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   137
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   138
lemma mult:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   139
     "Abs_Integ((intrel``{(x,y)})) * Abs_Integ((intrel``{(u,v)})) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   140
      Abs_Integ(intrel `` {(x*u + y*v, x*v + y*u)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   141
by (simp add: mult_int_def UN_UN_split_split_eq mult_congruent2
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   142
              UN_equiv_class2 [OF equiv_intrel equiv_intrel])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   143
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   144
text{*The integers form a @{text comm_ring_1}*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   145
instance int :: comm_ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   146
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   147
  fix i j k :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   148
  show "(i + j) + k = i + (j + k)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   149
    by (cases i, cases j, cases k) (simp add: add add_assoc)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   150
  show "i + j = j + i" 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   151
    by (cases i, cases j) (simp add: add_ac add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   152
  show "0 + i = i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   153
    by (cases i) (simp add: Zero_int_def add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   154
  show "- i + i = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   155
    by (cases i) (simp add: Zero_int_def minus add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   156
  show "i - j = i + - j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   157
    by (simp add: diff_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   158
  show "(i * j) * k = i * (j * k)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   159
    by (cases i, cases j, cases k) (simp add: mult algebra_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   160
  show "i * j = j * i"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   161
    by (cases i, cases j) (simp add: mult algebra_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   162
  show "1 * i = i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   163
    by (cases i) (simp add: One_int_def mult)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   164
  show "(i + j) * k = i * k + j * k"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   165
    by (cases i, cases j, cases k) (simp add: add mult algebra_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   166
  show "0 \<noteq> (1::int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   167
    by (simp add: Zero_int_def One_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   168
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   169
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   170
lemma int_def: "of_nat m = Abs_Integ (intrel `` {(m, 0)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   171
by (induct m, simp_all add: Zero_int_def One_int_def add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   172
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   173
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   174
subsection {* The @{text "\<le>"} Ordering *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   175
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   176
lemma le:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   177
  "(Abs_Integ(intrel``{(x,y)}) \<le> Abs_Integ(intrel``{(u,v)})) = (x+v \<le> u+y)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   178
by (force simp add: le_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   179
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   180
lemma less:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   181
  "(Abs_Integ(intrel``{(x,y)}) < Abs_Integ(intrel``{(u,v)})) = (x+v < u+y)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   182
by (simp add: less_int_def le order_less_le)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   183
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   184
instance int :: linorder
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   185
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   186
  fix i j k :: int
27682
25aceefd4786 added class preorder
haftmann
parents: 27395
diff changeset
   187
  show antisym: "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j"
25aceefd4786 added class preorder
haftmann
parents: 27395
diff changeset
   188
    by (cases i, cases j) (simp add: le)
25aceefd4786 added class preorder
haftmann
parents: 27395
diff changeset
   189
  show "(i < j) = (i \<le> j \<and> \<not> j \<le> i)"
25aceefd4786 added class preorder
haftmann
parents: 27395
diff changeset
   190
    by (auto simp add: less_int_def dest: antisym) 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   191
  show "i \<le> i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   192
    by (cases i) (simp add: le)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   193
  show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   194
    by (cases i, cases j, cases k) (simp add: le)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   195
  show "i \<le> j \<or> j \<le> i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   196
    by (cases i, cases j) (simp add: le linorder_linear)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   197
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   198
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   199
instantiation int :: distrib_lattice
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   200
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   201
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   202
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   203
  "(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   204
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   205
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   206
  "(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   207
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   208
instance
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   209
  by intro_classes
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   210
    (auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   211
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   212
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   213
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   214
instance int :: pordered_cancel_ab_semigroup_add
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   215
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   216
  fix i j k :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   217
  show "i \<le> j \<Longrightarrow> k + i \<le> k + j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   218
    by (cases i, cases j, cases k) (simp add: le add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   219
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   220
25961
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   221
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   222
text{*Strict Monotonicity of Multiplication*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   223
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   224
text{*strict, in 1st argument; proof is by induction on k>0*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   225
lemma zmult_zless_mono2_lemma:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   226
     "(i::int)<j ==> 0<k ==> of_nat k * i < of_nat k * j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   227
apply (induct "k", simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   228
apply (simp add: left_distrib)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   229
apply (case_tac "k=0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   230
apply (simp_all add: add_strict_mono)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   231
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   232
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   233
lemma zero_le_imp_eq_int: "(0::int) \<le> k ==> \<exists>n. k = of_nat n"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   234
apply (cases k)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   235
apply (auto simp add: le add int_def Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   236
apply (rule_tac x="x-y" in exI, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   237
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   238
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   239
lemma zero_less_imp_eq_int: "(0::int) < k ==> \<exists>n>0. k = of_nat n"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   240
apply (cases k)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   241
apply (simp add: less int_def Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   242
apply (rule_tac x="x-y" in exI, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   243
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   244
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   245
lemma zmult_zless_mono2: "[| i<j;  (0::int) < k |] ==> k*i < k*j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   246
apply (drule zero_less_imp_eq_int)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   247
apply (auto simp add: zmult_zless_mono2_lemma)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   248
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   249
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   250
text{*The integers form an ordered integral domain*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   251
instance int :: ordered_idom
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   252
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   253
  fix i j k :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   254
  show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   255
    by (rule zmult_zless_mono2)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   256
  show "\<bar>i\<bar> = (if i < 0 then -i else i)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   257
    by (simp only: zabs_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   258
  show "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   259
    by (simp only: zsgn_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   260
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   261
25961
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   262
instance int :: lordered_ring
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   263
proof  
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   264
  fix k :: int
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   265
  show "abs k = sup k (- k)"
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   266
    by (auto simp add: sup_int_def zabs_def max_def less_minus_self_iff [symmetric])
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   267
qed
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   268
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   269
lemma zless_imp_add1_zle: "w < z \<Longrightarrow> w + (1\<Colon>int) \<le> z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   270
apply (cases w, cases z) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   271
apply (simp add: less le add One_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   272
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   273
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   274
lemma zless_iff_Suc_zadd:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   275
  "(w \<Colon> int) < z \<longleftrightarrow> (\<exists>n. z = w + of_nat (Suc n))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   276
apply (cases z, cases w)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   277
apply (auto simp add: less add int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   278
apply (rename_tac a b c d) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   279
apply (rule_tac x="a+d - Suc(c+b)" in exI) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   280
apply arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   281
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   282
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   283
lemmas int_distrib =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   284
  left_distrib [of "z1::int" "z2" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   285
  right_distrib [of "w::int" "z1" "z2", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   286
  left_diff_distrib [of "z1::int" "z2" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   287
  right_diff_distrib [of "w::int" "z1" "z2", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   288
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   289
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   290
subsection {* Embedding of the Integers into any @{text ring_1}: @{text of_int}*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   291
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   292
context ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   293
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   294
31015
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   295
definition of_int :: "int \<Rightarrow> 'a" where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
   296
  [code del]: "of_int z = contents (\<Union>(i, j) \<in> Rep_Integ z. { of_nat i - of_nat j })"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   297
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   298
lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   299
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   300
  have "(\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) }) respects intrel"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   301
    by (simp add: congruent_def algebra_simps of_nat_add [symmetric]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   302
            del: of_nat_add) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   303
  thus ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   304
    by (simp add: of_int_def UN_equiv_class [OF equiv_intrel])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   305
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   306
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   307
lemma of_int_0 [simp]: "of_int 0 = 0"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   308
by (simp add: of_int Zero_int_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   309
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   310
lemma of_int_1 [simp]: "of_int 1 = 1"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   311
by (simp add: of_int One_int_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   312
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   313
lemma of_int_add [simp]: "of_int (w+z) = of_int w + of_int z"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   314
by (cases w, cases z, simp add: algebra_simps of_int add)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   315
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   316
lemma of_int_minus [simp]: "of_int (-z) = - (of_int z)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   317
by (cases z, simp add: algebra_simps of_int minus)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   318
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   319
lemma of_int_diff [simp]: "of_int (w - z) = of_int w - of_int z"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   320
by (simp add: OrderedGroup.diff_minus diff_minus)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   321
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   322
lemma of_int_mult [simp]: "of_int (w*z) = of_int w * of_int z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   323
apply (cases w, cases z)
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   324
apply (simp add: algebra_simps of_int mult of_nat_mult)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   325
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   326
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   327
text{*Collapse nested embeddings*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   328
lemma of_int_of_nat_eq [simp]: "of_int (of_nat n) = of_nat n"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   329
by (induct n) auto
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   330
31015
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   331
lemma of_int_power:
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   332
  "of_int (z ^ n) = of_int z ^ n"
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   333
  by (induct n) simp_all
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   334
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   335
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   336
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   337
context ordered_idom
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   338
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   339
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   340
lemma of_int_le_iff [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   341
  "of_int w \<le> of_int z \<longleftrightarrow> w \<le> z"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   342
by (cases w, cases z, simp add: of_int le minus algebra_simps of_nat_add [symmetric] del: of_nat_add)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   343
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   344
text{*Special cases where either operand is zero*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   345
lemmas of_int_0_le_iff [simp] = of_int_le_iff [of 0, simplified]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   346
lemmas of_int_le_0_iff [simp] = of_int_le_iff [of _ 0, simplified]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   347
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   348
lemma of_int_less_iff [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   349
  "of_int w < of_int z \<longleftrightarrow> w < z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   350
  by (simp add: not_le [symmetric] linorder_not_le [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   351
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   352
text{*Special cases where either operand is zero*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   353
lemmas of_int_0_less_iff [simp] = of_int_less_iff [of 0, simplified]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   354
lemmas of_int_less_0_iff [simp] = of_int_less_iff [of _ 0, simplified]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   355
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   356
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   357
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   358
text{*Class for unital rings with characteristic zero.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   359
 Includes non-ordered rings like the complex numbers.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   360
class ring_char_0 = ring_1 + semiring_char_0
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   361
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   362
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   363
lemma of_int_eq_iff [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   364
   "of_int w = of_int z \<longleftrightarrow> w = z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   365
apply (cases w, cases z, simp add: of_int)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   366
apply (simp only: diff_eq_eq diff_add_eq eq_diff_eq)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   367
apply (simp only: of_nat_add [symmetric] of_nat_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   368
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   369
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   370
text{*Special cases where either operand is zero*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   371
lemmas of_int_0_eq_iff [simp] = of_int_eq_iff [of 0, simplified]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   372
lemmas of_int_eq_0_iff [simp] = of_int_eq_iff [of _ 0, simplified]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   373
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   374
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   375
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   376
text{*Every @{text ordered_idom} has characteristic zero.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   377
subclass (in ordered_idom) ring_char_0 by intro_locales
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   378
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   379
lemma of_int_eq_id [simp]: "of_int = id"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   380
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   381
  fix z show "of_int z = id z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   382
    by (cases z) (simp add: of_int add minus int_def diff_minus)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   383
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   384
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   385
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   386
subsection {* Magnitude of an Integer, as a Natural Number: @{text nat} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   387
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   388
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   389
  nat :: "int \<Rightarrow> nat"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   390
where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
   391
  [code del]: "nat z = contents (\<Union>(x, y) \<in> Rep_Integ z. {x-y})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   392
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   393
lemma nat: "nat (Abs_Integ (intrel``{(x,y)})) = x-y"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   394
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   395
  have "(\<lambda>(x,y). {x-y}) respects intrel"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   396
    by (simp add: congruent_def) arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   397
  thus ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   398
    by (simp add: nat_def UN_equiv_class [OF equiv_intrel])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   399
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   400
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   401
lemma nat_int [simp]: "nat (of_nat n) = n"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   402
by (simp add: nat int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   403
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   404
lemma nat_zero [simp]: "nat 0 = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   405
by (simp add: Zero_int_def nat)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   406
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   407
lemma int_nat_eq [simp]: "of_nat (nat z) = (if 0 \<le> z then z else 0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   408
by (cases z, simp add: nat le int_def Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   409
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   410
corollary nat_0_le: "0 \<le> z ==> of_nat (nat z) = z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   411
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   412
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   413
lemma nat_le_0 [simp]: "z \<le> 0 ==> nat z = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   414
by (cases z, simp add: nat le Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   415
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   416
lemma nat_le_eq_zle: "0 < w | 0 \<le> z ==> (nat w \<le> nat z) = (w\<le>z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   417
apply (cases w, cases z) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   418
apply (simp add: nat le linorder_not_le [symmetric] Zero_int_def, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   419
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   420
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   421
text{*An alternative condition is @{term "0 \<le> w"} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   422
corollary nat_mono_iff: "0 < z ==> (nat w < nat z) = (w < z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   423
by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   424
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   425
corollary nat_less_eq_zless: "0 \<le> w ==> (nat w < nat z) = (w<z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   426
by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   427
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   428
lemma zless_nat_conj [simp]: "(nat w < nat z) = (0 < z & w < z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   429
apply (cases w, cases z) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   430
apply (simp add: nat le Zero_int_def linorder_not_le [symmetric], arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   431
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   432
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   433
lemma nonneg_eq_int:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   434
  fixes z :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   435
  assumes "0 \<le> z" and "\<And>m. z = of_nat m \<Longrightarrow> P"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   436
  shows P
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   437
  using assms by (blast dest: nat_0_le sym)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   438
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   439
lemma nat_eq_iff: "(nat w = m) = (if 0 \<le> w then w = of_nat m else m=0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   440
by (cases w, simp add: nat le int_def Zero_int_def, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   441
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   442
corollary nat_eq_iff2: "(m = nat w) = (if 0 \<le> w then w = of_nat m else m=0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   443
by (simp only: eq_commute [of m] nat_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   444
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   445
lemma nat_less_iff: "0 \<le> w ==> (nat w < m) = (w < of_nat m)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   446
apply (cases w)
29700
22faf21db3df added some simp rules
nipkow
parents: 29668
diff changeset
   447
apply (simp add: nat le int_def Zero_int_def linorder_not_le[symmetric], arith)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   448
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   449
29700
22faf21db3df added some simp rules
nipkow
parents: 29668
diff changeset
   450
lemma nat_0_iff[simp]: "nat(i::int) = 0 \<longleftrightarrow> i\<le>0"
22faf21db3df added some simp rules
nipkow
parents: 29668
diff changeset
   451
by(simp add: nat_eq_iff) arith
22faf21db3df added some simp rules
nipkow
parents: 29668
diff changeset
   452
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   453
lemma int_eq_iff: "(of_nat m = z) = (m = nat z & 0 \<le> z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   454
by (auto simp add: nat_eq_iff2)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   455
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   456
lemma zero_less_nat_eq [simp]: "(0 < nat z) = (0 < z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   457
by (insert zless_nat_conj [of 0], auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   458
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   459
lemma nat_add_distrib:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   460
     "[| (0::int) \<le> z;  0 \<le> z' |] ==> nat (z+z') = nat z + nat z'"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   461
by (cases z, cases z', simp add: nat add le Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   462
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   463
lemma nat_diff_distrib:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   464
     "[| (0::int) \<le> z';  z' \<le> z |] ==> nat (z-z') = nat z - nat z'"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   465
by (cases z, cases z', 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   466
    simp add: nat add minus diff_minus le Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   467
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   468
lemma nat_zminus_int [simp]: "nat (- (of_nat n)) = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   469
by (simp add: int_def minus nat Zero_int_def) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   470
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   471
lemma zless_nat_eq_int_zless: "(m < nat z) = (of_nat m < z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   472
by (cases z, simp add: nat less int_def, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   473
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   474
context ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   475
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   476
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   477
lemma of_nat_nat: "0 \<le> z \<Longrightarrow> of_nat (nat z) = of_int z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   478
  by (cases z rule: eq_Abs_Integ)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   479
   (simp add: nat le of_int Zero_int_def of_nat_diff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   480
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   481
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   482
29779
2786b348c376 declare "nat o abs" as default measure for int
krauss
parents: 29700
diff changeset
   483
text {* For termination proofs: *}
2786b348c376 declare "nat o abs" as default measure for int
krauss
parents: 29700
diff changeset
   484
lemma measure_function_int[measure_function]: "is_measure (nat o abs)" ..
2786b348c376 declare "nat o abs" as default measure for int
krauss
parents: 29700
diff changeset
   485
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   486
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   487
subsection{*Lemmas about the Function @{term of_nat} and Orderings*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   488
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   489
lemma negative_zless_0: "- (of_nat (Suc n)) < (0 \<Colon> int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   490
by (simp add: order_less_le del: of_nat_Suc)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   491
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   492
lemma negative_zless [iff]: "- (of_nat (Suc n)) < (of_nat m \<Colon> int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   493
by (rule negative_zless_0 [THEN order_less_le_trans], simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   494
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   495
lemma negative_zle_0: "- of_nat n \<le> (0 \<Colon> int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   496
by (simp add: minus_le_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   497
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   498
lemma negative_zle [iff]: "- of_nat n \<le> (of_nat m \<Colon> int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   499
by (rule order_trans [OF negative_zle_0 of_nat_0_le_iff])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   500
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   501
lemma not_zle_0_negative [simp]: "~ (0 \<le> - (of_nat (Suc n) \<Colon> int))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   502
by (subst le_minus_iff, simp del: of_nat_Suc)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   503
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   504
lemma int_zle_neg: "((of_nat n \<Colon> int) \<le> - of_nat m) = (n = 0 & m = 0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   505
by (simp add: int_def le minus Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   506
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   507
lemma not_int_zless_negative [simp]: "~ ((of_nat n \<Colon> int) < - of_nat m)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   508
by (simp add: linorder_not_less)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   509
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   510
lemma negative_eq_positive [simp]: "((- of_nat n \<Colon> int) = of_nat m) = (n = 0 & m = 0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   511
by (force simp add: order_eq_iff [of "- of_nat n"] int_zle_neg)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   512
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   513
lemma zle_iff_zadd: "(w\<Colon>int) \<le> z \<longleftrightarrow> (\<exists>n. z = w + of_nat n)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   514
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   515
  have "(w \<le> z) = (0 \<le> z - w)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   516
    by (simp only: le_diff_eq add_0_left)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   517
  also have "\<dots> = (\<exists>n. z - w = of_nat n)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   518
    by (auto elim: zero_le_imp_eq_int)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   519
  also have "\<dots> = (\<exists>n. z = w + of_nat n)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   520
    by (simp only: algebra_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   521
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   522
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   523
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   524
lemma zadd_int_left: "of_nat m + (of_nat n + z) = of_nat (m + n) + (z\<Colon>int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   525
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   526
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   527
lemma int_Suc0_eq_1: "of_nat (Suc 0) = (1\<Colon>int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   528
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   529
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   530
text{*This version is proved for all ordered rings, not just integers!
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   531
      It is proved here because attribute @{text arith_split} is not available
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   532
      in theory @{text Ring_and_Field}.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   533
      But is it really better than just rewriting with @{text abs_if}?*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   534
lemma abs_split [arith_split,noatp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   535
     "P(abs(a::'a::ordered_idom)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   536
by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   537
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   538
lemma negD: "(x \<Colon> int) < 0 \<Longrightarrow> \<exists>n. x = - (of_nat (Suc n))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   539
apply (cases x)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   540
apply (auto simp add: le minus Zero_int_def int_def order_less_le)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   541
apply (rule_tac x="y - Suc x" in exI, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   542
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   543
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   544
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   545
subsection {* Cases and induction *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   546
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   547
text{*Now we replace the case analysis rule by a more conventional one:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   548
whether an integer is negative or not.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   549
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   550
theorem int_cases [cases type: int, case_names nonneg neg]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   551
  "[|!! n. (z \<Colon> int) = of_nat n ==> P;  !! n. z =  - (of_nat (Suc n)) ==> P |] ==> P"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   552
apply (cases "z < 0", blast dest!: negD)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   553
apply (simp add: linorder_not_less del: of_nat_Suc)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   554
apply auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   555
apply (blast dest: nat_0_le [THEN sym])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   556
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   557
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   558
theorem int_induct [induct type: int, case_names nonneg neg]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   559
     "[|!! n. P (of_nat n \<Colon> int);  !!n. P (- (of_nat (Suc n))) |] ==> P z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   560
  by (cases z rule: int_cases) auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   561
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   562
text{*Contributed by Brian Huffman*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   563
theorem int_diff_cases:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   564
  obtains (diff) m n where "(z\<Colon>int) = of_nat m - of_nat n"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   565
apply (cases z rule: eq_Abs_Integ)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   566
apply (rule_tac m=x and n=y in diff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   567
apply (simp add: int_def diff_def minus add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   568
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   569
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   570
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   571
subsection {* Binary representation *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   572
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   573
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   574
  This formalization defines binary arithmetic in terms of the integers
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   575
  rather than using a datatype. This avoids multiple representations (leading
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   576
  zeroes, etc.)  See @{text "ZF/Tools/twos-compl.ML"}, function @{text
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   577
  int_of_binary}, for the numerical interpretation.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   578
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   579
  The representation expects that @{text "(m mod 2)"} is 0 or 1,
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   580
  even if m is negative;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   581
  For instance, @{text "-5 div 2 = -3"} and @{text "-5 mod 2 = 1"}; thus
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   582
  @{text "-5 = (-3)*2 + 1"}.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   583
  
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   584
  This two's complement binary representation derives from the paper 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   585
  "An Efficient Representation of Arithmetic for Term Rewriting" by
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   586
  Dave Cohen and Phil Watson, Rewriting Techniques and Applications,
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   587
  Springer LNCS 488 (240-251), 1991.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   588
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   589
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   590
subsubsection {* The constructors @{term Bit0}, @{term Bit1}, @{term Pls} and @{term Min} *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   591
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   592
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   593
  Pls :: int where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
   594
  [code del]: "Pls = 0"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   595
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   596
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   597
  Min :: int where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
   598
  [code del]: "Min = - 1"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   599
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   600
definition
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   601
  Bit0 :: "int \<Rightarrow> int" where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
   602
  [code del]: "Bit0 k = k + k"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   603
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   604
definition
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   605
  Bit1 :: "int \<Rightarrow> int" where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
   606
  [code del]: "Bit1 k = 1 + k + k"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   607
29608
564ea783ace8 no base sort in class import
haftmann
parents: 29046
diff changeset
   608
class number = -- {* for numeric types: nat, int, real, \dots *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   609
  fixes number_of :: "int \<Rightarrow> 'a"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   610
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   611
use "Tools/numeral.ML"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   612
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   613
syntax
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   614
  "_Numeral" :: "num_const \<Rightarrow> 'a"    ("_")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   615
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   616
use "Tools/numeral_syntax.ML"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   617
setup NumeralSyntax.setup
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   618
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   619
abbreviation
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   620
  "Numeral0 \<equiv> number_of Pls"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   621
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   622
abbreviation
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   623
  "Numeral1 \<equiv> number_of (Bit1 Pls)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   624
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   625
lemma Let_number_of [simp]: "Let (number_of v) f = f (number_of v)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   626
  -- {* Unfold all @{text let}s involving constants *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   627
  unfolding Let_def ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   628
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   629
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   630
  succ :: "int \<Rightarrow> int" where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
   631
  [code del]: "succ k = k + 1"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   632
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   633
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   634
  pred :: "int \<Rightarrow> int" where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
   635
  [code del]: "pred k = k - 1"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   636
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   637
lemmas
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   638
  max_number_of [simp] = max_def
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   639
    [of "number_of u" "number_of v", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   640
and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   641
  min_number_of [simp] = min_def 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   642
    [of "number_of u" "number_of v", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   643
  -- {* unfolding @{text minx} and @{text max} on numerals *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   644
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   645
lemmas numeral_simps = 
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   646
  succ_def pred_def Pls_def Min_def Bit0_def Bit1_def
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   647
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   648
text {* Removal of leading zeroes *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   649
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   650
lemma Bit0_Pls [simp, code post]:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   651
  "Bit0 Pls = Pls"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   652
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   653
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   654
lemma Bit1_Min [simp, code post]:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   655
  "Bit1 Min = Min"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   656
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   657
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
   658
lemmas normalize_bin_simps =
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   659
  Bit0_Pls Bit1_Min
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
   660
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   661
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   662
subsubsection {* Successor and predecessor functions *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   663
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   664
text {* Successor *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   665
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   666
lemma succ_Pls:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   667
  "succ Pls = Bit1 Pls"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   668
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   669
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   670
lemma succ_Min:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   671
  "succ Min = Pls"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   672
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   673
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   674
lemma succ_Bit0:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   675
  "succ (Bit0 k) = Bit1 k"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   676
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   677
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   678
lemma succ_Bit1:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   679
  "succ (Bit1 k) = Bit0 (succ k)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   680
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   681
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   682
lemmas succ_bin_simps [simp] =
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   683
  succ_Pls succ_Min succ_Bit0 succ_Bit1
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
   684
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   685
text {* Predecessor *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   686
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   687
lemma pred_Pls:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   688
  "pred Pls = Min"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   689
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   690
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   691
lemma pred_Min:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   692
  "pred Min = Bit0 Min"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   693
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   694
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   695
lemma pred_Bit0:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   696
  "pred (Bit0 k) = Bit1 (pred k)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   697
  unfolding numeral_simps by simp 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   698
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   699
lemma pred_Bit1:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   700
  "pred (Bit1 k) = Bit0 k"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   701
  unfolding numeral_simps by simp
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   702
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   703
lemmas pred_bin_simps [simp] =
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   704
  pred_Pls pred_Min pred_Bit0 pred_Bit1
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
   705
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   706
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   707
subsubsection {* Binary arithmetic *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   708
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   709
text {* Addition *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   710
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   711
lemma add_Pls:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   712
  "Pls + k = k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   713
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   714
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   715
lemma add_Min:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   716
  "Min + k = pred k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   717
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   718
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   719
lemma add_Bit0_Bit0:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   720
  "(Bit0 k) + (Bit0 l) = Bit0 (k + l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   721
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   722
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   723
lemma add_Bit0_Bit1:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   724
  "(Bit0 k) + (Bit1 l) = Bit1 (k + l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   725
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   726
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   727
lemma add_Bit1_Bit0:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   728
  "(Bit1 k) + (Bit0 l) = Bit1 (k + l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   729
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   730
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   731
lemma add_Bit1_Bit1:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   732
  "(Bit1 k) + (Bit1 l) = Bit0 (k + succ l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   733
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   734
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   735
lemma add_Pls_right:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   736
  "k + Pls = k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   737
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   738
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   739
lemma add_Min_right:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   740
  "k + Min = pred k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   741
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   742
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   743
lemmas add_bin_simps [simp] =
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   744
  add_Pls add_Min add_Pls_right add_Min_right
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   745
  add_Bit0_Bit0 add_Bit0_Bit1 add_Bit1_Bit0 add_Bit1_Bit1
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   746
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   747
text {* Negation *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   748
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   749
lemma minus_Pls:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   750
  "- Pls = Pls"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   751
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   752
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   753
lemma minus_Min:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   754
  "- Min = Bit1 Pls"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   755
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   756
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   757
lemma minus_Bit0:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   758
  "- (Bit0 k) = Bit0 (- k)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   759
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   760
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   761
lemma minus_Bit1:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   762
  "- (Bit1 k) = Bit1 (pred (- k))"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   763
  unfolding numeral_simps by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   764
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   765
lemmas minus_bin_simps [simp] =
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   766
  minus_Pls minus_Min minus_Bit0 minus_Bit1
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
   767
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   768
text {* Subtraction *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   769
29046
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   770
lemma diff_bin_simps [simp]:
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   771
  "k - Pls = k"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   772
  "k - Min = succ k"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   773
  "Pls - (Bit0 l) = Bit0 (Pls - l)"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   774
  "Pls - (Bit1 l) = Bit1 (Min - l)"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   775
  "Min - (Bit0 l) = Bit1 (Min - l)"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   776
  "Min - (Bit1 l) = Bit0 (Min - l)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   777
  "(Bit0 k) - (Bit0 l) = Bit0 (k - l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   778
  "(Bit0 k) - (Bit1 l) = Bit1 (pred k - l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   779
  "(Bit1 k) - (Bit0 l) = Bit1 (k - l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   780
  "(Bit1 k) - (Bit1 l) = Bit0 (k - l)"
29046
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   781
  unfolding numeral_simps by simp_all
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   782
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   783
text {* Multiplication *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   784
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   785
lemma mult_Pls:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   786
  "Pls * w = Pls"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   787
  unfolding numeral_simps by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   788
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   789
lemma mult_Min:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   790
  "Min * k = - k"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   791
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   792
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   793
lemma mult_Bit0:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   794
  "(Bit0 k) * l = Bit0 (k * l)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   795
  unfolding numeral_simps int_distrib by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   796
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   797
lemma mult_Bit1:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   798
  "(Bit1 k) * l = (Bit0 (k * l)) + l"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   799
  unfolding numeral_simps int_distrib by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   800
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   801
lemmas mult_bin_simps [simp] =
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   802
  mult_Pls mult_Min mult_Bit0 mult_Bit1
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
   803
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   804
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   805
subsubsection {* Binary comparisons *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   806
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   807
text {* Preliminaries *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   808
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   809
lemma even_less_0_iff:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   810
  "a + a < 0 \<longleftrightarrow> a < (0::'a::ordered_idom)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   811
proof -
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   812
  have "a + a < 0 \<longleftrightarrow> (1+1)*a < 0" by (simp add: left_distrib)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   813
  also have "(1+1)*a < 0 \<longleftrightarrow> a < 0"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   814
    by (simp add: mult_less_0_iff zero_less_two 
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   815
                  order_less_not_sym [OF zero_less_two])
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   816
  finally show ?thesis .
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   817
qed
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   818
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   819
lemma le_imp_0_less: 
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   820
  assumes le: "0 \<le> z"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   821
  shows "(0::int) < 1 + z"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   822
proof -
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   823
  have "0 \<le> z" by fact
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   824
  also have "... < z + 1" by (rule less_add_one) 
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   825
  also have "... = 1 + z" by (simp add: add_ac)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   826
  finally show "0 < 1 + z" .
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   827
qed
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   828
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   829
lemma odd_less_0_iff:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   830
  "(1 + z + z < 0) = (z < (0::int))"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   831
proof (cases z rule: int_cases)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   832
  case (nonneg n)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   833
  thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   834
                             le_imp_0_less [THEN order_less_imp_le])  
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   835
next
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   836
  case (neg n)
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30000
diff changeset
   837
  thus ?thesis by (simp del: of_nat_Suc of_nat_add of_nat_1
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30000
diff changeset
   838
    add: algebra_simps of_nat_1 [where 'a=int, symmetric] of_nat_add [symmetric])
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   839
qed
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   840
28985
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
   841
lemma bin_less_0_simps:
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   842
  "Pls < 0 \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   843
  "Min < 0 \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   844
  "Bit0 w < 0 \<longleftrightarrow> w < 0"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   845
  "Bit1 w < 0 \<longleftrightarrow> w < 0"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   846
  unfolding numeral_simps
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   847
  by (simp_all add: even_less_0_iff odd_less_0_iff)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   848
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   849
lemma less_bin_lemma: "k < l \<longleftrightarrow> k - l < (0::int)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   850
  by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   851
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   852
lemma le_iff_pred_less: "k \<le> l \<longleftrightarrow> pred k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   853
  unfolding numeral_simps
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   854
  proof
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   855
    have "k - 1 < k" by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   856
    also assume "k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   857
    finally show "k - 1 < l" .
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   858
  next
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   859
    assume "k - 1 < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   860
    hence "(k - 1) + 1 \<le> l" by (rule zless_imp_add1_zle)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   861
    thus "k \<le> l" by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   862
  qed
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   863
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   864
lemma succ_pred: "succ (pred x) = x"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   865
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   866
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   867
text {* Less-than *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   868
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   869
lemma less_bin_simps [simp]:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   870
  "Pls < Pls \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   871
  "Pls < Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   872
  "Pls < Bit0 k \<longleftrightarrow> Pls < k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   873
  "Pls < Bit1 k \<longleftrightarrow> Pls \<le> k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   874
  "Min < Pls \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   875
  "Min < Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   876
  "Min < Bit0 k \<longleftrightarrow> Min < k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   877
  "Min < Bit1 k \<longleftrightarrow> Min < k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   878
  "Bit0 k < Pls \<longleftrightarrow> k < Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   879
  "Bit0 k < Min \<longleftrightarrow> k \<le> Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   880
  "Bit1 k < Pls \<longleftrightarrow> k < Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   881
  "Bit1 k < Min \<longleftrightarrow> k < Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   882
  "Bit0 k < Bit0 l \<longleftrightarrow> k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   883
  "Bit0 k < Bit1 l \<longleftrightarrow> k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   884
  "Bit1 k < Bit0 l \<longleftrightarrow> k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   885
  "Bit1 k < Bit1 l \<longleftrightarrow> k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   886
  unfolding le_iff_pred_less
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   887
    less_bin_lemma [of Pls]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   888
    less_bin_lemma [of Min]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   889
    less_bin_lemma [of "k"]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   890
    less_bin_lemma [of "Bit0 k"]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   891
    less_bin_lemma [of "Bit1 k"]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   892
    less_bin_lemma [of "pred Pls"]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   893
    less_bin_lemma [of "pred k"]
28985
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
   894
  by (simp_all add: bin_less_0_simps succ_pred)
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   895
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   896
text {* Less-than-or-equal *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   897
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   898
lemma le_bin_simps [simp]:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   899
  "Pls \<le> Pls \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   900
  "Pls \<le> Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   901
  "Pls \<le> Bit0 k \<longleftrightarrow> Pls \<le> k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   902
  "Pls \<le> Bit1 k \<longleftrightarrow> Pls \<le> k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   903
  "Min \<le> Pls \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   904
  "Min \<le> Min \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   905
  "Min \<le> Bit0 k \<longleftrightarrow> Min < k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   906
  "Min \<le> Bit1 k \<longleftrightarrow> Min \<le> k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   907
  "Bit0 k \<le> Pls \<longleftrightarrow> k \<le> Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   908
  "Bit0 k \<le> Min \<longleftrightarrow> k \<le> Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   909
  "Bit1 k \<le> Pls \<longleftrightarrow> k < Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   910
  "Bit1 k \<le> Min \<longleftrightarrow> k \<le> Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   911
  "Bit0 k \<le> Bit0 l \<longleftrightarrow> k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   912
  "Bit0 k \<le> Bit1 l \<longleftrightarrow> k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   913
  "Bit1 k \<le> Bit0 l \<longleftrightarrow> k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   914
  "Bit1 k \<le> Bit1 l \<longleftrightarrow> k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   915
  unfolding not_less [symmetric]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   916
  by (simp_all add: not_le)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   917
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   918
text {* Equality *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   919
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   920
lemma eq_bin_simps [simp]:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   921
  "Pls = Pls \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   922
  "Pls = Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   923
  "Pls = Bit0 l \<longleftrightarrow> Pls = l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   924
  "Pls = Bit1 l \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   925
  "Min = Pls \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   926
  "Min = Min \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   927
  "Min = Bit0 l \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   928
  "Min = Bit1 l \<longleftrightarrow> Min = l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   929
  "Bit0 k = Pls \<longleftrightarrow> k = Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   930
  "Bit0 k = Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   931
  "Bit1 k = Pls \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   932
  "Bit1 k = Min \<longleftrightarrow> k = Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   933
  "Bit0 k = Bit0 l \<longleftrightarrow> k = l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   934
  "Bit0 k = Bit1 l \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   935
  "Bit1 k = Bit0 l \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   936
  "Bit1 k = Bit1 l \<longleftrightarrow> k = l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   937
  unfolding order_eq_iff [where 'a=int]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   938
  by (simp_all add: not_less)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   939
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   940
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   941
subsection {* Converting Numerals to Rings: @{term number_of} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   942
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   943
class number_ring = number + comm_ring_1 +
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   944
  assumes number_of_eq: "number_of k = of_int k"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   945
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   946
text {* self-embedding of the integers *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   947
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   948
instantiation int :: number_ring
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   949
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   950
28724
haftmann
parents: 28661
diff changeset
   951
definition int_number_of_def [code del]:
haftmann
parents: 28661
diff changeset
   952
  "number_of w = (of_int w \<Colon> int)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   953
28724
haftmann
parents: 28661
diff changeset
   954
instance proof
haftmann
parents: 28661
diff changeset
   955
qed (simp only: int_number_of_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   956
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   957
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   958
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   959
lemma number_of_is_id:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   960
  "number_of (k::int) = k"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   961
  unfolding int_number_of_def by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   962
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   963
lemma number_of_succ:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   964
  "number_of (succ k) = (1 + number_of k ::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   965
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   966
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   967
lemma number_of_pred:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   968
  "number_of (pred w) = (- 1 + number_of w ::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   969
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   970
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   971
lemma number_of_minus:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   972
  "number_of (uminus w) = (- (number_of w)::'a::number_ring)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   973
  unfolding number_of_eq by (rule of_int_minus)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   974
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   975
lemma number_of_add:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   976
  "number_of (v + w) = (number_of v + number_of w::'a::number_ring)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   977
  unfolding number_of_eq by (rule of_int_add)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   978
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   979
lemma number_of_diff:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   980
  "number_of (v - w) = (number_of v - number_of w::'a::number_ring)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   981
  unfolding number_of_eq by (rule of_int_diff)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   982
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   983
lemma number_of_mult:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   984
  "number_of (v * w) = (number_of v * number_of w::'a::number_ring)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   985
  unfolding number_of_eq by (rule of_int_mult)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   986
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   987
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   988
  The correctness of shifting.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   989
  But it doesn't seem to give a measurable speed-up.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   990
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   991
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   992
lemma double_number_of_Bit0:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   993
  "(1 + 1) * number_of w = (number_of (Bit0 w) ::'a::number_ring)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   994
  unfolding number_of_eq numeral_simps left_distrib by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   995
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   996
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   997
  Converting numerals 0 and 1 to their abstract versions.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   998
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   999
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1000
lemma numeral_0_eq_0 [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1001
  "Numeral0 = (0::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1002
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1003
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1004
lemma numeral_1_eq_1 [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1005
  "Numeral1 = (1::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1006
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1007
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1008
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1009
  Special-case simplification for small constants.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1010
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1011
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1012
text{*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1013
  Unary minus for the abstract constant 1. Cannot be inserted
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1014
  as a simprule until later: it is @{text number_of_Min} re-oriented!
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1015
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1016
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1017
lemma numeral_m1_eq_minus_1:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1018
  "(-1::'a::number_ring) = - 1"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1019
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1020
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1021
lemma mult_minus1 [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1022
  "-1 * z = -(z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1023
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1024
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1025
lemma mult_minus1_right [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1026
  "z * -1 = -(z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1027
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1028
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1029
(*Negation of a coefficient*)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1030
lemma minus_number_of_mult [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1031
   "- (number_of w) * z = number_of (uminus w) * (z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1032
   unfolding number_of_eq by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1033
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1034
text {* Subtraction *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1035
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1036
lemma diff_number_of_eq:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1037
  "number_of v - number_of w =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1038
    (number_of (v + uminus w)::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1039
  unfolding number_of_eq by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1040
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1041
lemma number_of_Pls:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1042
  "number_of Pls = (0::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1043
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1044
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1045
lemma number_of_Min:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1046
  "number_of Min = (- 1::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1047
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1048
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1049
lemma number_of_Bit0:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1050
  "number_of (Bit0 w) = (0::'a::number_ring) + (number_of w) + (number_of w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1051
  unfolding number_of_eq numeral_simps by simp
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1052
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1053
lemma number_of_Bit1:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1054
  "number_of (Bit1 w) = (1::'a::number_ring) + (number_of w) + (number_of w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1055
  unfolding number_of_eq numeral_simps by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1056
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1057
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1058
subsubsection {* Equality of Binary Numbers *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1059
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1060
text {* First version by Norbert Voelker *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1061
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1062
definition (*for simplifying equalities*)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1063
  iszero :: "'a\<Colon>semiring_1 \<Rightarrow> bool"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1064
where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1065
  "iszero z \<longleftrightarrow> z = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1066
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1067
lemma iszero_0: "iszero 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1068
by (simp add: iszero_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1069
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1070
lemma not_iszero_1: "~ iszero 1"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1071
by (simp add: iszero_def eq_commute)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1072
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1073
lemma eq_number_of_eq:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1074
  "((number_of x::'a::number_ring) = number_of y) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1075
   iszero (number_of (x + uminus y) :: 'a)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1076
unfolding iszero_def number_of_add number_of_minus
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1077
by (simp add: algebra_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1078
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1079
lemma iszero_number_of_Pls:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1080
  "iszero ((number_of Pls)::'a::number_ring)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1081
unfolding iszero_def numeral_0_eq_0 ..
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1082
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1083
lemma nonzero_number_of_Min:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1084
  "~ iszero ((number_of Min)::'a::number_ring)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1085
unfolding iszero_def numeral_m1_eq_minus_1 by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1086
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1087
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1088
subsubsection {* Comparisons, for Ordered Rings *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1089
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1090
lemmas double_eq_0_iff = double_zero
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1091
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1092
lemma odd_nonzero:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1093
  "1 + z + z \<noteq> (0::int)";
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1094
proof (cases z rule: int_cases)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1095
  case (nonneg n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1096
  have le: "0 \<le> z+z" by (simp add: nonneg add_increasing) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1097
  thus ?thesis using  le_imp_0_less [OF le]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1098
    by (auto simp add: add_assoc) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1099
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1100
  case (neg n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1101
  show ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1102
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1103
    assume eq: "1 + z + z = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1104
    have "(0::int) < 1 + (of_nat n + of_nat n)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1105
      by (simp add: le_imp_0_less add_increasing) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1106
    also have "... = - (1 + z + z)" 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1107
      by (simp add: neg add_assoc [symmetric]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1108
    also have "... = 0" by (simp add: eq) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1109
    finally have "0<0" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1110
    thus False by blast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1111
  qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1112
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1113
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1114
lemma iszero_number_of_Bit0:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1115
  "iszero (number_of (Bit0 w)::'a) = 
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1116
   iszero (number_of w::'a::{ring_char_0,number_ring})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1117
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1118
  have "(of_int w + of_int w = (0::'a)) \<Longrightarrow> (w = 0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1119
  proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1120
    assume eq: "of_int w + of_int w = (0::'a)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1121
    then have "of_int (w + w) = (of_int 0 :: 'a)" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1122
    then have "w + w = 0" by (simp only: of_int_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1123
    then show "w = 0" by (simp only: double_eq_0_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1124
  qed
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1125
  thus ?thesis
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1126
    by (auto simp add: iszero_def number_of_eq numeral_simps)
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1127
qed
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1128
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1129
lemma iszero_number_of_Bit1:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1130
  "~ iszero (number_of (Bit1 w)::'a::{ring_char_0,number_ring})"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1131
proof -
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1132
  have "1 + of_int w + of_int w \<noteq> (0::'a)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1133
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1134
    assume eq: "1 + of_int w + of_int w = (0::'a)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1135
    hence "of_int (1 + w + w) = (of_int 0 :: 'a)" by simp 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1136
    hence "1 + w + w = 0" by (simp only: of_int_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1137
    with odd_nonzero show False by blast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1138
  qed
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1139
  thus ?thesis
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1140
    by (auto simp add: iszero_def number_of_eq numeral_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1141
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1142
28985
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1143
lemmas iszero_simps =
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1144
  iszero_0 not_iszero_1
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1145
  iszero_number_of_Pls nonzero_number_of_Min
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1146
  iszero_number_of_Bit0 iszero_number_of_Bit1
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1147
(* iszero_number_of_Pls would never normally be used
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1148
   because its lhs simplifies to "iszero 0" *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1149
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1150
subsubsection {* The Less-Than Relation *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1151
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1152
lemma double_less_0_iff:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1153
  "(a + a < 0) = (a < (0::'a::ordered_idom))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1154
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1155
  have "(a + a < 0) = ((1+1)*a < 0)" by (simp add: left_distrib)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1156
  also have "... = (a < 0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1157
    by (simp add: mult_less_0_iff zero_less_two 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1158
                  order_less_not_sym [OF zero_less_two]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1159
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1160
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1161
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1162
lemma odd_less_0:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1163
  "(1 + z + z < 0) = (z < (0::int))";
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1164
proof (cases z rule: int_cases)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1165
  case (nonneg n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1166
  thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1167
                             le_imp_0_less [THEN order_less_imp_le])  
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1168
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1169
  case (neg n)
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30000
diff changeset
  1170
  thus ?thesis by (simp del: of_nat_Suc of_nat_add of_nat_1
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30000
diff changeset
  1171
    add: algebra_simps of_nat_1 [where 'a=int, symmetric] of_nat_add [symmetric])
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1172
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1173
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1174
text {* Less-Than or Equals *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1175
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1176
text {* Reduces @{term "a\<le>b"} to @{term "~ (b<a)"} for ALL numerals. *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1177
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1178
lemmas le_number_of_eq_not_less =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1179
  linorder_not_less [of "number_of w" "number_of v", symmetric, 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1180
  standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1181
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1182
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1183
text {* Absolute value (@{term abs}) *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1184
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1185
lemma abs_number_of:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1186
  "abs(number_of x::'a::{ordered_idom,number_ring}) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1187
   (if number_of x < (0::'a) then -number_of x else number_of x)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1188
  by (simp add: abs_if)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1189
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1190
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1191
text {* Re-orientation of the equation nnn=x *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1192
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1193
lemma number_of_reorient:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1194
  "(number_of w = x) = (x = number_of w)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1195
  by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1196
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1197
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1198
subsubsection {* Simplification of arithmetic operations on integer constants. *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1199
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1200
lemmas arith_extra_simps [standard, simp] =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1201
  number_of_add [symmetric]
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1202
  number_of_minus [symmetric]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1203
  numeral_m1_eq_minus_1 [symmetric]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1204
  number_of_mult [symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1205
  diff_number_of_eq abs_number_of 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1206
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1207
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1208
  For making a minimal simpset, one must include these default simprules.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1209
  Also include @{text simp_thms}.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1210
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1211
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1212
lemmas arith_simps = 
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
  1213
  normalize_bin_simps pred_bin_simps succ_bin_simps
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
  1214
  add_bin_simps minus_bin_simps mult_bin_simps
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1215
  abs_zero abs_one arith_extra_simps
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1216
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1217
text {* Simplification of relational operations *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1218
28962
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1219
lemma less_number_of [simp]:
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1220
  "(number_of x::'a::{ordered_idom,number_ring}) < number_of y \<longleftrightarrow> x < y"
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1221
  unfolding number_of_eq by (rule of_int_less_iff)
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1222
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1223
lemma le_number_of [simp]:
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1224
  "(number_of x::'a::{ordered_idom,number_ring}) \<le> number_of y \<longleftrightarrow> x \<le> y"
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1225
  unfolding number_of_eq by (rule of_int_le_iff)
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1226
28967
3bdb1eae352c enable eq_bin_simps for simplifying equalities on numerals
huffman
parents: 28962
diff changeset
  1227
lemma eq_number_of [simp]:
3bdb1eae352c enable eq_bin_simps for simplifying equalities on numerals
huffman
parents: 28962
diff changeset
  1228
  "(number_of x::'a::{ring_char_0,number_ring}) = number_of y \<longleftrightarrow> x = y"
3bdb1eae352c enable eq_bin_simps for simplifying equalities on numerals
huffman
parents: 28962
diff changeset
  1229
  unfolding number_of_eq by (rule of_int_eq_iff)
3bdb1eae352c enable eq_bin_simps for simplifying equalities on numerals
huffman
parents: 28962
diff changeset
  1230
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1231
lemmas rel_simps [simp] = 
28962
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1232
  less_number_of less_bin_simps
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1233
  le_number_of le_bin_simps
28988
13d6f120992b revert to using eq_number_of_eq for simplification (Groebner_Examples.thy was broken)
huffman
parents: 28985
diff changeset
  1234
  eq_number_of_eq eq_bin_simps
29039
8b9207f82a78 separate neg_simps from rel_simps
huffman
parents: 28988
diff changeset
  1235
  iszero_simps
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1236
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1237
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1238
subsubsection {* Simplification of arithmetic when nested to the right. *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1239
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1240
lemma add_number_of_left [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1241
  "number_of v + (number_of w + z) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1242
   (number_of(v + w) + z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1243
  by (simp add: add_assoc [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1244
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1245
lemma mult_number_of_left [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1246
  "number_of v * (number_of w * z) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1247
   (number_of(v * w) * z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1248
  by (simp add: mult_assoc [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1249
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1250
lemma add_number_of_diff1:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1251
  "number_of v + (number_of w - c) = 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1252
  number_of(v + w) - (c::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1253
  by (simp add: diff_minus add_number_of_left)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1254
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1255
lemma add_number_of_diff2 [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1256
  "number_of v + (c - number_of w) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1257
   number_of (v + uminus w) + (c::'a::number_ring)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1258
by (simp add: algebra_simps diff_number_of_eq [symmetric])
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1259
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1260
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1261
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1262
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1263
subsection {* The Set of Integers *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1264
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1265
context ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1266
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1267
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1268
definition Ints  :: "'a set" where
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  1269
  [code del]: "Ints = range of_int"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1270
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1271
notation (xsymbols)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1272
  Ints  ("\<int>")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1273
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1274
lemma Ints_0 [simp]: "0 \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1275
apply (simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1276
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1277
apply (rule of_int_0 [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1278
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1279
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1280
lemma Ints_1 [simp]: "1 \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1281
apply (simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1282
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1283
apply (rule of_int_1 [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1284
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1285
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1286
lemma Ints_add [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a + b \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1287
apply (auto simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1288
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1289
apply (rule of_int_add [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1290
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1291
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1292
lemma Ints_minus [simp]: "a \<in> \<int> \<Longrightarrow> -a \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1293
apply (auto simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1294
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1295
apply (rule of_int_minus [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1296
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1297
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1298
lemma Ints_mult [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a * b \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1299
apply (auto simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1300
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1301
apply (rule of_int_mult [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1302
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1303
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1304
lemma Ints_cases [cases set: Ints]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1305
  assumes "q \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1306
  obtains (of_int) z where "q = of_int z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1307
  unfolding Ints_def
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1308
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1309
  from `q \<in> \<int>` have "q \<in> range of_int" unfolding Ints_def .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1310
  then obtain z where "q = of_int z" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1311
  then show thesis ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1312
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1313
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1314
lemma Ints_induct [case_names of_int, induct set: Ints]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1315
  "q \<in> \<int> \<Longrightarrow> (\<And>z. P (of_int z)) \<Longrightarrow> P q"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1316
  by (rule Ints_cases) auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1317
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1318
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1319
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1320
lemma Ints_diff [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a-b \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1321
apply (auto simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1322
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1323
apply (rule of_int_diff [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1324
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1325
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1326
text {* The premise involving @{term Ints} prevents @{term "a = 1/2"}. *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1327
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1328
lemma Ints_double_eq_0_iff:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1329
  assumes in_Ints: "a \<in> Ints"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1330
  shows "(a + a = 0) = (a = (0::'a::ring_char_0))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1331
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1332
  from in_Ints have "a \<in> range of_int" unfolding Ints_def [symmetric] .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1333
  then obtain z where a: "a = of_int z" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1334
  show ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1335
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1336
    assume "a = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1337
    thus "a + a = 0" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1338
  next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1339
    assume eq: "a + a = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1340
    hence "of_int (z + z) = (of_int 0 :: 'a)" by (simp add: a)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1341
    hence "z + z = 0" by (simp only: of_int_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1342
    hence "z = 0" by (simp only: double_eq_0_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1343
    thus "a = 0" by (simp add: a)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1344
  qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1345
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1346
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1347
lemma Ints_odd_nonzero:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1348
  assumes in_Ints: "a \<in> Ints"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1349
  shows "1 + a + a \<noteq> (0::'a::ring_char_0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1350
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1351
  from in_Ints have "a \<in> range of_int" unfolding Ints_def [symmetric] .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1352
  then obtain z where a: "a = of_int z" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1353
  show ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1354
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1355
    assume eq: "1 + a + a = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1356
    hence "of_int (1 + z + z) = (of_int 0 :: 'a)" by (simp add: a)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1357
    hence "1 + z + z = 0" by (simp only: of_int_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1358
    with odd_nonzero show False by blast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1359
  qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1360
qed 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1361
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1362
lemma Ints_number_of:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1363
  "(number_of w :: 'a::number_ring) \<in> Ints"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1364
  unfolding number_of_eq Ints_def by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1365
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1366
lemma Ints_odd_less_0: 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1367
  assumes in_Ints: "a \<in> Ints"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1368
  shows "(1 + a + a < 0) = (a < (0::'a::ordered_idom))";
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1369
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1370
  from in_Ints have "a \<in> range of_int" unfolding Ints_def [symmetric] .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1371
  then obtain z where a: "a = of_int z" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1372
  hence "((1::'a) + a + a < 0) = (of_int (1 + z + z) < (of_int 0 :: 'a))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1373
    by (simp add: a)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1374
  also have "... = (z < 0)" by (simp only: of_int_less_iff odd_less_0)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1375
  also have "... = (a < 0)" by (simp add: a)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1376
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1377
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1378
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1379
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1380
subsection {* @{term setsum} and @{term setprod} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1381
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1382
lemma of_nat_setsum: "of_nat (setsum f A) = (\<Sum>x\<in>A. of_nat(f x))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1383
  apply (cases "finite A")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1384
  apply (erule finite_induct, auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1385
  done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1386
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1387
lemma of_int_setsum: "of_int (setsum f A) = (\<Sum>x\<in>A. of_int(f x))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1388
  apply (cases "finite A")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1389
  apply (erule finite_induct, auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1390
  done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1391
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1392
lemma of_nat_setprod: "of_nat (setprod f A) = (\<Prod>x\<in>A. of_nat(f x))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1393
  apply (cases "finite A")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1394
  apply (erule finite_induct, auto simp add: of_nat_mult)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1395
  done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1396
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1397
lemma of_int_setprod: "of_int (setprod f A) = (\<Prod>x\<in>A. of_int(f x))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1398
  apply (cases "finite A")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1399
  apply (erule finite_induct, auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1400
  done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1401
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1402
lemmas int_setsum = of_nat_setsum [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1403
lemmas int_setprod = of_nat_setprod [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1404
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1405
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1406
subsection{*Inequality Reasoning for the Arithmetic Simproc*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1407
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1408
lemma add_numeral_0: "Numeral0 + a = (a::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1409
by simp 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1410
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1411
lemma add_numeral_0_right: "a + Numeral0 = (a::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1412
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1413
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1414
lemma mult_numeral_1: "Numeral1 * a = (a::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1415
by simp 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1416
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1417
lemma mult_numeral_1_right: "a * Numeral1 = (a::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1418
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1419
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1420
lemma divide_numeral_1: "a / Numeral1 = (a::'a::{number_ring,field})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1421
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1422
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1423
lemma inverse_numeral_1:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1424
  "inverse Numeral1 = (Numeral1::'a::{number_ring,field})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1425
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1426
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1427
text{*Theorem lists for the cancellation simprocs. The use of binary numerals
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1428
for 0 and 1 reduces the number of special cases.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1429
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1430
lemmas add_0s = add_numeral_0 add_numeral_0_right
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1431
lemmas mult_1s = mult_numeral_1 mult_numeral_1_right 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1432
                 mult_minus1 mult_minus1_right
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1433
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1434
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1435
subsection{*Special Arithmetic Rules for Abstract 0 and 1*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1436
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1437
text{*Arithmetic computations are defined for binary literals, which leaves 0
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1438
and 1 as special cases. Addition already has rules for 0, but not 1.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1439
Multiplication and unary minus already have rules for both 0 and 1.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1440
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1441
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1442
lemma binop_eq: "[|f x y = g x y; x = x'; y = y'|] ==> f x' y' = g x' y'"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1443
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1444
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1445
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1446
lemmas add_number_of_eq = number_of_add [symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1447
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1448
text{*Allow 1 on either or both sides*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1449
lemma one_add_one_is_two: "1 + 1 = (2::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1450
by (simp del: numeral_1_eq_1 add: numeral_1_eq_1 [symmetric] add_number_of_eq)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1451
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1452
lemmas add_special =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1453
    one_add_one_is_two
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1454
    binop_eq [of "op +", OF add_number_of_eq numeral_1_eq_1 refl, standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1455
    binop_eq [of "op +", OF add_number_of_eq refl numeral_1_eq_1, standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1456
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1457
text{*Allow 1 on either or both sides (1-1 already simplifies to 0)*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1458
lemmas diff_special =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1459
    binop_eq [of "op -", OF diff_number_of_eq numeral_1_eq_1 refl, standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1460
    binop_eq [of "op -", OF diff_number_of_eq refl numeral_1_eq_1, standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1461
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1462
text{*Allow 0 or 1 on either side with a binary numeral on the other*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1463
lemmas eq_special =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1464
    binop_eq [of "op =", OF eq_number_of_eq numeral_0_eq_0 refl, standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1465
    binop_eq [of "op =", OF eq_number_of_eq numeral_1_eq_1 refl, standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1466
    binop_eq [of "op =", OF eq_number_of_eq refl numeral_0_eq_0, standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1467
    binop_eq [of "op =", OF eq_number_of_eq refl numeral_1_eq_1, standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1468
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1469
text{*Allow 0 or 1 on either side with a binary numeral on the other*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1470
lemmas less_special =
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1471
  binop_eq [of "op <", OF less_number_of numeral_0_eq_0 refl, standard]
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1472
  binop_eq [of "op <", OF less_number_of numeral_1_eq_1 refl, standard]
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1473
  binop_eq [of "op <", OF less_number_of refl numeral_0_eq_0, standard]
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1474
  binop_eq [of "op <", OF less_number_of refl numeral_1_eq_1, standard]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1475
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1476
text{*Allow 0 or 1 on either side with a binary numeral on the other*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1477
lemmas le_special =
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1478
    binop_eq [of "op \<le>", OF le_number_of numeral_0_eq_0 refl, standard]
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1479
    binop_eq [of "op \<le>", OF le_number_of numeral_1_eq_1 refl, standard]
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1480
    binop_eq [of "op \<le>", OF le_number_of refl numeral_0_eq_0, standard]
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1481
    binop_eq [of "op \<le>", OF le_number_of refl numeral_1_eq_1, standard]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1482
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1483
lemmas arith_special[simp] = 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1484
       add_special diff_special eq_special less_special le_special
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1485
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1486
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1487
lemma min_max_01: "min (0::int) 1 = 0 & min (1::int) 0 = 0 &
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1488
                   max (0::int) 1 = 1 & max (1::int) 0 = 1"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1489
by(simp add:min_def max_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1490
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1491
lemmas min_max_special[simp] =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1492
 min_max_01
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1493
 max_def[of "0::int" "number_of v", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1494
 min_def[of "0::int" "number_of v", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1495
 max_def[of "number_of u" "0::int", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1496
 min_def[of "number_of u" "0::int", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1497
 max_def[of "1::int" "number_of v", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1498
 min_def[of "1::int" "number_of v", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1499
 max_def[of "number_of u" "1::int", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1500
 min_def[of "number_of u" "1::int", standard, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1501
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1502
text {* Legacy theorems *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1503
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1504
lemmas zle_int = of_nat_le_iff [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1505
lemmas int_int_eq = of_nat_eq_iff [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1506
30802
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1507
subsection {* Setting up simplification procedures *}
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1508
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1509
lemmas int_arith_rules =
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1510
  neg_le_iff_le numeral_0_eq_0 numeral_1_eq_1
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1511
  minus_zero diff_minus left_minus right_minus
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1512
  mult_zero_left mult_zero_right mult_Bit1 mult_1_right
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1513
  mult_minus_left mult_minus_right
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1514
  minus_add_distrib minus_minus mult_assoc
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1515
  of_nat_0 of_nat_1 of_nat_Suc of_nat_add of_nat_mult
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1516
  of_int_0 of_int_1 of_int_add of_int_mult
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1517
28952
15a4b2cf8c34 made repository layout more coherent with logical distribution structure; stripped some $Id$s
haftmann
parents: 28724
diff changeset
  1518
use "Tools/int_arith.ML"
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 30273
diff changeset
  1519
declaration {* K Int_Arith.setup *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1520
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1521
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1522
subsection{*Lemmas About Small Numerals*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1523
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1524
lemma of_int_m1 [simp]: "of_int -1 = (-1 :: 'a :: number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1525
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1526
  have "(of_int -1 :: 'a) = of_int (- 1)" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1527
  also have "... = - of_int 1" by (simp only: of_int_minus)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1528
  also have "... = -1" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1529
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1530
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1531
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1532
lemma abs_minus_one [simp]: "abs (-1) = (1::'a::{ordered_idom,number_ring})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1533
by (simp add: abs_if)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1534
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1535
lemma abs_power_minus_one [simp]:
31001
7e6ffd8f51a9 cleaned up theory power further
haftmann
parents: 30960
diff changeset
  1536
  "abs(-1 ^ n) = (1::'a::{ordered_idom,number_ring})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1537
by (simp add: power_abs)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1538
30000
453077188eac declare of_int_number_of_eq [simp]
huffman
parents: 29955
diff changeset
  1539
lemma of_int_number_of_eq [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1540
     "of_int (number_of v) = (number_of v :: 'a :: number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1541
by (simp add: number_of_eq) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1542
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1543
text{*Lemmas for specialist use, NOT as default simprules*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1544
lemma mult_2: "2 * z = (z+z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1545
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1546
  have "2*z = (1 + 1)*z" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1547
  also have "... = z+z" by (simp add: left_distrib)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1548
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1549
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1550
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1551
lemma mult_2_right: "z * 2 = (z+z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1552
by (subst mult_commute, rule mult_2)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1553
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1554
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1555
subsection{*More Inequality Reasoning*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1556
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1557
lemma zless_add1_eq: "(w < z + (1::int)) = (w<z | w=z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1558
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1559
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1560
lemma add1_zle_eq: "(w + (1::int) \<le> z) = (w<z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1561
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1562
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1563
lemma zle_diff1_eq [simp]: "(w \<le> z - (1::int)) = (w<z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1564
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1565
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1566
lemma zle_add1_eq_le [simp]: "(w < z + (1::int)) = (w\<le>z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1567
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1568
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1569
lemma int_one_le_iff_zero_less: "((1::int) \<le> z) = (0 < z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1570
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1571
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1572
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1573
subsection{*The functions @{term nat} and @{term int}*}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1574
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1575
text{*Simplify the terms @{term "int 0"}, @{term "int(Suc 0)"} and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1576
  @{term "w + - z"}*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1577
declare Zero_int_def [symmetric, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1578
declare One_int_def [symmetric, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1579
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1580
lemmas diff_int_def_symmetric = diff_int_def [symmetric, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1581
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1582
lemma nat_0: "nat 0 = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1583
by (simp add: nat_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1584
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1585
lemma nat_1: "nat 1 = Suc 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1586
by (subst nat_eq_iff, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1587
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1588
lemma nat_2: "nat 2 = Suc (Suc 0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1589
by (subst nat_eq_iff, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1590
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1591
lemma one_less_nat_eq [simp]: "(Suc 0 < nat z) = (1 < z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1592
apply (insert zless_nat_conj [of 1 z])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1593
apply (auto simp add: nat_1)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1594
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1595
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1596
text{*This simplifies expressions of the form @{term "int n = z"} where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1597
      z is an integer literal.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1598
lemmas int_eq_iff_number_of [simp] = int_eq_iff [of _ "number_of v", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1599
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1600
lemma split_nat [arith_split]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1601
  "P(nat(i::int)) = ((\<forall>n. i = of_nat n \<longrightarrow> P n) & (i < 0 \<longrightarrow> P 0))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1602
  (is "?P = (?L & ?R)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1603
proof (cases "i < 0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1604
  case True thus ?thesis by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1605
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1606
  case False
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1607
  have "?P = ?L"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1608
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1609
    assume ?P thus ?L using False by clarsimp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1610
  next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1611
    assume ?L thus ?P using False by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1612
  qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1613
  with False show ?thesis by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1614
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1615
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1616
context ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1617
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1618
29955
61837a9bdd74 Added Nitpick tag to 'of_int_of_nat'.
blanchet
parents: 29779
diff changeset
  1619
lemma of_int_of_nat [nitpick_const_simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1620
  "of_int k = (if k < 0 then - of_nat (nat (- k)) else of_nat (nat k))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1621
proof (cases "k < 0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1622
  case True then have "0 \<le> - k" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1623
  then have "of_nat (nat (- k)) = of_int (- k)" by (rule of_nat_nat)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1624
  with True show ?thesis by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1625
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1626
  case False then show ?thesis by (simp add: not_less of_nat_nat)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1627
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1628
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1629
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1630
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1631
lemma nat_mult_distrib:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1632
  fixes z z' :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1633
  assumes "0 \<le> z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1634
  shows "nat (z * z') = nat z * nat z'"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1635
proof (cases "0 \<le> z'")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1636
  case False with assms have "z * z' \<le> 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1637
    by (simp add: not_le mult_le_0_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1638
  then have "nat (z * z') = 0" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1639
  moreover from False have "nat z' = 0" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1640
  ultimately show ?thesis by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1641
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1642
  case True with assms have ge_0: "z * z' \<ge> 0" by (simp add: zero_le_mult_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1643
  show ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1644
    by (rule injD [of "of_nat :: nat \<Rightarrow> int", OF inj_of_nat])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1645
      (simp only: of_nat_mult of_nat_nat [OF True]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1646
         of_nat_nat [OF assms] of_nat_nat [OF ge_0], simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1647
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1648
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1649
lemma nat_mult_distrib_neg: "z \<le> (0::int) ==> nat(z*z') = nat(-z) * nat(-z')"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1650
apply (rule trans)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1651
apply (rule_tac [2] nat_mult_distrib, auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1652
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1653
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1654
lemma nat_abs_mult_distrib: "nat (abs (w * z)) = nat (abs w) * nat (abs z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1655
apply (cases "z=0 | w=0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1656
apply (auto simp add: abs_if nat_mult_distrib [symmetric] 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1657
                      nat_mult_distrib_neg [symmetric] mult_less_0_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1658
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1659
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1660
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1661
subsection "Induction principles for int"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1662
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1663
text{*Well-founded segments of the integers*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1664
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1665
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1666
  int_ge_less_than  ::  "int => (int * int) set"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1667
where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1668
  "int_ge_less_than d = {(z',z). d \<le> z' & z' < z}"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1669
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1670
theorem wf_int_ge_less_than: "wf (int_ge_less_than d)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1671
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1672
  have "int_ge_less_than d \<subseteq> measure (%z. nat (z-d))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1673
    by (auto simp add: int_ge_less_than_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1674
  thus ?thesis 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1675
    by (rule wf_subset [OF wf_measure]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1676
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1677
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1678
text{*This variant looks odd, but is typical of the relations suggested
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1679
by RankFinder.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1680
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1681
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1682
  int_ge_less_than2 ::  "int => (int * int) set"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1683
where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1684
  "int_ge_less_than2 d = {(z',z). d \<le> z & z' < z}"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1685
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1686
theorem wf_int_ge_less_than2: "wf (int_ge_less_than2 d)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1687
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1688
  have "int_ge_less_than2 d \<subseteq> measure (%z. nat (1+z-d))" 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1689
    by (auto simp add: int_ge_less_than2_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1690
  thus ?thesis 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1691
    by (rule wf_subset [OF wf_measure]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1692
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1693
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1694
abbreviation
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1695
  int :: "nat \<Rightarrow> int"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1696
where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1697
  "int \<equiv> of_nat"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1698
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1699
(* `set:int': dummy construction *)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1700
theorem int_ge_induct [case_names base step, induct set: int]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1701
  fixes i :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1702
  assumes ge: "k \<le> i" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1703
    base: "P k" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1704
    step: "\<And>i. k \<le> i \<Longrightarrow> P i \<Longrightarrow> P (i + 1)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1705
  shows "P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1706
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1707
  { fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k \<le> i \<Longrightarrow> P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1708
    proof (induct n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1709
      case 0
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1710
      hence "i = k" by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1711
      thus "P i" using base by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1712
    next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1713
      case (Suc n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1714
      then have "n = nat((i - 1) - k)" by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1715
      moreover
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1716
      have ki1: "k \<le> i - 1" using Suc.prems by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1717
      ultimately
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1718
      have "P(i - 1)" by(rule Suc.hyps)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1719
      from step[OF ki1 this] show ?case by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1720
    qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1721
  }
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1722
  with ge show ?thesis by fast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1723
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1724
25928
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  1725
(* `set:int': dummy construction *)
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  1726
theorem int_gr_induct [case_names base step, induct set: int]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1727
  assumes gr: "k < (i::int)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1728
        base: "P(k+1)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1729
        step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1730
  shows "P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1731
apply(rule int_ge_induct[of "k + 1"])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1732
  using gr apply arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1733
 apply(rule base)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1734
apply (rule step, simp+)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1735
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1736
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1737
theorem int_le_induct[consumes 1,case_names base step]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1738
  assumes le: "i \<le> (k::int)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1739
        base: "P(k)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1740
        step: "\<And>i. \<lbrakk>i \<le> k; P i\<rbrakk> \<Longrightarrow> P(i - 1)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1741
  shows "P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1742
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1743
  { fix n have "\<And>i::int. n = nat(k-i) \<Longrightarrow> i \<le> k \<Longrightarrow> P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1744
    proof (induct n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1745
      case 0
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1746
      hence "i = k" by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1747
      thus "P i" using base by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1748
    next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1749
      case (Suc n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1750
      hence "n = nat(k - (i+1))" by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1751
      moreover
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1752
      have ki1: "i + 1 \<le> k" using Suc.prems by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1753
      ultimately
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1754
      have "P(i+1)" by(rule Suc.hyps)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1755
      from step[OF ki1 this] show ?case by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1756
    qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1757
  }
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1758
  with le show ?thesis by fast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1759
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1760
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1761
theorem int_less_induct [consumes 1,case_names base step]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1762
  assumes less: "(i::int) < k" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1763
        base: "P(k - 1)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1764
        step: "\<And>i. \<lbrakk>i < k; P i\<rbrakk> \<Longrightarrow> P(i - 1)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1765
  shows "P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1766
apply(rule int_le_induct[of _ "k - 1"])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1767
  using less apply arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1768
 apply(rule base)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1769
apply (rule step, simp+)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1770
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1771
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1772
subsection{*Intermediate value theorems*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1773
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1774
lemma int_val_lemma:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1775
     "(\<forall>i<n::nat. abs(f(i+1) - f i) \<le> 1) -->  
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1776
      f 0 \<le> k --> k \<le> f n --> (\<exists>i \<le> n. f i = (k::int))"
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30000
diff changeset
  1777
unfolding One_nat_def
27106
ff27dc6e7d05 removed some dubious code lemmas
haftmann
parents: 26975
diff changeset
  1778
apply (induct n, simp)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1779
apply (intro strip)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1780
apply (erule impE, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1781
apply (erule_tac x = n in allE, simp)
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30000
diff changeset
  1782
apply (case_tac "k = f (Suc n)")
27106
ff27dc6e7d05 removed some dubious code lemmas
haftmann
parents: 26975
diff changeset
  1783
apply force
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1784
apply (erule impE)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1785
 apply (simp add: abs_if split add: split_if_asm)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1786
apply (blast intro: le_SucI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1787
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1788
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1789
lemmas nat0_intermed_int_val = int_val_lemma [rule_format (no_asm)]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1790
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1791
lemma nat_intermed_int_val:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1792
     "[| \<forall>i. m \<le> i & i < n --> abs(f(i + 1::nat) - f i) \<le> 1; m < n;  
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1793
         f m \<le> k; k \<le> f n |] ==> ? i. m \<le> i & i \<le> n & f i = (k::int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1794
apply (cut_tac n = "n-m" and f = "%i. f (i+m) " and k = k 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1795
       in int_val_lemma)
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30000
diff changeset
  1796
unfolding One_nat_def
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1797
apply simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1798
apply (erule exE)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1799
apply (rule_tac x = "i+m" in exI, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1800
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1801
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1802
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1803
subsection{*Products and 1, by T. M. Rasmussen*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1804
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1805
lemma zabs_less_one_iff [simp]: "(\<bar>z\<bar> < 1) = (z = (0::int))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1806
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1807
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1808
lemma abs_zmult_eq_1: "(\<bar>m * n\<bar> = 1) ==> \<bar>m\<bar> = (1::int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1809
apply (cases "\<bar>n\<bar>=1") 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1810
apply (simp add: abs_mult) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1811
apply (rule ccontr) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1812
apply (auto simp add: linorder_neq_iff abs_mult) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1813
apply (subgoal_tac "2 \<le> \<bar>m\<bar> & 2 \<le> \<bar>n\<bar>")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1814
 prefer 2 apply arith 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1815
apply (subgoal_tac "2*2 \<le> \<bar>m\<bar> * \<bar>n\<bar>", simp) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1816
apply (rule mult_mono, auto) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1817
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1818
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1819
lemma pos_zmult_eq_1_iff_lemma: "(m * n = 1) ==> m = (1::int) | m = -1"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1820
by (insert abs_zmult_eq_1 [of m n], arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1821
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1822
lemma pos_zmult_eq_1_iff: "0 < (m::int) ==> (m * n = 1) = (m = 1 & n = 1)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1823
apply (auto dest: pos_zmult_eq_1_iff_lemma) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1824
apply (simp add: mult_commute [of m]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1825
apply (frule pos_zmult_eq_1_iff_lemma, auto) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1826
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1827
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1828
lemma zmult_eq_1_iff: "(m*n = (1::int)) = ((m = 1 & n = 1) | (m = -1 & n = -1))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1829
apply (rule iffI) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1830
 apply (frule pos_zmult_eq_1_iff_lemma)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1831
 apply (simp add: mult_commute [of m]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1832
 apply (frule pos_zmult_eq_1_iff_lemma, auto) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1833
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1834
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1835
(* Could be simplified but Presburger only becomes available too late *)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1836
lemma infinite_UNIV_int: "~finite(UNIV::int set)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1837
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1838
  assume "finite(UNIV::int set)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1839
  moreover have "~(EX i::int. 2*i = 1)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1840
    by (auto simp: pos_zmult_eq_1_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1841
  ultimately show False using finite_UNIV_inj_surj[of "%n::int. n+n"]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1842
    by (simp add:inj_on_def surj_def) (blast intro:sym)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1843
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1844
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1845
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1846
subsection {* Further theorems on numerals *}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1847
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1848
subsubsection{*Special Simplification for Constants*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1849
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1850
text{*These distributive laws move literals inside sums and differences.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1851
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1852
lemmas left_distrib_number_of [simp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1853
  left_distrib [of _ _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1854
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1855
lemmas right_distrib_number_of [simp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1856
  right_distrib [of "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1857
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1858
lemmas left_diff_distrib_number_of [simp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1859
  left_diff_distrib [of _ _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1860
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1861
lemmas right_diff_distrib_number_of [simp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1862
  right_diff_distrib [of "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1863
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1864
text{*These are actually for fields, like real: but where else to put them?*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1865
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1866
lemmas zero_less_divide_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1867
  zero_less_divide_iff [of "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1868
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1869
lemmas divide_less_0_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1870
  divide_less_0_iff [of "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1871
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1872
lemmas zero_le_divide_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1873
  zero_le_divide_iff [of "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1874
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1875
lemmas divide_le_0_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1876
  divide_le_0_iff [of "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1877
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1878
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1879
text {*Replaces @{text "inverse #nn"} by @{text "1/#nn"}.  It looks
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1880
  strange, but then other simprocs simplify the quotient.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1881
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1882
lemmas inverse_eq_divide_number_of [simp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1883
  inverse_eq_divide [of "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1884
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1885
text {*These laws simplify inequalities, moving unary minus from a term
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1886
into the literal.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1887
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1888
lemmas less_minus_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1889
  less_minus_iff [of "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1890
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1891
lemmas le_minus_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1892
  le_minus_iff [of "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1893
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1894
lemmas equation_minus_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1895
  equation_minus_iff [of "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1896
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1897
lemmas minus_less_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1898
  minus_less_iff [of _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1899
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1900
lemmas minus_le_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1901
  minus_le_iff [of _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1902
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1903
lemmas minus_equation_iff_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1904
  minus_equation_iff [of _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1905
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1906
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1907
text{*To Simplify Inequalities Where One Side is the Constant 1*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1908
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1909
lemma less_minus_iff_1 [simp,noatp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1910
  fixes b::"'b::{ordered_idom,number_ring}"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1911
  shows "(1 < - b) = (b < -1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1912
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1913
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1914
lemma le_minus_iff_1 [simp,noatp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1915
  fixes b::"'b::{ordered_idom,number_ring}"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1916
  shows "(1 \<le> - b) = (b \<le> -1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1917
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1918
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1919
lemma equation_minus_iff_1 [simp,noatp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1920
  fixes b::"'b::number_ring"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1921
  shows "(1 = - b) = (b = -1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1922
by (subst equation_minus_iff, auto)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1923
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1924
lemma minus_less_iff_1 [simp,noatp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1925
  fixes a::"'b::{ordered_idom,number_ring}"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1926
  shows "(- a < 1) = (-1 < a)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1927
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1928
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1929
lemma minus_le_iff_1 [simp,noatp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1930
  fixes a::"'b::{ordered_idom,number_ring}"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1931
  shows "(- a \<le> 1) = (-1 \<le> a)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1932
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1933
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1934
lemma minus_equation_iff_1 [simp,noatp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1935
  fixes a::"'b::number_ring"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1936
  shows "(- a = 1) = (a = -1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1937
by (subst minus_equation_iff, auto)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1938
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1939
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1940
text {*Cancellation of constant factors in comparisons (@{text "<"} and @{text "\<le>"}) *}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1941
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1942
lemmas mult_less_cancel_left_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1943
  mult_less_cancel_left [of "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1944
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1945
lemmas mult_less_cancel_right_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1946
  mult_less_cancel_right [of _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1947
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1948
lemmas mult_le_cancel_left_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1949
  mult_le_cancel_left [of "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1950
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1951
lemmas mult_le_cancel_right_number_of [simp, noatp] =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1952
  mult_le_cancel_right [of _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1953
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1954
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1955
text {*Multiplying out constant divisors in comparisons (@{text "<"}, @{text "\<le>"} and @{text "="}) *}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1956
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1957
lemmas le_divide_eq_number_of1 [simp] = le_divide_eq [of _ _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1958
lemmas divide_le_eq_number_of1 [simp] = divide_le_eq [of _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1959
lemmas less_divide_eq_number_of1 [simp] = less_divide_eq [of _ _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1960
lemmas divide_less_eq_number_of1 [simp] = divide_less_eq [of _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1961
lemmas eq_divide_eq_number_of1 [simp] = eq_divide_eq [of _ _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1962
lemmas divide_eq_eq_number_of1 [simp] = divide_eq_eq [of _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1963
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1964
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1965
subsubsection{*Optional Simplification Rules Involving Constants*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1966
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1967
text{*Simplify quotients that are compared with a literal constant.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1968
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1969
lemmas le_divide_eq_number_of = le_divide_eq [of "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1970
lemmas divide_le_eq_number_of = divide_le_eq [of _ _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1971
lemmas less_divide_eq_number_of = less_divide_eq [of "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1972
lemmas divide_less_eq_number_of = divide_less_eq [of _ _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1973
lemmas eq_divide_eq_number_of = eq_divide_eq [of "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1974
lemmas divide_eq_eq_number_of = divide_eq_eq [of _ _ "number_of w", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1975
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1976
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1977
text{*Not good as automatic simprules because they cause case splits.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1978
lemmas divide_const_simps =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1979
  le_divide_eq_number_of divide_le_eq_number_of less_divide_eq_number_of
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1980
  divide_less_eq_number_of eq_divide_eq_number_of divide_eq_eq_number_of
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1981
  le_divide_eq_1 divide_le_eq_1 less_divide_eq_1 divide_less_eq_1
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1982
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1983
text{*Division By @{text "-1"}*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1984
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1985
lemma divide_minus1 [simp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1986
     "x/-1 = -(x::'a::{field,division_by_zero,number_ring})"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1987
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1988
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1989
lemma minus1_divide [simp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1990
     "-1 / (x::'a::{field,division_by_zero,number_ring}) = - (1/x)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1991
by (simp add: divide_inverse inverse_minus_eq)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1992
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1993
lemma half_gt_zero_iff:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1994
     "(0 < r/2) = (0 < (r::'a::{ordered_field,division_by_zero,number_ring}))"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1995
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1996
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1997
lemmas half_gt_zero [simp] = half_gt_zero_iff [THEN iffD2, standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1998
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1999
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2000
subsection {* Configuration of the code generator *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2001
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2002
code_datatype Pls Min Bit0 Bit1 "number_of \<Colon> int \<Rightarrow> int"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2003
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2004
lemmas pred_succ_numeral_code [code] =
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2005
  pred_bin_simps succ_bin_simps
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2006
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2007
lemmas plus_numeral_code [code] =
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2008
  add_bin_simps
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2009
  arith_extra_simps(1) [where 'a = int]
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2010
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2011
lemmas minus_numeral_code [code] =
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2012
  minus_bin_simps
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2013
  arith_extra_simps(2) [where 'a = int]
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2014
  arith_extra_simps(5) [where 'a = int]
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2015
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2016
lemmas times_numeral_code [code] =
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2017
  mult_bin_simps
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2018
  arith_extra_simps(4) [where 'a = int]
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2019
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2020
instantiation int :: eq
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2021
begin
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2022
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2023
definition [code del]: "eq_class.eq k l \<longleftrightarrow> k - l = (0\<Colon>int)"
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2024
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2025
instance by default (simp add: eq_int_def)
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2026
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2027
end
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2028
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2029
lemma eq_number_of_int_code [code]:
26732
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2030
  "eq_class.eq (number_of k \<Colon> int) (number_of l) \<longleftrightarrow> eq_class.eq k l"
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2031
  unfolding eq_int_def number_of_is_id ..
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2032
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2033
lemma eq_int_code [code]:
26732
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2034
  "eq_class.eq Int.Pls Int.Pls \<longleftrightarrow> True"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2035
  "eq_class.eq Int.Pls Int.Min \<longleftrightarrow> False"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2036
  "eq_class.eq Int.Pls (Int.Bit0 k2) \<longleftrightarrow> eq_class.eq Int.Pls k2"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2037
  "eq_class.eq Int.Pls (Int.Bit1 k2) \<longleftrightarrow> False"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2038
  "eq_class.eq Int.Min Int.Pls \<longleftrightarrow> False"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2039
  "eq_class.eq Int.Min Int.Min \<longleftrightarrow> True"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2040
  "eq_class.eq Int.Min (Int.Bit0 k2) \<longleftrightarrow> False"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2041
  "eq_class.eq Int.Min (Int.Bit1 k2) \<longleftrightarrow> eq_class.eq Int.Min k2"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  2042
  "eq_class.eq (Int.Bit0 k1) Int.Pls \<longleftrightarrow> eq_class.eq k1 Int.Pls"
26732
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2043
  "eq_class.eq (Int.Bit1 k1) Int.Pls \<longleftrightarrow> False"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2044
  "eq_class.eq (Int.Bit0 k1) Int.Min \<longleftrightarrow> False"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  2045
  "eq_class.eq (Int.Bit1 k1) Int.Min \<longleftrightarrow> eq_class.eq k1 Int.Min"
26732
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2046
  "eq_class.eq (Int.Bit0 k1) (Int.Bit0 k2) \<longleftrightarrow> eq_class.eq k1 k2"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2047
  "eq_class.eq (Int.Bit0 k1) (Int.Bit1 k2) \<longleftrightarrow> False"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2048
  "eq_class.eq (Int.Bit1 k1) (Int.Bit0 k2) \<longleftrightarrow> False"
6ea9de67e576 constant HOL.eq now qualified
haftmann
parents: 26507
diff changeset
  2049
  "eq_class.eq (Int.Bit1 k1) (Int.Bit1 k2) \<longleftrightarrow> eq_class.eq k1 k2"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  2050
  unfolding eq_equals by simp_all
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2051
28351
abfc66969d1f non left-linear equations for nbe
haftmann
parents: 27682
diff changeset
  2052
lemma eq_int_refl [code nbe]:
abfc66969d1f non left-linear equations for nbe
haftmann
parents: 27682
diff changeset
  2053
  "eq_class.eq (k::int) k \<longleftrightarrow> True"
abfc66969d1f non left-linear equations for nbe
haftmann
parents: 27682
diff changeset
  2054
  by (rule HOL.eq_refl)
abfc66969d1f non left-linear equations for nbe
haftmann
parents: 27682
diff changeset
  2055
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2056
lemma less_eq_number_of_int_code [code]:
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2057
  "(number_of k \<Colon> int) \<le> number_of l \<longleftrightarrow> k \<le> l"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2058
  unfolding number_of_is_id ..
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2059
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2060
lemma less_eq_int_code [code]:
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2061
  "Int.Pls \<le> Int.Pls \<longleftrightarrow> True"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2062
  "Int.Pls \<le> Int.Min \<longleftrightarrow> False"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2063
  "Int.Pls \<le> Int.Bit0 k \<longleftrightarrow> Int.Pls \<le> k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2064
  "Int.Pls \<le> Int.Bit1 k \<longleftrightarrow> Int.Pls \<le> k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2065
  "Int.Min \<le> Int.Pls \<longleftrightarrow> True"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2066
  "Int.Min \<le> Int.Min \<longleftrightarrow> True"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2067
  "Int.Min \<le> Int.Bit0 k \<longleftrightarrow> Int.Min < k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2068
  "Int.Min \<le> Int.Bit1 k \<longleftrightarrow> Int.Min \<le> k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2069
  "Int.Bit0 k \<le> Int.Pls \<longleftrightarrow> k \<le> Int.Pls"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2070
  "Int.Bit1 k \<le> Int.Pls \<longleftrightarrow> k < Int.Pls"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2071
  "Int.Bit0 k \<le> Int.Min \<longleftrightarrow> k \<le> Int.Min"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2072
  "Int.Bit1 k \<le> Int.Min \<longleftrightarrow> k \<le> Int.Min"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2073
  "Int.Bit0 k1 \<le> Int.Bit0 k2 \<longleftrightarrow> k1 \<le> k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2074
  "Int.Bit0 k1 \<le> Int.Bit1 k2 \<longleftrightarrow> k1 \<le> k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2075
  "Int.Bit1 k1 \<le> Int.Bit0 k2 \<longleftrightarrow> k1 < k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2076
  "Int.Bit1 k1 \<le> Int.Bit1 k2 \<longleftrightarrow> k1 \<le> k2"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  2077
  by simp_all
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2078
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2079
lemma less_number_of_int_code [code]:
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2080
  "(number_of k \<Colon> int) < number_of l \<longleftrightarrow> k < l"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2081
  unfolding number_of_is_id ..
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2082
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2083
lemma less_int_code [code]:
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2084
  "Int.Pls < Int.Pls \<longleftrightarrow> False"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2085
  "Int.Pls < Int.Min \<longleftrightarrow> False"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2086
  "Int.Pls < Int.Bit0 k \<longleftrightarrow> Int.Pls < k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2087
  "Int.Pls < Int.Bit1 k \<longleftrightarrow> Int.Pls \<le> k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2088
  "Int.Min < Int.Pls \<longleftrightarrow> True"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2089
  "Int.Min < Int.Min \<longleftrightarrow> False"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2090
  "Int.Min < Int.Bit0 k \<longleftrightarrow> Int.Min < k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2091
  "Int.Min < Int.Bit1 k \<longleftrightarrow> Int.Min < k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2092
  "Int.Bit0 k < Int.Pls \<longleftrightarrow> k < Int.Pls"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2093
  "Int.Bit1 k < Int.Pls \<longleftrightarrow> k < Int.Pls"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2094
  "Int.Bit0 k < Int.Min \<longleftrightarrow> k \<le> Int.Min"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2095
  "Int.Bit1 k < Int.Min \<longleftrightarrow> k < Int.Min"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2096
  "Int.Bit0 k1 < Int.Bit0 k2 \<longleftrightarrow> k1 < k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2097
  "Int.Bit0 k1 < Int.Bit1 k2 \<longleftrightarrow> k1 \<le> k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2098
  "Int.Bit1 k1 < Int.Bit0 k2 \<longleftrightarrow> k1 < k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2099
  "Int.Bit1 k1 < Int.Bit1 k2 \<longleftrightarrow> k1 < k2"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  2100
  by simp_all
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2101
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2102
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2103
  nat_aux :: "int \<Rightarrow> nat \<Rightarrow> nat" where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2104
  "nat_aux i n = nat i + n"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2105
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2106
lemma [code]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2107
  "nat_aux i n = (if i \<le> 0 then n else nat_aux (i - 1) (Suc n))"  -- {* tail recursive *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2108
  by (auto simp add: nat_aux_def nat_eq_iff linorder_not_le order_less_imp_le
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2109
    dest: zless_imp_add1_zle)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2110
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2111
lemma [code]: "nat i = nat_aux i 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2112
  by (simp add: nat_aux_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2113
28514
da83a614c454 tuned of_nat code generation
haftmann
parents: 28351
diff changeset
  2114
hide (open) const nat_aux
25928
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  2115
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2116
lemma zero_is_num_zero [code, code inline, symmetric, code post]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2117
  "(0\<Colon>int) = Numeral0" 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2118
  by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2119
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2120
lemma one_is_num_one [code, code inline, symmetric, code post]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2121
  "(1\<Colon>int) = Numeral1" 
25961
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
  2122
  by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2123
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2124
code_modulename SML
25928
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  2125
  Int Integer
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2126
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2127
code_modulename OCaml
25928
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  2128
  Int Integer
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2129
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2130
code_modulename Haskell
25928
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  2131
  Int Integer
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2132
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2133
types_code
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2134
  "int" ("int")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2135
attach (term_of) {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2136
val term_of_int = HOLogic.mk_number HOLogic.intT;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2137
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2138
attach (test) {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2139
fun gen_int i =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2140
  let val j = one_of [~1, 1] * random_range 0 i
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2141
  in (j, fn () => term_of_int j) end;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2142
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2143
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2144
setup {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2145
let
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2146
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2147
fun strip_number_of (@{term "Int.number_of :: int => int"} $ t) = t
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2148
  | strip_number_of t = t;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2149
28537
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28514
diff changeset
  2150
fun numeral_codegen thy defs dep module b t gr =
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2151
  let val i = HOLogic.dest_numeral (strip_number_of t)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2152
  in
28537
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28514
diff changeset
  2153
    SOME (Codegen.str (string_of_int i),
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28514
diff changeset
  2154
      snd (Codegen.invoke_tycodegen thy defs dep module false HOLogic.intT gr))
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2155
  end handle TERM _ => NONE;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2156
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2157
in
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2158
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2159
Codegen.add_codegen "numeral_codegen" numeral_codegen
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2160
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2161
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2162
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2163
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2164
consts_code
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2165
  "number_of :: int \<Rightarrow> int"    ("(_)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2166
  "0 :: int"                   ("0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2167
  "1 :: int"                   ("1")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2168
  "uminus :: int => int"       ("~")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2169
  "op + :: int => int => int"  ("(_ +/ _)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2170
  "op * :: int => int => int"  ("(_ */ _)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2171
  "op \<le> :: int => int => bool" ("(_ <=/ _)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2172
  "op < :: int => int => bool" ("(_ </ _)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2173
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2174
quickcheck_params [default_type = int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2175
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  2176
hide (open) const Pls Min Bit0 Bit1 succ pred
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2177
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2178
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2179
subsection {* Legacy theorems *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2180
31001
7e6ffd8f51a9 cleaned up theory power further
haftmann
parents: 30960
diff changeset
  2181
instance int :: recpower ..
7e6ffd8f51a9 cleaned up theory power further
haftmann
parents: 30960
diff changeset
  2182
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2183
lemmas zminus_zminus = minus_minus [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2184
lemmas zminus_0 = minus_zero [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2185
lemmas zminus_zadd_distrib = minus_add_distrib [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2186
lemmas zadd_commute = add_commute [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2187
lemmas zadd_assoc = add_assoc [of "z1::int" "z2" "z3", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2188
lemmas zadd_left_commute = add_left_commute [of "x::int" "y" "z", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2189
lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2190
lemmas zmult_ac = OrderedGroup.mult_ac
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2191
lemmas zadd_0 = OrderedGroup.add_0_left [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2192
lemmas zadd_0_right = OrderedGroup.add_0_left [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2193
lemmas zadd_zminus_inverse2 = left_minus [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2194
lemmas zmult_zminus = mult_minus_left [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2195
lemmas zmult_commute = mult_commute [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2196
lemmas zmult_assoc = mult_assoc [of "z1::int" "z2" "z3", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2197
lemmas zadd_zmult_distrib = left_distrib [of "z1::int" "z2" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2198
lemmas zadd_zmult_distrib2 = right_distrib [of "w::int" "z1" "z2", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2199
lemmas zdiff_zmult_distrib = left_diff_distrib [of "z1::int" "z2" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2200
lemmas zdiff_zmult_distrib2 = right_diff_distrib [of "w::int" "z1" "z2", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2201
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2202
lemmas zmult_1 = mult_1_left [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2203
lemmas zmult_1_right = mult_1_right [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2204
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2205
lemmas zle_refl = order_refl [of "w::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2206
lemmas zle_trans = order_trans [where 'a=int and x="i" and y="j" and z="k", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2207
lemmas zle_anti_sym = order_antisym [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2208
lemmas zle_linear = linorder_linear [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2209
lemmas zless_linear = linorder_less_linear [where 'a = int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2210
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2211
lemmas zadd_left_mono = add_left_mono [of "i::int" "j" "k", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2212
lemmas zadd_strict_right_mono = add_strict_right_mono [of "i::int" "j" "k", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2213
lemmas zadd_zless_mono = add_less_le_mono [of "w'::int" "w" "z'" "z", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2214
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2215
lemmas int_0_less_1 = zero_less_one [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2216
lemmas int_0_neq_1 = zero_neq_one [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2217
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2218
lemmas inj_int = inj_of_nat [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2219
lemmas zadd_int = of_nat_add [where 'a=int, symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2220
lemmas int_mult = of_nat_mult [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2221
lemmas zmult_int = of_nat_mult [where 'a=int, symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2222
lemmas int_eq_0_conv = of_nat_eq_0_iff [where 'a=int and m="n", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2223
lemmas zless_int = of_nat_less_iff [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2224
lemmas int_less_0_conv = of_nat_less_0_iff [where 'a=int and m="k", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2225
lemmas zero_less_int_conv = of_nat_0_less_iff [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2226
lemmas zero_zle_int = of_nat_0_le_iff [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2227
lemmas int_le_0_conv = of_nat_le_0_iff [where 'a=int and m="n", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2228
lemmas int_0 = of_nat_0 [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2229
lemmas int_1 = of_nat_1 [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2230
lemmas int_Suc = of_nat_Suc [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2231
lemmas abs_int_eq = abs_of_nat [where 'a=int and n="m", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2232
lemmas of_int_int_eq = of_int_of_nat_eq [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2233
lemmas zdiff_int = of_nat_diff [where 'a=int, symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2234
lemmas zless_le = less_int_def
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2235
lemmas int_eq_of_nat = TrueI
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2236
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2237
lemma zpower_zadd_distrib:
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2238
  "x ^ (y + z) = ((x ^ y) * (x ^ z)::int)"
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2239
  by (rule power_add)
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2240
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2241
lemma zero_less_zpower_abs_iff:
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2242
  "(0 < abs x ^ n) \<longleftrightarrow> (x \<noteq> (0::int) | n = 0)"
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2243
  by (rule zero_less_power_abs_iff)
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2244
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2245
lemma zero_le_zpower_abs: "(0::int) \<le> abs x ^ n"
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2246
  by (rule zero_le_power_abs)
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2247
31015
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2248
lemma zpower_zpower:
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2249
  "(x ^ y) ^ z = (x ^ (y * z)::int)"
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2250
  by (rule power_mult [symmetric])
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2251
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2252
lemma int_power:
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2253
  "int (m ^ n) = int m ^ n"
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2254
  by (rule of_nat_power)
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2255
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2256
lemmas zpower_int = int_power [symmetric]
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2257
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2258
end