Ë
    7^(hg  ã                  óÜ   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ dd„Zdd„Zdd„Zedd„«       Zedd„«       Zedd„«       Zedd„«       Zdd„Zy)aÛ  A module for special angle formulas for trigonometric functions

TODO
====

This module should be developed in the future to contain direct square root
representation of

.. math
    F(\frac{n}{m} \pi)

for every

- $m \in \{ 3, 5, 17, 257, 65537 \}$
- $n \in \mathbb{N}$, $0 \le n < m$
- $F \in \{\sin, \cos, \tan, \csc, \sec, \cot\}$

Without multi-step rewrites
(e.g. $\tan \to \cos/\sin \to \cos/\sqrt \to \ sqrt$)
or using chebyshev identities
(e.g. $\cos \to \cos + \cos^2 + \cdots \to \sqrt{} + \sqrt{}^2 + \cdots $),
which are trivial to implement in sympy,
and had used to give overly complicated expressions.

The reference can be found below, if anyone may need help implementing them.

References
==========

.. [*] Gottlieb, Christian. (1999). The Simple and straightforward construction
   of the regular 257-gon. The Mathematical Intelligencer. 21. 31-37.
   10.1007/BF03024829.
.. [*] https://resources.wolframcloud.com/FunctionRepository/resources/Cos2PiOverFermatPrime
é    )Úannotations)ÚCallable)Úreduce)ÚExpr)ÚS)Úigcdex)ÚInteger©Úsqrt)Úcacheitc                 óì   ‡— | syt        | «      dk(  rd| d   fS t        | «      dk(  rt        | d   | d   «      \  }Š}|‰f|fS t        | dd Ž \  }}t        | d   |«      \  }Š}|gˆfd„|D «       ¢­|fS )aN  Compute extended gcd for multiple integers.

    Explanation
    ===========

    Given the integers $x_1, \cdots, x_n$ and
    an extended gcd for multiple arguments are defined as a solution
    $(y_1, \cdots, y_n), g$ for the diophantine equation
    $x_1 y_1 + \cdots + x_n y_n = g$ such that
    $g = \gcd(x_1, \cdots, x_n)$.

    Examples
    ========

    >>> from sympy.functions.elementary._trigonometric_special import migcdex
    >>> migcdex()
    ((), 0)
    >>> migcdex(4)
    ((1,), 4)
    >>> migcdex(4, 6)
    ((-1, 1), 2)
    >>> migcdex(6, 10, 15)
    ((1, 1, -1), 1)
    )© r   é   )r   r   é   Nc              3  ó(   •K  — | ]	  }‰|z  –— Œ y ­w©Nr   )Ú.0ÚiÚvs     €úo/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/functions/elementary/_trigonometric_special.pyú	<genexpr>zmigcdex.<locals>.<genexpr>S   s   øè ø€ Ò"˜1��Q•Ñ"ùs   ƒ)Úlenr   Úmigcdex)ÚxÚuÚhÚyÚgr   s        @r   r   r   .   s˜   ø€ ñ2 Øä
ˆ1ƒv�‚{Ø�Q�q‘TˆzÐä
ˆ1ƒv�‚{Ü˜˜1™˜q ™tÓ$‰ˆˆ1ˆaØ�1ˆv�qˆyÐä�A�a�b�Eˆ?�D€A€qÜ�Q�q‘T˜1‹o�G€A€qˆ!ØÐ#Ó" Ô"Ñ# QÐ&Ð&ó    c                 óp   — | sydd„}t        || «      }| D �cg c]  }||z  ‘Œ	 }}t        |Ž \  }}|S c c}w )aÞ  Compute the partial fraction decomposition.

    Explanation
    ===========

    Given a rational number $\frac{1}{q_1 \cdots q_n}$ where all
    $q_1, \cdots, q_n$ are pairwise coprime,

    A partial fraction decomposition is defined as

    .. math::
        \frac{1}{q_1 \cdots q_n} = \frac{p_1}{q_1} + \cdots + \frac{p_n}{q_n}

    And it can be derived from solving the following diophantine equation for
    the $p_1, \cdots, p_n$

    .. math::
        1 = p_1 \prod_{i \ne 1}q_i + \cdots + p_n \prod_{i \ne n}q_i

    Where $q_1, \cdots, q_n$ being pairwise coprime implies
    $\gcd(\prod_{i \ne 1}q_i, \cdots, \prod_{i \ne n}q_i) = 1$,
    which guarantees the existence of the solution.

    It is sufficient to compute partial fraction decomposition only
    for numerator $1$ because partial fraction decomposition for any
    $\frac{n}{q_1 \cdots q_n}$ can be easily computed by multiplying
    the result by $n$ afterwards.

    Parameters
    ==========

    denoms : int
        The pairwise coprime integer denominators $q_i$ which defines the
        rational number $\frac{1}{q_1 \cdots q_n}$

    Returns
    =======

    tuple[int, ...]
        The list of numerators which semantically corresponds to $p_i$ of the
        partial fraction decomposition
        $\frac{1}{q_1 \cdots q_n} = \frac{p_1}{q_1} + \cdots + \frac{p_n}{q_n}$

    Examples
    ========

    >>> from sympy import Rational, Mul
    >>> from sympy.functions.elementary._trigonometric_special import ipartfrac

    >>> denoms = 2, 3, 5
    >>> numers = ipartfrac(2, 3, 5)
    >>> numers
    (1, 7, -14)

    >>> Rational(1, Mul(*denoms))
    1/30
    >>> out = 0
    >>> for n, d in zip(numers, denoms):
    ...    out += Rational(n, d)
    >>> out
    1/30
    r   c                ó   — | |z  S r   r   )r   r   s     r   Úmulzipartfrac.<locals>.mul˜   s   € Ø�1‰uˆr   )r   Úintr   r#   Úreturnr#   )r   r   )Údenomsr"   Údenomr   Úar   Ú_s          r   Ú	ipartfracr)   V   sL   € ñ~ Øóô �3˜Ó€EØ#Ö$˜ˆ�!‹Ð$€AÐ$Ü�Aˆ;�D€A€qØ€Hùò 	%s   ˜3c                óx   — g }dD ]3  }t        | |«      \  }}|dk(  sŒ|} |j                  |«       | dk(  sŒ1|c S  y)z}If n can be factored in terms of Fermat primes with
    multiplicity of each being 1, return those primes, else
    None
    )é   é   é   é  i  r   r   N)ÚdivmodÚappend)ÚnÚprimesÚpÚquotientÚ	remainders        r   Úfermat_coordsr6   ¡   sQ   € ð
 €FØ#ò ˆÜ$ Q¨›lÑˆ�)Ø˜‹>ØˆAØ�M‰M˜!ÔØ�A‹vØ’ðð r   c                 ó"   — t         j                  S )z-Computes $\cos \frac{\pi}{3}$ in square roots)r   ÚHalfr   r   r   Úcos_3r9   ±   s   € ô �6‰6€Mr   c                 ó$   — t        d«      dz   dz  S )z-Computes $\cos \frac{\pi}{5}$ in square rootsr,   r   é   r
   r   r   r   Úcos_5r<   ·   s   € ô �‹G�a‰K˜1ÑÐr   c                 óV  — t        dt        d«      z   dz  t        d«      t        dt        d«      z
  «      t        t        d«      dt        dt        d«      z   «      z  dt        d«      z
  t        dt        d«      z
  «      z  z
  z  dt        d«      z  z   dz   «      z   z  dz  z   «      S )	z.Computes $\cos \frac{\pi}{17}$ in square rootsé   r-   é    r   iøÿÿÿr   é   é"   r
   r   r   r   Úcos_17rB   ½   s°   € ô Ø	Œd�2‹h‰˜"Ñœt A›w¬$¨r´D¸³H©}Ó*=ÜŒT�!‹W˜œT "¤t¨B£x¡-Ó0Ñ0°A¼¸R»±LÜ
ˆr”D˜“H‰}Ó
ñ4ñ ñ Ø!"¤T¨"£X¡ñ.Ø02ñ3ó 	4ñ+4ñ  5à79ñ :ñ 	:ó;ð ;r   c                 óê  — dd„} dd„} | t         j                  t        d«      «      \  }} | |t        d«      «      \  }} | |t        d«      «      \  }} | |dd|z   d|z  z   z  «      \  }}	 | |dd|z   d|z  z   z  «      \  }
} | |dd|z   d|z  z   z  «      \  }} | |dd|z   d|z  z   z  «      \  }} | |d||z   |z   d|
z  z   z  «      \  }} | |d||z   |z   d|z  z   z  «      \  }} | |d||z   |	z   d|z  z   z  «      \  }} | |d||z   |
z   d|z  z   z  «      \  }} | |	d||	z   |z   d|z  z   z  «      \  }} | |
d||
z   |z   d|z  z   z  «      \  }} | |d||z   |z   d|z  z   z  «      \  }} | |d||z   |z   d|	z  z   z  «      \  }} ||d||z   |z   |z   z  «      }  ||d||z   |z   |z   z  «      }! ||d||z   |z   |z   z  «      }" ||d||z   |z   |z   z  «      }# ||d||z   |z   |z   z  «      }$ ||d||z   |z   |z   z  «      }% ||  d|!|"z   z  «       }& ||# d|$|%z   z  «       }'d	 ||& d|'z  «      z  }(t        t        d«      t        |(dz   «      z  d
z  t         j                  z   «      S )a  Computes $\cos \frac{\pi}{257}$ in square roots

    References
    ==========

    .. [*] https://math.stackexchange.com/questions/516142/how-does-cos2-pi-257-look-like-in-real-radicals
    .. [*] https://r-knott.surrey.ac.uk/Fibonacci/simpleTrig.html
    c                ó^   — | t        | dz  |z   «      z   dz  | t        | dz  |z   «      z
  dz  fS ©Nr   r
   ©r'   Úbs     r   Úf1zcos_257.<locals>.f1Ð   s9   € Ø”D˜˜A™ ™“NÑ" aÑ'¨!¬d°1°a±4¸!±8«nÑ*<ÀÑ)AÐAÐAr   c                ó0   — | t        | dz  |z   «      z
  dz  S rE   r
   rF   s     r   Úf2zcos_257.<locals>.f2Ó   s   € Ø”D˜˜A™ ™“NÑ" AÑ%Ð%r   é   é@   r;   r,   r   éüÿÿÿéþÿÿÿé   )r'   r   rG   r   r$   ztuple[Expr, Expr])r'   r   rG   r   r$   r   )r   ÚNegativeOner	   r   r8   ))rH   rJ   Út1Út2Úz1Úz3Úz2Úz4Úy1Úy5Úy6Úy2Úy3Úy7Úy8Úy4Úx1Úx9Úx2Úx10Úx3Úx11Úx4Úx12Úx5Úx13Úx6Úx14Úx15Úx7Úx8Úx16Úv1Úv2Úv3Úv4Úv5Úv6Úu1Úu2Úw1s)                                            r   Úcos_257rx   Æ   s)  € óBó&ñ ”—‘œw s›|Ó,�F€BˆÙ�”G˜B“KÓ �F€BˆÙ�”G˜B“KÓ �F€BˆÙ��A�q˜2‘v  "¡‘}Ñ%Ó&�F€BˆÙ��A�q˜2‘v  "¡‘}Ñ%Ó&�F€BˆÙ��A�q˜2‘v  "¡‘}Ñ%Ó&�F€BˆÙ��A�q˜2‘v  "¡‘}Ñ%Ó&�F€BˆÙ��B˜˜R™ "™ q¨¡tÑ+Ñ,Ó-�F€BˆÙ��R˜˜b™ 2™¨¨"©Ñ,Ñ-Ó.�G€BˆÙ��R˜˜b™ 2™¨¨"©Ñ,Ñ-Ó.�G€BˆÙ��R˜˜b™ 2™¨¨"©Ñ,Ñ-Ó.�G€BˆÙ��R˜˜b™ 2™¨¨"©Ñ,Ñ-Ó.�G€BˆÙ��R˜˜b™ 2™¨¨"©Ñ,Ñ-Ó.�G€BˆÙ��R˜˜b™ 2™¨¨"©Ñ,Ñ-Ó.�G€CˆÙ��R˜˜b™ 2™¨¨"©Ñ,Ñ-Ó.�G€BˆÙ	ˆB��B˜‘G˜b‘L 2Ñ%Ñ&Ó	'€BÙ	ˆB��B˜‘G˜b‘L 2Ñ%Ñ&Ó	'€BÙ	ˆB��B˜‘G˜c‘M CÑ'Ñ(Ó	)€BÙ	ˆB��B˜‘H˜s‘N SÑ(Ñ)Ó	*€BÙ	ˆC��S˜3‘Y ‘_ sÑ*Ñ+Ó	,€BÙ	ˆC��S˜2‘X ‘] RÑ'Ñ(Ó	)€BÙ
ˆbˆS�"�b˜2‘g‘,Ó
Ð	€BÙ
ˆbˆS�"�b˜2‘g‘,Ó
Ð	€BØ	‰B�ˆs�B�r‘E‹NÑ	€BÜ”�Q“œ˜R !™V›Ñ$ QÑ&¬¯©Ñ/Ó0Ð0r   c                 ó0   — t         t        t        t        dœS )ag  Lazily evaluated table for $\cos \frac{\pi}{n}$ in square roots for
    $n \in \{3, 5, 17, 257, 65537\}$.

    Notes
    =====

    65537 is the only other known Fermat prime and it is nearly impossible to
    build in the current SymPy due to performance issues.

    References
    ==========

    https://r-knott.surrey.ac.uk/Fibonacci/simpleTrig.html
    )r+   r,   r-   r.   )r9   r<   rB   rx   r   r   r   Ú	cos_tablerz   ñ   s   € ô  ÜÜÜñ	ð r   N)r   r#   r$   ztuple[tuple[int, ...], int])r%   r#   r$   ztuple[int, ...])r1   r#   r$   zlist[int] | None)r$   r   )r$   zdict[int, Callable[[], Expr]])Ú__doc__Ú
__future__r   Útypingr   Ú	functoolsr   Úsympy.core.exprr   Úsympy.core.singletonr   Úsympy.core.intfuncr   Úsympy.core.numbersr	   Ú(sympy.functions.elementary.miscellaneousr   Úsympy.core.cacher   r   r)   r6   r9   r<   rB   rx   rz   r   r   r   ú<module>r…      s�   ðñ!õD #Ý Ý Ý  Ý "Ý %Ý &Ý 9Ý $ó%'óPHóVð  	òó 	ðð
 	òó 	ðð
 	ò;ó 	ð;ð 	ò'1ó 	ð'1ôTr   