4
$\begingroup$

I am trying to do some work on some math conjecture. I am testing the conjecture numbers using very large math numbers (100+ digits ). I am currently using python to test these numbers.

In the conjecture's calculation, I quickly need to multiply and divide different large numbers several times. Python can do this quickly(~3000 calculations per minute). Is there any other faster software to achieve this.

$\endgroup$
  • 3
    $\begingroup$ Have you tried any of the various GMP bindings for Python?At least at one point in the past that could lead to large speedups. $\endgroup$ – njuffa Dec 29 '18 at 22:02
  • $\begingroup$ Are the numbers integers? $\endgroup$ – nicoguaro Dec 30 '18 at 17:26
  • $\begingroup$ yes,numbers are intergers $\endgroup$ – Rahul Shah Dec 30 '18 at 18:12
  • 1
    $\begingroup$ You can probably use SymEngine, it is written in C++ but can be used as a Python library. $\endgroup$ – nicoguaro Dec 31 '18 at 2:42
  • 1
    $\begingroup$ Boost.Multiprecision? It has GMP bindings if you need it. $\endgroup$ – user14717 Jan 1 at 23:24
6
$\begingroup$

Why not give GMPY2 a try? From the introduction:

gmpy2 is a C-coded Python extension module that supports multiple-precision arithmetic. gmpy2 is the successor to the original gmpy module. The gmpy module only supported the GMP multiple-precision library. gmpy2 adds support for the MPFR (correctly rounded real floating-point arithmetic) and MPC (correctly rounded complex floating-point arithmetic) libraries. gmpy2 also updates the API and naming conventions to be more consistent and support the additional functionality.

GMPY2 supports the integer arithmetic I assume you need and I doubt you can find anything faster.

On *nix based systems, you'll need to make sure that the latest version of GMP is installed (GNU MP Bignum Library. On Windows, you can find a Python wheel courtesy of Christophe Gohlke here.

$\endgroup$
1
$\begingroup$

Using something such as numpy.divide, you most likely will see no considerable difference from doing it in C++. Although casting might be something to consider. C++ may see some improvement in this area as Python will have to deal with this in real-time. With C++ this will not pose an issue. (Python will now cast any ints to floats for doing division as well).

$\endgroup$
1
$\begingroup$

OP's comment on OP:

yes,numbers are intergers

For arbitrarily large integer calculations, MAPLE is an option worth trying. it has very efficient implementations for a number of such calculations.

$\endgroup$
  • $\begingroup$ thanks........... $\endgroup$ – Rahul Shah May 7 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.