Re: lisp function questions
- From: Raymond Toy <raymond.toy@xxxxxxxxxxxx>
- Date: Fri, 30 Sep 2005 09:37:55 -0400
>>>>> "Pascal" == Pascal Bourguignon <spam@xxxxxxxxxxxxxxxx> writes:
Pascal> Jon Harrop <usenet@xxxxxxxxxxxxxx> writes:
>> dan655t@xxxxxxxxx wrote:
>>> Thank you for the help, I will continue working on this. Also if there
>>> are any other suggestions please feel free to continue posting.
>>
>> I'm no Lisp programmer but:
Pascal> Indeed.
>> 1. The algorithm used to compute the roots of a quadratic is different for
>> different number types. In particular, different forms are used for
>> floating point arithmetic if you want numerical stability.
Pascal> There's no loop so there's no concern about numerical stability.
Pascal> In lisp, arithmetic operators are polymorphic:
Pascal> (defun solve-quadratic (a b c)
Pascal> (if (zerop a)
Pascal> (solve-linear b c)
Pascal> (let ((delta (- (* b b) (* 4 a c))))
Pascal> (delete-duplicates (list (/ (- (- b) (sqrt delta)) 2 a)
Pascal> (/ (+ (- b) (sqrt delta)) 2 a))
Pascal> :test (function =)))))
If the coefficients are real and the roots are real, there is a
problem with numerical stability. If 4*a*c is small, delta will be
close to b^2. When you compute -b+sqrt(delta) (for b > 0) , you'll be
subtracting two numbers that are nearly equal. Thus, most books
suggest computing this second root as c/<first root>. The first root
doesn't have a round-off issue.
Ray
.
- 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
- lisp function questions
- Prev by Date: Re: Why Bother Trolling?
- Next by Date: Re: branch and assignment statements translation to functional style
- Previous by thread: Re: lisp function questions
- Next by thread: Re: lisp function questions
- Index(es):