3 ms·
In the linked notebook http://nbviewer.jupyter.org/url/norvig.com/ipython/Countdown.ipynb http://nbviewer.jupyter.org/url/norvig.com/ipython/Countdown... when h
by monorailz 10y ago
In the linked notebook http://nbviewer.jupyter.org/url/norvig.com/ipython/Countdown.ipynb http://nbviewer.jupyter.org/url/norvig.com/ipython/Countdown... when he says
>because there are 2 ways to make 27 with the numbers (10, 9, 8), namely, ((10+9)+8) and (10+(9+8))
why not also (10+9+8)?
- dalke 10y ago+ is an associative binary operator. You have to decide which pair to add first.
- ibrahima 10y agoTo add on, I think he's writing from a Lisp perspective, not general math notation.
- monorailz 10y agoThank you both, that makes sense.
- moron4hire 10y agoThat doesn't matter. It's just the basic associative property of addition in arithmetic. As such, it's present in all programming languages.
- Dylan16807 10y agoBut in normal math it's easy to use n-ary addition.
- B1FF_PSUVM 10y agoNowadays math mostly ends up in a CPU crunching two inputs at a time. If you don't write it so explicitly, a compiler will do it for you anyway.
- gjm11 10y agoIn Lisp too -- arguably easier than in most languages. To add 10+9+8 in Lisp you write (+ 10 9 8), a single 3-ary call to +. In, say, C you write 10+9+8 and the parser turns that into two 2-ary additions. (Of course, in either language you end up with two 2-operand ADD instructions in the object code. Nothing has hardware for arbitrary n-ary adds!)
- zitterbewegung 10y agoThink about when you evaluate the expression (10+9+8). You will either add 10+9 or 9+8 first and add 19 to 8 or 17 to 8. (10+9+8) is ambiguous because it can be parsed both ways.