
    \h?                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJrJrJrJrJrJr  S S	KJr  S S
KJr  S SKJrJrJr  S SKJr  S SKJr  S SK J!r!   " S S\5      r"S r#g)    )Rational)S)symbols)sign)sqrt)gcd)
Complement)BasicTuplediffexpandEqInteger)ordered)_symbol)solvesetnonlinsolvediophantinetotal_degree)Point)corec                      ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r\S 5       r	S r
S rS	 rS
 rS rSS jrSrU =r$ )ImplicitRegion   a-  
Represents an implicit region in space.

Examples
========

>>> from sympy import Eq
>>> from sympy.abc import x, y, z, t
>>> from sympy.vector import ImplicitRegion

>>> ImplicitRegion((x, y), x**2 + y**2 - 4)
ImplicitRegion((x, y), x**2 + y**2 - 4)
>>> ImplicitRegion((x, y), Eq(y*x, 1))
ImplicitRegion((x, y), x*y - 1)

>>> parabola = ImplicitRegion((x, y), y**2 - 4*x)
>>> parabola.degree
2
>>> parabola.equation
-4*x + y**2
>>> parabola.rational_parametrization(t)
(4/t**2, 4/t)

>>> r = ImplicitRegion((x, y, z), Eq(z, x**2 + y**2))
>>> r.variables
(x, y, z)
>>> r.singular_points()
EmptySet
>>> r.regular_point()
(-10, -10, 200)

Parameters
==========

variables : tuple to map variables in implicit equation to base scalars.

equation : An expression or Eq denoting the implicit equation of the region.

c                    > [        U[        5      (       d  [        U6 n[        U[        5      (       a  UR                  UR                  -
  n[
        TU ]  XU5      $ N)
isinstancer   r   lhsrhssuper__new__)cls	variablesequation	__class__s      S/var/www/auris/envauris/lib/python3.13/site-packages/sympy/vector/implicitregion.pyr"   ImplicitRegion.__new__9   sJ    )U++y)Ih##||hll2Hwsx88    c                      U R                   S   $ )Nr   argsselfs    r'   r$   ImplicitRegion.variablesB       yy|r)   c                      U R                   S   $ )N   r+   r-   s    r'   r%   ImplicitRegion.equationF   r0   r)   c                 ,    [        U R                  5      $ r   )r   r%   r-   s    r'   degreeImplicitRegion.degreeJ   s    DMM**r)   c                    U R                   n[        U R                  5      S:X  a2  [        [	        XR                  S   [
        R                  S95      S   4$ [        U R                  5      S:X  ac  U R                  S:X  aS  [        U R                  U5      =nu  p4pVpxUS-  SU-  U-  :X  a  U R                  " U6 u  pX4$ U R                  " U6 u  pX4$ [        U R                  5      S:X  a  U R                  u  pn[        SS5       H  n	[        SS5       Hw  n
[	        UR                  XX05      U R                  S   [
        R                  S9R                  (       a  MK  X[        [	        UR                  XX05      5      5      S   4s  s  $    M     [        U R                  5       5      S:w  a  [        U R                  5          S   $ [        5       e)	a  
Returns a point on the implicit region.

Examples
========

>>> from sympy.abc import x, y, z
>>> from sympy.vector import ImplicitRegion
>>> circle = ImplicitRegion((x, y), (x + 2)**2 + (y - 3)**2 - 16)
>>> circle.regular_point()
(-2, -1)
>>> parabola = ImplicitRegion((x, y), x**2 - 4*y)
>>> parabola.regular_point()
(0, 0)
>>> r = ImplicitRegion((x, y, z), (x + y + z)**4)
>>> r.regular_point()
(-10, -10, 20)

References
==========

- Erik Hillgarter, "Rational Points on Conics", Diploma Thesis, RISC-Linz,
  J. Kepler Universitat Linz, 1996. Available:
  https://www3.risc.jku.at/publications/download/risc_1355/Rational%20Points%20on%20Conics.pdf

r2   r   )domain         i
   )r%   lenr$   listr   r   Realsr5   conic_coeff_regular_point_parabola_regular_point_ellipserangesubsis_emptysingular_pointsNotImplementedError)r.   r%   coeffsabcdefx_regy_regxyzs                 r'   regular_pointImplicitRegion.regular_pointN   s   6 ==t~~!#(NN1,=aggNOPQRTT A%{{a,7,QQ)qQa41Q3q5=#'#?#?#HLE |# $(#>#>#GLE|#t~~!#nnGA!sB"3^E#HMM1Q2F$GXYIZcdcjcjkttt %d8HMM1UVJ^<_3`.abc.dee , (
 t##%&!+,,./22!##r)   c                    X4S:g  =(       a(    X54S:g  =(       a    US-  SU-  U-  :H  =(       a    X4S:g  nU(       d  [        S5      eUS:w  a<  SU-  U-  SU-  U-  -
  SU-  U-  US-  -
  pUS:w  a  U	* U-  n
XBU
-  -   * SU-  -  nODSnOAUS:w  a;  SU-  U-  SU-  U-  -
  SU-  U-  US-  -
  pUS:w  a  U	* U-  nXRU-  -   * SU-  -  n
OSnU(       a  WW
4$ [        S5      e)N)r   r   r9   r:   *Rational Point on the conic does not existr   F)
ValueError)r.   rI   rJ   rK   rL   rM   rN   okd_dashf_dashrP   rO   s               r'   rA   &ImplicitRegion._regular_point_parabola   s"   6!]qf&6]1a41Q3q5=]aVW]M]B !MNNAv"#A#a%!A#a%-1QAQ;#GFNEE'kNAaC0EBa"#A#a%!A#a%-1QAQ;#GFNEE'kNAaC0EBe|# !MNNr)   c                 
  ^. SU-  U-  US-  -
  nUnU(       d  [        S5      eUS:X  a  US:X  a  Sn	SXE-  X&-  -
  -  n
OUS:w  aM  Un	SUS-  -  US-  -  SU-  U-  U-  U-  -
  SU-  U-  US-  -  -   SUS-  -  U-  U-  -   SU-  US-  -  U-  -
  n
O.Un	SUS-  -  US-  -  SU-  U-  U-  U-  -
  SUS-  -  U-  U-  -   n
U
S:g  =(       a    U	S:  =(       a    U
S:  (       + nU(       d  [        S5      e[        U	5      R                  S5      n	[        U
5      R                  S5      n
U	R                  U	R                  pU
R                  U
R                  p[        X5      nX-  U-  nX-  U-  nX-  * U-  n[        U5      [        [        U5      S5      -  n[        UU-  5      n[        U5      [        [        U5      S5      -  n[        UU-  5      n[        U5      [        [        U5      S5      -  n[        UU-  5      n[        [        UU5      U5      nUU-  nUU-  nUU-  n[        UU5      nUU-  nUU-  nUU-  n[        UU5      nUU-  nUU-  nUU-  n[        UU5      nUU-  nUU-  nUU-  n[        S5      u  nnnUUS-  -  UUS-  -  -   UUS-  -  -   n[        U5      n [        U 5      S:X  a  [        S5      eS	n!U  GH  n"[        U"6 R                  n#[        R!                  U#S
5      m.U"S   n$U$S:X  a  Sn!M;  [#        U$[$        [&        45      (       a  MX  U$R                  n%[        U%5      S:X  ah  [)        [+        U%5      5      n&[-        [.        R0                  [3        [5        U$S5      U&[.        R0                  5      5      n'[)        [+        U'5      5      T.U&'   [        U%5      S:X  a  [7        [9        U%5      5      u  n&n([.        R0                   H  n)U$R;                  U&U)5      n*[-        [.        R0                  [3        [5        U*S5      U([.        R0                  5      5      n+U+R<                  (       a  Me  U)T.U&'   [)        [+        U+5      5      T.U('     O   [        U#5      S:w  a  [?        U.4S jU" 5       5      u  nnnOU"u  nnnS	n!  O   U!(       a  [        S5      eUU-  U-  nUU-  U-  nUU-  U-  nUU-  nUU-  nUS:X  a,  US:X  a&  UU-   SU-  -
  SU-  -  n,UU-
  SU-  -
  SU-  -  n-U,U-4$ US:w  a(  USU-  U-  -
  X%-  -   U	-  n,UUU,-  -
  U-
  SU-  -  n-U,U-4$ USU-  U-  -
  X$-  -   U	-  n-UUU--  -
  U-
  SU-  -  n,U,U-4$ )Nr:   r9   rW   r      l    J)zx y zFr;   Tr2   c              3   D   >#    U  H  oR                  T5      v   M     g 7fr   rD   .0sreps     r'   	<genexpr>8ImplicitRegion._regular_point_ellipse.<locals>.<genexpr>   s     'ASsS    ) rX   r   limit_denominatorpqr   r   r   absr   r   r   r=   r   free_symbolsdictfromkeysr   intr   nextiterr	   r   Integersr   r   r>   r   rD   rE   tuple)/r.   rI   rJ   rK   rL   rM   rN   DrY   KLk1k2l1l2ga1b1c1a2r1b2r2c2r3g1g2g3rQ   rR   rS   eq	solutionsflagsolsymssol_zsyms_zrj   p_valuesrk   i
subs_sol_zq_valuesrO   rP   re   s/                                                 @r'   rB   %ImplicitRegion._regular_point_ellipse   s   !A1AB !MNNAv!q&qsQSyMaadF1a4K!A#a%'!)+ac!eAqDj81QT6!8A:E1QPQT	RSSadF1a4K!A#a%'!)+a1fQhqj8a0A!a%0B !MNN--f5A--f5ASS!##SS!##BA%B%B5!Bb$s2w**BbeBb$s2w**BbeBb$s2w**BbeBCBK$AABABABRBBBBBBBRBBBBBBBRBBBBBBBg&GAq!AqD2ad7"R1W,B#BI9~" !MNND c{//mmD!,AA:D!%#w88"//F6{a' f.#-ajj(2eQ<QRTUT^T^:_#`!%d8n!5A6{a'#GFO41!"A).Aq)9J'1!**hr*VWGXZ[]^]g]g>h'iH#+#4#4#4)*A)-d8n)=A % ", 4yA~"''AS'A"A1a$'1a DE !H  !MNN2r	A2r	A2r	A!A!AAv!q&Q1qs+Q1qs+ %< aQqSUQS!+QuWq1Q3/
 %< QqSUQS!+QuWq1Q3/%<r)   c                     U R                   /nU R                   H  nU[        U R                   U5      /-  nM     [        U[	        U R                  5      5      $ )aG  
Returns a set of singular points of the region.

The singular points are those points on the region
where all partial derivatives vanish.

Examples
========

>>> from sympy.abc import x, y
>>> from sympy.vector import ImplicitRegion
>>> I = ImplicitRegion((x, y), (y-1)**2 -x**3 + 2*x**2 -x)
>>> I.singular_points()
{(1, 1)}

)r%   r$   r   r   r>   )r.   eq_listvars      r'   rF   ImplicitRegion.singular_points  sM    " ==/>>CT]]C011G " 7D$899r)   c                 j   [        U[        5      (       a  UR                  nU R                  n[	        U R
                  5       H  u  p4UR                  XDX   -   5      nM     [        U5      n[        UR                  5      S:w  a   UR                  n[        S U 5       5      nU$ Un[        U5      nU$ )a  
Returns the multiplicity of a singular point on the region.

A singular point (x,y) of region is said to be of multiplicity m
if all the partial derivatives off to order m - 1 vanish there.

Examples
========

>>> from sympy.abc import x, y, z
>>> from sympy.vector import ImplicitRegion
>>> I = ImplicitRegion((x, y, z), x**2 + y**3 - z**4)
>>> I.singular_points()
{(0, 0, 0)}
>>> I.multiplicity((0, 0, 0))
2

r   c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   )rc   terms     r'   rf   .ImplicitRegion.multiplicity.<locals>.<genexpr>P  s     954L&&5s   )r   r   r,   r%   	enumerater$   rD   r   r=   minr   )r.   pointmodified_eqr   r   termsms          r'   multiplicityImplicitRegion.multiplicity2  s    & eU##JJEmm/FA%**3eh?K 0[){ A%$$E9599A
   EU#Ar)   c                 t  ^ U R                   nU R                  nUS:X  ag  [        U R                  5      S:X  a  U4$ [        U R                  5      S:X  a(  U R                  u  pV[	        [        X65      5      S   nXW4$ [        5       eSnUS:X  aP  Ub  UnOJ[        U R                  5       5      S:w  a  [	        U R                  5       5      S   nOU R                  5       n[        U R                  5       5      S:w  a  U R                  5       n	U	 Hk  n
[        U
6 R                  n[        R                  US5      m[        U5      S:w  a  [        U4S jU
 5       5      n
U R                  U
5      US-
  :X  d  Mi  U
n  O   [        U5      S:X  a
  [        5       eUn[        U R                  5       H  u  pUR!                  XX   -   5      nM     [#        U5      nS=nnUR$                   H  n['        U5      U:X  a  UU-  nM  UU-  nM      SU-  n[)        U[        5      (       d  U4n[        U R                  5      S:X  a  US   nUS:X  a  [+        SS	S
9nO
[+        SS	S
9n[+        US	S
9nUR!                  U R                  S   UU R                  S   U05      nUR!                  U R                  S   UU R                  S   U05      nUUU-  -  R!                  US5      US   -   nUUU-  -  R!                  US5      US   -   nUU4$ [        U R                  5      S:X  Ga  Uu  nnSU;   a  [+        SS	S
9nO
[+        SS	S
9n[+        US	S
9n[+        US	S
9nUR!                  U R                  S   UU R                  S   UU R                  S   U05      nUR!                  U R                  S   UU R                  S   UU R                  S   U05      nUUU-  -  R!                  US5      US   -   nUUU-  -  R!                  US5      US   -   nUUU-  -  R!                  US5      US   -   nUUU4$ [        5       e)a  
Returns the rational parametrization of implicit region.

Examples
========

>>> from sympy import Eq
>>> from sympy.abc import x, y, z, s, t
>>> from sympy.vector import ImplicitRegion

>>> parabola = ImplicitRegion((x, y), y**2 - 4*x)
>>> parabola.rational_parametrization()
(4/t**2, 4/t)

>>> circle = ImplicitRegion((x, y), Eq(x**2 + y**2, 4))
>>> circle.rational_parametrization()
(4*t/(t**2 + 1), 4*t**2/(t**2 + 1) - 2)

>>> I = ImplicitRegion((x, y), x**3 + x**2 - y**2)
>>> I.rational_parametrization()
(t**2 - 1, t*(t**2 - 1))

>>> cubic_curve = ImplicitRegion((x, y), x**3 + x**2 - y**2)
>>> cubic_curve.rational_parametrization(parameters=(t))
(t**2 - 1, t*(t**2 - 1))

>>> sphere = ImplicitRegion((x, y, z), x**2 + y**2 + z**2 - 4)
>>> sphere.rational_parametrization(parameters=(t, s))
(-2 + 4/(s**2 + t**2 + 1), 4*s/(s**2 + t**2 + 1), 4*t/(s**2 + t**2 + 1))

For some conics, regular_points() is unable to find a point on curve.
To calulcate the parametric representation in such cases, user need
to determine a point on the region and pass it using reg_point.

>>> c = ImplicitRegion((x, y), (x  - 1/2)**2 + (y)**2 - (1/4)**2)
>>> c.rational_parametrization(reg_point=(3/4, 0))
(0.75 - 0.5/(t**2 + 1), -0.5*t/(t**2 + 1))

References
==========

- Christoph M. Hoffmann, "Conversion Methods between Parametric and
  Implicit Curves and Surfaces", Purdue e-Pubs, 1990. Available:
  https://docs.lib.purdue.edu/cgi/viewcontent.cgi?article=1827&context=cstech

r2   r9   r    c              3   D   >#    U  H  oR                  T5      v   M     g 7fr   ra   rb   s     r'   rf   :ImplicitRegion.rational_parametrization.<locals>.<genexpr>  s     "?166#;;rh   r^   rd   s_T)realr;   rr_)r%   r5   r=   r$   r>   r   rG   rF   rT   r   rm   rn   ro   rt   r   r   rD   r   r,   r   r   r   )r.   
parameters	reg_pointr%   r5   rQ   rR   y_parr   rF   spointr   r   r   r   hnhn_1r   
parameter1rd   tx_par
parameter2r   z_parre   s                            @r'   rational_parametrization'ImplicitRegion.rational_parametrizationW  s'   ^ ==Q;4>>"a' {"T^^$)~~Xh23A6x)++ Q;$!t++-.!3 !5!5!78;E ..0Et##%&!+"224O)f~22mmD!,t9>""?"??F$$V,
:"E * u:?%''  /FA%**3eh?K 0[)T$$DD!V+d
	 % $w*e,,$Jt~~!##AJS Dt,Cd+
.A$..+Qq0A1EFB99dnnQ/DNN14EqIJDR[&&q!,uQx7ER[&&q!,uQx7E%< A%%/"J
j Dt,Cd+
.A
.A$..+Qq0A1dnnUVFWYZ[\B99dnnQ/DNN14Eq$..YZJ[]^_`DR[&&q!,uQx7ER[&&q!,uQx7ER[&&q!,uQx7E%&&!##r)   r   ))r   rd   N)__name__
__module____qualname____firstlineno____doc__r"   propertyr$   r%   r5   rT   rA   rB   rF   r   r   __static_attributes____classcell__)r&   s   @r'   r   r      st    &N9     + +5$nO4z x:.#JT$ T$r)   r   c                    [        U5      S:w  a
  [        5       eU S   nU S   n[        U5      nUR                  US-  5      nUR                  X#-  5      nUR                  US-  5      nUR                  US5      R                  US5      nUR                  US5      R                  US5      nUR                  US5      R                  US5      n	XEXgX4$ )Nr9   r   r2   )r   rX   r   coeff)
r$   r%   rQ   rR   rI   rJ   rK   rL   rM   rN   s
             r'   r@   r@     s    H"l!A!AhHq!tAqsAq!tAq!""1a(Aq!""1a(Aq!""1a(Aqr)   N)$sympy.core.numbersr   sympy.core.singletonr   sympy.core.symbolr   $sympy.functions.elementary.complexesr   (sympy.functions.elementary.miscellaneousr   sympy.polys.polytoolsr   sympy.sets.setsr	   
sympy.corer
   r   r   r   r   r   sympy.core.sortingr   r   sympy.solversr   r   r   sympy.polysr   sympy.geometryr   sympy.ntheory.factor_r   r   r@   r   r)   r'   <module>r      sI    ' " % 5 9 % & > > & % < < $   &Z$U Z$xr)   