# The following was supposedly scribed by
# Ken Williams
# on Tuesday 01 March 2005 11:39 am:
>So, is that positive or negative infinity? �Sometimes that makes an
>awful lot of difference.
Sure. I was just (sort of) playing devil's advocate by pointing out
that rules are meant to be broken. If your computer science professor
told you to "never divide by zero" and you blindly followed his advice,
you would be going to a lot more trouble to compare the slopes of
vertical lines than is needed. (apologies for my previous
transposition of dy for dx)
use bigint;
my @slopes;
foreach my $line (@lines) {
my @d = map({$line->[1][$_] - $line->[0][$_]} 0..1);
push(@slopes, $d[1]/$d[0]);
}
my $steepest = (sort({$slopes[$a] <=> $slopes[$b]} 0..$#lines))[-1];
As far as direction goes, in this case it is inherent in the conventions
of "slope".
The point is that by breaking the "rules" for a second, we are able to
better apply all of those other concepts that we're supposed to be
using like SPOT, compactness, maintainability, clarity, etc. (It
doesn't hurt that we're using the most powerful mainstream programming
language either.) I would take the time to write the "rule-bound"
example, but I think it's a safe bet to say that it would pass for C
once you ran it through s/\$// (and there's a reason that I don't write
everything in C.)
> If you don't specify the approach direction, the limit is
> undefined
Which of course is not equal to undef(). Don't get me wrong, I'm not
lobbying for pi==3 here.
>See also http://mathforum.org/dr.math/faq/faq.divideby0.html . �The
>explanations get progressively more advanced as you go down the page.
Yes. It's complicated and I'm not advocating that we rewrite the
elementary arithmetic books. Just pointing out that once you
understand how to calculate the limit as the denominator goes to zero
(and the implications/assumptions involved in that) that you can use
perl to solve real problems in intuitive ways.
(heh. Maybe I need a Perl hacker's license and registration that says
I'm authorized to divide by zero and use up to 3.7GB of memory
(equivalent of deadly force and what-not.) Then we'll all put our
certifications on our e-mail (and notches in our belts) so the
algorithm police know whether to pull us over or not. Something like
an irony meter/"beware of sarcasm" bumper-sticker might also be useful
(just like that "my speed limit is:" license plate that I've always
wanted.))
--Eric
--
"Chess is a foolish expedient for making idle people believe they are
doing something very clever when they are only wasting their time."
-- George Bernard Shaw
---------------------------------------------
http://scratchcomputing.com
---------------------------------------------