[clean-list] Handling of reals & boolean expressions?
G.W.M. Vissers
vissers@theochem.kun.nl
Wed, 18 Dec 2002 11:08:33 +0100 (CET)
Hello,
Consider the following program:
module tst
import StdReal, StdBool, StdClass
::Complex = { re :: Real, im :: Real }
absreal :: !Complex -> Real
absreal {re=re, im=im}
| mna == 0.0 = mxa
= mxa * sqrt (1.0 + u * u)
where
ax = abs re
ay = abs im
mna = min ax ay
mxa = max ax ay
u = mna / mxa
less :: !Complex !Complex -> Bool
less z1 z2 = az1 < az2
where
az1 = absreal z1
az2 = absreal z2
less2 :: !Complex !Complex -> Bool
less2 z1 z2 = az1 < az2 || az1 == az2
where
az1 = absreal z1
az2 = absreal z2
less3 :: !Complex !Complex -> Bool
less3 z1 z2 = az1 < az2 || False
where
az1 = absreal z1
az2 = absreal z2
Start = (less ip im, less2 ip im, less3 ip im)
where
ip = {re=2.0, im=1.0}
im = {re=2.0, im=(-1.0)}
When calling the function less, less2, less3 with complex numbers with the
same absolute value (as in the program above), I get the result
(True,False,True).
My two questions are then of course
a) why is in the functions less and less3 az1 < az2 evaluated to True?
b) if the behaviour in less and less3 is correct, then why is the result
of less2 False?
Using the three functions with complex numbers of different magnitude
results in the behaviour one expects, i.e. all three functions give the
same answer.
Thanks in advance for possible explanations,
Gé Vissers