Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • 1
    The lower version contains a repeated computation, namely (sqrt (- (* b b) (* 4 a c))). In this case I would prefer to have a variable holding the intermediate result. In case of recursive calls, using a variable to avoid repeated sub-expressions can make a big different with respect to complexity (linear versus exponential). Commented Jul 4, 2013 at 23:21
  • @Giorgio Any decent compiler does something called CSE (common subexpression elimination). Commented Jul 5, 2013 at 2:05
  • Although, it has to know that the functions used do not have side effects. Commented Jul 5, 2013 at 2:30
  • Which languages allow the compiler to determine that an expression has no side effects? I only know Haskell (maybe also Miranda and Clean). Commented Jul 5, 2013 at 5:56
  • @Giorgio C, Pascal, Fortran, Java, Algol, Lisp, Scheme, ... Commented Jul 5, 2013 at 6:07