by Confusion · 14y ago · 0 comments
(/ (+ (- b) (sqrt (- (* b b) (* 4 a c)))) (* 2 a))
Yeah, so it divides (the addition of (-b and the (sqrt of (the difference between (the product of b and b) and (the product of 4, a and c))) by (the multiplication of 2 and a))Right, that's much easier than
(-b + sqrt(b*b - 4*a*c)) / (2*a)
(-b plus the sqrt of ((b times b) - (4 times a times c))) divided by (2 times a)I see you omitted some parenthesis in the "conventional" expression, relying on the fact that multiplication takes priority over substraction. Making this fact explicit is exactly what makes Lisp better, especially for more complex domains: delegating priorities to the notation, freeing brain capacity for the actual problem.
(defun foo (a b c)
#I(
(-b + sqrt(b*b - 4*a*c)) / (2*a)
))
CL-USER 8 > (foo 1 2 3)
#C(-1.0 1.4142135)It may be bikeshedding, but I would not let 'blue is better than red, because the sky is blue' pass either.
(/ (+ (- b)
(sqrt (- (* b b)
(* 4 a c))))
(* 2 a))
It tells me:* there's a quotient of 2 things
* the first thing is a sum of -b and a sqrt
* the second thing is a product
and so on. Pretty nice. Of course, mathematical notation is more terse.