# Best Programming Language For Number Theory & Base

 Posts 114
Casual Member
Pinbacker
Casual Member
Joined: Feb 7 2014, 03:32 PM
Hello.

I realized that many of us are investigating what is the ultimate base, and in order to research on this eternally elusive question we do a lot of computer programming to make many number theoretic experiments. Thus an important question arises: what programming language should we use?

What are the best and most popular programming languages for working with all of these things?
• number bases
• prime numbers, prime factorization
• natural numbers
• very large integers
• integer sequences
• modular arithmetic, congruence
• totient function
• divisors, divisor function
Also, how would you rank Mapple, Mathematica, Python, IDL and Matlab for doing all of the previously mentioned things?

Dozens Disciple
Dan
Dozens Disciple
Joined: Aug 8 2005, 02:45 PM
I like Python. Easy to use, and has built-in support for arbitrarily-large integers.

Code: Select all

``````>>> 42**42
150130937545296572356771972164254457814047970568738777235893533016064``````
Only problem is that the implementation is slow.

 Posts 237
Regular
jrus
Regular
Joined: Oct 23 2015, 12:31 AM
The stuff on your list is easy enough to implement in any programming language. Having one with native support for big integers might help you though. And higher-level abstractions could save you some effort. Like Dan, Iâ€™m partial to Python.

You could also try Maple or Mathematica, if you want some symbolic computing support.

wendy.krieger
wendy.krieger
Most of the stuff I did with sevenites etc, was done in UBASIC, with a REXX wrappers.

Both of these handle large numbers. Prime factorisation is typically handled at 100+ digits.

UBASIC is very fast, and I wrote programs for the inner loops in it. The upfeed was made in REXX, which you can convert formulae into numbers without much hassle.

For example, one of the processes I do is to factorise the new factors that divide x^a-y^a for random values of a. The prototypes of the algebraic forms are stored by 'a', up to 162 places.

The rexx program inputs Aj 5/3 22 and this calculates the unique factor or algebraic root, in the base 5/3A22 (ie 5^22 - 3^22), and passes the output to 'factor' by Shamus Software to factorise.

Aj.rexx allows you to do things like reverse the inputs (ie Aj -r 22 5/2), so you can scroll through values of A22. It also handles the isobase versions, where x^2+y^2 = n, xy = d, for Aj 5/3 -22. This is indicated by setting the value of a to negative. In fact, it works in this as default, and converts a regular base into this form, by going n=x^2-y^2, d = xy.

 Posts 114
Casual Member
Pinbacker
Casual Member
Joined: Feb 7 2014, 03:32 PM
Thank you all for your answers so far.

I'm not going to use UBASIC since it seems to be an extremely uncommon and unpopular language.

Maple and Mathematica seem to me to be very weird. They look completely different than other programming languages. They seem messy and unclean. Just pure mayhem, anarchy, pandemonium.

What about C++, Fortran and Java? Are they good for working with bases and number theory?

wendy.krieger
wendy.krieger
On the other hand, UBASIC does byte-coding, which means it does not have to interpret the files. This means it does a partial compile of the code before it runs.

Dozens Disciple
Treisaran
Dozens Disciple
Joined: Feb 14 2012, 01:00 PM
The command-line calculator bc is an arbitrary-precision calculator with support for many bases (input up to unquadral inclusive; output up to base 2^27z), and can be programmed with C-like syntax. See the thread for its limitations and workarounds. I use it for all my base-n research on a computer.

 Posts 237
Regular
jrus
Regular
Joined: Oct 23 2015, 12:31 AM
C++ and Java are languages with lots of syntactic and conceptual overhead. It will take much more programmer effort to do what you want than if you were using Python, Ruby, Clojure, OCaml, Lua, Javascript, or the like.

Fortran might be a good choice if you have extremely large calculations that need to run very fast on scientific computing clusters, and you have large amounts of expert programmer time to spend on optimization. I donâ€™t think it makes any sense to use it for prototyping or small scale computation.

If you are considering something like Fortran or Matlab, I would recommend Julia as an alternative. http://juliacomputing.com

But hey, use whatever tools you want. If you are already familiar with some set of tools, youâ€™ll probably get to your goal faster by just rushing ahead with your implementation than by chatting about programming languages on the internet.

 Posts 113
Casual Member
Sennekuyl
Casual Member
Joined: Jun 29 2014, 06:00 AM
Common Lisp has a rudimentary native support for alternative bases up to 30z from memory.

But I don't know if it does the last few items of what you require. (I've really got to set aside some time to practice programming soon. :sigh: ). As a non-programmer its seems logical that most languages can do any of that, though.

 Posts 114
Casual Member
Pinbacker
Casual Member
Joined: Feb 7 2014, 03:32 PM
After thinking for a while, I've come to the conclusion that the best language for doing number theory is either Python or Mathematica, but I don't know which one is better.

Mathematica has not been discussed much in the thread.
What are its advantages and disadvantages compared to Python?
Does Mathematica have more number theory functions than Python?
Is it faster to write programs (in number theory) in Mathematica than in Python?
Would the calculations be done faster in Mathematica than in Python?

Dozens Demigod
icarus
Dozens Demigod
Joined: Apr 11 2006, 12:29 PM
I've done a great deal of work in Mathematica. (in past 3 years have written over 6000 integer sequence programs at OEIS and have coded about 1.75% of OEIS' over 287000 sequences in Mathematica). It has a large number of number theory functions, but plenty of other not necessarily mathematical tools, string and list manipulation tools, etc. that make it a great package. Problem is that it is proprietary and relatively expensive.

Python has sympi, a number theory package that you can load. I think Python is slow for many applications, unless you can compile your programs. You can read about both online. Mathematica has a stackexchange forum.

If you're into number theory, also look into PARI-GP out of France. It is open source and is fast. It does not have all the capabilities outside of number theory that Mathematica has. Search on "pari number theory" and you'll find it.

Dozens Disciple
Dan
Dozens Disciple
Joined: Aug 8 2005, 02:45 PM
I haven't used Mathematica, but as I understand it, it's a computer algebra system and graphing software (and a competitor to Maple), whereas Python (which I use frequently) is a general-purpose programming language that happens to have a few optional packages for scientific computing.

wendy.krieger
wendy.krieger
If the aim is to learn how to write tight code from number theory, then i found using a rexx wrapper around a hamster is the way to go. The hamster is a little program like 'factor' or the UBASIC factor routines on this. You don't have to modify this code much, largely to get it to print some extra string on the output line.

The REXX code isn't run much: its function in life is to create a command line for the hamster to chew on. This is usually something like a command line of a search-string and a very large number.

Code: Select all

``````&#91;D&#58;\&#93;aj 12 96
factorising 12A96 = 34182189187166851926484583071088641
first trying brute force division by small primes
PRIME FACTOR &nbsp; &nbsp; 7489
now trying 1000 iterations of brent's method
PRIME FACTOR &nbsp; &nbsp; 3122881
PRIME FACTOR &nbsp; &nbsp; 1461573322938242802306049``````
The hamster here is a win32 and os2 factor program.

Code: Select all

``````&#91;D&#58;\&#93;factor
Incorrect Usage
factor <number>
OR
factor -f <formula>
e.g. factor 999999999999999999999999999999999999999999999999999997
or &nbsp; factor -f 10#100-19

To suppress the commentary, use flag -s
To input from a file, use flag -i <filename>
To output to a file, use flag -o <filename>
e.g. factor -f 10#100-7 -s -o factors.dat

Freeware from Shamus Software, Dublin, Ireland
Full C source code and MIRACL multiprecision library available
Email to mscott@indigo.ie for details
Web page http&#58;//indigo.ie/~mscott
Source code from ftp&#58;//ftp.compapp.dcu.ie/pub/crypto/miracl.zip
``````
I use it fromhttp://home.netcom.com/%7Ejrhowell49/math/index.html which is updated.

The optimisation comes from feeding the hamster correctly. A spot of optimisation, over a period of three or so days, reduced the running time of a number of projects by months.

Another good trick in the rexx program is to put the program into shutdown mode, where a signal is raised by creating a file, and the batch run ends at the end of the signal. The last good record is kept updated, so it starts with the first undone one on power failure etc.