K iX ddlmZddlmZddlmZGddeZGddZGd d ZGd d Z Gd dZ GddZ GddZ dZ GddZdZdZGddZGddZdZGddZeee e e e eeeeeed Zd%d!Zd&d"Zd#Zee_ee_ee_ed$k(rdd lZej6y y )')print_function)copy)xrangeceZdZdZy)OptimizationMethodscyN)ctxs b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mpmath/calculus/optimization.py__init__zOptimizationMethods.__init__s N)__name__ __module__ __qualname__rr rr rrs rrc eZdZdZdZdZdZy)Newtona] 1d-solver generating pairs of approximative root and error. Needs starting points x0 close to the root. Pro: * converges fast * sometimes more robust than secant with bad second starting point Contra: * converges slowly for multiple roots * needs first derivative * 2 function evaluations per iteration c |_t|dk(r |d_ntdt|z_d|vrfd}|_y|d}|_y)Nr!expected 1 starting point, got %idfc<jj|Sr r diffxfselfs r rzNewton.__init__..df*xx}}Q**r)r lenx0 ValueErrorrr)r r rr#kwargsrs` ` r rzNewton.__init__"sc r7a<eDG@3r7JK Kv~ +Brc#K|j}|j}|j} |||||z z }t||z }|}||f+wr )rrr#abs)r rrr#x1errors r __iter__zNewton.__iter__0s[ FF WW WWaebfn$BRLEBu+  sAANrrr__doc__maxstepsrr*r rr rrs H rrc eZdZdZdZdZdZy)Secantz 1d-solver generating pairs of approximative root and error. Needs starting points x0 and x1 close to the root. x1 defaults to x0 + 0.25. Pro: * converges fast Contra: * converges slowly for multiple roots c ||_t|dk(r&|d|_|jdz|_||_yt|dk(r|d|_|d|_||_yt dt|z)Nrr?rz'expected 1 or 2 starting points, got %i)r r"r#r(r$rr r rr#r%s r rzSecant.__init__Ksz r7a<eDGggnDG  W\eDGeDGFRPQ Qrc#K|j}|j}|j}||} ||}||z }|sy||z |z }|sy||||z z }}|}|t|f7wr )rr#r(r')r rr#r(f0f1lss r r*zSecant.__iter__Ws FF WW WW rU2BRAbA AbdBBc!f* sA%A'Nr+r rr r/r/:s H rr/c eZdZdZdZdZdZy)MNewtonat 1d-solver generating pairs of approximative root and error. Needs starting point x0 close to the root. Uses modified Newton's method that converges fast regardless of the multiplicity of the root. Pro: * converges fast for multiple roots Contra: * needs first and second derivative of f * 3 function evaluations per iteration rc |_t|dk(stdt|z|d__d|vrfdn|d_d|vrfd}|_y|d}|_y)Nrrrrc<jj|Sr rrs r rzMNewton.__init__..dfr!rd2fc<jj|Sr rrrr s r r=zMNewton.__init__..d2fxx}}R++rr r"r$r#rrr=r r rr#r%r=rs` ` @r rzMNewton.__init__{2w!|@3r7JK KQ%v~ +B ,,Crc#K|j}|j}|j}|j} |}||}|dk(ry||}||}|||||z|z z z z}t ||z } || fFw)Nrr#rrr=r' r rrrr=prevxfxdfxd2fxr)s r r*zMNewton.__iter__s GG FF WWhhE1BQwQ%Cq6D sR$Y_,- -AE NEU(NsA8A:Nr+r rr r:r:hs H&rr:c eZdZdZdZdZdZy)Halleya 1d-solver generating pairs of approximative root and error. Needs a starting point x0 close to the root. Uses Halley's method with cubic convergence rate. Pro: * converges even faster the Newton's method * useful when computing with *many* digits Contra: * needs first and second derivative of f * 3 function evaluations per iteration * converges slowly for multiple roots rc |_t|dk(stdt|z|d__d|vrfdn|d_d|vrfd}|_y|d}|_y)Nrrrrc<jj|Sr rrs r rzHalley.__init__..dfr!rr=c<jj|Sr rr?s r r=zHalley.__init__..d2fr@rrArBs` ` @r rzHalley.__init__rCrc#K|j}|j}|j}|j} |}||}||}||}|d|z|zd|dzz||zz z z}t ||z } || fIwNrrErFs r r*zHalley.__iter__s GG FF WWhhE1BQ%Cq6D !B$s(aQhD01 1AE NEU(NsA;A=Nr+r rr rLrLs$H& rrLc eZdZdZdZdZdZy)Mullera 1d-solver generating pairs of approximative root and error. Needs starting points x0, x1 and x2 close to the root. x1 defaults to x0 + 0.25; x2 to x1 + 0.25. Uses Muller's method that converges towards complex roots. Pro: * converges fast (somewhat faster than secant) * can find complex roots Contra: * converges slowly for multiple roots * may have complex values for real starting points and real roots http://en.wikipedia.org/wiki/Muller's_method r0c ||_t|dk(r3|d|_|jdz|_|jdz|_n{t|dk(r)|d|_|d|_|jdz|_nDt|dk(r|d|_|d|_|d|_nt dt|z||_|d|_y)Nrrr2rz*expected 1, 2 or 3 starting points, got %iverbose)r r"r#r(x2r$rrVr3s r rzMuller.__init__s r7a<eDGggnDGggnDG W\eDGeDGggnDG W\eDGeDGeDGI"2w'( (i( rc#\K|j}|j}|j}|j}||}||}||} ||z ||z z }||z ||z z } ||z ||z z } || z| z } | |z ||z z } | dk(r-| dk(r(|jrt dt d|d|d|y|}|}|}|}|j j| dzd|z| zz } t| | z t| | zkDr| } |d|z| | zz z}||}t||z }||fw)Nrz canceled withzx0 =z, x1 =zand x2 =r) rr#r(rWrVprintr sqrtr')r rr#r(rWfx0fx1fx2fx2x1fx2x0fx1x0wfx2x1x0rr)s r r*zMuller.__iter__sa FF WW WW WWeee3Y27+E3Y27+E3Y27+E %Au}b1GAv'Q,<</*&"hJCBCBC adQsU7]23A1q5zCAJ&B !C%1q5/ !BB%CRLEe)O1sD*D,Nr+r rr rSrSs&H)( rrSc eZdZdZdZdZdZy) Bisectiona 1d-solver generating pairs of approximative root and error. Uses bisection method to find a root of f in [a, b]. Might fail for multiple roots (needs sign change). Pro: * robust and reliable Contra: * converges slowly * needs sign change dc ||_t|dk7rtdt|z||_|d|_|d|_y)Nr%expected interval of 2 points, got %irr)r r"r$rabr3s r rzBisection.__init__4sF r7a<Ds2wNO OAArc#TK|j}|j}|j}||z }||} |jj ||zd}||}||z}|dkr|}n$|dkDr|}|}n||jj f|dz}||zdz t |fsw)Nrr)rrjrkr ldexpzeror') r rrjrkr7fbmfmsigns r r*zBisection.__iter__<s FF FF FF E qTq1ub)A1B7Dax&& FAq5!)SV# #sB&B(Nr+r rr rfrf"sH$rrfcZ|dk(rd}|S|dk(rd}|S|dk(rd}|Std|z)zE Return a function to calculate m for Illinois-like methods. illinoiscy)N?r fzrps r getmz_getm..getmUsrpegasusc|||zz Sr r rxs r rzz_getm..getmXsrBw< randersonc"d||z z }|dkDr|Sy)Nrrrwr )ryrprqs r rzz_getm..getm[sBrE A1urzmethod '%s' not recognized)r$)methodrzs r _getmrPsW  K 9   K :   K5>??rc eZdZdZdZdZdZy)Illinoisa 1d-solver generating pairs of approximative root and error. Uses Illinois method or similar to find a root of f in [a, b]. Might fail for multiple roots (needs sign change). Combines bisect with secant (improved regula falsi). The only difference between the methods is the scaling factor m, which is used to ensure convergence (you can choose one using the 'method' keyword): Illinois method ('illinois'): m = 0.5 Pegasus method ('pegasus'): m = fb/(fb + fz) Anderson-Bjoerk method ('anderson'): m = 1 - fz/fb if positive else 0.5 Pro: * converges very fast Contra: * has problems with multiple roots * needs sign change r0c f||_t|dk7rtdt|z|d|_|d|_||_|d|_|d|_|jdd|_ t|j|_ |jrtd |jzyy) NrrirrtolrVrruzusing %s method) r r"r$rjrkrrrVgetrrrzrZr3s r rzIllinois.__init__s r7a<Ds2wNO OAA%=i( jj:6 $++& << #dkk1 2 rc#K|j}|j}|j}|j}||}||}d} ||z }|dk(ry||z |z } ||| z z } || } t | |j kr|j r td| | |fy| |zdkr |}|}| }| }n|j| |}| }| }||z}|j r|r|dk(s td|||zdz t |fw)Nrzcanceled with z =ruzm:r) rrrjrkr'rrVrZrz) r rrrjrkfarprqr7r8zrys r r*zIllinois.__iter__s FF FF FF qT qT AAAvbA ABqDA1B2w!<<-q1d Bw{IIb"%rT||&J*>dAq5!)SV# #3sC?DNr+r rr rres8H 3!$rrc"d|d<t|i|S)z 1d-solver generating pairs of approximative root and error. Uses Pegasus method to find a root of f in [a, b]. Wrapper for illinois to use method='pegasus'. r{rrargsr%s r Pegasusrs!F8 T $V $$rc"d|d<t|i|S)z 1d-solver generating pairs of approximative root and error. Uses Anderson-Bjoerk method to find a root of f in [a, b]. Wrapper for illinois to use method='pegasus'. r}rrrs r Andersonrs"F8 T $V $$rc eZdZdZdZdZdZy)Riddera 1d-solver generating pairs of approximative root and error. Ridders' method to find a root of f in [a, b]. Is told to perform as well as Brent's method while being simpler. Pro: * very fast * simpler than Brent's method Contra: * two function evaluations per step * has problems with multiple roots * needs sign change http://en.wikipedia.org/wiki/Ridders'_method r0c ||_||_t|dk7rtdt|z|d|_|d|_|d|_|d|_y)NrrirrrVr)r rr"r$r(rWrVrr3s r rzRidder.__init__s] r7a<Ds2wNO OQ%Q%i( %=rc#K|j}|j}|j}||}|j}||} d||zz}||}|||z |j ||z z|z|j |dz||zz z z} || } t | |jkr+|jr td| | t ||z fy| |zdkr| }| }n| }| }t ||z } ||zdz | f­w)Nrwrzcanceled with f(x4) =r) r rr(rWrsr[r'rrVrZ) r r rr(r]rWr^x3fx3x4fx4r)s r r*zRidder.__iter__shh FF WWe WWeb2gBB%CrBw#((39"55;chhsAvPSTWPWGW>XXXBB%C3x$(("<<137#b2g,&&Sy1}RLE7A+u$ $%sDDNr+r rr rrs&H!%rrc eZdZdZdZdZdZy)ANewtonz EXPERIMENTAL 1d-solver generating pairs of approximative root and error. Uses Newton's method modified to use Steffensens method when convergence is slow. (I.e. for multiple roots.) rc |_t|dk(stdt|z|d__d|vrfdn|d_fd}|_|d_y)Nrrrrc<jj|Sr rrs r rzANewton.__init__..dfr!rc,|||z z Sr r )rrrs r phizANewton.__init__..phisqtbe|# #rrV)r r"r$r#rrrrV)r r rr#r%rrs` ` @r rzANewton.__init__sr2w!|@3r7JK KQ%v~ +B $i( rc#K|j}|j}|j}|j}d}d} |} ||}|}t||z }|r0t||z |z dkr|j r t d|dz }|dk\r$t|}d}|j r t d||f}#t$r|j r t d|YywxYww)Nrz$ZeroDivisionError: canceled with x =rzconverging slowlyrUzaccelerating convergence) r#rrrZeroDivisionErrorrVrZr' steffensen) r r#rrrr)counterrG preverrors r r*zANewton.__iter__s WW FF WWhhE W I OEUY./%7!;<<-.1 !| o<<45e)O+% <<@"E s)8CB5A2C5!CCCCNr+r rr rrs H)"rrc|j|}|j|j}|j||}t|}t|}|j||}t |D]S}|j } | |xx|z cc<|j|| |z |z } t |D] } | | || |f<U|S)z Calculate the Jacobian matrix of a function at the point x0. This is the first derivative of a vectorial function: f : R^m -> R^n with m >= n )matrixr[epsr"rr) r rrhrHrqnJjxjJjis r jacobianrCs 1 A A AqE B BA AA 1aA AY VVX 1 jjB 2% * AUAacF   Hrc eZdZdZdZdZdZy)MDNewtona Find the root of a vector function numerically using Newton's method. f is a vector function representing a nonlinear equation system. x0 is the starting point close to the root. J is a function returning the Jacobian matrix for a point. Supports overdetermined systems. Use the 'norm' keyword to specify which norm to use. Defaults to max-norm. The function to calculate the Jacobian matrix can be given using the keyword 'J'. Otherwise it will be calculated numerically. Please note that this method converges only locally. Especially for high- dimensional systems it is not trivial to find a good starting point being close enough to the root. It is recommended to use a faster, low-precision solver from SciPy [1] or OpenOpt [2] to get an initial guess. Afterwards you can use this method for root-polishing to any precision. [1] http://scipy.org [2] http://openopt.org/Welcome c |_|_t|ttfrj |}|j dk(sJd||_d|vr |d|_n fd}||_|d|_ |d|_ y)Nrz need a vectorrc(j|Sr )r)rr rs r rzMDNewton.__init__..Js||Aq))rnormrV) r r isinstancetuplelistrcolsr#rrrV)r r rr#r%rs `` r rzMDNewton.__init__xs} b5$- (BBww!|,_,| &=C[DF *DF6N i( rc#jK|j}|j}|j}|j}|jj ||}||}d}|s| }||} |jj | |} |jr"tdt| td| |jj} || z} | |k(r|jr tdd}n>|jj || }||} | |kr| }| }n| dz} || | zz} ]||f|syyw)NFzJx:zs:Tzcanceled, won't get more excactr) rr#rrr rlu_solverVrZone)r rr#rrrHfxnormcancelfxnJxr8r7r(newnorms r r*zMDNewton.__iter__s- FF WWyy FF XX__QV $b#CBB!!"c*A||e b dA AaB8||?@!FXX__QV,r(V#$FBQ!A#Xv, 7s D.D31D3Nr+r rr rrZs6H) #rr) newtonsecantmnewtonhalleymullerbisectrur{r}ridderanewtonmdnewtonNc j} xjdz c_|jdz}|jd||d<d|vr|d|d<||d<t|tt fr|D cgc]} j | }} nj |g}t|tr t|}t|tt frt|fd} | } ||} t| tt jf} d |vr|d } | rt}d |vr fd } | |d <n |d } nt} | | d k(r&| rj||_S|d |_S|||fi|}d|vr|d}n |j }d }|D]C\} }|rt#d| t#d||dz }||t%d| | zks||k\sCn|s tdt tt jfs| g}n| }|r/| ||dz|kDrtd| ||dzd|d| |_Scc} w#t$r tdwxYw#t$r||d } d } YlwxYw#|_wxYw)a4 Find an approximate solution to `f(x) = 0`, using *x0* as starting point or interval for *x*. Multidimensional overdetermined systems are supported. You can specify them using a function or a list of functions. Mathematically speaking, this function returns `x` such that `|f(x)|^2 \leq \mathrm{tol}` is true within the current working precision. If the computed value does not meet this criterion, an exception is raised. This exception can be disabled with *verify=False*. For interval arithmetic (``iv.findroot()``), please note that the returned interval ``x`` is not guaranteed to contain `f(x)=0`! It is only some `x` for which `|f(x)|^2 \leq \mathrm{tol}` certainly holds regardless of numerical error. This may be improved in the future. **Arguments** *f* one dimensional function *x0* starting point, several starting points or interval (depends on solver) *tol* the returned solution has an error smaller than this *verbose* print additional information for each iteration if true *verify* verify the solution and raise a ValueError if `|f(x)|^2 > \mathrm{tol}` *solver* a generator for *f* and *x0* returning approximative solution and error *maxsteps* after how many steps the solver will cancel *df* first derivative of *f* (used by some solvers) *d2f* second derivative of *f* (used by some solvers) *multidimensional* force multidimensional solving *J* Jacobian matrix of *f* (used by multidimensional solvers) *norm* used vector norm (used by multidimensional solvers) solver has to be callable with ``(f, x0, **kwargs)`` and return an generator yielding pairs of approximative solution and estimated error (which is expected to be positive). You can use the following string aliases: 'secant', 'mnewton', 'halley', 'muller', 'illinois', 'pegasus', 'anderson', 'ridder', 'anewton', 'bisect' See mpmath.calculus.optimization for their documentation. **Examples** The function :func:`~mpmath.findroot` locates a root of a given function using the secant method by default. A simple example use of the secant method is to compute `\pi` as the root of `\sin x` closest to `x_0 = 3`:: >>> from mpmath import * >>> mp.dps = 30; mp.pretty = True >>> findroot(sin, 3) 3.14159265358979323846264338328 The secant method can be used to find complex roots of analytic functions, although it must in that case generally be given a nonreal starting value (or else it will never leave the real line):: >>> mp.dps = 15 >>> findroot(lambda x: x**3 + 2*x + 1, j) (0.226698825758202 + 1.46771150871022j) A nice application is to compute nontrivial roots of the Riemann zeta function with many digits (good initial values are needed for convergence):: >>> mp.dps = 30 >>> findroot(zeta, 0.5+14j) (0.5 + 14.1347251417346937904572519836j) The secant method can also be used as an optimization algorithm, by passing it a derivative of a function. The following example locates the positive minimum of the gamma function:: >>> mp.dps = 20 >>> findroot(lambda x: diff(gamma, x), 1) 1.4616321449683623413 Finally, a useful application is to compute inverse functions, such as the Lambert W function which is the inverse of `w e^w`, given the first term of the solution's asymptotic expansion as the initial value. In basic cases, this gives identical results to mpmath's built-in ``lambertw`` function:: >>> def lambert(x): ... return findroot(lambda w: w*exp(w) - x, log(1+x)) ... >>> mp.dps = 15 >>> lambert(1); lambertw(1) 0.567143290409784 0.567143290409784 >>> lambert(1000); lambert(1000) 5.2496028524016 5.2496028524016 Multidimensional functions are also supported:: >>> f = [lambda x1, x2: x1**2 + x2, ... lambda x1, x2: 5*x1**2 - 3*x1 + 2*x2 - 3] >>> findroot(f, (0, 0)) [-0.618033988749895] [-0.381966011250105] >>> findroot(f, (10, 10)) [ 1.61803398874989] [-2.61803398874989] You can verify this by solving the system manually. Please note that the following (more general) syntax also works:: >>> def f(x1, x2): ... return x1**2 + x2, 5*x1**2 - 3*x1 + 2*x2 - 3 ... >>> findroot(f, (0, 0)) [-0.618033988749895] [-0.381966011250105] **Multiple roots** For multiple roots all methods of the Newtonian family (including secant) converge slowly. Consider this example:: >>> f = lambda x: (x - 1)**99 >>> findroot(f, 0.9, verify=False) 0.918073542444929 Even for a very close starting point the secant method converges very slowly. Use ``verbose=True`` to illustrate this. It is possible to modify Newton's method to make it converge regardless of the root's multiplicity:: >>> findroot(f, -10, solver='mnewton') 1.0 This variant uses the first and second derivative of the function, which is not very efficient. Alternatively you can use an experimental Newtonian solver that keeps track of the speed of convergence and accelerates it using Steffensen's method if necessary:: >>> findroot(f, -10, solver='anewton', verbose=True) x: -9.88888888888888888889 error: 0.111111111111111111111 converging slowly x: -9.77890011223344556678 error: 0.10998877665544332211 converging slowly x: -9.67002233332199662166 error: 0.108877778911448945119 converging slowly accelerating convergence x: -9.5622443299551077669 error: 0.107778003366888854764 converging slowly x: 0.99999999999999999214 error: 10.562244329955107759 x: 1.0 error: 7.8598304758094664213e-18 ZeroDivisionError: canceled with x = 1.0 1.0 **Complex roots** For complex roots it's recommended to use Muller's method as it converges even for real starting points very fast:: >>> findroot(lambda x: x**4 + x + 1, (0, 1, 2), solver='muller') (0.727136084491197 + 0.934099289460529j) **Intersection methods** When you need to find a root in a known interval, it's highly recommended to use an intersection-based solver like ``'anderson'`` or ``'ridder'``. Usually they converge faster and more reliable. They have however problems with multiple roots and usually need a sign change to find a root:: >>> findroot(lambda x: x**3, (-1, 1), solver='anderson') 0.0 Be careful with symmetric functions:: >>> findroot(lambda x: x**2, (-1, 1), solver='anderson') #doctest:+ELLIPSIS Traceback (most recent call last): ... ZeroDivisionError It fails even for better starting points, because there is no sign change:: >>> findroot(lambda x: x**2, (-1, .5), solver='anderson') Traceback (most recent call last): ... ValueError: Could not find root within given tolerance. (1.0 > 2.16840434497100886801e-19) Try another starting point or tweak arguments. rirVd1frrzcould not recognize solverc4Dcgc]}|| c}Scc}wr r )rfnf2s r tmpzfindroot..tmps,./bD ///s rFmultidimensionalrc(j|dS)Ninf)r)rr s r zfindroot..s!U!3rr-zx: zerror:rzZCould not find root using the given solver. Try another starting point or tweak arguments.rz-Could not find root within given tolerance. (z > z0) Try another starting point or tweak arguments.)precrrrrrconvertstr str2solverKeyErrorr$rr TypeErrorrr'r-rZmax)r rr#solverrrVverifyr%rrrrHrr iterationsr-rr)xlrs` @r findrootrsb 88DW B ;''E/C"JJy':y F?!%=F4Lu b4- (*,-Q#++a.-B-++b/"B fc " ?#F+ a$ 'aB 0A %BB)"tUCJJ.GH   '%&89  FV#3!%vf~D 8q=zz"~B?!u>9CB1&1  j)H!**H " SHAuh"h& FAsSDG_,,X  S "RSS!dE3::67BB d1b6lAo+!%QV a67 7S. ? !=>> ? %2a5B$  %hsoA&I<6I%I<4 I=(I<&&I A I<I<)A'I<A)I<I<II<I95I<8I99I<< Jc |jdz}|d<t|D];dtzdz}||vr||}nfd}t|||kr:SS)a Return the multiplicity of a given root of f. Internally, numerical derivatives are used. This might be inefficient for higher order derviatives. Due to this, ``multiplicity`` cancels after evaluating 10 derivatives by default. You can be specify the n-th derivative using the dnf keyword. >>> from mpmath import * >>> multiplicity(lambda x: sin(x) - 1, pi/2) 2 g?d0fdrc*j|Sr )r)rr rrs r rzmultiplicity..s388Aq!,r)rrrr') r rrootrr-r%dfstrrrs `` @r multiplicityrsz {ggnF5M H c!f s" F?B,B2d8}s"  H Hrcfd}|S)a linear convergent function -> quadratic convergent function Steffensen's method for quadratic convergence of a linear converging sequence. Don not use it for higher rates of convergence. It may even work for divergent sequences. Definition: F(x) = (x*f(f(x)) - f(x)**2) / (f(f(x)) - 2*f(x) + x) Example ....... You can use Steffensen's method to accelerate a fixpoint iteration of linear (or less) convergence. x* is a fixpoint of the iteration x_{k+1} = phi(x_k) if x* = phi(x*). For phi(x) = x**2 there are two fixpoints: 0 and 1. Let's try Steffensen's method: >>> f = lambda x: x**2 >>> from mpmath.calculus.optimization import steffensen >>> F = steffensen(f) >>> for x in [0.5, 0.9, 2.0]: ... fx = Fx = x ... for i in xrange(9): ... try: ... fx = f(fx) ... except OverflowError: ... pass ... try: ... Fx = F(Fx) ... except ZeroDivisionError: ... pass ... print('%20g %20g' % (fx, Fx)) 0.25 -0.5 0.0625 0.1 0.00390625 -0.0011236 1.52588e-05 1.41691e-09 2.32831e-10 -2.84465e-27 5.42101e-20 2.30189e-80 2.93874e-39 -1.2197e-239 8.63617e-78 0 7.45834e-155 0 0.81 1.02676 0.6561 1.00134 0.430467 1 0.185302 1 0.0343368 1 0.00117902 1 1.39008e-06 1 1.93233e-12 1 3.73392e-24 1 4 1.6 16 1.2962 256 1.10194 65536 1.01659 4.29497e+09 1.00053 1.84467e+19 1 3.40282e+38 1 1.15792e+77 1 1.34078e+154 1 Unmodified, the iteration converges only towards 0. Modified it converges not only much faster, it converges even to the repelling fixpoint 1. cR|}|}||z|dzz |d|zz |zz SrQr )rrHffxrs r Fzsteffensen..FBs8 qTe#A #"*q.11rr )rrs` r rrsJ2 Hr__main__)rNFT)Nr) __future__rr libmp.backendrobjectrrr/r:rLrSrfrrrrrrrrrrrrrdoctesttestmodr rr rs%" & ))V,,\55n44lJJZ,$,$\*N$N$`%%9%9%v66| .QQn'!WXG iX  6I V ('#/  zGOOr