Floor and ceil #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Summary #
We define the natural- and integer-valued floor and ceil functions on linearly ordered rings.
Main Definitions #
-
floor_semiring
: An ordered semiring with natural-valued floor and ceil. -
nat.floor a
: Greatest naturaln
such thatn ≤ a
. Equal to0
ifa < 0
. -
nat.ceil a
: Least naturaln
such thata ≤ n
. -
floor_ring
: A linearly ordered ring with integer-valued floor and ceil. -
int.floor a
: Greatest integerz
such thatz ≤ a
. -
int.ceil a
: Least integerz
such thata ≤ z
. -
int.fract a
: Fractional part ofa
, defined asa - floor a
. -
round a
: Nearest integer toa
. It rounds halves towards infinity.
Notations #
The index ₊
in the notations for nat.floor
and nat.ceil
is used in analogy to the notation
for nnnorm
.
TODO #
linear_ordered_ring
/linear_ordered_semiring
can be relaxed to order_ring
/order_semiring
in
many lemmas.
Tags #
rounding, floor, ceil
Floor semiring #
- floor : α → ℕ
- ceil : α → ℕ
- floor_of_neg : ∀ {a : α}, a < 0 → floor_semiring.floor a = 0
- gc_floor : ∀ {a : α} {n : ℕ}, 0 ≤ a → (n ≤ floor_semiring.floor a ↔ ↑n ≤ a)
- gc_ceil : galois_connection floor_semiring.ceil coe
A floor_semiring
is an ordered semiring over α
with a function
floor : α → ℕ
satisfying ∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)
.
Note that many lemmas require a linear_order
. Please see the above TODO
.
Instances of this typeclass
Instances of other typeclasses for floor_semiring
- floor_semiring.has_sizeof_inst
⌊a⌋₊
is the greatest natural n
such that n ≤ a
. If a
is negative, then ⌊a⌋₊ = 0
.
Equations
⌈a⌉₊
is the least natural n
such that a ≤ n
Equations
Ceil #
Intervals #
Natural division is the floor of field division.
There exists at most one floor_semiring
structure on a linear ordered semiring.
Floor rings #
- floor : α → ℤ
- ceil : α → ℤ
- gc_coe_floor : galois_connection coe floor_ring.floor
- gc_ceil_coe : galois_connection floor_ring.ceil coe
A floor_ring
is a linear ordered ring over α
with a function
floor : α → ℤ
satisfying ∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)
.
Instances of this typeclass
Instances of other typeclasses for floor_ring
- floor_ring.has_sizeof_inst
Equations
- int.floor_ring = {floor := id ℤ, ceil := id ℤ, gc_coe_floor := int.floor_ring._proof_1, gc_ceil_coe := int.floor_ring._proof_2}
A floor_ring
constructor from the floor
function alone.
Equations
- floor_ring.of_floor α floor gc_coe_floor = {floor := floor, ceil := λ (a : α), -floor (-a), gc_coe_floor := gc_coe_floor, gc_ceil_coe := _}
A floor_ring
constructor from the ceil
function alone.
Equations
- floor_ring.of_ceil α ceil gc_ceil_coe = {floor := λ (a : α), -ceil (-a), ceil := ceil, gc_coe_floor := _, gc_ceil_coe := gc_ceil_coe}
int.floor a
is the greatest integer z
such that z ≤ a
. It is denoted with ⌊a⌋
.
Equations
int.ceil a
is the smallest integer z
such that a ≤ z
. It is denoted with ⌈a⌉
.
Equations
Floor #
Fractional part #
The fractional part of a
is positive if and only if a ≠ ⌊a⌋
.
Ceil #
Intervals #
Round #
A floor ring as a floor semiring #
There exists at most one floor_ring
structure on a given linear ordered ring.