You could try implementing something like this, but I very much suspect it will be slower this way. For one thing, the space complexity will be increased by a lot, which is quite significant when you consider how many rationals might exist at one time. Second, factoring an integer is slow, even for relatively small integers. On the other hand, the Euclidean algorithm is very fast, and integer division by the gcd at the end is extremely fast (one cycle if the integer is small enough). Division would require a loop in your scheme. The same for multiplication. Addition would be the worst. You would have do a complete refactorization in general.
Finally, you are mistaken in thinking that 10**20 is sufficient. Internal calculations of certain algorithms regularly result in very large numbers, and it's also not uncommon to start with very large numbers in the first place. Aaron Meurer On Feb 28, 2013, at 2:12 PM, Harsh Gupta <gupta.hars...@gmail.com> wrote: Hi, I think it would be better if we represent the rational numbers as a product of primes raised to some integer power. We can compute and store all the primes we will need to work with a practically large number, say anyone will not need to work with numbers larger than 10**20. Then well will need store only primes less than 10**10, because if some number is not divisible by any number less than equal to sqrt(n) then it is prime. And if we happen to need more primes than we have stored then we can compute them in the run time. Representing the rational this way will make multiplication and division of primes a lot faster. -- Harsh Gupta -- 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 post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- 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 post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.