×

# Don't Trust Machines

Find ordered quadruples of integer $$(a,b,c,d)$$ such that $\begin{cases} a+b+c+d & =0\\ \sin a + \sin b+ \sin c +\sin d &=0. \end{cases}$

I thought I had a solution to this question, and worked it out through pencil and paper. When I used Just-Basic (the free Windows version) to test all the possibilities, it confirmed my result. I was excited and submitted the answer, but was told that I was wrong so I filed a report. However, when I tested all the possibilities using a Python program in SAGE - I got a different answer. Intrigued, I have since gone back and found my mistakes and also why Just-Basic screwed up.

So what happened? We seldom get bit by the fact that calculators, computers, and poorly written programs can often miss things because of rounding errors or the fact that binary conversions are not always exact. The default precision of calculations is often unknown. Different machines and various programming languages combine to create peculiar results if we are not careful and fail to take these problems into consideration. It is never easy to know exactly what is happening "under the sheets".

Moral of the story - Don't trust machines - use what is between your ears better - especially when you are doing exact calculations in Algebra or Number Theory!

As a further illustration of this topic, try this question Remember the "Windows Calculator" is running on a machine.

7 months, 1 week ago

Sort by:

you do not have to trust your machines, you have to trust yourself that you wrote the correct code. Do you mind sharing the basic code?

And yes, floating point arithmetic is like that. When you are doing numerical analysis, I suggest you watch out for small errors like that. That is why there is a whole branch of mathematics devoted to it · 7 months, 1 week ago

Here is the first program that missed some valid ordered quadruples (a,b,c,d) and gave 1025 (wrong):

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 trips=0 cnt=0 for a=-10 to 10 for b=-10 to 10 for c=-10 to 10 for d=-10 to 10 S=(a+b+c+d) Ss=(sin(a)+sin(b)+sin(c)+sin(d)) if S=0 and Ss=0 then cnt=cnt+1: print cnt,a,b,c,d,S,Ss trips=trips+1 next d next c next b next a print "Done !!!",trips;" loops" 

LAST 2 LINES OF OUTPUT:

 1 2 1025 10 10 -10 -10 0 0 Done !!! 194481 loops 

Here is the program, after the fix, which got the correct answer:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 trips=0 cnt=0 for a=-10 to 10 for b=-10 to 10 for c=-10 to 10 for d=-10 to 10 S=(a+b+c+d) Ss=(sin(a)+sin(b)+sin(c)+sin(d)) if S=0 and abs(Ss)<=.000000002 then cnt=cnt+1: print cnt,a,b,c,d,S,Ss trips=trips+1 next d next c next b next a print "Done !!!",trips;" loops" 

LAST 2 LINES OF OUTPUT:

 1 2 'correct answer' 10 10 -10 -10 0 0 Done !!! 194481 loops 

This last program is in Python running on cloud.sagemath.com and it got the correct answer first try.

 1 2 3 4 5 6 7 8  cnt=0 for a in srange(-10,11): for b in srange(-10,11): for c in srange(-10,11): for d in srange(-10,11): if a+b+c+d==0 and sin(a)+sin(b)+sin(c)+sin(d)==0: cnt+=1 print cnt 

Sorry about the poor formatting - I'm just learning LaTeX. I hope Calvin Lin doesn't feel I've given too much away about his question. That's why I left out 'correct answer'

P.S. I have come across some of your work on Brilliant and found your animated graphs extraordinary!

Especially on this question where you made some graphs for Otto K Bretscher ! Just absolutely Brilliant ! · 7 months, 1 week ago

That's nice. Thanks. I fixed your formatting.

I am glad that you've figured the solution out. Dealing with numeric error is a common problem you've to deal with in the field of numeric analysis. It is easier for SAGE because SAGE is not just normal python, sage is a Computer Algebra System built on top of python which is optimised to deal specifically with mathematical problems.

I guess the moral isn't Don't trust computers but Computers are useful as long as you use your brain. Computing is an important part of the mathematics that is emerging today. You might want to check out this and Experimental Mathematics · 7 months, 1 week ago

Thank you - it looks much better now! My original errors have developed into an amazing learning experience in Math, Computing, and LaTeX ! Where did you learn about those " ` " characters' function?

The two Wikipedia references you suggested I check out were very interesting and linked to countless other articles I really enjoyed ! You've made this 'Note' twice as valuable. · 7 months, 1 week ago

I got them from the Formatting Guide.

Glad that you liked them :) · 7 months ago

I agree, except that in my case I can't trust the grey matter either. You might be interested in my solution to the first problem you mention above. · 7 months, 1 week ago

@bobbym none You might want to comment here. · 7 months, 1 week ago

Comparing two floating point numbers for equality... a recipe for disaster. · 6 months, 4 weeks ago

What is Donald Knuth's suggestion about that? · 6 months, 4 weeks ago

Nice point ! I think that sums up what happened here very well ! · 6 months, 4 weeks ago

Hi Agnishom; I do not know, he never answers any of my calls or emails...

Hi Bob; Computers are tricky, the point is get answers out of them. That you did, so you did well. · 6 months, 4 weeks ago

Humans are trickier.

Knuth does not have an email. I suggest you ask him directly.

· 6 months, 3 weeks ago