Flooring, ceiling division #
This file defines division rounded up and down.
The setup is an ordered monoid α acting on an ordered monoid β. If a : α, b : β, we would
like to be able to "divide" b by a, namely find c : β such that a • c = b.
This is of course not always possible, but in some cases at least there is a least c such that
b ≤ a • c and a greatest c such that a • c ≤ b. We call the first one the "ceiling division
of b by a" and the second one the "flooring division of b by a"
If α and β are both ℕ, then one can check that our flooring and ceiling divisions really are
the floor and ceil of the exact division.
If α is ℕ and β is the functions ι → ℕ, then the flooring and ceiling divisions are taken
pointwise.
In order theory terms, those operations are respectively the right and left adjoints to the map
b ↦ a • b.
Main declarations #
FloorDiv: Typeclass for the existence of a flooring division, denotedb ⌊/⌋ a.CeilDiv: Typeclass for the existence of a ceiling division, denotedb ⌈/⌉ a.
Note in both cases we only allow dividing by positive inputs. We enforce the following junk values:
b ⌊/⌋ a = b ⌈/⌉ a = 0ifa ≤ 00 ⌊/⌋ a = 0 ⌈/⌉ a = 0
Notation #
b ⌊/⌋ afor the flooring division ofbbyab ⌈/⌉ afor the ceiling division ofbbya
TODO #
norm_numextension- Prove
⌈a / b⌉ = a ⌈/⌉ bwhena, b : ℕ
Typeclass for division rounded down. For each a > 0, this asserts the existence of a right
adjoint to the map b ↦ a • b : β → β.
- floorDiv : β → α → β
Flooring division. If
a > 0, thenb ⌊/⌋ ais the greatestcsuch thata • c ≤ b. - floorDiv_gc ⦃a : α⦄ : 0 < a → GaloisConnection (fun (x : β) => a • x) fun (x : β) => x ⌊/⌋ a
Do not use this. Use
gc_floorDiv_smulorgc_floorDiv_mulinstead. Do not use this. Use
floorDiv_nonposinstead.Do not use this. Use
zero_floorDivinstead.
Instances
Typeclass for division rounded up. For each a > 0, this asserts the existence of a left
adjoint to the map b ↦ a • b : β → β.
- ceilDiv : β → α → β
Ceiling division. If
a > 0, thenb ⌈/⌉ ais the leastcsuch thatb ≤ a • c. - ceilDiv_gc ⦃a : α⦄ : 0 < a → GaloisConnection (fun (x : β) => x ⌈/⌉ a) fun (x : β) => a • x
Do not use this. Use
gc_smul_ceilDivorgc_mul_ceilDivinstead. Do not use this. Use
ceilDiv_nonposinstead.Do not use this. Use
zero_ceilDivinstead.
Instances
Flooring division. If a > 0, then b ⌊/⌋ a is the greatest c such that a • c ≤ b.
Equations
- «term_⌊/⌋_» = Lean.ParserDescr.trailingNode `«term_⌊/⌋_» 70 70 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⌊/⌋ ") (Lean.ParserDescr.cat `term 71))
Instances For
Ceiling division. If a > 0, then b ⌈/⌉ a is the least c such that b ≤ a • c.
Equations
- «term_⌈/⌉_» = Lean.ParserDescr.trailingNode `«term_⌈/⌉_» 70 70 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⌈/⌉ ") (Lean.ParserDescr.cat `term 71))
Instances For
Equations
- Nat.instFloorDiv = { floorDiv := HDiv.hDiv, floorDiv_gc := Nat.instFloorDiv._proof_1, floorDiv_nonpos := Nat.instFloorDiv._proof_2, zero_floorDiv := Nat.zero_div }
Equations
- Nat.instCeilDiv = { ceilDiv := fun (a b : ℕ) => (a + b - 1) / b, ceilDiv_gc := Nat.instCeilDiv._proof_2, ceilDiv_nonpos := Nat.instCeilDiv._proof_3, zero_ceilDiv := Nat.instCeilDiv._proof_4 }
Equations
- Pi.instFloorDiv = { floorDiv := fun (f : (i : ι) → π i) (a : α) (i : ι) => f i ⌊/⌋ a, floorDiv_gc := ⋯, floorDiv_nonpos := ⋯, zero_floorDiv := ⋯ }
Equations
- Pi.instCeilDiv = { ceilDiv := fun (f : (i : ι) → π i) (a : α) (i : ι) => f i ⌈/⌉ a, ceilDiv_gc := ⋯, ceilDiv_nonpos := ⋯, zero_ceilDiv := ⋯ }
Equations
- Finsupp.instFloorDiv = { floorDiv := fun (f : ι →₀ β) (a : α) => Finsupp.mapRange (fun (x : β) => x ⌊/⌋ a) ⋯ f, floorDiv_gc := ⋯, floorDiv_nonpos := ⋯, zero_floorDiv := ⋯ }
Equations
- Finsupp.instCeilDiv = { ceilDiv := fun (f : ι →₀ β) (a : α) => Finsupp.mapRange (fun (x : β) => x ⌈/⌉ a) ⋯ f, ceilDiv_gc := ⋯, ceilDiv_nonpos := ⋯, zero_ceilDiv := ⋯ }