src/HOL/Int.thy
author wenzelm
Wed, 29 Jun 2011 20:39:41 +0200
changeset 43596 78211f66cf8d
parent 43595 7ae4a23b5be6
child 44695 075327b8e841
permissions -rw-r--r--
simplified/unified Simplifier.mk_solver;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 40819
diff changeset
     1
(*  Title:      HOL/Int.thy
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
41959
b460124855b8 tuned headers;
wenzelm
parents: 40819
diff changeset
     3
    Author:     Tobias Nipkow, Florian Haftmann, TU Muenchen
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
     4
*)
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
header {* The Integers as Equivalence Classes over Pairs of Natural Numbers *} 
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
theory Int
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26732
diff changeset
     9
imports Equiv_Relations Nat Wellfounded
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    10
uses
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    11
  ("Tools/numeral.ML")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    12
  ("Tools/numeral_syntax.ML")
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31065
diff changeset
    13
  ("Tools/int_arith.ML")
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    14
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    15
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    16
subsection {* The equivalence relation underlying the integers *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    17
28661
a287d0e8aa9d slightly tuned
haftmann
parents: 28562
diff changeset
    18
definition intrel :: "((nat \<times> nat) \<times> (nat \<times> nat)) set" where
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    19
  "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
    20
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    21
typedef (Integ)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    22
  int = "UNIV//intrel"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    23
  by (auto simp add: quotient_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    24
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    25
instantiation int :: "{zero, one, plus, minus, uminus, times, ord, abs, sgn}"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    26
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    27
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    28
definition
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    29
  Zero_int_def: "0 = Abs_Integ (intrel `` {(0, 0)})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    30
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    31
definition
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    32
  One_int_def: "1 = Abs_Integ (intrel `` {(1, 0)})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    33
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    34
definition
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    35
  add_int_def: "z + w = Abs_Integ
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    36
    (\<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
    37
      intrel `` {(x + u, y + v)})"
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
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    40
  minus_int_def:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    41
    "- 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
    42
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    43
definition
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    44
  diff_int_def:  "z - w = z + (-w \<Colon> int)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    45
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    46
definition
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    47
  mult_int_def: "z * w = Abs_Integ
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    48
    (\<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
    49
      intrel `` {(x*u + y*v, x*v + y*u)})"
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
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    52
  le_int_def:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    53
   "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
    54
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    55
definition
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
    56
  less_int_def: "(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
    57
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    58
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    59
  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
    60
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    61
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    62
  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
    63
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    64
instance ..
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
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    67
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
subsection{*Construction of the Integers*}
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
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
    72
by (simp add: intrel_def)
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
lemma equiv_intrel: "equiv UNIV intrel"
30198
922f944f03b2 name changes
nipkow
parents: 30079
diff changeset
    75
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
    76
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    77
text{*Reduces equality of equivalence classes to the @{term intrel} relation:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    78
  @{term "(intrel `` {x} = intrel `` {y}) = ((x,y) \<in> intrel)"} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    79
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
    80
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    81
text{*All equivalence classes belong to set of representatives*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    82
lemma [simp]: "intrel``{(x,y)} \<in> Integ"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    83
by (auto simp add: Integ_def intrel_def quotient_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    84
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    85
text{*Reduces equality on abstractions to equality on representatives:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    86
  @{prop "\<lbrakk>x \<in> Integ; y \<in> Integ\<rbrakk> \<Longrightarrow> (Abs_Integ x = Abs_Integ y) = (x=y)"} *}
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
    87
declare Abs_Integ_inject [simp,no_atp]  Abs_Integ_inverse [simp,no_atp]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    88
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    89
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
    90
      class of pairs of naturals.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    91
lemma eq_Abs_Integ [case_names Abs_Integ, cases type: int]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    92
     "(!!x y. z = Abs_Integ(intrel``{(x,y)}) ==> P) ==> P"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    93
apply (rule Abs_Integ_cases [of z]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    94
apply (auto simp add: Integ_def quotient_def) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    95
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    96
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    97
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    98
subsection {* Arithmetic Operations *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
    99
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   100
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
   101
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   102
  have "(\<lambda>(x,y). intrel``{(y,x)}) respects intrel"
40819
2ac5af6eb8a8 adapted proofs to slightly changed definitions of congruent(2)
haftmann
parents: 39910
diff changeset
   103
    by (auto simp add: congruent_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   104
  thus ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   105
    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
   106
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   107
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   108
lemma add:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   109
     "Abs_Integ (intrel``{(x,y)}) + Abs_Integ (intrel``{(u,v)}) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   110
      Abs_Integ (intrel``{(x+u, y+v)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   111
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   112
  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
   113
        respects2 intrel"
40819
2ac5af6eb8a8 adapted proofs to slightly changed definitions of congruent(2)
haftmann
parents: 39910
diff changeset
   114
    by (auto simp add: congruent2_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   115
  thus ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   116
    by (simp add: add_int_def UN_UN_split_split_eq
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   117
                  UN_equiv_class2 [OF equiv_intrel equiv_intrel])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   118
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   119
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   120
text{*Congruence property for multiplication*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   121
lemma mult_congruent2:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   122
     "(%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
   123
      respects2 intrel"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   124
apply (rule equiv_intrel [THEN congruent2_commuteI])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   125
 apply (force simp add: mult_ac, clarify) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   126
apply (simp add: congruent_def mult_ac)  
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   127
apply (rename_tac u v w x y z)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   128
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
   129
apply (simp add: mult_ac)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   130
apply (simp add: add_mult_distrib [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   131
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   132
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   133
lemma mult:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   134
     "Abs_Integ((intrel``{(x,y)})) * Abs_Integ((intrel``{(u,v)})) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   135
      Abs_Integ(intrel `` {(x*u + y*v, x*v + y*u)})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   136
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
   137
              UN_equiv_class2 [OF equiv_intrel equiv_intrel])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   138
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   139
text{*The integers form a @{text comm_ring_1}*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   140
instance int :: comm_ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   141
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   142
  fix i j k :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   143
  show "(i + j) + k = i + (j + k)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   144
    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
   145
  show "i + j = j + i" 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   146
    by (cases i, cases j) (simp add: add_ac add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   147
  show "0 + i = i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   148
    by (cases i) (simp add: Zero_int_def add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   149
  show "- i + i = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   150
    by (cases i) (simp add: Zero_int_def minus add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   151
  show "i - j = i + - j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   152
    by (simp add: diff_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   153
  show "(i * j) * k = i * (j * k)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   154
    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
   155
  show "i * j = j * i"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   156
    by (cases i, cases j) (simp add: mult algebra_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   157
  show "1 * i = i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   158
    by (cases i) (simp add: One_int_def mult)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   159
  show "(i + j) * k = i * k + j * k"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   160
    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
   161
  show "0 \<noteq> (1::int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   162
    by (simp add: Zero_int_def One_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   163
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   164
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   165
lemma int_def: "of_nat m = Abs_Integ (intrel `` {(m, 0)})"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   166
by (induct m) (simp_all add: Zero_int_def One_int_def add)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   167
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   168
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   169
subsection {* The @{text "\<le>"} Ordering *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   170
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   171
lemma le:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   172
  "(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
   173
by (force simp add: le_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   174
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   175
lemma less:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   176
  "(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
   177
by (simp add: less_int_def le order_less_le)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   178
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   179
instance int :: linorder
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   180
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   181
  fix i j k :: int
27682
25aceefd4786 added class preorder
haftmann
parents: 27395
diff changeset
   182
  show antisym: "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j"
25aceefd4786 added class preorder
haftmann
parents: 27395
diff changeset
   183
    by (cases i, cases j) (simp add: le)
25aceefd4786 added class preorder
haftmann
parents: 27395
diff changeset
   184
  show "(i < j) = (i \<le> j \<and> \<not> j \<le> i)"
25aceefd4786 added class preorder
haftmann
parents: 27395
diff changeset
   185
    by (auto simp add: less_int_def dest: antisym) 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   186
  show "i \<le> i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   187
    by (cases i) (simp add: le)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   188
  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
   189
    by (cases i, cases j, cases k) (simp add: le)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   190
  show "i \<le> j \<or> j \<le> i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   191
    by (cases i, cases j) (simp add: le linorder_linear)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   192
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   193
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   194
instantiation int :: distrib_lattice
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   195
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   196
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   197
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   198
  "(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   199
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   200
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   201
  "(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   202
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   203
instance
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   204
  by intro_classes
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   205
    (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
   206
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   207
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   208
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
   209
instance int :: ordered_cancel_ab_semigroup_add
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   210
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   211
  fix i j k :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   212
  show "i \<le> j \<Longrightarrow> k + i \<le> k + j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   213
    by (cases i, cases j, cases k) (simp add: le add)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   214
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   215
25961
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
   216
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   217
text{*Strict Monotonicity of Multiplication*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   218
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   219
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
   220
lemma zmult_zless_mono2_lemma:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   221
     "(i::int)<j ==> 0<k ==> of_nat k * i < of_nat k * j"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   222
apply (induct k)
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   223
apply simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   224
apply (simp add: left_distrib)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   225
apply (case_tac "k=0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   226
apply (simp_all add: add_strict_mono)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   227
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   228
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   229
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
   230
apply (cases k)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   231
apply (auto simp add: le add int_def Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   232
apply (rule_tac x="x-y" in exI, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   233
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   234
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   235
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
   236
apply (cases k)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   237
apply (simp add: less int_def Zero_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   238
apply (rule_tac x="x-y" in exI, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   239
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   240
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   241
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
   242
apply (drule zero_less_imp_eq_int)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   243
apply (auto simp add: zmult_zless_mono2_lemma)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   244
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   245
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   246
text{*The integers form an ordered integral domain*}
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
   247
instance int :: linordered_idom
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   248
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   249
  fix i j k :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   250
  show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   251
    by (rule zmult_zless_mono2)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   252
  show "\<bar>i\<bar> = (if i < 0 then -i else i)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   253
    by (simp only: zabs_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   254
  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
   255
    by (simp only: zsgn_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   256
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   257
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   258
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
   259
apply (cases w, cases z) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   260
apply (simp add: less le add One_int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   261
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   262
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   263
lemma zless_iff_Suc_zadd:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   264
  "(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
   265
apply (cases z, cases w)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   266
apply (auto simp add: less add int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   267
apply (rename_tac a b c d) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   268
apply (rule_tac x="a+d - Suc(c+b)" in exI) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   269
apply arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   270
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   271
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   272
lemmas int_distrib =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   273
  left_distrib [of "z1::int" "z2" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   274
  right_distrib [of "w::int" "z1" "z2", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   275
  left_diff_distrib [of "z1::int" "z2" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   276
  right_diff_distrib [of "w::int" "z1" "z2", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   277
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   278
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   279
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
   280
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   281
context ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   282
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   283
31015
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   284
definition of_int :: "int \<Rightarrow> 'a" where
39910
10097e0a9dbd constant `contents` renamed to `the_elem`
haftmann
parents: 38857
diff changeset
   285
  "of_int z = the_elem (\<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
   286
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   287
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
   288
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   289
  have "(\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) }) respects intrel"
40819
2ac5af6eb8a8 adapted proofs to slightly changed definitions of congruent(2)
haftmann
parents: 39910
diff changeset
   290
    by (auto simp add: congruent_def) (simp add: algebra_simps of_nat_add [symmetric]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   291
            del: of_nat_add) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   292
  thus ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   293
    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
   294
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   295
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   296
lemma of_int_0 [simp]: "of_int 0 = 0"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   297
by (simp add: of_int Zero_int_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   298
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   299
lemma of_int_1 [simp]: "of_int 1 = 1"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   300
by (simp add: of_int One_int_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   301
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   302
lemma of_int_add [simp]: "of_int (w+z) = of_int w + of_int z"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   303
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
   304
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   305
lemma of_int_minus [simp]: "of_int (-z) = - (of_int z)"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   306
by (cases z) (simp add: algebra_simps of_int minus)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   307
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   308
lemma of_int_diff [simp]: "of_int (w - z) = of_int w - of_int z"
35050
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35032
diff changeset
   309
by (simp add: diff_minus Groups.diff_minus)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   310
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   311
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
   312
apply (cases w, cases z)
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
   313
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
   314
done
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
text{*Collapse nested embeddings*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   317
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
   318
by (induct n) auto
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   319
31015
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   320
lemma of_int_power:
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   321
  "of_int (z ^ n) = of_int z ^ n"
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   322
  by (induct n) simp_all
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
   323
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   324
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   325
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   326
text{*Class for unital rings with characteristic zero.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   327
 Includes non-ordered rings like the complex numbers.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   328
class ring_char_0 = ring_1 + semiring_char_0
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   329
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   330
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   331
lemma of_int_eq_iff [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   332
   "of_int w = of_int z \<longleftrightarrow> w = z"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   333
apply (cases w, cases z)
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   334
apply (simp add: of_int)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   335
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
   336
apply (simp only: of_nat_add [symmetric] of_nat_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   337
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   338
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   339
text{*Special cases where either operand is zero*}
36424
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   340
lemma of_int_eq_0_iff [simp]:
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   341
  "of_int z = 0 \<longleftrightarrow> z = 0"
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   342
  using of_int_eq_iff [of z 0] by simp
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   343
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   344
lemma of_int_0_eq_iff [simp]:
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   345
  "0 = of_int z \<longleftrightarrow> z = 0"
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   346
  using of_int_eq_iff [of 0 z] by simp
25919
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
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   349
36424
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   350
context linordered_idom
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   351
begin
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   352
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
   353
text{*Every @{text linordered_idom} has characteristic zero.*}
36424
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   354
subclass ring_char_0 ..
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   355
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   356
lemma of_int_le_iff [simp]:
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   357
  "of_int w \<le> of_int z \<longleftrightarrow> w \<le> z"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   358
  by (cases w, cases z)
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   359
    (simp add: of_int le minus algebra_simps of_nat_add [symmetric] del: of_nat_add)
36424
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   360
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   361
lemma of_int_less_iff [simp]:
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   362
  "of_int w < of_int z \<longleftrightarrow> w < z"
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   363
  by (simp add: less_le order_less_le)
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   364
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   365
lemma of_int_0_le_iff [simp]:
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   366
  "0 \<le> of_int z \<longleftrightarrow> 0 \<le> z"
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   367
  using of_int_le_iff [of 0 z] by simp
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   368
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   369
lemma of_int_le_0_iff [simp]:
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   370
  "of_int z \<le> 0 \<longleftrightarrow> z \<le> 0"
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   371
  using of_int_le_iff [of z 0] by simp
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   372
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   373
lemma of_int_0_less_iff [simp]:
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   374
  "0 < of_int z \<longleftrightarrow> 0 < z"
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   375
  using of_int_less_iff [of 0 z] by simp
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   376
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   377
lemma of_int_less_0_iff [simp]:
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   378
  "of_int z < 0 \<longleftrightarrow> z < 0"
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   379
  using of_int_less_iff [of z 0] by simp
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   380
f3f389fc7974 got rid of [simplified]
haftmann
parents: 36409
diff changeset
   381
end
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   382
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   383
lemma of_int_eq_id [simp]: "of_int = id"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   384
proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   385
  fix z show "of_int z = id z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   386
    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
   387
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   388
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   389
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   390
subsection {* Magnitude of an Integer, as a Natural Number: @{text nat} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   391
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   392
definition nat :: "int \<Rightarrow> nat" where
39910
10097e0a9dbd constant `contents` renamed to `the_elem`
haftmann
parents: 38857
diff changeset
   393
  "nat z = the_elem (\<Union>(x, y) \<in> Rep_Integ z. {x-y})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   394
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   395
lemma nat: "nat (Abs_Integ (intrel``{(x,y)})) = x-y"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   396
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   397
  have "(\<lambda>(x,y). {x-y}) respects intrel"
40819
2ac5af6eb8a8 adapted proofs to slightly changed definitions of congruent(2)
haftmann
parents: 39910
diff changeset
   398
    by (auto simp add: congruent_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   399
  thus ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   400
    by (simp add: nat_def UN_equiv_class [OF equiv_intrel])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   401
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   402
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   403
lemma nat_int [simp]: "nat (of_nat n) = n"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   404
by (simp add: nat int_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   405
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
   406
(* FIXME: duplicates nat_0 *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   407
lemma nat_zero [simp]: "nat 0 = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   408
by (simp add: Zero_int_def nat)
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
lemma int_nat_eq [simp]: "of_nat (nat z) = (if 0 \<le> z then z else 0)"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   411
by (cases z) (simp add: nat le int_def Zero_int_def)
25919
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
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
   414
by simp
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_0 [simp]: "z \<le> 0 ==> nat z = 0"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   417
by (cases z) (simp add: nat le Zero_int_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   418
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   419
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
   420
apply (cases w, cases z) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   421
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
   422
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   423
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   424
text{*An alternative condition is @{term "0 \<le> w"} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   425
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
   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
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
   429
by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   430
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   431
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
   432
apply (cases w, cases z) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   433
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
   434
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   435
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   436
lemma nonneg_eq_int:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   437
  fixes z :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   438
  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
   439
  shows P
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   440
  using assms by (blast dest: nat_0_le sym)
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
lemma nat_eq_iff: "(nat w = m) = (if 0 \<le> w then w = of_nat m else m=0)"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   443
by (cases w) (simp add: nat le int_def Zero_int_def, arith)
25919
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
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
   446
by (simp only: eq_commute [of m] nat_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   447
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   448
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
   449
apply (cases w)
29700
22faf21db3df added some simp rules
nipkow
parents: 29668
diff changeset
   450
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
   451
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   452
29700
22faf21db3df added some simp rules
nipkow
parents: 29668
diff changeset
   453
lemma nat_0_iff[simp]: "nat(i::int) = 0 \<longleftrightarrow> i\<le>0"
22faf21db3df added some simp rules
nipkow
parents: 29668
diff changeset
   454
by(simp add: nat_eq_iff) arith
22faf21db3df added some simp rules
nipkow
parents: 29668
diff changeset
   455
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   456
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
   457
by (auto simp add: nat_eq_iff2)
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 zero_less_nat_eq [simp]: "(0 < nat z) = (0 < z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   460
by (insert zless_nat_conj [of 0], auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   461
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   462
lemma nat_add_distrib:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   463
     "[| (0::int) \<le> z;  0 \<le> z' |] ==> nat (z+z') = nat z + nat z'"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   464
by (cases z, cases z') (simp add: nat add le Zero_int_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   465
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   466
lemma nat_diff_distrib:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   467
     "[| (0::int) \<le> z';  z' \<le> z |] ==> nat (z-z') = nat z - nat z'"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   468
by (cases z, cases z')
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   469
  (simp add: nat add minus diff_minus le Zero_int_def)
25919
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 nat_zminus_int [simp]: "nat (- (of_nat n)) = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   472
by (simp add: int_def minus nat Zero_int_def) 
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
lemma zless_nat_eq_int_zless: "(m < nat z) = (of_nat m < z)"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   475
by (cases z) (simp add: nat less int_def, arith)
25919
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
context ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   478
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   479
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   480
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
   481
  by (cases z rule: eq_Abs_Integ)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   482
   (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
   483
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   484
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   485
29779
2786b348c376 declare "nat o abs" as default measure for int
krauss
parents: 29700
diff changeset
   486
text {* For termination proofs: *}
2786b348c376 declare "nat o abs" as default measure for int
krauss
parents: 29700
diff changeset
   487
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
   488
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   489
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   490
subsection{*Lemmas about the Function @{term of_nat} and Orderings*}
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_0: "- (of_nat (Suc n)) < (0 \<Colon> int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   493
by (simp add: order_less_le del: of_nat_Suc)
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_zless [iff]: "- (of_nat (Suc n)) < (of_nat m \<Colon> int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   496
by (rule negative_zless_0 [THEN order_less_le_trans], simp)
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_0: "- of_nat n \<le> (0 \<Colon> int)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   499
by (simp add: minus_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 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
   502
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
   503
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   504
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
   505
by (subst le_minus_iff, simp del: of_nat_Suc)
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 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
   508
by (simp add: int_def le minus Zero_int_def)
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 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
   511
by (simp add: linorder_not_less)
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 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
   514
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
   515
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   516
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
   517
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   518
  have "(w \<le> z) = (0 \<le> z - w)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   519
    by (simp only: le_diff_eq add_0_left)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   520
  also have "\<dots> = (\<exists>n. z - w = of_nat n)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   521
    by (auto elim: zero_le_imp_eq_int)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   522
  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
   523
    by (simp only: algebra_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   524
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   525
qed
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 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
   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
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
   531
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   532
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   533
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
   534
      It is proved here because attribute @{text arith_split} is not available
35050
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35032
diff changeset
   535
      in theory @{text Rings}.
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   536
      But is it really better than just rewriting with @{text abs_if}?*}
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
   537
lemma abs_split [arith_split,no_atp]:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
   538
     "P(abs(a::'a::linordered_idom)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   539
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
   540
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   541
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
   542
apply (cases x)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   543
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
   544
apply (rule_tac x="y - Suc x" in exI, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   545
done
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
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   548
subsection {* Cases and induction *}
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
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
   551
whether an integer is negative or not.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   552
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   553
theorem int_cases [case_names nonneg neg, cases type: int]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   554
  "[|!! n. (z \<Colon> int) = of_nat n ==> P;  !! n. z =  - (of_nat (Suc n)) ==> P |] ==> P"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   555
apply (cases "z < 0")
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   556
apply (blast dest!: negD)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   557
apply (simp add: linorder_not_less del: of_nat_Suc)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   558
apply auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   559
apply (blast dest: nat_0_le [THEN sym])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   560
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   561
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   562
theorem int_of_nat_induct [case_names nonneg neg, induct type: int]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   563
     "[|!! n. P (of_nat n \<Colon> int);  !!n. P (- (of_nat (Suc n))) |] ==> P z"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   564
  by (cases z) auto
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   565
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   566
text{*Contributed by Brian Huffman*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   567
theorem int_diff_cases:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   568
  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
   569
apply (cases z rule: eq_Abs_Integ)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   570
apply (rule_tac m=x and n=y in diff)
37887
2ae085b07f2f diff_minus subsumes diff_def
haftmann
parents: 37767
diff changeset
   571
apply (simp add: int_def minus add diff_minus)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   572
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   573
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   574
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   575
subsection {* Binary representation *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   576
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   577
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   578
  This formalization defines binary arithmetic in terms of the integers
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   579
  rather than using a datatype. This avoids multiple representations (leading
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   580
  zeroes, etc.)  See @{text "ZF/Tools/twos-compl.ML"}, function @{text
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   581
  int_of_binary}, for the numerical interpretation.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   582
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   583
  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
   584
  even if m is negative;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   585
  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
   586
  @{text "-5 = (-3)*2 + 1"}.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   587
  
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   588
  This two's complement binary representation derives from the paper 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   589
  "An Efficient Representation of Arithmetic for Term Rewriting" by
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   590
  Dave Cohen and Phil Watson, Rewriting Techniques and Applications,
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   591
  Springer LNCS 488 (240-251), 1991.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   592
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   593
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   594
subsubsection {* The constructors @{term Bit0}, @{term Bit1}, @{term Pls} and @{term Min} *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   595
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   596
definition Pls :: int where
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   597
  "Pls = 0"
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   598
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   599
definition Min :: int where
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   600
  "Min = - 1"
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   601
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   602
definition Bit0 :: "int \<Rightarrow> int" where
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   603
  "Bit0 k = k + k"
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   604
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   605
definition Bit1 :: "int \<Rightarrow> int" where
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   606
  "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"
35123
e286d5df187a modernized structures;
wenzelm
parents: 35050
diff changeset
   617
setup Numeral_Syntax.setup
25919
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
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   629
definition succ :: "int \<Rightarrow> int" where
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   630
  "succ k = k + 1"
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   631
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   632
definition pred :: "int \<Rightarrow> int" where
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   633
  "pred k = k - 1"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   634
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   635
lemmas
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   636
  max_number_of [simp] = max_def
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
   637
    [of "number_of u" "number_of v", standard]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   638
and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   639
  min_number_of [simp] = min_def 
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
   640
    [of "number_of u" "number_of v", standard]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   641
  -- {* unfolding @{text minx} and @{text max} on numerals *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   642
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   643
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
   644
  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
   645
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   646
text {* Removal of leading zeroes *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   647
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31100
diff changeset
   648
lemma Bit0_Pls [simp, code_post]:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   649
  "Bit0 Pls = Pls"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   650
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   651
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31100
diff changeset
   652
lemma Bit1_Min [simp, code_post]:
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   653
  "Bit1 Min = Min"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   654
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   655
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
   656
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
   657
  Bit0_Pls Bit1_Min
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
   658
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   659
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   660
subsubsection {* Successor and predecessor functions *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   661
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   662
text {* Successor *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   663
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   664
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
   665
  "succ Pls = Bit1 Pls"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   666
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   667
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   668
lemma succ_Min:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   669
  "succ Min = Pls"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   670
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   671
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   672
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
   673
  "succ (Bit0 k) = Bit1 k"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   674
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   675
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   676
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
   677
  "succ (Bit1 k) = Bit0 (succ k)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   678
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   679
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   680
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
   681
  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
   682
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   683
text {* Predecessor *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   684
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   685
lemma pred_Pls:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   686
  "pred Pls = Min"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   687
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   688
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   689
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
   690
  "pred Min = Bit0 Min"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   691
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   692
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   693
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
   694
  "pred (Bit0 k) = Bit1 (pred k)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   695
  unfolding numeral_simps by simp 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   696
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   697
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
   698
  "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
   699
  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
   700
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   701
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
   702
  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
   703
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   704
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   705
subsubsection {* Binary arithmetic *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   706
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   707
text {* Addition *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   708
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   709
lemma add_Pls:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   710
  "Pls + k = k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   711
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   712
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   713
lemma add_Min:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   714
  "Min + k = pred k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   715
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   716
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   717
lemma add_Bit0_Bit0:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   718
  "(Bit0 k) + (Bit0 l) = Bit0 (k + l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   719
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   720
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   721
lemma add_Bit0_Bit1:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   722
  "(Bit0 k) + (Bit1 l) = Bit1 (k + l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   723
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   724
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   725
lemma add_Bit1_Bit0:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   726
  "(Bit1 k) + (Bit0 l) = Bit1 (k + l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   727
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   728
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   729
lemma add_Bit1_Bit1:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   730
  "(Bit1 k) + (Bit1 l) = Bit0 (k + succ l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   731
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   732
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   733
lemma add_Pls_right:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   734
  "k + Pls = k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   735
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   736
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   737
lemma add_Min_right:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   738
  "k + Min = pred k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   739
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   740
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   741
lemmas add_bin_simps [simp] =
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   742
  add_Pls add_Min add_Pls_right add_Min_right
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   743
  add_Bit0_Bit0 add_Bit0_Bit1 add_Bit1_Bit0 add_Bit1_Bit1
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   744
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   745
text {* Negation *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   746
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   747
lemma minus_Pls:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   748
  "- Pls = Pls"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   749
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   750
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   751
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
   752
  "- Min = Bit1 Pls"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   753
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   754
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   755
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
   756
  "- (Bit0 k) = Bit0 (- k)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   757
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   758
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   759
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
   760
  "- (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
   761
  unfolding numeral_simps by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   762
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   763
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
   764
  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
   765
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   766
text {* Subtraction *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   767
29046
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   768
lemma diff_bin_simps [simp]:
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   769
  "k - Pls = k"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   770
  "k - Min = succ k"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   771
  "Pls - (Bit0 l) = Bit0 (Pls - l)"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   772
  "Pls - (Bit1 l) = Bit1 (Min - l)"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   773
  "Min - (Bit0 l) = Bit1 (Min - l)"
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   774
  "Min - (Bit1 l) = Bit0 (Min - l)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   775
  "(Bit0 k) - (Bit0 l) = Bit0 (k - l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   776
  "(Bit0 k) - (Bit1 l) = Bit1 (pred k - l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   777
  "(Bit1 k) - (Bit0 l) = Bit1 (k - l)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   778
  "(Bit1 k) - (Bit1 l) = Bit0 (k - l)"
29046
773098b76201 clean up diff_bin_simps
huffman
parents: 29040
diff changeset
   779
  unfolding numeral_simps by simp_all
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   780
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   781
text {* Multiplication *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   782
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   783
lemma mult_Pls:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   784
  "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
   785
  unfolding numeral_simps by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   786
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   787
lemma mult_Min:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   788
  "Min * k = - k"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   789
  unfolding numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   790
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   791
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
   792
  "(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
   793
  unfolding numeral_simps int_distrib by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   794
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   795
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
   796
  "(Bit1 k) * l = (Bit0 (k * l)) + l"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   797
  unfolding numeral_simps int_distrib by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   798
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   799
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
   800
  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
   801
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   802
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   803
subsubsection {* Binary comparisons *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   804
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   805
text {* Preliminaries *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   806
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   807
lemma even_less_0_iff:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
   808
  "a + a < 0 \<longleftrightarrow> a < (0::'a::linordered_idom)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   809
proof -
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   810
  have "a + a < 0 \<longleftrightarrow> (1+1)*a < 0" by (simp add: left_distrib)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   811
  also have "(1+1)*a < 0 \<longleftrightarrow> a < 0"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   812
    by (simp add: mult_less_0_iff zero_less_two 
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   813
                  order_less_not_sym [OF zero_less_two])
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   814
  finally show ?thesis .
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   815
qed
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   816
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   817
lemma le_imp_0_less: 
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   818
  assumes le: "0 \<le> z"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   819
  shows "(0::int) < 1 + z"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   820
proof -
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   821
  have "0 \<le> z" by fact
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   822
  also have "... < z + 1" by (rule less_add_one) 
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   823
  also have "... = 1 + z" by (simp add: add_ac)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   824
  finally show "0 < 1 + z" .
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   825
qed
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   826
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   827
lemma odd_less_0_iff:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   828
  "(1 + z + z < 0) = (z < (0::int))"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
   829
proof (cases z)
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   830
  case (nonneg n)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   831
  thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   832
                             le_imp_0_less [THEN order_less_imp_le])  
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   833
next
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   834
  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
   835
  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
   836
    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
   837
qed
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   838
28985
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
   839
lemma bin_less_0_simps:
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   840
  "Pls < 0 \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   841
  "Min < 0 \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   842
  "Bit0 w < 0 \<longleftrightarrow> w < 0"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   843
  "Bit1 w < 0 \<longleftrightarrow> w < 0"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   844
  unfolding numeral_simps
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   845
  by (simp_all add: even_less_0_iff odd_less_0_iff)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   846
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   847
lemma less_bin_lemma: "k < l \<longleftrightarrow> k - l < (0::int)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   848
  by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   849
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   850
lemma le_iff_pred_less: "k \<le> l \<longleftrightarrow> pred k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   851
  unfolding numeral_simps
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   852
  proof
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   853
    have "k - 1 < k" by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   854
    also assume "k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   855
    finally show "k - 1 < l" .
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   856
  next
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   857
    assume "k - 1 < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   858
    hence "(k - 1) + 1 \<le> l" by (rule zless_imp_add1_zle)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   859
    thus "k \<le> l" by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   860
  qed
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   861
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   862
lemma succ_pred: "succ (pred x) = x"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   863
  unfolding numeral_simps by simp
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   864
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   865
text {* Less-than *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   866
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   867
lemma less_bin_simps [simp]:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   868
  "Pls < Pls \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   869
  "Pls < Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   870
  "Pls < Bit0 k \<longleftrightarrow> Pls < k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   871
  "Pls < Bit1 k \<longleftrightarrow> Pls \<le> k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   872
  "Min < Pls \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   873
  "Min < Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   874
  "Min < Bit0 k \<longleftrightarrow> Min < k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   875
  "Min < Bit1 k \<longleftrightarrow> Min < k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   876
  "Bit0 k < Pls \<longleftrightarrow> k < Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   877
  "Bit0 k < Min \<longleftrightarrow> k \<le> Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   878
  "Bit1 k < Pls \<longleftrightarrow> k < Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   879
  "Bit1 k < Min \<longleftrightarrow> k < Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   880
  "Bit0 k < Bit0 l \<longleftrightarrow> k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   881
  "Bit0 k < Bit1 l \<longleftrightarrow> k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   882
  "Bit1 k < Bit0 l \<longleftrightarrow> k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   883
  "Bit1 k < Bit1 l \<longleftrightarrow> k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   884
  unfolding le_iff_pred_less
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   885
    less_bin_lemma [of Pls]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   886
    less_bin_lemma [of Min]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   887
    less_bin_lemma [of "k"]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   888
    less_bin_lemma [of "Bit0 k"]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   889
    less_bin_lemma [of "Bit1 k"]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   890
    less_bin_lemma [of "pred Pls"]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   891
    less_bin_lemma [of "pred k"]
28985
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
   892
  by (simp_all add: bin_less_0_simps succ_pred)
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   893
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   894
text {* Less-than-or-equal *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   895
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   896
lemma le_bin_simps [simp]:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   897
  "Pls \<le> Pls \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   898
  "Pls \<le> Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   899
  "Pls \<le> Bit0 k \<longleftrightarrow> Pls \<le> k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   900
  "Pls \<le> Bit1 k \<longleftrightarrow> Pls \<le> k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   901
  "Min \<le> Pls \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   902
  "Min \<le> Min \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   903
  "Min \<le> Bit0 k \<longleftrightarrow> Min < k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   904
  "Min \<le> Bit1 k \<longleftrightarrow> Min \<le> k"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   905
  "Bit0 k \<le> Pls \<longleftrightarrow> k \<le> Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   906
  "Bit0 k \<le> Min \<longleftrightarrow> k \<le> Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   907
  "Bit1 k \<le> Pls \<longleftrightarrow> k < Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   908
  "Bit1 k \<le> Min \<longleftrightarrow> k \<le> Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   909
  "Bit0 k \<le> Bit0 l \<longleftrightarrow> k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   910
  "Bit0 k \<le> Bit1 l \<longleftrightarrow> k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   911
  "Bit1 k \<le> Bit0 l \<longleftrightarrow> k < l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   912
  "Bit1 k \<le> Bit1 l \<longleftrightarrow> k \<le> l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   913
  unfolding not_less [symmetric]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   914
  by (simp_all add: not_le)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   915
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   916
text {* Equality *}
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   917
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   918
lemma eq_bin_simps [simp]:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   919
  "Pls = Pls \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   920
  "Pls = Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   921
  "Pls = Bit0 l \<longleftrightarrow> Pls = l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   922
  "Pls = Bit1 l \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   923
  "Min = Pls \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   924
  "Min = Min \<longleftrightarrow> True"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   925
  "Min = Bit0 l \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   926
  "Min = Bit1 l \<longleftrightarrow> Min = l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   927
  "Bit0 k = Pls \<longleftrightarrow> k = Pls"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   928
  "Bit0 k = Min \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   929
  "Bit1 k = Pls \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   930
  "Bit1 k = Min \<longleftrightarrow> k = Min"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   931
  "Bit0 k = Bit0 l \<longleftrightarrow> k = l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   932
  "Bit0 k = Bit1 l \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   933
  "Bit1 k = Bit0 l \<longleftrightarrow> False"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   934
  "Bit1 k = Bit1 l \<longleftrightarrow> k = l"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   935
  unfolding order_eq_iff [where 'a=int]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   936
  by (simp_all add: not_less)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   937
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   938
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   939
subsection {* Converting Numerals to Rings: @{term number_of} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   940
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   941
class number_ring = number + comm_ring_1 +
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   942
  assumes number_of_eq: "number_of k = of_int k"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   943
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   944
class number_semiring = number + comm_semiring_1 +
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   945
  assumes number_of_int: "number_of (of_nat n) = of_nat n"
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   946
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   947
instance number_ring \<subseteq> number_semiring
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   948
proof
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   949
  fix n show "number_of (of_nat n) = (of_nat n :: 'a)"
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   950
    unfolding number_of_eq by (rule of_int_of_nat_eq)
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   951
qed
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
   952
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   953
text {* self-embedding of the integers *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   954
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   955
instantiation int :: number_ring
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   956
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   957
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   958
definition
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
   959
  int_number_of_def: "number_of w = (of_int w \<Colon> int)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   960
28724
haftmann
parents: 28661
diff changeset
   961
instance proof
haftmann
parents: 28661
diff changeset
   962
qed (simp only: int_number_of_def)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   963
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   964
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   965
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   966
lemma number_of_is_id:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   967
  "number_of (k::int) = k"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   968
  unfolding int_number_of_def by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   969
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   970
lemma number_of_succ:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   971
  "number_of (succ k) = (1 + number_of k ::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   972
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   973
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   974
lemma number_of_pred:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   975
  "number_of (pred w) = (- 1 + number_of w ::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   976
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   977
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   978
lemma number_of_minus:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   979
  "number_of (uminus w) = (- (number_of w)::'a::number_ring)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   980
  unfolding number_of_eq by (rule of_int_minus)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   981
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   982
lemma number_of_add:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   983
  "number_of (v + w) = (number_of v + number_of w::'a::number_ring)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   984
  unfolding number_of_eq by (rule of_int_add)
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   985
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   986
lemma number_of_diff:
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   987
  "number_of (v - w) = (number_of v - number_of w::'a::number_ring)"
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   988
  unfolding number_of_eq by (rule of_int_diff)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   989
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   990
lemma number_of_mult:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   991
  "number_of (v * w) = (number_of v * number_of w::'a::number_ring)"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
   992
  unfolding number_of_eq by (rule of_int_mult)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   993
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   994
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   995
  The correctness of shifting.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   996
  But it doesn't seem to give a measurable speed-up.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   997
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
   998
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
   999
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
  1000
  "(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
  1001
  unfolding number_of_eq numeral_simps left_distrib by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1002
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1003
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1004
  Converting numerals 0 and 1 to their abstract versions.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1005
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1006
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1007
lemma semiring_numeral_0_eq_0:
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1008
  "Numeral0 = (0::'a::number_semiring)"
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1009
  using number_of_int [where 'a='a and n=0]
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1010
  unfolding numeral_simps by simp
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1011
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1012
lemma semiring_numeral_1_eq_1:
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1013
  "Numeral1 = (1::'a::number_semiring)"
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1014
  using number_of_int [where 'a='a and n=1]
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1015
  unfolding numeral_simps by simp
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1016
32272
cc1bf9077167 added numeral code postprocessor rules on type int
haftmann
parents: 32069
diff changeset
  1017
lemma numeral_0_eq_0 [simp, code_post]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1018
  "Numeral0 = (0::'a::number_ring)"
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1019
  by (rule semiring_numeral_0_eq_0)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1020
32272
cc1bf9077167 added numeral code postprocessor rules on type int
haftmann
parents: 32069
diff changeset
  1021
lemma numeral_1_eq_1 [simp, code_post]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1022
  "Numeral1 = (1::'a::number_ring)"
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1023
  by (rule semiring_numeral_1_eq_1)
25919
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
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1026
  Special-case simplification for small constants.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1027
*}
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
text{*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1030
  Unary minus for the abstract constant 1. Cannot be inserted
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1031
  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
  1032
*}
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
lemma numeral_m1_eq_minus_1:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1035
  "(-1::'a::number_ring) = - 1"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1036
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1037
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1038
lemma mult_minus1 [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1039
  "-1 * z = -(z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1040
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1041
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1042
lemma mult_minus1_right [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1043
  "z * -1 = -(z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1044
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1045
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1046
(*Negation of a coefficient*)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1047
lemma minus_number_of_mult [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1048
   "- (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
  1049
   unfolding number_of_eq by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1050
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1051
text {* Subtraction *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1052
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1053
lemma diff_number_of_eq:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1054
  "number_of v - number_of w =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1055
    (number_of (v + uminus w)::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1056
  unfolding number_of_eq by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1057
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1058
lemma number_of_Pls:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1059
  "number_of Pls = (0::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1060
  unfolding number_of_eq numeral_simps by simp
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
lemma number_of_Min:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1063
  "number_of Min = (- 1::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1064
  unfolding number_of_eq numeral_simps by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1065
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1066
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
  1067
  "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
  1068
  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
  1069
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1070
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
  1071
  "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
  1072
  unfolding number_of_eq numeral_simps by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1073
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1074
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1075
subsubsection {* Equality of Binary Numbers *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1076
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1077
text {* First version by Norbert Voelker *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1078
36716
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1079
definition (*for simplifying equalities*) iszero :: "'a\<Colon>semiring_1 \<Rightarrow> bool" where
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1080
  "iszero z \<longleftrightarrow> z = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1081
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1082
lemma iszero_0: "iszero 0"
36716
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1083
  by (simp add: iszero_def)
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1084
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1085
lemma iszero_Numeral0: "iszero (Numeral0 :: 'a::number_ring)"
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1086
  by (simp add: iszero_0)
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1087
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1088
lemma not_iszero_1: "\<not> iszero 1"
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1089
  by (simp add: iszero_def)
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1090
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1091
lemma not_iszero_Numeral1: "\<not> iszero (Numeral1 :: 'a::number_ring)"
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1092
  by (simp add: not_iszero_1)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1093
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
  1094
lemma eq_number_of_eq [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1095
  "((number_of x::'a::number_ring) = number_of y) =
36716
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36424
diff changeset
  1096
     iszero (number_of (x + uminus y) :: 'a)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1097
unfolding iszero_def number_of_add number_of_minus
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1098
by (simp add: algebra_simps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1099
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1100
lemma iszero_number_of_Pls:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1101
  "iszero ((number_of Pls)::'a::number_ring)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1102
unfolding iszero_def numeral_0_eq_0 ..
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1103
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1104
lemma nonzero_number_of_Min:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1105
  "~ iszero ((number_of Min)::'a::number_ring)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1106
unfolding iszero_def numeral_m1_eq_minus_1 by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1107
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1108
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1109
subsubsection {* Comparisons, for Ordered Rings *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1110
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1111
lemmas double_eq_0_iff = double_zero
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1112
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1113
lemma odd_nonzero:
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1114
  "1 + z + z \<noteq> (0::int)"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1115
proof (cases z)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1116
  case (nonneg n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1117
  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
  1118
  thus ?thesis using  le_imp_0_less [OF le]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1119
    by (auto simp add: add_assoc) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1120
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1121
  case (neg n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1122
  show ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1123
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1124
    assume eq: "1 + z + z = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1125
    have "(0::int) < 1 + (of_nat n + of_nat n)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1126
      by (simp add: le_imp_0_less add_increasing) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1127
    also have "... = - (1 + z + z)" 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1128
      by (simp add: neg add_assoc [symmetric]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1129
    also have "... = 0" by (simp add: eq) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1130
    finally have "0<0" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1131
    thus False by blast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1132
  qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1133
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1134
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1135
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
  1136
  "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
  1137
   iszero (number_of w::'a::{ring_char_0,number_ring})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1138
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1139
  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
  1140
  proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1141
    assume eq: "of_int w + of_int w = (0::'a)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1142
    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
  1143
    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
  1144
    then show "w = 0" by (simp only: double_eq_0_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1145
  qed
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1146
  thus ?thesis
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1147
    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
  1148
qed
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1149
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1150
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
  1151
  "~ 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
  1152
proof -
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1153
  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
  1154
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1155
    assume eq: "1 + of_int w + of_int w = (0::'a)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1156
    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
  1157
    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
  1158
    with odd_nonzero show False by blast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1159
  qed
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1160
  thus ?thesis
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26075
diff changeset
  1161
    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
  1162
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1163
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
  1164
lemmas iszero_simps [simp] =
28985
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1165
  iszero_0 not_iszero_1
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1166
  iszero_number_of_Pls nonzero_number_of_Min
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1167
  iszero_number_of_Bit0 iszero_number_of_Bit1
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1168
(* iszero_number_of_Pls would never normally be used
af325cd29b15 add named lemma lists: neg_simps and iszero_simps
huffman
parents: 28984
diff changeset
  1169
   because its lhs simplifies to "iszero 0" *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1170
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1171
subsubsection {* The Less-Than Relation *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1172
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1173
lemma double_less_0_iff:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1174
  "(a + a < 0) = (a < (0::'a::linordered_idom))"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1175
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1176
  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
  1177
  also have "... = (a < 0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1178
    by (simp add: mult_less_0_iff zero_less_two 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1179
                  order_less_not_sym [OF zero_less_two]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1180
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1181
qed
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
lemma odd_less_0:
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1184
  "(1 + z + z < 0) = (z < (0::int))"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1185
proof (cases z)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1186
  case (nonneg n)
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1187
  then show ?thesis
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1188
    by (simp add: linorder_not_less add_assoc add_increasing
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1189
      le_imp_0_less [THEN order_less_imp_le])
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1190
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1191
  case (neg n)
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1192
  then show ?thesis
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1193
    by (simp del: of_nat_Suc of_nat_add of_nat_1
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1194
      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
  1195
qed
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
text {* Less-Than or Equals *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1198
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1199
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
  1200
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1201
lemmas le_number_of_eq_not_less =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1202
  linorder_not_less [of "number_of w" "number_of v", symmetric, 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1203
  standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1204
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1205
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1206
text {* Absolute value (@{term abs}) *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1207
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1208
lemma abs_number_of:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1209
  "abs(number_of x::'a::{linordered_idom,number_ring}) =
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1210
   (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
  1211
  by (simp add: abs_if)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1212
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1213
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1214
text {* Re-orientation of the equation nnn=x *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1215
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1216
lemma number_of_reorient:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1217
  "(number_of w = x) = (x = number_of w)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1218
  by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1219
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1220
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1221
subsubsection {* Simplification of arithmetic operations on integer constants. *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1222
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1223
lemmas arith_extra_simps [standard, simp] =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1224
  number_of_add [symmetric]
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1225
  number_of_minus [symmetric]
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1226
  numeral_m1_eq_minus_1 [symmetric]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1227
  number_of_mult [symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1228
  diff_number_of_eq abs_number_of 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1229
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1230
text {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1231
  For making a minimal simpset, one must include these default simprules.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1232
  Also include @{text simp_thms}.
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1233
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1234
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1235
lemmas arith_simps = 
26075
815f3ccc0b45 added lemma lists {normalize,succ,pred,minus,add,mult}_bin_simps
huffman
parents: 26072
diff changeset
  1236
  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
  1237
  add_bin_simps minus_bin_simps mult_bin_simps
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1238
  abs_zero abs_one arith_extra_simps
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
text {* Simplification of relational operations *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1241
28962
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1242
lemma less_number_of [simp]:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1243
  "(number_of x::'a::{linordered_idom,number_ring}) < number_of y \<longleftrightarrow> x < y"
28962
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1244
  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
  1245
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1246
lemma le_number_of [simp]:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1247
  "(number_of x::'a::{linordered_idom,number_ring}) \<le> number_of y \<longleftrightarrow> x \<le> y"
28962
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1248
  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
  1249
28967
3bdb1eae352c enable eq_bin_simps for simplifying equalities on numerals
huffman
parents: 28962
diff changeset
  1250
lemma eq_number_of [simp]:
3bdb1eae352c enable eq_bin_simps for simplifying equalities on numerals
huffman
parents: 28962
diff changeset
  1251
  "(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
  1252
  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
  1253
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
  1254
lemmas rel_simps =
28962
f603183f7a5c enable le_bin_simps and less_bin_simps for simplifying inequalities on numerals
huffman
parents: 28958
diff changeset
  1255
  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
  1256
  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
  1257
  eq_number_of_eq eq_bin_simps
29039
8b9207f82a78 separate neg_simps from rel_simps
huffman
parents: 28988
diff changeset
  1258
  iszero_simps
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
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1261
subsubsection {* Simplification of arithmetic when nested to the right. *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1262
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1263
lemma add_number_of_left [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1264
  "number_of v + (number_of w + z) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1265
   (number_of(v + w) + z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1266
  by (simp add: add_assoc [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1267
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1268
lemma mult_number_of_left [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1269
  "number_of v * (number_of w * z) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1270
   (number_of(v * w) * z::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1271
  by (simp add: mult_assoc [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1272
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1273
lemma add_number_of_diff1:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1274
  "number_of v + (number_of w - c) = 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1275
  number_of(v + w) - (c::'a::number_ring)"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
  1276
  by (simp add: diff_minus)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1277
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1278
lemma add_number_of_diff2 [simp]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1279
  "number_of v + (c - number_of w) =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1280
   number_of (v + uminus w) + (c::'a::number_ring)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29046
diff changeset
  1281
by (simp add: algebra_simps diff_number_of_eq [symmetric])
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1282
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1283
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1284
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1285
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1286
subsection {* The Set of Integers *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1287
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1288
context ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1289
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1290
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1291
definition Ints  :: "'a set" where
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
  1292
  "Ints = range of_int"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1293
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1294
notation (xsymbols)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1295
  Ints  ("\<int>")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1296
35634
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1297
lemma Ints_of_int [simp]: "of_int z \<in> \<int>"
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1298
  by (simp add: Ints_def)
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1299
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1300
lemma Ints_of_nat [simp]: "of_nat n \<in> \<int>"
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1301
apply (simp add: Ints_def)
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1302
apply (rule range_eqI)
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1303
apply (rule of_int_of_nat_eq [symmetric])
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1304
done
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1305
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1306
lemma Ints_0 [simp]: "0 \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1307
apply (simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1308
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1309
apply (rule of_int_0 [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1310
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1311
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1312
lemma Ints_1 [simp]: "1 \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1313
apply (simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1314
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1315
apply (rule of_int_1 [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1316
done
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
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
  1319
apply (auto simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1320
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1321
apply (rule of_int_add [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1322
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1323
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1324
lemma Ints_minus [simp]: "a \<in> \<int> \<Longrightarrow> -a \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1325
apply (auto simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1326
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1327
apply (rule of_int_minus [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1328
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1329
35634
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1330
lemma Ints_diff [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a - b \<in> \<int>"
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1331
apply (auto simp add: Ints_def)
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1332
apply (rule range_eqI)
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1333
apply (rule of_int_diff [symmetric])
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1334
done
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1335
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1336
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
  1337
apply (auto simp add: Ints_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1338
apply (rule range_eqI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1339
apply (rule of_int_mult [symmetric])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1340
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1341
35634
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1342
lemma Ints_power [simp]: "a \<in> \<int> \<Longrightarrow> a ^ n \<in> \<int>"
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1343
by (induct n) simp_all
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1344
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1345
lemma Ints_cases [cases set: Ints]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1346
  assumes "q \<in> \<int>"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1347
  obtains (of_int) z where "q = of_int z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1348
  unfolding Ints_def
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1349
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1350
  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
  1351
  then obtain z where "q = of_int z" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1352
  then show thesis ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1353
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1354
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1355
lemma Ints_induct [case_names of_int, induct set: Ints]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1356
  "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
  1357
  by (rule Ints_cases) auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1358
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1359
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1360
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1361
text {* The premise involving @{term Ints} prevents @{term "a = 1/2"}. *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1362
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1363
lemma Ints_double_eq_0_iff:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1364
  assumes in_Ints: "a \<in> Ints"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1365
  shows "(a + a = 0) = (a = (0::'a::ring_char_0))"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1366
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1367
  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
  1368
  then obtain z where a: "a = of_int z" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1369
  show ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1370
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1371
    assume "a = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1372
    thus "a + a = 0" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1373
  next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1374
    assume eq: "a + a = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1375
    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
  1376
    hence "z + z = 0" by (simp only: of_int_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1377
    hence "z = 0" by (simp only: double_eq_0_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1378
    thus "a = 0" by (simp add: a)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1379
  qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1380
qed
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 Ints_odd_nonzero:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1383
  assumes in_Ints: "a \<in> Ints"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1384
  shows "1 + a + a \<noteq> (0::'a::ring_char_0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1385
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1386
  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
  1387
  then obtain z where a: "a = of_int z" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1388
  show ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1389
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1390
    assume eq: "1 + a + a = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1391
    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
  1392
    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
  1393
    with odd_nonzero show False by blast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1394
  qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1395
qed 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1396
35634
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1397
lemma Ints_number_of [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1398
  "(number_of w :: 'a::number_ring) \<in> Ints"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1399
  unfolding number_of_eq Ints_def by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1400
35634
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1401
lemma Nats_number_of [simp]:
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1402
  "Int.Pls \<le> w \<Longrightarrow> (number_of w :: 'a::number_ring) \<in> Nats"
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1403
unfolding Int.Pls_def number_of_eq
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1404
by (simp only: of_nat_nat [symmetric] of_nat_in_Nats)
6fdfe37b84d6 add more simp rules for Ints
huffman
parents: 35216
diff changeset
  1405
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1406
lemma Ints_odd_less_0: 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1407
  assumes in_Ints: "a \<in> Ints"
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1408
  shows "(1 + a + a < 0) = (a < (0::'a::linordered_idom))"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1409
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1410
  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
  1411
  then obtain z where a: "a = of_int z" ..
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1412
  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
  1413
    by (simp add: a)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1414
  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
  1415
  also have "... = (a < 0)" by (simp add: a)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1416
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1417
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1418
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
subsection {* @{term setsum} and @{term setprod} *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1421
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1422
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
  1423
  apply (cases "finite A")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1424
  apply (erule finite_induct, auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1425
  done
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
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
  1428
  apply (cases "finite A")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1429
  apply (erule finite_induct, auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1430
  done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1431
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1432
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
  1433
  apply (cases "finite A")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1434
  apply (erule finite_induct, auto simp add: of_nat_mult)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1435
  done
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
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
  1438
  apply (cases "finite A")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1439
  apply (erule finite_induct, auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1440
  done
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
lemmas int_setsum = of_nat_setsum [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1443
lemmas int_setprod = of_nat_setprod [where 'a=int]
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
subsection{*Inequality Reasoning for the Arithmetic Simproc*}
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
lemma add_numeral_0: "Numeral0 + a = (a::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1449
by simp 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1450
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1451
lemma add_numeral_0_right: "a + Numeral0 = (a::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1452
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1453
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1454
lemma mult_numeral_1: "Numeral1 * a = (a::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1455
by simp 
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
lemma mult_numeral_1_right: "a * Numeral1 = (a::'a::number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1458
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1459
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1460
lemma divide_numeral_1: "a / Numeral1 = (a::'a::{number_ring,field})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1461
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1462
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1463
lemma inverse_numeral_1:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1464
  "inverse Numeral1 = (Numeral1::'a::{number_ring,field})"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1465
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1466
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1467
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
  1468
for 0 and 1 reduces the number of special cases.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1469
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1470
lemmas add_0s = add_numeral_0 add_numeral_0_right
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1471
lemmas mult_1s = mult_numeral_1 mult_numeral_1_right 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1472
                 mult_minus1 mult_minus1_right
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1473
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1474
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1475
subsection{*Special Arithmetic Rules for Abstract 0 and 1*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1476
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1477
text{*Arithmetic computations are defined for binary literals, which leaves 0
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1478
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
  1479
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
  1480
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1481
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1482
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
  1483
by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1484
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
lemmas add_number_of_eq = number_of_add [symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1487
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1488
text{*Allow 1 on either or both sides*}
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1489
lemma semiring_one_add_one_is_two: "1 + 1 = (2::'a::number_semiring)"
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1490
  using number_of_int [where 'a='a and n="Suc (Suc 0)"]
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1491
  by (simp add: numeral_simps)
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1492
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1493
lemma one_add_one_is_two: "1 + 1 = (2::'a::number_ring)"
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1494
by (rule semiring_one_add_one_is_two)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1495
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1496
lemmas add_special =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1497
    one_add_one_is_two
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1498
    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
  1499
    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
  1500
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1501
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
  1502
lemmas diff_special =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1503
    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
  1504
    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
  1505
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1506
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
  1507
lemmas eq_special =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1508
    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
  1509
    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
  1510
    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
  1511
    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
  1512
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1513
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
  1514
lemmas less_special =
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1515
  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
  1516
  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
  1517
  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
  1518
  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
  1519
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1520
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
  1521
lemmas le_special =
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28967
diff changeset
  1522
    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
  1523
    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
  1524
    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
  1525
    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
  1526
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1527
lemmas arith_special[simp] = 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1528
       add_special diff_special eq_special less_special le_special
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1529
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1530
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1531
text {* Legacy theorems *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1532
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1533
lemmas zle_int = of_nat_le_iff [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1534
lemmas int_int_eq = of_nat_eq_iff [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1535
30802
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1536
subsection {* Setting up simplification procedures *}
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1537
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1538
lemmas int_arith_rules =
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1539
  neg_le_iff_le numeral_0_eq_0 numeral_1_eq_1
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1540
  minus_zero diff_minus left_minus right_minus
36076
882403378a41 added missing mult_1_left to linarith simp rules
boehmes
parents: 35829
diff changeset
  1541
  mult_zero_left mult_zero_right mult_Bit1 mult_1_left mult_1_right
30802
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1542
  mult_minus_left mult_minus_right
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1543
  minus_add_distrib minus_minus mult_assoc
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1544
  of_nat_0 of_nat_1 of_nat_Suc of_nat_add of_nat_mult
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1545
  of_int_0 of_int_1 of_int_add of_int_mult
f9e9e800d27e simplify theorem references
huffman
parents: 30796
diff changeset
  1546
28952
15a4b2cf8c34 made repository layout more coherent with logical distribution structure; stripped some $Id$s
haftmann
parents: 28724
diff changeset
  1547
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
  1548
declaration {* K Int_Arith.setup *}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1549
43595
7ae4a23b5be6 modernized some simproc setup;
wenzelm
parents: 43531
diff changeset
  1550
simproc_setup fast_arith ("(m::'a::{linordered_idom,number_ring}) < n" |
7ae4a23b5be6 modernized some simproc setup;
wenzelm
parents: 43531
diff changeset
  1551
  "(m::'a::{linordered_idom,number_ring}) <= n" |
7ae4a23b5be6 modernized some simproc setup;
wenzelm
parents: 43531
diff changeset
  1552
  "(m::'a::{linordered_idom,number_ring}) = n") =
7ae4a23b5be6 modernized some simproc setup;
wenzelm
parents: 43531
diff changeset
  1553
  {* fn _ => fn ss => fn ct => Lin_Arith.simproc ss (term_of ct) *}
7ae4a23b5be6 modernized some simproc setup;
wenzelm
parents: 43531
diff changeset
  1554
31024
0fdf666e08bf reimplement reorientation simproc using theory data
huffman
parents: 31021
diff changeset
  1555
setup {*
33523
96730ad673be modernized structure Reorient_Proc;
wenzelm
parents: 33364
diff changeset
  1556
  Reorient_Proc.add
31065
d87465cbfc9e moved int_factor_simprocs.ML to theory Int
haftmann
parents: 31024
diff changeset
  1557
    (fn Const (@{const_name number_of}, _) $ _ => true | _ => false)
31024
0fdf666e08bf reimplement reorientation simproc using theory data
huffman
parents: 31021
diff changeset
  1558
*}
0fdf666e08bf reimplement reorientation simproc using theory data
huffman
parents: 31021
diff changeset
  1559
33523
96730ad673be modernized structure Reorient_Proc;
wenzelm
parents: 33364
diff changeset
  1560
simproc_setup reorient_numeral ("number_of w = x") = Reorient_Proc.proc
31024
0fdf666e08bf reimplement reorientation simproc using theory data
huffman
parents: 31021
diff changeset
  1561
25919
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
subsection{*Lemmas About Small Numerals*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1564
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1565
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
  1566
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1567
  have "(of_int -1 :: 'a) = of_int (- 1)" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1568
  also have "... = - of_int 1" by (simp only: of_int_minus)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1569
  also have "... = -1" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1570
  finally show ?thesis .
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1571
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1572
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1573
lemma abs_minus_one [simp]: "abs (-1) = (1::'a::{linordered_idom,number_ring})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1574
by (simp add: abs_if)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1575
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1576
lemma abs_power_minus_one [simp]:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1577
  "abs(-1 ^ n) = (1::'a::{linordered_idom,number_ring})"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1578
by (simp add: power_abs)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1579
30000
453077188eac declare of_int_number_of_eq [simp]
huffman
parents: 29955
diff changeset
  1580
lemma of_int_number_of_eq [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1581
     "of_int (number_of v) = (number_of v :: 'a :: number_ring)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1582
by (simp add: number_of_eq) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1583
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1584
text{*Lemmas for specialist use, NOT as default simprules*}
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1585
(* TODO: see if semiring duplication can be removed without breaking proofs *)
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1586
lemma semiring_mult_2: "2 * z = (z+z::'a::number_semiring)"
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1587
unfolding semiring_one_add_one_is_two [symmetric] left_distrib by simp
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1588
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1589
lemma semiring_mult_2_right: "z * 2 = (z+z::'a::number_semiring)"
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1590
by (subst mult_commute, rule semiring_mult_2)
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1591
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1592
lemma mult_2: "2 * z = (z+z::'a::number_ring)"
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1593
by (rule semiring_mult_2)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1594
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1595
lemma mult_2_right: "z * 2 = (z+z::'a::number_ring)"
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 42676
diff changeset
  1596
by (rule semiring_mult_2_right)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1597
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1598
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1599
subsection{*More Inequality Reasoning*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1600
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1601
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
  1602
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1603
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1604
lemma add1_zle_eq: "(w + (1::int) \<le> z) = (w<z)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1605
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1606
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1607
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
  1608
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1609
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1610
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
  1611
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1612
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1613
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
  1614
by arith
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
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  1617
subsection{*The functions @{term nat} and @{term int}*}
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1618
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1619
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
  1620
  @{term "w + - z"}*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1621
declare Zero_int_def [symmetric, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1622
declare One_int_def [symmetric, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1623
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1624
lemmas diff_int_def_symmetric = diff_int_def [symmetric, simp]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1625
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
  1626
(* FIXME: duplicates nat_zero *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1627
lemma nat_0: "nat 0 = 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1628
by (simp add: nat_eq_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1629
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1630
lemma nat_1: "nat 1 = Suc 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1631
by (subst nat_eq_iff, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1632
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1633
lemma nat_2: "nat 2 = Suc (Suc 0)"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1634
by (subst nat_eq_iff, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1635
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1636
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
  1637
apply (insert zless_nat_conj [of 1 z])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1638
apply (auto simp add: nat_1)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1639
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1640
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1641
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
  1642
      z is an integer literal.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1643
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
  1644
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1645
lemma split_nat [arith_split]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1646
  "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
  1647
  (is "?P = (?L & ?R)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1648
proof (cases "i < 0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1649
  case True thus ?thesis by auto
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1650
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1651
  case False
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1652
  have "?P = ?L"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1653
  proof
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1654
    assume ?P thus ?L using False by clarsimp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1655
  next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1656
    assume ?L thus ?P using False by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1657
  qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1658
  with False show ?thesis by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1659
qed
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
context ring_1
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1662
begin
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1663
33056
791a4655cae3 renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
blanchet
parents: 32437
diff changeset
  1664
lemma of_int_of_nat [nitpick_simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1665
  "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
  1666
proof (cases "k < 0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1667
  case True then have "0 \<le> - k" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1668
  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
  1669
  with True show ?thesis by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1670
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1671
  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
  1672
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1673
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1674
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1675
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1676
lemma nat_mult_distrib:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1677
  fixes z z' :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1678
  assumes "0 \<le> z"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1679
  shows "nat (z * z') = nat z * nat z'"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1680
proof (cases "0 \<le> z'")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1681
  case False with assms have "z * z' \<le> 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1682
    by (simp add: not_le mult_le_0_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1683
  then have "nat (z * z') = 0" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1684
  moreover from False have "nat z' = 0" by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1685
  ultimately show ?thesis by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1686
next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1687
  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
  1688
  show ?thesis
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1689
    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
  1690
      (simp only: of_nat_mult of_nat_nat [OF True]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1691
         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
  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
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
  1695
apply (rule trans)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1696
apply (rule_tac [2] nat_mult_distrib, auto)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1697
done
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
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
  1700
apply (cases "z=0 | w=0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1701
apply (auto simp add: abs_if nat_mult_distrib [symmetric] 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1702
                      nat_mult_distrib_neg [symmetric] mult_less_0_iff)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1703
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1704
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1705
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1706
subsection "Induction principles for int"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1707
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1708
text{*Well-founded segments of the integers*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1709
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1710
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1711
  int_ge_less_than  ::  "int => (int * int) set"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1712
where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1713
  "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
  1714
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1715
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
  1716
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1717
  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
  1718
    by (auto simp add: int_ge_less_than_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1719
  thus ?thesis 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1720
    by (rule wf_subset [OF wf_measure]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1721
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1722
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1723
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
  1724
by RankFinder.*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1725
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1726
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1727
  int_ge_less_than2 ::  "int => (int * int) set"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1728
where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1729
  "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
  1730
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1731
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
  1732
proof -
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1733
  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
  1734
    by (auto simp add: int_ge_less_than2_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1735
  thus ?thesis 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1736
    by (rule wf_subset [OF wf_measure]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1737
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1738
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1739
abbreviation
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1740
  int :: "nat \<Rightarrow> int"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1741
where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1742
  "int \<equiv> of_nat"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1743
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1744
(* `set:int': dummy construction *)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1745
theorem int_ge_induct [case_names base step, induct set: int]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1746
  fixes i :: int
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1747
  assumes ge: "k \<le> i" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1748
    base: "P k" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1749
    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
  1750
  shows "P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1751
proof -
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1752
  { fix n
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1753
    have "\<And>i::int. n = nat (i - k) \<Longrightarrow> k \<le> i \<Longrightarrow> P i"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1754
    proof (induct n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1755
      case 0
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1756
      hence "i = k" by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1757
      thus "P i" using base by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1758
    next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1759
      case (Suc n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1760
      then have "n = nat((i - 1) - k)" by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1761
      moreover
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1762
      have ki1: "k \<le> i - 1" using Suc.prems by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1763
      ultimately
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1764
      have "P (i - 1)" by (rule Suc.hyps)
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1765
      from step [OF ki1 this] show ?case by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1766
    qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1767
  }
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1768
  with ge show ?thesis by fast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1769
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1770
25928
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  1771
(* `set:int': dummy construction *)
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  1772
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
  1773
  assumes gr: "k < (i::int)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1774
        base: "P(k+1)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1775
        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
  1776
  shows "P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1777
apply(rule int_ge_induct[of "k + 1"])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1778
  using gr apply arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1779
 apply(rule base)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1780
apply (rule step, simp+)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1781
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1782
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1783
theorem int_le_induct [consumes 1, case_names base step]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1784
  assumes le: "i \<le> (k::int)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1785
        base: "P(k)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1786
        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
  1787
  shows "P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1788
proof -
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1789
  { fix n
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1790
    have "\<And>i::int. n = nat(k-i) \<Longrightarrow> i \<le> k \<Longrightarrow> P i"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1791
    proof (induct n)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1792
      case 0
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1793
      hence "i = k" by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1794
      thus "P i" using base by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1795
    next
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1796
      case (Suc n)
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1797
      hence "n = nat (k - (i + 1))" by arith
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1798
      moreover
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1799
      have ki1: "i + 1 \<le> k" using Suc.prems by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1800
      ultimately
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1801
      have "P (i + 1)" by(rule Suc.hyps)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1802
      from step[OF ki1 this] show ?case by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1803
    qed
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
  with le show ?thesis by fast
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1806
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1807
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1808
theorem int_less_induct [consumes 1, case_names base step]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1809
  assumes less: "(i::int) < k" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1810
        base: "P(k - 1)" and
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1811
        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
  1812
  shows "P i"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1813
apply(rule int_le_induct[of _ "k - 1"])
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1814
  using less apply arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1815
 apply(rule base)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1816
apply (rule step, simp+)
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
36811
4ab4aa5bee1c renamed former Int.int_induct to Int.int_of_nat_induct, former Presburger.int_induct to Int.int_induct: is more conservative and more natural than the intermediate solution
haftmann
parents: 36801
diff changeset
  1819
theorem int_induct [case_names base step1 step2]:
36801
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1820
  fixes k :: int
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1821
  assumes base: "P k"
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1822
    and step1: "\<And>i. k \<le> i \<Longrightarrow> P i \<Longrightarrow> P (i + 1)"
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1823
    and step2: "\<And>i. k \<ge> i \<Longrightarrow> P i \<Longrightarrow> P (i - 1)"
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1824
  shows "P i"
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1825
proof -
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1826
  have "i \<le> k \<or> i \<ge> k" by arith
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1827
  then show ?thesis
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1828
  proof
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1829
    assume "i \<ge> k"
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1830
    then show ?thesis using base
36801
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1831
      by (rule int_ge_induct) (fact step1)
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1832
  next
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1833
    assume "i \<le> k"
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1834
    then show ?thesis using base
36801
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1835
      by (rule int_le_induct) (fact step2)
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1836
  qed
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1837
qed
3560de0fe851 moved int induction lemma to theory Int as int_bidirectional_induct
haftmann
parents: 36749
diff changeset
  1838
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1839
subsection{*Intermediate value theorems*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1840
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1841
lemma int_val_lemma:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1842
     "(\<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
  1843
      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
  1844
unfolding One_nat_def
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1845
apply (induct n)
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  1846
apply simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1847
apply (intro strip)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1848
apply (erule impE, simp)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1849
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
  1850
apply (case_tac "k = f (Suc n)")
27106
ff27dc6e7d05 removed some dubious code lemmas
haftmann
parents: 26975
diff changeset
  1851
apply force
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1852
apply (erule impE)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1853
 apply (simp add: abs_if split add: split_if_asm)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1854
apply (blast intro: le_SucI)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1855
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1856
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1857
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
  1858
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1859
lemma nat_intermed_int_val:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1860
     "[| \<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
  1861
         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
  1862
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
  1863
       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
  1864
unfolding One_nat_def
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1865
apply simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1866
apply (erule exE)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1867
apply (rule_tac x = "i+m" in exI, arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1868
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1869
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1870
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1871
subsection{*Products and 1, by T. M. Rasmussen*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1872
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1873
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
  1874
by arith
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1875
34055
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1876
lemma abs_zmult_eq_1:
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1877
  assumes mn: "\<bar>m * n\<bar> = 1"
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1878
  shows "\<bar>m\<bar> = (1::int)"
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1879
proof -
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1880
  have 0: "m \<noteq> 0 & n \<noteq> 0" using mn
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1881
    by auto
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1882
  have "~ (2 \<le> \<bar>m\<bar>)"
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1883
  proof
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1884
    assume "2 \<le> \<bar>m\<bar>"
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1885
    hence "2*\<bar>n\<bar> \<le> \<bar>m\<bar>*\<bar>n\<bar>"
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1886
      by (simp add: mult_mono 0) 
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1887
    also have "... = \<bar>m*n\<bar>" 
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1888
      by (simp add: abs_mult)
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1889
    also have "... = 1"
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1890
      by (simp add: mn)
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1891
    finally have "2*\<bar>n\<bar> \<le> 1" .
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1892
    thus "False" using 0
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1893
      by auto
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1894
  qed
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1895
  thus ?thesis using 0
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1896
    by auto
fdf294ee08b2 streamlined proofs
paulson
parents: 33657
diff changeset
  1897
qed
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1898
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1899
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
  1900
by (insert abs_zmult_eq_1 [of m n], arith)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1901
35815
10e723e54076 tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents: 35634
diff changeset
  1902
lemma pos_zmult_eq_1_iff:
10e723e54076 tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents: 35634
diff changeset
  1903
  assumes "0 < (m::int)" shows "(m * n = 1) = (m = 1 & n = 1)"
10e723e54076 tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents: 35634
diff changeset
  1904
proof -
10e723e54076 tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents: 35634
diff changeset
  1905
  from assms have "m * n = 1 ==> m = 1" by (auto dest: pos_zmult_eq_1_iff_lemma)
10e723e54076 tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents: 35634
diff changeset
  1906
  thus ?thesis by (auto dest: pos_zmult_eq_1_iff_lemma)
10e723e54076 tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents: 35634
diff changeset
  1907
qed
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1908
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1909
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
  1910
apply (rule iffI) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1911
 apply (frule pos_zmult_eq_1_iff_lemma)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1912
 apply (simp add: mult_commute [of m]) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1913
 apply (frule pos_zmult_eq_1_iff_lemma, auto) 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1914
done
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1915
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1916
lemma infinite_UNIV_int: "\<not> finite (UNIV::int set)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1917
proof
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1918
  assume "finite (UNIV::int set)"
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1919
  moreover have "inj (\<lambda>i\<Colon>int. 2 * i)"
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1920
    by (rule injI) simp
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1921
  ultimately have "surj (\<lambda>i\<Colon>int. 2 * i)"
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1922
    by (rule finite_UNIV_inj_surj)
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1923
  then obtain i :: int where "1 = 2 * i" by (rule surjE)
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 33056
diff changeset
  1924
  then show False by (simp add: pos_zmult_eq_1_iff)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1925
qed
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1926
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  1927
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1928
subsection {* Further theorems on numerals *}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1929
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1930
subsubsection{*Special Simplification for Constants*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1931
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1932
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
  1933
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1934
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
  1935
  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
  1936
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1937
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
  1938
  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
  1939
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1940
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
  1941
  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
  1942
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1943
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
  1944
  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
  1945
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1946
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
  1947
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1948
lemmas zero_less_divide_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1949
  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
  1950
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1951
lemmas divide_less_0_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1952
  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
  1953
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1954
lemmas zero_le_divide_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1955
  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
  1956
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1957
lemmas divide_le_0_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1958
  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
  1959
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1960
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1961
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
  1962
  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
  1963
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1964
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
  1965
  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
  1966
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1967
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
  1968
into the literal.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1969
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1970
lemmas less_minus_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1971
  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
  1972
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1973
lemmas le_minus_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1974
  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
  1975
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1976
lemmas equation_minus_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1977
  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
  1978
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1979
lemmas minus_less_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1980
  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
  1981
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1982
lemmas minus_le_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1983
  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
  1984
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1985
lemmas minus_equation_iff_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1986
  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
  1987
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
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
  1990
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1991
lemma less_minus_iff_1 [simp,no_atp]:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1992
  fixes b::"'b::{linordered_idom,number_ring}"
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1993
  shows "(1 < - b) = (b < -1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1994
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1995
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  1996
lemma le_minus_iff_1 [simp,no_atp]:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  1997
  fixes b::"'b::{linordered_idom,number_ring}"
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  1998
  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
  1999
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2000
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  2001
lemma equation_minus_iff_1 [simp,no_atp]:
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2002
  fixes b::"'b::number_ring"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2003
  shows "(1 = - b) = (b = -1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2004
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
  2005
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  2006
lemma minus_less_iff_1 [simp,no_atp]:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  2007
  fixes a::"'b::{linordered_idom,number_ring}"
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2008
  shows "(- a < 1) = (-1 < a)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2009
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2010
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  2011
lemma minus_le_iff_1 [simp,no_atp]:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34055
diff changeset
  2012
  fixes a::"'b::{linordered_idom,number_ring}"
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2013
  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
  2014
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2015
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  2016
lemma minus_equation_iff_1 [simp,no_atp]:
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2017
  fixes a::"'b::number_ring"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2018
  shows "(- a = 1) = (a = -1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2019
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
  2020
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2021
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2022
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
  2023
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  2024
lemmas mult_less_cancel_left_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2025
  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
  2026
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  2027
lemmas mult_less_cancel_right_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2028
  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
  2029
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  2030
lemmas mult_le_cancel_left_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2031
  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
  2032
35828
46cfc4b8112e now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents: 35634
diff changeset
  2033
lemmas mult_le_cancel_right_number_of [simp, no_atp] =
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2034
  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
  2035
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2036
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2037
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
  2038
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2039
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
  2040
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
  2041
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
  2042
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
  2043
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
  2044
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
  2045
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2046
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2047
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
  2048
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2049
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
  2050
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2051
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
  2052
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
  2053
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
  2054
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
  2055
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
  2056
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
  2057
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2058
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2059
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
  2060
lemmas divide_const_simps =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2061
  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
  2062
  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
  2063
  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
  2064
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2065
text{*Division By @{text "-1"}*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2066
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2067
lemma divide_minus1 [simp]:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
  2068
     "x/-1 = -(x::'a::{field_inverse_zero, number_ring})"
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2069
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2070
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2071
lemma minus1_divide [simp]:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
  2072
     "-1 / (x::'a::{field_inverse_zero, number_ring}) = - (1/x)"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35123
diff changeset
  2073
by (simp add: divide_inverse)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2074
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2075
lemma half_gt_zero_iff:
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36349
diff changeset
  2076
     "(0 < r/2) = (0 < (r::'a::{linordered_field_inverse_zero,number_ring}))"
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2077
by auto
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2078
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2079
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
  2080
36719
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
  2081
lemma divide_Numeral1:
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
  2082
  "(x::'a::{field, number_ring}) / Numeral1 = x"
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
  2083
  by simp
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
  2084
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
  2085
lemma divide_Numeral0:
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
  2086
  "(x::'a::{field_inverse_zero, number_ring}) / Numeral0 = 0"
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
  2087
  by simp
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
  2088
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30496
diff changeset
  2089
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2090
subsection {* The divides relation *}
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2091
33657
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2092
lemma zdvd_antisym_nonneg:
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2093
    "0 <= m ==> 0 <= n ==> m dvd n ==> n dvd m ==> m = (n::int)"
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2094
  apply (simp add: dvd_def, auto)
33657
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2095
  apply (auto simp add: mult_assoc zero_le_mult_iff zmult_eq_1_iff)
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2096
  done
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2097
33657
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2098
lemma zdvd_antisym_abs: assumes "(a::int) dvd b" and "b dvd a" 
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2099
  shows "\<bar>a\<bar> = \<bar>b\<bar>"
33657
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2100
proof cases
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2101
  assume "a = 0" with assms show ?thesis by simp
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2102
next
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2103
  assume "a \<noteq> 0"
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2104
  from `a dvd b` obtain k where k:"b = a*k" unfolding dvd_def by blast 
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2105
  from `b dvd a` obtain k' where k':"a = b*k'" unfolding dvd_def by blast 
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2106
  from k k' have "a = a*k*k'" by simp
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2107
  with mult_cancel_left1[where c="a" and b="k*k'"]
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2108
  have kk':"k*k' = 1" using `a\<noteq>0` by (simp add: mult_assoc)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2109
  hence "k = 1 \<and> k' = 1 \<or> k = -1 \<and> k' = -1" by (simp add: zmult_eq_1_iff)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2110
  thus ?thesis using k k' by auto
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2111
qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2112
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2113
lemma zdvd_zdiffD: "k dvd m - n ==> k dvd n ==> k dvd (m::int)"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2114
  apply (subgoal_tac "m = n + (m - n)")
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2115
   apply (erule ssubst)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2116
   apply (blast intro: dvd_add, simp)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2117
  done
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2118
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2119
lemma zdvd_reduce: "(k dvd n + k * m) = (k dvd (n::int))"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2120
apply (rule iffI)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2121
 apply (erule_tac [2] dvd_add)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2122
 apply (subgoal_tac "n = (n + k * m) - k * m")
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2123
  apply (erule ssubst)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2124
  apply (erule dvd_diff)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2125
  apply(simp_all)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2126
done
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2127
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2128
lemma dvd_imp_le_int:
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2129
  fixes d i :: int
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2130
  assumes "i \<noteq> 0" and "d dvd i"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2131
  shows "\<bar>d\<bar> \<le> \<bar>i\<bar>"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2132
proof -
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2133
  from `d dvd i` obtain k where "i = d * k" ..
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2134
  with `i \<noteq> 0` have "k \<noteq> 0" by auto
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2135
  then have "1 \<le> \<bar>k\<bar>" and "0 \<le> \<bar>d\<bar>" by auto
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2136
  then have "\<bar>d\<bar> * 1 \<le> \<bar>d\<bar> * \<bar>k\<bar>" by (rule mult_left_mono)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2137
  with `i = d * k` show ?thesis by (simp add: abs_mult)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2138
qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2139
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2140
lemma zdvd_not_zless:
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2141
  fixes m n :: int
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2142
  assumes "0 < m" and "m < n"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2143
  shows "\<not> n dvd m"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2144
proof
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2145
  from assms have "0 < n" by auto
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2146
  assume "n dvd m" then obtain k where k: "m = n * k" ..
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2147
  with `0 < m` have "0 < n * k" by auto
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2148
  with `0 < n` have "0 < k" by (simp add: zero_less_mult_iff)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2149
  with k `0 < n` `m < n` have "n * k < n * 1" by simp
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2150
  with `0 < n` `0 < k` show False unfolding mult_less_cancel_left by auto
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2151
qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2152
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2153
lemma zdvd_mult_cancel: assumes d:"k * m dvd k * n" and kz:"k \<noteq> (0::int)"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2154
  shows "m dvd n"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2155
proof-
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2156
  from d obtain h where h: "k*n = k*m * h" unfolding dvd_def by blast
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2157
  {assume "n \<noteq> m*h" hence "k* n \<noteq> k* (m*h)" using kz by simp
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2158
    with h have False by (simp add: mult_assoc)}
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2159
  hence "n = m * h" by blast
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2160
  thus ?thesis by simp
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2161
qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2162
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2163
theorem zdvd_int: "(x dvd y) = (int x dvd int y)"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2164
proof -
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2165
  have "\<And>k. int y = int x * k \<Longrightarrow> x dvd y"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2166
  proof -
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2167
    fix k
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2168
    assume A: "int y = int x * k"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2169
    then show "x dvd y"
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2170
    proof (cases k)
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2171
      case (nonneg n)
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2172
      with A have "y = x * n" by (simp add: of_nat_mult [symmetric])
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2173
      then show ?thesis ..
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2174
    next
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2175
      case (neg n)
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2176
      with A have "int y = int x * (- int (Suc n))" by simp
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2177
      also have "\<dots> = - (int x * int (Suc n))" by (simp only: mult_minus_right)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2178
      also have "\<dots> = - int (x * Suc n)" by (simp only: of_nat_mult [symmetric])
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2179
      finally have "- int (x * Suc n) = int y" ..
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2180
      then show ?thesis by (simp only: negative_eq_positive) auto
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2181
    qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2182
  qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2183
  then show ?thesis by (auto elim!: dvdE simp only: dvd_triv_left of_nat_mult)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2184
qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2185
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2186
lemma zdvd1_eq[simp]: "(x::int) dvd 1 = (\<bar>x\<bar> = 1)"
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2187
proof
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2188
  assume d: "x dvd 1" hence "int (nat \<bar>x\<bar>) dvd int (nat 1)" by simp
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2189
  hence "nat \<bar>x\<bar> dvd 1" by (simp add: zdvd_int)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2190
  hence "nat \<bar>x\<bar> = 1"  by simp
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2191
  thus "\<bar>x\<bar> = 1" by (cases "x < 0") auto
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2192
next
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2193
  assume "\<bar>x\<bar>=1"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2194
  then have "x = 1 \<or> x = -1" by auto
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2195
  then show "x dvd 1" by (auto intro: dvdI)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2196
qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2197
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2198
lemma zdvd_mult_cancel1: 
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2199
  assumes mp:"m \<noteq>(0::int)" shows "(m * n dvd m) = (\<bar>n\<bar> = 1)"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2200
proof
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2201
  assume n1: "\<bar>n\<bar> = 1" thus "m * n dvd m" 
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2202
    by (cases "n >0") (auto simp add: minus_equation_iff)
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2203
next
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2204
  assume H: "m * n dvd m" hence H2: "m * n dvd m * 1" by simp
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2205
  from zdvd_mult_cancel[OF H2 mp] show "\<bar>n\<bar> = 1" by (simp only: zdvd1_eq)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2206
qed
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2207
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2208
lemma int_dvd_iff: "(int m dvd z) = (m dvd nat (abs z))"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2209
  unfolding zdvd_int by (cases "z \<ge> 0") simp_all
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2210
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2211
lemma dvd_int_iff: "(z dvd int m) = (nat (abs z) dvd m)"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2212
  unfolding zdvd_int by (cases "z \<ge> 0") simp_all
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2213
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2214
lemma nat_dvd_iff: "(nat z dvd m) = (if 0 \<le> z then (z dvd int m) else m = 0)"
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2215
  by (auto simp add: dvd_int_iff)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2216
33341
5a989586d102 moved some dvd [int] facts to Int
haftmann
parents: 33320
diff changeset
  2217
lemma eq_nat_nat_iff:
5a989586d102 moved some dvd [int] facts to Int
haftmann
parents: 33320
diff changeset
  2218
  "0 \<le> z \<Longrightarrow> 0 \<le> z' \<Longrightarrow> nat z = nat z' \<longleftrightarrow> z = z'"
5a989586d102 moved some dvd [int] facts to Int
haftmann
parents: 33320
diff changeset
  2219
  by (auto elim!: nonneg_eq_int)
5a989586d102 moved some dvd [int] facts to Int
haftmann
parents: 33320
diff changeset
  2220
5a989586d102 moved some dvd [int] facts to Int
haftmann
parents: 33320
diff changeset
  2221
lemma nat_power_eq:
5a989586d102 moved some dvd [int] facts to Int
haftmann
parents: 33320
diff changeset
  2222
  "0 \<le> z \<Longrightarrow> nat (z ^ n) = nat z ^ n"
5a989586d102 moved some dvd [int] facts to Int
haftmann
parents: 33320
diff changeset
  2223
  by (induct n) (simp_all add: nat_mult_distrib)
5a989586d102 moved some dvd [int] facts to Int
haftmann
parents: 33320
diff changeset
  2224
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2225
lemma zdvd_imp_le: "[| z dvd n; 0 < n |] ==> z \<le> (n::int)"
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2226
  apply (cases n)
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2227
  apply (auto simp add: dvd_int_iff)
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2228
  apply (cases z)
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2229
  apply (auto simp add: dvd_imp_le)
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2230
  done
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2231
36749
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2232
lemma zdvd_period:
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2233
  fixes a d :: int
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2234
  assumes "a dvd d"
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2235
  shows "a dvd (x + t) \<longleftrightarrow> a dvd ((x + c * d) + t)"
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2236
proof -
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2237
  from assms obtain k where "d = a * k" by (rule dvdE)
42676
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2238
  show ?thesis
8724f20bf69c proper case_names for int_cases, int_of_nat_induct;
wenzelm
parents: 42411
diff changeset
  2239
  proof
36749
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2240
    assume "a dvd (x + t)"
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2241
    then obtain l where "x + t = a * l" by (rule dvdE)
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2242
    then have "x = a * l - t" by simp
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2243
    with `d = a * k` show "a dvd x + c * d + t" by simp
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2244
  next
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2245
    assume "a dvd x + c * d + t"
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2246
    then obtain l where "x + c * d + t = a * l" by (rule dvdE)
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2247
    then have "x = a * l - c * d - t" by simp
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2248
    with `d = a * k` show "a dvd (x + t)" by simp
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2249
  qed
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2250
qed
a8dc19a352e6 moved lemma zdvd_period to theory Int
haftmann
parents: 36719
diff changeset
  2251
33320
73998ef6ea91 moved some dvd [int] facts to Int
haftmann
parents: 33296
diff changeset
  2252
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2253
subsection {* Configuration of the code generator *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2254
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2255
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
  2256
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2257
lemmas pred_succ_numeral_code [code] =
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2258
  pred_bin_simps succ_bin_simps
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2259
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2260
lemmas plus_numeral_code [code] =
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2261
  add_bin_simps
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2262
  arith_extra_simps(1) [where 'a = int]
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2263
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2264
lemmas minus_numeral_code [code] =
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2265
  minus_bin_simps
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2266
  arith_extra_simps(2) [where 'a = int]
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2267
  arith_extra_simps(5) [where 'a = int]
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2268
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2269
lemmas times_numeral_code [code] =
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2270
  mult_bin_simps
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2271
  arith_extra_simps(4) [where 'a = int]
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2272
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2273
instantiation int :: equal
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2274
begin
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2275
37767
a2b7a20d6ea3 dropped superfluous [code del]s
haftmann
parents: 36811
diff changeset
  2276
definition
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2277
  "HOL.equal k l \<longleftrightarrow> k - l = (0\<Colon>int)"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2278
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2279
instance by default (simp add: equal_int_def)
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2280
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2281
end
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2282
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2283
lemma eq_number_of_int_code [code]:
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2284
  "HOL.equal (number_of k \<Colon> int) (number_of l) \<longleftrightarrow> HOL.equal k l"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2285
  unfolding equal_int_def number_of_is_id ..
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2286
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2287
lemma eq_int_code [code]:
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2288
  "HOL.equal Int.Pls Int.Pls \<longleftrightarrow> True"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2289
  "HOL.equal Int.Pls Int.Min \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2290
  "HOL.equal Int.Pls (Int.Bit0 k2) \<longleftrightarrow> HOL.equal Int.Pls k2"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2291
  "HOL.equal Int.Pls (Int.Bit1 k2) \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2292
  "HOL.equal Int.Min Int.Pls \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2293
  "HOL.equal Int.Min Int.Min \<longleftrightarrow> True"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2294
  "HOL.equal Int.Min (Int.Bit0 k2) \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2295
  "HOL.equal Int.Min (Int.Bit1 k2) \<longleftrightarrow> HOL.equal Int.Min k2"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2296
  "HOL.equal (Int.Bit0 k1) Int.Pls \<longleftrightarrow> HOL.equal k1 Int.Pls"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2297
  "HOL.equal (Int.Bit1 k1) Int.Pls \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2298
  "HOL.equal (Int.Bit0 k1) Int.Min \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2299
  "HOL.equal (Int.Bit1 k1) Int.Min \<longleftrightarrow> HOL.equal k1 Int.Min"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2300
  "HOL.equal (Int.Bit0 k1) (Int.Bit0 k2) \<longleftrightarrow> HOL.equal k1 k2"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2301
  "HOL.equal (Int.Bit0 k1) (Int.Bit1 k2) \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2302
  "HOL.equal (Int.Bit1 k1) (Int.Bit0 k2) \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2303
  "HOL.equal (Int.Bit1 k1) (Int.Bit1 k2) \<longleftrightarrow> HOL.equal k1 k2"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2304
  unfolding equal_eq by simp_all
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2305
28351
abfc66969d1f non left-linear equations for nbe
haftmann
parents: 27682
diff changeset
  2306
lemma eq_int_refl [code nbe]:
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2307
  "HOL.equal (k::int) k \<longleftrightarrow> True"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37887
diff changeset
  2308
  by (rule equal_refl)
28351
abfc66969d1f non left-linear equations for nbe
haftmann
parents: 27682
diff changeset
  2309
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2310
lemma less_eq_number_of_int_code [code]:
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2311
  "(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
  2312
  unfolding number_of_is_id ..
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2313
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2314
lemma less_eq_int_code [code]:
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2315
  "Int.Pls \<le> Int.Pls \<longleftrightarrow> True"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2316
  "Int.Pls \<le> Int.Min \<longleftrightarrow> False"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2317
  "Int.Pls \<le> Int.Bit0 k \<longleftrightarrow> Int.Pls \<le> k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2318
  "Int.Pls \<le> Int.Bit1 k \<longleftrightarrow> Int.Pls \<le> k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2319
  "Int.Min \<le> Int.Pls \<longleftrightarrow> True"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2320
  "Int.Min \<le> Int.Min \<longleftrightarrow> True"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2321
  "Int.Min \<le> Int.Bit0 k \<longleftrightarrow> Int.Min < k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2322
  "Int.Min \<le> Int.Bit1 k \<longleftrightarrow> Int.Min \<le> k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2323
  "Int.Bit0 k \<le> Int.Pls \<longleftrightarrow> k \<le> Int.Pls"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2324
  "Int.Bit1 k \<le> Int.Pls \<longleftrightarrow> k < Int.Pls"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2325
  "Int.Bit0 k \<le> Int.Min \<longleftrightarrow> k \<le> Int.Min"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2326
  "Int.Bit1 k \<le> Int.Min \<longleftrightarrow> k \<le> Int.Min"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2327
  "Int.Bit0 k1 \<le> Int.Bit0 k2 \<longleftrightarrow> k1 \<le> k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2328
  "Int.Bit0 k1 \<le> Int.Bit1 k2 \<longleftrightarrow> k1 \<le> k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2329
  "Int.Bit1 k1 \<le> Int.Bit0 k2 \<longleftrightarrow> k1 < k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2330
  "Int.Bit1 k1 \<le> Int.Bit1 k2 \<longleftrightarrow> k1 \<le> k2"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  2331
  by simp_all
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2332
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2333
lemma less_number_of_int_code [code]:
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2334
  "(number_of k \<Colon> int) < number_of l \<longleftrightarrow> k < l"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2335
  unfolding number_of_is_id ..
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2336
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28537
diff changeset
  2337
lemma less_int_code [code]:
26507
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2338
  "Int.Pls < Int.Pls \<longleftrightarrow> False"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2339
  "Int.Pls < Int.Min \<longleftrightarrow> False"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2340
  "Int.Pls < Int.Bit0 k \<longleftrightarrow> Int.Pls < k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2341
  "Int.Pls < Int.Bit1 k \<longleftrightarrow> Int.Pls \<le> k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2342
  "Int.Min < Int.Pls \<longleftrightarrow> True"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2343
  "Int.Min < Int.Min \<longleftrightarrow> False"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2344
  "Int.Min < Int.Bit0 k \<longleftrightarrow> Int.Min < k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2345
  "Int.Min < Int.Bit1 k \<longleftrightarrow> Int.Min < k"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2346
  "Int.Bit0 k < Int.Pls \<longleftrightarrow> k < Int.Pls"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2347
  "Int.Bit1 k < Int.Pls \<longleftrightarrow> k < Int.Pls"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2348
  "Int.Bit0 k < Int.Min \<longleftrightarrow> k \<le> Int.Min"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2349
  "Int.Bit1 k < Int.Min \<longleftrightarrow> k < Int.Min"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2350
  "Int.Bit0 k1 < Int.Bit0 k2 \<longleftrightarrow> k1 < k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2351
  "Int.Bit0 k1 < Int.Bit1 k2 \<longleftrightarrow> k1 \<le> k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2352
  "Int.Bit1 k1 < Int.Bit0 k2 \<longleftrightarrow> k1 < k2"
6da615cef733 moved some code lemmas for Numerals here
haftmann
parents: 26300
diff changeset
  2353
  "Int.Bit1 k1 < Int.Bit1 k2 \<longleftrightarrow> k1 < k2"
28958
74c60b78969c cleaned up subsection headings;
huffman
parents: 28952
diff changeset
  2354
  by simp_all
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2355
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2356
definition
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2357
  nat_aux :: "int \<Rightarrow> nat \<Rightarrow> nat" where
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2358
  "nat_aux i n = nat i + n"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2359
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2360
lemma [code]:
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2361
  "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
  2362
  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
  2363
    dest: zless_imp_add1_zle)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2364
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2365
lemma [code]: "nat i = nat_aux i 0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2366
  by (simp add: nat_aux_def)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2367
36176
3fe7e97ccca8 replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents: 36076
diff changeset
  2368
hide_const (open) nat_aux
25928
042e877d9841 tuned code setup
haftmann
parents: 25919
diff changeset
  2369
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
  2370
lemma zero_is_num_zero [code, code_unfold_post]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2371
  "(0\<Colon>int) = Numeral0" 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2372
  by simp
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2373
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
  2374
lemma one_is_num_one [code, code_unfold_post]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2375
  "(1\<Colon>int) = Numeral1" 
25961
ec39d7e40554 moved definition of power on ints to theory Int
haftmann
parents: 25928
diff changeset
  2376
  by simp
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2377
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2378
code_modulename SML
33364
2bd12592c5e8 tuned code setup
haftmann
parents: 33341
diff changeset
  2379
  Int Arith
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2380
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2381
code_modulename OCaml
33364
2bd12592c5e8 tuned code setup
haftmann
parents: 33341
diff changeset
  2382
  Int Arith
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2383
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2384
code_modulename Haskell
33364
2bd12592c5e8 tuned code setup
haftmann
parents: 33341
diff changeset
  2385
  Int Arith
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2386
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2387
types_code
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2388
  "int" ("int")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2389
attach (term_of) {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2390
val term_of_int = HOLogic.mk_number HOLogic.intT;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2391
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2392
attach (test) {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2393
fun gen_int i =
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2394
  let val j = one_of [~1, 1] * random_range 0 i
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2395
  in (j, fn () => term_of_int j) end;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2396
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2397
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2398
setup {*
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2399
let
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2400
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2401
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
  2402
  | strip_number_of t = t;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2403
42411
ff997038e8eb eliminated Codegen.mode in favour of explicit argument;
wenzelm
parents: 41959
diff changeset
  2404
fun numeral_codegen thy mode defs dep module b t gr =
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2405
  let val i = HOLogic.dest_numeral (strip_number_of t)
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2406
  in
28537
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28514
diff changeset
  2407
    SOME (Codegen.str (string_of_int i),
42411
ff997038e8eb eliminated Codegen.mode in favour of explicit argument;
wenzelm
parents: 41959
diff changeset
  2408
      snd (Codegen.invoke_tycodegen thy mode defs dep module false HOLogic.intT gr))
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2409
  end handle TERM _ => NONE;
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2410
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2411
in
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2412
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2413
Codegen.add_codegen "numeral_codegen" numeral_codegen
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2414
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2415
end
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2416
*}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2417
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2418
consts_code
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2419
  "number_of :: int \<Rightarrow> int"    ("(_)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2420
  "0 :: int"                   ("0")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2421
  "1 :: int"                   ("1")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2422
  "uminus :: int => int"       ("~")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2423
  "op + :: int => int => int"  ("(_ +/ _)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2424
  "op * :: int => int => int"  ("(_ */ _)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2425
  "op \<le> :: int => int => bool" ("(_ <=/ _)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2426
  "op < :: int => int => bool" ("(_ </ _)")
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2427
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2428
quickcheck_params [default_type = int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2429
36176
3fe7e97ccca8 replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents: 36076
diff changeset
  2430
hide_const (open) Pls Min Bit0 Bit1 succ pred
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2431
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2432
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2433
subsection {* Legacy theorems *}
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2434
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2435
lemmas zminus_zminus = minus_minus [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2436
lemmas zminus_0 = minus_zero [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2437
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
  2438
lemmas zadd_commute = add_commute [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2439
lemmas zadd_assoc = add_assoc [of "z1::int" "z2" "z3", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2440
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
  2441
lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute
35050
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35032
diff changeset
  2442
lemmas zmult_ac = mult_ac
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35032
diff changeset
  2443
lemmas zadd_0 = add_0_left [of "z::int", standard]
9f841f20dca6 renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents: 35032
diff changeset
  2444
lemmas zadd_0_right = add_0_right [of "z::int", standard]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2445
lemmas zadd_zminus_inverse2 = left_minus [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2446
lemmas zmult_zminus = mult_minus_left [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2447
lemmas zmult_commute = mult_commute [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2448
lemmas zmult_assoc = mult_assoc [of "z1::int" "z2" "z3", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2449
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
  2450
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
  2451
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
  2452
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
  2453
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2454
lemmas zmult_1 = mult_1_left [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2455
lemmas zmult_1_right = mult_1_right [of "z::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2456
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2457
lemmas zle_refl = order_refl [of "w::int", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2458
lemmas zle_trans = order_trans [where 'a=int and x="i" and y="j" and z="k", standard]
33657
a4179bf442d1 renamed lemmas "anti_sym" -> "antisym"
nipkow
parents: 33523
diff changeset
  2459
lemmas zle_antisym = order_antisym [of "z::int" "w", standard]
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2460
lemmas zle_linear = linorder_linear [of "z::int" "w", standard]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2461
lemmas zless_linear = linorder_less_linear [where 'a = int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2462
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2463
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
  2464
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
  2465
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
  2466
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2467
lemmas int_0_less_1 = zero_less_one [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2468
lemmas int_0_neq_1 = zero_neq_one [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2469
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2470
lemmas inj_int = inj_of_nat [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2471
lemmas zadd_int = of_nat_add [where 'a=int, symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2472
lemmas int_mult = of_nat_mult [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2473
lemmas zmult_int = of_nat_mult [where 'a=int, symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2474
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
  2475
lemmas zless_int = of_nat_less_iff [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2476
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
  2477
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
  2478
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
  2479
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
  2480
lemmas int_0 = of_nat_0 [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2481
lemmas int_1 = of_nat_1 [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2482
lemmas int_Suc = of_nat_Suc [where 'a=int]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2483
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
  2484
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
  2485
lemmas zdiff_int = of_nat_diff [where 'a=int, symmetric]
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2486
lemmas zless_le = less_int_def
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2487
lemmas int_eq_of_nat = TrueI
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2488
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2489
lemma zpower_zadd_distrib:
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2490
  "x ^ (y + z) = ((x ^ y) * (x ^ z)::int)"
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2491
  by (rule power_add)
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2492
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2493
lemma zero_less_zpower_abs_iff:
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2494
  "(0 < abs x ^ n) \<longleftrightarrow> (x \<noteq> (0::int) | n = 0)"
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2495
  by (rule zero_less_power_abs_iff)
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2496
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2497
lemma zero_le_zpower_abs: "(0::int) \<le> abs x ^ n"
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2498
  by (rule zero_le_power_abs)
fec1a04b7220 power operation defined generic
haftmann
parents: 30843
diff changeset
  2499
31015
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2500
lemma zpower_zpower:
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2501
  "(x ^ y) ^ z = (x ^ (y * z)::int)"
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2502
  by (rule power_mult [symmetric])
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2503
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2504
lemma int_power:
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2505
  "int (m ^ n) = int m ^ n"
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2506
  by (rule of_nat_power)
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2507
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2508
lemmas zpower_int = int_power [symmetric]
555f4033cd97 reorganization of power lemmas
haftmann
parents: 31010
diff changeset
  2509
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
diff changeset
  2510
end