The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V06. Rings, fields and ordered algebra

Mathlib.Algebra.Order.Floor.Defs

78 declarations. Mathlib docs · Source

Floor and ceil

We define the natural- and integer-valued floor and ceil functions on linearly ordered rings. We also provide positivity extensions to handle floor and ceil.

Main definitions

  • FloorSemiring: An ordered semiring with natural-valued floor and ceil.

  • Nat.floor a: Greatest natural n such that n ≤ a. Equal to 0 if a < 0.

  • Nat.ceil a: Least natural n such that a ≤ n.

  • FloorRing: A linearly ordered ring with integer-valued floor and ceil.

  • Int.floor a: Greatest integer z such that z ≤ a.

  • Int.ceil a: Least integer z such that a ≤ z.

  • Int.fract a: Fractional part of a, defined as a - floor a.

Notation

  • ⌊a⌋₊ is Nat.floor a.
  • ⌈a⌉₊ is Nat.ceil a.
  • ⌊a⌋ is Int.floor a.
  • ⌈a⌉ is Int.ceil a.

The index ₊ in the notations for Nat.floor and Nat.ceil is used in analogy to the notation for nnNorm.

TODO

LinearOrder can be relaxed to PartialOrder in many lemmas.

Tags

rounding, floor, ceil

Floor semiring

Floor rings

Floor

Ceil

A floor ring as a floor semiring

Int.cast is strictly monotone on floor rings

def FloorRing.ctorIdx E1 #

{α : Type u_3} → {inst : Ring α} → {inst_1 : LinearOrder α} → FloorRing α → ℕ

def FloorSemiring.ctorIdx E1 #

{α : Type u_3} → {inst : Semiring α} → {inst_1 : PartialOrder α} → FloorSemiring α → ℕ

class FloorSemiring E3 #

(α : Type u_3) → [Semiring α] → [PartialOrder α] → Type u_3

A FloorSemiring is an ordered semiring over α with a function floor : α → ℕ satisfying ∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x. Note that many lemmas require a LinearOrder. Please see the above TODO.

ctor FloorSemiring.mk E0 #

{α : Type u_3} →
  [inst : Semiring α] →
    [inst_1 : PartialOrder α] →
      (floor ceil : α → ℕ) →
        (∀ {a : α}, a < 0 → floor a = 0) →
          (∀ {a : α} {n : ℕ}, 0 ≤ a → (n ≤ floor a ↔ ↑n ≤ a)) → GaloisConnection ceil Nat.cast → FloorSemiring α

abbrev FloorSemiring.floor E1 #

{α : Type u_3} → {inst : Semiring α} → {inst_1 : PartialOrder α} → [self : FloorSemiring α] → α → ℕ

FloorSemiring.floor a computes the greatest natural n such that (n : α) ≤ a.

abbrev FloorSemiring.ceil E1 #

{α : Type u_3} → {inst : Semiring α} → {inst_1 : PartialOrder α} → [self : FloorSemiring α] → α → ℕ

FloorSemiring.ceil a computes the least natural n such that a ≤ (n : α).

theorem FloorSemiring.floor_of_neg E1 #

∀ {α : Type u_3} {inst : Semiring α} {inst_1 : PartialOrder α} [self : FloorSemiring α] {a : α},
  a < 0 → FloorSemiring.floor a = 0

FloorSemiring.floor of a negative element is zero.

theorem FloorSemiring.gc_floor E1 #

∀ {α : Type u_3} {inst : Semiring α} {inst_1 : PartialOrder α} [self : FloorSemiring α] {a : α} {n : ℕ},
  0 ≤ a → (n ≤ FloorSemiring.floor a ↔ ↑n ≤ a)

A natural number n is smaller than FloorSemiring.floor a iff its coercion to α is smaller than a.

theorem FloorSemiring.gc_ceil E1 #

∀ {α : Type u_3} {inst : Semiring α} {inst_1 : PartialOrder α} [self : FloorSemiring α],
  GaloisConnection FloorSemiring.ceil Nat.cast

FloorSemiring.ceil is the lower adjoint of the coercion ↑ : ℕ → α.

instance instFloorSemiringNat E0 #

FloorSemiring ℕ

theorem FloorSemiring.natCast_mono E1 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [FloorSemiring α], Monotone Nat.cast

A version of Nat.mono_cast for floor semirings, whose addition is not necessarily monotone.

theorem FloorSemiring.natCast_nonneg E1 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [FloorSemiring α] (n : ℕ), 0 ≤ ↑n

A version of Nat.cast_nonneg' for floor semirings, whose addition is not necessarily monotone.

theorem FloorSemiring.natCast_strictMono E1 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [FloorSemiring α], StrictMono Nat.cast

A version of Nat.strictMono_cast for floor semirings, whose addition is not necessarily monotone.

theorem FloorSemiring.natCast_pos E1 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [FloorSemiring α] {n : ℕ}, 0 < ↑n ↔ 0 < n

theorem FloorSemiring.natCast_lt_iff E0 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [FloorSemiring α] {m n : ℕ}, ↑m < ↑n ↔ m < n

theorem FloorSemiring.natCast_le_iff E0 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [FloorSemiring α] {m n : ℕ}, ↑m ≤ ↑n ↔ m ≤ n

instance FloorSemiring.instZeroLEOneClass E0 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [FloorSemiring α], ZeroLEOneClass α

instance FloorSemiring.instCharZero E0 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [FloorSemiring α], CharZero α

def Nat.floor E1 #

{α : Type u_1} → [inst : Semiring α] → [inst_1 : PartialOrder α] → [FloorSemiring α] → α → ℕ

⌊a⌋₊ is the greatest natural n such that n ≤ a. If a is negative, then ⌊a⌋₊ = 0.

def Nat.ceil E1 #

{α : Type u_1} → [inst : Semiring α] → [inst_1 : PartialOrder α] → [FloorSemiring α] → α → ℕ

⌈a⌉₊ is the least natural n such that a ≤ n

theorem Nat.floor_nat E0 #

Nat.floor = id

theorem Nat.ceil_nat E0 #

Nat.ceil = id

def Nat.«term⌊_⌋₊» E1 #

Lean.ParserDescr

⌊a⌋₊ is the greatest natural n such that n ≤ a. If a is negative, then ⌊a⌋₊ = 0.

def Nat.«term⌈_⌉₊» E1 #

Lean.ParserDescr

⌈a⌉₊ is the least natural n such that a ≤ n

theorem Nat.le_floor_iff E0 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [inst_2 : FloorSemiring α] {a : α} {n : ℕ},
  0 ≤ a → (n ≤ ⌊a⌋₊ ↔ ↑n ≤ a)

theorem Nat.le_floor E1 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [inst_2 : FloorSemiring α] {a : α} {n : ℕ},
  ↑n ≤ a → n ≤ ⌊a⌋₊

theorem Nat.gc_ceil_coe E0 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [inst_2 : FloorSemiring α],
  GaloisConnection Nat.ceil Nat.cast

theorem Nat.ceil_le E0 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : PartialOrder α] [inst_2 : FloorSemiring α] {a : α} {n : ℕ},
  ⌈a⌉₊ ≤ n ↔ a ≤ ↑n

theorem Nat.lt_ceil E1 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : LinearOrder α] [inst_2 : FloorSemiring α] {a : α} {n : ℕ},
  n < ⌈a⌉₊ ↔ ↑n < a

theorem Nat.ceil_pos E0 #

∀ {α : Type u_1} [inst : Semiring α] [inst_1 : LinearOrder α] [inst_2 : FloorSemiring α] {a : α}, 0 < ⌈a⌉₊ ↔ 0 < a

class FloorRing E3 #

(α : Type u_3) → [Ring α] → [LinearOrder α] → Type u_3

A FloorRing is a linear ordered ring over α with a function floor : α → ℤ satisfying ∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a.

ctor FloorRing.mk E0 #

{α : Type u_3} →
  [inst : Ring α] →
    [inst_1 : LinearOrder α] →
      (floor ceil : α → ℤ) → GaloisConnection Int.cast floor → GaloisConnection ceil Int.cast → FloorRing α

abbrev FloorRing.floor E1 #

{α : Type u_3} → {inst : Ring α} → {inst_1 : LinearOrder α} → [self : FloorRing α] → α → ℤ

FloorRing.floor a computes the greatest integer z such that (z : α) ≤ a.

abbrev FloorRing.ceil E1 #

{α : Type u_3} → {inst : Ring α} → {inst_1 : LinearOrder α} → [self : FloorRing α] → α → ℤ

FloorRing.ceil a computes the least integer z such that a ≤ (z : α).

theorem FloorRing.gc_coe_floor E1 #

∀ {α : Type u_3} {inst : Ring α} {inst_1 : LinearOrder α} [self : FloorRing α],
  GaloisConnection Int.cast FloorRing.floor

FloorRing.ceil is the upper adjoint of the coercion ↑ : ℤ → α.

theorem FloorRing.gc_ceil_coe E0 #

∀ {α : Type u_3} {inst : Ring α} {inst_1 : LinearOrder α} [self : FloorRing α], GaloisConnection FloorRing.ceil Int.cast

FloorRing.ceil is the lower adjoint of the coercion ↑ : ℤ → α.

instance instFloorRingInt E0 #

FloorRing ℤ

def FloorRing.ofFloor E1 #

(α : Type u_3) →
  [inst : Ring α] →
    [inst_1 : LinearOrder α] → [IsOrderedAddMonoid α] → (floor : α → ℤ) → GaloisConnection Int.cast floor → FloorRing α

A FloorRing constructor from the floor function alone.

def FloorRing.ofCeil E1 #

(α : Type u_3) →
  [inst : Ring α] →
    [inst_1 : LinearOrder α] → [IsOrderedAddMonoid α] → (ceil : α → ℤ) → GaloisConnection ceil Int.cast → FloorRing α

A FloorRing constructor from the ceil function alone.

theorem exists_floor' E1 #

∀ {α : Type u_3} [inst : Ring α] [inst_1 : PartialOrder α] [IsOrderedRing α] [Nontrivial α] (x : α),
  (∃ n, ↑n ≤ x) → (∃ n, x ≤ ↑n) → ∃ fl, ∀ (z : ℤ), z ≤ fl ↔ ↑z ≤ x

See exists_floor for a variant which instead assumes an Archimedean ring.

def FloorRing.ofBounded E1 #

(α : Type u_3) →
  [inst : Ring α] →
    [inst_1 : LinearOrder α] → [IsOrderedRing α] → [Nontrivial α] → (∀ (x : α), ∃ n, x ≤ ↑n) → FloorRing α

Construct a FloorRing instance noncomputably, from the hypothesis that every element is bounded above by a natural number.

def Int.floor E1 #

{α : Type u_1} → [inst : Ring α] → [inst_1 : LinearOrder α] → [FloorRing α] → α → ℤ

Int.floor a is the greatest integer z such that z ≤ a. It is denoted with ⌊a⌋.

def Int.ceil E1 #

{α : Type u_1} → [inst : Ring α] → [inst_1 : LinearOrder α] → [FloorRing α] → α → ℤ

Int.ceil a is the smallest integer z such that a ≤ z. It is denoted with ⌈a⌉.

def Int.fract E1 #

{α : Type u_1} → [inst : Ring α] → [inst_1 : LinearOrder α] → [FloorRing α] → α → α

Int.fract a the fractional part of a, is a minus its floor.

theorem Int.floor_int E0 #

Int.floor = id

theorem Int.ceil_int E0 #

Int.ceil = id

theorem Int.fract_int E0 #

Int.fract = 0

def Int.«term⌊_⌋» E1 #

Lean.ParserDescr

Int.floor a is the greatest integer z such that z ≤ a. It is denoted with ⌊a⌋.

def Int.«term⌈_⌉» E1 #

Lean.ParserDescr

Int.ceil a is the smallest integer z such that a ≤ z. It is denoted with ⌈a⌉.

theorem Int.floorRing_floor_eq E0 #

@FloorRing.floor = @Int.floor

theorem Int.floorRing_ceil_eq E0 #

@FloorRing.ceil = @Int.ceil

theorem Int.gc_coe_floor E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α], GaloisConnection Int.cast Int.floor

theorem Int.le_floor E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {z : ℤ} {a : α}, z ≤ ⌊a⌋ ↔ ↑z ≤ a

theorem Int.floor_lt E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {z : ℤ} {a : α}, ⌊a⌋ < z ↔ a < ↑z

theorem Int.floor_le E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] (a : α), ↑⌊a⌋ ≤ a

theorem Int.floor_le_iff E0 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {z : ℤ} {a : α}, ⌊a⌋ ≤ z ↔ a < ↑z + 1

theorem Int.lt_floor_iff E0 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {z : ℤ} {a : α}, z < ⌊a⌋ ↔ ↑z + 1 ≤ a

theorem Int.floor_nonneg E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {a : α}, 0 ≤ ⌊a⌋ ↔ 0 ≤ a

theorem Int.floor_lt_zero E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {a : α}, ⌊a⌋ < 0 ↔ a < 0

theorem Int.gc_ceil_coe E0 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α], GaloisConnection Int.ceil Int.cast

theorem Int.ceil_le E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {z : ℤ} {a : α}, ⌈a⌉ ≤ z ↔ a ≤ ↑z

theorem Int.lt_ceil E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {z : ℤ} {a : α}, z < ⌈a⌉ ↔ ↑z < a

theorem Int.le_ceil E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] (a : α), a ≤ ↑⌈a⌉

theorem Int.le_ceil_iff E0 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {z : ℤ} {a : α}, z ≤ ⌈a⌉ ↔ ↑z - 1 < a

theorem Int.ceil_lt_iff E0 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {z : ℤ} {a : α}, ⌈a⌉ < z ↔ a ≤ ↑z - 1

theorem Int.ceil_nonpos E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {a : α}, ⌈a⌉ ≤ 0 ↔ a ≤ 0

theorem Int.ceil_pos E0 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {a : α}, 0 < ⌈a⌉ ↔ 0 < a

instance FloorRing.toFloorSemiring E0 #

{α : Type u_1} → [inst : Ring α] → [inst_1 : LinearOrder α] → [FloorRing α] → FloorSemiring α

theorem Int.floor_toNat E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] (a : α), ⌊a⌋.toNat = ⌊a⌋₊

theorem Int.ceil_toNat E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] (a : α), ⌈a⌉.toNat = ⌈a⌉₊

theorem Nat.floor_int E0 #

Nat.floor = Int.toNat

theorem Nat.ceil_int E0 #

Nat.ceil = Int.toNat

theorem FloorRing.intCast_mono E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [FloorRing α], Monotone Int.cast

A version of Int.cast_mono for floor rings, whose addition is not necessarily monotone.

theorem FloorRing.intCast_strictMono E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [FloorRing α], StrictMono Int.cast

A version of Int.cast_strictMono for floor rings, whose addition is not necessarily monotone.

theorem FloorRing.intCast_lt_iff E0 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [FloorRing α] {m n : ℤ}, ↑m < ↑n ↔ m < n

theorem FloorRing.intCast_le_iff E0 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [FloorRing α] {m n : ℤ}, ↑m ≤ ↑n ↔ m ≤ n

theorem Int.ceil_nonneg E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {a : α}, 0 ≤ a → 0 ≤ ⌈a⌉

theorem Int.floor_nonpos E1 #

∀ {α : Type u_1} [inst : Ring α] [inst_1 : LinearOrder α] [inst_2 : FloorRing α] {a : α}, a ≤ 0 → ⌊a⌋ ≤ 0