The areas / V06. Rings, fields and ordered algebra
Mathlib.Algebra.Order.Round
31 declarations. Mathlib docs · Source
Rounding
This file defines the round function, which uses the floor or ceil function to round a number
to the nearest integer.
Main Definitions
round a: Nearest integer toa. It rounds halves towards infinity.
Tags
rounding
Round
def round E1 #
{α : Type u_2} → [inst : Ring α] → [inst_1 : LinearOrder α] → [FloorRing α] → α → ℤ
round x rounds x to the nearest integer, breaking ties towards positive infinity.
round (0.5 : ℚ) = 1.
theorem round_zero E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α], round 0 = 0
theorem round_one E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α], round 1 = 1
theorem round_natCast E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] (n : ℕ), round ↑n = ↑n
theorem round_ofNat E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] (n : ℕ) [inst_3 : n.AtLeastTwo],
round (OfNat.ofNat n) = OfNat.ofNat n
theorem round_intCast E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] (n : ℤ), round ↑n = n
theorem round_eq_div E1 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α),
round x = (⌊2 * x⌋ + 1) / 2
Formula for round in terms of Int.floor, a version that works over any ring.
TODO: decide if we want to use this as a definition. It may be slightly faster over ℚ.
theorem round_eq_half_ceil_two_mul E1 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] {x : α},
2 * Int.fract x ≠ 1 → round x = ⌈2 * x⌉ / 2
Away from the points with fractional part 1 / 2, round x = ⌈2 * x⌉ / 2.
theorem round_add_intCast E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α)
(y : ℤ), round (x + ↑y) = round x + y
theorem round_add_one E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (a : α),
round (a + 1) = round a + 1
theorem round_sub_intCast E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α)
(y : ℤ), round (x - ↑y) = round x - y
theorem round_sub_one E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (a : α),
round (a - 1) = round a - 1
theorem round_add_natCast E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α)
(y : ℕ), round (x + ↑y) = round x + ↑y
theorem round_add_ofNat E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α) (n : ℕ)
[inst_4 : n.AtLeastTwo], round (x + OfNat.ofNat n) = round x + OfNat.ofNat n
theorem round_sub_natCast E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α)
(y : ℕ), round (x - ↑y) = round x - ↑y
theorem round_sub_ofNat E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α) (n : ℕ)
[inst_4 : n.AtLeastTwo], round (x - OfNat.ofNat n) = round x - OfNat.ofNat n
theorem round_intCast_add E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α)
(y : ℤ), round (↑y + x) = y + round x
theorem round_natCast_add E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α)
(y : ℕ), round (↑y + x) = ↑y + round x
theorem round_ofNat_add E0 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (n : ℕ)
[inst_4 : n.AtLeastTwo] (x : α), round (OfNat.ofNat n + x) = OfNat.ofNat n + round x
theorem abs_sub_round_eq_min E1 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α),
|x - ↑(round x)| = min (Int.fract x) (1 - Int.fract x)
theorem round_le E1 #
∀ {α : Type u_2} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] [IsStrictOrderedRing α] (x : α)
(z : ℤ), |x - ↑(round x)| ≤ |x - ↑z|
theorem round_eq E0 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α] (x : α),
round x = ⌊x + 1 / 2⌋
theorem round_eq_iff E0 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α] {x : α}
{n : ℤ}, round x = n ↔ x ∈ Set.Ico (↑n - 1 / 2) (↑n + 1 / 2)
theorem round_two_inv E0 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α], round 2⁻¹ = 1
theorem round_neg_two_inv E0 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α],
round (-2⁻¹) = 0
theorem round_eq_zero_iff E0 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α] {x : α},
round x = 0 ↔ x ∈ Set.Ico (-(1 / 2)) (1 / 2)
theorem abs_sub_round E1 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α] (x : α),
|x - ↑(round x)| ≤ 1 / 2
theorem abs_sub_round_div_natCast_eq E0 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α] {m n : ℕ},
|↑m / ↑n - ↑(round (↑m / ↑n))| = ↑(min (m % n) (n - m % n)) / ↑n
theorem sub_half_lt_round E1 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α] (x : α),
x - 1 / 2 < ↑(round x)
theorem round_le_add_half E1 #
∀ {α : Type u_2} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α] [inst_3 : FloorRing α] (x : α),
↑(round x) ≤ x + 1 / 2
theorem Int.map_round E0 #
∀ {F : Type u_1} {α : Type u_2} {β : Type u_3} [inst : Field α] [inst_1 : LinearOrder α] [IsStrictOrderedRing α]
[inst_3 : Field β] [inst_4 : LinearOrder β] [IsStrictOrderedRing β] [inst_6 : FloorRing α] [inst_7 : FloorRing β]
[inst_8 : FunLike F α β] [RingHomClass F α β] (f : F), StrictMono ⇑f → ∀ (a : α), round (f a) = round a