11 ms·
Estimating square roots in your head
- Corun 4y agoKnowing powers of two in your head (as I guess many of us do) can helps with root estimates and this algorithm. Take an example sqrt(5819): That's between two powers of two 2^12 = 4096 and 2^13 = 8192. The square roots of those numbers are easy, since you just half the exponent sqrt(4096) = 2^6 = 64 That gives us our initial estimate g for the algorithm from the article. Now we do: b = n / g = 5819 / 64 To do this division in our head we remember that we already know 4096 is 64 x 64. So we just need the remainder (5819 - 4096) / 64 ~= 1700 / 64. Now that's low enough that I can approximate it in my head 64 * 30 is too high by about 3 * 64 so the answer should be around 27 (actual answer 26.5). So b = 64 + 27 = 91 So now we finish the algorithm, sqrt(5819) ~= g + b / 2 = (64 + 91 / 2) = 77.5. So, how did we do? The actual sqrt is 76.28, so seems pretty good!
- chadlavi 4y agoThat's pretty neat. I'll never need to use it, but it's pretty neat.
- themeiguoren 4y agoWho want to calculate a fraction in their head? My method for this: * Pick the lower integer square root (5) * The distance from 25 to 33 is over half the distance from 25 to 36. * Eyeball that that little over half on a mental picture of sqrt(x) between 0 and 1. Guesstimate 0.7. * 5.7 is the guess. You can multiply that out on your head and similarly iterate on the error if you want closer.
- barbazoo 4y ago> We start by finding a number that forms a perfect square that is close to 33 I usually just stop there which works for my use cases. :) > b=n/g. In practice, computing b in your head may require an approximation I'm not sure how realistic this is to do in your head at all. Won't you introduce an error similar to the error of g anyway? Maybe "in your head" means without a calculator but on paper using long division.
- nicoburns 4y ago> Maybe "in your head" means without a calculator but on paper using long division. There's not really any benefit if you have paper available. But it's possible to do long division (and other "paper" techniques) in your head if your short-term memory is good enough.
- lcnPylGDnU4H9OF 4y ago> But it's possible to do long division (and other "paper" techniques) in your head if your short-term memory is good enough. That's actually how I learned long division. I didn't want to pay attention to any of these weird methods of arithmetic that require me to write things so I just did it all in my head and this happened to be a method that worked (go figure!). Many of my K12 math teachers understandably didn't like the fact that I would write down the correct answers to things without showing how I got there. On the topic of this article, I'm actually really glad for this trick. If anything is my hobby it is mental arithmetic.
- lurquer 4y agoBtw, doing long division in your head (during sex) is a good way to increase endurance…
- jethro_tell 4y agoso, I don't know why this isn't brought up, but doing a lot of this kind of stuff in the field on construction sites, I'd have used 5 x 5 = 25 and 6 x 6 = 36 then split the difference so (36-25)/2 = 11/2 = 5.5, then you split the difference again in this process. For me, most estimation in the field is finding two known facts above and below and splitting the difference. Depending on your required precision, the above gets you pretty close right off the bat.
- paulpauper 4y agothat is really cool it's interesting how it's a direct application of calculus. was not expecting that
- sfpotter 4y agoHerons’s method is just Newton’s method applied to the problem of computing a square root recast as a rootfinding problem.
- zabzonk 4y agoi think estimating is one of the most important skills in maths (well, arithmetic/common sense) that is rarely taught in schools. for example, estimating the cost of your supermarket trolley, estimating how much wallpaper you will need to paper a room, etc. now, obviously you want to get these things accurate, but the estimate tells you when you got the calculation wrong in your measurements, spreadsheet or calculator. i was guilty of this when i over-valued my late-dad's book collection in a python program. i sort of knew it was wrong but what i didn't realise he had changed his data format halfway the dataset.
- mapierce2 4y agoYou're right. It's hard to teach in schools though because of standardized (often multiple-choice) tests; teachers are incentivized to teach "skills" that have objective correct answers that can be easily tested. Then by the time students hit college, they're resistant to any sort of mathematics that doesn't have a correct answer. I've been trying to sell it as a means of error-correction, or as a sanity check. If they've gotta answer a question "Joe is 6'4" tall and, at the suggestion of an ergonomist, wants to build a desk 40% of his height. How tall should the desk be?" I urge them to not immediately go into math-brain and just think for a minute, and estimate a reasonable answer to match their calculations against. This mental workflow sticks for a few of them by the end of the class.
- delecti 4y agoAbsolutely. The concept of a "sanity check" is so valuable. Thinking about what the answer should "look like", ignoring the precise value, always makes me much more confident in a precise value I've computed. It's the kind of thinking makes math so much more useful in the "real world" too.
- JohnFen 4y agoIt was my shop teacher who taught me the value of estimating. As he put it, "in the real world, you rarely need high precision. Start with the quick-and-dirty, most of the time that's plenty good enough."
- deleted 4y ago[deleted]
- phkahler 4y agoI've used this is control systems where I wanted the square root of a signal. Given that the signal should not change quickly (may even have a low pass filter on it) doing one iteration of this is much quicker than doing a regular square root computation each time step. Obviously, the usefulness of an approximation depends on what you're doing, but this does converge to the exact solution over time ;-)
- ubicomp 4y agoWe played a game in high school that I called "The Root is Right!" We'd take turns coming up with crazy numbers for each other to estimate in our heads. Then we'd draw little pictures of prizes for the person closest to the real root. We all got super good at estimating roots! We used a lazy version of Heron’s method, which was just to memorize a bunch of general number roots, and then average our guesses based on closeness to that root. It ended up being as easy as mental math around tipping at a restaurant. It definitely came in handy for engineering classes later on!
- kadoban 4y agoIt converges more slowly, but you can also just binary search for the square root. This is just easier for me to remember how to do. You can also cheat it a bit by trying to bias towards the way you intuit the answer lies.
- LanceH 4y agoIf you can avoid floating point division and search for what squares into the number you're looking at, it may converge more quickly per computer cycle. Heron's method does converge quickly per algorithm cycle, though. I haven't tried both, but you could definitely do your binary search with only multiplication and bit shifts. Ok, now I'm looking up number of cycles for division, which is a lot less than I remember. How much has this changed in the last 20 years? any? Ugh, now I have to try both out tonight. Thanks everyone.
- kadoban 4y agoYeah, my vague sense of low-level stuff these days is that it's moved a lot more towards memory/bus bound, and branch-prediction dependent. Anything that's in a register already and doesn't branch is about the same cost (probably technically extremely wrong, but that's my rule of thumb).
- euroderf 4y agoIsn't this just Newton's method ?
- madcaptenor 4y agoyes, but the special case that Heron did predates Newton.
- super256 4y agoTrivia: The guy who wrote QOI and QOA, @phoboslab, had a phone interview with facebook a decade ago where he was asked to implement sqrt() in js. https://twitter.com/phoboslab/status/1554127643011850242 https://twitter.com/phoboslab/status/1554127643011850242
- eklitzke 4y agoI was given a similar interview problem in one of my first job interviews (I think at Google?) 15 or so years ago. I don't remember the exact question, but I do remember that I needed to use Newton's method to solve it. However I was a math major in university, and I remember the interviewer pointing that out, so I felt like it was fair game.
- deleted 4y ago[deleted]
- btilly 4y agoI have a better proposal than the last line. Just repeat Heron's method, using the approximate square root. In the article they find that sqrt(33) is approximately 5.75 = 5 3/4. Square that and we get 25 + 2 * 15/4 + 9/16 = 33 1/16 = g. Now we want n / g = 33 / 5.75 = 33 / (23 / 4) = 132 / 23 = 5 17/23. Average that with g and we get (5 3/4 + 5 17/23)/2 = (5 69/92 + 5 68/92)/2 = 5 137/184 = 5.74456217... The actual answer is 5.74456264... What's going on here is that we're using Newton's method, and doubling the number of digits of accuracy every time. By contrast the Taylor series is only adding a fixed number of digits for each term. So "do the simple stupid thing, take feedback, iterate" is far better "do the complex thing right the first time". That's a lesson from math that is widely applicable everywhere. Such as for running startups.
- scythe 4y agoThe slightly easier version is to use Heron's method, but know the squares of half-integers. They are: 2.25, 6.25, 12.25, 20.25, 30.25, 42.25, 56.25, 72.25, 90.25. You might notice there is a similar pattern to these as the familiar odd-number increments in the sequence of integer squares. It also happens that (n + 1/2)^2 = n(n + 1) + 0.25 The iterated method tends to double the number of bits of accuracy at each iteration. Moving from integers to half-integers gives you one more bit of accuracy on average. When you apply the first iteration, this becomes two extra bits. This already gives accuracy within 0.2% in one step for any integer (except 3 and 5, with errors of 1.0104% and 0.6231% respectively).
- selfmodruntime 4y agoI‘m sorry, can you show an example of where this helps in the usage of Heron‘s Method?
- scythe 4y agoHere are the results for numbers up to 50: http://codepad.org/NBmpZGpT http://codepad.org/NBmpZGpT The advantage simply comes from getting a better initial guess in some cases. When the test number is halfway between two perfect squares, the advantage is maximized -- for 30 we get 5.5 for the one method and 5.47727~ for the other, with a true value of 5.47722~. For some numbers, like 35, the integer square is closer than the half-integer, so the results are the same, but these are also the numbers with the best approximations to start with.
- peplee 4y agoWas anybody else not taught things like this in school? Shortcuts like these where you get pretty close, but not exact are really useful; however, I recall math in school having to be exact or it was wrong. These handy get-you-close-enough tricks are helpful in competitions, standardized tests, real life. Anyways, thanks for sharing!
- doubled112 4y agoYour solution must be exactly as it is taught, or the solution is worthless. You're not supposed to think for yourself in school, just do what you are told.
- bee_rider 4y agoLots of approximation algorithms fall out of calculus pretty naturally. So they end up taught as examples or applications in that sort of class, rather as tricks when learning algebra or arithmetic.
- JohnFen 4y agoI wasn't. At least, not officially. I struggled in math, though, and one of my teachers (not my math teacher) taught me several of these tricks on the sly. I remain grateful to him to this day.
- klyrs 4y agoI always had a calculator. If they taught me shortcuts, I didn't listen. But, I was not a good student in primary school.
- renewiltord 4y agoI learned them for exams that involved lots of arithmetic. A lot of it was folk knowledge passed along the peer group partly by asking some of the kids who were one year ahead (and closer to the exam). There was some stuff like this but also other “tricks” (in physics problems, approximating sqrt(g) by pi and stuff like that), or calculating the integral of e^ax times sin bx by “completing” it to e^(a+ib)x, or the cube root technique here http://thinkinghard.com/blog/CubeRoots.html http://thinkinghard.com/blog/CubeRoots.html that we used mostly for modulo arithmetic. I’ve forgotten nearly all the useful stuff and now only recall trivia like the base ten logarithm of a few small primes. I wonder if those school kids are still passing on this sort of cobbled together knowledge, now decades past. I always considered this kind of trick stuff somewhat beneath me, as a child, since it did not discover some underlying truth of the universe like a mathematics proof in number theory would. But that was dumb because in the end I managed neither anything interesting in Number Theory nor complete mastery of thE tricks and at least the latter would have been entertaining to document. As an aside, there was a kid in our group who could rapidly decompose numbers into sums of powers of two (a skill that turned out useless even in the constrained environment), essentially obtaining the binary representation as soon as you wrote the number out (or showed him the written one). He couldn’t explain how, though, because he was mentally not quite there and would frequently lose verbal skills. After the nth time he stood up on the desk and randomly peed while we were there he was out of the place. Besides it wasn’t that useful and it could just be high skill at the straightforward modulo and shift algorithm. Going the other way was also fast for him but useless for us, though more impressive since adding 2^64 (a number I could still tell you off the top of my head) to some other power of two seems less straightforward.
- dylan604 4y agoThere's a lot of these math "tricks" or "shortcuts" that sound crazy at first listen, but then with practice, they turn out to be quite useful. I forget what the most recent brouhaha was called, but when I finally read up on what this "new" math being taught was, I just rolled my eyes. The problem with the recent teaching kids shortcuts to me was that they were seemingly only teaching the shortcut rather than teaching the long way so there's a proper understanding before teaching the shortcut. In high school, I participated in an event called Number Sense. 10 minutes to answer up to 80 questions. Catch was no scratch paper, no errant marks, no erasing, no modifications for anything. If you tried to turn a 7 into a 9, it was marked wrong. squares and roots were common. 3 digit numbers multiplied by 3 digit numbers. lots of things that once you knew the shortcuts made it very possible to do this.
- karmanyaahm 4y agoI do Number Sense right now!
- bee_rider 4y agoDid they only teach the shortcuts? It seems just as likely to me that they taught all the way through, but the parents only started complaining because, without seeing the whole development, they weren’t able to come up with the shortcuts on their own. The solution of course is for the parent to read, like, a paragraph from their kid’s textbook.
- mattmaroon 4y agoThey did not only teach short cuts. New math actually does a much better job of helping kids understand how it works rather than memorize rules and it has significant data to back that up. It’s basically better in every way except that it is unfamiliar to parents. People are just averse to change. I can’t tell you how many math-illiterate middle aged people I know who have said something like “If it ain’t broke don’t fix it” about new math. Then I ask them some simple multiplication problem they can’t do in their head and point out that maybe it is broken and that’s why they’re not good at math.
- marmetio 4y agoI would never do this much work in my head :-) You can get a decent answer just by glancing at the fixed scales of a slide rule [1]. This is also called a nomogram, and you can make your own custom ones programmatically with PyNomo [2]. [1] https://youtu.be/dT7bSn03lx0?t=11m45s https://youtu.be/dT7bSn03lx0?t=11m45s [2] http://pynomo.org/wiki/index.php/Main_Page http://pynomo.org/wiki/index.php/Main_Page
- BitwiseFool 4y agoIt dawns on me that I was never taught how to calculate a square root manually during all my schooling. We used them all the time in Algebra II and Calculus, but we were never shown a procedure like with multiplication or long division.
- enriquto 4y agoI once met a guy who could compute logarithms in his head, as well as exponentials (or antilogarithms, as he called them). He did that slowly but steadily, at about one decimal per second, to an arbitrary precision. He could start giving the answer before you finished reciting your question. That's actually easy with logarithms, because the logarithm is essentially the number of digits. As a byproduct, he could compute square roots easily, and also cubic roots and tenth roots. The easiest case for him, he said, because it was just "a shift". I cannot recall his name, he was a kind of "showman" that did his tricks to a large audience. From Colombia or Peru, I think. He was invited to our math department, and after his show, he explained in petit comité some of the secret sauce. We were a bit surprised to hear that he essentially memorized a large part of a table of logarithms. But maybe he was just trolling us.
- acchow 4y ago> As a byproduct, he could compute square roots easily, and also cubic roots and tenth roots. The easiest case for him, he said, because it was just "a shift". https://en.wikipedia.org/wiki/Shifting_nth_root_algorithm https://en.wikipedia.org/wiki/Shifting_nth_root_algorithm
- com2kid 4y agoI used to be able to do logarithms in my head, not to arbitrary precision though, I'd just get 2 or 3 decimal places. Square roots, same thing, take enough math classes and don't use a calculator to do the arithmetic, and after a few quarters you can get down to a couple of digits pretty easily.
- gumby 4y agoIf you used a slide rule you got a feel for what the answer will be, so in that case this guy's skill might be less than a superpower and more like good intuition. More likely though that case would not apply as slide rules have been dead for half a century. I'm not old enough to have used a slide rule "professionally" (i.e. for work or even school) but I did use my dad's old engineering slide rule for a while in high school physics out of sheer orneriness and desire to be weird. Once I got used to it I often had the answer (to a decimal place or two) faster than my classmates using calculators, when doing problems as the teacher was working them out on the board in class. Of course I had some advantages they did not, for example I only needed one or two digits of significance for problems like that, and if I got the power of 10 wrong it was immediately obvious.
- thomasmg 4y agoIn the movie "Gifted" a girl calculates the approximate square root of a 4-digit number in her head. Here the scene on YouTube: https://www.youtube.com/watch?v=37meAwQqPsE https://www.youtube.com/watch?v=37meAwQqPsE Later, it is said she is using the Trachtenberg system: https://en.wikipedia.org/wiki/Trachtenberg_system https://en.wikipedia.org/wiki/Trachtenberg_system The square root method seems to be described in the book "The Trachtenberg speed system of basic mathematics", the text is available on archive.org: https://archive.org/stream/TheTrachtenbergSpeedSystemOfBasicMathematics_201803/The%20Trachtenberg%20Speed%20System%20of%20Basic%20Mathematics_djvu.txt https://archive.org/stream/TheTrachtenbergSpeedSystemOfBasic... (search for "square root").
- thehappypm 4y agoJust tried this in my head with a random n=150. g = 12, since 12x12 = 144, pretty close to 150. 150/12 = 150/(4x3) = 50/4 = 12.5 Average of 12 and 12.5 is 12.25. Real answer: 12.247 Amazing!
- knaik94 4y agoThis is nice, but I personally just do a rough estimate based on known perfect squares and the idea of graph in my head. If I need anything more accurate than +-0.5 for small numbers, and +-10 for large, I'd just take out a calculator. Small numbers are much easier to estimate accurately than large numbers. Everyone generally knows the perfect squares up to at least 12, and then for bigger values, you can use even powers of 2, which I assume people also know. The useful trick is remembering the square root product/dividend property. Some examples, for a small number, 33, that's less than 36 but more than 25 and it's a lot closer to 36, so I'd guess 5.8 or 5.7 (actual value 5.74..). Halfway between the numbers wouldn't necessarily mean halfway between the known factors. For a bigger number like 1076, you can use 1024, and since it grows more slowly as the factors get bigger, I'd assume something like 32.5 (actual value 32.74..). For a number like 34128, 34128 is ~ 32000, 2 * 16000, 2161000 (almost 1024), so 1.5ish432 so 192ish [1.5*128=128+64] (actual value 184.74). Heron's method is much better in terms of error though. On the other hand, the method I use is better for larger numbers. I thought about trying Heron's after breaking down the number into smaller factors, but there's something about the division operator with decimals that feels exhausting to even think about.
- mmahemoff 4y agoBTW there’s a formatting issue with your last example. 2161000 should be 2 * 16 * 1000
- SpaceManNabs 4y agothis person's blog is consistently good! i immediately noticed the URL from their post on the reparametrization trick.
- amelius 4y agoJust use: https://en.wikipedia.org/wiki/Fast_inverse_square_root https://en.wikipedia.org/wiki/Fast_inverse_square_root and invert :)
- version_five 4y agoOne I learned recently: E.g. sqrt(7) = 3 x sqrt(1-2/9) ~= 3 x (1 - (1/2)(2/9)) = 3 x 8/9 = 2.6667 Where the second line uses the first term of the binomial series, i.e. (1+x)^(1/2) ~= 1+ x/2 Real answer is 2.65 in this case, obviously picking a factor to pull out that makes x as small as possible works best
- opsunit 4y ago> We start by finding a number that forms a perfect square that is close to 33. Here, let’s pick g=6, since 6^2=36. As somebody who is numerically essentially blind I'm not only incredibly jealous and in awe of most of the comments in this thread but also utterly perplexed by the above. How does that even come to mind that 6 is a good starting value? Do you people just intuit this stuff or do you rapidly run through the options? If you're asking me to come up with something that when multiplied by itself is something near 33 then you're in for a long wait. There's another comment in this thread: >Everyone generally knows the perfect squares up to at least 12, and then for bigger values, you can use even powers of 2, which I assume people also know. Do they? Jeez.
- zdyn5 4y agoKnowing the squares up to 12 isn’t that difficult to memorize and comes in handy… I imagine those who have them memorized did so in K-12 and just never forgot it.
- gamegoblin 4y agoIn every elementary school I have encountered in the US, one learns the multiplication tables up to 10 in 3rd grade (age ~8). Some schools go up to 12 (presumably because imperial units are somewhat base 12?). Edit: On a lark, I just tested this on my wife who is not mathy whatsoever, and she was able to remember them up to n=12 (with a slight hesitation for 7^2 == 49).
- wrycoder 4y agoFor another lark, go to Kahn Academy and check out how he teaches arithmetic up to third grade. You have to look really hard to find addition and multiplication tables. They’re there, with the rather lame comment that they’re good to know. But, they are not in his main stream, which depends on gimmicks to figure out the answer, instead of just rote memorization of the tables (which is good for the brain, as well). As an example, I know my multiplication table just fine through 12. But, something went wrong in the second grade, and my addition was terrible. I depended for years on tricks: to add three, count up very quickly on the three points of the numeral 3. Same for four. For five, count one point twice. I was in trouble at adding seven, because I couldn’t do something like add three twice! I was shocked that Kahn uses tricks like that.
- stevefan1999 4y agooh I used to derive this in high school by Newton's method: x[k] = x[k - 1] - x[k-1]^2/2x[k-1] = x[k] / 2 + a / 2x[k]; base case x[0] = a reasonable guess of the initial square root. Do a few iterations and you will get a close estimate of the square root. In fact the babylonians found it first by intuition a few thousand years ago it was Newton and Ralpson who proved and generalized it to all derivable functions I think? So the big advantage of this is that it is easily applicable to say like cubic root or quintic root, although the difficulty goes harder and harder.
- hndamien 4y agoI estimate square roots by just imagining a square. The area of tyhe square is the thing you are square rooting, the sides of the square are the roots. Eg, wahts the square root of 2345. Well roughly imagine a square of Area 2300, the sides are bigger than 100 (1/2 as big), but not more than 200 which would be 2x too big, so its probably around 150.
- qyph 4y agoYour method apparently isn't very good seeing as a square with area 2300 has sides of length ~48
- hndamien 4y agoWell, considering 100 * 100 is clearly more than 4 times 2300 its more an error of my basic mulitplication than my method of estimating squares. Was just focused on something else at the time of writing (as indicated by the spelling). Considering that a square root by definition is the side of the square described, visualising it sure doesn't hurt. If I tried again I'd say 100* 100 = 10,000, 1010 = 100, 50 50 = 2500, so that going to be pretty close. 48 is pretty close to 50.
- userbinator 4y agoI learned this method of calculating square roots to arbitrary precision and could probably easily produce 5-6 significant digits in my head if I concentrated enough: 5. 7 4 4 5 6 33.00 00 00 00 00 25 = 5 * 5 8 00 7 49 = 10 7 * 7 51 00 45 76 = 114 4 * 4 5 24 00 4 59 36 = 1148 4 * 4 64 64 00 57 44 25 = 11488 5 * 5 7 19 75 00 6 89 34 36 = 114890 6 * 6 30 40 64
- DangitBobby 4y agoI can't make sense of this.
- userbinator 4y agoLook for "square root by long division". That's what it seems to be called these days, but it was just taught as "the square root algorithm" when I learned it many decades ago.
- japanman425 4y agoAnyone can do this with anything. Just how accurate your estimations are, well, remains to be seen
- raghavram10 4y agoI used to perform a lot of mental arithmetic when I was kid and even read some books about different techniques (Vedic mathematics, Trachtenberg system, etc.). I don't remember the specific techniques from the books these days. Since I can also do multiplication and division in my head, I simply figure out which two consecutive integers when squared bound the number of interest. I then divide the difference between the number of interest and the lower integer by the sum of the two integers and add that fraction to the lower integer to get the square root. For example, if we want to calculate the square root of 1051, I know that 32^2 is 1024 and 33^2 is 1089. Then, 1051^0.5 = 32 + (1051-1024)/(32+33) = 32 + (27/65) ~ 32 + (26/65) + (1/65) ~ 32 + 0.4 + 0.02 ~ 32.42. The square of 32.42 is actually 1051.0564, so that's pretty close.
- smugma 4y agoI got C’s in college math but was a little clever when I was younger. I came up with my own method for estimating square roots, which was not bad (but not nearly as good as Heron’s method). Find the biggest whole number less than the square root of N, call it A. Sqrt N =~ A + (N-A^2) / ((A+1)^2-A^2) e.g. Sqrt 33 = 5 + 33-25 / 36-25 = 5 8/11 = 5.73 I didn’t explain it to my 5th grade teacher but told my older brother, who was taking calculus. He said I was doing a sort of Taylor expansion. What I learned later was that I was quick at mental math and got by until I was taking real calculus, then I fell behind as I didn’t know how to learn material because of bad study habits and not being clever enough to intuitively get it (my roommate who was slightly less clever at quick math breezed through the same college math classes and became a physicist).
- madcaptenor 4y agoBasically you're linearly interpolating between, for example, sqrt(25) and sqrt(36) to get sqrt(33). That will work quite well, but it's always an underestimate.
- smugma 4y agoThat’s a concise summary, thank you!
- psychphysic 4y agoReminds me of the rule of 72. Which also happens to be a second order approximation based on Taylor series. Is that a trend? Second order is the sweet spot?