Theory IntDiv_ZF_IML

(* 
    This file is a part of IsarMathLib - 
    a library of formalized mathematics for Isabelle/Isar.

    Copyright (C) 2005, 2006  Slawomir Kolodynski

    This program is free software; Redistribution and use in source and binary forms, 
    with or without modification, are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice, 
   this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright notice, 
   this list of conditions and the following disclaimer in the documentation and/or 
   other materials provided with the distribution.
   3. The name of the author may not be used to endorse or promote products 
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*)

section Division on integers

theory IntDiv_ZF_IML imports Int_ZF_1 ZF.IntDiv

begin

textThis theory translates some results form the Isabelle's 
  IntDiv.thy› theory to the notation used by IsarMathLib.

subsectionQuotient and reminder

textFor any integers $m,n$ , $n>0$ there are unique integers $q,p$
  such that $0\leq p < n$ and $m = n\cdot q + p$. Number $p$ in this 
  decompsition is usually called $m$ mod $n$. Standard Isabelle denotes numbers
  $q,p$ as m zdiv n› and m zmod n›, resp., 
  and we will use the same notation.

textThe next lemma is sometimes called the "quotient-reminder theorem".

lemma (in int0) IntDiv_ZF_1_L1: assumes "m"  "n"
  shows "m = n(m zdiv n) \<ra> (m zmod n)"
  using assms Int_ZF_1_L2 raw_zmod_zdiv_equality
  by simp

textIf $n$ is greater than $0$ then m zmod n› is between $0$ and $n-1$.

lemma (in int0) IntDiv_ZF_1_L2: 
  assumes A1: "m" and A2: "𝟬\<lsq>n"  "n𝟬"
  shows 
  "𝟬 \<lsq> m zmod n"  
  "m zmod n \<lsq> n"    "m zmod n  n" 
  "m zmod n \<lsq> n\<rs>𝟭"
proof -
  from A2 have T: "n  "
    using Int_ZF_2_L1A by simp
  from A2 have "#0 $< n" using Int_ZF_2_L9 Int_ZF_1_L8 
    by auto
  with T show 
    "𝟬 \<lsq> m zmod n"  
    "m zmod n \<lsq> n"  
    "m zmod n  n" 
    using pos_mod Int_ZF_1_L8 Int_ZF_1_L8A zmod_type 
      Int_ZF_2_L1 Int_ZF_2_L9AA 
    by auto
  then show "m zmod n \<lsq> n\<rs>𝟭"
    using Int_ZF_4_L1B by auto
qed

text$(m\cdot k)$ div $k = m$.

lemma (in int0) IntDiv_ZF_1_L3: 
  assumes "m"  "k"  and "k𝟬"
  shows 
  "(mk) zdiv k = m"
  "(km) zdiv k = m"
  using assms zdiv_zmult_self1 zdiv_zmult_self2 
    Int_ZF_1_L8 Int_ZF_1_L2 by auto

textThe next lemma essentially translates zdiv_mono1› from 
  standard Isabelle to our notation.

lemma (in int0) IntDiv_ZF_1_L4: 
  assumes A1: "m \<lsq> k" and A2: "𝟬\<lsq>n"  "n𝟬"
  shows "m zdiv n \<lsq>  k zdiv n"
proof -
  from A2 have "#0 \<lsq> n"  "#0  n"
    using Int_ZF_1_L8 by auto
  with A1 have 
    "m zdiv n $≤ k zdiv n"
    "m zdiv n  "    "m zdiv k  "
    using Int_ZF_2_L1A Int_ZF_2_L9 zdiv_mono1
    by auto
  then show "(m zdiv n) \<lsq> (k zdiv n)"
    using Int_ZF_2_L1 by simp
qed

textA quotient-reminder theorem about integers greater than a given 
  product.

lemma (in int0) IntDiv_ZF_1_L5:
  assumes A1: "n  +" and A2: "n \<lsq> k" and A3: "kn \<lsq> m" 
  shows 
  "m = n(m zdiv n) \<ra> (m zmod n)"
  "m = (m zdiv n)n \<ra> (m zmod n)"
  "(m zmod n)  𝟬..(n\<rs>𝟭)"
  "k \<lsq> (m zdiv n)"  
  "m zdiv n  +"
proof -
  from A2 A3 have T: 
    "m"  "n"  "k"  "m zdiv n  "  
    using Int_ZF_2_L1A by auto
   then show "m = n(m zdiv n) \<ra> (m zmod n)"
     using IntDiv_ZF_1_L1 by simp
   with T show "m = (m zdiv n)n \<ra> (m zmod n)"
     using Int_ZF_1_L4 by simp
    from A1 have I: "𝟬\<lsq>n"  "n𝟬"
     using PositiveSet_def by auto
   with T show "(m zmod n)  𝟬..(n\<rs>𝟭)"
    using IntDiv_ZF_1_L2 Order_ZF_2_L1
    by simp
  from A3 I have "(kn zdiv n) \<lsq> (m zdiv n)"
    using IntDiv_ZF_1_L4 by simp
  with I T show "k \<lsq> (m zdiv n)"
    using IntDiv_ZF_1_L3 by simp
  with A1 A2 show "m zdiv n  +"
    using Int_ZF_1_5_L7 by blast
qed

  
end