Re:Introduction to Python for Computational Science and Engi...
by godelski on Friday November 25, 2016 @03:52PM
(#13039745)
I actually see np.dot(np.dot(x,y),z) as easier to read and remember. It is more explicit in what it is doing. Being explicit is a good thing.
[ Parent
| on HN ]
Re:Introduction to Python for Computational Science and Engi...
by noobermin on Friday November 25, 2016 @04:08PM
(#13039837)
a + 4*(x-y) + b**5
vs (+ a (* 4 (- x y )) (expt b 5 ))
Sometimes, as arithmetic with lisp shows, conciseness is better. Also, it isn't being more explicit than it is being more verbose.
Re:Introduction to Python for Computational Science and Engi...
by kazinator on Friday November 25, 2016 @06:14PM
(#13040577)
It is abosolutely being more explicit. It's being more explicit that (expt b 5) is a unit that forms a single argument in the + form.
This is implicit in
a + b ** 5
according to a precedence rule between the and + operator, which is hidden in the parser's implementation and in documentation thereof.Well, the white-spacing
a + b**5
suggests it. But the suggestions produced by insignificant whitespace can be mere wishful thinking: int* x, y; // two C pointers? not!
Speaking of whitespace, also have the advantage of there being multiple ways to split the expression into multiple lines, all conforming to a very clear, simple formatting rule: (+ a
(* 4 (- x y))
(expt b 5))
(+ a
(* 4
(- x y))
(expt b 5))
Fully expanded, every term on separate line: (+ a
(* 4
(- x
y))
(expt b
5))
In this manner, we can write complex expressions that would be quite unreadable in infix, requiring break-up into intermediate temporaries.We almost have a circuit diagram now with "gates" for the operations: a three input + gate, etc:
____
/ |- a
| | ____
--| + |-----/ |- 4
| | | * | ____
\____|- | |-----/ |- x
` \____| | - |
| \____|- y
| _____
`--/ |- b
| expt|
\_____|- 5