Re: [pure-lang-users] math.pure
Status: Beta
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2008-08-23 06:32:22
|
Eddie Rucker wrote: > LOL! I noticed atanh is not defined in mzscheme so had to look it up. > (define (atanh x) (* .5 (log (/ (+ 1.0 x) (- 1.0 x))))) Beware, that definition gives you a +nan.0+nan.0i for x = 1.0+0.0i. Pure gets this right: > atanh 1, atanh (-1); inf,-inf > atanh (1+:0), atanh (-1+:0); inf+:0.0,-inf+:0.0 It will also compute the required complex result for atanh (-2), but of course in the latest revision you have to tell it that you want a complex result: > atanh (-2); nan > atanh (-2+:0); -0.549306144334055+:1.5707963267949 > Very good point! Hmmm... I guess this is another good reason for not duplicating the functionality of ^ and pow. > (-8+0i)^(1%3) = 1.0000000000000002+:1.7320508075688772 Well, my definition of complex (^) of course computes all powers in polar representation (and then converts them back to rectangular if needed). As the polar representation is normalized to the (-pi,pi] phase range automagically (see the constructor equations for (<:) in math.pure), it will always give you the principal roots without any ado. In fact, the definition I have does work pretty well, it's just a few corner cases with integer exponents that are causing me grief. Well, if nothing else helps I'll just have to add a few special case rules, but I thought it would be nice to put it all in a closed formula. ;-) > pow (-8) (1%3) = -2 You must be running an old revision there, pow is only defined for integer exponents now. > I noticed in mzscheme, > > (expt -8 1/3) > 1 I don't get that here (mzscheme v372, running on 32 bit Linux), it gives me the proper result: > (expt -8 1/3) 1.0000000000000002+1.7320508075688772i Cheers, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |