Comment On Sticking to the Method

Long before the √-button on calculators, and the now-antique slide rules and logarithm tables, people actually had to calculate square roots by hand. Like so many other pre-Computer Age tasks, square root calculation isn’t really complicated, it’s just tedious. The simplest – and, as it happens, the oldest – technique for this the Babylonian method: guess the square root of a number and then continually refine the result by taking the arithmetic mean of the result and the quotient of the number and the result, until you’re satisfied with the precision. In other words: [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Sticking to the Method

2008-09-30 11:06 • by BK (unregistered)
this beam comes first

Re: Sticking to the Method

2008-09-30 11:09 • by DeLos
I was so close to being first. I suppose instead of reading the article I should have just made a guess at what it was about and see if my comment stuck or was removed.

Re: Sticking to the Method

2008-09-30 11:09 • by SE (unregistered)
No such thing as a W4x10.

Re: Sticking to the Method

2008-09-30 11:14 • by Satanicpuppy
Heh. Root finding launched me to cult hero status in college, as I managed to be the first person to program my graphing calculator to calculate roots via Newton's Method while showing the work. Made a tedious test question the work of seconds.

Sure it was cheating, but I was a CS major, and I felt it was "better" for my career to be able to hack together the code on my calculator than it was to actually be able to do the math.

Re: Sticking to the Method

2008-09-30 11:18 • by skztr (unregistered)
Real wtf is the salesperson not responding with "That feature is in the latest version, I can bring that in for you tomorrow if you like". Almost makes me want to work for that vendor.

Re: Sticking to the Method

2008-09-30 11:22 • by EJ_
220075 in reply to 220071
Satanicpuppy:
Heh. Root finding launched me to cult hero status in college, as I managed to be the first person to program my graphing calculator to calculate roots via Newton's Method while showing the work. Made a tedious test question the work of seconds.

Sure it was cheating, but I was a CS major, and I felt it was "better" for my career to be able to hack together the code on my calculator than it was to actually be able to do the math.


Haha, I loved doing this too. The teachers would proclaim "show your work!" so we wouldn't just let the calculators do it for us. I'd write a little application to show me what my work would have been had I done it out :) I never shared with anybody though... probably would have been a good way to make some friends looking back...

Re: Sticking to the Method

2008-09-30 11:23 • by Satanicpuppy
TopCod3r (Deleted as Troll):
It is obvious the submitter of this story is not a PE (Professional Engineer). There is a major liability (legal) with the program recommending beam choices for a bridge. The only way to avoid this is to make the engineer suggest the beam, and only have the program tell whether it meets specifications or not.


I don't see how that follows. If the engineer wants a list of beams that meet X criteria, and the program spits out an accurate list, then all is well. If the program cannot be trusted to accurately judge whether or not a beam meets specified criteria, then it's just as invalid whether its talking about one beam, or one-hundred beams.

That's like saying it's the calculator's fault that the engineer made a math error. Regardless of the tools he uses, it's still his responsibility. I remember a case where the engineer was held responsible for a design decision that the contractors made without consulting him: the court decided that he should damn well have supervised.

Re: Sticking to the Method

2008-09-30 11:23 • by Herman (unregistered)
It's important not to let your computer calculate too much you know.

It might take more than a second and that's an awful waste of time.

Re: Sticking to the Method

2008-09-30 11:25 • by gabba
Heh. This was possibly the best javascript-based introduction to non-linear minimization I have ever read.

Re: Sticking to the Method

2008-09-30 11:26 • by GettinSadda
So, the root problem solved like this would be:
function rootGuess()

{
var numbr = prompt('What number do you want the Square Root of?',5),
guess = prompt('OK, what do you *think* the Square Root of ' + numbr + ' is?',2);
if (isNaN(parseFloat(numbr)) || isNaN(parseFloat(guess))) return;

if ((guess * guess) == numbr) {
alert('Correct - the Square Root of ' + numbr + ' is ' + guess);
} else {
alert('Wrong - the Square Root of ' + numbr + ' is NOT ' + guess);
}
}

Brillant!

Re: Sticking to the Method

2008-09-30 11:36 • by JD (unregistered)
Satanicpuppy:
Heh. Root finding launched me to cult hero status in college, as I managed to be the first person to program my graphing calculator to calculate roots via Newton's Method while showing the work. Made a tedious test question the work of seconds.

Sure it was cheating, but I was a CS major, and I felt it was "better" for my career to be able to hack together the code on my calculator than it was to actually be able to do the math.

Finally, a voice of reason. I'm entirely with you my friend; as a CS student who hated maths I also found it a great deal more beneficial to program maths solutions on my graphical calculator than to figure them out by hand. This was many years ago now and since then, I've re-written (in production apps) plenty of the logic that I originally implemented on my calculator. In contrast, I've never had to work out any of those sums by hand at any time in my programming career. So with the power of hindsight I can say with absolute certainty that it was better from an educational standpoint to "cheat" with my calculator than to "do it properly". QED.

Unfortunately, I don't really have anything relevant to note about today's post. So I'm just going to say thanks for the interactive Javascript root finder - that defnitely added a certain something to the tale for me.

Re: Sticking to the Method

2008-09-30 11:41 • by lindee (unregistered)
the real wtf is that parseFloat returns a new number. your function should be called terribleBabylonianGuessPlusStringConcatenation


Note from Alex: Whoops, my bad: the "interactive" babylonianGuess() script has now been fixed. Score one for CDD (Community Driven Development).

Re: Sticking to the Method

2008-09-30 11:44 • by Graham Stewart (unregistered)
Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)

Re: Sticking to the Method

2008-09-30 11:44 • by TopCod3rFan (unregistered)
I'd like to reiterate my hope that one day we can sticky friends' posts as something to blue-ify for the main page.

Re: Sticking to the Method

2008-09-30 11:50 • by bjolling
nitehawk:
SE:
"The only way to avoid this is to make the engineer suggest the beam, and only have the program tell whether it meets specifications or not."

No, you're wrong.


It's TopCod3r, of course he is.

Actually when I did my internship at a construction firm, I had to determine the dimensions of a small concrete bridge. Off course I inputted the parameters into a "finite elements" application and got the results. Then the head engineer asked me to re-calculate it manually using the apps output so that they would have the calculation on paper, in case something should need to be reviewed afterwards. (I suppose after my bridge collapsed...)
TopCod3r isn't as wrong as usual :-)

Re: Sticking to the Method

2008-09-30 11:50 • by Me (unregistered)
220087 in reply to 220085
TopCod3rFan:
I'd like to reiterate my hope that one day we can sticky friends' posts as something to blue-ify for the main page.

Whenever TopCod3r's posts get blue'd the entire comments section becomes nothing but an indulgence in delicious flame bait. Shame so many people round here need <sarcasm> tags.

Re: Sticking to the Method

2008-09-30 11:52 • by Vince (unregistered)
Try to guess 0, the answer is NaN !

Re: Sticking to the Method

2008-09-30 11:55 • by Vince (unregistered)
220089 in reply to 220088
Btw I don't understand why if I put 10 and guess 10 the first guess is 50.5 ?

Re: Sticking to the Method

2008-09-30 12:03 • by lindee (unregistered)
220090 in reply to 220089
lindee:
the real wtf is that parseFloat returns a new number. your function should be called terribleBabylonianGuessPlusStringConcatenation


babylonians couldn't parse floats... and neither can alex

Re: Sticking to the Method

2008-09-30 12:04 • by Ilya Ehrenburg (unregistered)
220091 in reply to 220089
Vince:
Btw I don't understand why if I put 10 and guess 10 the first guess is 50.5 ?

That's a nice little wtf in this site's code: originally, guess seems to be a string and so on entering the loop, the initial guess and the quotient numbr/guess are concatenated.

Re: Sticking to the Method

2008-09-30 12:04 • by Yep (unregistered)
I like how if you give the root finder script a decimal number for your guess, it only guesses NaN..

Re: Sticking to the Method

2008-09-30 12:04 • by Square Root (unregistered)
220093 in reply to 220084
Graham Stewart:
Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)
As Graham Stewart (unregistered) put it: That feature is in the latest version, I can bring that in for you tomorrow if you like.

Re: Sticking to the Method

2008-09-30 12:13 • by Jack V (unregistered)
220094 in reply to 220071
Satanicpuppy:
Sure it was cheating
If you programmed that into the calculator in the first place it sounds to me like you _did_ do the math.

OK, you were probably supposed to do it during the exam, rather than just once in your life, but so what :)

(For some things, when you may need to have an intuitive grasp of them, doing them by hand is definitely useful. But AFAIK almost everyone only calculates roots by hand a few times when they first learn it.)

Re: Sticking to the Method

2008-09-30 12:18 • by bucket (unregistered)
A typical example of some 'manager' and it's crew designing an application from their point of view, without considering the real users, let alone actually having those real users help designing it or testing it. A shame, as this happens a lot and so many generic software applications could be so much better and so much more useful if people actually bothered to bring in the target audience to help with development (and if those people actually cared to help).

Re: Sticking to the Method

2008-09-30 12:19 • by Thief^
220096 in reply to 220091
Ilya Ehrenburg:
Vince:
Btw I don't understand why if I put 10 and guess 10 the first guess is 50.5 ?

That's a nice little wtf in this site's code: originally, guess seems to be a string and so on entering the loop, the initial guess and the quotient numbr/guess are concatenated.

Yup, like this:
function babylonianGuess()
{
var numbr = prompt('What number do you want the Square Root of?',5),
// numbr = "10", also note the , instead of ;
guess = prompt('OK, what do you *think* the Square Root of ' + numbr + ' is?',2);
// guess = "10"
if (isNaN(parseFloat(numbr)) || isNaN(parseFloat(guess))) return;
// yay

do { guess = 0.5 * (guess + numbr/guess); }
// 0.5 * ("10" + "10"/"10")
// = 0.5 * ("10" + 10/10)
// = 0.5 * ("10" + 1)
// = 0.5 * "101"
// = 0.5 * 101
// = 50.5
while (confirm('Refine Further? ' + guess));
// ok
do { guess = 0.5 * (guess + numbr/guess); }
// 0.5 * (50.5 + "10"/50.5)
// = 0.5 * (50.5 + 10/50.5)
// basically it works as expected the second time onwards
while (confirm('Refine Further? ' + guess));
}

Re: Sticking to the Method

2008-09-30 12:21 • by Gorfblot (unregistered)
I started writing a detailed explanation as to why the code gives a poor first approximation, as people are still asking.

About 2 words into it, it occured to me- Did we just get trolled by Alex?

Re: Sticking to the Method

2008-09-30 12:30 • by SomeCoder (unregistered)
220098 in reply to 220081
JD:

Finally, a voice of reason. I'm entirely with you my friend; as a CS student who hated maths I also found it a great deal more beneficial to program maths solutions on my graphical calculator than to figure them out by hand. This was many years ago now and since then, I've re-written (in production apps) plenty of the logic that I originally implemented on my calculator. In contrast, I've never had to work out any of those sums by hand at any time in my programming career. So with the power of hindsight I can say with absolute certainty that it was better from an educational standpoint to "cheat" with my calculator than to "do it properly". QED.

Unfortunately, I don't really have anything relevant to note about today's post. So I'm just going to say thanks for the interactive Javascript root finder - that defnitely added a certain something to the tale for me.


The university I attended had a professor who not only wrote part of the STL for C++ but was a math major. As such, he offered a down to the metal, C++, math course. It was applying mathematical equations to programming, basically. We dealt with round off errors, IEEE floating point specs (we had to write a version of the entire IEEE spec for one assignment and had to actually manipulate the bits to do it) as well as applying Newton's method to get accurate roots, etc.

Sounds like you guys might have enjoyed it. It had more direct application to programmers than a typical math class. It was one of the best classes I ever took there :)

Re: Sticking to the Method

2008-09-30 12:32 • by Gabe (OP) (unregistered)
TopCod3r:
It is obvious the submitter of this story is not a PE (Professional Engineer). There is a major liability (legal) with the program recommending beam choices for a bridge.


You know you're right - I'm not a PE - thats a US term and I work exclusively in Europe, mostly in England and we have different rules, regulations and qualifications. Alex has done a fair job of translating what I told him into Americanese, converting sizes and regulations etc, so cut him some slack.

Why would there be a problem with a computers suggestion? Maths is maths, it doesn't matter if its done by a human or a pc. Potential for screw ups are -1) the program can't add up, in which case its the programmers liability, -2) The engineer makes a stupid choice, engineers can do that without needing to use a computer.

Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.

Re: Sticking to the Method

2008-09-30 12:34 • by Jack V (unregistered)
220100 in reply to 220091
Ilya Ehrenburg:
guess seems to be a string and so on entering the loop, the initial guess and the quotient numbr/guess are concatenated.


That's what I eventually figured out. Easily done.

Interestingly, because of the multiplication, it _does_ work just fine if you start with an integer (just slightly longer because the first guess was off). And it gives NaN for negative inputs, which is probably correct :)

(It would be more general if it correctly took complex square roots, and obviously more information is always potentially helpful, but there are many applications where NaN is much more meaningful than 3i; and if you want to treat a field more general than R+, you have to choose _which_ square root to return, as there are two; and complex numbers is a natural place to stop, since square roots are again closed in C, but there are other fields where you can take roots so it's not the only correct answer, as it may appear :))

Re: Sticking to the Method

2008-09-30 12:35 • by Sr Sw Eng (unregistered)
TRWTF is thinking engineers cannot be good software developers. You know, as in Software Engineering.

Re: Sticking to the Method

2008-09-30 12:37 • by TopCod3r
220102 in reply to 220099
Gabe (OP):
Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.


Hi Gabe, have you considered upgrading it from GWBASIC to QUICKBASIC?

Re: Sticking to the Method

2008-09-30 12:37 • by Sr Sw Eng (unregistered)
And before all those mentions to square roots of negative numbers trigger it, here is a preventive strike: http://xkcd.com/179/

Re: Sticking to the Method

2008-09-30 12:41 • by Worf (unregistered)
Root finding - can't we optimize it a bit and just "guess" that the initial root is the number entered? (Or to optimize further, half the initial value, and then just test for 1).

That way we have an automated square root function.

The next challenge is figuring out what the stop condition is.

Re: Sticking to the Method

2008-09-30 12:43 • by Rob (unregistered)
220108 in reply to 220101
Sr Sw Eng:
TRWTF is thinking engineers cannot be good software developers. You know, as in Software Engineering.

At my place of work we have no "software developers"; all the developers have the official job title of "Software Engineer". This was done so that the company didn't have to employ any actual software engineers. We're never given any design to work to. If we ask for a design we get told "you're software engineers, it's your responsibility to design your work before you code it".

Re: Sticking to the Method

2008-09-30 12:47 • by Yep (unregistered)
Top Cod3r:
lol top cod3r had to take the space out of his name


All it took was someone registering his name for him to realize that maybe, just maybe, he ought to register a name if he plans to continue the regularly scheduled farce.

Re: Sticking to the Method

2008-09-30 13:07 • by Jamface (unregistered)
I want the square root of 2049.

I think that it is 45.26588119

Would I like to refine further than NaN?

FAIL

Re: Sticking to the Method

2008-09-30 13:11 • by SomeCoder (unregistered)
220111 in reply to 220099
Gabe (OP):
TopCod3r:
It is obvious the submitter of this story is not a PE (Professional Engineer). There is a major liability (legal) with the program recommending beam choices for a bridge.


You know you're right - I'm not a PE - thats a US term and I work exclusively in Europe, mostly in England and we have different rules, regulations and qualifications. Alex has done a fair job of translating what I told him into Americanese, converting sizes and regulations etc, so cut him some slack.

Why would there be a problem with a computers suggestion? Maths is maths, it doesn't matter if its done by a human or a pc. Potential for screw ups are -1) the program can't add up, in which case its the programmers liability, -2) The engineer makes a stupid choice, engineers can do that without needing to use a computer.

Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.


Gabe, this IS TopCod3r so please don't feed the trolls :)

Re: Sticking to the Method

2008-09-30 13:11 • by Global Warmer (unregistered)
220112 in reply to 220084
Graham Stewart:
Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)


Why don't you tell me what the square root of -25 is?

Re: Sticking to the Method

2008-09-30 13:11 • by jmroth

city building departments come to us for help in developing codes and standards for the computer age


gimme teh codez :)

Re: Sticking to the Method

2008-09-30 13:18 • by Marc B (unregistered)
Why didn't he just write a script wrapped around the vendor's program to iteratively feed in each beam size and have it print out the ones that passed the test?

Re: Sticking to the Method

2008-09-30 13:20 • by NotTheDroidYou'reLookingFor (unregistered)
It's obvious the engineering firm was just too stubborn for their own good. All they needed to do was write a program to automatically input values into the forms to try every beam. When will people learn that fear of change is paralysis?

Re: Sticking to the Method

2008-09-30 13:21 • by SomeCoder (unregistered)
220117 in reply to 220112
Global Warmer:
Graham Stewart:
Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)


Why don't you tell me what the square root of -25 is?


5i? :)

Re: Sticking to the Method

2008-09-30 13:21 • by Topper Cod3r (unregistered)
220118 in reply to 220099
Gabe (OP):
Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.


Any decent engineer would have have known in 1983 that QUICKBASIC was in development, and would have designed programs using the beta version, as even it was vastly superior to GWBASIC. Obviously that means that your firm was clueless.

Besides, TRWTF is that an engineer would use "83" and "85" to represent dates. Didn't you folks learn anything from that y2k fiasco?

Re: Sticking to the Method

2008-09-30 13:24 • by El Bartho (unregistered)
220119 in reply to 220112
5i !?!

Re: Sticking to the Method

2008-09-30 13:29 • by themagni
TopCod3r:
It is obvious the submitter of this story is not a PE (Professional Engineer). There is a major liability (legal) with the program recommending beam choices for a bridge. The only way to avoid this is to make the engineer suggest the beam, and only have the program tell whether it meets specifications or not.


That's incorrect.

I'm not a professional - yet. I'm an EIT, and they're wrapping up the paperwork next month.

In order to accept computer calculations as valid for public safety and professional work, it is strongly suggested that you do three sets of calculations:

1. By hand to get a rough idea. (e.g. It's somewhere between 70 and 80)
2. By computer to confirm your results. (e.g. 75.1233)
3. By a second program (not a second copy), ideally on a second computer to confirm the two previous results. (e.g. 74.9830)

These recommendations are as a result of the roof collapse at a Save-on-Foods in Burnaby (Yes, it's called Cave-On-Foods by locals) due to a software glitch in the selection of the building materials. Luckily, nobody was killed. There was one injury (trampling) during the panicked customer egress.

The investigation found that if the engineers had done a rough calculation, they would have found that the computer's answers were woefully inadequate. Thus the recommendation of rough calculations. The suggestion of the second computer is because computers are cheap.

Re: Sticking to the Method

2008-09-30 13:32 • by ContraCorners
220121 in reply to 220118
Topper Cod3r:
Gabe (OP):
Next point, why did we use GWBASIC over QUICKBASIC. Well GWBASIC was released in 83 and QUICKBASIC came out in 85, sorry but we didn't have a time machine.


Any decent engineer would have have known in 1983 that QUICKBASIC was in development, and would have designed programs using the beta version, as even it was vastly superior to GWBASIC. Obviously that means that your firm was clueless.

Besides, TRWTF is that an engineer would use "83" and "85" to represent dates. Didn't you folks learn anything from that y2k fiasco?



Laughing my a** off! Thank tc

Re: Sticking to the Method

2008-09-30 13:33 • by Marvin the Martian (unregistered)
This code would be better if it was more generic, to deal with decimal and negative numbers (you know, for when engineering goes imaginary).

Please use generify-wand on the code.

Re: Sticking to the Method

2008-09-30 13:33 • by Zap Brannigan (unregistered)
220123 in reply to 220117
SomeCoder:
Global Warmer:
Graham Stewart:
Hmm... the javascript root finder doesn't do so well with finding the root of negative numbers. :)


Why don't you tell me what the square root of -25 is?


5i? :)

5j?

e^{j\pi} + 1 = 0

Re: Sticking to the Method

2008-09-30 13:41 • by Atlantys (unregistered)
220124 in reply to 220117
5j!

Re: Sticking to the Method

2008-09-30 13:42 • by jDeepBeep (unregistered)
220125 in reply to 220117
For any positive real number b

sqrt of negative b equals i sqrt of b

« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment