Documentation

Mathlib.Data.Int.Init

Basic operations on the integers #

This file contains some basic lemmas about integers.

See note [foundational algebra order theory].

This file should not depend on anything defined in Mathlib (except for notation), so that it can be upstreamed to Batteries easily.

theorem Int.neg_eq_neg {a b : } (h : -a = -b) :
a = b

succ and pred #

def Int.succ (a : ) :

Immediate successor of an integer: succ n = n + 1

Equations
Instances For
    def Int.pred (a : ) :

    Immediate predecessor of an integer: pred n = n - 1

    Equations
    Instances For
      theorem Int.pred_succ (a : ) :
      a.succ.pred = a
      theorem Int.succ_pred (a : ) :
      a.pred.succ = a
      theorem Int.neg_succ (a : ) :
      -a.succ = (-a).pred
      theorem Int.succ_neg_succ (a : ) :
      (-a.succ).succ = -a
      theorem Int.neg_pred (a : ) :
      -a.pred = (-a).succ
      theorem Int.pred_neg_pred (a : ) :
      (-a.pred).pred = -a
      theorem Int.pred_nat_succ (n : ) :
      (↑n.succ).pred = n
      theorem Int.neg_nat_succ (n : ) :
      -n.succ = (-n).pred
      theorem Int.succ_neg_natCast_succ (n : ) :
      (-n.succ).succ = -n
      theorem Int.natCast_pred_of_pos {n : } (h : 0 < n) :
      ↑(n - 1) = n - 1
      theorem Int.lt_succ_self (a : ) :
      a < a.succ
      theorem Int.pred_self_lt (a : ) :
      a.pred < a
      theorem Int.induction_on {motive : Prop} (i : ) (zero : motive 0) (succ : ∀ (i : ), motive imotive (i + 1)) (pred : ∀ (i : ), motive (-i)motive (-i - 1)) :
      motive i

      Induction on integers: prove a proposition p i by proving the base case p 0, the upwards induction step p i → p (i + 1) and the downwards induction step p (-i) → p (-i - 1).

      It is used as the default induction principle for the induction tactic.

      def Int.inductionOn' {motive : Sort u_1} (z b : ) (zero : motive b) (succ : (k : ) → b kmotive kmotive (k + 1)) (pred : (k : ) → k bmotive kmotive (k - 1)) :
      motive z

      Inductively define a function on by defining it at b, for the succ of a number greater than b, and the pred of a number less than b.

      Equations
      Instances For
        def Int.inductionOn'.pos {motive : Sort u_1} (b : ) (zero : motive b) (succ : (k : ) → b kmotive kmotive (k + 1)) (n : ) :
        motive (b + n)

        The positive case of Int.inductionOn'.

        Equations
        Instances For
          def Int.inductionOn'.neg {motive : Sort u_1} (b : ) (zero : motive b) (pred : (k : ) → k bmotive kmotive (k - 1)) (n : ) :
          motive (b + negSucc n)

          The negative case of Int.inductionOn'.

          Equations
          Instances For
            theorem Int.inductionOn'_self {motive : Sort u_1} {b : } {zero : motive b} {succ : (k : ) → b kmotive kmotive (k + 1)} {pred : (k : ) → k bmotive kmotive (k - 1)} :
            Int.inductionOn' b b zero succ pred = zero
            theorem Int.inductionOn'_add_one {motive : Sort u_1} {z b : } {zero : motive b} {succ : (k : ) → b kmotive kmotive (k + 1)} {pred : (k : ) → k bmotive kmotive (k - 1)} (hz : b z) :
            Int.inductionOn' (z + 1) b zero succ pred = succ z hz (Int.inductionOn' z b zero succ pred)
            theorem Int.inductionOn'_sub_one {motive : Sort u_1} {z b : } {zero : motive b} {succ : (k : ) → b kmotive kmotive (k + 1)} {pred : (k : ) → k bmotive kmotive (k - 1)} (hz : z b) :
            Int.inductionOn' (z - 1) b zero succ pred = pred z hz (Int.inductionOn' z b zero succ pred)
            def Int.negInduction {motive : Sort u_1} (nat : (n : ) → motive n) (neg : ((n : ) → motive n)(n : ) → motive (-n)) (n : ) :
            motive n

            Inductively define a function on by defining it on and extending it from n to -n.

            Equations
            Instances For
              def Int.leInduction {m : } {motive : (n : ) → m nSort u_1} (base : motive m ) (succ : (n : ) → (hmn : m n) → motive n hmnmotive (n + 1) ) (n : ) (hmn : m n) :
              motive n hmn

              See Int.inductionOn' for an induction in both directions.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[deprecated Int.leInduction (since := "2026-03-25")]
                def Int.le_induction {m : } {motive : (n : ) → m nSort u_1} (base : motive m ) (succ : (n : ) → (hmn : m n) → motive n hmnmotive (n + 1) ) (n : ) (hmn : m n) :
                motive n hmn

                Alias of Int.leInduction.


                See Int.inductionOn' for an induction in both directions.

                Equations
                Instances For
                  theorem Int.leInduction_base {m : } {motive : (n : ) → m nSort u_1} (base : motive m ) (succ : (n : ) → (hmn : m n) → motive n hmnmotive (n + 1) ) :
                  Int.leInduction base succ m = base
                  theorem Int.leInduction_add_one {m : } {motive : (n : ) → m nSort u_1} (base : motive m ) (succ : (n : ) → (hmn : m n) → motive n hmnmotive (n + 1) ) (n : ) (hmn : m n) :
                  Int.leInduction base succ (n + 1) = succ n hmn (Int.leInduction base succ n hmn)
                  def Int.leInductionDown {m : } {motive : (n : ) → n mSort u_1} (base : motive m ) (pred : (n : ) → (hnm : n m) → motive n hnmmotive (n - 1) ) (n : ) (hnm : n m) :
                  motive n hnm

                  See Int.inductionOn' for an induction in both directions.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem Int.leInductionDown_base {m : } {motive : (n : ) → n mSort u_1} (base : motive m ) (pred : (n : ) → (hnm : n m) → motive n hnmmotive (n - 1) ) :
                    Int.leInductionDown base pred m = base
                    theorem Int.leInductionDown_sub_one {m : } {motive : (n : ) → n mSort u_1} (base : motive m ) (pred : (n : ) → (hnm : n m) → motive n hnmmotive (n - 1) ) (n : ) (hnm : n m) :
                    Int.leInductionDown base pred (n - 1) = pred n hnm (Int.leInductionDown base pred n hnm)
                    @[deprecated Int.leInductionDown (since := "2026-03-25")]
                    def Int.le_induction_down {m : } {motive : (n : ) → n mSort u_1} (base : motive m ) (pred : (n : ) → (hnm : n m) → motive n hnmmotive (n - 1) ) (n : ) (hnm : n m) :
                    motive n hnm

                    Alias of Int.leInductionDown.


                    See Int.inductionOn' for an induction in both directions.

                    Equations
                    Instances For
                      def Int.strongRec {m : } {motive : Sort u_1} (lt : (n : ) → n < mmotive n) (ge : (n : ) → n m((k : ) → k < nmotive k)motive n) (n : ) :
                      motive n

                      A strong recursor for Int that specifies explicit values for integers below a threshold, and is analogous to Nat.strongRec for integers on or above the threshold.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        theorem Int.strongRec_of_lt {m n : } {motive : Sort u_1} {lt : (n : ) → n < mmotive n} {ge : (n : ) → n m((k : ) → k < nmotive k)motive n} (hn : n < m) :
                        Int.strongRec lt ge n = lt n hn

                        mul #

                        natAbs #

                        theorem Int.natAbs_sq (a : ) :
                        a.natAbs ^ 2 = a ^ 2

                        Alias of Int.natAbs_pow_two.

                        / #

                        theorem Int.natCast_div (m n : ) :
                        ↑(m / n) = m / n
                        theorem Int.ediv_of_neg_of_pos {a b : } (Ha : a < 0) (Hb : 0 < b) :
                        a.ediv b = -((-a - 1) / b + 1)

                        mod #

                        @[simp]
                        theorem Int.natCast_mod (m n : ) :
                        ↑(m % n) = m % n
                        theorem Int.div_le_iff_of_dvd_of_pos {a b c : } (hb : 0 < b) (hba : b a) :
                        a / b c a b * c
                        theorem Int.div_le_iff_of_dvd_of_neg {a b c : } (hb : b < 0) (hba : b a) :
                        a / b c b * c a
                        theorem Int.div_lt_iff_of_dvd_of_pos {a b c : } (hb : 0 < b) (hba : b a) :
                        a / b < c a < b * c
                        theorem Int.div_lt_iff_of_dvd_of_neg {a b c : } (hb : b < 0) (hba : b a) :
                        a / b < c b * c < a
                        theorem Int.le_div_iff_of_dvd_of_pos {a b c : } (hc : 0 < c) (hcb : c b) :
                        a b / c c * a b
                        theorem Int.le_div_iff_of_dvd_of_neg {a b c : } (hc : c < 0) (hcb : c b) :
                        a b / c b c * a
                        theorem Int.lt_div_iff_of_dvd_of_pos {a b c : } (hc : 0 < c) (hcb : c b) :
                        a < b / c c * a < b
                        theorem Int.lt_div_iff_of_dvd_of_neg {a b c : } (hc : c < 0) (hcb : c b) :
                        a < b / c b < c * a
                        theorem Int.div_le_div_iff_of_dvd_of_pos_of_pos {a b c d : } (hb : 0 < b) (hd : 0 < d) (hba : b a) (hdc : d c) :
                        a / b c / d d * a c * b
                        theorem Int.div_le_div_iff_of_dvd_of_pos_of_neg {a b c d : } (hb : 0 < b) (hd : d < 0) (hba : b a) (hdc : d c) :
                        a / b c / d c * b d * a
                        theorem Int.div_le_div_iff_of_dvd_of_neg_of_pos {a b c d : } (hb : b < 0) (hd : 0 < d) (hba : b a) (hdc : d c) :
                        a / b c / d c * b d * a
                        theorem Int.div_le_div_iff_of_dvd_of_neg_of_neg {a b c d : } (hb : b < 0) (hd : d < 0) (hba : b a) (hdc : d c) :
                        a / b c / d d * a c * b
                        theorem Int.div_lt_div_iff_of_dvd_of_pos {a b c d : } (hb : 0 < b) (hd : 0 < d) (hba : b a) (hdc : d c) :
                        a / b < c / d d * a < c * b
                        theorem Int.div_lt_div_iff_of_dvd_of_pos_of_neg {a b c d : } (hb : 0 < b) (hd : d < 0) (hba : b a) (hdc : d c) :
                        a / b < c / d c * b < d * a
                        theorem Int.div_lt_div_iff_of_dvd_of_neg_of_pos {a b c d : } (hb : b < 0) (hd : 0 < d) (hba : b a) (hdc : d c) :
                        a / b < c / d c * b < d * a
                        theorem Int.div_lt_div_iff_of_dvd_of_neg_of_neg {a b c d : } (hb : b < 0) (hd : d < 0) (hba : b a) (hdc : d c) :
                        a / b < c / d d * a < c * b

                        properties of / and % #

                        theorem Int.emod_two_eq_zero_or_one (n : ) :
                        n % 2 = 0 n % 2 = 1

                        dvd #

                        theorem Int.dvd_mul_of_div_dvd {a b c : } (h : b a) (hdiv : a / b c) :
                        a b * c
                        theorem Int.div_dvd_iff_dvd_mul {a b c : } (h : b a) (hb : b 0) :
                        a / b c a b * c
                        theorem Int.mul_dvd_of_dvd_div {a b c : } (hcb : c b) (h : a b / c) :
                        c * a b
                        theorem Int.dvd_div_of_mul_dvd {a b c : } (h : a * b c) :
                        b c / a
                        theorem Int.dvd_div_iff_mul_dvd {a b c : } (hbc : c b) :
                        a b / c c * a b
                        theorem Int.exists_lt_and_lt_iff_not_dvd {n : } (m : ) (hn : 0 < n) :
                        ( (k : ), n * k < m m < n * (k + 1)) ¬n m

                        If n > 0 then m is not divisible by n iff it is between n * k and n * (k + 1) for some k.

                        theorem Int.eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : } (hb : b 0) (hbc : b c) (h : b * a = c * d) :
                        a = c / b * d
                        theorem Int.ofNat_add_negSucc_of_ge {m n : } (h : n.succ m) :
                        ofNat m + negSucc n = ofNat (m - n.succ)

                        / and ordering #

                        theorem Int.le_iff_pos_of_dvd {a b : } (ha : 0 < a) (hab : a b) :
                        a b 0 < b
                        theorem Int.le_add_iff_lt_of_dvd_sub {a b c : } (ha : 0 < a) (hab : a c - b) :
                        a + b c b < c

                        sign #

                        theorem Int.sign_add_eq_of_sign_eq {m n : } :
                        m.sign = n.sign(m + n).sign = n.sign

                        toNat #

                        @[simp]
                        theorem Int.toNat_pred_coe_of_pos {i : } (h : 0 < i) :
                        ↑(i.toNat - 1) = i - 1
                        theorem Int.toNat_lt_of_ne_zero {m : } {n : } (hn : n 0) :
                        m.toNat < n m < n
                        def Int.natMod (m n : ) :

                        The modulus of an integer by another as a natural. Uses the E-rounding convention.

                        Equations
                        Instances For
                          theorem Int.natMod_lt {m : } {n : } (hn : n 0) :
                          m.natMod n < n
                          @[simp]
                          theorem Int.pow_eq (m : ) (n : ) :
                          m.pow n = m ^ n

                          For use in Mathlib/Tactic/NormNum/Pow.lean

                          @[simp]
                          theorem Int.gcd_ofNat_negSucc (m n : ) :
                          (↑m).gcd (negSucc n) = m.gcd (n + 1)
                          @[simp]
                          theorem Int.gcd_negSucc_ofNat (m n : ) :
                          (negSucc m).gcd n = (m + 1).gcd n
                          @[simp]
                          theorem Int.gcd_negSucc_negSucc (m n : ) :
                          (negSucc m).gcd (negSucc n) = (m + 1).gcd (n + 1)