Floor and ceiling functions
In mathematics, the floor function is the function that takes as input a real number, and gives as output the greatest integer less than or equal to, denoted or. Similarly, the ceiling function maps to the least integer greater than or equal to, denoted or.
For example, for floor:,, and for ceiling:, and.
The floor of is also called the integral part, integer part, greatest integer, or entier of, and was historically denoted . However, the same term, integer part, is also used for truncation towards zero, which differs from the floor function for negative numbers.
For an integer,.
Although and produce graphs that appear exactly alike, they are not the same when the value of is an exact integer. For example, when,. However, if, then, while .
| x | Floor | Ceiling | Fractional part |
| 2 | 2 | 2 | 0 |
| 2.0001 | 2 | 3 | 0.0001 |
| e | | 2 | 3 | 0.7182... |
| 2.9 | 2 | 3 | 0.9 |
| 2.999 | 2 | 3 | 0.999 |
| −Pi| | −4 | −3 | 0.8584... |
| −2 | −2 | −2 | 0 |
Notation
The integral part or integer part of a number was first defined in 1798 by Adrien-Marie Legendre in his proof of the Legendre's formula.Carl Friedrich Gauss introduced the square bracket notation in his third proof of quadratic reciprocity. This remained the standard in mathematics until Kenneth E. Iverson introduced, in his 1962 book A Programming Language, the names "floor" and "ceiling" and the corresponding notations and. Both notations are now used in mathematics, although Iverson's notation will be followed in this article.
In some sources, boldface or double brackets are used for floor, and reversed brackets or for ceiling.
The fractional part is the sawtooth function, denoted by for real and defined by the formula
For all x,
These characters are provided in Unicode:
and commands in math mode. LaTeX has supported UTF-8 since 2018, so the Unicode characters can now be used directly. Larger versions are and .Definition and properties
Given real numbers x and y, integers m and n and the set of integers, floor and ceiling may be defined by the equationsSince there is exactly one integer in a half-open interval of length one, for any real number x, there are unique integers m and n satisfying the equation
where and may also be taken as the definition of floor and ceiling.
Equivalences
These formulas can be used to simplify expressions involving floors and ceilings.In the language of order theory, the floor function is a residuated mapping, that is, part of a Galois connection: it is the upper adjoint of the function that embeds the integers into the reals.
These formulas show how adding an integer to the arguments affects the functions:
The above are never true if is not an integer; however, for every and, the following inequalities hold:
Monotonicity
Both floor and ceiling functions are monotonically non-decreasing functions:Relations among the functions
It is clear from the definitions thatIn fact, for integers n, both floor and ceiling functions are the identity:
Negating the argument switches floor and ceiling and changes the sign:
and:
Negating the argument complements the fractional part:
The floor, ceiling, and fractional part functions are idempotent:
The result of nested floor or ceiling functions is the innermost function:
due to the identity property for integers.
Quotients
If m and n are integers and n ≠ 0,If n is positive
If m is positive
For m = 2 these imply
More generally, for positive m
The following can be used to convert floors to ceilings and vice versa
For all m and n strictly positive integers:
which, for positive and coprime m and n, reduces to
and similarly for the ceiling and fractional part functions,
Since the right-hand side of the general case is symmetrical in m and n, this implies that
More generally, if m and n are positive,
This is sometimes called a [|reciprocity law].
Division by positive integers gives rise to an interesting and sometimes useful property. Assuming,
Similarly,
Indeed,
keeping in mind that
The second equivalence involving the ceiling function can be proved similarly.
For d being a positive integer with x greater than d. Then
where is the remainder of dividing by ''d''
Nested divisions
For a positive integer n, and arbitrary real numbers m and x:Continuity and series expansions
None of the functions discussed in this article are continuous, but all are piecewise linear: the functions,, and have discontinuities at the integers.is upper semi-continuous and and are lower semi-continuous.
Since none of the functions discussed in this article are continuous, none of them have a power series expansion. Since floor and ceiling are not periodic, they do not have uniformly convergent Fourier series expansions. The fractional part function has Fourier series expansion
for not an integer.
At points of discontinuity, a Fourier series converges to a value that is the average of its limits on the left and the right, unlike the floor, ceiling and fractional part functions: for y fixed and x a multiple of y the Fourier series given converges to y/2, rather than to x mod y = 0. At points of continuity the series converges to the true value.
Using the formula gives
for not an integer.
Applications
Mod operator
For an integer x and a positive integer y, the modulo operation, denoted by x mod y, gives the value of the remainder when x is divided by y. This definition can be extended to real x and y, y ≠ 0, by the formulaThen it follows from the definition of floor function that this extended operation satisfies many natural properties. Notably, x mod y is always between 0 and y, i.e.,
if y is positive,
and if y is negative,
Quadratic reciprocity
Gauss's third proof of quadratic reciprocity, as modified by Eisenstein, has two basic steps.Let p and q be distinct positive odd prime numbers, and let
First, Gauss's lemma is used to show that the Legendre symbols are given by
The second step is to use a geometric argument to show that
Combining these formulas gives quadratic reciprocity in the form
There are formulas that use floor to express the quadratic character of small numbers mod odd primes p:
Rounding
For an arbitrary real number, rounding to the nearest integer with tie breaking towards positive infinity is given byrounding towards negative infinity is given as
If tie-breaking is away from 0, then the rounding function is
, and rounding towards even can be expressed with the more cumbersome
which is the above expression for rounding towards positive infinity minus an integrality indicator for.
Rounding a real number to the nearest integer value forms a very basic type of quantizer – a uniform one. A typical uniform quantizer with a quantization step size equal to some value can be expressed as
Number of digits
The number of digits in base b of a positive integer k isNumber of strings without repeated characters
The number of possible strings of arbitrary length that doesn't use any character twice is given bywhere:
- > 0 is the number of letters in the alphabet
- the falling factorial denotes the number of strings of length that don't use any character twice.
- ! denotes the factorial of
- = 2.718... is Euler's number
Factors of factorials
Let n be a positive integer and p a positive prime number. The exponent of the highest power of p that divides n! is given by a version of Legendre's formulawhere is the way of writing n in base p. This is a finite sum, since the floors are zero when pk > n.
Beatty sequence
The Beatty sequence shows how every positive irrational number gives rise to a partition of the natural numbers into two sequences via the floor function.Euler's constant (γ)
There are formulas for Euler's constant γ = 0.57721 56649... that involve the floor and ceiling, e.g.and
Riemann zeta function (ζ)
The fractional part function also shows up in integral representations of the Riemann zeta function. It is straightforward to prove that if is any function with a continuous derivative in the closed interval ,Letting for real part of s greater than 1 and letting a and b be integers, and letting b approach infinity gives
This formula is valid for all s with real part greater than −1, and combined with the Fourier expansion for can be used to extend the zeta function to the entire complex plane and to prove its functional equation.
For s = σ + it in the critical strip 0 < σ < 1,
In 1947 van der Pol used this representation to construct an analogue computer for finding roots of the zeta function.