Built with
doc-gen4 , running Lean4.
Bubbles (
) indicate interactive fragments: hover for details, tap to reveal contents.
Use
Ctrl+โ Ctrl+โ to navigate,
Ctrl+๐ฑ๏ธ to focus.
On Mac, use
Cmd instead of
Ctrl .
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
! This file was ported from Lean 3 source module data.int.lemmas
! leanprover-community/mathlib commit 09597669f02422ed388036273d8848119699c22f
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Set.Function
import Mathlib.Data.Int.Order.Lemmas
import Mathlib.Data.Int.Bitwise
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Data.Nat.Order.Lemmas
/-!
# Miscellaneous lemmas about the integers
This file contains lemmas about integers, which require further imports than
`Data.Int.Basic` or `Data.Int.Order`.
-/
open Nat
namespace Int
theorem le_coe_nat_sub : โ (m n : โ ), โm - โn โค โ(m - n ) le_coe_nat_sub ( m n : โ ) : ( m - n : โค ) โค โ( m - n : โ ) := by
โm - โn โค โ(m - n ) by_cases h : m โฅ n pos โm - โn โค โ(m - n ) neg โm - โn โค โ(m - n )
โm - โn โค โ(m - n ) ยท pos โm - โn โค โ(m - n ) pos โm - โn โค โ(m - n ) neg โm - โn โค โ(m - n ) exact le_of_eq : โ {ฮฑ : Type ?u.302} [inst : Preorder ฮฑ ] {a b : ฮฑ }, a = b โ a โค b le_of_eq ( Int.ofNat_sub : โ {m n : โ }, m โค n โ โ(n - m ) = โn - โm Int.ofNat_sub h ). symm : โ {ฮฑ : Sort ?u.374} {a b : ฮฑ }, a = b โ b = a symm
โm - โn โค โ(m - n ) ยท neg โm - โn โค โ(m - n ) neg โm - โn โค โ(m - n ) simp [ le_of_not_ge h , ofNat_le ]
#align int.le_coe_nat_sub Int.le_coe_nat_sub : โ (m n : โ ), โm - โn โค โ(m - n ) Int.le_coe_nat_sub
/-! ### `succ` and `pred` -/
-- Porting note: simp can prove this @[simp]
theorem succ_coe_nat_pos : โ (n : โ ), 0 < โn + 1 succ_coe_nat_pos ( n : โ ) : 0 < ( n : โค ) + 1 :=
lt_add_one_iff . mpr : โ {a b : Prop }, (a โ b ) โ b โ a mpr ( by simp )
#align int.succ_coe_nat_pos Int.succ_coe_nat_pos : โ (n : โ ), 0 < โn + 1 Int.succ_coe_nat_pos
/-! ### `natAbs` -/
variable { a b : โค } { n : โ }
theorem natAbs_eq_iff_sq_eq { a b : โค } : a . natAbs = b . natAbs โ a ^ 2 = b ^ 2 := by
rw [ sq : โ {M : Type ?u.2278} [inst : Monoid M ] (a : M ), a ^ 2 = a * a sq, sq : โ {M : Type ?u.2334} [inst : Monoid M ] (a : M ), a ^ 2 = a * a sq]
exact natAbs_eq_iff_mul_self_eq
#align int.nat_abs_eq_iff_sq_eq Int.natAbs_eq_iff_sq_eq
theorem natAbs_lt_iff_sq_lt { a b : โค } : a . natAbs < b . natAbs โ a ^ 2 < b ^ 2 := by
rw [ sq : โ {M : Type ?u.2787} [inst : Monoid M ] (a : M ), a ^ 2 = a * a sq, sq : โ {M : Type ?u.2843} [inst : Monoid M ] (a : M ), a ^ 2 = a * a sq]
exact natAbs_lt_iff_mul_self_lt
#align int.nat_abs_lt_iff_sq_lt Int.natAbs_lt_iff_sq_lt
theorem natAbs_le_iff_sq_le { a b : โค } : a . natAbs โค b . natAbs โ a ^ 2 โค b ^ 2 := by
rw [ sq : โ {M : Type ?u.3312} [inst : Monoid M ] (a : M ), a ^ 2 = a * a sq, sq : โ {M : Type ?u.3368} [inst : Monoid M ] (a : M ), a ^ 2 = a * a sq]
exact natAbs_le_iff_mul_self_le
#align int.nat_abs_le_iff_sq_le Int.natAbs_le_iff_sq_le
theorem natAbs_inj_of_nonneg_of_nonneg { a b : โค } ( ha : 0 โค a ) ( hb : 0 โค b ) :
natAbs a = natAbs b โ a = b := by rw [ โ sq_eq_sq ha hb , โ natAbs_eq_iff_sq_eq ]
#align int.nat_abs_inj_of_nonneg_of_nonneg Int.natAbs_inj_of_nonneg_of_nonneg
theorem natAbs_inj_of_nonpos_of_nonpos { a b : โค } ( ha : a โค 0 ) ( hb : b โค 0 ) :
natAbs a = natAbs b โ a = b := by
simpa only [ Int.natAbs_neg , neg_inj ] using
natAbs_inj_of_nonneg_of_nonneg ( neg_nonneg_of_nonpos ha ) ( neg_nonneg_of_nonpos hb )
#align int.nat_abs_inj_of_nonpos_of_nonpos Int.natAbs_inj_of_nonpos_of_nonpos
theorem natAbs_inj_of_nonneg_of_nonpos { a b : โค } ( ha : 0 โค a ) ( hb : b โค 0 ) :
natAbs a = natAbs b โ a = - b := by
simpa only [ Int.natAbs_neg ] using natAbs_inj_of_nonneg_of_nonneg ha ( neg_nonneg_of_nonpos hb )
#align int.nat_abs_inj_of_nonneg_of_nonpos Int.natAbs_inj_of_nonneg_of_nonpos
theorem natAbs_inj_of_nonpos_of_nonneg { a b : โค } ( ha : a โค 0 ) ( hb : 0 โค b ) :
natAbs a = natAbs b โ - a = b := by
simpa only [ Int.natAbs_neg ] using natAbs_inj_of_nonneg_of_nonneg ( neg_nonneg_of_nonpos ha ) hb
#align int.nat_abs_inj_of_nonpos_of_nonneg Int.natAbs_inj_of_nonpos_of_nonneg
section Intervals
open Set
theorem strictMonoOn_natAbs : StrictMonoOn natAbs ( Ici 0 ) := fun _ ha _ _ hab =>
natAbs_lt_natAbs_of_nonneg_of_lt ha hab
#align int.strict_mono_on_nat_abs Int.strictMonoOn_natAbs
theorem strictAntiOn_natAbs : StrictAntiOn natAbs ( Iic 0 ) := fun a _ b hb hab => by
simpa [ Int.natAbs_neg ] using
natAbs_lt_natAbs_of_nonneg_of_lt ( Right.nonneg_neg_iff . mpr : โ {a b : Prop }, (a โ b ) โ b โ a mpr hb ) ( neg_lt_neg_iff . mpr : โ {a b : Prop }, (a โ b ) โ b โ a mpr hab )
#align int.strict_anti_on_nat_abs Int.strictAntiOn_natAbs
theorem injOn_natAbs_Ici : InjOn : {ฮฑ : Type ?u.6773} โ {ฮฒ : Type ?u.6772} โ (ฮฑ โ ฮฒ ) โ Set ฮฑ โ Prop InjOn natAbs ( Ici 0 ) :=
strictMonoOn_natAbs . injOn
#align int.inj_on_nat_abs_Ici Int.injOn_natAbs_Ici
theorem injOn_natAbs_Iic : InjOn : {ฮฑ : Type ?u.6957} โ {ฮฒ : Type ?u.6956} โ (ฮฑ โ ฮฒ ) โ Set ฮฑ โ Prop InjOn natAbs ( Iic 0 ) :=
strictAntiOn_natAbs . injOn
#align int.inj_on_nat_abs_Iic Int.injOn_natAbs_Iic
end Intervals
/-! ### `toNat` -/
theorem toNat_of_nonpos : โ { z : โค }, z โค 0 โ z . toNat = 0
| 0 , _ => rfl : โ {ฮฑ : Sort ?u.7219} {a : ฮฑ }, a = a rfl
| ( n + 1 : โ), h => ( h . not_lt ( by simp )). elim
| -[ n +1], _ => rfl : โ {ฮฑ : Sort ?u.7445} {a : ฮฑ }, a = a rfl
#align int.to_nat_of_nonpos Int.toNat_of_nonpos
/-! ### bitwise ops
This lemma is orphaned from `Data.Int.Bitwise` as it also requires material from `Data.Int.Order`.
-/
attribute [ local simp ] Int.zero_div : โ (b : โค ), div 0 b = 0 Int.zero_div
@[ simp ]
theorem div2_bit ( b n ) : div2 ( bit b n ) = n := by
rw [ bit_val : โ (b : Bool ) (n : โค ), bit b n = 2 * n + bif b then 1 else 0 bit_val, div2 (2 * n + bif b then 1 else 0 ) = n div2_val , (2 * n + bif b then 1 else 0 ) / 2 = n add_comm , ((bif b then 1 else 0 ) + 2 * n ) / 2 = n Int.add_mul_ediv_left : โ (a : โค ) {b : โค } (c : โค ), b โ 0 โ (a + b * c ) / b = a / b + c Int.add_mul_ediv_left, (bif b then 1 else 0 ) / 2 + n = n H ( _ : ( _ / 2 : โค ) = 0 ), (bif b then 1 else 0 ) / 2 = 0 H zero_add (bif b then 1 else 0 ) / 2 = 0 H ] (bif b then 1 else 0 ) / 2 = 0 H
cases b false true (bif true then 1 else 0 ) / 2 = 0 H
ยท false true (bif true then 1 else 0 ) / 2 = 0 H simp
ยท true (bif true then 1 else 0 ) / 2 = 0 true (bif true then 1 else 0 ) / 2 = 0 H show ofNat _ = _
true (bif true then 1 else 0 ) / 2 = 0 rw [ Nat.div_eq_zero : โ {a b : โ }, a < b โ a / b = 0 Nat.div_eq_zero] <;> simp
ยท decide
#align int.div2_bit Int.div2_bit
end Int