K i?ddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZdd lmZdd lmZdd lmZmZmZdd lmZdd lmZddl m!Z!GddeZ"dZ#y))Rational)S)symbols)sign)sqrt)gcd) Complement)BasicTuplediffexpandEqInteger)ordered)_symbol)solveset nonlinsolve diophantine total_degree)Point)corecxeZdZdZfdZedZedZedZdZ dZ dZ d Z d Z d d ZxZS) ImplicitRegiona 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. ct|tst|}t|tr|j|jz }t ||||SN) isinstancer rlhsrhssuper__new__)cls variablesequation __class__s a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/vector/implicitregion.pyr!zImplicitRegion.__new__9sF)U+y)I h #||hll2HwsIx88c |jdS)Nrargsselfs r&r#zImplicitRegion.variablesByy|r'c |jdS)Nr)r+s r&r$zImplicitRegion.equationFr-r'c,t|jSr)rr$r+s r&degreezImplicitRegion.degreeJsDMM**r'c|j}t|jdk(r6tt ||jdt j dfSt|jdk(rh|jdk(rYt|j|x}\}}}}}}|dzd|z|zk(r|j|\} } | | fS|j|\} } | | fSt|jdk(r|j\} } } tddD]} tddD]y} t |j| | | | i|jdt j jrJ| | tt |j| | | | idfccSt|jdk7rt|jdSt) a0 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 r/r)domaini )r$lenr#listrrRealsr1 conic_coeff_regular_point_parabola_regular_point_ellipserangesubsis_emptysingular_pointsNotImplementedError)r,r$coeffsabcdefx_regy_regxyzs r& regular_pointzImplicitRegion.regular_pointNs6== t~~ ! #(DNN1,=aggNOPQRT T  A %{{a,7,QQ)Aq!Qa41Q3q5=#?4#?#?#HLE5e|#$?4#>#>#GLE5e|# t~~ ! #nnGAq!sB f"3^fE#HMM1eQ2F$GXYIZcdcjcjktt %ud8HMM1eUVX]J^<_3`.abc.deef f t##% &! +,,./2 2!##r'c||fdk7xr ||fdk7xr|dzd|z|zk(xr||fdk7}|s td|dk7r=d|z|zd|z|zz d|z|z|dzz } }|dk7r| |z } ||| zz d|zz } nDd}nA|dk7rz8ImplicitRegion._regular_point_ellipse..s'As 'A) rRrlimit_denominatorpqrrrabsrrrr8r free_symbolsdictfromkeysrintrnextiterr rIntegersrrr9rr?r@tuple)/r,rDrErFrGrHrIDrSKLk1k2l1l2ga1b1c1a2r1b2r2c2r3g1g2g3rLrMrNeq solutionsflagsolsymssol_zsyms_zrbp_valuesrci subs_sol_zq_valuesrJrKr^s/ @r&r=z%ImplicitRegion._regular_point_ellipses!A1 AB !MNNAv!q&qsQqSyMaadF1a4K!A#a%'!)+ac!eAqDj81QT6!8A:E1QPQT RS SadF1a4K!A#a%'!)+a1fQhqj8a0A!a%0B !MNN --f5A --f5ASS!##BSS!##BB AR%BR%Bb5!Bb$s2w**BbeBb$s2w**BbeBb$s2w**BbeBCBK$AABABABRBBBBBBBRBBBBBBBRBBBBBBBg&GAq!AqD2ad7"R1W,B#BI9~" !MNND " c{//mmD!,AA:D!%#w8"//F6{a' f.#-ajj(2eQh'iH#+#4#4)*A)-d8n)=A %&4yA~"''AS'A"A1a$'1a DE" H !MNN2r A2r A2r A!A!AAv!q&Q1qs+Q1qs+%< aQqSUQqS!+QuWq1Q3/ %< QqSUQqS!+QuWq1Q3/%< r'c|jg}|jD]}|t|j|gz }t|t |jS)a 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 rr9)r,eq_listvars r&rAzImplicitRegion.singular_pointssR"==/>> 2C T]]C01 1G 27D$899r'c`t|tr |j}|j}t |j D]\}}|j ||||z}t|}t|jdk7r |j}td|D}|S|}t|}|S)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 rc32K|]}t|ywrr)r\terms r&r_z.ImplicitRegion.multiplicity..Ps94L&9s) rrr*r$ enumerater#r?r r8minr)r,point modified_eqrrtermsms r& multiplicityzImplicitRegion.multiplicity2s& eU #JJEmm / @FAs%**3eAh?K @[) { A %$$E9599A  EU#Ar'cp|j}|j}|dk(rht|jdk(r|fSt|jdk(r+|j\}}t t ||d}||fSt d}|dk(rN||}nIt|jdk7rt |jd}n|j}t|jdk7r||j} | D]g} t| j} tj| dt| dk7rtfd| D} |j| |dz k(se| }nt|dk(r t |} t|jD]\} }| j!|||| z} t#| } dx}}| j$D]}t'||k(r||z }||z }d|z}t)|ts|f}t|jdk(r|d}|dk(rt+dd }n t+dd }t+|d }|j!|jd||jd|i}|j!|jd||jd|i}|||z zj!|d|dz}|||z zj!|d|dz}||fSt|jd k(r|\}}d |vrt+d d }n t+d d }t+|d }t+|d }|j!|jd||jd||jd|i}|j!|jd||jd||jd|i}|||z zj!|d|dz}|||z zj!|d|dz}|||z zj!|d|dz}|||fSt )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 r/r4rc3@K|]}|jywrrZr[s r&r_z:ImplicitRegion.rational_parametrization..s"?1166#;"?r`rWr]s_T)realr6rr_)r$r1r8r#r9rrBrArOr rerfrgrlrrr?r r*rrr)r, parameters reg_pointr$r1rLrMy_parrrAspointrrrrhnhn_1r parameter1r]tx_par parameter2rz_parr^s @r&rational_parametrizationz'ImplicitRegion.rational_parametrizationWsA^== Q;4>>"a' {"T^^$)~~1Xh23A6%x)++ Q;$!t++-.!3 !5!5!78;E ..0E t##% &! +"224O) f~22mmD!,t9>""?"??F$$V, :"E  u:?%' '  / @FAs%**3eAh?K @[)  T$$ DD!V+d     $w*e,$J t~~ ! ##AJS Dt,Cd+ .A$..+Qq0A1EFB99dnnQ/DNN14EqIJDR[&&q!,uQx7ER[&&q!,uQx7E%<   A %%/ "J j Dt,Cd+ .A .A$..+Qq0A1dnnUVFWYZ[\B99dnnQ/DNN14Eq$..YZJ[]^_`DR[&&q!,uQx7ER[&&q!,uQx7ER[&&q!,uQx7E%& &!##r'))rr]N)__name__ __module__ __qualname____doc__r!propertyr#r$r1rOr<r=rArr __classcell__)r%s@r&rrsn&N9++5$nO4z x:.#JT$r'rct|dk7r t|d}|d}t|}|j|dz}|j||z}|j|dz}|j|dj|d}|j|dj|d}|j|dj|d} |||||| fS)Nr4rr/)rrRr coeff) r#r$rLrMrDrErFrGrHrIs r&r;r;sH"l! A! AhHq!tAqsAq!tAq!""1a(Aq!""1a(Aq!""1a(A aAq! r'N)$sympy.core.numbersrsympy.core.singletonrsympy.core.symbolr$sympy.functions.elementary.complexesr(sympy.functions.elementary.miscellaneousrsympy.polys.polytoolsrsympy.sets.setsr sympy.corer r r r rrsympy.core.sortingrr sympy.solversrrr sympy.polysrsympy.geometryrsympy.ntheory.factor_rrr;rr'r&rsI'"%59%&>>&%<<$ &Z$UZ$x r'