Re: [Haskell-cafe] Fractional sqrt

2007-01-22 Thread Yitzchak Gale
I wrote: I added a new page for the Numeric Quest library... http://www.haskell.org/haskellwiki/Numeric_Quest I also updated the references to Numeric Quest on the Mathematics and Physics page. http://www.haskell.org/haskellwiki/Libraries_and_tools/Mathematics Henning Thielemann wrote I wou

Re: [Haskell-cafe] Fractional sqrt

2007-01-22 Thread Ian Lynagh
On Mon, Jan 22, 2007 at 03:26:38PM +0200, Yitzchak Gale wrote: > > Can someone with access to darcs.haskell.org > please fix this library? darcs get currently does not > seem to work for it. > > http://darcs.haskell.org/numeric-quest/ I've fixed the permissions, although applying patches in the

Re: [Haskell-cafe] Fractional sqrt

2007-01-22 Thread Henning Thielemann
On Mon, 22 Jan 2007, Yitzchak Gale wrote: > Henning Thielemann wrote: > > > > there is already an implementation of continued > > > > fractions for approximation of roots and transcendent functions by Jan > > > > Skibinski: > > > > http://darcs.haskell.org/numeric-quest/Fraction.hs > > I wrote:

Re: [Haskell-cafe] Fractional sqrt

2007-01-22 Thread Yitzchak Gale
Henning Thielemann wrote: there is already an implementation of continued fractions for approximation of roots and transcendent functions by Jan Skibinski: http://darcs.haskell.org/numeric-quest/Fraction.hs I wrote: Wow, nice. Now - how was I supposed to have found that? http://www.haskell.

Re: [Haskell-cafe] Fractional sqrt

2007-01-21 Thread Yitzchak Gale
Henning Thielemann wrote: Certainly no surprise - there is already an implementation of continued fractions for approximation of roots and transcendent functions by Jan Skibinski: http://darcs.haskell.org/numeric-quest/Fraction.hs Wow, nice. Now - how was I supposed to have found that? It has

Re: [Haskell-cafe] Fractional sqrt

2007-01-21 Thread Henning Thielemann
On Sun, 21 Jan 2007, Yitzchak Gale wrote: > You always get the best approximation for a Rational > using continued fractions. For most calculations that > is easier said than done, but for square root we are > very lucky. Certainly no surprise - there is already an implementation of continued fr

Re: [Haskell-cafe] Fractional sqrt

2007-01-20 Thread Yitzchak Gale
Sorry folks, it is just wrong to use Newton's method for Rational. Andrew Bromage wrote: First off, note that for fractions, sqrt(p/q) = sqrt p / sqrt q. Don't do that for Rational - you lose precious precision. The whole idea for calculations in Rational is to find a lucky denominator that i

Re: [Haskell-cafe] Fractional sqrt

2007-01-20 Thread ajb
G'day all. I said: > I've also extended the range for approxSmallSqrt here from (0,255) to > (0,271). It is left as an exercise as to why this might be a good idea. > > (Hint: 272 is approximately 16.5*16.5.) The correct answer, for those playing at home, is it's because it WAS a good idea when

Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Thorkil Naur
Hello, On Friday 19 January 2007 16:48, [EMAIL PROTECTED] wrote: > ... > sqrtApprox' :: Integer -> Rational > sqrtApprox' n > | n < 0 = error "sqrtApprox'" > | otherwise = approx n 1 > where > approx n acc > | n < 256 = (acc%1) * approxSmallSqrt (fromIntegral

Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread ajb
G'day all. Quoting Henning Thielemann <[EMAIL PROTECTED]>: > Newton method for sqrt is very fast. It converges quadratically, that is > in each iteration the number of correct digits doubles. The problem is to > find a good starting approximation. Yup. So how might we go about doing this? Firs

Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Lennart Augustsson
If it's arbitrary precision floating point that you want then sqrt should where it already is, as a member of Floating. (I find "arbitrary precision real" to be an oxymoron, the real numbers are the real numbers, they already have arbitrary precision.) For a real number module, you can use,

Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Yitzchak Gale
Hi Zoltán, I only need sqrt, so probably I will... use... just the simple Newton alg. It is still not clear to me what type you want to work in. Is it Rational? In that case, you don't need the Newton algorithm. realToFrac . sqrt . realToFrac works fine, as you originally suggested. If that

Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Novák Zoltán
Hi, Thanks for the answers. The best solution would be a general purpose  arbitrary precision math library for Haskell. I found two: http://medialab.freaknet.org/bignum/ http://r6.ca/FewDigits/ I think both uses power series and have trigonometric functions too. (I only need sqrt, so probably I

Re: [Haskell-cafe] Fractional sqrt

2007-01-19 Thread Henning Thielemann
On Thu, 18 Jan 2007, Novák Zoltán wrote: > I have to admit that I do not fully understand the Haskell numerical tower... > Now I'm using the Newton method: > > mysqrt :: (Fractional a) => a -> a > mysqrt x = (iterate (\y -> (x / y + y) / 2.0 ) 1.0) !!2000 > > But I want a faster solution. (Not

Re: [Haskell-cafe] Fractional sqrt

2007-01-18 Thread Yitzchak Gale
Lennart Augustsson wrote: I don't see a much better way than using something like Newton- Raphson and testing for some kind of convergence. The Fractional class can contain many things; for instance it contains rational numbers. So your mysqrt function would have to be able to cope with returni

Re: [Haskell-cafe] Fractional sqrt

2007-01-18 Thread Lennart Augustsson
I don't see a much better way than using something like Newton- Raphson and testing for some kind of convergence. The Fractional class can contain many things; for instance it contains rational numbers. So your mysqrt function would have to be able to cope with returning arbitrary precisio

[Haskell-cafe] Fractional sqrt

2007-01-18 Thread Novák Zoltán
Hello, I would like to use the sqrt function on Fractional numbers. (mysqrt :: (Fractional a) => a->a) Half of the problem is solved by: Prelude> :t (realToFrac.sqrt) (realToFrac.sqrt) :: (Fractional b, Real a, Floating a) => a -> b For the other half I tried: Prelude> :t (realToFrac.sqrt.real