K ir ddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZmZdd lmZmZmZmZmZdd lmZdd lmZdd lmZmZdd lmZm Z ddl!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z0ddl1m2Z2m3Z3m4Z4ddl5m6Z6ddl7m8Z8m9Z9ddl:m;Z;ddlZ>ddl?m@Z@ddlAmBZBmCZCddlDmEZEddlFmGZGddlHmIZIddlJmKZKmLZLddlMmNZNmOZOmPZPmQZQmRZRd d!gZSGd"d#eTZUGd$d%ZVGd&d'eVZWGd(d)eVZXGd*d+eVZYGd,d-eVZZGd.d/eVZ[Gd0d1eVZ\Gd2d3eVZ]Gd4d5eVZ^Gd6d7eVZ_Gd8d9eVZ`Gd:d;eVZaGd<d=eVZbeXeWeYeZe[e\e]e^e_e`eaebg ZcecDchc]}|jc}Zed>Zfd?Zgd@ZhdAZidBZje dCdDEdFdGfdHZkdIZld|dJZme dCdDEfdKZnd}dLZodMdNjeqeezeo_re dCdDEfdOZsd|dPZtdQZudRZve dCdDEfdSZwdTZxe dCdDEfdUZydVZzd~dXZ{dYZ|e dCdDEfdZZ}d[Z~d\Zd]Zd^Zd_Zd`ZdaZddbZdcZddZdeZdfZdgZddhZdiZddjZdkZdlZdmZdnZddoZdpZe dWdDEfdqZddrZddsZddtZduZdvZdwZddxZeZdyZddzZd{ZyFcc}w)) annotations)Add)check_assumptions)Tuple) factor_terms)_mexpand)Mul)Rational int_valued)igcdexilcmigcdinteger_nthrootisqrt)Eq)S)default_sort_keyordered)Symbolsymbols)_sympify)jacobiremoveinvertiroot)sign)floor)sqrt)MutableDenseMatrix)divisors factorint perfect_power) nextprime) is_squareisprime)symmetric_residue)sqrt_mod sqrt_mod_iter)GeneratorsNeeded)Poly factor_list)signsimp) solveset_real)numbered_symbols)as_int filldedent) is_sequencesubsets permute_signssigned_permutationsordered_partitions diophantine classify_diopcDeZdZdZfdZfdZdZdZdZdZ xZ S)DiophantineSolutionSeta Container for a set of solutions to a particular diophantine equation. The base representation is a set of tuples representing each of the solutions. Parameters ========== symbols : list List of free symbols in the original equation. parameters: list List of parameters to be used in the solution. Examples ======== Adding solutions: >>> from sympy.solvers.diophantine.diophantine import DiophantineSolutionSet >>> from sympy.abc import x, y, t, u >>> s1 = DiophantineSolutionSet([x, y], [t, u]) >>> s1 set() >>> s1.add((2, 3)) >>> s1.add((-1, u)) >>> s1 {(-1, u), (2, 3)} >>> s2 = DiophantineSolutionSet([x, y], [t, u]) >>> s2.add((3, 4)) >>> s1.update(*s2) >>> s1 {(-1, u), (2, 3), (3, 4)} Conversion of solutions into dicts: >>> list(s1.dict_iterator()) [{x: -1, y: u}, {x: 2, y: 3}, {x: 3, y: 4}] Substituting values: >>> s3 = DiophantineSolutionSet([x, y], [t, u]) >>> s3.add((t**2, t + u)) >>> s3 {(t**2, t + u)} >>> s3.subs({t: 2, u: 3}) {(4, 5)} >>> s3.subs(t, -1) {(1, u - 1)} >>> s3.subs(t, 3) {(9, u + 3)} Evaluation at specific values. Positional arguments are given in the same order as the parameters: >>> s3(-2, 3) {(4, 1)} >>> s3(5) {(25, u + 5)} >>> s3(None, 2) {(t**2, t + 2)} ct|t|s tdt|s tdt ||_t ||_y)Nz$Symbols must be given as a sequence.z'Parameters must be given as a sequence.)super__init__r1 ValueErrortupler parameters)self symbols_seqr? __class__s k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/solvers/diophantine/diophantine.pyr<zDiophantineSolutionSet.__init__fsN ;'CD D:&FG G[)  +ct|t|jk7r-tdt|jdt|t|}t t|D]M}||}t |t us| js(| |vs.|Dcgc]}|j| |}}Ot|)t|ycc}w)Nz!Solution should have a length of z, not ) lenrr=setrangetypeint is_Symbolsubsr;addr)r@solutionargsix_rBs rCrMzDiophantineSolutionSet.addrs x=C - -cRVR^R^N_ademanop p8}s8}% =A A7c>rnn!43;z3DiophantineEquationType.__init__..s>Q:a=>zCoefficients should be Integers)rexpandequation free_symbolslistsortrr=as_coefficients_dictcoeffallvalues TypeErrorr* total_degree homogeneousrGhomogeneous_orderrF dimension _parameters)r@ryrzs rCr<z DiophantineEquationType.__init__s *111=  # ,D  $T]]%?%? @D     " "'7 " 8  JK K]]779 >$***;*;*=>>=> > /<<>DJJ.&)$**oD>> from sympy.solvers.diophantine.diophantine import Univariate >>> from sympy.abc import x >>> Univariate((x - 2)*(x - 3)**2).solve() # solves equation (x - 2)*(x - 3)**2 == 0 {(2,), (3,)} univariatec |jdk(SNrwrrs rCrzUnivariate.matchess~~""rDNc|j|t|j|j}t |j |jdj tjD]}|j|f|S)Nr?r) rr9rzr?r-ry intersectrIntegersrM)r@r?rr]rPs rCrzUnivariate.solvesk z"'(9(9dooVt}}d.?.?.BCMMajjY A JJt   rDrrcrdrerfrkrrrrDrCrrs" D#rDrc"eZdZdZdZdZddZy)Lineara Representation of a linear diophantine equation. A linear diophantine equation is an equation of the form `a_{1}x_{1} + a_{2}x_{2} + .. + a_{n}x_{n} = 0` where `a_{1}, a_{2}, ..a_{n}` are integer constants and `x_{1}, x_{2}, ..x_{n}` are integer variables. Examples ======== >>> from sympy.solvers.diophantine.diophantine import Linear >>> from sympy.abc import x, y, z >>> l1 = Linear(2*x - 3*y - 5) >>> l1.matches() # is this equation linear True >>> l1.solve() # solves equation 2*x - 3*y - 5 == 0 {(3*t_0 - 5, 2*t_0 - 5)} Here x = -3*t_0 - 5 and y = -2*t_0 - 5 >>> Linear(2*x - 3*y - 4*z -3).solve() {(t_0, 2*t_0 + 4*t_1 + 3, -t_0 - 3*t_1 - 3)} linearc |jdk(Sr)rrs rCrzLinear.matchess  A%%rDNc|j||j}|j}d|vr|d }nd}t||j}|j}t |dk(r+t |||d\}} | s|j|f|S |D cgc]} ||  } } g} t |dkDr| jt| d| d| d| dz| d<| d| dz| d<tt | dz ddD]<} t| d| | }| d|z| d<| | |z| | <| jd|>| j| d g}t| | D]H\}}gg}}tj|D]}|jr|t j"}}|d}n*|j%\}}||j'|dz}t)||||x}\}}|t j"ur d|vrj|ccSt+|tr"|j,d|z|j,dz}t+|tr"|j,d|z|j,dz}|j||j| |jt|t|}K|j||j||Scc} w)Nrwrr)rr~rzr9r?rFdivmodrMappendrrHinsertrYr make_args is_IntegerrOne as_coeff_Mulindexbase_solution_linear isinstancerO)r@r?rr~varrtr]paramsqrr`ABrPgcdrUAiBitot_xtot_yargkr_pnewsolsol_xsol_ys rCrz Linear.solves z"  :q AA'H"" s8q=!U3q6]+DAq A4 M( T # #!U1X # #  s8a< HHT!B%2' (bEQqTMAbEbEQqTMAbE3q6A:q"- !1Q41&ts{!ts{!C  ! 23 h !Qi FBr5E}}Q' $>>qA!!9D++-DAq!&,,q/A"56D%9!RT%JJleU:s{% "%- % 1 a%**Q- ?!%- % 1 a%**Q- ? U# U#1 $4   S%[ )U A= @  9 I $s KrrrrDrCrrs2 D&drDrc$eZdZdZdZdZdddZy)BinaryQuadratica Representation of a binary quadratic diophantine equation. A binary quadratic diophantine equation is an equation of the form `Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0`, where `A, B, C, D, E, F` are integer constants and `x` and `y` are integer variables. Examples ======== >>> from sympy.abc import x, y >>> from sympy.solvers.diophantine.diophantine import BinaryQuadratic >>> b1 = BinaryQuadratic(x**3 + y**2 + 1) >>> b1.matches() False >>> b2 = BinaryQuadratic(x**2 + y**2 + 2*x + 2*y + 2) >>> b2.matches() True >>> b2.solve() {(-1, -1)} References ========== .. [1] Methods to solve Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0, [online], Available: https://www.alpertron.com.ar/METHODS.HTM .. [2] Solving the equation ax^2+ bxy + cy^2 + dx + ey + f= 0, [online], Available: https://web.archive.org/web/20160323033111/http://www.jpr2718.org/ax2p.pdf binary_quadraticcB|jdk(xr|jdk(SNrrrrs rCrzBinaryQuadratic.matches!  A%=$..A*==rDNc h;<=>?@ABC|j||j}|j}|\}}||dz}|||z}||dz} ||;||<|tj=t ||| ;<=D cgc] } t | c} \}}} ;<=t||j} | j\C} |dzd|z| zz } |dk(r| dk(r|dk7r;>st%dd }A@z|dzz;|zzA=zz}t'||j)tj*}|D]5}t-A|z?Bz|zz|z }| j|d|df7| St/|r<=>?@BCfd };=>@ACfd }t1dt3>D]k} t5A@z| dzz;| zzA=zz>s%t5?Bz@z| dzz<| zz?Bz=zz>sM| j|| || fm| St7| r|dk7rrt9| }t;d d \} }!t=d|z|z| z|!zd|z;z||!z|| zz||!zz|| zz zzd|zdz|z}|(tS||gz|)z} | j|D,cgc] },t |,c},@JW| StW|+}+|+jEdtY|+DtQ;d}|dd}-|dd}.t[d|(dd|)ddzDr|+D]\}}||t9;zz|-|.t9;zzCzz}/||t9;zz |-|.t9;zz Czz}0t=t|/|0zdz }1t=t|/|0z dt9;zz }2|(tS|1|2gz|)z}| j|| St]|(dd|)ddzD,cgc]},|,j^c},}3d}4|-}5|.}6|5dz |3zdk7s|6|3zdk7r3|5|-z;|6z|.zz|5|.z|6|-zz}6}5|4dz }4|5dz |3zdk7r*|6|3zdk7r3|+D]\}7}8t1|4D]} t[d|(tS|7|8gz|)zDr|7t9;|8zz|5t9;|6zzCzz}/|7t9;|8zz |5t9;|6zz Czz}0t|/|0zdz }9t|/|0z dt9;zz }:|(tS|9|:gz|)z}| j||7|-z;|.z|8zz|7|.z|8|-zz}8}7| Scc} wcc}wcc},w#tT$rYwxYwcc},w)NrrrzrrwzT)realc zzzdzzdzzz|zzzz zz|dzz|zzzzzzz Srr)uEF_cegsqcts rCz'BinaryQuadratic.solve..8sp3q AqD(8A!C ! OQ;N(N+,S571a4.;s]AbA QsU1WQY8I(I+.q5A:!+;c!e+C*J)KrDzu, vrrc3.K|] \}}| | fywrTr)rsXYs rCruz(BinaryQuadratic.solve..ys!Htq!A2r(!Hsc32K|]}t|ywrTrrrsrRs rCruz(BinaryQuadratic.solve..s<z!}.s"OQ:a="Orv)0rrzr~rr _remove_gcdr/r9r?rrMr rryrrrrrr-rr diop_solver rHabs divisibler$rrrrrF check_paramrVris_solution_quadpop_transformation_to_DN_find_DNdiop_DNMatrixr=rGr{rr r)Dr@r?rrr~rQyrrCrPr]rdiscrrrdivtermdx0y0ssolnartreqrootsrootanssolve_xsolve_yz0r`rNs0t0numx_0y_0PQN solns_pellrRTU_a_bx_ny_nLrT_kU_krrXtYtrrrrrrrrrsD @@@@@@@@@rCrzBinaryQuadratic.solves  z" 1 !Q$K !A#J !Q$K !H !H !%%L/:1aAq!/LM!F1IM1aAq(T__=  11qs1u  6a1fasQqSyA~a|1JJAw'a|1JJA2w'h eqsQqSy)s3tdU335A"1q5!,EB%acAaCi31 $*1q5!$4EB#$ & B8 45` EaZAv#DMMAGMMZ[]^Y_M`3DJJQa123| uGDAJ&FFQKAhAhsU1Ws1u_s.AQq!tac)CE1B)"a0::1::FE %5(Q3q4)?@ CFCF#345\ U ]OOGKKG$As2w/C%c!eBEkAbD&83q5&@"E%aeAgb!emad&:QsU1W&DbI"JJ WR['AB CF su AvKvt41aCE!GAI!AqsQqSy1Q31'< ==aCE!GAIq1u%&()!Aa ! 45&b!,& 3FBB$2+",qt3CC&AaCE*CBG*!,C!"f-B1G{3QqSUJGH1L"-c3!Az"JC)FMM3/CNN+CSA"JJSz2 3^ C$DMMDbD JPP]^`a\bPcJJquuwtt}-@ s)e4DAqC'DAq AJ1u(%FB!c2Y%#%#r%A !&!Q. 01 4A% & q+A!F1I+A B%%%h S!_ !!!HtJ7G!HHAqMaDGaDG D>vrDrceZdZdZdZdZy)InhomogeneousTernaryQuadraticz Representation of an inhomogeneous ternary quadratic. No solver is currently implemented for this equation type. inhomogeneous_ternary_quadraticct|jdk(r|jdk(sy|jsy|j S)NrrF)rrrrrs rCrz%InhomogeneousTernaryQuadratic.matchess9!!Q&4>>Q+>))))rDNrcrdrerfrkrrrDrCrrs -D*rDrc$eZdZdZdZdZdddZy)!HomogeneousTernaryQuadraticNormalaQ Representation of a homogeneous ternary quadratic normal diophantine equation. Examples ======== >>> from sympy.abc import x, y, z >>> from sympy.solvers.diophantine.diophantine import HomogeneousTernaryQuadraticNormal >>> HomogeneousTernaryQuadraticNormal(4*x**2 - 5*y**2 + z**2).solve() {(1, 2, 4)} $homogeneous_ternary_quadratic_normalc0|jdk(r|jdk(sy|jsy|jsy|jDcgc]}|j|s|c}t dk(xrt fd|jDScc}w)NrrFc3,K|] }|dzv ywrNrrsrPnonzeros rCruz.s(TQA(Trrrrr~rFrrzr@rr's @rCrz)HomogeneousTernaryQuadraticNormal.matchess!!Q&4>>Q+>%%"jj:DJJqM1:7|q TS(T$BSBS(T%TT;s BBNc |j||j}|j}|\}}}||dz}||dz} ||dz} t|| | d\\} } } \}}}\}}}| |z}| |z}t ||j }|dkr|dkr|St | |z| t | |z|t | |z||St||\}}}t|t|\}}||z}||z}t|||\}}}t|t| k(r0t|||t|t|t|\}}}nvt|t| k(r0t|||t|t|t|\}}}n/t|||t|t|t|\}}}t|||}t|||}t|||}t| | | }t||z| z}t||z| z}t||z| z}|jt||||S)NrT)stepsrr)rrzr~ sqf_normalr9r?r'descent _rational_pqrrrholzer reconstructr rM)r@r?rrr~rQrrrbrtsqf_of_asqf_of_bsqf_of_ca_1b_1c_1a_2b_2c_2rrr]z_0r r rsq_lcms rCrz'HomogeneousTernaryQuadraticNormal.solvesi z" 1a !Q$K !Q$K !Q$K q!Qd + I&8Xc3#sCDH DH'H q5QUM cT#Xs # + cT#Xs # + cT#Xs # +M1 S#c3s8,Q q q#Cc2 S# 7d1g "3S#c(CHc#hOMCc !WQ "3S#c(CHc#hOMCc"3S#c(CHc#hOMCc#sC(#sC(#sC(h(3#f*()#f*()#f*() ;sC-. rDrrrrrDrCr!r!s  2D U9rDr!c"eZdZdZdZdZddZy)HomogeneousTernaryQuadratica Representation of a homogeneous ternary quadratic diophantine equation. Examples ======== >>> from sympy.abc import x, y, z >>> from sympy.solvers.diophantine.diophantine import HomogeneousTernaryQuadratic >>> HomogeneousTernaryQuadratic(x**2 + y**2 - 3*z**2 + x*y).solve() {(-1, 2, 1)} >>> HomogeneousTernaryQuadratic(3*x**2 + y**2 - 3*z**2 + 5*x*y + y*z).solve() {(3, 12, 13)} homogeneous_ternary_quadraticc2|jdk(r|jdk(sy|jsy|jsy|jDcgc]}|j|s|c}t dk(xrt fd|jD Scc}w)NrrFc3,K|] }|dzv ywr%rr&s rCruz6HomogeneousTernaryQuadratic.matches..)s-Y!adgo-Yr(r)r*s @rCrz#HomogeneousTernaryQuadratic.matches s!!Q&4>>Q+>%%"jj:DJJqM1:LA%Y#-YtGXGX-Y*YZZ;s BBNcR|j||j}|j|\}}}|||g}t||j}d} t fd|Ds||zr_t ||z|z||z|zz||zz } t| d} |jt| d||z | d|S|d|dc|d<|d<| t|\} } }| |j| | |f|S|dzdk(r]|dzdk(r)|d|dc|d<|d<| t|\}} } n|d|dc|d<|d<| t|\} } }n||zs||zr׉|dz}||z}||z}|dz}||z}|dz}i}d |dzz||dz<d |z|z|dzz ||dz<d |z|z|dzz ||dz<d |z|zd|z|zz |||z<d|||z<d|||z<| t||\} } }| |St|| z||zzd|z\}}| |z|z | |z||z}} } n||zdk7r|dzdk(rZ|dzdk(r'|dz}||z}t| |\}}|||}} } nf|d|dc|d<|d<| t|\}} } n>|d|dc|d<|d<| t|\} } }n| t|\} } }| |S|jt| | ||S) Nrc<t|dkDrt|dSy)NrNNN)rFr{)rs rC unpack_solz5HomogeneousTernaryQuadratic.solve..unpack_sol?s3x!|Cy|##rDc3.K|] }|dzywr%rrsrPr~s rCruz4HomogeneousTernaryQuadratic.solve..Ds,15A;,c<t|dt|dzSNrrwr)rs rCrz3HomogeneousTernaryQuadratic.solve..GsC!IAaD ,ArDrorrwrr) rrzr~r9r?anyr6minrMr_diop_ternary_quadraticr/_diop_ternary_quadratic_normal)r@r?r_varrQrrrr]rFsolsrr r r<rrrrrr_coeffr_rr2rr~s @rCrz!HomogeneousTernaryQuadratic.solve+s z"   1a!Qi(H $ ,,,QqSz"51:a<%!*Q,#>1#DE"AB ;qteAaCj[!A$?@ !!Wd1gNCFCF&'>sE'JKMCc Cc?+M A;! QT{a!%a$q'AA *+B3+N O S#"&a$q'AA *+B3+N O S#QqSzU1Q3Z!Q$K!A#J!A#J!Q$K!A#J!Q$K Avq!t  s1uq!t|q!t  s1uq!t|q!t c!eac!emqs qs qs *+B3+O P S#;!M#AcEAcEM1Q371 #A 3q5#a%#SqsqA;!#QT{a'!!Q$K!!A#J+QB21()1a#S*.a$q'AA(23J3PU3V(W S#&*!Wd1gNCFCF$./FsE/R$SMCc!++I#u+U V S# ;M ;sC-. rDrrrrDrCr?r?s  +D [hrDr?ceZdZdZdZdZy)InhomogeneousGeneralQuadraticz Representation of an inhomogeneous general quadratic. No solver is currently implemented for this equation type. inhomogeneous_general_quadraticc|jdk(r|jdk\sy|jsytd|jDxr |j S)NrrFTc34K|]}|jywrTis_Mulrsrs rCruz8InhomogeneousGeneralQuadratic.matches..01880rrrrMr~rrs rCrz%InhomogeneousGeneralQuadratic.matchessM!!Q&4>>Q+>%%0TZZ00I9I9I5IIrDNrrrDrCrUrUs -DJrDrUceZdZdZdZdZy)HomogeneousGeneralQuadraticz~ Representation of a homogeneous general quadratic. No solver is currently implemented for this equation type. homogeneous_general_quadraticc|jdk(r|jdk\sy|jsytd|jDxr |j S)NrrFc34K|]}|jywrTrYr[s rCruz6HomogeneousGeneralQuadratic.matches..r\r]r^rs rCrz#HomogeneousGeneralQuadratic.matchessJ!!Q&4>>Q+>%%0TZZ00ET5E5EErDNrrrDrCr`r`s +DFrDr`c"eZdZdZdZdZddZy)GeneralSumOfSquaresa Representation of the diophantine equation `x_{1}^2 + x_{2}^2 + . . . + x_{n}^2 - k = 0`. Details ======= When `n = 3` if `k = 4^a(8m + 7)` for some `a, m \in Z` then there will be no solutions. Refer [1]_ for more details. Examples ======== >>> from sympy.solvers.diophantine.diophantine import GeneralSumOfSquares >>> from sympy.abc import a, b, c, d, e >>> GeneralSumOfSquares(a**2 + b**2 + c**2 + d**2 + e**2 - 2345).solve() {(15, 22, 22, 24, 24)} By default only 1 solution is returned. Use the `limit` keyword for more: >>> sorted(GeneralSumOfSquares(a**2 + b**2 + c**2 + d**2 + e**2 - 2345).solve(limit=3)) [(15, 22, 22, 24, 24), (16, 19, 24, 24, 24), (16, 20, 22, 23, 26)] References ========== .. [1] Representing an integer as a sum of three squares, [online], Available: https://proofwiki.org/wiki/Integer_as_Sum_of_Three_Squares general_sum_of_squarescjdk(rjdk\syjsytdjDryt fdjDS)NrrFc34K|]}|jywrTrYr[s rCruz.GeneralSumOfSquares.matches..,Aqxx,r]c3NK|]}|dk7s j|dk(ywrwNr~rsrr@s rCruz.GeneralSumOfSquares.matches..$D!Q!V4::a=A%D %%)rrrrMr~rrs`rCrzGeneralSumOfSquares.matchessU!!Q&4>>Q+>%% ,, ,DtzzDDDrDNc |j||j}t|jd }|j}t ||j }|dks|dkr|S|Dcgc]}|jrdnd}}|jddk7} d} t||dD]V} | r4|jt| D cgc] \} } || | zc} } n|j| | dz } | |k(sU|S|Scc}wcc} } w)NrwrrrTzeros) rrzrJr~rr9r?is_nonpositivecountsum_of_squaresrM enumerate)r@r?rrrnr]rQsignsnegstookrrPjs rCrzGeneralSumOfSquares.solves z" A   NN'H q5EAIM8;<1q''Q.<<{{2!#1D1 A 9Q<@41aE!HQJ@A 1 AIDu}   = As *DD rrrrDrCreres@ $DErDrec2eZdZdZdZdZedZddZy)GeneralPythagoreana Representation of the general pythagorean equation, `a_{1}^2x_{1}^2 + a_{2}^2x_{2}^2 + . . . + a_{n}^2x_{n}^2 - a_{n + 1}^2x_{n + 1}^2 = 0`. Examples ======== >>> from sympy.solvers.diophantine.diophantine import GeneralPythagorean >>> from sympy.abc import a, b, c, d, e, x, y, z, t >>> GeneralPythagorean(a**2 + b**2 + c**2 - d**2).solve() {(t_0**2 + t_1**2 - t_2**2, 2*t_0*t_2, 2*t_1*t_2, t_0**2 + t_1**2 + t_2**2)} >>> GeneralPythagorean(9*a**2 - 4*b**2 + 16*c**2 + 25*d**2 + e**2).solve(parameters=[x, y, z, t]) {(-10*t**2 + 10*x**2 + 10*y**2 + 10*z**2, 15*t**2 + 15*x**2 + 15*y**2 + 15*z**2, 15*t*x, 12*t*y, 60*t*z)} general_pythagoreancjdk(rjdk\syjsytdjDryt fdjDryt fdjDsyt tfdjDjdz k(S)NrrFc34K|]}|jywrTrYr[s rCruz-GeneralPythagorean.matches..rir]c3NK|]}|dk7s j|dk(ywrkrlrms rCruz-GeneralPythagorean.matches..s$@aatzz!}!@roc3`K|]%}ttj|'ywrT)r$rr~rms rCruz-GeneralPythagorean.matches.. s#EQ9SA/0Es+.c3NK|]}tj|ywrT)rr~rms rCruz-GeneralPythagorean.matches..$s?qtDJJqM*?s"%)rrrrMr~rrsumrs`rCrzGeneralPythagorean.matchess!!Q&4>>Q+>%% ,, , @4::@ @E$**EE3?DJJ??@DNNUVDVVVrDc |jdz Srrrs rCrzGeneralPythagorean.n_parameters&s~~!!rDNc D|j||j}|j}|j}t ||ddzt ||ddzzt ||ddzzdkr|j D] }|| ||< t ||j}d}t|D]\} } t || dzdk(s| }|j} td| D} | d| |dz dzzz g} | jt|dz D cgc]} d| | z| |dz zc} | d|| gz| |dz}d}t|D]p\} } | |k(s|dkDr| dk(s |dk(r*| dk(r%t|tt|| dz}Dt|| dz}t|t|r|n|dz}rt|D]+\} } ||| ztt|| dzz || <-|j!||Scc} w)Nrrrwrrc3&K|] }|dz ywr%r)rsm_is rCruz+GeneralPythagorean.solve..?s(s#((s)rr~rzrrkeysr9r?rvrextendrHr rr_oddrM)r@r?rr~rrwrpr]rrPr`mithrrlcmrs rCrzGeneralPythagorean.solve*sI z"  NN c!fk" #d5Q1+=&> >eCPQFVWKFXAY Y\] ]zz| )#Cj[c  )(HcN DAqE!q&M"b(    (a(( 1qQx1}$ $ % uQU|>CF ?  3 =s#Hr) rcrdrerfrkrrrrrrDrCr}r}s-  !D W""&rDr}ceZdZdZdZdZy) CubicThuea Representation of a cubic Thue diophantine equation. A cubic Thue diophantine equation is a polynomial of the form `f(x, y) = r` of degree 3, where `x` and `y` are integers and `r` is a rational number. No solver is currently implemented for this equation type. Examples ======== >>> from sympy.abc import x, y >>> from sympy.solvers.diophantine.diophantine import CubicThue >>> c1 = CubicThue(x**3 + y**2 + 1) >>> c1.matches() True cubic_thuecB|jdk(xr|jdk(S)Nrrrrs rCrzCubicThue.matchesjrrDNrrrDrCrrSs( D>rDrc"eZdZdZdZdZddZy)GeneralSumOfEvenPowersas Representation of the diophantine equation `x_{1}^e + x_{2}^e + . . . + x_{n}^e - k = 0` where `e` is an even, integer power. Examples ======== >>> from sympy.solvers.diophantine.diophantine import GeneralSumOfEvenPowers >>> from sympy.abc import a, b >>> GeneralSumOfEvenPowers(a**4 + b**4 - (2**4 + 3**4)).solve() {(2, 3)} general_sum_of_even_powerscjdkDsyjdzdk7rytfdjDsytfdjDS)NrFrrc3xK|]1}|dk7s |jxr|jjk(3ywrk)is_Powexprrms rCruz1GeneralSumOfEvenPowers.matches..s5YqRSWXRX188:):): ::Ys :,:c3NK|]}|dk7s j|dk(ywrkrlrms rCruz1GeneralSumOfEvenPowers.matches..rnro)rrr~rs`rCrzGeneralSumOfEvenPowers.matchessT  1$   q A %YDJJYYDtzzDDDrDNc v|j||j}|j}d}|jD]!}|js||s|j }#t |}|d }t||j} |dks|dkr| S|D cgc]} | jrdnd} } | jddk7} d} t|||D]V}| r4| jt|Dcgc] \}}| ||zc}}n| j|| dz } | |k(sU| S| Scc} wcc}}w)Nrwrrr)rrzr~rrrrFr9r?rsrtpower_representationrMrv)r@r?rrr~r_rrrwr]rQrryrzrrPr{s rCrzGeneralSumOfEvenPowers.solves: z"   AxxE!HEE  H 1XI'H q5EAIM7:;!a&&A-;;tzz"~"%aA. A )A,?$!QDGAI?@ 1 AIDu}   < @s D03D5 rrrrDrCrrns" (DErDrcP t|}|dk(r|St|Dcgc]}||z c}S#t$rWttd|}t |dkr|cYSt|Dcgc]}|j dncc}wc}}Yt $r t dwxYwcc}w)Nrrz-_remove_gcd(a,b,c) or _remove_gcd(*container)rw)rr=r{filterrFas_content_primitiverr>)rQrfxrPs rCrrsI !H Av "1!Q$" ## = &q/ " r7Q;H ;11))+A.;; < IGHHI#s&- B#.B  B &B B  B cDtt||zt|SrT)rrrrr2s rCr/r/s tAwqy#a& ))rDcbt||\}}t|t|dzkr|S|dzS)Nrrw)rr)r_rwrs rC_nint_or_floorrs3 !Qf$rttAd wxYw#tR$rd}YwxYw#tR$rd}YwxYw#tR$rd}YcwxYw#tR$rd}Y8wxYw#ttVf$rBtY|}|djZr|ddk7rt!||dz |||cYS|d}YLwxYw)a Simplify the solution procedure of diophantine equation ``eq`` by converting it into a product of terms which should equal zero. Explanation =========== For example, when solving, `x^2 - y^2 = 0` this is treated as `(x + y)(x - y) = 0` and `x + y = 0` and `x - y = 0` are solved independently and combined. Each term is solved by calling ``diop_solve()``. (Although it is possible to call ``diop_solve()`` directly, one must be careful to pass an equation in the correct form and to interpret the output correctly; ``diophantine()`` is the public-facing function to use in general.) Output of ``diophantine()`` is a set of tuples. The elements of the tuple are the solutions for each variable in the equation and are arranged according to the alphabetic ordering of the variables. e.g. For an equation with two variables, `a` and `b`, the first element of the tuple is the solution for `a` and the second for `b`. Usage ===== ``diophantine(eq, t, syms)``: Solve the diophantine equation ``eq``. ``t`` is the optional parameter to be used by ``diop_solve()``. ``syms`` is an optional list of symbols which determines the order of the elements in the returned tuple. By default, only the base solution is returned. If ``permute`` is set to True then permutations of the base solution and/or permutations of the signs of the values will be returned when applicable. Details ======= ``eq`` should be an expression which is assumed to be zero. ``t`` is the parameter to be used in the solution. Examples ======== >>> from sympy import diophantine >>> from sympy.abc import a, b >>> eq = a**4 + b**4 - (2**4 + 3**4) >>> diophantine(eq) {(2, 3)} >>> diophantine(eq, permute=True) {(-3, -2), (-3, 2), (-2, -3), (-2, 3), (2, -3), (2, 3), (3, -2), (3, 2)} >>> from sympy.abc import x, y, z >>> diophantine(x**2 - y**2) {(t_0, -t_0), (t_0, t_0)} >>> diophantine(x*(2*x + 3*y - z)) {(0, n1, n2), (t_0, t_1, 2*t_0 + 3*t_1)} >>> diophantine(x**2 + 3*x*y + 4*x) {(0, n1), (-3*t_0 - 4, t_0)} See Also ======== diop_solve sympy.utilities.iterables.permute_signs sympy.utilities.iterables.signed_permutations Trmroz/syms should be given as a sequence, e.g. a list)permuteas_AddFrwc34K|]}|jywrT) is_number)rsrs rCruzdiophantine..Fs3qq{{3r]z@ Equation should be a polynomial with Rational coefficients.rrc32K|]}|d|dzywrrwNr)rsrs rCruzdiophantine..l$@1QqT!A$Y$@rvrc32K|]}|d|dzywrr)rsrQs rCruzdiophantine..rrvrf)paramsymsr_dict)evaluatec38K|]}t|ywrT)merge_solution)rsrrvar_ts rCruzdiophantine..sLCsE37Lszunhandled type: %src3RK|]\}}t|fi|jdu!yw)FN)r assumptions0)rsvalrs rCruzdiophantine..s(ba 77uDbs%'c32K|]}t|ywrTrr)rsrs rCruzdiophantine..s*z!}*rvc2|d|dzddzk(SrKr)rQrs rCrzdiophantine..s$AaD1IQA,FrD)=rrrlhsrhsr{rxrzr|rr1rrXrYrHrFr6r>as_numer_denomrrGrrLras_independentr*rMgensas_expr is_polynomialr)AssertionErrorr0r7rerkrr?r!rr2KeyErrorboolrr+ is_Rationalr,rrrr}rMrrrVdiscardis_zerorr3rr4),rrrrrPdict_sym_indexrrwrdsolgoodrr_do_permute_signsdo_permute_signs_varpermute_few_signsr`rtlen_varpermute_signs_forpermute_signs_checkvar_mulxy_coeffx_coeff var1_mul_var2 v1_mul_v2r~v1termsflrRrbaserReq_typerNnull final_soln permuted_signlstpermuted_sign_varrrrs, @@@rCr6r6sL "B"b VVbff_E29949(556 %& t$EGG#0!qCxA0D0s{!%c$c$i0@&A!B%0UG%LN !SAq!23ABNN  "1 ;;5L{{q>Dq>D(D#E!xs3{0C'DAE E !_<< R   2E 21 5 H3AFF3333 YY[!!!  X #1a !fG#((&++!- ,00166$$#& %%'+$))a<"71a=1G#H"G$@$@M&3B &$%iLE$(>#Ad5k B #71a=1G%@&$%beHE#'w-"?DK @ '23+/($,0)\"71a=1G#H"G$@$@M%2B &$%iLE$(>#Ad5k B #71a=1G%@&$%beHE#'w-"?DK @ '23,0($ -1) ( (!WIEO  5DFa)$e<q'4%0==?4dE*  +00166"'' ) ) HH^C9 : $$#((&++ !! KKL8L L&&:W&DE E-F0 LL !SX D BGGCTN+33 bSVW[]`Sab b HHTNJ$ *c* * #M#$6 7 !!-0"=-.6"FLM #C !!-0%$'(;C(@$A!!!"34s#s#!$" U1BNF n -E $CDE EET (&$%E& (&$%E&" (&$%E& (&$%E&& * + _ a5  A!r"Q%xu4Q Q1 sAY Y Y ?YY+Y: YY(Y0)Y)YYY A9Y B%[ 1Z64[ +Z3A[ Z)4[ Z;?[ YY Y$Z Z[ Z[  Z&"[ %Z&&[ ) Z84[ 7Z88[ ; [ [ [  [ A\\\c4g}d|vryt|}tddd}|D];}||vr|jt|"|jt|=t ||D]\}}t |fi|j dusyt|S)a' This is used to construct the full solution from the solutions of sub equations. Explanation =========== For example when solving the equation `(x - y)(x^2 + y^2 - z^2) = 0`, solutions for each of the equations `x - y = 0` and `x^2 + y^2 - z^2` are found independently. Solutions for `x - y = 0` are `(x, y) = (t, t)`. But we should introduce a value for z when we output the solution for the original equation. This function converts `(t, t)` into `(t, t, n_{1})` where `n_{1}` is an integer parameter. NrrwTrw)rstartF)iterr.rnextrYrrr>)rrrNrrr`rsymbs rCrrs C xH~H c4q 9F % : JJtH~ & JJtF| $ % c] T S 6D$5$5 6% ? :rDcztD]2}||js||j|cSy)Nr)all_diop_classesrr)rr diop_types rC _diop_solvers9%: R= "R=&&&&9 9:rDct|d\}}}|tjk(r t||S|tjk(r t ||S|t jk(r t|dS|tjk(r t|dS|tjk(r t||S|tjk(r t|S|tjk(rt|t j"S|t$jk(rt'|t j"S||t(vrt+t-dt/d|z)a= Solves the diophantine equation ``eq``. Explanation =========== Unlike ``diophantine()``, factoring of ``eq`` is not attempted. Uses ``classify_diop()`` to determine the type of the equation and calls the appropriate solver function. Use of ``diophantine()`` is recommended over other helper functions. ``diop_solve()`` can return either a set or a tuple depending on the nature of the equation. All non-trivial solutions are returned: assumptions on symbols are ignored. Usage ===== ``diop_solve(eq, t)``: Solve diophantine equation, ``eq`` using ``t`` as a parameter if needed. Details ======= ``eq`` should be an expression which is assumed to be zero. ``t`` is a parameter to be used in the solution. Examples ======== >>> from sympy.solvers.diophantine import diop_solve >>> from sympy.abc import x, y, z, w >>> diop_solve(2*x + 3*y - 5) (3*t_0 - 5, 5 - 2*t_0) >>> diop_solve(4*x + 3*y - 4*z + 5) (t_0, 8*t_0 + 4*t_1 + 5, 7*t_0 + 3*t_1 + 5) >>> diop_solve(x + 3*y - 4*z + w - 6) (t_0, t_0 + t_1, 6*t_0 + 5*t_1 + 4*t_2 - 6, 5*t_0 + 4*t_1 + 3*t_2 - 6) >>> diop_solve(x**2 + y**2 - 5) {(-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)} See Also ======== diophantine() FrT) parameterizerz Although this type of equation was identified, it is not yet handled. It should, however, be listed in `diop_known` at the top of this file. Developers should see comments at the end of `classify_diop`. r)r7rrk diop_linearrdiop_quadraticr?diop_ternary_quadraticr!diop_ternary_quadratic_normalr}diop_general_pythagoreanrdiop_univariaterediop_general_sum_of_squaresrInfinityrdiop_general_sum_of_even_powers diop_knownr=r0r)rrrr~rs rCrr s4`(%8C&++2u%% O(( (b%(( /44 4%bt<< 5:: :,RdCC &++ +'E22 JOO #r"" ',, ,*2QZZ@@ *// /.rDDwj8Z) " 07 :< >> from sympy.solvers.diophantine import classify_diop >>> from sympy.abc import x, y, z, w, t >>> classify_diop(4*x + 6*y - 4) ([x, y], {1: -4, x: 4, y: 6}, 'linear') >>> classify_diop(x + 3*y -4*z + 5) ([x, y, z], {1: 5, x: 1, y: 3, z: -4}, 'linear') >>> classify_diop(x**2 + y**2 - x*y + x + 5) ([x, y], {1: 5, x: 1, x**2: 1, y**2: 1, x*y: -1}, 'binary_quadratic') z * cxt|d\}}}|tjk(rd}|td|t |fzd}t|j |}||dgt |j z}t |dkDrt|dStdgt |j zSy) am Solves linear diophantine equations. A linear diophantine equation is an equation of the form `a_{1}x_{1} + a_{2}x_{2} + .. + a_{n}x_{n} = 0` where `a_{1}, a_{2}, ..a_{n}` are integer constants and `x_{1}, x_{2}, ..x_{n}` are integer variables. Usage ===== ``diop_linear(eq)``: Returns a tuple containing solutions to the diophantine equation ``eq``. Values in the tuple is arranged in the same order as the sorted variables. Details ======= ``eq`` is a linear diophantine equation which is assumed to be zero. ``param`` is the parameter to be used in the solution. Examples ======== >>> from sympy.solvers.diophantine.diophantine import diop_linear >>> from sympy.abc import x, y, z >>> diop_linear(2*x - 3*y - 5) # solves equation 2*x - 3*y - 5 == 0 (3*t_0 - 5, 2*t_0 - 5) Here x = -3*t_0 - 5 and y = -2*t_0 - 5 >>> diop_linear(2*x - 3*y - 4*z -3) (t_0, 2*t_0 + 4*t_1 + 3, -t_0 - 3*t_1 - 3) See Also ======== diop_quadratic(), diop_ternary_quadratic(), diop_general_pythagorean(), diop_general_sum_of_squares() FrNz%s_0:%iTrrr) r7rrkrrFrr?r{r>)rrrr~rr?r]s rCrrsP*"E:C FKK   eSX->!>MJ!!Z!8 =aSV%6%6!778F v;?<? "$F$5$5 667 7 rDc6t|||\}}}|dk(r|y|dkr| }||z| |zfStt|t|\}}}|t|z}|t|z}||zry| ||z||zfS|dkr| }||z||zz||z||zz fS)a Return the base solution for the linear equation, `ax + by = c`. Explanation =========== Used by ``diop_linear()`` to find the base solution of a linear Diophantine equation. If ``t`` is given then the parametrized solution is returned. Usage ===== ``base_solution_linear(c, a, b, t)``: ``a``, ``b``, ``c`` are coefficients in `ax + by = c` and ``t`` is the parameter to be used in the solution. Examples ======== >>> from sympy.solvers.diophantine.diophantine import base_solution_linear >>> from sympy.abc import t >>> base_solution_linear(5, 2, 3) # equation 2*x + 3*y = 5 (-5, 5) >>> base_solution_linear(0, 5, 7) # equation 5*x + 7*y = 0 (0, 0) >>> base_solution_linear(5, 2, 3, t) # equation 2*x + 3*y = 5 (3*t - 5, 5 - 2*t) >>> base_solution_linear(0, 5, 7, t) # equation 5*x + 7*y = 0 (7*t, -5*t) rrrr)rr rr)rtrr2rrrrs rCrrs>!Q"GAq!Av 9 q5A!aRT{s1vs1v&IBA$q'MB$q'MB1uy"ad|1u B bD1Q3J"qs ##rDct|d\}}}|tjk(rDt||dj t j Dchc]}t|fc}Sycc}w)a Solves a univariate diophantine equations. Explanation =========== A univariate diophantine equation is an equation of the form `a_{0} + a_{1}x + a_{2}x^2 + .. + a_{n}x^n = 0` where `a_{1}, a_{2}, ..a_{n}` are integer constants and `x` is an integer variable. Usage ===== ``diop_univariate(eq)``: Returns a set containing solutions to the diophantine equation ``eq``. Details ======= ``eq`` is a univariate diophantine equation which is assumed to be zero. Examples ======== >>> from sympy.solvers.diophantine.diophantine import diop_univariate >>> from sympy.abc import x >>> diop_univariate((x - 2)*(x - 3)**2) # solves equation (x - 2)*(x - 3)**2 == 0 {(2,), (3,)} FrrN)r7rrkr-rrrrJ)rrr~rrPs rCrrsf>*"E:C JOO##0 A$! !**-/aQ / /$/sA*c||z S)zN Returns `True` if ``a`` is divisible by ``b`` and `False` otherwise. rrs rCrr<s1u9rDct|d\}}}|tjk(r8||tddg}nd}t t|j |Sy)a Solves quadratic diophantine equations. i.e. equations of the form `Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0`. Returns a set containing the tuples `(x, y)` which contains the solutions. If there are no solutions then `(None, None)` is returned. Usage ===== ``diop_quadratic(eq, param)``: ``eq`` is a quadratic binary diophantine equation. ``param`` is used to indicate the parameter to be used in the solution. Details ======= ``eq`` should be an expression which is assumed to be zero. ``param`` is a parameter to be used in the solution. Examples ======== >>> from sympy.abc import x, y, t >>> from sympy.solvers.diophantine.diophantine import diop_quadratic >>> diop_quadratic(x**2 + y**2 + 2*x + 2*y + 2, t) {(-1, -1)} References ========== .. [1] Methods to solve Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0, [online], Available: https://www.alpertron.com.ar/METHODS.HTM .. [2] Solving the equation ax^2+ bxy + cy^2 + dx + ey + f= 0, [online], Available: https://web.archive.org/web/20160323033111/http://www.jpr2718.org/ax2p.pdf See Also ======== diop_linear(), diop_ternary_quadratic(), diop_general_sum_of_squares(), diop_general_pythagorean() FrNrTrr)r7rrkrrGr)rrrr~rr?s rCrrCseV*"E:C O(((  T!:;JJ?2&,, ,CDD )rDc tt|||f}t|jDcgc]\}}||j |zc}}}t |dk(Scc}}w)z Check whether `(u, v)` is solution to the quadratic binary diophantine equation with the variable list ``var`` and coefficient dictionary ``coeff``. Not intended for use by normal users. r)rXrYritemsxreplacer)rr~rr`repsrPr{rs rCrrxsZ C!Q !D ekkm 0, D` is not a perfect square, which is the same as the generalized Pell equation. The LMM algorithm [1]_ is used to solve this equation. Returns one solution tuple, (`x, y)` for each class of the solutions. Other solutions of the class can be constructed according to the values of ``D`` and ``N``. Usage ===== ``diop_DN(D, N, t)``: D and N are integers as in `x^2 - Dy^2 = N` and ``t`` is the parameter to be used in the solutions. Details ======= ``D`` and ``N`` correspond to D and N in the equation. ``t`` is the parameter to be used in the solutions. Examples ======== >>> from sympy.solvers.diophantine.diophantine import diop_DN >>> diop_DN(13, -4) # Solves equation x**2 - 13*y**2 = -4 [(3, 1), (393, 109), (36, 10)] The output can be interpreted as follows: There are three fundamental solutions to the equation `x^2 - 13y^2 = -4` given by (3, 1), (393, 109) and (36, 10). Each tuple is in the form (x, y), i.e. solution (3, 1) means that `x = 3` and `y = 1`. >>> diop_DN(986, 1) # Solves equation x**2 - 986*y**2 = 1 [(49299, 1570)] See Also ======== find_DN(), diop_bf_DN() References ========== .. [1] Solving the generalized Pell equation x**2 - D*y**2 = N, John P. Robertson, July 31, 2004, Pages 16 - 17. [online], Available: https://web.archive.org/web/20160323033128/http://www.jpr2718.org/pell.pdf rrT generatorrwrrF) all_roots)r square_factor cornacchiarJrrrHrrr=_special_diop_DNrPQarrvr'r&lengthr)rrrrrrQrsN_exactsDsqpqarRprev_Bprev_Gr{r_B_Gframsqmrrs rCrrsl 1u 68O q5I-*d; +A"1c1"gs119~> +1 AaC1:&7JJ!QqSz* + +  Av q5I 6F8O$Q* F G9  !A&JB 6T1I; uT!Wa!e_ad34q89 $A ,Qq!tVaZ; F B7#  $ 1a4|!|1%%Avx C 1v{!Ql!#YFF%.s^ $ !A!Aq"bAbDyFF $ q5Av FF+,J 7V$% %q #AcJQB #Rz mA&$ 7( AI VArT2 (C!#r*AaQ-C!%c Q6!R+a/0 (#'9 1q"bq6Q;qy1VQY;.!3 AfHah#78%an,, Avad1g~q1a8H'H$I$%vad1g~qtAw'F$G$IJ!#R ( ((" Ja  sL>> M  M ct|}ttt|dDcic] }||dzz| }}d}d}d\}}d\} } g} t dD]b} ||z|z} | |z|z }||dzz |z}|| |z|z}}| | | z| z} } |dz|| dzzz x}|vsE||}| j ||z|| zfd|dk(r | Sycc}w)a1 Solves the equation `x^2 - Dy^2 = N` for the special case where `1 < N**2 < D` and `D` is not a perfect square. It is better to call `diop_DN` rather than this function, as the former checks the condition `1 < N**2 < D`, and calls the latter only if appropriate. Usage ===== WARNING: Internal method. Do not call directly! ``_special_diop_DN(D, N)``: D and N are integers as in `x^2 - Dy^2 = N`. Details ======= ``D`` and ``N`` correspond to D and N in the equation. Examples ======== >>> from sympy.solvers.diophantine.diophantine import _special_diop_DN >>> _special_diop_DN(13, -3) # Solves equation x**2 - 13*y**2 = -3 [(7, 2), (137, 38)] The output can be interpreted as follows: There are two fundamental solutions to the equation `x^2 - 13y^2 = -3` given by (7, 2) and (137, 38). Each tuple is in the form (x, y), i.e. solution (7, 2) means that `x = 7` and `y = 2`. >>> _special_diop_DN(2445, -20) # Solves equation x**2 - 2445*y**2 = -20 [(445, 9), (17625560, 356454), (698095554475, 14118073569)] See Also ======== diop_DN() References ========== .. [1] Section 4.4.4 of the following book: Quadratic Diophantine Equations, T. Andreescu and D. Andrica, Springer, 2015. Tr rrrw)rrw)rwr)rr rrrHr)rrsqrt_Drrr r G0G1B0B1rUrRrrs rCrrsl1XF' c!f(=NO!adAOAO A A FB FBI q /AV!A!aAQTaA2B2BUQr1uW_$*aD  !B$". / 6    PsC rclt}||z|kDrv|dk(r7t||zd\}}|r|jt|df||k(r|S||zdk(r0t||zd\}}|r|jdt|f|St | t ||z|D]}||dzkr ||}}|||dzzz x} dkr|||z}}|||dzzz x} dkrt | |\} } | rJt| d\}}|s\||k(r ||kr||}}|jt|t|f|S)a: Solves `ax^2 + by^2 = m` where `\gcd(a, b) = 1 = gcd(a, m)` and `a, b > 0`. Explanation =========== Uses the algorithm due to Cornacchia. The method only finds primitive solutions, i.e. ones with `\gcd(x, y) = 1`. So this method cannot be used to find the solutions of `x^2 + y^2 = 20` since the only solution to former is `(x, y) = (4, 2)` and it is not primitive. When `a = b`, only the solutions with `x \leq y` are found. For more details, see the References. Examples ======== >>> from sympy.solvers.diophantine.diophantine import cornacchia >>> cornacchia(2, 3, 35) # equation 2x**2 + 3y**2 = 35 {(2, 3), (4, 1)} >>> cornacchia(1, 1, 25) # equation x**2 + y**2 = 25 {(4, 3)} References =========== .. [1] A. Nitaj, "L'algorithme de Cornacchia" .. [2] Solving the diophantine equation ax**2 + by**2 = m by Cornacchia's method, [online], Available: http://www.numbertheory.org/php/cornacchia.html See Also ======== sympy.utilities.iterables.signed_permutations rwrr)rGrrMrJr(rr) rr2rrRrrrrrm1_rs rCrr]siH 5D1uqy 6a1fa(IAv#a&!%Av q5A:a1fa(IAv!SV% A2fQl?A . ' qAv: !11a4ZrA%a!eqA1a4ZrA%AB "aL 6 Av!a%!1 HHc!fc!f% & ' KrDc#Kt|}dx}}dx}}|}| } |} |} | |z| z} | |z|z|}}| |z|z|}}| |z| z|} }| | | |||f| | z| z } || dzz | z} Dw)a Returns useful information needed to solve the Pell equation. Explanation =========== There are six sequences of integers defined related to the continued fraction representation of `\\frac{P + \sqrt{D}}{Q}`, namely {`P_{i}`}, {`Q_{i}`}, {`a_{i}`},{`A_{i}`}, {`B_{i}`}, {`G_{i}`}. ``PQa()`` Returns these values as a 6-tuple in the same order as mentioned above. Refer [1]_ for more detailed information. Usage ===== ``PQa(P_0, Q_0, D)``: ``P_0``, ``Q_0`` and ``D`` are integers corresponding to `P_{0}`, `Q_{0}` and `D` in the continued fraction `\\frac{P_{0} + \sqrt{D}}{Q_{0}}`. Also it's assumed that `P_{0}^2 == D mod(|Q_{0}|)` and `D` is square free. Examples ======== >>> from sympy.solvers.diophantine.diophantine import PQa >>> pqa = PQa(13, 4, 5) # (13 + sqrt(5))/4 >>> next(pqa) # (P_0, Q_0, a_0, A_0, B_0, G_0) (13, 4, 3, 3, 1, -1) >>> next(pqa) # (P_1, Q_1, a_1, A_1, B_1, G_1) (-1, 1, 1, 4, 1, 3) References ========== .. [1] Solving the generalized Pell equation x^2 - Dy^2 = N, John P. Robertson, July 31, 2004, Pages 4 - 8. https://web.archive.org/web/20160323033128/http://www.jpr2718.org/pell.pdf rrwr)r) P_0Q_0rsqDA2r$A1B2r"G2P_iQ_ia_is rCrrsJ (CKBKB B B C C SyS R"bBR"bBR"bB3RR''#gm36zc! sA"A$c t|}t|}g}t|d}|dd}|dk(r5|dkrdgS|dk(rd|fgSt|d\}}|r||z|f| |z|fgSdgSt|dk(r t||S|dkDr*d}tt ||dz zd|zz dddz} nKtt ||z  d\}}|s|dz }tt ||dzzd|zz  dddz} t || D]W} t||| dzzzd\} }|s|j | ft| | | | ||rD|j| | fY|S#t $rd}YMwxYw)a Uses brute force to solve the equation, `x^2 - Dy^2 = N`. Explanation =========== Mainly concerned with the generalized Pell equation which is the case when `D > 0, D` is not a perfect square. For more information on the case refer [1]_. Let `(t, u)` be the minimal positive solution of the equation `x^2 - Dy^2 = 1`. Then this method requires `\sqrt{\\frac{\mid N \mid (t \pm 1)}{2D}}` to be small. Usage ===== ``diop_bf_DN(D, N, t)``: ``D`` and ``N`` are coefficients in `x^2 - Dy^2 = N` and ``t`` is the parameter to be used in the solutions. Details ======= ``D`` and ``N`` correspond to D and N in the equation. ``t`` is the parameter to be used in the solutions. Examples ======== >>> from sympy.solvers.diophantine.diophantine import diop_bf_DN >>> diop_bf_DN(13, -4) [(3, 1), (-3, 1), (36, 10)] >>> diop_bf_DN(986, 1) [(49299, 1570)] See Also ======== diop_DN() References ========== .. [1] Solving the generalized Pell equation x**2 - D*y**2 = N, John P. Robertson, July 31, 2004, Page 15. https://web.archive.org/web/20160323033128/http://www.jpr2718.org/pell.pdf rwrrrF) r/rrrrJrHr=r equivalent) rrrrrrrrL1L2rrQs rC diop_bf_DNr7sZ q Aq A C1 A !QAAv q58O 6F8O$Q* F T1IAqz* *x 1v{q!}1u  SAEAaC11 5a 81 <$c!A#hY2 F !GB c!QU)QqS/22A 6q 9A = 2r]$ 'AadF A6IAv  JJ1v aQB1a0 QB7#$ J F s E## E10E1c`t||z||z|zz |xrt||z||zz |S)aV Returns True if two solutions `(u, v)` and `(r, s)` of `x^2 - Dy^2 = N` belongs to the same equivalence class and False otherwise. Explanation =========== Two solutions `(u, v)` and `(r, s)` to the above equation fall to the same equivalence class iff both `(ur - Dvs)` and `(us - vr)` are divisible by `N`. See reference [1]_. No test is performed to test whether `(u, v)` and `(r, s)` are actually solutions to the equation. User should take care of this. Usage ===== ``equivalent(u, v, r, s, D, N)``: `(u, v)` and `(r, s)` are two solutions of the equation `x^2 - Dy^2 = N` and all parameters involved are integers. Examples ======== >>> from sympy.solvers.diophantine.diophantine import equivalent >>> equivalent(18, 5, -18, -5, 13, -1) True >>> equivalent(3, 1, -18, 393, 109, -4) False References ========== .. [1] Solving the generalized Pell equation x**2 - D*y**2 = N, John P. Robertson, July 31, 2004, Page 12. https://web.archive.org/web/20160323033128/http://www.jpr2718.org/pell.pdf )r)rr`rrrrs rCr4r45 s:H QqS1Q3q5[! $ @1Q319a)@@rDcddlm}||||}t|dtr!t |d}t |dz }||zSd}t |}||zS)av Returns the (length of aperiodic part + length of periodic part) of continued fraction representation of `\\frac{P + \sqrt{D}}{Q}`. It is important to remember that this does NOT return the length of the periodic part but the sum of the lengths of the two parts as mentioned above. Usage ===== ``length(P, Q, D)``: ``P``, ``Q`` and ``D`` are integers corresponding to the continued fraction `\\frac{P + \sqrt{D}}{Q}`. Details ======= ``P``, ``D`` and ``Q`` corresponds to P, D and Q in the continued fraction, `\\frac{P + \sqrt{D}}{Q}`. Examples ======== >>> from sympy.solvers.diophantine.diophantine import length >>> length(-2, 4, 5) # (-2 + sqrt(5))/4 3 >>> length(-5, 4, 17) # (-5 + sqrt(17))/4 4 See Also ======== sympy.ntheory.continued_fraction.continued_fraction_periodic r)continued_fraction_periodicrrw) sympy.ntheory.continued_fractionr:rr{rF)r r rr:r`rptnonrpts rCrr\ seDM#Aq!,A!B%!B%jQ! <Q <rDcdt|d\}}}|tjk(r t||Sy)aG This function transforms general quadratic, `ax^2 + bxy + cy^2 + dx + ey + f = 0` to more easy to deal with `X^2 - DY^2 = N` form. Explanation =========== This is used to solve the general quadratic equation by transforming it to the latter form. Refer to [1]_ for more detailed information on the transformation. This function returns a tuple (A, B) where A is a 2 X 2 matrix and B is a 2 X 1 matrix such that, Transpose([x y]) = A * Transpose([X Y]) + B Usage ===== ``transformation_to_DN(eq)``: where ``eq`` is the quadratic to be transformed. Examples ======== >>> from sympy.abc import x, y >>> from sympy.solvers.diophantine.diophantine import transformation_to_DN >>> A, B = transformation_to_DN(x**2 - 3*x*y - y**2 - 2*y + 1) >>> A Matrix([ [1/26, 3/26], [ 0, 1/13]]) >>> B Matrix([ [-6/13], [-4/13]]) A, B returned are such that Transpose((x y)) = A * Transpose((X Y)) + B. Substituting these values for `x` and `y` and a bit of simplifying work will give an equation of the form `x^2 - Dy^2 = N`. >>> from sympy.abc import X, Y >>> from sympy import Matrix, simplify >>> u = (A*Matrix([X, Y]) + B)[0] # Transformation for x >>> u X/26 + 3*Y/26 - 6/13 >>> v = (A*Matrix([X, Y]) + B)[1] # Transformation for y >>> v Y/13 - 4/13 Next we will substitute these formulas for `x` and `y` and do ``simplify()``. >>> eq = simplify((x**2 - 3*x*y - y**2 - 2*y + 1).subs(zip((x, y), (u, v)))) >>> eq X**2/676 - Y**2/52 + 17/13 By multiplying the denominator appropriately, we can get a Pell equation in the standard form. >>> eq * 676 X**2 - 13*Y**2 + 884 If only the final equation is needed, ``find_DN()`` can be used. See Also ======== find_DN() References ========== .. [1] Solving the equation ax^2 + bxy + cy^2 + dx + ey + f = 0, John P.Robertson, May 8, 2003, Page 7 - 11. https://web.archive.org/web/20160323033111/http://www.jpr2718.org/ax2p.pdf FrN)r7rrkrrrr~rs rCtransformation_to_DNr@ s8\*"E:C O((($S%00)rDc|\}}||dz}|||z}||dz}||}||}|d} t|||||| D cgc] } t| c} \}}}}}} tdd\} } |rtd|z|\} }t|| dz\}}| dz|| z| | zd| dz| ||z||dzzz z| ||z| | |z|z||z|zz d| |z| zi}t | | g|\}}t ddt j| z t | | z ddg|zt ddt j| z t | | z ddg|zfS|rtd|z|\} }t|| dz\}}| dz|| | zd| dz||z| d| ||zd| |z||dzzz i}t | | g|\}}t ddt j| z dddg|zt ddt j| z dddg|zt t | | z dgzfS|rtd|z|\} }t|| dz\}}| dz||z| | zd| dz|| d| dd| |z||dzzz i}t | | g|\}}t dddddt j| z g|zt dddddt j| z g|zt dt | | z gzfSt ddt j|z dddgt ddgfScc} w)NrrwX, YTrr)rr/rr/rrrr)rr~rQrrr2rtrrrrPrrrrrrA_0B_0s rCrr s DAq ad A ac A ad A aA aA aA+6q!Q1a+HIaq IAq!Q1 64 (DAqAaC#1Aq!t$1AqsAaCAqD!QqS1QT6\*:AqsAqs1uqQRsSTu}VWYZ[\Y\]^Y^_(!Q7SaQUU1WqteAgq!45c96!QqSTUVSWRWXYRY[\^_H`;abe;eeeAaC#1Aq!t$1Aq!A#q!Q$!Q1ac1acAadFlK(!Q7SaQUU1WaA./3VAq1557AqRSBT5UVY5Y\befgheidijkdkmnco\p5pppAaC#1Aq!t$1AqsAaCAqD!Q1aAaC!AqD&LI(!Q7SaQ1aeeAg./3VAq1aAEERSGBT5UVY5Y\bdehijkhlglmngnco\p5ppp !Qq!Q* +VQF^ ;;CJsK=cdt|d\}}}|tjk(r t||Sy)a This function returns a tuple, `(D, N)` of the simplified form, `x^2 - Dy^2 = N`, corresponding to the general quadratic, `ax^2 + bxy + cy^2 + dx + ey + f = 0`. Solving the general quadratic is then equivalent to solving the equation `X^2 - DY^2 = N` and transforming the solutions by using the transformation matrices returned by ``transformation_to_DN()``. Usage ===== ``find_DN(eq)``: where ``eq`` is the quadratic to be transformed. Examples ======== >>> from sympy.abc import x, y >>> from sympy.solvers.diophantine.diophantine import find_DN >>> find_DN(x**2 - 3*x*y - y**2 - 2*y + 1) (13, -884) Interpretation of the output is that we get `X^2 -13Y^2 = -884` after transforming `x^2 - 3xy - y^2 - 2y + 1` using the transformation returned by ``transformation_to_DN()``. See Also ======== transformation_to_DN() References ========== .. [1] Solving the equation ax^2 + bxy + cy^2 + dx + ey + f = 0, John P.Robertson, May 8, 2003, Page 7 - 11. https://web.archive.org/web/20160323033111/http://www.jpr2718.org/ax2p.pdf FrN)r7rrkrr?s rCfind_DNrF s8N*"E:C O(((U##)rDc |\}}tdd\}}t||\}}|t||gz|zd}|t||gz|zd} |dz||dzz||z|||zzz|dz||dzzz|||zz|||zz|dz} t| j t ||f|| f} | j }||dz ||dzz |d ||dzz fS)NrBTrrrwr)rrrrrLrYr}) rr~rQrrrrrrr`r simplifieds rCrr7 s0 DAq 64 (DAq e ,DAq 61a&> A q!A 61a&> A q!A AeAqDk AaCac N *QT%1+-= =%( JQuUVxZ WZ_`aZb bB"''#q!fq!f"567J  + + -E !Q$K<ad #eAhYuQT{%: ::rDcddlm}|jr|jst ||g|S|jr|jst ||g|St dd\}}||z||zzj \}}||jzrt ||g|S|||d|||dz } | j \} } t| |S) z If there is a number modulo ``a`` such that ``x`` and ``y`` are both integers, then return a parametric representation for ``x`` and ``y`` else return (None, None). Here ``x`` and ``y`` are functions of ``t``. r)clear_coefficientsrzm, nTrrw)r) sympy.simplify.simplifyrJrrr9rrrr) rQrrrrJrrwrtr_rjunks rCrrH s;{{1<<%q!f@@{{1<<%q!f@@ 64 (DAq aC!A#I + + -DAq133w%q!f@@ Aq !! $'9!Q'?'B BB&&(HD" r& ))rDct|d\}}}|tjtjfvrJt ||}t |dkDrt |d\}}}nd\}}}|rt|||f||S|||fSy)a Solves the general quadratic ternary form, `ax^2 + by^2 + cz^2 + fxy + gyz + hxz = 0`. Returns a tuple `(x, y, z)` which is a base solution for the above equation. If there are no solutions, `(None, None, None)` is returned. Usage ===== ``diop_ternary_quadratic(eq)``: Return a tuple containing a basic solution to ``eq``. Details ======= ``eq`` should be an homogeneous expression of degree two in three variables and it is assumed to be zero. Examples ======== >>> from sympy.abc import x, y, z >>> from sympy.solvers.diophantine.diophantine import diop_ternary_quadratic >>> diop_ternary_quadratic(x**2 + 3*y**2 - z**2) (1, 0, 1) >>> diop_ternary_quadratic(4*x**2 + 5*y**2 - z**2) (1, 0, 2) >>> diop_ternary_quadratic(45*x**2 - 7*y**2 - 8*x*y - z**2) (28, 45, 105) >>> diop_ternary_quadratic(x**2 - 49*y**2 - z**2 + 13*z*y -8*x*y) (9, 1, 5) FrrrEN)r7r?rkr!rOrFr{_parametrize_ternary_quadratic rrrr~rrr r r<s rCrrd sD*"E:C  ' , , - 2 244&c51 s8a< IaLMCc,MCc 1c3e- -C}4rDctfdD}t|jrt||jSt |jrt ||jSy)Nc3.K|] }||zywrTrrHs rCruz*_diop_ternary_quadratic.. s 'AQuQxZ 'rIr)rr?rrr!)rQr~rs ` rCrOrO sf ' ' 'B"2&..0*2DAGGII *2 . 6 6 80$GMMOO 9rDcFt|d\}}}|dvr t||Sy)a< Returns the transformation Matrix that converts a general ternary quadratic equation ``eq`` (`ax^2 + by^2 + cz^2 + dxy + eyz + fxz`) to a form without cross terms: `ax^2 + by^2 + cz^2 = 0`. This is not used in solving ternary quadratics; it is only implemented for the sake of completeness. Frr@r"N)r7_transformation_to_normalr?s rCtransformation_to_normalrU s8*"E:C 44)e444rDc t|}|\}}}tfd|Dsf||z}||z}||z}d} |sd} ||}}tdd| |z fdd| |z fdf} | r$| jdd| j dd| S|dzdk(r|dzdk(rC|d|dc|d<|d<t |} | jdd| j dd| S|d|dc|d<|d<t |} | jdd| j dd| S||zdk7s ||zdk7rԉ|dz} ||z} ||z} |dz}||z}|dz}i}d | dzz||dz<d | z|z| dzz ||dz<d | z|z| dzz ||dz<d | z|zd| z| zz |||z<d|||z<d|||z<t ||}td d dt | d| zz t | d| zz ddddddg |zS||zdk7r|dzdk(r]|dzdk(rtd d gd S|d|dc|d<|d<t |} | jdd| j dd| S|d|dc|d<|d<t |} | jdd| j dd| Stjd S) Nc3.K|] }|dzywr%rrHs rCruz,_transformation_to_normal.. s(quQT{(rIFTrwrrrrwrrrr) rwrrrrwrwrrwr)r{rMrrow_swapcol_swaprTreye)rr~rQrQrrrr2rtswaprrrrrrrrST_0s ` rCrTrT s 9DGAq! (C( ( !A#J !A#J !A#JDaqA QA2a4L1b1"Q$-; <  JJq!  JJq!  QT{a A;! "1vs1v DGT!W)$6A JJq!  JJq! Hq63q6Qa %dE 2 1a 1a QqSzQ%!*/ !Q$K !A#J !A#J !Q$K !A#J !Q$KAvq!t s1uq!t|q!t s1uq!t|q!t c!eac!emqs qs qs 'f5aQ1"qs QrUAaC[!Q1aKLSPP qsq A;! QT{aa$@AA #1vs1v DGT!W)$6A JJq!  JJq! Hq63q6Qa %dE 2 1a 1a ::a=rDct|d\}}}|dvr,tt||d\}}}t|||f||Sy)a Returns the parametrized general solution for the ternary quadratic equation ``eq`` which has the form `ax^2 + by^2 + cz^2 + fxy + gyz + hxz = 0`. Examples ======== >>> from sympy import Tuple, ordered >>> from sympy.abc import x, y, z >>> from sympy.solvers.diophantine.diophantine import parametrize_ternary_quadratic The parametrized solution may be returned with three parameters: >>> parametrize_ternary_quadratic(2*x**2 + y**2 - 2*z**2) (p**2 - 2*q**2, -2*p**2 + 4*p*q - 4*p*r - 4*q**2, p**2 - 4*p*q + 2*q**2 - 4*q*r) There might also be only two parameters: >>> parametrize_ternary_quadratic(4*x**2 + 2*y**2 - 3*z**2) (2*p**2 - 3*q**2, -4*p**2 + 12*p*q - 6*q**2, 4*p**2 - 8*p*q + 6*q**2) Notes ===== Consider ``p`` and ``q`` in the previous 2-parameter solution and observe that more than one solution can be represented by a given pair of parameters. If `p` and ``q`` are not coprime, this is trivially true since the common factor will also be a common factor of the solution values. But it may also be true even when ``p`` and ``q`` are coprime: >>> sol = Tuple(*_) >>> p, q = ordered(sol.free_symbols) >>> sol.subs([(p, 3), (q, 2)]) (6, 12, 12) >>> sol.subs([(q, 1), (p, 1)]) (-1, 2, 2) >>> sol.subs([(q, 0), (p, 1)]) (2, -4, 4) >>> sol.subs([(q, 1), (p, 0)]) (-3, -6, 6) Except for sign and a common factor, these are equivalent to the solution of (1, 2, 2). References ========== .. [1] The algorithmic resolution of Diophantine equations, Nigel P. Smart, London Mathematical Society Student Texts 41, Cambridge University Press, Cambridge, 1998. FrrSrN)r7r{rOrN)rrr~rr r r<s rCparametrize_ternary_quadraticr_ scn*"E:C 444S%@A!D S#- #sOS%) ) 4rDc Jd|vsJ|\}}}t|}|y|jddk\ry|dk(r*|d|dc|d<|d<t|||f||\}}} ||| fS|\} } } tdd\} }}t d|j D}t |jt| | | f| |z| |z|z| |z|zf}|j| d \}}||z} ||zt || z |zz } ||zt || z |zz } t| | | S) NrwrErrzr, p, qTrc3,K|] \}}||zywrTr)rsrr`s rCruz1_parametrize_ternary_quadratic..[ s +TQQqS +s)r) r{rtrNrrrrrLrYrr)rNrQr~r r r<r`y_px_pz_prQrrrr_rreq_1rrs rCrNrN@ sg E>>MCc T A {!~~aA " axqT1Q4 !ad6 #sOQ' S#C}GAq!i.GAq! +U[[] + +B BGGC Aq AcE1S519aeai023 4D   q  .DAq #A 3!A#a% A 3!A#a% A q!Q rDct|d\}}}|tjk(rJt||}t |dkDrt |d\}}}nd\}}}|rt |||f||S|||fSy)a Solves the quadratic ternary diophantine equation, `ax^2 + by^2 + cz^2 = 0`. Explanation =========== Here the coefficients `a`, `b`, and `c` should be non zero. Otherwise the equation will be a quadratic binary or univariate equation. If solvable, returns a tuple `(x, y, z)` that satisfies the given equation. If the equation does not have integer solutions, `(None, None, None)` is returned. Usage ===== ``diop_ternary_quadratic_normal(eq)``: where ``eq`` is an equation of the form `ax^2 + by^2 + cz^2 = 0`. Examples ======== >>> from sympy.abc import x, y, z >>> from sympy.solvers.diophantine.diophantine import diop_ternary_quadratic_normal >>> diop_ternary_quadratic_normal(x**2 + 3*y**2 - z**2) (1, 0, 1) >>> diop_ternary_quadratic_normal(4*x**2 + 5*y**2 - z**2) (1, 0, 2) >>> diop_ternary_quadratic_normal(34*x**2 - 3*y**2 - 301*z**2) (4, 9, 1) FrrrEN)r7r!rkrPrFr{rNrOs rCrrh s>*"E:C 5:::,S%8 s8a< IaLMCc,MCc 1c3e- -C};rDcbtfdD}t||jS)Nc3.K|] }||zywrTrrHs rCruz1_diop_ternary_quadratic_normal.. s )aQq\ )rIr)rr!r)rr~rs ` rCrPrP s) )5 ) )B ,Rc B H H JJrDc tt|||}td|D}tt||Dcgc] \}}||dzzc}}x}\} } } t| | } | | z} | | z} t| | } | | z} | | z} t| | }| |z} | |z} | | z} | |z} | | z} |r||| | | ffS| | | fScc}}w)a Return `a', b', c'`, the coefficients of the square-free normal form of `ax^2 + by^2 + cz^2 = 0`, where `a', b', c'` are pairwise prime. If `steps` is True then also return three tuples: `sq`, `sqf`, and `(a', b', c')` where `sq` contains the square factors of `a`, `b` and `c` after removing the `gcd(a, b, c)`; `sqf` contains the values of `a`, `b` and `c` after removing both the `gcd(a, b, c)` and the square factors. The solutions for `ax^2 + by^2 + cz^2 = 0` can be recovered from the solutions of `a'x^2 + b'y^2 + c'z^2 = 0`. Examples ======== >>> from sympy.solvers.diophantine.diophantine import sqf_normal >>> sqf_normal(2 * 3**2 * 5, 2 * 5 * 11, 2 * 7**2 * 11) (11, 1, 5) >>> sqf_normal(2 * 3**2 * 5, 2 * 5 * 11, 2 * 7**2 * 11, True) ((3, 1, 7), (5, 55, 11), (11, 1, 5)) References ========== .. [1] Legendre's Theorem, Legrange's Descent, https://public.csusm.edu/aitken_html/notes/legendre.pdf See Also ======== reconstruct() c32K|]}t|ywrT)rrsrPs rCruzsqf_normal.. s-A}Q-rvr)rr>rYr)rr2rtr,ABCrrPr{sqfrrrpcpapbs rCr-r- sD aA C -- -Bc#rl;sq1ad7;<>> from sympy.solvers.diophantine.diophantine import square_factor >>> square_factor(24) 2 >>> square_factor(-36*3) 6 >>> square_factor(1) 1 >>> square_factor({3: 2, 2: 1, -1: 1}) # -18 3 See Also ======== sympy.ntheory.factor_.core r)rrXr!r r)rrr_rs rCrr sC,4 ilA qwwy1tq!QT1 221sA ctt||}|jD]\}}|dk7r td||z}|S)a Reconstruct the `z` value of an equivalent solution of `ax^2 + by^2 + cz^2` from the `z` value of a solution of the square-free normal form of the equation, `a'*x^2 + b'*y^2 + c'*z^2`, where `a'`, `b'` and `c'` are square free and `gcd(a', b', c') == 1`. rwza and b should be square-free)r!rrr=)rrrrr_rs rCr1r1 sP $q!*A 1 6<= = Q HrDc|dk(s|dk(r tdt|t|kDrt||\}}}|||fS|dk(ry|dk(ry|dk(ryt||}|y|dz|z |z}|dk(r|ddfSt |D]b}t t||zd\}} | s!t ||z} t|| \} } } t| | z|| zz|| z| z | | z|zcSy) av Return a non-trivial solution to `w^2 = Ax^2 + By^2` using Lagrange's method; return None if there is no such solution. Parameters ========== A : Integer B : Integer non-zero integer Returns ======= (int, int, int) | None : a tuple `(w_0, x_0, y_0)` which is a solution to the above equation. Examples ======== >>> from sympy.solvers.diophantine.diophantine import ldescent >>> ldescent(1, 1) # w^2 = x^2 + y^2 (1, 1, 0) >>> ldescent(4, -7) # w^2 = 4x^2 - 7y^2 (2, -1, 0) This means that `x = -1, y = 0` and `w = 2` is a solution to the equation `w^2 = 4x^2 - 7y^2` >>> ldescent(5, -1) # w^2 = 5x^2 - y^2 (2, 1, -1) References ========== .. [1] The algorithmic resolution of Diophantine equations, Nigel P. Smart, London Mathematical Society Student Texts 41, Cambridge University Press, Cambridge, 1998. .. [2] Cremona, J. E., Rusin, D. (2003). Efficient Solution of Rational Conics. Mathematics of Computation, 72(243), 1417-1441. https://doi.org/10.1090/S0025-5718-02-01480-1 rz!A and B must be non-zero integersrwrwrwrrwrrwrNr)r=rldescentr'r rrr)rrrrrQrr rPrrrDWrrs rCrvrv sT Ava<== 1vA1a.1a!QwAvAvBwAAy AaAAv"ax a[=#CFaK3 6 q'!)Cq#&GAq!r!tacz1Q37AcE!G< < =rDct|t|kDrt||\}}}|||fS|dk(ry|dk(ry|| k(ry||k(rtd|\}}}||z||fSt||}t|||\}}|dz||dzzz |z}t |} || dzz} t|| \} } } t || z||z| zz|| z|| zz| | z| zS)a) Returns a non-trivial solution, (x, y, z), to `x^2 = Ay^2 + Bz^2` using Lagrange's descent method with lattice-reduction. `A` and `B` are assumed to be valid for such a solution to exist. This is faster than the normal Lagrange's descent algorithm because the Gaussian reduction is used. Examples ======== >>> from sympy.solvers.diophantine.diophantine import descent >>> descent(3, 1) # x**2 = 3*y**2 + z**2 (1, 0, 1) `(x, y, z) = (1, 0, 1)` is a solution to the above equation. >>> descent(41, -113) (-16, -3, 1) References ========== .. [1] Cremona, J. E., Rusin, D. (2003). Efficient Solution of Rational Conics. Mathematics of Computation, 72(243), 1417-1441. https://doi.org/10.1090/S0025-5718-02-01480-1 rwrurtrrwrwrr)rr.r'gaussian_reducerr)rrrQrrrr r<rt_2t_1x_1z_1y_1s rCr.r.? s 8 1vA!Q-1a!QwAvAvQBwAv"a.1a!Q{AAq!Q'HC a!CF( q A  C sAv+CAsOMCc s3w3s*CGc#g,=s3ws{ KKrDctfd}|df}||zdk\r|dfn| df}|dz|dzzkr||}}||||||x}kDr@||||z}||d||dzz |d||dzz f}}||||||x}kDr@|d|dz |d|dz f}||||||cxkrd|||zkr|S|S|S)ax Returns a reduced solution `(x, z)` to the congruence `X^2 - aZ^2 \equiv 0 \pmod{b}` so that `x^2 + |a|z^2` is as small as possible. Here ``w`` is a solution of the congruence `x^2 \equiv a \pmod{b}`. This function is intended to be used only for ``descent()``. Explanation =========== The Gaussian reduction can find the shortest vector for any norm. So we define the special norm for the vectors `u = (u_1, u_2)` and `v = (v_1, v_2)` as follows. .. math :: u \cdot v := (wu_1 + bu_2)(wv_1 + bv_2) + |a|u_1v_1 Note that, given the mapping `f: (u_1, u_2) \to (wu_1 + bu_2, u_1)`, `f((u_1,u_2))` is the solution to `X^2 - aZ^2 \equiv 0 \pmod{b}`. In other words, finding the shortest vector in this norm will yield a solution with smaller `X^2 + |a|Z^2`. The algorithm starts from basis vectors `(0, 1)` and `(1, 0)` (corresponding to solutions `(b, 0)` and `(w, 1)`, respectively) and finds the shortest vector. The shortest vector does not necessarily correspond to the smallest solution, but since ``descent()`` only wants the smallest possible solution, it is sufficient. Parameters ========== w : int ``w`` s.t. `w^2 \equiv a \pmod{b}` a : int square-free nonzero integer b : int square-free nonzero integer Examples ======== >>> from sympy.solvers.diophantine.diophantine import gaussian_reduce >>> from sympy.ntheory.residue_ntheory import sqrt_mod >>> a, b = 19, 101 >>> gaussian_reduce(sqrt_mod(a, b), a, b) # 1**2 - 19*(-4)**2 = -303 (1, -4) >>> a, b = 11, 14 >>> x, z = gaussian_reduce(sqrt_mod(a, b), a, b) >>> (x**2 - a*z**2) % b == 0 True It does not always return the smallest solution. >>> a, b = 6, 95 >>> min_x, min_z = 1, 4 >>> x, z = gaussian_reduce(sqrt_mod(a, b), a, b) >>> (x**2 - a*z**2) % b == 0 and (min_x**2 - a*min_z**2) % b == 0 True >>> min_x**2 + abs(a)*min_z**2 < x**2 + abs(a)*z**2 True References ========== .. [1] Gaussian lattice Reduction [online]. Available: https://web.archive.org/web/20201021115213/http://home.ie.cuhk.edu.hk/~wkshum/wordpress/?p=404 .. [2] Cremona, J. E., Rusin, D. (2003). Efficient Solution of Rational Conics. Mathematics of Computation, 72(243), 1417-1441. https://doi.org/10.1090/S0025-5718-02-01480-1 c8|d|dz|dz|dzzSrKr)rr`rs rC_dotzgaussian_reduce.._dot s*tAaDy1QqT6!A$;&&rDrrwrrrL) rrr2rrr`dvrrts ` rCrzrzu s&F AA' AAA#(A!RA !tadQh!1 q!*d1aj( ) AJ" 1Q4!AaD&=!A$1Q4-01 q!*d1aj( ) 1!adQqTk"A AqzT!QZ/1T!QZ</0 H1HrDct|rd|z}n|dz}||z|z}d} ||dzz||dzz||dzz} } } | | z| k7r|dk(r tdnk|||}} } t| | | |krnSt|| | x}\}}d|vrn:||z| z||z| zz ||z}}t ||}t |r-t ||}t||z tjksGJ||z}t||z||zz||zzr|dz }t||z tjksJ||dzz||dzzz||dzzz}||z| z||z| zz||z|zz}t | |zd|z|zz |}t | |zd|z|zz |}t ||zd|z|zz |}td|||fDsJ|dz }t  fDcgc] }t|c}Scc}w)a Simplify the solution `(x, y, z)` of the equation `ax^2 + by^2 = cz^2` with `a, b, c > 0` and `z^2 \geq \mid ab \mid` to a new reduced solution `(x', y', z')` such that `z'^2 \leq \mid ab \mid`. The algorithm is an interpretation of Mordell's reduction as described on page 8 of Cremona and Rusin's paper [1]_ and the work of Mordell in reference [2]_. References ========== .. [1] Cremona, J. E., Rusin, D. (2003). Efficient Solution of Rational Conics. Mathematics of Computation, 72(243), 1417-1441. https://doi.org/10.1090/S0025-5718-02-01480-1 .. [2] Diophantine Equations, L. J. Mordell, page 48. rrzbad starting solutionNrwc34K|]}|jywrT)rrks rCruzholzer.. s3A1<<3r])rr=maxrr rrrrHalfrrr>rJ)rQrrrr2rtrsmallstept1t2t3r r r<uvrr`r_rrrrrrPs rCr0r0 sP( Aw aC qD aCEE D q!tVQq!tVQq!tVB 7b=qy !899 1a#S r2r?e # (C#66TQ 2: 1S1Q3s7"#QsU1 QN 8q!$Aq1u:' ''1AAaC!A#I!O$Qq1u:& && q!tVa1f_qAv % qSWqs3w 1S ( SUQqSU]A & SUQqSU]A & SUQqSU]A &3!Q3333  C F 3S/2Q#a&2 332s G$ct|d\}}}|tjk(rG|d}ntd|t |fzd}t t|j |dSy) a Solves the general pythagorean equation, `a_{1}^2x_{1}^2 + a_{2}^2x_{2}^2 + . . . + a_{n}^2x_{n}^2 - a_{n + 1}^2x_{n + 1}^2 = 0`. Returns a tuple which contains a parametrized solution to the equation, sorted in the same order as the input variables. Usage ===== ``diop_general_pythagorean(eq, param)``: where ``eq`` is a general pythagorean equation which is assumed to be zero and ``param`` is the base parameter used to construct other parameters by subscripting. Examples ======== >>> from sympy.solvers.diophantine.diophantine import diop_general_pythagorean >>> from sympy.abc import a, b, c, d, e >>> diop_general_pythagorean(a**2 + b**2 + c**2 - d**2) (m1**2 + m2**2 - m3**2, 2*m1*m3, 2*m2*m3, m1**2 + m2**2 + m3**2) >>> diop_general_pythagorean(9*a**2 - 4*b**2 + 16*c**2 + 25*d**2 + e**2) (10*m1**2 + 10*m2**2 + 10*m3**2 - 10*m4**2, 15*m1**2 + 15*m2**2 + 15*m3**2 + 15*m4**2, 15*m1*m4, 12*m2*m4, 60*m3*m4) FrNz%s1:%iTrrr)r7r}rkrrFr{r)rrrr~rrs rCrr ss2+2U;C &+++ =FXC(994HF&r*00F0CDQGG ,rDct|d\}}}|tjk(r$tt|j |Sy)a Solves the equation `x_{1}^2 + x_{2}^2 + . . . + x_{n}^2 - k = 0`. Returns at most ``limit`` number of solutions. Usage ===== ``general_sum_of_squares(eq, limit)`` : Here ``eq`` is an expression which is assumed to be zero. Also, ``eq`` should be in the form, `x_{1}^2 + x_{2}^2 + . . . + x_{n}^2 - k = 0`. Details ======= When `n = 3` if `k = 4^a(8m + 7)` for some `a, m \in Z` then there will be no solutions. Refer to [1]_ for more details. Examples ======== >>> from sympy.solvers.diophantine.diophantine import diop_general_sum_of_squares >>> from sympy.abc import a, b, c, d, e >>> diop_general_sum_of_squares(a**2 + b**2 + c**2 + d**2 + e**2 - 2345) {(15, 22, 22, 24, 24)} Reference ========= .. [1] Representing an integer as a sum of three squares, [online], Available: https://proofwiki.org/wiki/Integer_as_Sum_of_Three_Squares FrrN)r7rerkrGrrrrr~rs rCrr1 sKD*"E:C ',,,&r*00u0=>>-rDct|d\}}}|tjk(r$tt|j |Sy)a Solves the equation `x_{1}^e + x_{2}^e + . . . + x_{n}^e - k = 0` where `e` is an even, integer power. Returns at most ``limit`` number of solutions. Usage ===== ``general_sum_of_even_powers(eq, limit)`` : Here ``eq`` is an expression which is assumed to be zero. Also, ``eq`` should be in the form, `x_{1}^e + x_{2}^e + . . . + x_{n}^e - k = 0`. Examples ======== >>> from sympy.solvers.diophantine.diophantine import diop_general_sum_of_even_powers >>> from sympy.abc import a, b >>> diop_general_sum_of_even_powers(a**4 + b**4 - (2**4 + 3**4)) {(2, 3)} See Also ======== power_representation FrrN)r7rrkrGrrs rCrrY sJ6*"E:C *///)"-33%3@AA0rDc#K|r|t||D]}t|ytd|dzD]4}t||D]#}t|}d|t|z z|z%6yw)aD Returns a generator that can be used to generate partitions of an integer `n`. Explanation =========== A partition of `n` is a set of positive integers which add up to `n`. For example, partitions of 3 are 3, 1 + 2, 1 + 1 + 1. A partition is returned as a tuple. If ``k`` equals None, then all possible partitions are returned irrespective of their size, otherwise only the partitions of size ``k`` are returned. If the ``zero`` parameter is set to True then a suitable number of zeros are added at the end of every partition of size less than ``k``. ``zero`` parameter is considered only if ``k`` is not None. When the partitions are over, the last `next()` call throws the ``StopIteration`` exception, so this function should always be used inside a try - except block. Details ======= ``partition(n, k)``: Here ``n`` is a positive integer and ``k`` is the size of the partition which is also positive integer. Examples ======== >>> from sympy.solvers.diophantine.diophantine import partition >>> f = partition(5) >>> next(f) (1, 1, 1, 1, 1) >>> next(f) (1, 1, 1, 2) >>> g = partition(5, 3) >>> next(g) (1, 1, 3) >>> next(g) (1, 2, 2) >>> g = partition(5, 3, zeros=True) >>> next(g) (0, 0, 5) Nrwr)r5r>rHrF)rwrrrrPrs rC partitionr s\ AI#Aq) A(N q!a% ,A'1- ,!HAAJ'!++ , ,sA+A-ctt|}|dzdk7ryt|s td|dzdk(rd}nA|dzdk(rd }n6|dzd vrd}n,d }t||dk(rt |}t||dk(rt ||dz |}|}|dz|kDr|||z}}|dz|kDrt ||zt |fS) a Represent a prime `p` as a unique sum of two squares; this can only be done if the prime is congruent to 1 mod 4. Parameters ========== p : Integer A prime that is congruent to 1 mod 4 Returns ======= (int, int) | None : Pair of positive integers ``(x, y)`` satisfying ``x**2 + y**2 = p``. None if ``p`` is not congruent to 1 mod 4. Raises ====== ValueError If ``p`` is not prime number Examples ======== >>> from sympy.solvers.diophantine.diophantine import prime_as_sum_of_two_squares >>> prime_as_sum_of_two_squares(7) # can't be done >>> prime_as_sum_of_two_squares(5) (1, 2) Reference ========= .. [1] Representing a number as a sum of four squares, [online], Available: https://schorn.ch/lagrange.html See Also ======== sum_of_squares rrwNzp should be a prime numberr r)rr)r/r%r=rr#powrJ)r_r2rs rCprime_as_sum_of_two_squaresr sV q A1uz 1:5661uz  R1  Q&  Qla! AQla AqAvqA A Q$(!a%1 Q$( AJA rDc 6iddddddddd d d d d ddddddddddddddddddd d!d"d#d$i}t|}|d%kr td&|d%k(ry't|d(\}}d|z}|d)zd*k(ry+||vrt||Dcgc]}||z c}St |d\}}|rd%d%||zfS|d)zdk(rs|dzs|dz}t |d,d-D]W}||dzz dz}t |st|\}} tt||z||| zz|t|| z zgcSJ|dz|dzz s|dz}t |d,d-D]E}||dzz }t |st|\}} tt||z||z|| zgcSJcc}w).a5 Returns a 3-tuple $(a, b, c)$ such that $a^2 + b^2 + c^2 = n$ and $a, b, c \geq 0$. Returns None if $n = 4^a(8m + 7)$ for some `a, m \in \mathbb{Z}`. See [1]_ for more details. Parameters ========== n : Integer non-negative integer Returns ======= (int, int, int) | None : 3-tuple non-negative integers ``(a, b, c)`` satisfying ``a**2 + b**2 + c**2 = n``. a,b,c are sorted in ascending order. ``None`` if no such ``(a,b,c)``. Raises ====== ValueError If ``n`` is a negative integer Examples ======== >>> from sympy.solvers.diophantine.diophantine import sum_of_three_squares >>> sum_of_three_squares(44542) (18, 37, 207) References ========== .. [1] Representing a number as a sum of three squares, [online], Available: https://schorn.ch/lagrange.html See Also ======== power_representation : ``sum_of_three_squares(n)`` is one of the solutions output by ``power_representation(n, 2, 3, zeros=True)`` rwrXrryr)rwrwrw )rrwr")rrr:)rrrU)rr)rr )rr )r rir)rri)rri)rri)rrwi)r!ir)rr$i )r 'i%)89rr"n should be a non-negative integer)rrrrrrNrr) r/r=rr>rrHr%rsortedr) rwspecialr`rPrrrQrrrs rCsum_of_three_squaresr sb^q)^Q ^1i^Y^I^9^ )^-0*^>A:^ORT]^J^ #Z^14l^DG^[^#' ^7;L^KOP\^G q A1u=>>Av !Q>> from sympy.solvers.diophantine.diophantine import sum_of_four_squares >>> sum_of_four_squares(3456) (8, 8, 32, 48) >>> sum_of_four_squares(1294585930293) (0, 1234, 2161, 1137796) References ========== .. [1] Representing a number as a sum of four squares, [online], Available: https://schorn.ch/lagrange.html See Also ======== power_representation : ``sum_of_four_squares(n)`` is one of the solutions output by ``power_representation(n, 2, 4, zeros=True)`` rr)rrrrrrwrrr)rr)r/r=rrr>r)rwr`rrQrrs rCsum_of_four_squaresrZsZ q A1u=>>Av !Q>> from sympy.solvers.diophantine.diophantine import power_representation Represent 1729 as a sum of two cubes: >>> f = power_representation(1729, 3, 2) >>> next(f) (9, 10) >>> next(f) (1, 12) If the flag `zeros` is True, the solution may contain tuples with zeros; any such solutions will be generated after the solutions without zeros: >>> list(power_representation(125, 2, 3, zeros=True)) [(5, 6, 8), (3, 4, 10), (0, 5, 10), (0, 2, 11)] For even `p` the `permute_sign` function can be used to get all signed values: >>> from sympy.utilities.iterables import permute_signs >>> list(permute_signs((1, 12))) [(1, 12), (-1, 12), (1, -12), (-1, -12)] All possible signed permutations can also be obtained: >>> from sympy.utilities.iterables import signed_permutations >>> list(signed_permutations((1, 12))) [(1, 12), (-1, 12), (1, -12), (-1, -12), (12, 1), (-12, 1), (12, -1), (-12, -1)] rrc3"K|]}|  ywrTrrks rCruz'power_representation..s?1QB?s Nrwz9 Expecting positive integers for `(p, k)`, but got `(z, z)`rrwrqrrc3(K|] }|z ywrTr)rsrPr`s rCruz'power_representation..s/!/srr)rrrrrrrw)rwrrrrr))rr) rwrrrr%rrrT)r/rr>r=r0r"rrr_can_do_sum_of_squaresrrpow_rep_recursivereversedrH)rwr_rrrrPrber2rrrfeasiblerr`s @rCrrs\$%a),Qvay,GAq!1u q5)1"aE: +??** +1uA!%   Av q&LAv 6$J !VJ  q!B1a|1a4'MAvQ///Av 6!QrrHr)n_ir n_remainingrr_ next_termexactresiduals rCrrs ax16Q3sA;$Av+"El a*;: 5 Y#% +, , !8A"1cAg. a &Y)::a<,YAxR[Q\I\^_```  a8 asB5C7C8 Cc#<Kt|d||Ed{y7w)ayReturn a generator that yields the k-tuples of nonnegative values, the squares of which sum to n. If zeros is False (default) then the solution will not contain zeros. The nonnegative elements of a tuple are sorted. * If k == 1 and n is square, (n,) is returned. * If k == 2 then n can only be written as a sum of squares if every prime in the factorization of n that has the form 4*k + 3 has an even multiplicity. If n is prime then it can only be written as a sum of two squares if it is in the form 4*k + 1. * if k == 3 then n can be written as a sum of squares if it does not have the form 4**m*(8*k + 7). * all integers can be written as the sum of 4 squares. * if k > 4 then n can be partitioned and each partition can be written as a sum of 4 squares; if n is not evenly divisible by 4 then n can be written as a sum of squares only if the an additional partition can be written as sum of squares. For example, if k = 6 then n is partitioned into two parts, the first being written as a sum of 4 squares and the second being written as a sum of 2 squares -- which can only be done if the condition above for k = 2 can be met, so this will automatically reject certain partitions of n. Examples ======== >>> from sympy.solvers.diophantine.diophantine import sum_of_squares >>> list(sum_of_squares(25, 2)) [(3, 4)] >>> list(sum_of_squares(25, 2, True)) [(3, 4), (0, 5)] >>> list(sum_of_squares(25, 4)) [(1, 2, 2, 4)] See Also ======== sympy.utilities.iterables.signed_permutations rN)r)rwrrrs rCruru>sZ$Aq!U333s c |dkry|dkry|dk(ry|dk(r t|S|dk(rC|dvryt|r |dzdk(ryytdt|j DS|d k(rt |ddd zd k7Sy) aReturn True if n can be written as the sum of k squares, False if it cannot, or 1 if ``k == 2`` and ``n`` is prime (in which case it *can* be written as a sum of two squares). A False is returned only if it cannot be written as ``k``-squares, even if 0s are allowed. rwFrTr)rwrrc3FK|]\}}|dzdk7xs|dzdk(yw)rrrrNr)rsr_rs rCruz)_can_do_sum_of_squares..s,Ltq!1q519*A *Ls!rrr)r$r%rr!rr)rwrs rCrrns 1u1uAvAv|Av ; 1:1uzLy|7I7I7KLLLAva|A"a'' rDrT)T)rrJr2rJrrJrzset[tuple[int, int]])F)rrJrrJr2rJrztuple[int, int]r)NF) __future__rsympy.core.addrsympy.core.assumptionsrsympy.core.containersrsympy.core.exprtoolsrsympy.core.functionrsympy.core.mulr sympy.core.numbersr r sympy.core.intfuncr r rrrsympy.core.relationalrsympy.core.singletonrsympy.core.sortingrrsympy.core.symbolrrsympy.core.sympifyrsympy.external.gmpyrrrr$sympy.functions.elementary.complexesr#sympy.functions.elementary.integersr(sympy.functions.elementary.miscellaneousrsympy.matrices.denserrsympy.ntheory.factor_r r!r"sympy.ntheory.generater#sympy.ntheory.primetestr$r%sympy.ntheory.modularr&sympy.ntheory.residue_ntheoryr'r(sympy.polys.polyerrorsr)sympy.polys.polytoolsr*r+rKr,sympy.solvers.solvesetr-sympy.utilitiesr.sympy.utilities.miscr/r0sympy.utilities.iterablesr1r2r3r4r5__all__rGr9rirrrrr!r?rUr`rer}rrrrkrrr/rrrr6rrrr7joinrfunc_docrrrrrrrrrrr7r4rr@rrFrrrrOrUrTr_rNrrPr-rr1rvr.rzr0rrrrrrrr sum_of_powersrrur)rs0rCrsm"4'-(3II$"8-'==559=DD,63A33,0,3PP / *gSgTK&K&\(@C $CL[-[|*$;*&T(?TnE"9EPJ$;J(F"9F(D1DNK0K\>'>6<4<B !%!  1A A*joo A  $* "#t44|~ F: !d3S)B% P)XK 6r34  A=H3LlU p>4B(/sD'A HF%?PBL5,pC LZz@/F|8~% a>-4`cUBsK