HOME

TheInfoList



OR:

In
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
and computer science, 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, , , , and . Historically, the floor of has been–and still is–called the integral part or integer part of , often denoted (as well as a variety of other notations). Some authors may define the integral part as if is nonnegative, and otherwise: for example, and . The operation of
truncation In mathematics and computer science, truncation is limiting the number of digits right of the decimal point. Truncation and floor function Truncation of positive real numbers can be done using the floor function. Given a number x \in \mathbb ...
generalizes this to a specified number of digits: truncation to zero significant digits is the same as the integer part. For an integer, .


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 Kenneth Eugene Iverson (17 December 1920 – 19 October 2004) was a Canadian computer scientist noted for the development of the programming language APL. He was honored with the Turing Award in 1979 "for his pioneering effort in programming l ...
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 In mathematics, the Iverson bracket, named after Kenneth E. Iverson, is a notation that generalises the Kronecker delta, which is the Iverson bracket of the statement . It maps any statement to a function of the free variables in that statement. ...
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. Sometimes is taken to mean the round-toward-zero function. The
fractional part The fractional part or decimal part of a non‐negative real number x is the excess beyond that number's integer part. If the latter is defined as the largest integer not greater than , called floor of or \lfloor x\rfloor, its fractional part can ...
is the sawtooth function, denoted by for real and defined by the formula : For all ''x'', :. These characters are provided in Unicode: * * * * In the LaTeX typesetting system, these symbols can be specified with the and commands in math mode, and extended in size using \left\lfloor, \right\rfloor, \left\lceil and \right\rceil as needed.


Definition and properties

Given real numbers ''x'' and ''y'', integers ''k'', ''m'', ''n'' and the set of integers \mathbb, floor and ceiling may be defined by the equations : \lfloor x \rfloor=\max \, : \lceil x \rceil=\min \. Since 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 :x-1 where \lfloor x \rfloor = m and \lceil x \rceil = n may also be taken as the definition of floor and ceiling.


Equivalences

These formulas can be used to simplify expressions involving floors and ceilings. : \begin \lfloor x \rfloor = m &\;\;\mbox &m &\le x < m+1,\\ \lceil x \rceil = n &\;\;\mbox &n -1 &< x \le n,\\ \lfloor x \rfloor = m &\;\;\mbox &x-1 &< m \le x,\\ \lceil x \rceil = n &\;\;\mbox &x &\le n < x+1. \end In the language of order theory, the floor function is a residuated mapping, that is, part of a
Galois connection In mathematics, especially in order theory, a Galois connection is a particular correspondence (typically) between two partially ordered sets (posets). Galois connections find applications in various mathematical theories. They generalize the funda ...
: it is the upper adjoint of the function that embeds the integers into the reals. : \begin x These formulas show how adding integers to the arguments affects the functions: : \begin \lfloor x+n \rfloor &= \lfloor x \rfloor+n,\\ \lceil x+n \rceil &= \lceil x \rceil+n,\\ \ &= \. \end The above are never true if ''n'' is not an integer; however, for every and , the following inequalities hold: :\begin \lfloor x \rfloor + \lfloor y \rfloor &\leq \lfloor x + y \rfloor \leq \lfloor x \rfloor + \lfloor y \rfloor + 1,\\ \lceil x \rceil + \lceil y \rceil -1 &\leq \lceil x + y \rceil \leq \lceil x \rceil + \lceil y \rceil. \end


Monotonicity

Both floor and ceiling functions are the monotonically non-decreasing function: : \begin x_ \le x_ &\Rightarrow \lfloor x_ \rfloor \le \lfloor x_ \rfloor, \\ x_ \le x_ &\Rightarrow \lceil x_ \rceil \le \lceil x_ \rceil. \end


Relations among the functions

It is clear from the definitions that :\lfloor x \rfloor \le \lceil x \rceil,   with equality if and only if ''x'' is an integer, i.e. :\lceil x \rceil - \lfloor x \rfloor = \begin 0&\mbox x\in \mathbb\\ 1&\mbox x\not\in \mathbb \end In fact, for integers ''n'', both floor and ceiling functions are the identity: :\lfloor n \rfloor = \lceil n \rceil = n. Negating the argument switches floor and ceiling and changes the sign: : \begin \lfloor x \rfloor +\lceil -x \rceil &= 0 \\ -\lfloor x \rfloor &= \lceil -x \rceil \\ -\lceil x \rceil &= \lfloor -x \rfloor \end and: :\lfloor x \rfloor + \lfloor -x \rfloor = \begin 0&\text x\in \mathbb\\ -1&\text x\not\in \mathbb, \end :\lceil x \rceil + \lceil -x \rceil = \begin 0&\text x\in \mathbb\\ 1&\text x\not\in \mathbb. \end Negating the argument complements the fractional part: :\ + \ = \begin 0&\text x\in \mathbb\\ 1&\text x\not\in \mathbb. \end The floor, ceiling, and fractional part functions are idempotent: : \begin \Big\lfloor \lfloor x \rfloor \Big\rfloor &= \lfloor x \rfloor, \\ \Big\lceil \lceil x \rceil \Big\rceil &= \lceil x \rceil, \\ \Big\ &= \. \end The result of nested floor or ceiling functions is the innermost function: : \begin \Big\lfloor \lceil x \rceil \Big\rfloor &= \lceil x \rceil, \\ \Big\lceil \lfloor x \rfloor \Big\rceil &= \lfloor x \rfloor \end due to the identity property for integers.


Quotients

If ''m'' and ''n'' are integers and ''n'' ≠ 0, :0 \le \left \ \le 1-\frac. If ''n'' is a positive integer :\left\lfloor\frac\right\rfloor = \left\lfloor\frac\right\rfloor, :\left\lceil\frac\right\rceil = \left\lceil\frac\right\rceil. If ''m'' is positive :n=\left\lceil\frac\right\rceil + \left\lceil\frac\right\rceil +\dots+\left\lceil\frac\right\rceil, :n=\left\lfloor\frac\right\rfloor + \left\lfloor\frac\right\rfloor +\dots+\left\lfloor\frac\right\rfloor. For ''m'' = 2 these imply :n= \left\lfloor \frac\right \rfloor + \left\lceil\frac\right \rceil. More generally, for positive ''m'' (See Hermite's identity) :\lceil mx \rceil =\left\lceil x\right\rceil + \left\lceil x-\frac\right\rceil +\dots+\left\lceil x-\frac\right\rceil, :\lfloor mx \rfloor=\left\lfloor x\right\rfloor + \left\lfloor x+\frac\right\rfloor +\dots+\left\lfloor x+\frac\right\rfloor. The following can be used to convert floors to ceilings and vice versa (''m'' positive) :\left\lceil \frac \right\rceil = \left\lfloor \frac \right\rfloor = \left\lfloor \frac \right\rfloor + 1, :\left\lfloor \frac \right\rfloor = \left\lceil \frac \right\rceil = \left\lceil \frac \right\rceil - 1, For all ''m'' and ''n'' strictly positive integers: :\sum_^ \left\lfloor \frac \right\rfloor = \frac2, which, for positive and coprime ''m'' and ''n'', reduces to :\sum_^ \left\lfloor \frac \right\rfloor = \frac(m - 1)(n - 1) , and similarly for the ceiling and fractional part functions (still for positive and coprime ''m'' and ''n''), :\sum_^ \left\lceil \frac \right\rceil = \frac(m + 1)(n - 1), :\sum_^ \left\ = \frac(n - 1). Since the right-hand side of the general case is symmetrical in ''m'' and ''n'', this implies that :\left\lfloor \frac \right \rfloor + \left\lfloor \frac \right \rfloor + \dots + \left\lfloor \frac \right \rfloor = \left\lfloor \frac \right \rfloor + \left\lfloor \frac \right \rfloor + \dots + \left\lfloor \frac \right \rfloor. More generally, if ''m'' and ''n'' are positive, :\begin &\left\lfloor \frac \right \rfloor + \left\lfloor \frac \right \rfloor + \left\lfloor \frac \right \rfloor + \dots + \left\lfloor \frac \right \rfloor\\= &\left\lfloor \frac \right \rfloor + \left\lfloor \frac \right \rfloor + \left\lfloor \frac \right \rfloor + \cdots + \left\lfloor \frac \right \rfloor. \end This is sometimes called a reciprocity law.


Nested divisions

For positive integer ''n'', and arbitrary real numbers ''m'',''x'': : \left\lfloor \frac \right\rfloor = \left\lfloor \frac \right\rfloor : \left\lceil \frac \right\rceil = \left\lceil \frac \right\rceil.


Continuity and series expansions

None of the functions discussed in this article are continuous, but all are piecewise linear: the functions \lfloor x \rfloor, \lceil x \rceil, and \ have discontinuities at the integers. \lfloor x \rfloor  is upper semi-continuous and  \lceil x \rceil  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 A Fourier series () is a summation of harmonically related sinusoidal functions, also known as components or harmonics. The result of the summation is a periodic function whose functional form is determined by the choices of cycle length (or ''p ...
expansions. The fractional part function has Fourier series expansion :\= \frac - \frac \sum_^\infty \frac 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 floor(x) = x − gives :\lfloor x\rfloor = x - \frac + \frac \sum_^\infty \frac 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 formula :x \bmod y = x-y\left\lfloor \frac\right\rfloor. Then 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, :0 \le x \bmod y and if ''y'' is negative, :0 \ge x \bmod y >y.


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 :m = \frac, n = \frac. First,
Gauss's lemma Gauss's lemma can mean any of several lemmas named after Carl Friedrich Gauss: * * * * A generalization of Euclid's lemma is sometimes called Gauss's lemma See also * List of topics named after Carl Friedrich Gauss Carl Friedrich Gauss ( ...
is used to show that the
Legendre symbol In number theory, the Legendre symbol is a multiplicative function with values 1, −1, 0 that is a quadratic character modulo an odd prime number ''p'': its value at a (nonzero) quadratic residue mod ''p'' is 1 and at a non-quadratic residu ...
s are given by :\left(\frac\right) = (-1)^ and :\left(\frac\right) = (-1)^. The second step is to use a geometric argument to show that :\left\lfloor\frac\right\rfloor +\left\lfloor\frac\right\rfloor +\dots +\left\lfloor\frac\right\rfloor +\left\lfloor\frac\right\rfloor +\left\lfloor\frac\right\rfloor +\dots +\left\lfloor\frac\right\rfloor = mn. Combining these formulas gives quadratic reciprocity in the form :\left(\frac\right) \left(\frac\right) = (-1)^=(-1)^. There are formulas that use floor to express the quadratic character of small numbers mod odd primes ''p'': :\left(\frac\right) = (-1)^, :\left(\frac\right) = (-1)^.


Rounding

For an arbitrary real number x, rounding x to the nearest integer with tie breaking towards positive infinity is given by \text(x)=\left\lfloor x+\tfrac\right\rfloor = \left\lceil \tfrac2 \right\rceil; rounding towards negative infinity is given as \text(x)=\left\lceil x-\tfrac\right\rceil = \left\lfloor \tfrac2 \right\rfloor. If tie-breaking is away from 0, then the rounding function is \text(x) = \sgn(x)\left\lfloor, x, +\tfrac\right\rfloor (see
sign function In mathematics, the sign function or signum function (from '' signum'', Latin for "sign") is an odd mathematical function that extracts the sign of a real number. In mathematical expressions the sign function is often represented as . To avoi ...
), and rounding towards even can be expressed with the more cumbersome \lfloor x\rceil=\left\lfloor x+\tfrac\right\rfloor+\left\lceil\tfrac4\right\rceil-\left\lfloor\tfrac4\right\rfloor-1, which is the above expression for rounding towards positive infinity \text(x) minus an integrality indicator for \tfrac4.


Number of digits

The number of digits in base ''b'' of a positive integer ''k'' is :\lfloor \log_ \rfloor + 1 = \lceil \log_ \rceil .


Number of strings without repeated characters

The number of possible strings of arbitrary length that don't use any character twice is given by :(n)_0 + \cdots + (n)_n = \lfloor e n! \rfloor where: * > 0 is the number of letters in the alphabet (e.g., 26 in English) * the
falling factorial In mathematics, the falling factorial (sometimes called the descending factorial, falling sequential product, or lower factorial) is defined as the polynomial :\begin (x)_n = x^\underline &= \overbrace^ \\ &= \prod_^n(x-k+1) = \prod_^(x-k) \,. \e ...
(n)_k = n(n-1)\cdots(n-k+1) denotes the number of strings of length that don't use any character twice. * ! denotes the
factorial In mathematics, the factorial of a non-negative denoted is the product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial: \begin n! &= n \times (n-1) \times (n-2) \t ...
of * = 2.718… is Euler's number For = 26, this comes out to 1096259850353149530222034277.


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 formula :\left\lfloor\frac\right\rfloor + \left\lfloor\frac\right\rfloor + \left\lfloor\frac\right\rfloor + \dots = \frac where n = \sum_a_kp^k is the way of writing ''n'' in base ''p''. This is a finite sum, since the floors are zero when ''p''''k'' > ''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. :\gamma =\int_1^\infty\left(-\right)\,dx, :\gamma = \lim_ \frac \sum_^n \left( \left \lceil \frac \right \rceil - \frac \right), and : \gamma = \sum_^\infty (-1)^k \frac = \tfrac12-\tfrac13 + 2\left(\tfrac14 - \tfrac15 + \tfrac16 - \tfrac17\right) + 3\left(\tfrac18 - \cdots - \tfrac1\right) + \cdots


Riemann zeta function (ζ)

The fractional part function also shows up in integral representations of the
Riemann zeta function The Riemann zeta function or Euler–Riemann zeta function, denoted by the Greek letter (zeta), is a mathematical function of a complex variable defined as \zeta(s) = \sum_^\infty \frac = \frac + \frac + \frac + \cdots for \operatorname(s) > ...
. It is straightforward to prove (using integration by parts) that if \phi(x) is any function with a continuous derivative in the closed interval 'a'', ''b'' :\sum_\phi(n) = \int_a^b\phi(x) \, dx + \int_a^b\left(\-\tfrac12\right)\phi'(x) \, dx + \left(\-\tfrac12\right)\phi(a) - \left(\-\tfrac12\right)\phi(b). Letting \phi(n)=^ for real part of ''s'' greater than 1 and letting ''a'' and ''b'' be integers, and letting ''b'' approach infinity gives :\zeta(s) = s\int_1^\infty\frac\,dx + \frac + \frac 1 2. This formula is valid for all ''s'' with real part greater than −1, (except ''s'' = 1, 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 ''s'' = ''σ'' + ''it'' in the critical strip 0 < ''σ'' < 1, :\zeta(s)=s\int_^\infty e^(\lfloor e^\omega\rfloor - e^\omega)e^\,d\omega. In 1947
van der Pol Van der Pol (also "Van de Pol", "Van de Poll", "Van den Pol" or "Van Pol") is a Dutch language, Dutch, toponymic surname, originally meaning "from the raised land".if and only if :\sum_^\left(\left\lfloor\frac\right\rfloor-\left\lfloor\frac\right\rfloor\right) = 2. One may also give formulas for producing the prime numbers. For example, let ''p''''n'' be the ''n''-th prime, and for any integer ''r'' > 1, define the real number ''α'' by the sum :\alpha = \sum_^\infty p_m r^. Then :p_n = \left\lfloor r^\alpha \right\rfloor - r^\left\lfloor r^\alpha\right\rfloor. A similar result is that there is a number ''θ'' = 1.3064... ( Mills' constant) with the property that :\left\lfloor \theta^3 \right\rfloor, \left\lfloor \theta^9 \right\rfloor, \left\lfloor \theta^ \right\rfloor, \dots are all prime.Ribenboim, p. 186 There is also a number ''ω'' = 1.9287800... with the property that :\left\lfloor 2^\omega\right\rfloor, \left\lfloor 2^ \right\rfloor, \left\lfloor 2^ \right\rfloor, \dots are all prime. Let (''x'') be the number of primes less than or equal to ''x''. It is a straightforward deduction from Wilson's theorem that :\pi(n) = \sum_^n\left\lfloor\frac - \left\lfloor\frac\right\rfloor\right\rfloor. Also, if ''n'' ≥ 2, :\pi(n) = \sum_^n \left\lfloor \frac\right\rfloor. 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 ''n'' is a positive integer, prove that
  1. \left\lfloor\tfrac\right\rfloor + \left\lfloor\tfrac\right\rfloor + \left\lfloor\tfrac\right\rfloor = \left\lfloor\tfrac\right\rfloor + \left\lfloor\tfrac\right\rfloor,
  2. \left\lfloor\tfrac12 + \sqrt\right\rfloor = \left\lfloor\tfrac12 + \sqrt\right\rfloor,
  3. \left\lfloor\sqrt+ \sqrt\right\rfloor = \left\lfloor \sqrt\right\rfloor.
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 ''k'' ≥ 6 such that :3^k-2^k\left\lfloor \left(\tfrac 3 2\right)^k \right\rfloor > 2^k-\left\lfloor \left(\tfrac 3 2\right)^k \right\rfloor -2 ? Mahler has proved there can only be a finite number of such ''k''; 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 In mathematics and computer science, truncation is limiting the number of digits right of the decimal point. Truncation and floor function Truncation of positive real numbers can be done using the floor function. Given a number x \in \mathbb ...
. 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. A bit-wise right-shift of a signed integer x by n is the same as \left\lfloor \frac \right\rfloor. 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, 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 floor function is implemented as INT (which rounds down rather than toward zero). The command FLOOR in earlier versions would round toward zero, effectively the opposite of what "int" and "floor" do in other languages. Since 2010 FLOOR has been fixed to round down, with extra arguments that can reproduce previous behavior. The OpenDocument file format, as used by OpenOffice.org, Libreoffice and others, uses the same function names; INT does floor and FLOOR has a third argument that can make it round toward zero.


See also

* Bracket (mathematics) * Integer-valued function * Step function * Modulo operation


Notes


Citations


References

* * * * *Nicholas J. Higham, ''Handbook of writing for the mathematical sciences'', SIAM. , p. 25 * 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 * * {{DEFAULTSORT:Floor And Ceiling Functions Special functions Mathematical notation Unary operations