If the numbers are represented as prime factors to begin with, finding the gcd 
is easier. Then, calculating the sum requires multiplying out the numerators, 
which should be easier than factoring the decimal representation. But that's 
just my relatively naïve observation.

The power series I am dealing with was invented in a paper that is about 150 
years old and the author calculated some of the coefficients up to a power of 9 
and used the prime-factor representation for the denominator and the decimal 
representation for the numerator.  One of the larger coefficients has a value 
of 2114557858/(2**12*3**6*5*3). I don't know how much paper he needed to 
calculate that one. Most subsequent papers calculate to a power of 5.

My software can calculate to a power of 23 and then reaches the limits of my 
PC. Looking at the resource monitor tells me that I can probably benefit a lot 
from more RAM, but I haven't done that yet.

Based on your observations, I think the best way forward is the simple solution 
(more RAM), since we haven't received a response indicating that another 
solution is easy.

Tom
(Dr. Thomas S. Ligon)
thomassli...@gmail.com
Frohnloher Str. 6a
81475 Muenchen
Germany
Tel. +49(89)74575075

-----Original Message-----
From: sympy@googlegroups.com <sympy@googlegroups.com> On Behalf Of Oscar 
Benjamin
Sent: Saturday, August 6, 2022 6:15 PM
To: sympy <sympy@googlegroups.com>
Subject: Re: [sympy] storing big integers as prime factors

Integer gcd is not that slow. Factorising large integers into primes is though.

If you represent integers in terms of their prime factorisation then how can 
you efficiently add two integers?

On Sat, 6 Aug 2022 at 15:08, Thomas Ligon <thomassli...@gmail.com> wrote:
>
> Is there any way to do this, perhaps just by saying that I want to keep prime 
> factors instead of decimal digits?
> Background: I am writing software (using Python and SymPy) to calculate the 
> coefficients of a power series. By using Rational(0) to initialize sums and 
> Rational(1,2) to avoid getting a floating point, I have results that are 
> always rational, specifically quotients of large integers and have reached 
> the point where the integers have about 50 digits. I have a (fairly complex) 
> recursive function that calculates the coefficient of x**(n+1) when the 
> coefficients of x**n are known. When calculating the sum of two rational 
> numbers, this most likely calculates the greatest common denominator, 
> something which is sure to be hard. If all of the integers were always stored 
> in terms of their prime factors instead of decimal digits, it would be much 
> more efficient.
> Is there such a feature out there somewhere?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/7171be2f-67a7-4d48-8eac-5d37571677c4n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxTbrJwOfx8X%3DFHdZ8e-J3w0_qAt6iWBxW2POzJ9%3DNb9zw%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/001401d8aa30%24865ccb10%2493166130%24%40gmail.com.

Reply via email to