From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Float conversion
Date: Fri, 30 Jul 2010 16:34:03 +0200
Date: 2010-07-30T16:34:03+02:00 [thread overview]
Message-ID: <1cw2fli9ghz3v$.19tgtbe83nchl.dlg@40tude.net> (raw)
In-Reply-To: d981aeab-67e9-4fde-a96c-ec6a2a403703@c10g2000yqi.googlegroups.com
On Fri, 30 Jul 2010 06:14:49 -0700 (PDT), Phil Clayton wrote:
> Certainly ill-advised, but it can be difficult to know when this
> difference matters.
I think it could when intervals were used as keys in some sorted map. I
learnt a couple of quite painful lessons when used keys (not intervals
though), which appeared ordered to me, but in reality "<" was not
transitive.
> This gives me the perfect excuse to wheel out one
> of my favourite examples. It's a great example that I keep coming
> back to for many reasons.
>
> We want a 3-way min function (for integers or reals) that gives
>
> Y = min {A, B, C}
>
> and we are given
>
> if A < B and A < C
> then
> Y := A;
> elsif B < C and B < A
> then
> Y := B;
> else
> Y := C;
> end if;
>
> The justification given is
>
> if A is smallest, set Y to A
> else if B is smallest, set Y to B
> else C is smallest so set Y to C
A great example. I think every programmer wrote something like above at
least once.
[...]
> I often bring this example up to motivate the use of formal methods as
> it is particularly difficult to find the error through testing,
> especially when A, B and C are real types.
Absolutely. Same happens when a poor "<" is used for sorting. It is very
difficult to detect the problem through blind testing. The thing is so
nasty that it can easily pass a branch coverage test.
People overestimate the power of testing, because they often have a mental
model where the behavior is monotonic. They test for the extremes and
consider the rest granted. Your example shows how wrong this presumption is
already in apparently "trivial" cases.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2010-07-30 14:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-29 12:23 Float conversion Henrique
2010-07-29 12:44 ` Jacob Sparre Andersen
2010-07-29 12:46 ` Dmitry A. Kazakov
2010-07-29 15:08 ` Georg Bauhaus
2010-07-29 15:10 ` Georg Bauhaus
2010-07-29 15:35 ` Dmitry A. Kazakov
2010-07-29 18:21 ` Henrique
2010-07-29 19:08 ` Jeffrey R. Carter
2010-07-29 19:15 ` Dmitry A. Kazakov
2010-07-30 1:30 ` Phil Clayton
2010-07-30 8:43 ` Dmitry A. Kazakov
2010-07-30 13:14 ` Phil Clayton
2010-07-30 14:34 ` Dmitry A. Kazakov [this message]
2010-07-31 15:12 ` Stephen Leake
2010-08-03 1:07 ` Phil Clayton
2010-08-03 3:31 ` Shark8
2010-08-03 10:38 ` Georg Bauhaus
2010-08-04 7:27 ` Stephen Leake
2010-08-04 16:15 ` Georg Bauhaus
2010-08-04 16:32 ` Phil Clayton
2010-08-04 7:26 ` Stephen Leake
2010-08-04 12:52 ` Robert A Duff
2010-08-04 14:32 ` Dmitry A. Kazakov
2010-08-04 19:36 ` Simon Wright
2010-08-04 19:46 ` Dmitry A. Kazakov
2010-08-04 20:29 ` Georg Bauhaus
2010-08-05 12:05 ` Stephen Leake
2010-08-07 5:54 ` Shark8
2010-08-07 8:56 ` Georg Bauhaus
2010-08-07 13:49 ` Shark8
2010-08-05 10:20 ` Phil Clayton
2010-07-30 13:16 ` Henrique
2010-07-29 15:37 ` Warren
2010-07-29 14:56 ` Georg Bauhaus
2010-07-29 17:56 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox