<p>The question displays a fundamental misunderstanding about the nature of what can be done with computers.  To correct this misunderstanding, I suggest getting a copy of the computer algebra software <a href="http://www.maplesoft.com/products/maple/">Maple</a> and trying the commands</p>

<pre><code>expand((1+sqrt(2))^5);
sin(Pi/4);
</code></pre>

<p>If computers can only deal with rational numbers, how do you explain the results?</p>

CC BY-SA 3.0
2017-01-22T08:07:43.180Z
You mean that you don't have to know the last 4 digits of Pi in order to do exact computations with it?
Peter - Reinstate Monica
CC BY-SA 3.0
2017-01-25T00:52:09.293Z
+1 for the good answer. Unfortunately, not everyone can try the given commands.
drzbir
CC BY-SA 3.0
2017-01-30T08:58:19.277Z
I think this answer displays a misunderstanding of the question: it is possible in the same way to deal with subjects from art, philosophy, botany, economics--you name it, by using symbols whose meanings we agree to interpret in some particular way. Clearly, the question doesn't ask about the symbols computation can be applied to, but about importance of irrational numbers in the application itself (which I think is rather minor up to be extraneous).
wvxvw
CC BY-SA 3.0
2017-01-21T20:52:48.067Z
2017-01-22T13:30:19.087Z
2017-01-22T13:30:19.087Z
Jeffrey Shallit
<p>You're assuming that numbers can only be represented as fractions (either literally, by having a datatype storing integer numerator and denominator, or implicitly by using some kind of floating point representation) but this isn't true.  For example, you can easily represent rational complex numbers by storing the rational real and imaginary parts. Similarly, you can represent all numbers of the form $a+b\sqrt{2}$ for rational $a$, $b$, and compute exactly with them (note that this class of numbers is closed under addition, subtraction, multiplication and division).  Going a little bit farther, it's not hard to represent all algebraic numbers (i.e., all numbers that are roots of polynomials with rational coefficients). And, hey, you might was well throw in your favourite transcendental (non-algebraic) constants, such as $\pi$ and&nbsp;$\mathrm{e}$.</p>

<p>As to why it's important to be able to deal with irrational numbers: much of mathematics uses them and we want to be able to both do mathematics with computers, and use mathematics to analyze computation.</p>

CC BY-SA 3.0
2017-01-25T15:00:12.423Z
Of course, if you include both $e$ and $\pi$ then in principle you will not necessarily be able to tell whether two quantities are equal.
David
CC BY-SA 3.0
2017-01-25T15:15:29.150Z
@David It depends what operations you allow and what quantities you add. For example, if you close $\mathbb{Q}\cup\{\mathrm{e},\pi\}$ under $+$, $-$ and $\times$, then any expression can be written as a sum of monomials of the form $r\mathrm{e}^i\pi^j$ for $r\in\mathbb{Q}$, $i,j\in\mathbb{N}$ and two expressions are equal if, and only if, their corresponding monomials have the same rational coefficients.
David Richerby
CC BY-SA 3.0
2017-01-25T18:26:09.067Z
Only if you believe that $e$ and $\pi$ are algebraically independent, which is a famous open conjecture.
David
CC BY-SA 3.0
2017-01-22T10:54:06.183Z
2017-01-22T12:24:25.577Z
2017-01-22T12:24:25.577Z
David Richerby
<p>I can see why the question is being downvoted, but this is too good not to post. Suppose you have a coin with bias $p\in[0,1]$, which might be rational or irrational. Question: using only finite memory, can you devise a test for determining whether $p$ is rational or not from a sequence of independent $p$-coin flips? Incredibly, as Hirschler and Cover showed in 1975,
"an 8-state memory with a time-varying algorithm makes only a finite number of mistakes with probability one on determining the rationality of the parameter of a coin. Thus, determining the rationality of the Bernoulli parameter $p$ does not depend on infinite memory of the data."
<a href="http://projecteuclid.org/euclid.aos/1176343194">http://projecteuclid.org/euclid.aos/1176343194</a></p>

CC BY-SA 3.0
2017-01-22T19:16:03.827Z
That seems like a rather misleading summary. The procedure makes only a finite number of mistakes, but you have no idea when it's done making them. It doesn't look like there's any finite time at which you can say "we've determined the rationality of $p$".
user2357112
CC BY-SA 3.0
2017-01-22T20:00:03.780Z
It's a direct quote from the abstract; please address all complaints to Profs. Hirschler and Cover. But really, you wouldn't expect to be able to determine the rationality in finite time *and know it* -- even with unbounded memory, right?
Aryeh
CC BY-SA 3.0
2017-01-23T07:12:53.067Z
@Aryeh: by quoting the paper you've implicitly endorsed it. I do not think it's fair to "forward" the objections to the author, who is not present on this forum.
Andrej Bauer
CC BY-SA 3.0
2017-01-23T07:16:22.293Z
I'm flattered to have someone appraise my standing in the community sufficiently highly so as to be able to "endorse" a result of Tom Cover.
Aryeh
CC BY-SA 3.0
2017-01-29T09:02:48.137Z
_you wouldn't expect to be able to determine the rationality in finite time and know ii_ -- Isn't that what "determine" means?
Jeffε
CC BY-SA 3.0
2017-01-29T09:47:17.827Z
If they had used the phrase "decide rationality", we would say that it's incompatible with modern usage. I do feel a bit surreal having to defend a paper with Thomas Cover as a co-author -- a very clever paper at that. If the cstheory.stackexchange community feels that Hirschler and Cover oversold their results, feel free to open a thread about that somewhere. I just quoted the paper's abstract verbatim.
Aryeh
CC BY-SA 3.0
2017-01-21T20:04:36.667Z
2017-01-21T20:04:36.667Z
Aryeh
<p>Even if you're not trying to compute them, irrational numbers arise throughout computer science, particularly in the analysis of the complexity of algorithms.</p>

<p>For example, if you want to know how deep your <a href="https://en.m.wikipedia.org/wiki/Binary_search_tree" rel="noreferrer">binary search tree</a> needs to be, or you want to know how many steps your divide-and-conquer algorithm will take, you'll need logarithms (see the so-called <a href="https://en.m.wikipedia.org/wiki/Master_theorem" rel="noreferrer">master theorem</a>.) As a bonus, logarithms are not only irrational - they're typically transcendental!</p>

<p>Fibonacci numbers arise in many algorithms (e.g. Fibonacci hashing, Fibonacci heaps, etc.); the Fibonacci numbers are given by
$\frac{1}{\sqrt5}(\alpha^n-\beta^n)$ where
$\alpha=(1+\sqrt5)/2$ and $\beta=(1-\sqrt5)/2$ are both irrational. In particular, $F_{n+1}/F_n$ converges to $\alpha$ (the golden ratio.)</p>

<p>In a different vein, say you have to write code that compresses a certain kind of databases. You'll need to understand the (information-theoretic) <a href="https://en.m.wikipedia.org/wiki/Entropy_(information_theory)" rel="noreferrer">entropy</a> of the language of the information in the database in order to determine how much space you can save; this is computed in terms of logarithms. </p>

<p>In short, as a computer scientist, you can try to hide, but you can't escape the irrationals.</p>

CC BY-SA 3.0
2017-01-23T11:09:41.110Z
But the Fibonacci numbers themselves are rational.
David Richerby
CC BY-SA 3.0
2017-01-23T13:23:23.383Z
@DavidRicherby That's right! But to understand them you need irrationals. Even though they're rational, the *ratio* of consecutive Fibonacci numbers tends to $\alpha$.
Tad
CC BY-SA 3.0
2017-01-26T10:42:39.183Z
More generally, the analysis of algorithms rely a  lot on linear recurrence sequence; their solution is expressed using an *exponential polynomial*, which involve irrational numbers.  Yes, it so happens that all the elements of the sequence are integers, but if you want to compute the $n$-th element, for some large $n$, you'll most likely use a closed form of the sequence.
Michaël Cadilhac
CC BY-SA 3.0
2017-01-26T12:46:37.727Z
@MichaëlCadilhac Yes, and I'd go further. Often (as in the Fibonacci case) the underlying recursive process satisfies the hypotheses of the Perron-Frobenius theorem. In such cases there's a unique eigenvalue $\alpha$ of maximum modulus and the recursive sequence is $\Theta(\alpha^n)$.
Tad
CC BY-SA 3.0
2017-01-22T22:34:08.230Z
2017-01-24T23:18:09.977Z
2017-01-24T23:18:09.977Z
Tad
<p><a href="https://arxiv.org/abs/cs/9907011" rel="noreferrer">Chen and Kao</a> use irrational numbers to reduce the number of random bits in Polynomial Identity Testing (though eventually they use rational appproximations to these irrational numbers of sufficient accuracy)</p>

CC BY-SA 3.0
2017-01-25T08:02:37.140Z
2017-01-25T08:02:37.140Z
Nikhil
<p>One reason that computer scientists can be interested in irrational numbers is because of any of their mathematical properties in various contexts. Such properties can then be utilized in algorithms.</p>
<p>An example: Fibonacci Hashing makes use of the mathematical properties of irrationals and specifically the golden-ratio (the context here is Three-Distance Theorem, which deals with gaps created by fractional-part of multiples of the irrational). Though in the implementation of this hashing, we are actually approximating that irrational (golden ratio) with some rational, but its property helped in making a choice.</p>

CC BY-SA 4.0
2021-01-13T13:35:26.840Z
2021-01-13T13:35:26.840Z
Nitin Verma
<p>Computers can only deal with a few rational numbers. Why is it important as a computer scientist to deal with irrational numbers?</p>

CC BY-SA 3.0
2017-01-22T09:19:31.067Z
Some irrational numbers have an **exact** and **finite** representation (e.g. via periodic continuous fractions).
Bakuriu
CC BY-SA 3.0
2017-01-23T07:13:41.050Z
Computers can deal with [computable real numbers](https://en.wikipedia.org/wiki/Computable_number).
Andrej Bauer
<computability>
Importance of irrational numbers in computer science
user44036
# Importance of irrational numbers in computer science

(Asked by: username_0 on 2017-01-21)

Computers can only deal with a few rational numbers. Why is it important as a computer scientist to deal with irrational numbers?

**Tags:** computability

> **Comments:**
> **username_1**: Some irrational numbers have an **exact** and **finite** representation (e.g. via periodic continuous fractions).  
> **username_2**: Computers can deal with [computable real numbers](https://en.wikipedia.org/wiki/Computable_number).  

---

## 6 answers

### Answer by username_3 on 2017-01-21. Score: 21

The question displays a fundamental misunderstanding about the nature of what can be done with computers.  To correct this misunderstanding, I suggest getting a copy of the computer algebra software Maple and trying the commands
expand((1+sqrt(2))^5);
sin(Pi/4);

If computers can only deal with rational numbers, how do you explain the results?

> **Comments:**
> **username_4**: You mean that you don't have to know the last 4 digits of Pi in order to do exact computations with it?  
> **username_5**: +1 for the good answer. Unfortunately, not everyone can try the given commands.  
> **username_6**: I think this answer displays a misunderstanding of the question: it is possible in the same way to deal with subjects from art, philosophy, botany, economics--you name it, by using symbols whose meanings we agree to interpret in some particular way. Clearly, the question doesn't ask about the symbols computation can be applied to, but about importance of irrational numbers in the application itself (which I think is rather minor up to be extraneous).  

---

### Answer by username_7 on 2017-01-22. Score: 18

You're assuming that numbers can only be represented as fractions (either literally, by having a datatype storing integer numerator and denominator, or implicitly by using some kind of floating point representation) but this isn't true. For example, you can easily represent rational complex numbers by storing the rational real and imaginary parts. Similarly, you can represent all numbers of the form $a+b\sqrt{2}$ for rational $a$, $b$, and compute exactly with them (note that this class of numbers is closed under addition, subtraction, multiplication and division). Going a little bit farther, it's not hard to represent all algebraic numbers (i.e., all numbers that are roots of polynomials with rational coefficients). And, hey, you might was well throw in your favourite transcendental (non-algebraic) constants, such as $\pi$ and $\mathrm{e}$.

As to why it's important to be able to deal with irrational numbers: much of mathematics uses them and we want to be able to both do mathematics with computers, and use mathematics to analyze computation.

> **Comments:**
> **username_8**: Of course, if you include both $e$ and $\pi$ then in principle you will not necessarily be able to tell whether two quantities are equal.  
> **username_7**: @username_8 It depends what operations you allow and what quantities you add. For example, if you close $\mathbb{Q}\cup\{\mathrm{e},\pi\}$ under $+$, $-$ and $\times$, then any expression can be written as a sum of monomials of the form $r\mathrm{e}^i\pi^j$ for $r\in\mathbb{Q}$, $i,j\in\mathbb{N}$ and two expressions are equal if, and only if, their corresponding monomials have the same rational coefficients.  
> **username_8**: Only if you believe that $e$ and $\pi$ are algebraically independent, which is a famous open conjecture.  

---

### Answer by username_9 on 2017-01-21. Score: 16

I can see why the question is being downvoted, but this is too good not to post. Suppose you have a coin with bias $p\in[0,1]$, which might be rational or irrational. Question: using only finite memory, can you devise a test for determining whether $p$ is rational or not from a sequence of independent $p$-coin flips? Incredibly, as Hirschler and Cover showed in 1975,
"an 8-state memory with a time-varying algorithm makes only a finite number of mistakes with probability one on determining the rationality of the parameter of a coin. Thus, determining the rationality of the Bernoulli parameter $p$ does not depend on infinite memory of the data."
<http://projecteuclid.org/euclid.aos/1176343194>

> **Comments:**
> **username_10**: That seems like a rather misleading summary. The procedure makes only a finite number of mistakes, but you have no idea when it's done making them. It doesn't look like there's any finite time at which you can say "we've determined the rationality of $p$".  
> **username_9**: It's a direct quote from the abstract; please address all complaints to Profs. Hirschler and Cover. But really, you wouldn't expect to be able to determine the rationality in finite time *and know it* -- even with unbounded memory, right?  
> **username_2**: @username_9: by quoting the paper you've implicitly endorsed it. I do not think it's fair to "forward" the objections to the author, who is not present on this forum.  
> **username_9**: I'm flattered to have someone appraise my standing in the community sufficiently highly so as to be able to "endorse" a result of Tom Cover.  
> **username_11**: _you wouldn't expect to be able to determine the rationality in finite time and know ii_ -- Isn't that what "determine" means?  
> **username_9**: If they had used the phrase "decide rationality", we would say that it's incompatible with modern usage. I do feel a bit surreal having to defend a paper with Thomas Cover as a co-author -- a very clever paper at that. If the cstheory.stackexchange community feels that Hirschler and Cover oversold their results, feel free to open a thread about that somewhere. I just quoted the paper's abstract verbatim.  

---

### Answer by username_12 on 2017-01-22. Score: 10

Even if you're not trying to compute them, irrational numbers arise throughout computer science, particularly in the analysis of the complexity of algorithms.

For example, if you want to know how deep your [binary search tree](https://en.m.wikipedia.org/wiki/Binary_search_tree) needs to be, or you want to know how many steps your divide-and-conquer algorithm will take, you'll need logarithms (see the so-called [master theorem](https://en.m.wikipedia.org/wiki/Master_theorem).) As a bonus, logarithms are not only irrational - they're typically transcendental!

Fibonacci numbers arise in many algorithms (e.g. Fibonacci hashing, Fibonacci heaps, etc.); the Fibonacci numbers are given by
$\frac{1}{\sqrt5}(\alpha^n-\beta^n)$ where
$\alpha=(1+\sqrt5)/2$ and $\beta=(1-\sqrt5)/2$ are both irrational. In particular, $F\_{n+1}/F\_n$ converges to $\alpha$ (the golden ratio.)

In a different vein, say you have to write code that compresses a certain kind of databases. You'll need to understand the (information-theoretic) [entropy](https://en.m.wikipedia.org/wiki/Entropy_(information_theory)) of the language of the information in the database in order to determine how much space you can save; this is computed in terms of logarithms.

In short, as a computer scientist, you can try to hide, but you can't escape the irrationals.

> **Comments:**
> **username_7**: But the Fibonacci numbers themselves are rational.  
> **username_12**: @username_8Richerby That's right! But to understand them you need irrationals. Even though they're rational, the *ratio* of consecutive Fibonacci numbers tends to $\alpha$.  
> **username_13**: More generally, the analysis of algorithms rely a  lot on linear recurrence sequence; their solution is expressed using an *exponential polynomial*, which involve irrational numbers.  Yes, it so happens that all the elements of the sequence are integers, but if you want to compute the $n$-th element, for some large $n$, you'll most likely use a closed form of the sequence.  
> **username_12**: @MichaëlCadilhac Yes, and I'd go further. Often (as in the Fibonacci case) the underlying recursive process satisfies the hypotheses of the Perron-Frobenius theorem. In such cases there's a unique eigenvalue $\alpha$ of maximum modulus and the recursive sequence is $\Theta(\alpha^n)$.  

---

### Answer by username_14 on 2017-01-25. Score: 5

[Chen and Kao](https://arxiv.org/abs/cs/9907011) use irrational numbers to reduce the number of random bits in Polynomial Identity Testing (though eventually they use rational appproximations to these irrational numbers of sufficient accuracy)


---

### Answer by username_15 on 2021-01-13. Score: 1

One reason that computer scientists can be interested in irrational numbers is because of any of their mathematical properties in various contexts. Such properties can then be utilized in algorithms.

An example: Fibonacci Hashing makes use of the mathematical properties of irrationals and specifically the golden-ratio (the context here is Three-Distance Theorem, which deals with gaps created by fractional-part of multiples of the irrational). Though in the implementation of this hashing, we are actually approximating that irrational (golden ratio) with some rational, but its property helped in making a choice.


---

