+
    ‰°³jEr  ã                   óú  € R t ^RIHt ^RIHtHt R t ! R R]4      tRGR	 lt	RHR
 lt
R tR tR tR tR R^ 3R R^3R R^ 3R R^ 3R R^3R R^ 3R R^3R R^3R R ^3R! R"^ 3R# R$^3R% R&^ 3R' R(^3R) R*^3R+ R,^3R- R.^ 3R/ R0^3R1 R2^ 3R3 R4^3R5 R6^3R7 R8^ 3R9 R:^ 3R; R<^3R= R>^ 3R? R@^3RA RB^3RC RD^ 3.t. RRRR3RE lt]	]n	        ]
]n
        ]]n        ]RF8X  d   ^ RIt]P&                  ! 4        R# R# )Izs
Implements the PSLQ algorithm for integer relation detection,
and derivative algorithms for constant recognition.
)Úxrange)Ú	int_typesÚ
sqrt_fixedc                 óL   € V ^V^,
          ,          ,           V,	          V,          # ©é   © )ÚxÚprecs   &&ÚV/home/luca/screen-checking/.venv/lib/python3.14/site-packages/mpmath/identification.pyÚround_fixedr   
   s   € Ø�!�d˜1•f•+Õ 4Õ'¨DÕ0Ð0ó    c                   ó   € ] tR t^tRtR# )ÚIdentificationMethodsr   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   r   r   r   r      s   † Ûr   r   Néè  Fc                óô  € \        V4      pV^8  d   \        R4      hV P                  pV^58  d   \        R4      hV'       d$   V\        ^V4      ,          ^8  d   \	        R4       \        VR,          4      pVf   V P                  ^4      V) ,          pMV P                  V4      p^<p	Wy,          pV'       d#   \	        RWpP                  V4      3,          4       V P                  W'4      pV'       g   Q hR.V U
u. uF#  q P                  V P                  V
4      V4      NK%  	  up
,           p\        R VR,           4       4      pV'       g   \        R	4      hW²^d,          8  d   V'       d   \	        R
4       R# \        ^V,          ^,          V4      p/ p/ p/ p\        ^V^,           4       F<  p\        ^V^,           4       F"  pVV8H  V,          ;VVV3&   VVV3&   ^ VVV3&   K$  	  K>  	  R.^ .V,          ,           p\        ^V^,           4       FL  p^ p\        VV^,           4       F!  pVVV,          ^,          V,	          ,          pK#  	  \        VV4      VV&   KN  	  V^,          pVR,          p\        ^V^,           4       F7  pVV,          V,          V,          VV&   VV,          V,          V,          VV&   K9  	  \        ^V^,           4       Fà  p\        V^,           V4       F
  p^ VVV3&   K  	  VV^,
          8:  dB   VV,          '       d,   VV^,           ,          V,          VV,          ,          VVV3&   M^ VVV3&   \        ^V4       F]  pVV,          VV^,           ,          ,          pV'       d.   VV,          ) VV,          ,          V,          V,          VVV3&   KV  ^ VVV3&   K_  	  Kâ  	  \        ^V^,           4       EFG  p\        V^,
          ^ R4       EF*  pVVV3,          '       d.   \        VVV3,          V,          VVV3,          ,          V4      pMKD  VV,          VVV,          ,          V,	          ,           VV&   \        ^V^,           4       F1  pVVV3,          VVVV3,          ,          V,	          ,
          VVV3&   K3  	  \        ^V^,           4       F_  pVVV3,          VVVV3,          ,          V,	          ,
          VVV3&   VVV3,          VVVV3,          ,          V,	          ,           VVV3&   Ka  	  EK-  	  EKJ  	  \        V4       EF�  pRpRp\        ^V4       FI  pVVV3,          pVV,          \        V4      ,          VV^,
          ,          ,	          pVV8”  g   KE  TpTpKK  	  VV^,           ,          VV,          uVV&   VV^,           &   \        ^V^,           4       F2  pVV^,           V3,          VVV3,          uVVV3&   VV^,           V3&   K4  	  \        ^V^,           4       F2  pVV^,           V3,          VVV3,          uVVV3&   VV^,           V3&   K4  	  \        ^V^,           4       F2  pVVV^,           3,          VVV3,          uVVV3&   VVV^,           3&   K4  	  VV^,
          8:  Ed   \        VVV3,          ^,          VVV^,           3,          ^,          ,           V,	          V4      pV'       g    EMÈVVV3,          V,          V,          pVVV^,           3,          V,          V,          p\        VV^,           4       Fn  pVVV3,          pVVV^,           3,          p VV,          VV ,          ,           V,	          VVV3&   V) V,          VV ,          ,           V,	          VVV^,           3&   Kp  	  \        V^,           V^,           4       EFE  p\        \        V^,
          V^,           4      ^ R4       EF  p \        VVV3,          V,          VVV3,          ,          V4      pTT,          TTT,          ,          T,	          ,           TT&   \        ^T^,           4       F1  pTTT3,          TTTT3,          ,          T,	          ,
          TTT3&   K3  	  \        ^T^,           4       F_  pTTT3,          TTTT3,          ,          T,	          ,
          TTT3&   TTT3,          TTTT3,          ,          T,	          ,           TTT3&   Ka  	  EK  	  EKH  	  W7,          p!\        ^V^,           4       FÓ  p\        VV,          4      p"V"V8  d¬   \        ^V^,           4       Uu. uF(  p\        \        VVV3,          V4      V,	          4      NK*  	  p#p\        R V# 4       4      V8  dP   V'       dB   \	        RVW@P                  V"V P                  ^4      V,          ,          ^4      3,          4       V#u u # \        V"V!4      p!KÕ  	  \        R VP#                  4        4       4      p$V$'       d)   ^^V,          ,          V$,          V,	          p%V%^d,          p%MV P$                  p%V'       dC   \	        RVW@P                  V!V P                  ^4      V,          ,          ^4      V%3,          4       V%V8¼  g   EK‚   M	  V'       d'   \	        RXV3,          4       \	        RX%,          4       R# u up
i   \          d      EK5  i ; iu upi )az  
Given a vector of real numbers `x = [x_0, x_1, ..., x_n]`, ``pslq(x)``
uses the PSLQ algorithm to find a list of integers
`[c_0, c_1, ..., c_n]` such that

.. math ::

    |c_1 x_1 + c_2 x_2 + ... + c_n x_n| < \mathrm{tol}

and such that `\max |c_k| < \mathrm{maxcoeff}`. If no such vector
exists, :func:`~mpmath.pslq` returns ``None``. The tolerance defaults to
3/4 of the working precision.

**Examples**

Find rational approximations for `\pi`::

    >>> from mpmath import *
    >>> mp.dps = 15; mp.pretty = True
    >>> pslq([-1, pi], tol=0.01)
    [22, 7]
    >>> pslq([-1, pi], tol=0.001)
    [355, 113]
    >>> mpf(22)/7; mpf(355)/113; +pi
    3.14285714285714
    3.14159292035398
    3.14159265358979

Pi is not a rational number with denominator less than 1000::

    >>> pslq([-1, pi])
    >>>

To within the standard precision, it can however be approximated
by at least one rational number with denominator less than `10^{12}`::

    >>> p, q = pslq([-1, pi], maxcoeff=10**12)
    >>> print(p); print(q)
    238410049439
    75888275702
    >>> mpf(p)/q
    3.14159265358979

The PSLQ algorithm can be applied to long vectors. For example,
we can investigate the rational (in)dependence of integer square
roots::

    >>> mp.dps = 30
    >>> pslq([sqrt(n) for n in range(2, 5+1)])
    >>>
    >>> pslq([sqrt(n) for n in range(2, 6+1)])
    >>>
    >>> pslq([sqrt(n) for n in range(2, 8+1)])
    [2, 0, 0, 0, 0, 0, -1]

**Machin formulas**

A famous formula for `\pi` is Machin's,

.. math ::

    \frac{\pi}{4} = 4 \operatorname{acot} 5 - \operatorname{acot} 239

There are actually infinitely many formulas of this type. Two
others are

.. math ::

    \frac{\pi}{4} = \operatorname{acot} 1

    \frac{\pi}{4} = 12 \operatorname{acot} 49 + 32 \operatorname{acot} 57
        + 5 \operatorname{acot} 239 + 12 \operatorname{acot} 110443

We can easily verify the formulas using the PSLQ algorithm::

    >>> mp.dps = 30
    >>> pslq([pi/4, acot(1)])
    [1, -1]
    >>> pslq([pi/4, acot(5), acot(239)])
    [1, -4, 1]
    >>> pslq([pi/4, acot(49), acot(57), acot(239), acot(110443)])
    [1, -12, -32, 5, -12]

We could try to generate a custom Machin-like formula by running
the PSLQ algorithm with a few inverse cotangent values, for example
acot(2), acot(3) ... acot(10). Unfortunately, there is a linear
dependence among these values, resulting in only that dependence
being detected, with a zero coefficient for `\pi`::

    >>> pslq([pi] + [acot(n) for n in range(2,11)])
    [0, 1, -1, 0, 0, 0, -1, 0, 0, 0]

We get better luck by removing linearly dependent terms::

    >>> pslq([pi] + [acot(n) for n in range(2,11) if n not in (3, 5)])
    [1, -8, 0, 0, 4, 0, 0, 0]

In other words, we found the following formula::

    >>> 8*acot(2) - 4*acot(7)
    3.14159265358979323846264338328
    >>> +pi
    3.14159265358979323846264338328

**Algorithm**

This is a fairly direct translation to Python of the pseudocode given by
David Bailey, "The PSLQ Integer Relation Algorithm":
http://www.cecm.sfu.ca/organics/papers/bailey/paper/html/node3.html

The present implementation uses fixed-point instead of floating-point
arithmetic, since this is significantly (about 7x) faster.
zn cannot be less than 2zprec cannot be less than 53z*Warning: precision for PSLQ may be too lowg      è?NzPSLQ using prec %i and tol %sc              3   ó8   "  € T F  p\        V4      x € K  	  R # 5i©N©Úabs)Ú.0Úxxs   & r   Ú	<genexpr>Úpslq.<locals>.<genexpr>§   s   é € Ð'¡˜2Œs�2�wˆw£ùó   ‚ºr   NNz)PSLQ requires a vector of nonzero numbersz#STOPPING: (one number is too small):NNNc              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir   r   )r   Úvs   & r   r   r     s   é € Ð+¡s !”s˜1—v�v£sùr   z'FOUND relation at iter %i/%i, error: %sc              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir   r   )r   Úhs   & r   r   r   '  s   é € Ð1¡j ”c˜!—f�f£jùr   z%i/%i:  Error: %8s   Norm: %szCANCELLING after step %i/%i.z2Could not find an integer relation. Norm bound: %séÿÿÿÿ)ÚlenÚ
ValueErrorr
   ÚmaxÚprintÚintÚmpfÚconvertÚnstrÚto_fixedÚminr   r   Úranger   r   ÚZeroDivisionErrorÚvaluesÚinf)&Úctxr	   ÚtolÚmaxcoeffÚmaxstepsÚverboseÚnr
   ÚtargetÚextraÚxkÚminxÚgÚAÚBÚHÚiÚjÚsÚkÚtÚyÚsjj1ÚREPÚmÚszmaxr$   ÚszÚt0Út1Út2Út3Út4Úbest_errÚerrÚvecÚrecnormÚnorms&   &&&&&&                                r   ÚpslqrW      s‹	  € ôf 	ˆA‹€AØˆ1„uÜÐ2Ó3Ð3ð �8‰8€DØˆb„yÜÐ6Ó7Ð7ç�4œ3˜q ›8Õ# aÔ'ÜÐ:Ô;ä�˜•Ó€Fà
‚{Ø�g‰g�a‹j˜F˜7Õ#‰à�k‰k˜#Óˆà€EØ…M€DçÜÐ-°·x±xÀ³}Ð0EÕEÔFà
�,‰,�sÓ
!€Cß€Jˆ3ð 
ˆ¹AÓ>¹A°b—,‘,˜sŸw™w r›{¨DÖ1¹AÑ>Õ>€Aô Ñ'  2¦Ó'Ó'€DßÜÐDÓEÐEØ�3�h„ßÜÐ7Ô8Ùä�A�t•G˜a•< Ó&€AØ
€AØ
€AØ
€Aô �A�q˜•sŽ^ˆÜ˜˜1˜Q�3–ˆAØ  !™t¨�nÐ,ˆAˆa�ˆc‰F�Q�q˜�s‘VØˆAˆa�ˆc‹Fó  ñ ð
 
ˆ�!��q•Õ€AÜ�A�q˜•sŽ^ˆØˆÜ˜˜1˜Q�3–ˆAØ�!�A•$˜•'˜T•/Õ"ŠAñ  ä˜!˜TÓ"ˆˆ!‹ñ	 ð
 	
ˆ!�€AØ	ˆ!�€AÜ�A�q˜•sŽ^ˆØ�!•˜• Õ"ˆˆ!‰Ø�!•˜• Õ"ˆˆ!‹ñ ô �A�q˜•sŽ^ˆÜ˜˜!�˜Q–ˆAØˆAˆa�ˆc‹Fñ  à��!•Œ8Ø��tŒtØ˜A˜a�C�& D�.¨Q¨q­TÕ1��!�A�#’à��!�A�#‘Ü�q˜!–ˆAØ�Q•4˜˜!˜A�#�•;ˆDßØ˜a�D˜5  1¥�:¨Õ,¨tÕ3��!�A�#“à��!�A�#“ó ñ ô �A�q˜•s�^ˆÜ˜˜!�˜Q ×#ˆAà��1��vŒvÜ  1 Q 3¥¨4¥°!°A°a°Cµ&Õ 8¸$Ó?‘ñ Ø�Q•4˜1˜Q˜q�T�6 T�>Õ*ˆAˆa‰DÜ˜A˜q �s–^�Ø˜1˜Q˜3� 1 Q q¨ s¥V¥8¨tÕ#3Õ4��!�A�#“ñ $ä˜A˜q �s–^�Ø˜1˜Q˜3� 1 Q q¨ s¥V¥8¨tÕ#3Õ4��!�A�#‘Ø˜1˜Q˜3� 1 Q q¨ s¥V¥8¨tÕ#3Õ4��!�A�#“ô $ô $ñ ô �X�ˆàˆØˆÜ�q˜!–ˆAØ�!�A�#•ˆAØ�Q•$œ˜Q›•- T¨1¨Q­3¥ZÕ0ˆBØ�EŽzØ�Ø’ñ ð ˜˜1�•v˜q �tˆˆˆ!‰ˆa��!•‰fÜ˜˜!˜A�#–ˆA°1°Q°qµS¸°Uµ8¸Q¸qÀ¸s½VÐ 0  ! A #¡¨¨!¨A­#¨a¨%«‘Ü˜˜!˜A�#–ˆA°1°Q°qµS¸°Uµ8¸Q¸qÀ¸s½VÐ 0  ! A #¡¨¨!¨A­#¨a¨%«‘Ü˜˜!˜A�#–ˆA°1°Q°q¸µs°Uµ8¸Q¸qÀ¸s½VÐ 0  ! A #¡¨¨!¨A¨a­C¨%«‘à��A•�:Ü˜Q˜q ˜s�V Q�Y¨¨1¨Q¨q­S¨5­°1­Õ4°tÕ;¸TÓBˆB÷ ÚØ�A�a�C•&˜D•. RÕ'ˆBØ�A�a˜•c�E•(˜dÕ" rÕ)ˆBÜ˜A˜q �s–^�Ø�q˜�s•V�Ø�q˜˜1��u•X�Ø˜R�%  2¥�+¨$Õ.��!�A�#‘Ø˜C �F 2 b¥5�L¨TÕ1��!�A�a•C�%“ñ	 $ô ˜˜!�˜Q˜q�S×!ˆAÜœC  !¥ Q q¥S›M¨1¨b×1�ðÜ# Q q¨ s¥V¨t¥^°a¸¸!¸µfÕ$<¸dÓC�Að ˜•t  ! A¥$¥¨4Õ/Õ0��!‘Ü  1 Q¥3ž�AØ˜q ˜s�V q¨¨1¨Q¨3­¥x°4Õ'7Õ8�A�a˜�c“Fñ (ä  1 Q¥3ž�AØ˜q ˜s�V q¨¨1¨Q¨3­¥x°4Õ'7Õ8�A�a˜�c‘FØ˜q ˜s�V q¨¨1¨Q¨3­¥x°4Õ'7Õ8�A�a˜�c“Fô (ô 2ñ "ð& •>ˆÜ˜˜1˜Q�3–ˆAÜ�a˜•d“)ˆCà�SŒyô �a˜˜!�”óÙð CD”sœ; q¨¨1¨¥v¨tÓ4¸Õ<Ö=Ùð ð äÑ+¡sÓ+Ó+¨hÔ6ßÜÐGØ  (¯H©H°S¸3¿7¹7À1»:ÀtÕ;KÕ5KÈQÓ,OÐPõQô Rà”JÜ˜3 Ó)ŠHñ  ô  Ñ1 a§h¡h¤jÓ1Ó1ˆßØ˜1˜T�6•] wÕ.°4Õ7ˆDØ�S�L‰Dà—7‘7ˆDßÜÐ1Ø�h§¡¨°C·G±G¸A³JÀÕ4DÕ)DÀaÓ HÈ$ÐOõPô Qà�8×Ùñ[ ÷\ ÜÐ,°°X¨Õ>Ô?ÜÐBÀTÕIÔJÙùòc ?øôH )ô Üðüò(s   Ã=)kß*,k!å.k5ë!k2	ë1k2	c                ó2  € V P                  V4      pV^8  d   \        R4      hV^ 8X  d   ^^ .# V P                  ^4      .p\        ^V^,           4       F?  pVP                  W,          4       V P                  ! V3/ VB pVf   K3  VRRR1,          u # 	  R# )a¹  
``findpoly(x, n)`` returns the coefficients of an integer
polynomial `P` of degree at most `n` such that `P(x) \approx 0`.
If no polynomial having `x` as a root can be found,
:func:`~mpmath.findpoly` returns ``None``.

:func:`~mpmath.findpoly` works by successively calling :func:`~mpmath.pslq` with
the vectors `[1, x]`, `[1, x, x^2]`, `[1, x, x^2, x^3]`, ...,
`[1, x, x^2, .., x^n]` as input. Keyword arguments given to
:func:`~mpmath.findpoly` are forwarded verbatim to :func:`~mpmath.pslq`. In
particular, you can specify a tolerance for `P(x)` with ``tol``
and a maximum permitted coefficient size with ``maxcoeff``.

For large values of `n`, it is recommended to run :func:`~mpmath.findpoly`
at high precision; preferably 50 digits or more.

**Examples**

By default (degree `n = 1`), :func:`~mpmath.findpoly` simply finds a linear
polynomial with a rational root::

    >>> from mpmath import *
    >>> mp.dps = 15; mp.pretty = True
    >>> findpoly(0.7)
    [-10, 7]

The generated coefficient list is valid input to ``polyval`` and
``polyroots``::

    >>> nprint(polyval(findpoly(phi, 2), phi), 1)
    -2.0e-16
    >>> for r in polyroots(findpoly(phi, 2)):
    ...     print(r)
    ...
    -0.618033988749895
    1.61803398874989

Numbers of the form `m + n \sqrt p` for integers `(m, n, p)` are
solutions to quadratic equations. As we find here, `1+\sqrt 2`
is a root of the polynomial `x^2 - 2x - 1`::

    >>> findpoly(1+sqrt(2), 2)
    [1, -2, -1]
    >>> findroot(lambda x: x**2 - 2*x - 1, 1)
    2.4142135623731

Despite only containing square roots, the following number results
in a polynomial of degree 4::

    >>> findpoly(sqrt(2)+sqrt(3), 4)
    [1, 0, -10, 0, 1]

In fact, `x^4 - 10x^2 + 1` is the *minimal polynomial* of
`r = \sqrt 2 + \sqrt 3`, meaning that a rational polynomial of
lower degree having `r` as a root does not exist. Given sufficient
precision, :func:`~mpmath.findpoly` will usually find the correct
minimal polynomial of a given algebraic number.

**Non-algebraic numbers**

If :func:`~mpmath.findpoly` fails to find a polynomial with given
coefficient size and tolerance constraints, that means no such
polynomial exists.

We can verify that `\pi` is not an algebraic number of degree 3 with
coefficients less than 1000::

    >>> mp.dps = 15
    >>> findpoly(pi, 3)
    >>>

It is always possible to find an algebraic approximation of a number
using one (or several) of the following methods:

    1. Increasing the permitted degree
    2. Allowing larger coefficients
    3. Reducing the tolerance

One example of each method is shown below::

    >>> mp.dps = 15
    >>> findpoly(pi, 4)
    [95, -545, 863, -183, -298]
    >>> findpoly(pi, 3, maxcoeff=10000)
    [836, -1734, -2658, -457]
    >>> findpoly(pi, 3, tol=1e-7)
    [-4, 22, -29, -2]

It is unknown whether Euler's constant is transcendental (or even
irrational). We can use :func:`~mpmath.findpoly` to check that if is
an algebraic number, its minimal polynomial must have degree
at least 7 and a coefficient of magnitude at least 1000000::

    >>> mp.dps = 200
    >>> findpoly(euler, 6, maxcoeff=10**6, tol=1e-100, maxsteps=1000)
    >>>

Note that the high precision and strict tolerance is necessary
for such high-degree runs, since otherwise unwanted low-accuracy
approximations will be detected. It may also be necessary to set
maxsteps high to prevent a premature exit (before the coefficient
bound has been reached). Running with ``verbose=True`` to get an
idea what is happening can be useful.
zn cannot be less than 1Nr%   )r+   r'   r0   ÚappendrW   )r4   r	   r9   ÚkwargsÚxsrB   Úas   &&&,   r   Úfindpolyr]   7  sŠ   € ðR 	�‰�‹
€AØˆ1„uÜÐ2Ó3Ð3ØˆA„vØ�1ˆvˆØ
�'‰'�!‹*ˆ€BÜ�1�Q�q•SŽ\ˆØ
�	‰	�!•$ŒØ�HŠH�RÑ"˜6Ñ"ˆØŒ=Ø‘T�r�T•7ŠNó	 r   c                 ór   € Yr2V'       d   Y2V,          r2K  V^8w  d   W,          p W,          pV^8X  d   V # W3# r   r   )ÚpÚqr	   rG   s   &&  r   Úfracgcdra   ¬  s;   € Ø€qß
Ø�a•%Š1ØˆA„vØ	�ˆØ	�ˆØˆA„vØˆØˆ4€Kr   c                 ó  € V ^ ,          pV R,          p . p\        \        V 4      4       F¦  pW,          pV'       g   K  \        V) V4      pW,          ^,          pVR8X  d   RpM	RV,           p\        V\        4      '       d,   V^ 8”  d   \        V4      V,           pM!RV,          V,           pMRV,          V,           pVP                  V4       K¨  	  RP                  V4      pRV9   g   RV9   d   R	V,           R
,           pT;'       g    R# )é    r    Ú1Ú Ú*z(%s)z(%s/%s)z + Ú+Ú(Ú)Ú0)r0   r&   ra   Ú
isinstancer   ÚstrrY   Újoin)	ÚrÚ	constantsr`   rD   rB   r_   ÚzÚcsÚterms	   &&       r   Ú
pslqstringrs   ·  sß   € Ø	ˆ!�€AØ	ˆ"�€AØ
€AÜ”3�q“6Ž]ˆØ�Dˆß‰1Ü˜˜˜1“ˆAØ•˜a•ˆBØ�SŒyØ‘à˜2•X�Ü˜!œY×'Ò'Ø�q”5¤ Q£¨"¥™$Ø"(¨1¥*°Õ!2™$à! A�¨Õ+�Ø�H‰H�TŽNñ ð 	�
‰
�1‹€AØ
ˆa„x�3˜!”8Ø�!�G�c�MˆØ�8ˆ8�€Or   c                 ó¶  € V ^ ,          pV R,          p . p. p\        \        V 4      4       FÒ  pW,          pV'       g   K  \        V) V4      pW,          ^,          p\        V\        4      '       dD   \        V4      ^8X  d   Tp	MV: R\        V4      : 2p	W4.V^ 8  ,          P                  V	4       KŠ  V: R\        V^ ,          4      : RV^,          : R2p	W4.V^ ,          ^ 8  ,          P                  V	4       KÔ  	  RP                  V4      pRP                  V4      pV'       d   V'       d   RV: RV: R2# V'       d   V# V'       d
   R	V,          # R
# )rc   r    z**z**(Ú/ri   rf   rh   z)/(z1/(%s)N)r0   r&   ra   rk   r   r   rY   rm   )
rn   ro   r`   ÚnumÚdenrB   r_   rp   rq   rF   s
   &&        r   Ú
prodstringrx   Ï  s  € Ø	ˆ!�€AØ	ˆ"�€AØ
€CØ
€CÜ”3�q“6Ž]ˆØ�Dˆß‰1Ü˜˜˜1“ˆAØ•˜a•ˆBÜ˜!œY×'Ò'Ü�q“6˜Q”; B¡Û02´C¸µFÐ$; Ø�˜1˜Q™3•×'Ñ'¨Ö*ã%'¬¨Q¨q­T®°A°a·D°DÐ9�Ø�˜1˜Q�4 ™6Õ"×*Ñ*¨1Ö-ñ ð �(‰(�3‹-€CØ
�(‰(�3‹-€Cß
�sˆs«#«sÐ3Ð3ß
�3ˆJß
�8˜c•>Ð!�sr   c                 óô  € V^ 8  d	   V) V) V) rCpV) V P                  V^,          ^V,          V,          ,
          4      ,           ^V,          ,          pV) V P                  V^,          ^V,          V,          ,
          4      ,
          ^V,          ,          p\        WQ,
          4      \        Wa,
          4      8  da   V'       d6   RV) : RV^,          ^V,          V,          ,
          : R^V,          : R2pV# RR	V,          V,          : R^V,          : R2p V# V'       d6   RV) : RV^,          ^V,          V,          ,
          : R^V,          : R2pV# RR	V,          V,          : R^V,          : R2pV# )
rc   z((z+sqrt(z))/ri   z(sqrt(z)/z-sqrt(z(-sqrt(éüÿÿÿ)Úsqrtr   )r4   rF   r\   ÚbÚcÚu1Úu2rD   s   &&&&&   r   Úquadraticstringr€   æ  s6  € Øˆ1„uØ��A�2�q�bˆAˆØˆ"ˆS�X‰X�a˜•d˜1˜Q�3˜q�5•jÓ!Õ
! A a¥CÕ	(€BØˆ"ˆS�X‰X�a˜•d˜1˜Q�3˜q�5•jÓ!Õ
! A a¥CÕ	(€BÜ
ˆ2�4ƒy”3�r•t“9Ôßˆ1¨A«2¨a°­d°1°Qµ3°qµ5¯j¨j¸¸1¿¸Ð=ˆqð
 €Hð Ø&(¨¥d¨1§f f¨Q¨q¯S¨SÐ1‰qð €H÷ ˆ1¨A«2¨a°­d°1°Qµ3°qµ5¯j¨j¸¸1¿¸Ð=ˆqà€Hð Ø')¨!¥t¨A§v v¨a°¯c¨cÐ2ˆqØ€Hr   c                 ó   € W,          # r   r   ©r4   r	   r}   s   &&&r   Ú<lambda>rƒ   ÷  ó   € �1–3r   z$y/$cc                 ó   € W,          # r   r   r‚   s   &&&r   rƒ   rƒ   ø  r„   r   z$c*$yc                 ó   € W!,          # r   r   r‚   s   &&&r   rƒ   rƒ   ù  r„   r   z$c/$yc                 ó    € W,          ^,          # ©é   r   r‚   s   &&&r   rƒ   rƒ   ú  ó
   € �A•C˜!–8r   zsqrt($y)/$cc                 ó    € W,          ^,          # rˆ   r   r‚   s   &&&r   rƒ   rƒ   û  rŠ   r   z$c*sqrt($y)c                 ó    € W!,          ^,          # rˆ   r   r‚   s   &&&r   rƒ   rƒ   ü  rŠ   r   z$c/sqrt($y)c                 ó    € W!^,          ,          # rˆ   r   r‚   s   &&&r   rƒ   rƒ   ý  ó
   € �1˜•T–6r   zsqrt($y)/sqrt($c)c                 ó"   € V^,          V,          # rˆ   r   r‚   s   &&&r   rƒ   rƒ   þ  s   € �1�a•4˜–6r   zsqrt($c)*sqrt($y)c                 ó    € W!^,          ,          # rˆ   r   r‚   s   &&&r   rƒ   rƒ   ÿ  rŽ   r   zsqrt($c)/sqrt($y)c                 ó0   € V P                  W,          4      # r   ©r{   r‚   s   &&&r   rƒ   rƒ      ó   € �3—8‘8˜A�C”=r   z$y**2/$cc                 ó0   € V P                  W,          4      # r   r’   r‚   s   &&&r   rƒ   rƒ     r“   r   z$c*$y**2c                 ó0   € V P                  W!,          4      # r   r’   r‚   s   &&&r   rƒ   rƒ     r“   r   z$c/$y**2c                 ó0   € W P                  V4      ,          # r   r’   r‚   s   &&&r   rƒ   rƒ     ó   € �1—X‘X˜a“[–=r   z$y**2/$c**2c                 ó2   € V P                  V4      V,          # r   r’   r‚   s   &&&r   rƒ   rƒ     s   € �3—8‘8˜A“;˜q–=r   z$c**2*$y**2c                 ó0   € W P                  V4      ,          # r   r’   r‚   s   &&&r   rƒ   rƒ     r—   r   z$c**2/$y**2c                 ó0   € V P                  W,          4      # r   ©Úexpr‚   s   &&&r   rƒ   rƒ     ó   € �3—7‘7˜1�3”<r   z
log($y)/$cc                 ó0   € V P                  W,          4      # r   r›   r‚   s   &&&r   rƒ   rƒ     r�   r   z
$c*log($y)c                 ó0   € V P                  W!,          4      # r   r›   r‚   s   &&&r   rƒ   rƒ     r�   r   z
$c/log($y)c                 ó0   € W P                  V4      ,          # r   r›   r‚   s   &&&r   rƒ   rƒ   	  ó   € �1—W‘W˜Q“Z–<r   z
log($y/$c)c                 ó2   € V P                  V4      V,          # r   r›   r‚   s   &&&r   rƒ   rƒ   
  s   € �3—7‘7˜1“:˜a–<r   z
log($c*$y)c                 ó0   € W P                  V4      ,          # r   r›   r‚   s   &&&r   rƒ   rƒ     r¡   r   z
log($c/$y)c                 ó0   € V P                  W,          4      # r   ©Úlnr‚   s   &&&r   rƒ   rƒ     ó   € �3—6‘6˜!�#”;r   z
exp($y)/$cc                 ó0   € V P                  W,          4      # r   r¥   r‚   s   &&&r   rƒ   rƒ     r§   r   z
$c*exp($y)c                 ó0   € V P                  W!,          4      # r   r¥   r‚   s   &&&r   rƒ   rƒ     r§   r   z
$c/exp($y)c                 ó0   € W P                  V4      ,          # r   r¥   r‚   s   &&&r   rƒ   rƒ     ó   € �1—V‘V˜A“Y–;r   z
exp($y/$c)c                 ó2   € V P                  V4      V,          # r   r¥   r‚   s   &&&r   rƒ   rƒ     s   € �3—6‘6˜!“9˜Q–;r   z
exp($c*$y)c                 ó0   € W P                  V4      ,          # r   r¥   r‚   s   &&&r   rƒ   rƒ     r«   r   z
exp($c/$y)c           
     ó~	  a aaa€ . oVV3R lpS P                  V4      pV^ 8X  d   V'       d   R.# R# V^ 8  dF   S P                  V) W#WES4      pVf   V# V'       d   V U	u. uF  p	RV	,          NK  	  up	# RV,          # V'       d   S P                  V4      pMS P                  R,          pTp
V'       d�   \        V\        4      '       d?   \        VP                  4       4       UUu. uF  w  r¼S P                  V4      V3NK  	  pppM=\	        V 3R l\        S 4       4       4      pV Uu. uF  p\        Wí4      V3NK  	  ppM. p^V UUu. uF  w  r¿VNK	  	  upp9  d   S P                  ^4      R3.V,           p\         EFÝ  w  pppV EFÎ  w  ppV'       d
   VR8X  d   K  V! S VV4      p\        V4      V
^,          8”  g   \        V4      V8  d   KK  S P                  V.V Uu. uF  pV^ ,          NK  	  up,           W:4      pRp	Ve4   \        R V 4       4      V
8:  d   V^ ,          '       d   \        VV4      p	M‹S P                  S P                  VV^,          .W:4      pVeb   \        V4      ^8X  dR   V^,          '       dC   Vw  ppp\        \        V4      \        V4      \        V4      4      V
8:  d   \!        S VVVV4      p	V	'       dq   VR8X  d+   R	V9   d$   VP#                  R
V	4      P#                  R	R4      p	M"VP#                  R
V	4      P#                  RV4      p	V! V	4       V'       g   S^ ,          u u # S'       g   EKÃ  \%        R4       EKÑ  	  EKà  	  V^8w  Ed   . ROp. pV FF  w  op	\'        VV 3R lV 4       4      '       d   K$  VP)                  S P+                  S4      V	34       KH  	  V Uu. uF  pS P+                  V4      \-        V4      3NK!  	  upV,           pS P                  S P+                  V4      .V Uu. uF  pV^ ,          NK  	  up,           W:4      pVeJ   \        R V 4       4      V
8:  d3   V^ ,          '       d$   V! \/        VV4      4       V'       g
   S^ ,          # V'       d   \        S\        R7      # R# u up	i u uppi u upi u uppi u upi u upi u upi )aÆ  
Given a real number `x`, ``identify(x)`` attempts to find an exact
formula for `x`. This formula is returned as a string. If no match
is found, ``None`` is returned. With ``full=True``, a list of
matching formulas is returned.

As a simple example, :func:`~mpmath.identify` will find an algebraic
formula for the golden ratio::

    >>> from mpmath import *
    >>> mp.dps = 15; mp.pretty = True
    >>> identify(phi)
    '((1+sqrt(5))/2)'

:func:`~mpmath.identify` can identify simple algebraic numbers and simple
combinations of given base constants, as well as certain basic
transformations thereof. More specifically, :func:`~mpmath.identify`
looks for the following:

    1. Fractions
    2. Quadratic algebraic numbers
    3. Rational linear combinations of the base constants
    4. Any of the above after first transforming `x` into `f(x)` where
       `f(x)` is `1/x`, `\sqrt x`, `x^2`, `\log x` or `\exp x`, either
       directly or with `x` or `f(x)` multiplied or divided by one of
       the base constants
    5. Products of fractional powers of the base constants and
       small integers

Base constants can be given as a list of strings representing mpmath
expressions (:func:`~mpmath.identify` will ``eval`` the strings to numerical
values and use the original strings for the output), or as a dict of
formula:value pairs.

In order not to produce spurious results, :func:`~mpmath.identify` should
be used with high precision; preferably 50 digits or more.

**Examples**

Simple identifications can be performed safely at standard
precision. Here the default recognition of rational, algebraic,
and exp/log of algebraic numbers is demonstrated::

    >>> mp.dps = 15
    >>> identify(0.22222222222222222)
    '(2/9)'
    >>> identify(1.9662210973805663)
    'sqrt(((24+sqrt(48))/8))'
    >>> identify(4.1132503787829275)
    'exp((sqrt(8)/2))'
    >>> identify(0.881373587019543)
    'log(((2+sqrt(8))/2))'

By default, :func:`~mpmath.identify` does not recognize `\pi`. At standard
precision it finds a not too useful approximation. At slightly
increased precision, this approximation is no longer accurate
enough and :func:`~mpmath.identify` more correctly returns ``None``::

    >>> identify(pi)
    '(2**(176/117)*3**(20/117)*5**(35/39))/(7**(92/117))'
    >>> mp.dps = 30
    >>> identify(pi)
    >>>

Numbers such as `\pi`, and simple combinations of user-defined
constants, can be identified if they are provided explicitly::

    >>> identify(3*pi-2*e, ['pi', 'e'])
    '(3*pi + (-2)*e)'

Here is an example using a dict of constants. Note that the
constants need not be "atomic"; :func:`~mpmath.identify` can just
as well express the given number in terms of expressions
given by formulas::

    >>> identify(pi+e, {'a':pi+2, 'b':2*e})
    '((-2) + 1*a + (1/2)*b)'

Next, we attempt some identifications with a set of base constants.
It is necessary to increase the precision a bit.

    >>> mp.dps = 50
    >>> base = ['sqrt(2)','pi','log(2)']
    >>> identify(0.25, base)
    '(1/4)'
    >>> identify(3*pi + 2*sqrt(2) + 5*log(2)/7, base)
    '(2*sqrt(2) + 3*pi + (5/7)*log(2))'
    >>> identify(exp(pi+2), base)
    'exp((2 + 1*pi))'
    >>> identify(1/(3+sqrt(2)), base)
    '((3/7) + (-1/7)*sqrt(2))'
    >>> identify(sqrt(2)/(3*pi+4), base)
    'sqrt(2)/(4 + 3*pi)'
    >>> identify(5**(mpf(1)/3)*pi*log(2)**2, base)
    '5**(1/3)*pi*log(2)**2'

An example of an erroneous solution being found when too low
precision is used::

    >>> mp.dps = 15
    >>> identify(1/(3*pi-4*e+sqrt(8)), ['pi', 'e', 'sqrt(2)'])
    '((11/25) + (-158/75)*pi + (76/75)*e + (44/15)*sqrt(2))'
    >>> mp.dps = 50
    >>> identify(1/(3*pi-4*e+sqrt(8)), ['pi', 'e', 'sqrt(2)'])
    '1/(3*pi + (-4)*e + 2*sqrt(2))'

**Finding approximate solutions**

The tolerance ``tol`` defaults to 3/4 of the working precision.
Lowering the tolerance is useful for finding approximate matches.
We can for example try to generate approximations for pi::

    >>> mp.dps = 15
    >>> identify(pi, tol=1e-2)
    '(22/7)'
    >>> identify(pi, tol=1e-3)
    '(355/113)'
    >>> identify(pi, tol=1e-10)
    '(5**(339/269))/(2**(64/269)*3**(13/269)*7**(92/269))'

With ``full=True``, and by supplying a few base constants,
``identify`` can generate almost endless lists of approximations
for any number (the output below has been truncated to show only
the first few)::

    >>> for p in identify(pi, ['e', 'catalan'], tol=1e-5, full=True):
    ...     print(p)
    ...  # doctest: +ELLIPSIS
    e/log((6 + (-4/3)*e))
    (3**3*5*e*catalan**2)/(2*7**2)
    sqrt(((-13) + 1*e + 22*catalan))
    log(((-6) + 24*e + 4*catalan)/e)
    exp(catalan*((-1/5) + (8/15)*e))
    catalan*(6 + (-6)*e + 15*catalan)
    sqrt((5 + 26*e + (-3)*catalan))/e
    e*sqrt(((-27) + 2*e + 25*catalan))
    log(((-1) + (-11)*e + 59*catalan))
    ((3/20) + (21/20)*e + (3/20)*catalan)
    ...

The numerical values are roughly as close to `\pi` as permitted by the
specified tolerance:

    >>> e/log(6-4*e/3)
    3.14157719846001
    >>> 135*e*catalan**2/98
    3.14166950419369
    >>> sqrt(e-13+22*catalan)
    3.14158000062992
    >>> log(24*e-6+4*catalan)-1
    3.14158791577159

**Symbolic processing**

The output formula can be evaluated as a Python expression.
Note however that if fractions (like '2/3') are present in
the formula, Python's :func:`~mpmath.eval()` may erroneously perform
integer division. Note also that the output is not necessarily
in the algebraically simplest form::

    >>> identify(sqrt(2))
    '(sqrt(8)/2)'

As a solution to both problems, consider using SymPy's
:func:`~mpmath.sympify` to convert the formula into a symbolic expression.
SymPy can be used to pretty-print or further simplify the formula
symbolically::

    >>> from sympy import sympify # doctest: +SKIP
    >>> sympify(identify(sqrt(2))) # doctest: +SKIP
    2**(1/2)

Sometimes :func:`~mpmath.identify` can simplify an expression further than
a symbolic algorithm::

    >>> from sympy import simplify # doctest: +SKIP
    >>> x = sympify('-1/(-3/2+(1/2)*5**(1/2))*(3/2-1/2*5**(1/2))**(1/2)') # doctest: +SKIP
    >>> x # doctest: +SKIP
    (3/2 - 5**(1/2)/2)**(-1/2)
    >>> x = simplify(x) # doctest: +SKIP
    >>> x # doctest: +SKIP
    2/(6 - 2*5**(1/2))**(1/2)
    >>> mp.dps = 30 # doctest: +SKIP
    >>> x = sympify(identify(x.evalf(30))) # doctest: +SKIP
    >>> x # doctest: +SKIP
    1/2 + 5**(1/2)/2

(In fact, this functionality is available directly in SymPy as the
function :func:`~mpmath.nsimplify`, which is essentially a wrapper for
:func:`~mpmath.identify`.)

**Miscellaneous issues and limitations**

The input `x` must be a real number. All base constants must be
positive real numbers and must not be rationals or rational linear
combinations of each other.

The worst-case computation time grows quickly with the number of
base constants. Already with 3 or 4 base constants,
:func:`~mpmath.identify` may require several seconds to finish. To search
for relations among a large number of constants, you should
consider using :func:`~mpmath.pslq` directly.

The extended transformations are applied to x, not the constants
separately. As a result, ``identify`` will for example be able to
recognize ``exp(2*pi+3)`` with ``pi`` given as a base constant, but
not ``2*exp(pi)+3``. It will be able to recognize the latter if
``exp(pi)`` is given explicitly as a base constant.

c                 óR   <€ S'       d   \        R V 4       SP                  V 4       R# )zFound: N)r)   rY   )rD   Ú	solutionsr8   s   &€€r   ÚaddsolutionÚidentify.<locals>.addsolutionë  s   ø€ ß”E˜) QÔ'Ø×Ñ˜Ör   rj   Nz-(%s)gffffffæ?c              3   ó>   <"  € T F  q\        SV4      3x € K  	  R # 5ir   )Úgetattr)r   Únamer4   s   & €r   r   Úidentify.<locals>.<genexpr>  s   øé € ÐLÁ8¸4¤G¨C°Ó$5Õ6Ã8ùs   ƒrd   c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir   r   ©r   Úuws   & r   r   r¶     s   é € Ð$9±q°¤S¨§W W³qùr   z/$cz$yre   z$cÚ.c           	   3   ó¤   <"  € T FE  p\        SP                  SP                  S4      SP                  V4      ,          ^4      4      x € KG  	  R# 5i)r   N)Úboolr]   r¦   )r   rB   r\   r4   s   & €€r   r   r¶   8  s9   øé € ÐPÉ%ÀQ”t˜CŸL™L¨¯©°«°3·6±6¸!³9Õ)<¸QÓ?×@Ð@Ë%ùs   ƒAAc              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir   r   r¸   s   & r   r   r¶   <  s   é € Ð 5±1¨R¤ R§ ³1ùr   )Úkey)r‰   é   é   é   )r+   ÚidentifyÚepsrk   ÚdictÚsortedÚitemsÚdirÚevalÚ
transformsr   rW   r(   rs   Úoner&   r€   Úreplacer)   ÚsumrY   r¦   rl   rx   ) r4   r	   ro   r5   r6   Úfullr8   r±   ÚsolrD   ÚMrµ   r"   Ú	namespacer_   ÚvalueÚftÚftnÚredr}   ÚcnrF   r\   rn   r`   ÚaaÚbbÚccÚilogsÚlogsrB   r°   s    f&&&&&f               `        @r   rÂ   rÂ     s   û€ ðj €Iöð 	�‰�‹
€Að 	ˆA„vß˜˜�ÙØˆ1„uØ�l‰l˜A˜2˜y¨x¸wÓGˆØŠ;ØˆJßÙ'*Ó+¡s !�G˜A—I�I¡sÑ+Ð+à˜S•=Ð ç
Ø�g‰g�c‹l‰à�g‰g�s�lˆØ€AçÜ�i¤×&Ò&Ü=CÀIÇOÁOÓDUÔ=VÔWÑ=V±	°˜#Ÿ'™' !›* dÓ+Ñ=VˆIÑWˆIäÔLÄ3ÀsÄ8ÓLÓLˆIÙ:CÓD¹)°Qœ$˜qÓ,¨aÓ0¹)ˆIÐDˆIàˆ	ð 	©IÔ6©I™=˜D“©IÒ6Ô6Ø—g‘g˜a“j #Ð&Ð'¨)Õ3ˆ	÷ #˜
‰ˆˆC�Ü‰EˆAˆrß�r˜S”yÙÙ�3�q˜“ˆAä�1‹v˜˜1�Œ}¤ A£¨¤Ùà—‘˜!˜©iÓ8©i¨  !§ ©iÑ8Õ8¸#ÓAˆAØˆAØŠ}¤Ñ$9±qÓ$9Ó!9¸QÔ!>À1ÀQÇ4Ä4Ü˜q )Ó,‘ð —H‘H˜cŸg™g q¨!¨Q­$Ð/°Ó8�Ø’=¤S¨£V¨q¤[°Q°q·T´TØ!"‘J�B˜˜BÜœ3˜r›7¤3 r£7¬3¨r«7Ó3°qÔ8Ü+¨C°°"°R¸Ó;˜ßØ˜”9 %¨3¤,ØŸ™ D¨!Ó,×4Ñ4°U¸BÓ?‘AàŸ™ D¨!Ó,×4Ñ4°T¸2Ó>�AÙ˜A”ß I¨a¥LÔ0çŠwÜ�c—
ô9 ñ #ð@ 	ˆA…vâˆàˆÛ‰DˆAˆqÜÕPÉ%ÓP×PÔPØ—‘˜SŸV™V A›Y¨˜NÖ+ñ ñ -2Ó2©E q�—‘˜“œ3˜q›6Ó"©EÑ2°TÕ9ˆØ�H‰H�c—f‘f˜Q“i�[±$Ó#7±$¨Q A a§D D±$Ñ#7Õ7¸Ó@ˆØŠ=œSÑ 5±1Ó 5Ó5¸Ô:¸qÀ¿t¼tÙœ
 1 dÓ+Ô,ß 	¨!¥Ð,çÜ�i¤SÔ)Ð)áùòS ,ùó Xùò Eùó
 7ùò  9ùò> 3ùÚ#7s*   Á!RÃ(RÄ,R%ÅR*Ç)R0Ï%R5ÐR:
Ú__main__)Nr   éd   Fr   )Ú__doc__Úlibmp.backendr   Úlibmpr   r   r   Úobjectr   rW   r]   ra   rs   rx   r€   rÉ   rÂ   r   ÚdoctestÚtestmodr   r   r   Ú<module>rã      s­  ðñõ
 "ß (ò1ô	˜Fô 	ôdôL	sòj	òò0"ò.ñ" ˜ Ð#Ù˜ Ð#Ù˜ Ð#Ù˜]¨AÐ.Ù˜]¨AÐ.Ù˜]¨AÐ.ÙÐ.°Ð2ÙÐ.°Ð2ÙÐ.°Ð2Ù  *¨aÐ0Ù  *¨aÐ0Ù  *¨aÐ0Ù  -°Ð3Ù  -°Ð3Ù  -°Ð3Ù ¨qÐ1Ù ¨qÐ1Ù ¨qÐ1Ù ¨qÐ1Ù ¨qÐ1Ù ¨qÐ1Ù ¨aÐ0Ù ¨aÐ0Ù ¨aÐ0Ù ¨aÐ0Ù ¨aÐ0Ù ¨aÐ0ð7€
ð<  " t°dÀØôoðb	 "Ð Ô Ø!)Ð Ô Ø!)Ð Ô ð ˆzÔÛØ‡O‚OÖñ r   