Multiplicaton of big integers (factorial) [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I accidentally saw on Internet that functional programming language SML allows to do arbitrary precision integer arithmetic. I had written big integer arithmetic on C++ before and I decided(for curiosity) to compare my implementation with SML's by computing factorial of big numbers. I found out that SML program works about 15 times faster than mine. My implementation uses elementary school multiplication algorithm. But as I know the fast algorithms (such as FFT or Karatsuba's algorithm) worked better than elementary school multiplication when multipliers aren't much different. In this case they are, because (n-1)! is much greater than n. My question is what are the other possible reasons that the SML program works so faster.

Three possible reasons:
It uses multiple CPU cores (easy to test)
It uses SIMD instructions
It uses GPU (rare, but not unheard of)

Related

Solving a modular exponentiation with unknown power [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Guys I what is the fastest algorithm to solve a modular equation in the format of a^b = c mod p where p is a really big prime and b is unknown.
e.g.:
2^k = 15 mod 30903154482632612361920641803533
I already tried trial and error using boost library in C++ but it would take very long time to reach the answer.
You're trying to solve what is called a discrete logarithm. If there was an efficient solution to this, I imagine whoever discovered it would wreak chaos on cryptographic systems long before it would be posted here.
You will find quite a couple of algorithms on Wikipedia with varying time complexity. Some of these are quite easy to implement. See The computational complexity of discrete log for the best space complexity.

How to draw conclusions of performance comparisons between CPLEX, GuRoBi and SAS solvers [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Are there guidelines to estimate beforehand which solver should be used for a mathematical optimization project?
Specifically this leads me to the following sub-questions:
How do performance benchmarks translate to probable or even possible optimization-performance-limits - specifically I mean maximum variable numbers for LPs and MILPs? (I am very much aware that this depends on the optimization problem, but there could to be a number(-range) from personal experience. The benchmark I am referring to is by H. Mittelmann: http://plato.asu.edu/ftp/milpc.html.)
Is it a fair conclusion to say CPLEX is 1.42 times slower than GUROBI, and if you are using CPLEX, but not switching to GUROBI, that you are wasting your company's resources (disregarding investments)?
Is it a fair conclusion to state that SAS is an incalculable risk for an optimization-project, because it fails 3 out of 87 calculation-runs when GUROBI doesn't?
I am aware that this question is awkward, but I think it has practical relevance (at least for me). Thanks in advance for answers.

Interior Point Method(Path following) vs Simplex [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What are pros and cons of these two LP methods ?
I can only think of less iterations in Interior Point Method (when LPP is sufficiently large).
I'm going to list some features of both algorithms to explain what differentiates them.
Simplex
provides a basic solution, useful for branch and bound solvers in integer programming
easy to warm (or hot) start from a suboptimal solution, also necessary for integer programming
very high iteration speed mainly due to preservation of sparse data structures, but sometimes requires many iterations to reach optimality
memory efficient
numerically very stable
Interior Point
iteration count independent of problem size
often faster to reach optimality
easier to parallelize (Cholesky factorization)
In summary, IPM is the way to go for pure LPs, while for reoptimization-heavy applications like (mixed) integer programming the Simplex is better suited. One may also combine both approaches and perform a Simplex-like cross-over after the IPM found an optimal solution to get a basic one.
Often, it is a good idea to try both methods and decide then what works best, because performance is very much problem dependent.

What is the most efficient way to calculate PI in C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm have to write a C program, what it does is takes a integer as input. And gives output to the input(th) number of PI after decimal. Like if input is 100, output will be 9(100th digit of pi, after decimal is 9).
What will be the best algorithm for that?
p.s I don't want to save the value of pi into the string, and do it.
Your question is more a math question than a C programming one (so perhaps off-topic). Read first the wikipage on Pi and Approximations of π
If you need to compute only a few hundred (or even hundred thousands) digits, you just need to use some algorithm and code it using some bignum library (e.g. GMPlib, which has mpfr_const_pî ass commented by chtz).
Things become interesting for many billions of digits. I'm not expert on Pi, but look into Fabrice Bellard work on it (read the technical notes mentioning Chudnovsky's algorithm).

C++ sort() function algorithm [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Some days ago I wanted to use C++ sort() function to sort an array of strings, but I had a problem!
What algorithm does it use to sort the array? Is it a deterministic one or may it use different algorithms based on the type of the array?
Also, is there a clear time complexity analysis about it?
Does this function use the same algorithm for sorting numbers array and strings array?
It might or it might not. That is not specified by the standard.
And if we use it to sort an array of strings which the total size of them is less than 100,000 characters, would it work in less than 1 second(in the worst case)?
It might or it might not. It depends on the machine you're running the program on. Even if it will work in less than 1 second in worst case on a particular machine, it would be difficult to prove. But you can get a decent estimation by measuring. A measurement only applies to the machine it was performed, of course.