Re: lisp function questions
- From: Jon Harrop <usenet@xxxxxxxxxxxxxx>
- Date: Fri, 30 Sep 2005 12:16:25 +0100
Pascal Bourguignon wrote:
> If you want more precision, ask for more precision:
>
> [22]> (solve-quadratic 1L0 1L9 1L0)
> (-9.99999999999999999L8 -9.895302355289459229L-10)
>
> Note that: (and (float-equal -9.99999999999999999L8 -1.0d+9)
> (float-equal -9.895302355289459229L-10 0.0d0))
>
> with: (defun float-equal (x y)
> (cond ((not (zerop y)) (< (abs (- 1 (/ x y))) 0.0001))
> ((not (zerop x)) (< (abs (- 1 (/ y x))) 0.0001))
> (t t)))
Using more precision is generally the wrong answer to numerical stability
problems. Knuth's bible gives an excellent explanation.
In this case, you've still got 10% error even with extended precision, i.e.
one of your answers is correct to only two significant figures and you
can't easily tell which answer that is.
If you want to find a root at 1e-100 (an entirely reasonable float value),
you don't want to have to use 200-digit precision arbitrary floating-point
arithmetic. A numerically stable implementation will get an accurate answer
using only conventional floating point precision.
>> Could you elaborate on what you think is incorrect about my average
>> function? It was a joke, but I believe it is correct.
>
> It fails on lists longer than CALL-ARGUMENTS-LIMIT which may be as
> small as 50,
Ok. It is 1152921504606846975 here.
> and it "fails" when the items in the list are not
> self-evaluating, giving unsuspected results, like erasing your hard disk.
Subexpressions will be evaluated in advance without eval:
* (average (cons 1 (cons (print 2) (cons 3 (cons 4 nil)))))
2
5/2
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com
.
- References:
- lisp function questions
- From: dan655t
- Re: lisp function questions
- From: Pascal Bourguignon
- Re: lisp function questions
- From: dan655t
- Re: lisp function questions
- From: Pascal Bourguignon
- Re: lisp function questions
- From: Pascal Bourguignon
- lisp function questions
- Prev by Date: Re: C++ and lisp and Games
- Next by Date: Re: C++ and lisp and Games
- Previous by thread: Re: lisp function questions
- Next by thread: Re: lisp function questions
- Index(es):
Relevant Pages
|