Instable evaluation of combined logical expressions
Jörg Bretschneider
Joerg.Bretschneider at eas.iis.fraunhofer.de
Mon Feb 23 01:10:59 CST 2009
Well I think I understand more of the complexity of this issue now,
thanks for all contributions. I dived into the original discussions and
now tend to use && and || if I want to enforce short-circuiting in octave.
There is seemingly no short way to heal all the problems without the
programmer carefully thinking about what is going to happen with his
arguments to the conditional expression, especially in terms of
dimension. I have used those tricks occasionally but with great care.
It seems that some people wanted to create/preserve what we in Germany
call the "eierlegende Wollmilchsau", i.e. something like octave's famous
variable dowhatImeannotwhatIsay. Maybe I did also sometimes.
Again, thanks to all
Joerg
John W. Eaton wrote:
> On 17-Feb-2009, Jaroslav Hajek wrote:
>
> | The problem with short-circuiting is that it introduces unsymmetry
> | into a seemingly symmetric operation. Also, short-circuiting matrices
> | might imply performance losses. For instance, if you insist that (A &
> | B) does not evaluate B if A has only false elements, then A will
> | usually be traversed twice; first to check whether B is needed and
> | second to really perform the operation (unless A happens to be all
> | false).
> |
> | This is bad, bad, bad. It really is much better to have special scalar
> | operators for short-circuiting. Mathworks apparently came to the same
> | conclusion eventually.
>
> This is not quite how short-circuiting works with the & and |
> operators in Matlab . They only do short-circuiting if the first
> expression is a scalar. But there are still problems. The first one
> that I thought of when the topic first came up (earlier than I
> thought; there was a comp.soft-sys.matlab thread about it in May 1994
> with the subject "&,| aren't short-circuit operators") was that
>
> t = x () | y (); if (t) ...
>
> would be different from
>
> if (x () | y ()) ...
>
> if y had some side effects. Another problem that was brought up later
> has to do with empty matrices. For example,
>
> t = 1 | []; if (t) ...
>
> vs
>
> if (1 | []) ...
>
> In the first case, t is [], and in the if statement, this condition is
> false. In the second case, the condition is true. This is also bad,
> bad, bad. I have no intention of copying this behavior in Octave, and
> this latter example is apparently the issue that finally convinced the
> MathWorks that their clever way of handling short-circuiting without
> introducing new operators was not actually so clever (there was a
> discussion on the comp.soft-sys.matlab group about it in September
> 2000 with the subject "if (1 | []) : inconsistencies?"). The
> side-effect example discussed in 1994 was apparently not
> sufficient...
>
> jwe
>
>
--
Jörg Bretschneider
Fraunhofer-Institut für Integrierte Schaltungen
Institutsteil Entwurfsautomatisierung
Zeunerstr. 38,
01069 Dresden,
Germany
Tel. ++49(0)351/4640-749
Fax: ++49(0)351/4640-703
Joerg.Bretschneider at eas.iis.fraunhofer.de
www.eas.iis.fraunhofer.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3627 bytes
Desc: S/MIME Cryptographic Signature
Url : https://www-old.cae.wisc.edu/pipermail/bug-octave/attachments/20090223/ab7c8176/attachment.bin
More information about the Bug-octave
mailing list