## Multiprecision Computing Toolbox for MATLAB

The Multiprecision Computing Toolbox is the MATLAB extension for computing with arbitrary precision.

The toolbox equips MATLAB with a new multiple precision floating-point numeric type and extensive set of mathematical functions that are capable of computing with arbitrary precision.

The multiprecision numbers and matrices can be seamlessly used in place of the built-in `double`

entities following standard MATLAB syntax rules. As a result, **existing MATLAB programs can be converted to run with arbitrary precision with minimal changes to source code**.

**Quadruple precision computations** (compliant with IEEE 754-2008) are supported as a special case.

## Functionality

Toolbox provides a comprehensive library of computational routines covering the following areas:

- Real and complex numbers, full and sparse matrices, multidimensional arrays
- Elementary and special mathematical functions
- Solvers for system of linear equations (including direct and iterative sparse solvers)
- Matrix analysis functions and factorizations
- Eigenvalues and eigenvectors including generalized and large-scale problems.
- Singular value decomposition
- Solvers for system of nonlinear equations (
`fsolve`

with Levenberg-Marquardt and other trust region methods) - Numerical integration (including adaptive
`quadgk`

and full set of Gaussian quadrature) - Optimization and polynomials
- Ordinary differential equations solvers
- Data analysis and Fourier transform
- Number theory functions

Please visit the Function Reference page for a complete list of supported functions and User’s Manual for usage examples.

## Performance

There is a common misbelief that arbitrary precision computations are very slow. Indeed, mainstream numerical software packages are largely responsible for this false perception. Their codes were written decades ago using textbook algorithms, without proper optimization nor updates for the latest hardware.

We are determined to change the situation by developing high-performance numerical libraries for computations with arbitrary precision, tuned for modern CPU architectures, multi-core parallelism and relying on recent state-of-the-art algorithms. All combined makes our toolbox order(s) of magnitude faster compared to famous competitors:

Factorization | Timing (sec) | Speed-up (times) | |||||
---|---|---|---|---|---|---|---|

MATLAB (VPA) | Maple | Mathematica | Advanpix | Over VPA | Over Maple | Over Mathematica | |

A & B are pseudo-random real matrices (500×500): | |||||||

[L,U] = lu(A) | 249.13 | 85.16 | 15.12 | 0.47 | 534.38 | 182.67 | 32.42 |

[Q,R] = qr(A) | 514.34 | 458.86 | 44.39 | 3.08 | 167.25 | 149.21 | 14.43 |

[U,S,V] = svd(A) | 5595.26 | 4317.40 | 376.94 | 9.57 | 584.62 | 451.11 | 39.38 |

S = svd(A) | 2765.11 | 645.60 | 56.96 | 2.98 | 927.17 | 216.48 | 19.10 |

[V,D] = eig(A) | 21806.30 | 6060.90 | 584.86 | 33.75 | 646.05 | 179.57 | 17.33 |

lambda = eig(A) | 3384.58 | 7822.30 | 205.46 | 23.55 | 143.70 | 332.11 | 8.72 |

[V,D] = eig(A,B) | n/a | 11358.00 | 928.89 | 112.05 | ∞ | 101.36 | 8.29 |

lambda = eig(A,B) | n/a | 5273.00 | 510.80 | 60.37 | ∞ | 87.34 | 8.46 |

Function | Timing (sec) | Speed-up (times) | |||||
---|---|---|---|---|---|---|---|

MATLAB (VPA) | Maple | Mathematica | Advanpix | Over VPA | Over Maple | Over Mathematica | |

Power & exponential: | |||||||

EXP | 107.34 | 756.14 | 4.54 | 0.12 | 886.34 | 6243.90 | 37.49 |

LOG | 1161.18 | 593.98 | 6.61 | 0.23 | 5133.40 | 2625.91 | 29.21 |

LOG10 | 1438.91 | 639.46 | 11.13 | 0.24 | 5958.23 | 2647.88 | 46.09 |

LOG2 | 1442.71 | 643.17 | 11.08 | 0.25 | 5789.35 | 2580.94 | 44.48 |

SQRT | 28.75 | 427.40 | 2.60 | 0.27 | 105.74 | 1571.90 | 9.55 |

Trigonometric: | |||||||

SIN | 85.28 | 736.89 | 6.07 | 0.15 | 570.80 | 4932.33 | 40.62 |

COS | 78.96 | 513.73 | 6.10 | 0.15 | 516.44 | 3359.92 | 39.89 |

TAN | 1261.92 | 844.05 | 8.91 | 0.17 | 7277.51 | 4867.64 | 51.37 |

ASIN | 105.12 | 1181.83 | 12.39 | 0.39 | 266.40 | 2995.01 | 31.39 |

ACOS | 100.49 | 1330.99 | 23.10 | 0.39 | 257.55 | 3411.03 | 59.19 |

ATAN | 131.92 | 1039.55 | 5.71 | 0.14 | 974.28 | 7677.64 | 42.17 |

SEC | 1466.09 | 778.14 | 8.00 | 0.18 | 8199.59 | 4352.01 | 44.76 |

CSC | 1503.75 | 793.87 | 8.35 | 0.18 | 8490.95 | 4482.60 | 47.13 |

COT | 1511.67 | 1014.76 | 10.46 | 0.20 | 7728.36 | 5187.95 | 53.48 |

Selected special: | |||||||

gamma | 2491.81 | 7734.53 | 228.35 | 0.76 | 3266.23 | 13018.78 | 299.31 |

erf | 104.11 | 321.20 | 125.88 | 0.16 | 669.96 | 2163.26 | 810.02 |

bessely(0,x) | 7855.70 | 14923.53 | 250.38 | 0.83 | 9482.98 | 18014.89 | 302.25 |

bessely(1,x) | 7302.29 | 14964.26 | 267.94 | 0.83 | 8786.29 | 18005.36 | 322.39 |

besselj(0,x) | 7273.29 | 9998.60 | 90.54 | 0.75 | 9684.81 | 13313.72 | 120.55 |

besselj(1,x) | 5987.67 | 10153.13 | 91.89 | 0.74 | 8077.25 | 13696.38 | 123.96 |

More detailed comparison with VPA: Symbolic Math Toolbox (VPA) vs. Multiprecision Computing Toolbox.

In some cases, the speed of quadruple precision computations in toolbox is comparable (or even higher) to double precision routines of MATLAB. Eigendecomposition of banded matrices is one of the examples.

## Demos

Computation of eigenvalues and especially eigenvectors is one of classic problems requiring extended-precision. The main reason is that eigenproblem might be ill-conditioned and hard to compute even when matrix itself is well-conditioned with respect to inversion.

The two plots below show the eigenvalues of the Grcar matrix computed by MATLAB and by the toolbox, respectively. The eigenvalues of the Grcar matrix are displayed in black, and the eigenvalues of the transposed matrix – in red. In theory they should coincide:

**Figure 1**. MATLAB is unable to generate accurate results using the

`double`

precision.**Figure 2**. Correct eigenvalues computed with quadruple precision by the toolbox.

Although condition number of the Grcar matrix is low, `cond(A) = cond(A') = 3.61`

, MATLAB’s `double`

precision routines suffer from accuracy loss. More examples can be found on Computing Eigenvalues in Extended Precision.

## Applications

The toolbox removes MATLAB’s inherent limitation on computing precision, thus enabling the user to solve a variety of important problems previously impossible to handle with MATLAB:

- Allows solving of numerically unstable problems (e.g. computing eigenvalues, matrix functions, solving ill-conditioned matrices, algebraic Riccati equations, differential equations using RBF methods, finding roots, analyzing control system stability by solving Lyapunov and Sylvester equations, etc. etc.).
- Enables checking of accuracy of results by re-running existing MATLAB programs in extended precision.
- Minimizes rounding and cancellation errors in computations (e.g. summation of series with alternating signs, oscillatory integrals, etc.).
- Allows computing of reference constants and coefficients of algorithms with high accuracy.

## Key Features

**Comprehensive set of mathematical functions.**Multiprecision Computing Toolbox supplies arbitrary-precision analogs to the majority of the functions listed in the famous MATLAB Top 500, from simple arithmetic operations to advanced numerical algorithms (e.g.`fft, eig, svd, quadgk, ode45, etc.`

), and adds original functionality not available in MATLAB. Please visit the Function Reference page for a complete list of supported routines.**Easy porting of existing MATLAB programs to arbitrary precision.**

The Toolbox employs an operator overloading technique which allows easy porting of pre-existing programs to arbitrary precision – with little or no modifications to the source code. In most cases the conversion is automatic, and no extra action is required by the user. For further examples, visit User’s Manual.**Algorithms.**Multiprecision Computing Toolbox stands on the shoulders of giants – we implement only state-of-the-art algorithms designed for parallelism and high-performance. Usually we convert algorithms from LAPACK to precision-independent C++ code with various optimizations for vector and multi-core execution.

Every routine in toolbox is a meta-algorithm, which analyses the input matrix and applies best suitable method for its type (symmetric/Hermitian, positive definite, triadiagonal, band, triangular, etc.). Thus, for example, we use multi-shift QR for unsymmetric eigen-decomposition whereas symmetric/Hermitian or tridiagonal problems are solved by MRRR or Divide & Conquer algorithms.**High-performance.**Our product is developed using compiled programming languages C/C++ and Assembler with only a thin M-file interface for smooth integration to MATLAB. Toolbox is specifically optimized for parallel execution on multi-core CPU.**Ease of access and user-friendliness.**

We provide comprehensive instructions and step-by-step installation help, making it easy to install and use the Multiprecision Computing Toolbox. Toolbox is available for 64-bit versions of**GNU Linux**,**Microsoft Windows**, and**Apple Mac OS X**. The Quick Start User’s Manual, Function Reference, and our frequently updated Blog provide examples, tips, and announcements about our product.

## Reviews

*“While it is rather surprising that MATLAB does not have a native engine for handling arbitrary-precision computations, Advanpix more than fills this gap. The toolbox has a very intuitive syntax, is well documented and is therefore straightforward to use with a fairly gentle learning curve. In my research group we have used Advanpix to tackle a range of different problems in areas such as control theory (involving solution of complicated systems of nonlinear algebraic equations), integration of stiff ODE systems and evaluation of special functions. In all these cases Advanpix turned out to be the key enabler making it possible for us to solve problems which otherwise could not be cracked using standard tools.*

The part of the entire product which I find the most impressive is the customer support. Pavel Holoborodko is very prompt, efficient and professional. He constantly seeks to expand the multiprecision capability of Advanpix to different MATLAB functions and toolboxes. As an example, on my request, he quickly developed the multiprecision versions of some specialized functions in the control toolbox. As we are based on different continents, his responses and solutions usually arrive overnight, if not sooner. This all the more impressive given that the company seems to have limited human resources.

*I consider Advanpix a very solid piece of scientific computing software and offer it my highest recommendation.”*

Department of Mathematics & Statistics

McMaster University

Hamilton, Ontario, CANADA L8S 4K1

www.math.mcmaster.ca/bprotas

*“Some relative orbit determination problems require solving a high-dimensional eigenproblem. The Multiprecision Computing Toolbox environment with quad-precision allowed accurate resolution of many more eigenvalues when compared with standard double-precision computations. Advanpix provided a versatile and easy-to-use computational tool to satisfy our needs.*

I highly recommend their product when high-precision multi-digit computations are required.”

I highly recommend their product when high-precision multi-digit computations are required.”

Dept. of Mechanical and Aerospace Engineering

Old Dominion University

www.odu.edu

*“As far as I know, this is the fastest multiple-precision toolbox for MATLAB. In particular, the quadruple precision (binary128) arithmetic is surprisingly fast, which is comparable to the double precision (binary64) arithmetic. As improbable as it may sound, it is true, also for matrix computations on multi-core systems.*

The implementation of numerical algorithms in the toolbox is stable and highly reliable. Therefore, it is available for professional use such as verification of computed results by our developed methods, numerical results in scientific paper and so forth.

*The user support is also satisfactory. The toolbox developer kindly replies to e-mails very quickly. I hope it will continue far into the future.”*

Director of the Center for Information Science

Associate Professor at Division of Mathematical Sciences,

Tokyo Woman’s Christian University

www.math.twcu.ac.jp/ogita/

*“My experience with Advanpix Toolbox has always been smooth and nice. First of all, the learning curve is very gentle when you already know the standard MATLAB language. I think this is one of the main advantages of this software.*

*I hope to underline also the fact that the main developer of this Toolbox is simply unstoppable. The new features and updates appear with such a speed that the users get tired to download the new versions. Imagine, you are just debugging your poor program and meanwhile already two new versions of Advanpix appear with 36 new features and 10x speed improvement at each update. When I look at the version history I feel depressed and want to change immediately the profession… It is simply impossible to code like Pavel. Sometimes I suspect that “Pavel Holodoborodko” is a nickname (like Nicolas Bourbaki in Mathematics) for a group of coders who work 26h per day. The productivity of this person remains a mystery to me.”*

www.denys-dutykh.com/

LAMA UMR #5127

Laboratoire de Mathématiques

Université de Savoie

Campus Scientifique

73376 Le Bourget-du-Lac, France

*“After using the Advanpix toolbox for a couple of weeks I am pretty convinced that this add-on to MATLAB is a must for everyone having to solve problems at the edge of precision. It is not for the final result, which in Physics is usually significant with a few digits (ten at most for the best known observables like the fine structure constant) that multiple precision is important; but it often occurs that in the course of a complex calculation, involving matrix analysis and/or solution of multidimensional differential equations, extended precision can be crucial to get the right final result.*

*In a problem I considered recently, expansion into a series of Legendre polynomials for a highly oscillating polynomial (up to 1000 roots in the unit interval), double precision runs into trouble very early and quadruple or even higher precision is essential to get to the right result. The choice is obviously to be made among floating point high-precision calculations and symbolic, in principle exact, approaches. Running time is one important aspect which has a great impact on the decision. Advanpix is really fast and together with reliability this fact makes it a great piece of modern numerical software.”*