Calculus and Linear Algebra Functions

JavaTools provides a few functions for calculus that outperform the built-in Mathematica functions.

JEigenvalues[]

The function JEigenvalues[] computes all eigenvalues of a tridiagonal matrix having three diagonals with the values a, b, and c, and a dimension of n x n. Tridiagonal matrices are special cases of the band matrices, which occur frequently in the theory of differential equations, as discretisations of many initial value problems lead to bandmatrices. The error of such discretisations is decreased the larger the number of rows (columns) is made, which results in linear band matrix systems of hundreds and thousands of rows (columns) for real-life practical problems.

In the following example we use a tridiagonal matrix that has 5 on the main diagonal, 3 on the subdiagonal, and 6 on the superdiagonal, and 40 rows (40 columns). It looks like this:

Its eigenvalues are:

Note the speed of the computations (single-threaded!):

Mathematica does unfortunately not output the eigenvalues in the correct order (all eigenvalues of a real bandmatrix are monotonic!), and Mathematica is much slower:

341 milliseconds, vs 0., and problematic results.

With a larger dimension the problem in Mathematica unfortunately becomes progressively worse. Eigenvalues[] throws a warning informing about the fact that for a 400 x 400 element matrix the dense matrix methods would likely be faster, which is disappointing, as tridiagonal matrices (in general: band matrices) are perfect applications for sparse matrix technology. Also the timing results show drastic differences, and some eigenvalues even are missing:

4.14 econds vs. 0., and problematic output.

With matrix dimensions in the millions, Mathematica's Eigenvalues[] cannot produce any results anymore. JavaTools' JEigenvalues[] has no problems computing 20 million eigenvalues of a tridiagonal matrix in 2.2 seconds (and this doesn't even use any multi-threading!):

... or 200 million in 26 seconds:

JEulerSieve[]

The JavaTools function JEulerSieve[] computes all prime numbers up to the given limit. The function is extremely fast and beats a Mathematica-only implementation also provided by JavaTools. However, the Mathematica implementation can still be useful if the number of prime numbers requested causes Java to run out of heap space because of memory limitations of the user's system. The Mathematica-only implementation then can make use of file swapping, although the running time for this increases exponentially.

JEulerSieve[] can compute all prime numbers up to 35 million (over 2.1 million), in a little over a second.

Here we compute all prime numbers up to 1.4 billion in a little over a minute.

The Mathematica -only implementation of JavaTools can compute this list as well, but it needs file swapping, and therefore is much slower.

The Java-only method is about 1052/63 = 17 times faster.

On a Linux system with 8 GB of RAM there is not enough heap space to compute all prime numbers up to 1.5 billion.

The Mathematica -only implementation of JavaTools can still compute it, but it takes substantially longer due to the use of a swap file.