Can exact square roots not be found? I'm brushing up on some higher level maths for a programming project. I was going along and then I realized that I have absolutely no idea how square roots can be computed.
I mean sure, I've memorized a lot of perfect squares. But I wouldn't be able to get an exact answer from some arbitrary number like 432,434, would I?
I Googled how to calculate square roots and everything always points to it basically being based on algorithms which have a degree of error because they're more or less guesses.
I can't seem to find out why it's impossible to get an exact square root though. Like why can't you plug in $x$ to a function $f(x)$ and get the exact square root?
Very curious about this.
 A: It depends what data types you have available in your programming environment. Typically, you’d be using double-precision floating-point numbers. But floating-point numbers are always rational numbers (quotient of two integers), and square roots are often not rational, so they can’t be represented exactly by floating-point values. 
If you have a more exotic set of data types, you may be able to represent some (but not all) square roots exactly. 
But there’s not really much point calculating square roots exactly unless our divisions and trig functions are also exact (which they are not, in floating-point math).
A: You can't find the exact value of square roots for non-square number. For the same reason you can't calculate the exact value of $\pi$ or $e$.
It's not a question of programming or approximation. Square roots of non-square numbers are irrational numbers.
One of their properties is that you can't calculate an exact, numeric value for them, you can't represent them in decimal notation. You can represent them with a symbol or approximate them, but that's it.
$\sqrt 2$ is actually the most famous irrational number, and is the reason we discovered them.
A: Technically speaking, when you find $\sqrt2 = 1.414 ...$, you're calculating the decimal expansion of the square root of 2. When people say things like "calculate the square root of 2", what they generally mean is to find this decimal expansion. That's because when people think of the term "number", what they generally think of is "number represented in decimal format". Since the decimal expansion has an infinite number of digits, it's impossible to calculate in its entirety. (Although, more technically speaking, decimal expansion is writing the number in terms of powers of ten, while floating point expresses numbers in terms of powers of two, but that distinction doesn't affect this particular issue).
However, if we consider "number" as simply an abstract data class with particular methods, then it is possible to have a data class in which "square root of two" is a valid object, and an object whose square is exactly equal to two. In this context, the phrase "calculate the square root of two" would not have a clear meaning. We might have a print method that takes a number of digits, and outputs that number of digits. For instance, we might have that two.power(one.divide(two)).print(5) (i.e "print five digits after the decimal point of 2^(1/2)") gives the output 1.41421, but precise language would refer to this in terms of the method that is defined in the class, rather than just referring to it as "calculating" the square root of two. If you just type two.power(one.divide(two)), then depending on how the class is implemented, it may indeed "calculate" the floating point representation of $\sqrt 2$, but it may represent the object in a more abstract form. In the former case, two.power(one.divide(two)).power(two) (that is, $(\sqrt 2)^2)$) could be slightly less than 2, but in the latter case, it could very well return exactly 2. (It could also return exactly 2 in the former case, depending on how the rounding is set up).
A: The square roots of non-perfect-square-integers are irrational numbers, which means that they have an infinite number of decimals, that do not repeat. So it would be a little tedious to write down the exact value...

Square roots can be computed, among others, by the so-called Heron's method (known BC), which is of the "guess" type, but converges extremely fast.
A: I understand that this question is actually about the representation of the square root in binary (float) or decimal notation.
However, that is not what these numbers are about themselves.
$\sqrt 3$ is itself a perfectly valid number and an exact representation of the number that is the square root of 3. It can't be exactly represented as a binary or decimal number as these representations ar fairly limited (you can't even find an exact $1/3$ in either of those). But you can find it up to a certain precision.
Furthermore, these representations are actually used in computers. For example, Wolfram Mathematica will not replace $\sqrt 3$ or $\frac 2 {17}$ with an approximate representation which could screw up simplification later on. If you need the precision, you can exactly the same - store the numbers in a fancy structure that allows you to save the fact that it's a root of some number.
A: An irrational number cannot be equated to a finite series of rational numbers, only an infinite series of such. 
Assuming $x$ is rational, a fairly compact infinite series of rational numbers which equate to the square root and its reciprocal, that are derived from the generalized binomial theorem, are given below:
$$\sqrt{x} = \sum_{k=0}^\infty \frac{1}{4^k}\binom{2k}{k}\left(1-\frac{1}{x} \right)^k$$
and
$$\frac{1}{\sqrt{x}} = -\sum_{k=0}^\infty \frac{1}{4^k \left( 2k-1\right)}\binom{2k}{k}\left(1-\frac{1}{x} \right)^k$$
where $x>1$. See here for proof. 
Unfortunately these series are much slower to converge to the desired values than other approximation/iterative methods available. Not even the most efficient algorithm will find you the exact value for a square root in your lifetime.
A: Square roots are typically computed by root finding; if you want to find $\sqrt{x}$, you would use a root finding algorithm on
$$g(t) = t^2 - x$$
One such algorithm would be, for example, Newton's Method. Wikipedia has an entire page describing algorithms for root finding, and some more for computing square roots.
The unifying theme behind these algorithms is that you define a sequence $\{x_n\}_{n \in \mathbb{N}}$ such that $x_n \to x^*$, where $g(x^*) = 0$ and, depending on the algorithm and function, you can prove that it converges to the true root, and that it does so with a certain speed. The convergence properties usually depend on a good first approximation to where the root is, so not everything's rose colored. However, a priori this means that you can get arbitrarily close to the root and, for well behaved inputs, you will get the actual root (i.e. perfect squares).
As many other answers described, computers work with a floating point representation, which are limited in what they can represent to a subset of the rational numbers. This means, in practice, that most numbers can't in fact be handled by your computer, and furthermore that you have to take several precautions when working with them; "What Every Computer Scientist Should Know About Floating-Point Arithmetic" is a pretty classic introduction, which is also friendly for math students.
Computer Algebra Systems usually choose to instead work with a symbolic representation of math: instead of using actual numbers, implement the typical rules of math on symbols. In this approach, you would have a representation for $\sqrt{2}$, and a rule that tells you $\sqrt{x}^2 = x$; thus $\sqrt{2}^2 = 2$. At the end, they do have to approximate, but they have the most accurate representation possible until the very last minute, which avoids many errors.
If you are interested in reading more, "Numerical Analysis" by Richard L. Burden is a book I really liked when taking my Numerical Analysis class.
A: Square roots(and all other roots and some other interesting functions) of some numbers are irrational numbers. It means that they have infinite trail of digits after a decimal point(or comma in some other languages) and these digits are not periodic. Your screen has a finite number of pixels so it cannot depict an infinite number of digits. Therefore you will have to omit some of them. Even if you depict 50000 first digits and omit the rest of infinity it's still not exactly precise.
However don't think that such numbers are somehow unreal. They are used to measure physical quantities in given units. For instance if you have a square with a side exactly 1 meter long then its diagonal equals exactly square root of 2.
A: Depending on what you're trying to do with the square root once it's been computed, a pair of floating point numbers bracketing the true value might be good enough. This is called Interval arithmetic .
Here's an example demonstrating the use of pyinterval (credit here for extracting the bits of a double in Python).
from interval import interval, imath
import struct

# https://stackoverflow.com/a/23624284/931154
def double_to_hex(f):
    return hex(struct.unpack('<Q', struct.pack('<d', f))[0])

a = interval(10)
b = imath.sqrt(a)

print(b)
print(double_to_hex(b[0][0]))
print(double_to_hex(b[0][1]))

When run, this script produces the following output, the two hexadecimal numbers are the bit patterns of the floats, so it's clear they aren't identical.
interval([3.16227766017, 3.16227766017])
0x40094c583ada5b52
0x40094c583ada5b53

Because isqrt (interval sqrt) has a dedicated implementation in the library, the interval produced is as narrow as possible, but functions do not produce narrow intervals in general. Successive operations tend to cause the interval to grow. It's also important to keep in mind that interval arithmetic is inherently pessimistic, especially if the same variable appears multiple times in the expression of interest.
A: Even supposing you could symbolically handle irrational numbers in your program, if x is a rational and f(x) can be irrational, there's no rigorously defined (i.e. finite) algorithm to implement f, whatever it may be. Square root is just one example of such f.
You cannot express (using rational numbers) the square root of an arbitrary integer x with a mathematical tool less complicated than an infinite sum.
That said, if you want a fancy, practical yet fascinating (that's opinionated) answer to your original problem, I'd suggest reading this: https://en.wikipedia.org/wiki/Fast_inverse_square_root
A: You cannot always get exact square roots because of the nature of the numbers, for example square root of 2 is irrational meaning you have a infinity of decimals
