28

I'm curious as to how the floor function can be defined using mathematical notation.

What I mean by this, is, instead of a word-based explanation (i.e. "The closest integer that is not greater than x"), I'm curious to see the mathematical equivalent of the definition, if that is even possible.

For example, a word-based explanation of the factorial function would be "multiply the number by all integers below it", whereas a mathematical equivalent of the definition would be $n! = \prod^n_{i=1}i$.

So, in summary: how can I show what $\lfloor x \rfloor$ means without words?

Cisplatin
  • 4,675
  • 7
  • 33
  • 58
  • 8
    "instead of a word-based explanation" - it can happen that insisting on formal notation often hurts clarity more than helping it. In this case, since the textual definition is straightforward, why bother? – J. M. ain't a mathematician May 12 '13 at 03:53
  • 10
    For curiosity's sake; consider it a puzzle – Cisplatin May 12 '13 at 03:55
  • 7
    What do you mean by that big capital pi with all those other symbols around it? Can you describe that "without words" please? In your accepted answer, what does arctan mean? My point is, all notation was invented to describe some intellectual phenomenon, which may in turn have been based on some earlier idea, etc. until the whole thing ultimately boils down to cavemen telling how many mastadon had been successfully hunted by holding up fingers. – cobaltduck May 12 '13 at 18:06
  • @cobaltduck "hire or otherwise persuade a caveman to walk clockwise a circle of radius 0.5/pi until he has covered a distance of x. then have him walk counter-clockwise back to his starting point and subtract from x the distance he walked back" it helps to mark the starting point with a mastodon. ;p – agks mehx May 12 '13 at 20:46
  • see alsso: https://math.stackexchange.com/q/1810859/51028 – Stephan Jul 11 '18 at 22:24

12 Answers12

85

For a real number $x$, $$\lfloor x\rfloor=\max\{n\in\mathbb{Z}\mid n\leq x\}.$$ I'd like to add though, that "$\lfloor x\rfloor$" is mathematical notation, just as much as the right side of the above equation is; the right side might use more "basic" constructions, but you can then ask about $$\max,\qquad\in,\qquad \mathbb{Z},\qquad {}\mathbin{\mid}{},\qquad \leq$$ and so on. At some point you just have to start writing notation and explaining it in words and hope your readers understand. So I disagree with your phrasing of the question.

Zev Chonoles
  • 129,973
31

$\lfloor x \rfloor = x - \arctan(\tan(\pi x))/\pi$ ?...

DVD
  • 1,137
  • 19
  • 1
    love this answer - so cool! i don't know why this one isn't accepted or voted higher, the rest are simply saying in notation what the question said in english so chickening out. this one computes it directly like a boss. also @gangqinlaohu – agks mehx May 12 '13 at 08:34
  • 4
    @agksmehx: Zev's answer should be the accepted one - no chickening out there, just the plain professional definition. (Of course this answer is a nice idea, too.) – Hendrik Vogt May 12 '13 at 12:18
  • 7
    One tiny quibble is that $\arctan$ is a multi-valued function, and this relies on taking the principal value, otherwise the answer could be any integer. It's somewhat similar to defining $|x|$ as $\sqrt{x^2}$, which could technically be $|x|$ or $-|x|$. – N. Virgo May 12 '13 at 14:35
  • I like this answer because it's easy for me to see it implemented as a function in most curly-brace programming languages (e.g., C++, Java). It's unclear to me how Zev's answer could be coded in these languages. Now a language that is tailored for mathematical notation (e.g., Haskell) might be different, so I guess it depends on your perspective. – Clayton Stanley May 12 '13 at 19:23
  • 5
    @Clayton: But which answer is clearer as to what $\lfloor x\rfloor$ means (which is usually the goal for things intended to be read by humans)? Besides, a computer seems far more likely to make round-off errors or mistakes trying to mimick $\pi$, an arbitrary real number $x$, subtraction, division, and the functions $\tan$ and $\arctan$, than in trying to compare numbers with $\leq$ (though I don't know anything about programming languages, so maybe I'm wrong about that). – Zev Chonoles May 12 '13 at 19:49
  • @ZevChonoles right on on all points. The best approach is to build a programming language that allows the mathematical notation you wrote, and then 'code' it that way. I'm pretty sure Haskell supports that, or something close to it. – Clayton Stanley May 12 '13 at 20:16
  • @HendrikVogt on re-reading the question there is some ambiguity so i sympathize with the other answers. the question is clear that "instead of words ..." paragraph is looking for more than a set notation replacement of english. on the other hand the next paragraph defines the factorial pretty much using mathematicalized english. i think that is just because the author wasn't aware of the cool gamma function: http://en.wikipedia.org/wiki/Gamma_function which also directly computes the factorial. – agks mehx May 12 '13 at 20:17
  • @ClaytonStanley for programming the time complexity of the two answers is different. the set-notation requires a search which i would implement as start from 1, keep doubling until exceeds n, then do a binary search between the last two points. it is O(log N). this answer is O(1). the art, rather than science, of computer programming requires a human to understand and come up with a better algorithm. that is for a well-coded computer. for a human unacquainted with binary search computing or coding computing the set-theoretic answer can be difficult in general. – agks mehx May 12 '13 at 20:29
  • 1
    @ZevChonoles sorry to bust your answer; there is some ambiguity in the question so i sympathize. see response on computability above. round-off and mimicking pi tend to be second-order concerns in that there are well-defined way to get arbitrarily close to what you want. this answer seems particularly sensitive to roundoff concerns but a smart compiler would "see through" the arctan(tan(..)). the correct implementation could simply knock off bits rather than using your answer or this one. but being a math forum i would ignore computability issues unless that is the primary goal. – agks mehx May 12 '13 at 20:35
  • 1
    to the original author and everybody pitching in, i will interpret this answer in words: "walk clockwise a circle of radius 0.5/pi until you have covered a distance of x. then walk counter-clockwise back to your starting point and subtract from x the distance you walked back :-) – agks mehx May 12 '13 at 20:39
  • 5
    But there is a problem, should you use the function with an integer, the result would be its preceding integer. I.e., f(x) = (x - 0.5) - atan(tan(pi*(x - 0.5)))/pi, f(1) = 0. – Severo Raz May 12 '13 at 20:52
  • 1
    @agks, Wolter has this nice point... – J. M. ain't a mathematician May 13 '13 at 01:03
  • 3
    Ahem This sort of mistake is less likely when writing things that convey meaning, as opposed to things that happen to give the correct answer... – Zev Chonoles May 13 '13 at 01:27
  • @ZevChonoles i made the same mistake when writing it out in a way that conveys meaning by not adding the clause "unless you are already at the starting point". what you probably mean is that any time you give a method for arriving at the answer rather than just defining the answer there is an increased likelihood of making a mistake. that's just because there are more moving parts when you are describing how to arrive at an answer rather than just giving a definition or a test for the answer. right? i thought this was a useful debate in that it pinpointed the difference in the types of answers – agks mehx May 13 '13 at 02:19
  • @J.M. there was already a mistake in the answer, it was corrected in a comment, and there is one more flaw which can easily be rectified: subtract the value only if it is strictly less than one. there are probably other details if you wanted to actually implement it. but the point is that one type of answer (Zev's) defines the notation or declares properties of the answer. the other gives a reasonably efficient method to get the answer. this arctan answer answers a slightly different question: "how to efficiently compute the answer" (not in a programming sense but mathematically) – agks mehx May 13 '13 at 02:24
  • @J.M. similarly Zev's answer answers a slightly different question: "how to express the floor operator using more elementary ones" and he gave a great answer to that. – agks mehx May 13 '13 at 02:26
  • 1
    ultimately the question is ambiguous, but in being so it enlightened me tremendously in understanding the difference between declarative versus computable answers. there is more interesting stuff about how tan is itself computed versus how do you find the max of a bounded set. ultimately they have the same efficient solution and there are similarities between the efficient methods to arrive at an answer that i didn't think existed before. so, KUDOS+thank-you to @ZevChonoles and community for not closing or discouraging the question and letting it educate at least me! cheers :) – agks mehx May 13 '13 at 02:29
  • @Nathaniel: Why do you say that $\arctan$ is multi-valued? Isn't it widely accepted that it's the inverse function of $\tan\colon(-\frac\pi2,\frac\pi2)\to\mathbb R$? (For me as a mathematician this is the standard definition, and I don't know any programming language that would use another definition.) – Hendrik Vogt May 13 '13 at 12:13
  • @agksmehx: Still, the factorial should be defined as a (finite) product, not via the Gamma function! – Hendrik Vogt May 13 '13 at 12:16
  • 2
    @Clayton and agksmehx: Using this as an implementation for the floor function would be ludicrous (pardon my French). I'm pretty sure that any implementation of $\tan$ involves the floor function in some way of another. – Hendrik Vogt May 13 '13 at 12:22
  • @HendrikVogt $\tan(\theta + 2\pi n) = \tan(\theta)$ for any $n\in \mathbb{Z}$. Taking the $(-\pi,\pi]$ branch (or the $[0,2\pi)$ one) of the inverse function is just a matter of convention. Of course you're right that a computer language will only return a single value, but I didn't interpret the question as asking for an implementation so much as a formal expression. – N. Virgo May 13 '13 at 13:21
  • 1
    @Nathaniel: We're talking about the $(-\frac\pi2,\frac\pi2)$ branch (the tangent is $\pi$-periodic) :-) Of course it's only convention, but it's the standard mathematical convention to use this branch and not another one. – Hendrik Vogt May 13 '13 at 13:42
  • @HendrikVogt d'oh, $(-\pi/2,\pi/2)$ is right of course. The point is just that this means we're defining $\lfloor x \rfloor$ in terms of a convention, rather than in terms of a really "fundamental" property of $\tanh$. I did say it was only a tiny quibble... – N. Virgo May 13 '13 at 15:07
  • @Nathaniel what about my interpretation of arctan(tan(θ)) as walking around in a circle θ and then measuring how far you are from the starting point? (to be precise either of two "poles" marked on the circle) it is a pretty fundamental concept encountered in real life, and therefore a solid rationale for using the principal value. – agks mehx May 13 '13 at 21:25
  • @HendrikVogt i agree factorial should be defined as a finite product. on that note for computing stirling and other approximations are also interesting. – agks mehx May 13 '13 at 21:26
  • @DVD how was this derived? – Albert Renshaw Jan 29 '18 at 00:48
  • @AlbertRenshaw Periodicity of tangent function and common sense? – DVD Jan 30 '18 at 02:24
  • 1
    see also: https://math.stackexchange.com/q/1810859/51028 – Stephan Jul 11 '18 at 22:23
20

I am an engineer, perhaps this helps if you do not expect too much.

$x-(x$ mod $1$)

newzad
  • 4,855
13

Recursive way: $\lfloor x\rfloor \equiv \begin{cases} 1+\lfloor x-1\rfloor& x\ge1 \\ -1+\lfloor x+1\rfloor& x<-1 \\ 0&0\le x<1\\ -1&-1\le x<0 \end{cases}$

Also directly(sort of) computes the answer.

swish
  • 850
9

$\lfloor x\rfloor=n\leftrightarrow \{n\}=\{y\in\mathbb{Z}:\forall z\in\mathbb{Z}~ z\le x \rightarrow z\le y\}$

This game is fun! Now let's prove 1+1=2.

vadim123
  • 82,796
5

You have raised a most-interesting question which has a beautiful solution.

The floor-function is characterized by the following formula,

$\boxed{ \;\; \forall n \in \mathbb{Z},x \in \mathbb{R} :: n \leq \lfloor x \rfloor \equiv n \leq x \;\; }$

Indeed this states that ``$\lfloor x \rfloor$ is the greatest integer that is at-most $x$'':

  1. $\lfloor x \rfloor$ is an ingeter at-most $x$ ---ie $x \leq \lfloor x \rfloor$. We obtain this my taking $n = \lfloor x \rfloor$ in the above formula.

  2. It is also the largest such integer : $\forall n \in \mathbb{Z},x \in \mathbb{R} :: n \leq x \implies n \leq \lfloor x \rfloor$. We obtain this from the characterization by weakening the equivalence $\equiv$ into an implication $\implies$.

Some immediate results from the characterization, for $n \in \mathbb{Z}, x \in \mathbb{R}$, are

  1. $\lfloor x \rfloor < n \equiv x < n$, by negating the equivalence.

  2. $\lfloor x \rfloor \leq x$, by taking $n = \lfloor x \rfloor$. [Contracting]

  3. $\lfloor x \rfloor \leq \lfloor y \rfloor \Leftarrow x \leq y$, proven by the characterization and properties of $\leq$. [Order preserving]

  4. $\lfloor \lfloor x \rfloor \rfloor = \lfloor x \rfloor$, characterization again. [Idempotent]

Other nifty theorems can be easily proven from this characterization, such as

  1. $n = \lfloor x \rfloor \, \equiv \, ( n \leq x \text{ and } x<n+1)$

  2. $\lfloor x+n \rfloor = \lfloor x \rfloor + n$

  3. $\lfloor x \rfloor + \lfloor y \rfloor \leq \lfloor x+y \rfloor $

  4. $0\leq x \implies \lfloor \sqrt{\lfloor x \rfloor} \rfloor = \lfloor \sqrt{x} \rfloor$

Unlike the other answers presented earlier, this characterization shows its power in reasoning. For example, try proving one of the above theorems using one of the definitions presented by the others and then compare that with a proof using the characterization presented here.

These theorems and the characterization are explored in Feijen's ``The Joy of Formula Manipulation'', http://www.mathmeth.com/wf/files/wf2xx/wf268t.pdf.

Best regards,

Moses

4

I suspect that this question can be better articulated as: how can we compute the floor of a given number using real number field operations, rather than by exploiting the printed notation, which separates the real and fractional part, making nearby integers instantly identifiable.

How about as Fourier series? If we subtract the function $y = x$ from $\lfloor x\rfloor$ then we get a periodic sawtooth wave. Hey look, that Wikipedia page even mentions this relationship.

So if you obtain the Fourier series (a sum of sinusoidal functions of various frequencies and amplitudes) for the sawtooth wave $\lfloor x\rfloor - x$ and add $x$, then you have an approximation for $\lfloor x\rfloor$ which is as good to whatever accuracy you care to apply in evaluating the series. Obtaining the Fourier series for $\lfloor x\rfloor - x$ is a basically a matter of scaling the function to fit: finding the parameters to substitute into the generic equation to produce the right amplitude, frequency and offset.

But another answer is that the printed notation which approximates a number is computable. When a computer evaluates floor(x), it's all math. The printed (or electronically stored) notation for a rational number which approximates a real number is a mathematical object.

Kaz
  • 6,859
3

$$\lfloor x \rfloor = \text{supremum} \{n \in \mathbb{Z} : n \leq x\}$$

For a subset $S \subset X$, where we have an order $\leq$ on $X$, a supremum or least upper bound of $S$ is an element $M \in X$ such that $$x \leq M, \,\,\,\,\, \forall x \in S$$ and for any $m \in X$ such that $x \leq m$ for all $x \in S$, we have $M \leq m$.

3

There exists exactly one integer $n$ such that $n \le x < n+1$. We define $\lfloor x \rfloor$ to be this $n$.

Or, if you really like symbols: $\forall x \in \mathbb{R} \ \exists! n \in \mathbb{Z} \ n \le x < n+1 \quad \lfloor x \rfloor := n$.

Henry Swanson
  • 12,972
2

$\left \lfloor x \right \rfloor = a \in \mathbb{Z}, a \le x \ni a\ge b \;\forall \;b \in \mathbb{Z}, b\le x$

AJMansfield
  • 1,025
1

Another expression is \begin{equation} \lfloor x \rfloor = \lim_{n \rightarrow \infty} (\sum_{k=-n}^n \mu(x-k)) - n - 1 \ , \end{equation} where $\mu$ is the step function. The function $\mu$ has the expression \begin{equation} \mu(x) = \lim_{n \rightarrow \infty} f(nx) \ , \end{equation} where $f(x) = e^{-x^2} + \frac{2}{\pi} \textrm{Si}(x)$. We have \begin{eqnarray} f(x) & = & 1 + \frac{2}{\pi}x + \sum_{k=1}^\infty \frac{(-1)^k}{\prod_{j=1}^k j} x^{2k} + \frac{2}{\pi} \frac{(\prod_{j=1}^{2k} j) (-1)^k}{(\prod_{j=1}^{2k+1} j)^2} x^{2k+1} . \end{eqnarray} The Taylor series converges for every $x \in \mathbb{R}$. Hence there is a representation for $\lfloor x \rfloor$ that applies multiplication, addition and limit.

  • 1
    Im not convinced. For starter the term exp(-x^2) can be omitted i think. Because exp( - n x^2) Goes to 0 as n Goes to +oo ... – mick May 09 '16 at 01:12
0

$$\large \left\lfloor x\right\rfloor = \sum_{n = -\infty}^{\infty}n\Theta\left(x - n\right) \Theta\left(n + 1 - x\right)\,, \qquad x \not\in {\mathbb Z} $$

$$\large \left\lfloor x\right\rfloor = \lim_{z \to x^{+}}\left\lfloor z\right\rfloor\,, \qquad x \in {\mathbb Z} $$

Felix Marin
  • 89,464