Best Programming Language For Number Theory & Base

Best Programming Language For Number Theory & Base

Pinbacker
Casual Member
Pinbacker
Casual Member
Joined: Feb 7 2014, 03:32 PM

Mar 17 2016, 10:11 PM #1

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?

Thanks in advance for your answers.
Quote
Like
Share

Dan
Dozens Disciple
Dan
Dozens Disciple
Joined: Aug 8 2005, 02:45 PM

Mar 18 2016, 04:24 AM #2

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.
Quote
Like
Share

jrus
Regular
jrus
Regular
Joined: Oct 23 2015, 12:31 AM

Mar 18 2016, 09:35 AM #3

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.
Quote
Like
Share

wendy.krieger
wendy.krieger

Mar 18 2016, 09:50 AM #4

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.
Quote
Share

Pinbacker
Casual Member
Pinbacker
Casual Member
Joined: Feb 7 2014, 03:32 PM

Mar 20 2016, 05:07 AM #5

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?
Quote
Like
Share

wendy.krieger
wendy.krieger

Mar 20 2016, 09:37 AM #6

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.
Quote
Share

Treisaran
Dozens Disciple
Treisaran
Dozens Disciple
Joined: Feb 14 2012, 01:00 PM

Mar 20 2016, 10:11 AM #7

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.
Quote
Like
Share

jrus
Regular
jrus
Regular
Joined: Oct 23 2015, 12:31 AM

Mar 20 2016, 11:37 PM #8

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.
Quote
Like
Share

Sennekuyl
Casual Member
Sennekuyl
Casual Member
Joined: Jun 29 2014, 06:00 AM

Mar 21 2016, 05:37 AM #9

Common Lisp has a rudimentary native support for alternative bases up to 30z from memory.

See this thread

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.
Quote
Like
Share

Pinbacker
Casual Member
Pinbacker
Casual Member
Joined: Feb 7 2014, 03:32 PM

May 26 2017, 05:14 PM #10

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?
Quote
Like
Share

icarus
Dozens Demigod
icarus
Dozens Demigod
Joined: Apr 11 2006, 12:29 PM

May 28 2017, 03:30 PM #11

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.
Quote
Like
Share

Dan
Dozens Disciple
Dan
Dozens Disciple
Joined: Aug 8 2005, 02:45 PM

May 29 2017, 03:05 AM #12

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.
Quote
Like
Share

wendy.krieger
wendy.krieger

May 30 2017, 12:36 PM #13

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

[D:\]aj 12 96
factorising 12A96 = 34182189187166851926484583071088641
first trying brute force division by small primes
PRIME FACTOR     7489
now trying 1000 iterations of brent's method
PRIME FACTOR     3122881
PRIME FACTOR     1461573322938242802306049
The hamster here is a win32 and os2 factor program.

Code: Select all

[D:\]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.
Quote
Share