ArticleslgStudy

mathematics

Integer square root

Integer square root is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Integer square root rather than just read about it. In short: In number theory, the integer square root (isqrt) of a non-negative integer n is the non-negative integer m which is the greatest integer less than or equal to the square root of n, isqrt⁡(n)=⌊n⌋. For example, isqrt⁡(27)=⌊27⌋=⌊5.19615242270663...⌋=5.

Key takeaways

  • Integer square root belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Integer square root to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Integer square root from memory before moving on to harder problems.

Reference excerpt

In number theory, the integer square root (isqrt) of a non-negative integer n is the non-negative integer m which is the greatest integer less than or equal to the square root of n, isqrt⁡(n)=⌊n⌋. For example, isqrt⁡(27)=⌊27⌋=⌊5.19615242270663...⌋=5.

Introductory remark Let y and k be non-negative integers. Algorithms that compute (the decimal representation of) y run forever on each input y which is not a perfect square. Algorithms that compute ⌊y⌋ do not run forever, but are nevertheless capable of computing y up to any desired accuracy k. Choose any k and compute ⌊y×100k⌋. For example (setting y=2): k=0:⌊2×1000⌋=⌊2⌋=1k=1:⌊2×1001⌋=⌊200⌋=14k=2:⌊2×1002⌋=⌊20000⌋=141k=3:⌊2×1003⌋=⌊2000000⌋=1414⋮k=8:⌊2×1008⌋=⌊20000000000000000⌋=141421356⋮ Compare the results with 2=1.41421356237309504880168872420969807856967187537694... It appears that the multiplication of the input by 100k gives an accuracy of k decimal digits. To compute the (entire) decimal representation of y, one can execute isqrt⁡(y) an infinite number of times, increasing y by a factor 100 at each pass. Assume that in the next program (sqrtForever) the procedure isqrt⁡(y) is already defined and — for the sake of the argument — that all variables can hold integers of unlimited magnitude. Then sqrtForever⁡(y) will print the entire decimal representation of y.

The conclusion is that algorithms which compute isqrt() are computationally equivalent to algorithms which compute sqrt(). Another derivation of y from ⌊y⌋ is given in section Continued fraction of √c based on isqrt below.

Basic algorithms The integer square root of a non-negative integer y can be defined as ⌊y⌋=max⁡{x:x2≤y<(x+1)2,x∈ℕ} For example, isqrt⁡(27)=⌊27⌋=5 because 52≤27 and 27<62. Since isqrt is a computable function, its graph is Diophantine by the MRDP theorem. This is easily made explicit: for non-negative integers x and y, x=isqrt⁡(y) holds if and only if there are non-negative integers a and b with y=x2+aanda+b=2x, since the first equation expresses x2≤y and, given the first, the second is equivalent to y<(x+1)2. The two equations can be combined into the single Diophantine equation (y−x2−a)2+(a+b−2x)2=0. Here a=y−x2 is the remainder, as returned by SqrtRem below. All unknowns are bounded by 2y, so a solution can always be found by finite search; the ascending linear search below is such a search.

Algorithm using linear search The following Python programs are straightforward implementations.

Linear search using addition In the program above (linear search, ascending) one can replace multiplication by addition, using the equivalence (L+1)2=L2+2L+1=L2+1+∑i=1L2.

Algorithm using binary search Linear search sequentially checks every value until it hits the smallest x where x2>y. A speed-up is achieved by using binary search instead.

Numerical examples

isqrt⁡(0)=0, isqrt⁡(1)=1. Using binary search the computation of isqrt⁡(131072) converges to 362 in 17 iteration steps via the [L,R] sequence [0,131073]→[0,65536]→[0,32768]→[0,16384]→[0,8192]→[0,4096]→[0,2048]→[0,1024]→[0,512]→[256,512]→[256,384]→[320,384]→[352,384]→[352,368]→[360,368]→[360,364]→[362,364]→[362,363] The computation of isqrt⁡(2000000) converges to 1414 in 21 steps via the [L,R] sequence [0,2000001]→[0,1000000]→[0,500000]→[0,250000]→[0,125000]→[0,62500]→[0,31250]→[0,15625]→[0,7812]→[0,3906]→[0,1953]→[976,1953]→[976,1464]→[1220,1464]→[1342,1464]→[1403,1464]→[1403,1433]→[1403,1418]→[1410,1418]→[1414,1418]→[1414,1416]→[1414,1415] Linear search (ascending, starting from 0) needs 1414 steps.

Algorithm using Newton's method One way of calculating n and isqrt⁡(n) is to use Heron's method, which is a special case of Newton's method, to find a solution for the equation x2−n=0, giving the iterative formula xk+1=12(xk+nxk),k≥0,x0>0. The sequence {xk} converges quadratically to n as k→∞.

Using only integer division For computing ⌊n⌋ one can use the quotient of Euclidean division for both of the division operations. This has the advantage of only using integers for each intermediate value, thus making the use of floating point representations unnecessary. Let n>0 and initial guess x0>0. Define the integer sequence:

xk+1=⌊xk+⌊n/xk⌋2⌋,k=0,1,2,…

Proof of convergence By definition, the sequence xk consists entirely of positive integers. We must prove it eventually reaches r=⌊n⌋. In fact, we might as well assume x0≥r. Indeed, given any xk>0 we have

r2xk−(2r−xk)=(r−xk)2xk≥0 Thus, ⌊r2/xk⌋≥2r−xk because 2r−xk is an integer, so (noting n≥r2)

⌊n/xk⌋≥⌊r2/xk⌋≥2r−xk. Therefore,

xk+1≥⌊xk+2r−xk2⌋=r. That is, no matter the initial x0>0, the next value x1 is at least r. We have the following monotonicity property:

If xk≥r+1>n, then n/xk<xk, and so (using ⌊n/xk⌋≤n/xk) xk+1=⌊xk+⌊n/xk⌋2⌋≤xk+n/xk2<xk. That is, the sequence decreases. Therefore, the sequence eventually reaches r: if xk>r, it must strictly decrease but never go below r by the first argument. Moreover, if xk=r, a similar calculation to the above shows r≤xk+1≤r+1, so the sequence either stabilizes at r or oscillates between r and r+1. The oscillating case occurs precisely when n=(r+1)2−1, i.e. when n+1 is a perfect square, in which case r+1=⌈n⌉.

Example implementation

Numerical examples The call isqrt(2000000) converges to 1414 in 14 passes through while:

1000000→500001→250002→125004→62509→31270→15666→7896→4074→2282→1579→1422→1414→1414. One iteration is gained by setting x0 to ⌊n/2⌋ with the call isqrt(2000000, 1000000). Although Heron's method converges quadratically close to the solution, less than one bit precision per iteration is gained at the beginning. This means that the choice of the initial estimate is critical for the performance of the algorithm. When a fast computation for the integer part of the binary logarithm or for the bit-length is available (like e.g. n.bit_length() in Python), one should better start at x0=2⌊(log2n)/2⌋+1, which is the least power of two bigger than n. In the example of the integer square root of 2000000, ⌊log2n⌋=20, x0=211=2048, and the resulting sequence is 2048→1512→1417→1414→1414. In this case only four iteration steps are needed. This corresponds to the call isqrt(2000000, 2048).

Generalization to Nth roots Newton's method may be applied to compute ⌊nN⌋ in a manner entirely analogous to the N=2 case. Using integer division, the sequence becomes

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Integer square root

Start with the simplest possible case. Write down what Integer square root claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Integer square root before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Integer square root ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Integer square root

In research
Integer square root appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Integer square root in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Integer square root is common in secondary-school and first-year university syllabi. It links to neighbouring topics Number theoretic algorithms, Number theory, Root-finding algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Integer square root outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Integer square root” →

How to study Integer square root in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Integer square root means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Integer square root out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Integer square root in simple terms?

In number theory, the integer square root (isqrt) of a non-negative integer n is the non-negative integer m which is the greatest integer less than or equal to the square root of n, isqrt⁡(n)=⌊n⌋. For example, isqrt⁡(27)=⌊27⌋=⌊5.19615242270663...⌋=5.

Why does Integer square root matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Integer square root?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Integer square root.

Tags

  • Number theoretic algorithms
  • Number theory
  • Root-finding algorithms

Keep exploring