Wikipedia / Floor and ceiling functions
Wikipedia / Floor and ceiling functions
In mathematics, the floor function is the function that takes a real number as input and returns the greatest integer less than or equal to , written or . Similarly, the ceiling function returns the least integer greater than or equal to , written 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 (among other notations). However, the term "integer part" is ambiguous, as it can also mean truncation towards zero, which differs from the floor function for negative numbers.
For an integer , .
Although and are equal for non-integer values of , and thus produce graphs that appear exactly alike, they differ when is an integer. For example, when , . However, if , then but .
Notation
The integral part or integer part of a number ( in the original) 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 (1808). 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 . (Iverson used square brackets for a different purpose, the Iverson bracket notation.) 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 HTML entities:
In the LaTeX typesetting system, these symbols can be specified with the 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 and , integers and and the set of integers
Since there is exactly one integer in a half-open interval of length one, for any real number , there are unique integers 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
The above are never true if is not an integer; however, for every and
Monotonicity
Both floor and ceiling functions are monotonically non-decreasing functions
Relations among the functions
with equality if and only if x
In fact, for integers , both floor and ceiling functions are the identity
The floor, ceiling, and fractional part functions are idempotent
due to the identity property for integers.
Quotients
If and are integers and
If is positive
If is positive
For
More generally, for positive (See Hermite's identity
The following can be used to convert floors to ceilings and vice versa (with being positive)
For all and strictly positive integers: which, for positive and coprime and and similarly for the ceiling and fractional part functions (still for positive and coprime and
Since the right-hand side of the general case is symmetrical in and
More generally, if and
This is sometimes called a reciprocity law.
The second equivalence involving the ceiling function can be proved similarly.
For being a positive integer with greater than . Then by
Nested divisions
For a positive integer , and arbitrary real numbers and :
Continuity and series expansions
None of the functions discussed in this article are continuous, but all are piecewise linear have discontinuities at the integers.
is upper semi-continuous 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 fixed and a multiple of the Fourier series given converges to , rather than to . At points of continuity the series converges to the true value.
for not an integer.
Applications
Mod operator
For an integer and a positive integer , the modulo operation, denoted by , gives the value of the remainder when is divided by . This definition can be extended to real and ,
Then it follows from the definition of floor function that this extended operation satisfies many natural properties. Notably, is always between 0 and , i.e.,
if and if
Quadratic reciprocity
Gauss's third proof of quadratic reciprocity, as modified by Eisenstein, has two basic steps.
Let and
First, Gauss's lemma is used to show that the Legendre symbols
The second step is to use a geometric
There are formulas that use floor to express the quadratic character of small numbers mod odd primes :
Rounding
, rounding to the nearest integer with tie breaking
is the sign function), and rounding towards even minus an integrality indicator.
Rounding a real number to the nearest integer value forms a very basic type of quantizer – a uniform one. A typical (mid-tread) uniform quantizer with a quantization step size
Number of digits
The number of digits in base of a positive integer
Number of strings without repeated characters
The number of possible strings of arbitrary length that doesn't use any character twice is given by where:
is the number of letters in the alphabet (e.g., 26 in English)
the falling factorial denotes the number of strings of length that don't use any character twice.
denotes the factorial of
For , this comes out to 1096259850353149530222034277.
Factors of factorials
Let be a positive integer and a positive prime number. The exponent of the highest power of that divides is given by a version of Legendre's formula is the way of writing in base . This is a finite sum, since the floors are zero when .
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 that involve the floor and ceiling, e.g.
Riemann zeta function (ζ)
The fractional part function also shows up in integral representations of the Riemann zeta function. It is straightforward to prove (using integration by parts) is any function with a continuous derivative in the closed interval
for real part of greater than 1 and letting and be integers, and letting
This formula is valid for all with real part greater than 1, (except , where there is a pole) 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 in the critical strip
In 1947 van der Pol used this representation to construct an analogue computer for finding roots of the zeta function.
Formulas for prime numbers
it follows that a positive integer is a prime if and only if
One may also give formulas for producing the prime numbers. For example, let be the -th prime, and for any integer , define the real number
Then
A similar result is that there is a number (Mills' constant are all prime.
There is also a number are all prime.
Let be the number of primes less than or equal to x. It is a straightforward deduction from Wilson's theorem that
Also, if ,
None of the formulas in this section are of any practical use.
Solved problems
Ramanujan submitted these problems to the Journal of the Indian Mathematical Society.
If is a positive integer, prove that
Some generalizations to the above floor function identities have been proven.
Unsolved problem
The study of Waring's problem has led to an unsolved problem:
Are there any positive integers such that
Mahler has proved there can only be a finite number of such ; none are known.
Computer implementations
In most programming languages, the simplest method to convert a floating point number to an integer does not do floor or ceiling, but truncation. The reason for this is historical, as the first machines used ones' complement and truncation was simpler to implement (floor is simpler in two's complement). FORTRAN was defined to require this behavior and thus almost all processors implement conversion this way. Some consider this to be an unfortunate historical design decision that has led to bugs handling negative offsets and graphics on the negative side of the origin.
An arithmetic right-shift. Division by a power of 2 is often written as a right-shift, not for optimization as might be assumed, but because the floor of negative results is required. Assuming such shifts are "premature optimization" and replacing them with division can break software.
Many programming languages (including C, C++, C#, Java, Julia, PHP, R, and Python) provide standard functions for floor and ceiling, usually called floor and ceil, or less commonly ceiling. The language APL uses ⌊x for floor. The J Programming Language, a follow-on to APL that is designed to use standard keyboard symbols, uses <. for floor and >. for ceiling. ALGOL usesentier for floor.
In Microsoft Excel the function INT rounds down rather than toward zero, while FLOOR rounds toward zero, the opposite of what "int" and "floor" do in other languages. Since 2010 FLOOR has been changed to error if the number is negative. The OpenDocument file format, as used by OpenOffice.org, Libreoffice and others, INT and FLOOR both do floor, and FLOOR has a third argument to reproduce Excel's earlier behavior.
See also
Citations
References
ISO/IEC. ISO/IEC 9899::1999(E): Programming languages — C (2nd ed), 1999; Section 6.3.1.4, p.43.
Michael Sullivan. Precalculus, 8th edition, p.86
External links
Štefan Porubský, "Integer rounding functions" , Interactive Information Portal for Algorithmic Mathematics, Institute of Computer Science of the Czech Academy of Sciences, Prague, Czech Republic, retrieved 24 October 2008