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
Instances For
Ceiling division. If a > 0, then b ⌈/⌉ a is the least c such that b ≤ a • c.