# Why are integers subset of reals?

In most programming languages, integer and real (or float, rational, whatever) types are usually disjoint; 2 is not the same as 2.0 (although most languages do an automatic conversion when necessary). In addition to technical reasons, this separation makes sense -- you use them for quite different purposes.

Why did they choose to say $\mathbb{Z} \subset \mathbb{R}$ in math? In other words, why are 2 and 2.0 considered the same?

When you are working in $\mathbb{R}$, does it make any difference whether some elements, eg. 2.0, also belong to $\mathbb{Z}$ or not?

• In the first place, ${\mathbb Q}$ and ${\mathbb R}$ are successive extensions of ${\mathbb Z}$; so ${\mathbb Z}\subset{\mathbb R}$ to begin with. – Christian Blatter Dec 7 '14 at 10:52
• Looking in the other direction, one reason not to consider $\mathbb Z\subset \mathbb R$ in a programming language is that 1 / 3 = 0 but 1. / 3. = 0.333.... This breaks the Liskov substitution principle. – Veedrac Dec 7 '14 at 15:04
• I think it's worth mentioning that real numbers in typical programming language are fixed-size, that roughly means fixed-precision, so they are very different from real numbers as defined in mathematics. Floating-point number types are an engineering artifact without any relation to clear and well-defined mathematical concept. Google "What Every Computer Scientist Should Know About Floating-Point Arithmetic" for the details. – artem Dec 8 '14 at 19:39
• "Real" types in programming languages have almost nothing to do with the set of real numbers as defined by mathematicians. k-bit floating-point numbers in programming languages are an attempt to map real numbers onto 2^k distinct values and while the IEEE standards are fairly universal there exist other mappings with very different properties. – Chuu Dec 8 '14 at 20:33
• You write your question as if programming languages had been around "forever" and then these math guys came along and decided that, suddenly, integers are a special kind of real number. It was actually precisely the other way around. – David Richerby Dec 8 '14 at 22:19

If you want to do things very formally, the integers are in fact not a subset of the reals: they are entirely different constructs (which I guess is more or less what you are saying in your question). However, the reals do contain the set $$\{\,\ldots,\,-2.0,\,-1.0,\,0.0,\,1.0,\,\ldots\,\}$$ which "looks just like" the integers. The usual terminology is that the sets are isomorphic. If you take any true statement in the arithmetic of integers, and replace each integer by the corresponding real number, the result will be a true statement about the real numbers. For example, the statement $$2+3=5$$ corresponds to $$2.0+3.0=5.0\ .$$

• The statement “2 does not divide 1” is true in the integers, but the corresponding statement is false in the reals. What you write is only correct for existential sentences (in the language of rings), not for more complicated statements. – Emil Jeřábek Dec 7 '14 at 20:01
• The correct translation of "$2$ does not divide $1$" is that there is no element $x$ of $\{\ldots,-1.0,0.0,1.0,\ldots\}$ such that $1.0=2.0x$. This statement is true. – David Dec 7 '14 at 20:48
• You want the remainder to be strictly smaller than the divisor. – David Dec 8 '14 at 3:18
• @Lawtonfogle If by $2$ you mean the element of $\mathbb{Z}$ and by $3.0$ the element of $\mathbb{R}$ defined formally in the way David mentions, then $2+3.0$ is (strictly speaking) meaningless. You can't just add two things; there must be an addition operation you're using, and there's no standard addition operation that takes an integer on one side and a real number on the other. – cpast Dec 8 '14 at 19:04
• Some programming languages have a thing called "coercion": a way to automatically cast elements of some types into other types when the need arises (i.e., when an operator which is defined on the other type is applied to an element of a smaller type). I am not sure how good the theory behind this is understood (issues like this tend to break into Univalent Foundations occasionally). But mathematicians tacitly use coercion all the time -- even viewing $\mathbb{Z}$ as a subset of $\mathbb{Q}$ is an instance of coercion if you define rational numbers as fractions! – darij grinberg Dec 9 '14 at 4:34

Formally speaking, this depends on the context.

Sometimes it's nice to have everything as a subset. It's easy to have that an integer is a real number, since it allows us to talk about the subspace topology, and that the operations coincide with what we expect them to be.

Sometimes it's not as nice, in which case we prefer to talk about "embedding", namely there is an embedding (which is unique up to some properties preserved) which identifies a subset of the real numbers with the integers.

If you want to build things from the ground up, then you're right. You build the natural numbers, then you build the integers and then the rationals and finally the real numbers (and you can continue). Each step comes with some canonical embedding, which we can then extend and have a canonical way to identify the natural numbers with a subset of the real numbers, and so on.

But sometimes it's nicer to say "Okay, now that we have $\Bbb R$ and all those canonical subsets which behave like $\Bbb{N,Z,Q}$ and so on, let's redefine them as these subsets." now we can talk about subspaces directly and subrings and subfields and so on and so forth.

Similarly you might want to have $\Bbb R$ as a subset of $\Bbb C$, and sometimes as a subspace (and therefore a subset) of $\Bbb R^3$; and sometimes you will want to have these objects separated as "different types", and keep track on the embeddings.

If you want to focus on the example of $2$, then note that $\Bbb Z$ and $\Bbb Q$ and $\Bbb R$ are all rings (whatever that means) which has a unit, and $1$ is that unit, so each has a version of $1$ and $2$ is defined as a shorthand for $1+1$. Does it matter where you do this addition? No, it doesn't, since the term $1+1$ is syntactical in the language of rings, and will have similar properties in $\Bbb Q$ and $\Bbb R$, and the same properties in $\Bbb Z$. Since it doesn't matter for the basic properties of $2$ in which of these rings we consider it, we can just think about those rings coincide on these numbers.

Programming languages usually offer implicit conversions: you can usually use an integer in any context where a floating point number is required. This is very convenient.

Even in mathematics, we often need to convert integers into real numbers, and we have a canonical function $\mathbf{Z} \to \mathbf{R}$ for doing the conversion. This conversion is often done implicitly, so you rarely see actual notation for it.

In some styles of reasoning, particularly those motivted by algebra or category theory, we believe that "subset" is a bad notion: we should think about subobjects instead; loosely speaking, that means we think about monomorphisms relating objects. We might even coopt the notation $\subseteq$ for talking about subobjects instead of subsets.

Unfortunately, I don't believe there has been any work done in formalizing the mathematical usage of implicit conversions. I think there is work that can be done in that regard, just that I haven't seen anyone do it.

However, in more traditional, set-theoretic style notation, we try to arrange so all of the implicit conversions are identity maps. This is a very powerful simplification, both in the use of and in the organization of implicit conversions. But it can obscure what's going on -- it can be very difficult to make the transition to contexts where the conversions need to be explicit.

Of course, none of this really reflects history. I expect the most accurate response to "why are things this way?" is simply that once upon a time people believed there was One True Number System, and "being an integer" is merely a property that some numbers have and others don't.

• Many programming languages have implicit conversions, but the more mathematical ones actually tend not to – I think it would be a horrible mess to properly formalise such conversions. What languages like Haskell use instead is just as powerful and convenient, but immediately safe&sound, mathematically: in Haskell, a literal like 5 has no particular type at all. Rather, a type is inferred from the context (Hindley-Milner type system). So in 5 + length "bla", you have 5 :: Int, but in 5 + pi you have 5 :: Double. – leftaroundabout Dec 7 '14 at 20:46
• Arguably, rather a lot of work in the last 50-60 years of programming language research has concerned "formalizing the mathematical usage of implicit conversions" well enough to program a computer to understand something that a human with mathematical training would understand, while striking a reasonable balance between internal consistency and approximating the way real mathematics is written. E.g. in the guise of type inference for type systems with a subtyping relation. – Henning Makholm Dec 7 '14 at 20:54
• @Henning: Good point: I hadn't thought about it from that angle; my opinion on that point could very well just be a function of following my own mathematical interests rather than a function of reality. – Hurkyl Dec 7 '14 at 21:26
• As @HenningMakholm remarks, there is a lot of work on formalizing the mathematical (or logical) principles of such embeddings, usually called coercions. This is of particular interest in computer assisted mathematical formalization, see e.g. Luo or Wenzel. – cody Dec 12 '14 at 1:09

It's practical to consider the reals and the integers as points on the same geometrical line, even though the axiomatic construction of reals may seem far away from the integers.

In programming language all types has to be declared and treated different. Even different representations of integers are treated different (as Integer and BigInteger).

And there are no reals at all in programming, just float: truncated reals.

Your question is in fact perfectly legitimate. Throughout most of the history of mathematics, the discrete realm of numbers was distinct from the continuous realm (the continuum), and of course the continuum was not thought of as made up of either points or numbers. Perhaps the first mathematician to have begun to bridge the gap was Simon Stevin already in the 16th century, and James Gregory in the 17th. There is some fine work on the latter by the historian Antoni Malet. See for example his thesis

Malet, Antoni; Studies on James Gregorie (1638-1675). Thesis (Ph.D.)–Princeton University. 1989.

and a number of other articles. The idea of uniting the two domains turned out to be fruitful as far as practicing mathematics is concerned, but as you correctly point out, in other fields such as computer science this assumption has to be re-examined!

• I think the notion of commensurable and in incommensurable pairs of lengths was studied in ancient Greek mathematics. So they were aware of things (ratios) that could be either rational or irrational; I think it is fair to say that in some sense the inclusion of the rational ratios (and therefore the integer ones) as strict subset of all possible ratios already occurs there, even though the number concept was rather different from ours. – Marc van Leeuwen Dec 8 '14 at 17:06
• @MarcvanLeeuwen, thanks for your thoughtful comment. I am not sure I agree with the implication implied by your "So". We think of these as irrational numbers, but I don't think they did, as you seem to acknowledge in your final comment on the difference between the number concepts. – Mikhail Katz Dec 9 '14 at 8:48
• Disclaimer: I am not a historian. Was not Eudoxus' theory of incommensurables an attempt to unify what we would nowadays call rationals and irrationals? – David Dec 9 '14 at 10:24
• @David, good question. My impression is that what you are suggesting is a modern interpretation of what is attributed to Eudoxus. Seems like a good candidate for a separate question. There are a few historians of math active at MO so I would suggest posting it there. – Mikhail Katz Dec 9 '14 at 10:29

The Integers are not strictly a subset of the Reals. In particular, $0$ in the integers is not exactly the same as $0.0$ in the real numbers. (I use a common programming language notation here.) They behave slightly differently. The main example is:

$$0^0=1 \text{ and}$$ $$0.0^0=1 \text{, but}$$ $$0.0^{0.0} \text{ is undefined}$$

The integers $\{\ldots,-2,-1,0,1,2,\ldots\}$ are isomorphic to a subset of the real numbers, namely $\{\ldots,-2.0,-1.0,0.0,1.0,2.0,\ldots\}$. This means that the two sets behave identically with respect to addition and multiplication. So we usually say that the two sets are identical, for all practical purposes.

However, addition and multiplication are not all there is. Exponentiation (powers) can be defined in several ways, and for a variety of reasons (including historical and contextual) it is usually defined differently for the integers and for the reals.

Why do we usually say that $0^0=1$? The non-negative integers are isomorphic to the finite ordinal numbers, and some mathematicians such as von Neumann said that they are identical. So given non-negative integers $m$ and $n$ we can use any sets $M$ and $N$ with the appropriate sizes (cardinalities) and say that $m^n$ is the cardinality of the set of all functions from $N$ to $M$. This is proved in set theory to be possible and well-defined, and by this definition $0^0$ is indeed $1$. (The only function from the empty set to the empty set is the empty function--namely the empty set.)

Why do we usually say that $0.0^0=1$? For non-zero real values $x$, $x^0=1$, and it makes sense to let $0^0=lim_{x \to 0}x^0=1$. It is true that $0.0^n=0$ for positive integers $n$, but there is a break with that pattern for negative integers anyway. So who cares if $0.0^n$ differs from $0.0^0$? There is no good reason here to make $0.0^0$ undefined.

There are many other reasons for zero power integral zero being one. For example, we often write this as a polynomial for integral or real $x$: $$\sum_{i=0}^n a_ix^i$$

But the "constant" term there is $a_0x^0$, which makes sense only if $x^0=1$ for all $x$, integral or real, including zero.

For some more points, look at my favorite programming language, Object Pascal as implemented in Borland Delphi / Embarcadero Delphi. Zero power integral zero is implemented as IntPower$(0.0, 0)$, which evaluates as $1$, even if Power$(0.0,0.0)$ is undefined. Or look at the popular calculator TI-84 Plus, which evaluates $0^0$ and $0.0^0$ as $1$, though with a warning that it might be undefined.

Why do we usually say that $0.0^{0.0}$ is undefined? Here we look at $x^y$ for real $x$ and $y$ as the point $(x,y)$ approaches the point $(0,0)$ along various paths. If we set $y=kx$, $x^y$ approaches $1$ as both $x$ and $y$ approach zero from the right. If we set $x=0$, the limit is $0$. Other paths give other limits. Therefore we cannot say that $x^y$ has any limit as $x$ and $y$ approach zero, so we declare that $0.0^{0.0}$ is undefined.

Note that this reason, as well as others with which I am familiar, does not apply to $x^0$ where the zero is integral. So I conclude that integral zero and real zero are not exactly the same.

Note that this is similar to the real numbers not exactly being a subset of the complex numbers. For example, the cube root of real-valued $-1$ is $-1$ but the cube root of complex-valued $-1$ is $\frac 12+\frac{\sqrt 3}2i$. (Did I open another can of worms?)

• That's an... interesting perspective. I can see some sense to what you're saying ($m^k$ in the integers can be thought of---cardinality-wise---as the set of all functions from $k$ to $m$, so there is only one of those for $0 = \{\}$), but that is a little idiosyncratic. I would say that $0^0$ is always defined or undefined based on context, personally. – Simon Rose Dec 7 '14 at 14:45
• To me $0^0$ is defined (and equals $1$ no matter which $0$ you take, i.e., also $0.0^{0.0}=1.0$. It's just that the power function is not continuous near those border cases of its domain (that is $a_n\to 0$, $b_n\to 0$ does not imply $a_n^{b_n}\to 1$ or even that all $a_n^{b_n}$ are defined). - Would you extend your distinction to say that the indicator function $1_{\mathbb Q}$ has the properties $1_{\mathbb Q}(\sqrt 2)=0$, $1_{\mathbb Q}(\frac12)=1$, but $1_{\mathbb Q}(0.5)=0$? – Hagen von Eitzen Dec 8 '14 at 7:01
• I see your point on $0.0^{0.0}=1$ but apparently few others agree with that. On your second point, $1_{\mathbb Q}$ is a function of the real numbers that equals zero for any value that is in the subset of $\mathbb R$ that is isomorphic to the rational numbers. I.e. the function is defined on real numbers, and there $0.5=1/2$, so clearly $1_{\mathbb Q}(0.5)=1$. – Rory Daulton Dec 8 '14 at 11:05

There are very many reasons, but first of all, if the real numbers did not contain the integers then it would be very very very difficult to do elementary arithmetic.

Computers don't have any way to represent "real numbers", they can represent only integers and rationals.

• I didn't mean to ask why 2.0 belongs to R, rather why are 2 and 2.0 considered the same in maths. – Aivar Dec 7 '14 at 10:37
• @Aivar: It is not clear from the question as it is currently written that this is the sort of information you are interested in; please edit accordingly. – Eric Stucky Dec 7 '14 at 11:20
• 2 and 2.0 are the same mathematically because the latter means $2 + 0/10$. – murray Dec 7 '14 at 17:33
• Computers are quite capable of representing some irrational numbers. I can use a pair of rationals to represent $a + b\sqrt 2$, for example. – Ben Millwood Dec 8 '14 at 15:24
• Computers have a way to represent whatever is computable. For example, all algebraic numbers are, although they are mostly irrational. – Incnis Mrsi Dec 8 '14 at 20:29

Why shouldn't we say $\mathbb Z\subset \mathbb R$?

In some cases it makes a lot of a difference to be able to conslude that some number obtainined by calculations within $\mathbb R$ is an integer as that allows us to do much more.

• Could you please give an example where it matters – Aivar Dec 7 '14 at 10:35
• @Aivar: I'm not sure if this is what Henrik is suggesting, but we can prove that $e$ is irrational by (1) assuming $e = \frac{b}{a}$ for integers $a$ and $b$, and then (2) 'finding' an integer between $0$ and $1$, which we know is impossible. See here. – Strants Dec 7 '14 at 19:51

@David's explained that $\{\dots, -2.0, -1.0, 0.0, 1.0, 2.0, \dots\}$ can be considered the set of integers because the sets have the same mathematical properties. I'm complementing this by adding another point of view, trying to explain why I don't see this only as a mathematical isomorphism but something more intuitive.

Natural numbers ($\mathbb{N}$) are the objects that can be used for counting things: you can for example have $0$, $1$, or $2$ apples.

Integers ($\mathbb{Z}$) are an extended version of these objects used for counting: now you can also subtract them as you wish. Why $\mathbb{N}$ is considered as a subset of $\mathbb{Z}$? Because it is natural to use them in a similar way: if you have five apples, and you eat two of them, how many apples do you have in the end? $5 + (-2) = 3$.

Now consider real numbers ($\mathbb{R}$). Here's an example: For which $x\in\mathbb{R}$ is $\sin(\pi x)$ zero? When $x$ has a certain property. If $x>0$ has this property, how many zeros does $\sin$ have in $(0,\pi x]$? The answer $x$ is an object of $\mathbb{R}$, but it is now used for counting things! So it is a natural number.

The statement $ℤ ⊂ ℝ$ is in fact true, $ℤ ⊂ ℚ$ is also true. $3 = 3.0 = \sqrt{9} = \frac{6}{2}$ It does not really matter how you represent the number, they are all the same number: three. What does in fact matter is the domain you are operating in. For example $\sqrt{2}$ is not defined in the space of $ℤ$, nor is $2-3$ defined in $ℕ$. While they are all perfectly defined in $ℝ$ All these sets $ℕ, ℤ, ℚ, ℝ$ are infinite, while $ℝ$ is also nondenumerable.

entirely different set of numbers are the sets representable by computers, eg int32 (32 bit integer) and float32 (32 bit IEEE floating point number). because 32bits can only have $2^{32}$ distinct states, we can say $|int32| ≤ 2^{32} ∧ |float32| ≤ 2^{32}$. And both sets have numbers non-representable in the other format. Folloing statements are true

\begin{align*} int32 &⊂ ℤ \\ float32 &⊂ ℚ ∪ \{-∞,∞,NaN\} \\ -∞,∞,NaN &\notin ℝ \\ int32 &\not⊂ float32 \\ float32 &\not⊂ int32 \\ \end{align*}

A $1$ from int32 is still just a 1. A $1$ in float32 is also just one. Same is for all numbers in $int32 ∩ float32$. They are just different representations. You have to be careful when casting to another type, because when your number is not representable in the other type, you have loss of information.

just because in some programming languages 2.0 and 2 are different things, doesn't mean that 2.0 and 2 are different in math. Math on computers is very different from math in algebra class.

to come back to your question: do not mix up ℤ and ℝ from math with float and int in programming languages. And on a computer you are never really working in ℝ. Some symbolic prgramming languages allow you to deal with π exactly, but here the computer just curcumvents the calculation by applying transformation rules (like you would do on a paper).

• Thanks for the answer! In my question, the programming languages' way was just an example. The real question is what's the benefit of making Z subset of R. It seems quite easy to take an alternative road and build up Z and R so that 2 is not the same as 2.0. But what would I lose then? – Aivar Dec 10 '14 at 8:07
• I don't think I can answer that in a comment what you would loose when 2 is not the same as 2.0. But you would at least loose this nice relation that so many mathematicians already got used to and like: ℕ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ – Arne Dec 12 '14 at 21:59