src/HOL/Integ/IntDiv.thy
author paulson
Tue, 28 May 2002 11:06:06 +0200
changeset 13183 c7290200b3f4
parent 11868 56db9f3a6b3e
child 13260 ea36a40c004f
permissions -rw-r--r--
conversion of IntDiv.thy to Isar format
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
     1
(*  Title:      HOL/IntDiv.thy
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
     2
    ID:         $Id$
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
     4
    Copyright   1999  University of Cambridge
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
     5
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
     6
The division operators div, mod and the divides relation "dvd"
13183
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
     7
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
     8
Here is the division algorithm in ML:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
     9
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    10
    fun posDivAlg (a,b) =
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    11
      if a<b then (0,a)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    12
      else let val (q,r) = posDivAlg(a, 2*b)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    13
	       in  if 0<=r-b then (2*q+1, r-b) else (2*q, r)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    14
	   end
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    15
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    16
    fun negDivAlg (a,b) =
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    17
      if 0<=a+b then (~1,a+b)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    18
      else let val (q,r) = negDivAlg(a, 2*b)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    19
	       in  if 0<=r-b then (2*q+1, r-b) else (2*q, r)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    20
	   end;
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    21
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    22
    fun negateSnd (q,r:int) = (q,~r);
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    23
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    24
    fun divAlg (a,b) = if 0<=a then 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    25
			  if b>0 then posDivAlg (a,b) 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    26
			   else if a=0 then (0,0)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    27
				else negateSnd (negDivAlg (~a,~b))
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    28
		       else 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    29
			  if 0<b then negDivAlg (a,b)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    30
			  else        negateSnd (posDivAlg (~a,~b));
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    31
*)
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    32
13183
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    33
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    34
theory IntDiv = IntArith + Recdef:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    35
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    36
declare zless_nat_conj [simp]
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    37
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    38
constdefs
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    39
  quorem :: "(int*int) * (int*int) => bool"
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    40
    "quorem == %((a,b), (q,r)).
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    41
                      a = b*q + r &
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    42
                      (if 0 < b then 0<=r & r<b else b<r & r <= 0)"
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    43
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    44
  adjust :: "[int, int*int] => int*int"
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    45
    "adjust b == %(q,r). if 0 <= r-b then (2*q + 1, r-b)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    46
                         else (2*q, r)"
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    47
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    48
(** the division algorithm **)
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    49
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    50
(*for the case a>=0, b>0*)
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    51
consts posDivAlg :: "int*int => int*int"
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    52
recdef posDivAlg "inv_image less_than (%(a,b). nat(a - b + 1))"
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    53
    "posDivAlg (a,b) =
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    54
       (if (a<b | b<=0) then (0,a)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    55
        else adjust b (posDivAlg(a, 2*b)))"
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    56
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    57
(*for the case a<0, b>0*)
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    58
consts negDivAlg :: "int*int => int*int"
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    59
recdef negDivAlg "inv_image less_than (%(a,b). nat(- a - b))"
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    60
    "negDivAlg (a,b) =
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    61
       (if (0<=a+b | b<=0) then (-1,a+b)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    62
        else adjust b (negDivAlg(a, 2*b)))"
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    63
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    64
(*for the general case b~=0*)
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    65
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    66
constdefs
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    67
  negateSnd :: "int*int => int*int"
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    68
    "negateSnd == %(q,r). (q,-r)"
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    69
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    70
  (*The full division algorithm considers all possible signs for a, b
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    71
    including the special case a=0, b<0, because negDivAlg requires a<0*)
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    72
  divAlg :: "int*int => int*int"
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    73
    "divAlg ==
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    74
       %(a,b). if 0<=a then
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    75
                  if 0<=b then posDivAlg (a,b)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    76
                  else if a=0 then (0,0)
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    77
                       else negateSnd (negDivAlg (-a,-b))
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    78
               else 
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    79
                  if 0<b then negDivAlg (a,b)
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    80
                  else         negateSnd (posDivAlg (-a,-b))"
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    81
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    82
instance
13183
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    83
  int :: "Divides.div" ..       (*avoid clash with 'div' token*)
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    84
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
    85
defs
13183
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    86
  div_def:   "a div b == fst (divAlg (a,b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    87
  mod_def:   "a mod b == snd (divAlg (a,b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    88
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    89
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    90
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    91
(*** Uniqueness and monotonicity of quotients and remainders ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    92
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    93
lemma unique_quotient_lemma:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    94
     "[| b*q' + r'  <= b*q + r;  0 <= r';  0 < b;  r < b |]  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    95
      ==> q' <= (q::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    96
apply (subgoal_tac "r' + b * (q'-q) <= r")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    97
 prefer 2 apply (simp add: zdiff_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    98
apply (subgoal_tac "0 < b * (1 + q - q') ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
    99
apply (erule_tac [2] order_le_less_trans)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   100
 prefer 2 apply (simp add: zdiff_zmult_distrib2 zadd_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   101
apply (subgoal_tac "b * q' < b * (1 + q) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   102
 prefer 2 apply (simp add: zdiff_zmult_distrib2 zadd_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   103
apply (simp add: zmult_zless_cancel1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   104
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   105
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   106
lemma unique_quotient_lemma_neg:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   107
     "[| b*q' + r' <= b*q + r;  r <= 0;  b < 0;  b < r' |]  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   108
      ==> q <= (q'::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   109
by (rule_tac b = "-b" and r = "-r'" and r' = "-r" in unique_quotient_lemma, 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   110
    auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   111
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   112
lemma unique_quotient:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   113
     "[| quorem ((a,b), (q,r));  quorem ((a,b), (q',r'));  b ~= 0 |]  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   114
      ==> q = q'"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   115
apply (simp add: quorem_def linorder_neq_iff split: split_if_asm)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   116
apply (blast intro: order_antisym
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   117
             dest: order_eq_refl [THEN unique_quotient_lemma] 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   118
             order_eq_refl [THEN unique_quotient_lemma_neg] sym)+
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   119
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   120
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   121
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   122
lemma unique_remainder:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   123
     "[| quorem ((a,b), (q,r));  quorem ((a,b), (q',r'));  b ~= 0 |]  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   124
      ==> r = r'"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   125
apply (subgoal_tac "q = q'")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   126
 apply (simp add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   127
apply (blast intro: unique_quotient)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   128
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   129
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   130
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   131
(*** Correctness of posDivAlg, the division algorithm for a>=0 and b>0 ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   132
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   133
lemma adjust_eq [simp]:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   134
     "adjust b (q,r) = 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   135
      (let diff = r-b in  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   136
	if 0 <= diff then (2*q + 1, diff)   
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   137
                     else (2*q, r))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   138
by (simp add: Let_def adjust_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   139
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   140
declare posDivAlg.simps [simp del]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   141
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   142
(**use with a simproc to avoid repeatedly proving the premise*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   143
lemma posDivAlg_eqn:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   144
     "0 < b ==>  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   145
      posDivAlg (a,b) = (if a<b then (0,a) else adjust b (posDivAlg(a, 2*b)))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   146
by (rule posDivAlg.simps [THEN trans], simp)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   147
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   148
(*Correctness of posDivAlg: it computes quotients correctly*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   149
lemma posDivAlg_correct [rule_format]:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   150
     "0 <= a --> 0 < b --> quorem ((a, b), posDivAlg (a, b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   151
apply (induct_tac a b rule: posDivAlg.induct, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   152
 apply (simp_all add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   153
 (*base case: a<b*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   154
 apply (simp add: posDivAlg_eqn)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   155
(*main argument*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   156
apply (subst posDivAlg_eqn, simp_all)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   157
apply (erule splitE)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   158
apply (auto simp add: zadd_zmult_distrib2 Let_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   159
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   160
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   161
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   162
(*** Correctness of negDivAlg, the division algorithm for a<0 and b>0 ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   163
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   164
declare negDivAlg.simps [simp del]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   165
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   166
(**use with a simproc to avoid repeatedly proving the premise*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   167
lemma negDivAlg_eqn:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   168
     "0 < b ==>  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   169
      negDivAlg (a,b) =       
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   170
       (if 0<=a+b then (-1,a+b) else adjust b (negDivAlg(a, 2*b)))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   171
by (rule negDivAlg.simps [THEN trans], simp)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   172
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   173
(*Correctness of negDivAlg: it computes quotients correctly
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   174
  It doesn't work if a=0 because the 0/b equals 0, not -1*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   175
lemma negDivAlg_correct [rule_format]:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   176
     "a < 0 --> 0 < b --> quorem ((a, b), negDivAlg (a, b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   177
apply (induct_tac a b rule: negDivAlg.induct, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   178
 apply (simp_all add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   179
 (*base case: 0<=a+b*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   180
 apply (simp add: negDivAlg_eqn)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   181
(*main argument*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   182
apply (subst negDivAlg_eqn, assumption)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   183
apply (erule splitE)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   184
apply (auto simp add: zadd_zmult_distrib2 Let_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   185
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   186
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   187
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   188
(*** Existence shown by proving the division algorithm to be correct ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   189
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   190
(*the case a=0*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   191
lemma quorem_0: "b ~= 0 ==> quorem ((0,b), (0,0))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   192
by (auto simp add: quorem_def linorder_neq_iff)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   193
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   194
lemma posDivAlg_0 [simp]: "posDivAlg (0, b) = (0, 0)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   195
by (subst posDivAlg.simps, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   196
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   197
lemma negDivAlg_minus1 [simp]: "negDivAlg (-1, b) = (-1, b - 1)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   198
by (subst negDivAlg.simps, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   199
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   200
lemma negateSnd_eq [simp]: "negateSnd(q,r) = (q,-r)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   201
by (unfold negateSnd_def, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   202
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   203
lemma quorem_neg: "quorem ((-a,-b), qr) ==> quorem ((a,b), negateSnd qr)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   204
by (auto simp add: split_ifs quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   205
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   206
lemma divAlg_correct: "b ~= 0 ==> quorem ((a,b), divAlg(a,b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   207
by (force simp add: linorder_neq_iff quorem_0 divAlg_def quorem_neg
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   208
                    posDivAlg_correct negDivAlg_correct)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   209
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   210
(** Arbitrary definitions for division by zero.  Useful to simplify 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   211
    certain equations **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   212
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   213
lemma DIVISION_BY_ZERO: "a div (0::int) = 0 & a mod (0::int) = a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   214
by (simp add: div_def mod_def divAlg_def posDivAlg.simps)  (*NOT for adding to default simpset*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   215
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   216
(** Basic laws about division and remainder **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   217
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   218
lemma zmod_zdiv_equality: "(a::int) = b * (a div b) + (a mod b)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   219
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   220
apply (cut_tac a = a and b = b in divAlg_correct)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   221
apply (auto simp add: quorem_def div_def mod_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   222
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   223
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   224
lemma pos_mod_conj : "(0::int) < b ==> 0 <= a mod b & a mod b < b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   225
apply (cut_tac a = a and b = b in divAlg_correct)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   226
apply (auto simp add: quorem_def mod_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   227
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   228
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   229
lemmas pos_mod_sign  = pos_mod_conj [THEN conjunct1, standard]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   230
   and pos_mod_bound = pos_mod_conj [THEN conjunct2, standard]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   231
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   232
lemma neg_mod_conj : "b < (0::int) ==> a mod b <= 0 & b < a mod b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   233
apply (cut_tac a = a and b = b in divAlg_correct)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   234
apply (auto simp add: quorem_def div_def mod_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   235
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   236
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   237
lemmas neg_mod_sign  = neg_mod_conj [THEN conjunct1, standard]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   238
   and neg_mod_bound = neg_mod_conj [THEN conjunct2, standard]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   239
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   240
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   241
(** proving general properties of div and mod **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   242
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   243
lemma quorem_div_mod: "b ~= 0 ==> quorem ((a, b), (a div b, a mod b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   244
apply (cut_tac a = a and b = b in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   245
apply (force simp add: quorem_def linorder_neq_iff pos_mod_sign pos_mod_bound
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   246
                       neg_mod_sign neg_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   247
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   248
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   249
lemma quorem_div: "[| quorem((a,b),(q,r));  b ~= 0 |] ==> a div b = q"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   250
by (simp add: quorem_div_mod [THEN unique_quotient])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   251
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   252
lemma quorem_mod: "[| quorem((a,b),(q,r));  b ~= 0 |] ==> a mod b = r"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   253
by (simp add: quorem_div_mod [THEN unique_remainder])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   254
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   255
lemma div_pos_pos_trivial: "[| (0::int) <= a;  a < b |] ==> a div b = 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   256
apply (rule quorem_div)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   257
apply (auto simp add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   258
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   259
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   260
lemma div_neg_neg_trivial: "[| a <= (0::int);  b < a |] ==> a div b = 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   261
apply (rule quorem_div)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   262
apply (auto simp add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   263
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   264
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   265
lemma div_pos_neg_trivial: "[| (0::int) < a;  a+b <= 0 |] ==> a div b = -1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   266
apply (rule quorem_div)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   267
apply (auto simp add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   268
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   269
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   270
(*There is no div_neg_pos_trivial because  0 div b = 0 would supersede it*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   271
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   272
lemma mod_pos_pos_trivial: "[| (0::int) <= a;  a < b |] ==> a mod b = a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   273
apply (rule_tac q = 0 in quorem_mod)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   274
apply (auto simp add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   275
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   276
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   277
lemma mod_neg_neg_trivial: "[| a <= (0::int);  b < a |] ==> a mod b = a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   278
apply (rule_tac q = 0 in quorem_mod)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   279
apply (auto simp add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   280
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   281
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   282
lemma mod_pos_neg_trivial: "[| (0::int) < a;  a+b <= 0 |] ==> a mod b = a+b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   283
apply (rule_tac q = "-1" in quorem_mod)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   284
apply (auto simp add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   285
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   286
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   287
(*There is no mod_neg_pos_trivial...*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   288
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   289
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   290
(*Simpler laws such as -a div b = -(a div b) FAIL, but see just below*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   291
lemma zdiv_zminus_zminus [simp]: "(-a) div (-b) = a div (b::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   292
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   293
apply (simp add: quorem_div_mod [THEN quorem_neg, simplified, 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   294
                                 THEN quorem_div, THEN sym])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   295
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   296
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   297
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   298
(*Simpler laws such as -a mod b = -(a mod b) FAIL, but see just below*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   299
lemma zmod_zminus_zminus [simp]: "(-a) mod (-b) = - (a mod (b::int))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   300
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   301
apply (subst quorem_div_mod [THEN quorem_neg, simplified, THEN quorem_mod],
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   302
       auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   303
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   304
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   305
(*** div, mod and unary minus ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   306
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   307
lemma zminus1_lemma:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   308
     "quorem((a,b),(q,r))  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   309
      ==> quorem ((-a,b), (if r=0 then -q else -q - 1),  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   310
                          (if r=0 then 0 else b-r))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   311
by (force simp add: split_ifs quorem_def linorder_neq_iff zdiff_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   312
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   313
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   314
lemma zdiv_zminus1_eq_if:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   315
     "b ~= (0::int)  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   316
      ==> (-a) div b =  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   317
          (if a mod b = 0 then - (a div b) else  - (a div b) - 1)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   318
by (blast intro: quorem_div_mod [THEN zminus1_lemma, THEN quorem_div])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   319
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   320
lemma zmod_zminus1_eq_if:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   321
     "(-a::int) mod b = (if a mod b = 0 then 0 else  b - (a mod b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   322
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   323
apply (blast intro: quorem_div_mod [THEN zminus1_lemma, THEN quorem_mod])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   324
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   325
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   326
lemma zdiv_zminus2: "a div (-b) = (-a::int) div b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   327
by (cut_tac a = "-a" in zdiv_zminus_zminus, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   328
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   329
lemma zmod_zminus2: "a mod (-b) = - ((-a::int) mod b)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   330
by (cut_tac a = "-a" and b = b in zmod_zminus_zminus, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   331
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   332
lemma zdiv_zminus2_eq_if:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   333
     "b ~= (0::int)  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   334
      ==> a div (-b) =  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   335
          (if a mod b = 0 then - (a div b) else  - (a div b) - 1)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   336
by (simp add: zdiv_zminus1_eq_if zdiv_zminus2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   337
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   338
lemma zmod_zminus2_eq_if:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   339
     "a mod (-b::int) = (if a mod b = 0 then 0 else  (a mod b) - b)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   340
by (simp add: zmod_zminus1_eq_if zmod_zminus2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   341
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   342
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   343
(*** division of a number by itself ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   344
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   345
lemma lemma1: "[| (0::int) < a; a = r + a*q; r < a |] ==> 1 <= q"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   346
apply (subgoal_tac "0 < a*q")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   347
 apply (simp add: int_0_less_mult_iff, arith)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   348
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   349
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   350
lemma lemma2: "[| (0::int) < a; a = r + a*q; 0 <= r |] ==> q <= 1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   351
apply (subgoal_tac "0 <= a* (1-q) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   352
 apply (simp add: int_0_le_mult_iff)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   353
apply (simp add: zdiff_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   354
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   355
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   356
lemma self_quotient: "[| quorem((a,a),(q,r));  a ~= (0::int) |] ==> q = 1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   357
apply (simp add: split_ifs quorem_def linorder_neq_iff)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   358
apply (rule order_antisym, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   359
apply (rule_tac [3] a = "-a" and r = "-r" in lemma1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   360
apply (rule_tac a = "-a" and r = "-r" in lemma2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   361
apply (force intro: lemma1 lemma2 simp add: zadd_commute zmult_zminus)+
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   362
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   363
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   364
lemma self_remainder: "[| quorem((a,a),(q,r));  a ~= (0::int) |] ==> r = 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   365
apply (frule self_quotient, assumption)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   366
apply (simp add: quorem_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   367
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   368
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   369
lemma zdiv_self [simp]: "a ~= 0 ==> a div a = (1::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   370
by (simp add: quorem_div_mod [THEN self_quotient])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   371
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   372
(*Here we have 0 mod 0 = 0, also assumed by Knuth (who puts m mod 0 = 0) *)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   373
lemma zmod_self [simp]: "a mod a = (0::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   374
apply (case_tac "a = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   375
apply (simp add: quorem_div_mod [THEN self_remainder])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   376
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   377
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   378
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   379
(*** Computation of division and remainder ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   380
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   381
lemma zdiv_zero [simp]: "(0::int) div b = 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   382
by (simp add: div_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   383
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   384
lemma div_eq_minus1: "(0::int) < b ==> -1 div b = -1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   385
by (simp add: div_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   386
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   387
lemma zmod_zero [simp]: "(0::int) mod b = 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   388
by (simp add: mod_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   389
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   390
lemma zdiv_minus1: "(0::int) < b ==> -1 div b = -1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   391
by (simp add: div_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   392
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   393
lemma zmod_minus1: "(0::int) < b ==> -1 mod b = b - 1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   394
by (simp add: mod_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   395
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   396
(** a positive, b positive **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   397
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   398
lemma div_pos_pos: "[| 0 < a;  0 <= b |] ==> a div b = fst (posDivAlg(a,b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   399
by (simp add: div_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   400
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   401
lemma mod_pos_pos: "[| 0 < a;  0 <= b |] ==> a mod b = snd (posDivAlg(a,b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   402
by (simp add: mod_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   403
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   404
(** a negative, b positive **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   405
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   406
lemma div_neg_pos: "[| a < 0;  0 < b |] ==> a div b = fst (negDivAlg(a,b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   407
by (simp add: div_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   408
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   409
lemma mod_neg_pos: "[| a < 0;  0 < b |] ==> a mod b = snd (negDivAlg(a,b))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   410
by (simp add: mod_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   411
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   412
(** a positive, b negative **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   413
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   414
lemma div_pos_neg:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   415
     "[| 0 < a;  b < 0 |] ==> a div b = fst (negateSnd(negDivAlg(-a,-b)))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   416
by (simp add: div_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   417
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   418
lemma mod_pos_neg:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   419
     "[| 0 < a;  b < 0 |] ==> a mod b = snd (negateSnd(negDivAlg(-a,-b)))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   420
by (simp add: mod_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   421
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   422
(** a negative, b negative **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   423
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   424
lemma div_neg_neg:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   425
     "[| a < 0;  b <= 0 |] ==> a div b = fst (negateSnd(posDivAlg(-a,-b)))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   426
by (simp add: div_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   427
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   428
lemma mod_neg_neg:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   429
     "[| a < 0;  b <= 0 |] ==> a mod b = snd (negateSnd(posDivAlg(-a,-b)))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   430
by (simp add: mod_def divAlg_def)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   431
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   432
text {*Simplify expresions in which div and mod combine numerical constants*}
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   433
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   434
declare div_pos_pos [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   435
declare div_neg_pos [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   436
declare div_pos_neg [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   437
declare div_neg_neg [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   438
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   439
declare mod_pos_pos [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   440
declare mod_neg_pos [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   441
declare mod_pos_neg [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   442
declare mod_neg_neg [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   443
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   444
declare posDivAlg_eqn [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   445
declare negDivAlg_eqn [of "number_of v" "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   446
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   447
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   448
(** Special-case simplification **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   449
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   450
lemma zmod_1 [simp]: "a mod (1::int) = 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   451
apply (cut_tac a = a and b = 1 in pos_mod_sign)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   452
apply (cut_tac [2] a = a and b = 1 in pos_mod_bound, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   453
done 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   454
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   455
lemma zdiv_1 [simp]: "a div (1::int) = a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   456
by (cut_tac a = a and b = 1 in zmod_zdiv_equality, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   457
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   458
lemma zmod_minus1_right [simp]: "a mod (-1::int) = 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   459
apply (cut_tac a = a and b = "-1" in neg_mod_sign)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   460
apply (cut_tac [2] a = a and b = "-1" in neg_mod_bound, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   461
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   462
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   463
lemma zdiv_minus1_right [simp]: "a div (-1::int) = -a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   464
by (cut_tac a = a and b = "-1" in zmod_zdiv_equality, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   465
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   466
(** The last remaining special cases for constant arithmetic:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   467
    1 div z and 1 mod z **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   468
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   469
declare div_pos_pos [OF int_0_less_1, of "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   470
declare div_pos_neg [OF int_0_less_1, of "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   471
declare mod_pos_pos [OF int_0_less_1, of "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   472
declare mod_pos_neg [OF int_0_less_1, of "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   473
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   474
declare posDivAlg_eqn [of concl: 1 "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   475
declare negDivAlg_eqn [of concl: 1 "number_of w", standard, simp]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   476
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   477
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   478
(*** Monotonicity in the first argument (divisor) ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   479
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   480
lemma zdiv_mono1: "[| a <= a';  0 < (b::int) |] ==> a div b <= a' div b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   481
apply (cut_tac a = a and b = b in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   482
apply (cut_tac a = a' and b = b in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   483
apply (rule unique_quotient_lemma)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   484
apply (erule subst)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   485
apply (erule subst)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   486
apply (simp_all add: pos_mod_sign pos_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   487
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   488
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   489
lemma zdiv_mono1_neg: "[| a <= a';  (b::int) < 0 |] ==> a' div b <= a div b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   490
apply (cut_tac a = a and b = b in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   491
apply (cut_tac a = a' and b = b in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   492
apply (rule unique_quotient_lemma_neg)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   493
apply (erule subst)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   494
apply (erule subst)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   495
apply (simp_all add: neg_mod_sign neg_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   496
done
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
   497
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
   498
13183
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   499
(*** Monotonicity in the second argument (dividend) ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   500
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   501
lemma q_pos_lemma:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   502
     "[| 0 <= b'*q' + r'; r' < b';  0 < b' |] ==> 0 <= (q'::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   503
apply (subgoal_tac "0 < b'* (q' + 1) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   504
 apply (simp add: int_0_less_mult_iff)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   505
apply (simp add: zadd_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   506
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   507
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   508
lemma zdiv_mono2_lemma:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   509
     "[| b*q + r = b'*q' + r';  0 <= b'*q' + r';   
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   510
         r' < b';  0 <= r;  0 < b';  b' <= b |]   
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   511
      ==> q <= (q'::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   512
apply (frule q_pos_lemma, assumption+) 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   513
apply (subgoal_tac "b*q < b* (q' + 1) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   514
 apply (simp add: zmult_zless_cancel1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   515
apply (subgoal_tac "b*q = r' - r + b'*q'")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   516
 prefer 2 apply simp
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   517
apply (simp (no_asm_simp) add: zadd_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   518
apply (subst zadd_commute, rule zadd_zless_mono, arith)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   519
apply (rule zmult_zle_mono1, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   520
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   521
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   522
lemma zdiv_mono2:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   523
     "[| (0::int) <= a;  0 < b';  b' <= b |] ==> a div b <= a div b'"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   524
apply (subgoal_tac "b ~= 0")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   525
 prefer 2 apply arith
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   526
apply (cut_tac a = a and b = b in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   527
apply (cut_tac a = a and b = b' in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   528
apply (rule zdiv_mono2_lemma)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   529
apply (erule subst)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   530
apply (erule subst)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   531
apply (simp_all add: pos_mod_sign pos_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   532
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   533
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   534
lemma q_neg_lemma:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   535
     "[| b'*q' + r' < 0;  0 <= r';  0 < b' |] ==> q' <= (0::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   536
apply (subgoal_tac "b'*q' < 0")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   537
 apply (simp add: zmult_less_0_iff, arith)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   538
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   539
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   540
lemma zdiv_mono2_neg_lemma:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   541
     "[| b*q + r = b'*q' + r';  b'*q' + r' < 0;   
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   542
         r < b;  0 <= r';  0 < b';  b' <= b |]   
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   543
      ==> q' <= (q::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   544
apply (frule q_neg_lemma, assumption+) 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   545
apply (subgoal_tac "b*q' < b* (q + 1) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   546
 apply (simp add: zmult_zless_cancel1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   547
apply (simp add: zadd_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   548
apply (subgoal_tac "b*q' <= b'*q'")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   549
 prefer 2 apply (simp add: zmult_zle_mono1_neg)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   550
apply (subgoal_tac "b'*q' < b + b*q")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   551
 apply arith
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   552
apply simp 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   553
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   554
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   555
lemma zdiv_mono2_neg:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   556
     "[| a < (0::int);  0 < b';  b' <= b |] ==> a div b' <= a div b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   557
apply (cut_tac a = a and b = b in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   558
apply (cut_tac a = a and b = b' in zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   559
apply (rule zdiv_mono2_neg_lemma)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   560
apply (erule subst)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   561
apply (erule subst)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   562
apply (simp_all add: pos_mod_sign pos_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   563
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   564
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   565
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   566
(*** More algebraic laws for div and mod ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   567
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   568
(** proving (a*b) div c = a * (b div c) + a * (b mod c) **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   569
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   570
lemma zmult1_lemma:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   571
     "[| quorem((b,c),(q,r));  c ~= 0 |]  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   572
      ==> quorem ((a*b, c), (a*q + a*r div c, a*r mod c))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   573
by (force simp add: split_ifs quorem_def linorder_neq_iff zadd_zmult_distrib2
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   574
                    pos_mod_sign pos_mod_bound neg_mod_sign neg_mod_bound 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   575
                    zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   576
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   577
lemma zdiv_zmult1_eq: "(a*b) div c = a*(b div c) + a*(b mod c) div (c::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   578
apply (case_tac "c = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   579
apply (blast intro: quorem_div_mod [THEN zmult1_lemma, THEN quorem_div])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   580
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   581
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   582
lemma zmod_zmult1_eq: "(a*b) mod c = a*(b mod c) mod (c::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   583
apply (case_tac "c = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   584
apply (blast intro: quorem_div_mod [THEN zmult1_lemma, THEN quorem_mod])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   585
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   586
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   587
lemma zmod_zmult1_eq': "(a*b) mod (c::int) = ((a mod c) * b) mod c"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   588
apply (rule trans)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   589
apply (rule_tac s = "b*a mod c" in trans)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   590
apply (rule_tac [2] zmod_zmult1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   591
apply (simp_all add: zmult_commute)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   592
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   593
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   594
lemma zmod_zmult_distrib: "(a*b) mod (c::int) = ((a mod c) * (b mod c)) mod c"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   595
apply (rule zmod_zmult1_eq' [THEN trans])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   596
apply (rule zmod_zmult1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   597
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   598
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   599
lemma zdiv_zmult_self1 [simp]: "b ~= (0::int) ==> (a*b) div b = a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   600
by (simp add: zdiv_zmult1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   601
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   602
lemma zdiv_zmult_self2 [simp]: "b ~= (0::int) ==> (b*a) div b = a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   603
by (subst zmult_commute, erule zdiv_zmult_self1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   604
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   605
lemma zmod_zmult_self1 [simp]: "(a*b) mod b = (0::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   606
by (simp add: zmod_zmult1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   607
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   608
lemma zmod_zmult_self2 [simp]: "(b*a) mod b = (0::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   609
by (simp add: zmult_commute zmod_zmult1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   610
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   611
lemma zmod_eq_0_iff: "(m mod d = 0) = (EX q::int. m = d*q)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   612
by (cut_tac a = m and b = d in zmod_zdiv_equality, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   613
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   614
declare zmod_eq_0_iff [THEN iffD1, dest!]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   615
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   616
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   617
(** proving (a+b) div c = a div c + b div c + ((a mod c + b mod c) div c) **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   618
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   619
lemma zadd1_lemma:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   620
     "[| quorem((a,c),(aq,ar));  quorem((b,c),(bq,br));  c ~= 0 |]  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   621
      ==> quorem ((a+b, c), (aq + bq + (ar+br) div c, (ar+br) mod c))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   622
by (force simp add: split_ifs quorem_def linorder_neq_iff zadd_zmult_distrib2
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   623
                    pos_mod_sign pos_mod_bound neg_mod_sign neg_mod_bound
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   624
                    zmod_zdiv_equality)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   625
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   626
(*NOT suitable for rewriting: the RHS has an instance of the LHS*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   627
lemma zdiv_zadd1_eq:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   628
     "(a+b) div (c::int) = a div c + b div c + ((a mod c + b mod c) div c)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   629
apply (case_tac "c = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   630
apply (blast intro: zadd1_lemma [OF quorem_div_mod quorem_div_mod] quorem_div)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   631
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   632
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   633
lemma zmod_zadd1_eq: "(a+b) mod (c::int) = (a mod c + b mod c) mod c"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   634
apply (case_tac "c = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   635
apply (blast intro: zadd1_lemma [OF quorem_div_mod quorem_div_mod] quorem_mod)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   636
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   637
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   638
lemma mod_div_trivial [simp]: "(a mod b) div b = (0::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   639
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   640
apply (auto simp add: linorder_neq_iff pos_mod_sign pos_mod_bound
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   641
            div_pos_pos_trivial neg_mod_sign neg_mod_bound div_neg_neg_trivial)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   642
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   643
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   644
lemma mod_mod_trivial [simp]: "(a mod b) mod b = a mod (b::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   645
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   646
apply (force simp add: linorder_neq_iff pos_mod_sign pos_mod_bound
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   647
                       mod_pos_pos_trivial neg_mod_sign neg_mod_bound 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   648
                       mod_neg_neg_trivial)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   649
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   650
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   651
lemma zmod_zadd_left_eq: "(a+b) mod (c::int) = ((a mod c) + b) mod c"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   652
apply (rule trans [symmetric])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   653
apply (rule zmod_zadd1_eq, simp)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   654
apply (rule zmod_zadd1_eq [symmetric])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   655
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   656
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   657
lemma zmod_zadd_right_eq: "(a+b) mod (c::int) = (a + (b mod c)) mod c"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   658
apply (rule trans [symmetric])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   659
apply (rule zmod_zadd1_eq, simp)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   660
apply (rule zmod_zadd1_eq [symmetric])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   661
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   662
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   663
lemma zdiv_zadd_self1[simp]: "a ~= (0::int) ==> (a+b) div a = b div a + 1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   664
by (simp add: zdiv_zadd1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   665
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   666
lemma zdiv_zadd_self2[simp]: "a ~= (0::int) ==> (b+a) div a = b div a + 1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   667
by (simp add: zdiv_zadd1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   668
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   669
lemma zmod_zadd_self1[simp]: "(a+b) mod a = b mod (a::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   670
apply (case_tac "a = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   671
apply (simp add: zmod_zadd1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   672
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   673
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   674
lemma zmod_zadd_self2[simp]: "(b+a) mod a = b mod (a::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   675
apply (case_tac "a = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   676
apply (simp add: zmod_zadd1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   677
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   678
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   679
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   680
(*** proving  a div (b*c) = (a div b) div c ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   681
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   682
(*The condition c>0 seems necessary.  Consider that 7 div ~6 = ~2 but
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   683
  7 div 2 div ~3 = 3 div ~3 = ~1.  The subcase (a div b) mod c = 0 seems
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   684
  to cause particular problems.*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   685
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   686
(** first, four lemmas to bound the remainder for the cases b<0 and b>0 **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   687
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   688
lemma lemma1: "[| (0::int) < c;  b < r;  r <= 0 |] ==> b*c < b*(q mod c) + r"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   689
apply (subgoal_tac "b * (c - q mod c) < r * 1")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   690
apply (simp add: zdiff_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   691
apply (rule order_le_less_trans)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   692
apply (erule_tac [2] zmult_zless_mono1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   693
apply (rule zmult_zle_mono2_neg)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   694
apply (auto simp add: zcompare_rls zadd_commute [of 1]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   695
                      add1_zle_eq pos_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   696
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   697
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   698
lemma lemma2: "[| (0::int) < c;   b < r;  r <= 0 |] ==> b * (q mod c) + r <= 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   699
apply (subgoal_tac "b * (q mod c) <= 0")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   700
 apply arith
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   701
apply (simp add: zmult_le_0_iff pos_mod_sign)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   702
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   703
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   704
lemma lemma3: "[| (0::int) < c;  0 <= r;  r < b |] ==> 0 <= b * (q mod c) + r"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   705
apply (subgoal_tac "0 <= b * (q mod c) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   706
apply arith
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   707
apply (simp add: int_0_le_mult_iff pos_mod_sign)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   708
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   709
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   710
lemma lemma4: "[| (0::int) < c; 0 <= r; r < b |] ==> b * (q mod c) + r < b * c"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   711
apply (subgoal_tac "r * 1 < b * (c - q mod c) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   712
apply (simp add: zdiff_zmult_distrib2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   713
apply (rule order_less_le_trans)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   714
apply (erule zmult_zless_mono1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   715
apply (rule_tac [2] zmult_zle_mono2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   716
apply (auto simp add: zcompare_rls zadd_commute [of 1]
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   717
                      add1_zle_eq pos_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   718
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   719
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   720
lemma zmult2_lemma: "[| quorem ((a,b), (q,r));  b ~= 0;  0 < c |]  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   721
      ==> quorem ((a, b*c), (q div c, b*(q mod c) + r))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   722
by (auto simp add: zmult_ac zmod_zdiv_equality quorem_def linorder_neq_iff
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   723
                   int_0_less_mult_iff zadd_zmult_distrib2 [symmetric] 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   724
                   lemma1 lemma2 lemma3 lemma4)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   725
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   726
lemma zdiv_zmult2_eq: "(0::int) < c ==> a div (b*c) = (a div b) div c"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   727
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   728
apply (force simp add: quorem_div_mod [THEN zmult2_lemma, THEN quorem_div])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   729
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   730
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   731
lemma zmod_zmult2_eq:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   732
     "(0::int) < c ==> a mod (b*c) = b*(a div b mod c) + a mod b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   733
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   734
apply (force simp add: quorem_div_mod [THEN zmult2_lemma, THEN quorem_mod])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   735
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   736
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   737
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   738
(*** Cancellation of common factors in div ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   739
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   740
lemma lemma1: "[| (0::int) < b;  c ~= 0 |] ==> (c*a) div (c*b) = a div b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   741
by (subst zdiv_zmult2_eq, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   742
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   743
lemma lemma2: "[| b < (0::int);  c ~= 0 |] ==> (c*a) div (c*b) = a div b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   744
apply (subgoal_tac " (c * (-a)) div (c * (-b)) = (-a) div (-b) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   745
apply (rule_tac [2] lemma1, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   746
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   747
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   748
lemma zdiv_zmult_zmult1: "c ~= (0::int) ==> (c*a) div (c*b) = a div b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   749
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   750
apply (auto simp add: linorder_neq_iff lemma1 lemma2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   751
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   752
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   753
lemma zdiv_zmult_zmult2: "c ~= (0::int) ==> (a*c) div (b*c) = a div b"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   754
apply (drule zdiv_zmult_zmult1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   755
apply (auto simp add: zmult_commute)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   756
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   757
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   758
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   759
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   760
(*** Distribution of factors over mod ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   761
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   762
lemma lemma1: "[| (0::int) < b;  c ~= 0 |] ==> (c*a) mod (c*b) = c * (a mod b)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   763
by (subst zmod_zmult2_eq, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   764
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   765
lemma lemma2: "[| b < (0::int);  c ~= 0 |] ==> (c*a) mod (c*b) = c * (a mod b)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   766
apply (subgoal_tac " (c * (-a)) mod (c * (-b)) = c * ((-a) mod (-b))")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   767
apply (rule_tac [2] lemma1, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   768
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   769
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   770
lemma zmod_zmult_zmult1: "(c*a) mod (c*b) = (c::int) * (a mod b)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   771
apply (case_tac "b = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   772
apply (case_tac "c = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   773
apply (auto simp add: linorder_neq_iff lemma1 lemma2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   774
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   775
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   776
lemma zmod_zmult_zmult2: "(a*c) mod (b*c) = (a mod b) * (c::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   777
apply (cut_tac c = c in zmod_zmult_zmult1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   778
apply (auto simp add: zmult_commute)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   779
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   780
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   781
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   782
(*** Speeding up the division algorithm with shifting ***)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   783
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   784
(** computing div by shifting **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   785
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   786
lemma pos_zdiv_mult_2: "(0::int) <= a ==> (1 + 2*b) div (2*a) = b div a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   787
apply (case_tac "a = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   788
apply (subgoal_tac "1 <= a")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   789
 prefer 2 apply arith
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   790
apply (subgoal_tac "1 < a * 2")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   791
 prefer 2 apply arith
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   792
apply (subgoal_tac "2* (1 + b mod a) <= 2*a")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   793
 apply (rule_tac [2] zmult_zle_mono2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   794
apply (auto simp add: zadd_commute [of 1] zmult_commute add1_zle_eq 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   795
                      pos_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   796
apply (subst zdiv_zadd1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   797
apply (simp add: zdiv_zmult_zmult2 zmod_zmult_zmult2 div_pos_pos_trivial)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   798
apply (subst div_pos_pos_trivial)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   799
apply (auto simp add: mod_pos_pos_trivial)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   800
apply (subgoal_tac "0 <= b mod a", arith)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   801
apply (simp add: pos_mod_sign)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   802
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   803
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   804
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   805
lemma neg_zdiv_mult_2: "a <= (0::int) ==> (1 + 2*b) div (2*a) = (b+1) div a"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   806
apply (subgoal_tac " (1 + 2* (-b - 1)) div (2 * (-a)) = (-b - 1) div (-a) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   807
apply (rule_tac [2] pos_zdiv_mult_2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   808
apply (auto simp add: zmult_zminus_right)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   809
apply (subgoal_tac " (-1 - (2 * b)) = - (1 + (2 * b))")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   810
apply (simp only: zdiv_zminus_zminus zdiff_def zminus_zadd_distrib [symmetric],
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   811
       simp) 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   812
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   813
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   814
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   815
(*Not clear why this must be proved separately; probably number_of causes
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   816
  simplification problems*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   817
lemma not_0_le_lemma: "~ 0 <= x ==> x <= (0::int)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   818
by auto
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   819
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   820
lemma zdiv_number_of_BIT[simp]:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   821
     "number_of (v BIT b) div number_of (w BIT False) =  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   822
          (if ~b | (0::int) <= number_of w                    
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   823
           then number_of v div (number_of w)     
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   824
           else (number_of v + (1::int)) div (number_of w))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   825
apply (simp only: zadd_assoc number_of_BIT)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   826
(*create subgoal because the next step can't simplify numerals*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   827
apply (subgoal_tac "2 ~= (0::int) ")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   828
apply (simp del: bin_arith_extra_simps 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   829
         add: zdiv_zmult_zmult1 pos_zdiv_mult_2 not_0_le_lemma neg_zdiv_mult_2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   830
apply simp
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   831
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   832
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   833
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   834
(** computing mod by shifting (proofs resemble those for div) **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   835
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   836
lemma pos_zmod_mult_2:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   837
     "(0::int) <= a ==> (1 + 2*b) mod (2*a) = 1 + 2 * (b mod a)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   838
apply (case_tac "a = 0", simp add: DIVISION_BY_ZERO)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   839
apply (subgoal_tac "1 <= a")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   840
 prefer 2 apply arith
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   841
apply (subgoal_tac "1 < a * 2")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   842
 prefer 2 apply arith
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   843
apply (subgoal_tac "2* (1 + b mod a) <= 2*a")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   844
 apply (rule_tac [2] zmult_zle_mono2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   845
apply (auto simp add: zadd_commute [of 1] zmult_commute add1_zle_eq 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   846
                      pos_mod_bound)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   847
apply (subst zmod_zadd1_eq)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   848
apply (simp add: zmod_zmult_zmult2 mod_pos_pos_trivial)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   849
apply (rule mod_pos_pos_trivial)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   850
apply (auto simp add: mod_pos_pos_trivial)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   851
apply (subgoal_tac "0 <= b mod a", arith)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   852
apply (simp add: pos_mod_sign)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   853
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   854
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   855
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   856
lemma neg_zmod_mult_2:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   857
     "a <= (0::int) ==> (1 + 2*b) mod (2*a) = 2 * ((b+1) mod a) - 1"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   858
apply (subgoal_tac "(1 + 2* (-b - 1)) mod (2* (-a)) = 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   859
                    1 + 2* ((-b - 1) mod (-a))")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   860
apply (rule_tac [2] pos_zmod_mult_2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   861
apply (auto simp add: zmult_zminus_right)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   862
apply (subgoal_tac " (-1 - (2 * b)) = - (1 + (2 * b))")
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   863
 prefer 2 apply simp 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   864
apply (simp only: zmod_zminus_zminus zdiff_def zminus_zadd_distrib [symmetric])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   865
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   866
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   867
lemma zmod_number_of_BIT [simp]:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   868
     "number_of (v BIT b) mod number_of (w BIT False) =  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   869
          (if b then  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   870
                if (0::int) <= number_of w  
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   871
                then 2 * (number_of v mod number_of w) + 1     
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   872
                else 2 * ((number_of v + (1::int)) mod number_of w) - 1   
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   873
           else 2 * (number_of v mod number_of w))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   874
apply (simp only: zadd_assoc number_of_BIT)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   875
apply (simp del: bin_arith_extra_simps bin_rel_simps 
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   876
         add: zmod_zmult_zmult1 pos_zmod_mult_2 not_0_le_lemma neg_zmod_mult_2)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   877
apply simp
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   878
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   879
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   880
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   881
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   882
(** Quotients of signs **)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   883
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   884
lemma div_neg_pos_less0: "[| a < (0::int);  0 < b |] ==> a div b < 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   885
apply (subgoal_tac "a div b <= -1", force)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   886
apply (rule order_trans)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   887
apply (rule_tac a' = "-1" in zdiv_mono1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   888
apply (auto simp add: zdiv_minus1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   889
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   890
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   891
lemma div_nonneg_neg_le0: "[| (0::int) <= a;  b < 0 |] ==> a div b <= 0"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   892
by (drule zdiv_mono1_neg, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   893
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   894
lemma pos_imp_zdiv_nonneg_iff: "(0::int) < b ==> (0 <= a div b) = (0 <= a)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   895
apply auto
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   896
apply (drule_tac [2] zdiv_mono1)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   897
apply (auto simp add: linorder_neq_iff)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   898
apply (simp (no_asm_use) add: linorder_not_less [symmetric])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   899
apply (blast intro: div_neg_pos_less0)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   900
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   901
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   902
lemma neg_imp_zdiv_nonneg_iff:
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   903
     "b < (0::int) ==> (0 <= a div b) = (a <= (0::int))"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   904
apply (subst zdiv_zminus_zminus [symmetric])
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   905
apply (subst pos_imp_zdiv_nonneg_iff, auto)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   906
done
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   907
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   908
(*But not (a div b <= 0 iff a<=0); consider a=1, b=2 when a div b = 0.*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   909
lemma pos_imp_zdiv_neg_iff: "(0::int) < b ==> (a div b < 0) = (a < 0)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   910
by (simp add: linorder_not_le [symmetric] pos_imp_zdiv_nonneg_iff)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   911
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   912
(*Again the law fails for <=: consider a = -1, b = -2 when a div b = 0*)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   913
lemma neg_imp_zdiv_neg_iff: "b < (0::int) ==> (a div b < 0) = (0 < a)"
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   914
by (simp add: linorder_not_le [symmetric] neg_imp_zdiv_nonneg_iff)
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   915
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   916
ML
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   917
{*
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   918
val quorem_def = thm "quorem_def";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   919
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   920
val unique_quotient = thm "unique_quotient";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   921
val unique_remainder = thm "unique_remainder";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   922
val adjust_eq = thm "adjust_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   923
val posDivAlg_eqn = thm "posDivAlg_eqn";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   924
val posDivAlg_correct = thm "posDivAlg_correct";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   925
val negDivAlg_eqn = thm "negDivAlg_eqn";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   926
val negDivAlg_correct = thm "negDivAlg_correct";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   927
val quorem_0 = thm "quorem_0";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   928
val posDivAlg_0 = thm "posDivAlg_0";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   929
val negDivAlg_minus1 = thm "negDivAlg_minus1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   930
val negateSnd_eq = thm "negateSnd_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   931
val quorem_neg = thm "quorem_neg";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   932
val divAlg_correct = thm "divAlg_correct";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   933
val DIVISION_BY_ZERO = thm "DIVISION_BY_ZERO";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   934
val zmod_zdiv_equality = thm "zmod_zdiv_equality";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   935
val pos_mod_conj = thm "pos_mod_conj";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   936
val pos_mod_sign = thm "pos_mod_sign";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   937
val neg_mod_conj = thm "neg_mod_conj";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   938
val neg_mod_sign = thm "neg_mod_sign";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   939
val quorem_div_mod = thm "quorem_div_mod";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   940
val quorem_div = thm "quorem_div";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   941
val quorem_mod = thm "quorem_mod";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   942
val div_pos_pos_trivial = thm "div_pos_pos_trivial";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   943
val div_neg_neg_trivial = thm "div_neg_neg_trivial";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   944
val div_pos_neg_trivial = thm "div_pos_neg_trivial";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   945
val mod_pos_pos_trivial = thm "mod_pos_pos_trivial";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   946
val mod_neg_neg_trivial = thm "mod_neg_neg_trivial";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   947
val mod_pos_neg_trivial = thm "mod_pos_neg_trivial";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   948
val zdiv_zminus_zminus = thm "zdiv_zminus_zminus";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   949
val zmod_zminus_zminus = thm "zmod_zminus_zminus";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   950
val zdiv_zminus1_eq_if = thm "zdiv_zminus1_eq_if";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   951
val zmod_zminus1_eq_if = thm "zmod_zminus1_eq_if";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   952
val zdiv_zminus2 = thm "zdiv_zminus2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   953
val zmod_zminus2 = thm "zmod_zminus2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   954
val zdiv_zminus2_eq_if = thm "zdiv_zminus2_eq_if";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   955
val zmod_zminus2_eq_if = thm "zmod_zminus2_eq_if";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   956
val self_quotient = thm "self_quotient";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   957
val self_remainder = thm "self_remainder";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   958
val zdiv_self = thm "zdiv_self";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   959
val zmod_self = thm "zmod_self";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   960
val zdiv_zero = thm "zdiv_zero";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   961
val div_eq_minus1 = thm "div_eq_minus1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   962
val zmod_zero = thm "zmod_zero";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   963
val zdiv_minus1 = thm "zdiv_minus1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   964
val zmod_minus1 = thm "zmod_minus1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   965
val div_pos_pos = thm "div_pos_pos";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   966
val mod_pos_pos = thm "mod_pos_pos";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   967
val div_neg_pos = thm "div_neg_pos";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   968
val mod_neg_pos = thm "mod_neg_pos";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   969
val div_pos_neg = thm "div_pos_neg";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   970
val mod_pos_neg = thm "mod_pos_neg";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   971
val div_neg_neg = thm "div_neg_neg";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   972
val mod_neg_neg = thm "mod_neg_neg";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   973
val zmod_1 = thm "zmod_1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   974
val zdiv_1 = thm "zdiv_1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   975
val zmod_minus1_right = thm "zmod_minus1_right";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   976
val zdiv_minus1_right = thm "zdiv_minus1_right";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   977
val zdiv_mono1 = thm "zdiv_mono1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   978
val zdiv_mono1_neg = thm "zdiv_mono1_neg";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   979
val zdiv_mono2 = thm "zdiv_mono2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   980
val zdiv_mono2_neg = thm "zdiv_mono2_neg";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   981
val zdiv_zmult1_eq = thm "zdiv_zmult1_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   982
val zmod_zmult1_eq = thm "zmod_zmult1_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   983
val zmod_zmult1_eq' = thm "zmod_zmult1_eq'";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   984
val zmod_zmult_distrib = thm "zmod_zmult_distrib";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   985
val zdiv_zmult_self1 = thm "zdiv_zmult_self1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   986
val zdiv_zmult_self2 = thm "zdiv_zmult_self2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   987
val zmod_zmult_self1 = thm "zmod_zmult_self1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   988
val zmod_zmult_self2 = thm "zmod_zmult_self2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   989
val zmod_eq_0_iff = thm "zmod_eq_0_iff";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   990
val zdiv_zadd1_eq = thm "zdiv_zadd1_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   991
val zmod_zadd1_eq = thm "zmod_zadd1_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   992
val mod_div_trivial = thm "mod_div_trivial";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   993
val mod_mod_trivial = thm "mod_mod_trivial";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   994
val zmod_zadd_left_eq = thm "zmod_zadd_left_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   995
val zmod_zadd_right_eq = thm "zmod_zadd_right_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   996
val zdiv_zadd_self1 = thm "zdiv_zadd_self1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   997
val zdiv_zadd_self2 = thm "zdiv_zadd_self2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   998
val zmod_zadd_self1 = thm "zmod_zadd_self1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
   999
val zmod_zadd_self2 = thm "zmod_zadd_self2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1000
val zdiv_zmult2_eq = thm "zdiv_zmult2_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1001
val zmod_zmult2_eq = thm "zmod_zmult2_eq";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1002
val zdiv_zmult_zmult1 = thm "zdiv_zmult_zmult1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1003
val zdiv_zmult_zmult2 = thm "zdiv_zmult_zmult2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1004
val zmod_zmult_zmult1 = thm "zmod_zmult_zmult1";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1005
val zmod_zmult_zmult2 = thm "zmod_zmult_zmult2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1006
val pos_zdiv_mult_2 = thm "pos_zdiv_mult_2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1007
val neg_zdiv_mult_2 = thm "neg_zdiv_mult_2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1008
val zdiv_number_of_BIT = thm "zdiv_number_of_BIT";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1009
val pos_zmod_mult_2 = thm "pos_zmod_mult_2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1010
val neg_zmod_mult_2 = thm "neg_zmod_mult_2";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1011
val zmod_number_of_BIT = thm "zmod_number_of_BIT";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1012
val div_neg_pos_less0 = thm "div_neg_pos_less0";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1013
val div_nonneg_neg_le0 = thm "div_nonneg_neg_le0";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1014
val pos_imp_zdiv_nonneg_iff = thm "pos_imp_zdiv_nonneg_iff";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1015
val neg_imp_zdiv_nonneg_iff = thm "neg_imp_zdiv_nonneg_iff";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1016
val pos_imp_zdiv_neg_iff = thm "pos_imp_zdiv_neg_iff";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1017
val neg_imp_zdiv_neg_iff = thm "neg_imp_zdiv_neg_iff";
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1018
*}
c7290200b3f4 conversion of IntDiv.thy to Isar format
paulson
parents: 11868
diff changeset
  1019
6917
eba301caceea Introduction of integer division algorithm
paulson
parents:
diff changeset
  1020
end