Re: inverse of a matrix with Fraction entries

2010-11-27 Thread Steven D'Aprano
On Sat, 27 Nov 2010 15:44:38 -0800, casevh wrote: > I think most users are expecting infinite precision when they use > rationals. Trying to explain limited precision rational arithmetic might > be interesting. Most users are expecting infinite precision decimals when they use floats, and get su

Re: inverse of a matrix with Fraction entries

2010-11-27 Thread casevh
On Nov 27, 3:08 pm, Steven D'Aprano wrote: > On Fri, 26 Nov 2010 19:21:47 -0800, casevh wrote: > > On Nov 26, 2:11 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote: > >> On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > >> > For ordinary number crunching, > >> > rational arithme

Re: inverse of a matrix with Fraction entries

2010-11-27 Thread Steven D'Aprano
On Fri, 26 Nov 2010 19:21:47 -0800, casevh wrote: > On Nov 26, 2:11 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: >> > For ordinary number crunching, >> > rational arithmetic is completely inappropriate. >> >> Why? >> >> -- >>

Re: inverse of a matrix with Fraction entries

2010-11-27 Thread casevh
On Nov 27, 4:00 am, m...@distorted.org.uk (Mark Wooding) wrote: > casevh writes: > > I coded a quick matrix inversion function and measured running times > > using GMPY2 rational and floating point types. For the floating point > > tests, I used a precision of 1000 bits. With floating point values

Re: inverse of a matrix with Fraction entries

2010-11-27 Thread Mark Wooding
casevh writes: > I coded a quick matrix inversion function and measured running times > using GMPY2 rational and floating point types. For the floating point > tests, I used a precision of 1000 bits. With floating point values, > the running time grew as n^3. With rational values, the running tim

Re: inverse of a matrix with Fraction entries

2010-11-26 Thread casevh
On Nov 26, 2:11 pm, Steven D'Aprano wrote: > On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > > For ordinary number crunching, > > rational arithmetic is completely inappropriate. > > Why? > > -- > Steven As you perform repeated calculations with rationals, the size of the values (usually)

Re: inverse of a matrix with Fraction entries

2010-11-26 Thread Steven D'Aprano
On Fri, 26 Nov 2010 12:54:12 -0800, John Nagle wrote: > For ordinary number crunching, > rational arithmetic is completely inappropriate. Why? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: inverse of a matrix with Fraction entries

2010-11-26 Thread John Nagle
On 11/24/2010 10:30 AM, Robert Kern wrote: On 11/24/10 12:07 PM, Daniel Fetchinson wrote: The whole story is that I have a matrix A and matrix B both of which have rational entries and they both have pretty crazy entries too. Their magnitude spans many orders of magnitude, but inverse(A)*B is a

Re: inverse of a matrix with Fraction entries

2010-11-26 Thread casevh
On Nov 25, 1:28 pm, Daniel Fetchinson wrote: > Okay, I see your point and I completely agree. > Surely it will be faster to do it with integers, will give it a shot. > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown You may want to look at using GMPY. GMP

Re: inverse of a matrix with Fraction entries

2010-11-25 Thread Daniel Fetchinson
>> > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of >> > the denominators, and multiply the matrix by that to make it an integer >> > matrix N = l M. Then work out the determinant d of that integer matrix. >> > Next, the big step: use Gaussian elimination to find a matrix

Re: inverse of a matrix with Fraction entries

2010-11-25 Thread Mark Wooding
Daniel Fetchinson writes: > > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of > > the denominators, and multiply the matrix by that to make it an integer > > matrix N = l M. Then work out the determinant d of that integer matrix. > > Next, the big step: use Gaussian elim

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Robert Kern
On 11/24/10 12:30 PM, Robert Kern wrote: On 11/24/10 12:07 PM, Daniel Fetchinson wrote: The whole story is that I have a matrix A and matrix B both of which have rational entries and they both have pretty crazy entries too. Their magnitude spans many orders of magnitude, but inverse(A)*B is an

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Daniel Fetchinson
>> So after all I might just code the inversion via Gauss elimination >> myself in a way that can deal with fractions, shouldn't be that hard. > > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of > the denominators, and multiply the matrix by that to make it an integer > mat

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Mark Wooding
Daniel Fetchinson writes: > So after all I might just code the inversion via Gauss elimination > myself in a way that can deal with fractions, shouldn't be that hard. I wouldn't do it that way. Let M be your matrix. Work out the LCM l of the denominators, and multiply the matrix by that to mak

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Robert Kern
On 11/24/10 12:07 PM, Daniel Fetchinson wrote: The whole story is that I have a matrix A and matrix B both of which have rational entries and they both have pretty crazy entries too. Their magnitude spans many orders of magnitude, but inverse(A)*B is an okay matrix and I can deal with it using f

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Daniel Fetchinson
>> It's a mathematical problem so no uncertainty is present in the >> initial values. And even if there was, if there are many orders of >> magnitude differences between the entries in the matrix floating point >> does not suffice for various things like eigenvalue calculation and >> stuff like tha

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Daniel Fetchinson
>> I'm using fractions.Fraction as entries in a matrix because I need to >> have very high precision and fractions.Fraction provides infinite >> precision . . . >> >> Probably it doesn't matter but the matrix has all components non-zero >> and is about a thousand by thousand in size. > > I wonder h

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Daniel Fetchinson
I guess this is a question to folks with some numpy background (but not necessarily). I'm using fractions.Fraction as entries in a matrix because I need to have very high precision and fractions.Fraction provides infinite precision (as I've learned from advice from thi

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Robert Kern
On 11/24/10 9:10 AM, Daniel Fetchinson wrote: It's a mathematical problem so no uncertainty is present in the initial values. And even if there was, if there are many orders of magnitude differences between the entries in the matrix floating point does not suffice for various things like eigenva

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Peter Pearson
On Wed, 24 Nov 2010 14:02:21 +0100, Daniel Fetchinson wrote: [snip] > I'm using fractions.Fraction as entries in a matrix because I need to > have very high precision and fractions.Fraction provides infinite > precision . . . [snip] > > Probably it doesn't matter but the matrix has all components n

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Peter Otten
Daniel Fetchinson wrote: >>> I guess this is a question to folks with some numpy background (but >>> not necessarily). >>> >>> I'm using fractions.Fraction as entries in a matrix because I need to >>> have very high precision and fractions.Fraction provides infinite >>> precision (as I've learned

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Daniel Fetchinson
>> I guess this is a question to folks with some numpy background (but >> not necessarily). >> >> I'm using fractions.Fraction as entries in a matrix because I need to >> have very high precision and fractions.Fraction provides infinite >> precision (as I've learned from advice from this list). > >

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Peter Otten
Daniel Fetchinson wrote: > I guess this is a question to folks with some numpy background (but > not necessarily). > > I'm using fractions.Fraction as entries in a matrix because I need to > have very high precision and fractions.Fraction provides infinite > precision (as I've learned from advice

inverse of a matrix with Fraction entries

2010-11-24 Thread Daniel Fetchinson
I guess this is a question to folks with some numpy background (but not necessarily). I'm using fractions.Fraction as entries in a matrix because I need to have very high precision and fractions.Fraction provides infinite precision (as I've learned from advice from this list). Now I need to calcul