At Fri, 2 Mar 2018 12:34:00 +0100, "'Paulo Matos' via Racket Developers" wrote:
> (define (f x y)
> (if (and (zero? x)
> (= (+ x y) y))
> 1
> 0))
>
> In reality this is the same as:
> (define (f x y)
> (if (zero? x)
> 1
> 0))
Those turn out to be different. Try `(f 0 +nan.0)` or `(f 0 'symbol)`.
> Except racket does not perform the optimization. What's the reason for
> this?
Even if you throw in enough constraints on the program to make a
similar transformation valid, the optimizer would have to include
specific mechanisms for tracking zero values and number types (more
than it does) and rules on how arithmetic operations interact with
those abstract values. We haven't so far had a reason to create all of
those rules. And as your example illustrates, they'd help less often
than you might expect.