We have already seen several aspects of the improvements in Mathematica 4 when working with arrays of machine numbers. One reason that works efficiently is that many operations such as
But another aspect of efficient programming is to have useful primitives that make it easy to express problems directly and have it work efficiently, i.e., programmer time is also a valuable commodity. Below we see some enhancements to functional and list-based programming that should make it easy to express many programs very succinctly.
In Mathematica 4 there are basic extensions of the functional programming approach in
The following program adds until some element reappears.
It is then easy to combine this construction with other ones such as
The extensions to list operations include new operations such as
One of course naturally associates
Below is an example that performs multiplication of integer sequences in base b.
This works just fine even for quite large numbers, in this case 100,000 digit numbers.
But it is more efficient to work in a slightly larger base, in this case base . This effectively shortens the digit sequence and makes better use of the built-in arithmetic in the processor.
The same ideas apply to polynomial and series multiplication. Below is an example of polynomial multiplication that is quite efficient for certain types of polynomials. As can be seen, it basically mimics the number multiplication algorithm.
In this case we have to define a function that returns a polynomial expression from its coefficient tensor.
First a simple check that we have gotten the details right.
This defines a random dense polynomial of degree , and then multiplies it by itself.
Converted by Mathematica June 4, 2000