Understanding MPmath Extraprec

Asked 2 months ago, Updated 2 months ago, 2 views

I'm making a program with python3.
In the process, I am using polyroots in mpmath.
There is a sentence called extraprec in that code. Please tell me what code this sentence is for.


python python3

2022-09-30 11:43

1 Answers

Parameter to extend computational accuracy when calculating all the roots of a given polynomial.

The answers to the following article are likely to be relevant.(Although the default values are inconsistent)
The reason may not be accurate because I use Google.(Corrected typo pointed out by comment)
Finding the roots of a simple political with mpmath

The documentation comments that increasing extreme may be necessary to achieve convergence. This is the case for your example, due to root multiplicity.

>>mpmath.polyroots (p, maxsteps=100, extraprec=110)
[mpf('0.0'), mpf('4.0'), mpf('4.0'), mpf('4.0')]

The extraprec parameter means the extra number of digits to be used in the process of calculation, compared the number of digits needed in the result (which is 15 by default, set globally in mpmath.mp.dps). Its default value is 10; increasing it to 110 achieves convergence in 100 steps. This actually takes less time than trying (and failing) to find the roots with maxsteps=2000 at the default extraprec level.

The documentation says that increasing extra prec may be necessary to achieve convergence.This is your example due to root multiplicity.

The extraprec parameter means the additional digits used in the calculation and comparison process, and the number of digits required for the result. (default is 15, globally configured in mpmath.mp.dps)
The default value is 10.Increasing to 110 converges in 100 steps.
This actually takes less time than trying (and failing) to find the root at the default extraprec level on maxsteps=2000.

The mpmath document says:
The same reason is that I use Google, so it may not be accurate.

Polynominal roots(polyroots)


Computers all routes (real or complex) of a given political.

The roots are returned as a sorted list, where real roots appear first followed by complex conjugate roots as adjacent elements. The political should be given as a list of coeficants, in the format used by polyval(). The leading coeficent must be non/po>

With error=True, polyroot() returns a table(root, err) where error is an estimate of the maximum error among the computed routes.

Compute all roots (real or complex) of a given polynomial.

Roots are returned as sorted lists.The actual root is the first, followed by the complex conjugate root as an adjacency element.A polynomial should be given as a list of coefficients in the format used in polyval().The leading factor must be non-zero.

If error=True, polyroot() returns a tuple (root, err).where err is the estimate of the maximum error in the calculated root.

Precision and conditioning

The roots are computed to the current working precision accuracy. If this accuracy cannot be achieved in maxsteps steps, then a NoConvergence exception is raised. The algorithm internally is using the current working precision extended by extraprec. If NoConvergence was raised, that is caused either by not having enough extra precision to achieve convergence (in which case increasing extraprec should fix the problem) or too low maxsteps (in which case increasing maxsteps should fix the problem), or a combination of both.

The user should always do a convergence study with registers to extreme accelerate results. It is possible to get convergence to a wrong answer with too low extent.

Provided there are no repeated routes, polyroots() can typeically compute all routes of an arbitrary polynomial to high precision:

Accuracy and Conditioning

Roots are calculated with current working accuracy.If this accuracy is not achieved in the maxsteps step, a NoConvergence exception occurs.The algorithm uses the current work accuracy internally enhanced by extraprec.If NoConvergence occurs, there is not sufficient accuracy to achieve convergence (in this case, increasing extraprec solves the problem), or maxsteps is too small (in this case, increasing maxsteps solves the problem), or both combinations.

To ensure accurate results, users should always take extra prec into consideration for convergence research (research?).Too low extraprec can converge to the wrong answer.

In the absence of recurring roots, polyroots() can usually calculate all the roots of any polynomial with high accuracy.

2022-09-30 11:43

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.