One more question on the program simplification and `bottom'.
People say, that the transformations like x - x -> 0 :: Integer
are hardly ever applicable, because x may occur `undefined'.
Say,
(let n = -n in n - n :: Integer) = undefined
But consider the program
f,f' :: Integer -> Integer
f x = x - x + (x*5 - x*2 - x*3 + 1)
f' x = if x==0 then x - x + (x*5 - x*2 - x*3 + 1)
else x - x + (x*5 - x*2 - x*3 + 1)
(contrived example).
Has the compiler right to "optimize" f to fO = const 1 ?
It has not - because of the `undefined' possibility.
But f' can be optimized to fO x = if x==0 then 1 else 1
Because the branches `then ...', `else ...' operate with the x
value, of which the compiler can prove that it is defined at this
stage. Otherwise, the previous operator (x==0) would not let the
program go further than `x==0'.
Also, it looks like this `if x==0' can be "prepended" to the body
of f by the compiler, and then, simplified as f' - ?
Probably, the compiler can prove "defined" very often. Hence, the
optimization transformations like x - x --> 0 can be made widely
applicable.
What is wrong here?
------------------
Sergey Mechveliani
[EMAIL PROTECTED]