2

I know something about Pascal, Mathematica and Matlab, but I dont have any idea about C,C++,C# languages.

I want to learn one of the languages that they they are fast and exact to compute some arithmetic functions for large numbers(for example larger than $10^3000$). I asked somebody and he said he used C++ and he said I computed this sequence in less than 10 min.

I want to know C, C++, C# and visual kind of theses programs and know which is better for my goal.

Let $f$ be an arithmetic function and A={k1,k2,...,kn} are integers in increasing order.

Now I want to start with k1 and compare f(ki) with f(k1). If f(ki)>f(k1), put ki as k1.

Now start with ki, and compare f(kj) with f(ki), for j>i. If f(kj)>f(ki), put kj as ki, and repeat this procedure.

At the end we will have a sub sequence B={L1,...,Lm} of A by this property: f(L(i+1))>f(L(i)), for any 1<=i<=m-1

I have written a code for this program with Mathematica, and it take some hours to compute f of ki's or the set B for large numbers.

For example, let f is the divisor function of integers. Do you know how to write the code for my purpose in Mathematica or Matlab. Mathematica is preferable.

4
  • 1
    what sort of calculations do you want to make? Matlab is probably as good as C++ for just integer arithmetic, especially if you're already familiar with it.
    – TZHX
    Commented Jan 28, 2011 at 9:08
  • 1
    Are you interested in exploring the mathematics (e.g. number theory), or reimplementing computational number theory algorithms in a mainstream programming language? These goals are somewhat different.
    – rwong
    Commented Jan 28, 2011 at 11:43
  • my question is similar to this one: stackoverflow.com/questions/4830953/…
    – asd
    Commented Jan 28, 2011 at 23:56
  • I don't see any actual question here - which explains why the answers are all over the map.
    – Aaronaught
    Commented Jul 5, 2011 at 2:00

5 Answers 5

1

Every task is different.

I'd say, pick a flawed micro-benchmark which comes closest to your requirements, e.g. http://shootout.alioth.debian.org/, and draw your conclusions.

1

Bearing in mind "large numbers" (hence presumably bigger than 2^32), which means that it's "C or C++ or C# and a decent library". Some languages ship with support for large numbers (Smalltalk, Haskell, Common Lisp) and some don't.

0

You'd better use a language with a decent support for large numbers - e.g., Scheme, or a specialised language like Mathematica or Maxima. With C++ your choice is pretty much limited to libgmp.

3
  • Not even close to true -- there are about as many large integer math libraries for C++ as there are languages that support large integers as part of the language (e.g., NTL, MIRACL, LIP, ...) Commented Jan 28, 2011 at 14:32
  • @Jerry Coffin, most of that libraries are (IMHO, IMHO) inferior to GMP, so there is only one choice left, and it is not nearly close to ideal as well.
    – SK-logic
    Commented Jan 28, 2011 at 14:35
  • disliking something is no excuse for denying its existence. Commented Jan 28, 2011 at 14:39
0

C and C++ don't natively support very large numbers; you'd have to use a third-party bignum library (can't speak to C#).

Frankly, C and C++ aren't the best tools for number-crunching work.

0

If you are trying to do very high precision arithmetic (not quite the correct terminology, since this is integer rather than floating point), 99.9% of the CPU time will be spent in the library functions for said arithmetic, and it won't matter if the user layer is an intrepreter or a fast compiled language. What matters is finding a good "big integer" library, with a decent interface to a language you like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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