Department of Mathematics



Computing With Large Integers Using the CLN C++ Library

CLN is a C++ library that allows you to do arithmetic with arbitrarily large integers. This library is installed on the computers in the Math Lab.

As an example, I have written a program, ammprobcln.cpp, that searches for solutions to the equation

n3 + n2 + n + 1 = x2

To run the program on a computer in the lab, first save the file to your home directory. Then start up a terminal, and enter the command
$ g++ ammprobcln.cpp -o ammprobcln -lcln
This will compile the C++ program, and create the command ammprobcln. This command takes two arguments that give the range of integers to test. For example, to test the integers from 1 to 10000, enter
$ ./ammprobcln 1 10000
This will produce the output
1 4 2
7 400 20
The first number in each line of output is the value of n, and the third number is x.

You don't have to be an expert C++ programmer to use this library. Take a look at the C++ program. The main loop of the computation is at the bottom, beginning with the line that says while ( n <= nlast ). (Note that n3 + n2 + n + 1 = (n2+1)(n+1).) The code before this point consists of C++ header information, variable declarations, and some code that gets the numbers from the command line. You can use this C++ file as a template for your own programs.

To learn about the CLN functions that are available, check out the CLN documentation. In particular, for integers, you will find an assortment of interesting functions (including gcd, lcm, and more) in Section 4.9, and the sqrtp function that I used in my example is documented in Section 4.7.




But what about...?

Experienced programmers, or users of software such as Maple or Mathematica, might ask about alternatives to CLN.

Footnotes:

(Notes by Warren Weckesser, June 2006)