K ijdZddlmZddlmZmZmZmZddlm Z ddl m Z m Z m Z ddlmZmZddlmZmZmZmZddlmZmZdd lmZdd lmZdd lmZmZdd l m!Z!m"Z"m#Z#m$Z$dd l%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-ddl.m/Z/dZ0dZ1dZ2d"dZ3d#dZ4d#dZ5d#dZ6d#dZ7d#dZ8d#dZ9d#dZ:d#dZ;d#d ZFKKN1,<<=CV[[^fkk!nQ.>>?Eu!3u9"2"2QI4y3I"JK"6Aq6E#Qs1vX2R7)CLQTUVQWDWYZ:[[C((QK!V#=>C?$S!}:>>#1Q4 >>1Q4v{A!6q!9:;;1Q4v{A!6q!9:;;e2 ?/,s+,%#   @=sHLL(M' L27L-,)M# L%$L%2MM M M cxt}i}|j}|jd}|j|}t d} t d} |d} |d} |j dd} | rt ||d||dz  }ntd} |j|| }| i| g| |||t| | |||t| ig}tt|||||dddrd gt|z}|| d }d}|D]!}tt||||||}|s|cS|S) Nrr-r.r/der!)r2r3 user_defined)r0r/)lie_heuristicsr2r;r?r poprrr>rr"r listr\)r6r2r3r4 heuristicsrFrGrHdfr-r.xisetasr/r0rRrEs r[_ode_lie_grouprh~sTJ C A ! A 1B $B 5/C +C >> from sympy import Function, Eq, pprint >>> from sympy.abc import x, y >>> xi, eta, h = map(Function, ['xi', 'eta', 'h']) >>> h = h(x, y) # dy/dx = h >>> eta = eta(x, y) >>> xi = xi(x, y) >>> genform = Eq(eta.diff(x) + (eta.diff(y) - xi.diff(x))*h ... - (xi.diff(y))*h**2 - xi*(h.diff(x)) - eta*(h.diff(y)), 0) >>> pprint(genform) /d d \ d 2 d d d |--(eta(x, y)) - --(xi(x, y))|*h(x, y) - eta(x, y)*--(h(x, y)) - h (x, y)*--(xi(x, y)) - xi(x, y)*--(h(x, y)) + --(eta(x, y)) = 0 \dy dx / dy dy dx dx Solving the above mentioned PDE is not trivial, and can be solved only by making intelligent assumptions for `\xi` and `\eta` (heuristics). Once an infinitesimal is found, the attempt to find more heuristics stops. This is done to optimise the speed of solving the differential equation. If a list of all the infinitesimals is needed, ``hint`` should be flagged as ``all``, which gives the complete list of infinitesimals. If the infinitesimals for a particular heuristic needs to be found, it can be passed as a flag to ``hint``. Examples ======== >>> from sympy import Function >>> from sympy.solvers.ode.lie_group import infinitesimals >>> from sympy.abc import x >>> f = Function('f') >>> eq = f(x).diff(x) - x**2*f(x) >>> infinitesimals(eq) [{eta(x, f(x)): exp(x**3/3), xi(x, f(x)): 0}] References ========== - Solving differential equations by Symmetry Groups, John Starrett, pp. 1 - pp. 14 r!z(ODE's have only one independent variablerz?Infinitesimals for only first order ODE's have been implementedaexcludebr0r/z9Infinitesimals for the first order ODE could not be foundu)r0r2hxhyr/hinvalllie_heuristic_T)compz3Infinitesimals could not be found for the given ODEdefaultFzHeuristic not recognized: z;Infinitesimals could not be found using the given heuristic) isinstancer lhsr@rr;lenr=r rBr?rrr r4rrrr>raglobalsextend)rDr2r3r1r4 variablesrHrerkrnr0r/rRrorprqrrxietarEfunctioninflistrFs r[r<r<s|"h VVbff_ r?D I 9~CDD aLb$'E A:%':; ;1BSRD)ASRD)A#J#Jr B/55adQh?!%(58"344A##Bm  F#JFF4Oc ABBqSJJAA/066q!cBg}|d}|d}|d}|jd}|d}|d}td||} td||} |j} || vrG tt ||} | t j | | i} |s| gS|r| |vr|j|  ||z }|j}||vrW tt ||}| t j | |j||i} |s| gS|r| |vr|j|  | |z }|j}||vrG tt ||} | | | t j i} |s| gS|r| |vr|j|  | |d zz }|j}||vrW tt ||}| |j||| t j i} |s| gS|r| |vr|j|  |r|Sy #t$rYJwxYw#t$rYwxYw#t$rYwxYw#t$rY>wxYw) aD The first heuristic uses the following four sets of assumptions on `\xi` and `\eta` .. math:: \xi = 0, \eta = f(x) .. math:: \xi = 0, \eta = f(y) .. math:: \xi = f(x), \eta = 0 .. math:: \xi = f(y), \eta = 0 The success of this heuristic is determined by algebraic factorisation. For the first assumption `\xi = 0` and `\eta` to be a function of `x`, the PDE .. math:: \frac{\partial \eta}{\partial x} + (\frac{\partial \eta}{\partial y} - \frac{\partial \xi}{\partial x})*h - \frac{\partial \xi}{\partial y}*h^{2} - \xi*\frac{\partial h}{\partial x} - \eta*\frac{\partial h}{\partial y} = 0 reduces to `f'(x) - f\frac{\partial h}{\partial y} = 0` If `\frac{\partial h}{\partial y}` is a function of `x`, then this can usually be integrated easily. A similar idea is applied to the other 3 assumptions as well. References ========== - E.S Cheb-Terrab, L.G.S Duarte and L.A,C.P da Mota, Computer Algebra Solving of First Order ODEs Using Symmetry Methods, pp. 8 r/r0r2rrprqr-r.N) r;r free_symbolsrrrZerorCrBr>)r4rur}r/r0r2rHrprqr-r.hysymfxrFfactorfacsymfys r[lie_heuristic_abaco1_simpler.sjF E c A c A =D ! A tB tB $4 B (5/!T "C OOE~ "Yr1%&BqvvsB'Cu 5( S! TF  F "Yvq)*BqvvsBGGAt$45Cu 5( S!SUF  F "Yvq)*Br3'Cu 5( S!S!Q$ZF  F "Yvq)*Brwwq$'aff5Cu 5( S!   g#   #   #   #   sH G$<G4)H H$ G10G14 H?H HH HHcVg}|d}|d}|d}|d}|jd}td||}td||} tt|j |j ||dzz d ||g } | r| d r| |} t | d | |zz j |z} | j } || vrXtt| |} | tj|| | zj||i} |s| gS|r| |vr|j| td }tt|j |j ||dzz d ||g } | r| d r| |} t | d | |zz j |z} | j } || vrtt| |} | | z}|j||f||fgj||}| |j|||tji} |s| gS|r| |vr|j| |r|Sy)a The second heuristic uses the following two assumptions on `\xi` and `\eta` .. math:: \eta = 0, \xi = f(x)*g(y) .. math:: \eta = f(x)*g(y), \xi = 0 The first assumption of this heuristic holds good if `\frac{1}{h^{2}}\frac{\partial^2}{\partial x \partial y}\log(h)` is separable in `x` and `y`, then the separated factors containing `x` is `f(x)`, and `g(y)` is obtained by .. math:: e^{\int f\frac{\partial}{\partial x}\left(\frac{1}{f*h}\right)\,dy} provided `f\frac{\partial}{\partial x}\left(\frac{1}{f*h}\right)` is a function of `y` only. The second assumption holds good if `\frac{dy}{dx} = h(x, y)` is rewritten as `\frac{dy}{dx} = \frac{1}{h(y, x)}` and the same properties of the first assumption satisfies. After obtaining `f(x)` and `g(y)`, the coordinates are again interchanged, to get `\eta` as `f(x)*g(y)` References ========== - E.S. Cheb-Terrab, A.D. Roche, Symmetries and First Order ODE Patterns, pp. 7 - pp. 8 r/r0rrr2rr-r.rTr9rr:r!u1N)r;r rrr?rrrrrrr>rCr)r4rur}r/r0rrr2rHr-r.rFrgygysymsretavals r[lie_heuristic_abaco1_productrs5> E c A c A =D =D ! A $4 B (5/!T "C QQ--a0!Q$6TAq6 RC s7| V b1bd8//!,- . F?Yr1%&BRULLD$9:Cu 5( S! tB T*003T1W<4RSUVQW XC s7| V b1bg;,,Q/0 1 F?Yr1%&BUFkkAr7QF"34::2qAF At,b!&&9Cu 5( S!   ricJ|d}|d}|d}|d}|jd}|d}td||}td||} |jrdoitr is_polynomialis_Addas_dictrunionrvaluesrwrcanyr9fromkeys)"r4rur0rprqr2rHr/r-r.etaxetayetadxixxiyxidipderUrVdegrrxieqetaeqipowerpdenpolyysymsetsoldictxiredetareddict_rFs" r[lie_heuristic_bivariaters& c A tB tB =D ! A c A $4 B (5/!T "C+22N*O'dD#sCtcz1n$s1a4x/#b&847BD\002 U31o**,x1%huoa# !  ! sxx{ :A==!aQRd@RR"fBwe}vsQw !A!&q1u/53u:-3c!e)nDEahNqSTW\S\~]/00!&q1u/6CJ.4s1u9~EFq%xOPQTUX]T]P^^/00 99c4u%=>CCEUUWKD%$|j|}t2j5|d }|j|}t7||\}}||j||||j|| i}|gcSy y cc}w)a The aim of the fourth heuristic is to find the function `\chi(x, y)` that satisfies the PDE `\frac{d\chi}{dx} + h\frac{d\chi}{dx} - \frac{\partial h}{\partial y}\chi = 0`. This assumes `\chi` to be a bivariate polynomial in `x` and `y`. By intuition, `h` should be a rational function in `x` and `y`. The method used here is to substitute a general binomial for `\chi` up to a certain maximum degree is reached. The coefficients of the polynomials, are calculated by by collecting terms of the same order in `x` and `y`. After finding `\chi`, the next step is to use `\eta = \xi*h + \chi`, to determine `\xi` and `\eta`. This can be done by dividing `\chi` by `h` which would give `-\xi` as the quotient and `\eta` as the remainder. References ========== - E.S Cheb-Terrab, L.G.S Duarte and L.A,C.P da Mota, Computer Algebra Solving of First Order ODEs Using Symmetry Methods, pp. 8 r0rqr2rr/r-r.zschi, schix, schiyr+r!chi_rN)r;r rrrrrrr?rrrrr>rr rrrrrrrwrcrr9rr)r4rur0rqr2rHr/r-r.schischixschiycpderUrVrr+chixchiychieqrrcnumcdencpolysolsymsrrxicetacrFs r[lie_heuristic_chir&s0 c A tB =D ! A c A $4 B (5/!T "C$%9:eUqwD(D\002 U31o**,huoa#xx{xx{af}r#v%u q#'" %A S"1q5\+vE *S03q5y>AB1e8KAPQTYPYNZ+, ,E  3- 8 = = ?@OOQJD$$>+, % 7 3 $ gq 9 % 5 1%(qM T"DIIa$6SXXa=Nrris_MulrrrrCrB)r4rur}r0r2rrrHr/r-r.odefacrrXrrfddrcheckrRrargrFs r[lie_heuristic_function_sumrmshL E c A =D =D ! A c A $4 B (5/!T "Cd))!F(A./AfH??1-D1a&I 3w)r4rur0rprqr2rrrHr/r-r.rfactorxfactoryrrrtaugxgammatauints r[lie_heuristic_abaco2_similarrsL c A tB tB =D =D ! A c A $4 B (5/!T "C AFF1IaffQl* +Fkk!nGkk!nG ::a=A qc " qc " q!f %Ac!A#hJ' (yq%(!233Q7a@Cq#Bc2&' 'ww'yy|U2X 1 5:QYGHF::a=0i23CeBc2.// DIIaL1a0 1Fkk!nGkk!nG ::a=A qc " qc " q!f %Ac!A#hJ' Dyq%(!233Q7a@Cq#B#((1d+RD1ABC Cww'yy|U499Q</%**Q-?$))A,Nu F::a=Li23CeB #((1d"3RD9IJKK!K#   + #   +sH%N N"%N2O NN" N/.N/2 N>=N> O  O c|d}|d}|d}|d}|jd}|d}td||}td||} g} |jtD]W} | j \} } | j |s(| j |s:| j rG| j| Y|jtD])}|j}||vs||vs| j|+| D]}t|j||j|z }t|d ||g }|r|d r||}d |||d zz }|j||z|j||zz ||zz ||zz }t|s||| |j||igcSd |z }d |z }|j||j||dzzz ||zz ||zz }tt|r||j||| |igcSd |z }|j||j||zz|z ||zz }t|s'|t j"| |j||igcS| }|j| |z|j||dzzz ||zz |z }tt|r||j||| t j"igcSy)a This heuristic assumes the presence of unknown functions or known functions with non-integer powers. 1. A list of all functions and non-integer powers containing x and y 2. Loop over each element `f` in the list, find `\frac{\frac{\partial f}{\partial x}}{ \frac{\partial f}{\partial x}} = R` If it is separable in `x` and `y`, let `X` be the factors containing `x`. Then a] Check if `\xi = X` and `\eta = -\frac{X}{R}` satisfy the PDE. If yes, then return `\xi` and `\eta` b] Check if `\xi = \frac{-R}{X}` and `\eta = -\frac{1}{X}` satisfy the PDE. If yes, then return `\xi` and `\eta` If not, then check if a] :math:`\xi = -R,\eta = 1` b] :math:`\xi = 1, \eta = -\frac{1}{R}` are solutions. References ========== - E.S. Cheb-Terrab, A.D. Roche, Symmetries and First Order ODE Patterns, pp. 10 - pp. 12 r0rprqr2rr/r-r.Trr:r8r!rN)r;r atomsr as_base_expr is_IntegerrCr rrr?rrr>r rOne)r4rur0rprqr2rHr/r-r.funclistatombaserr~symsrGfracrXxitry1etatry1pde1xitry2etatry2pde2etatrypdexitrys r[#lie_heuristic_abaco2_unique_unknownr3s> c A tB tB =D ! A c A $4 B (5/!T "CH &$$& c 88A;488A;>>% & GGL)&$$ 9d OOH %& ?affQiq )*4dQF; 3w<VF#a&W-.G<<?1$v{{1~a'77&)CgbjPDD>VS',,q$*?@AAwYFhG<<?fkk!nad%::VBYFQSSDF4L)V[[D13@AAWF++a.6;;q>!#33b86"9DCC=QUUCQ)=>??EE::a=."EJJqM!Q$$66rA2ECF3K(UZZ40#quu=>>/?ric$|d}|d}|d}|jd}|d}td||}td||}|j|} |j||dzz} |j||dzz } | r| r| sy | j|} | j|} | j|}| j|}| j|}td|z|| zz| |zz ||zd| zz| zz| zd | z| zz }|std | dzz|dzd| zz| zd|zz | zz}|rtd|zd| z|dzz | zz| zd | dzzz }|st|d | zd |z| zz| d zz||| z| zzz z|j|d z| d zzz }|s}t d | d zz| || zz z||| z| z zzt d| z|zz }||vr@ t t||}d| d zz|z|z }||vr||||j||igSy y y y y td|zd| z|dzz | zz| zd | dzzz }|r td | d zz|z|dzz |d|z|dzd| zz| zz | zd | dzzz zz}|st| |z |j|z|j|||zz | zd | z|zz| |zd | zz |zz|zz}|srt | |z| z |z| | |zz|zz t d| z|zz }||vr; t t||}| |z|z }||vr||||j||igSy y y y y #t$rYy wxYw#t$rYy wxYw)aQ This heuristic finds if infinitesimals of the form `\eta = f(x)`, `\xi = g(y)` without making any assumptions on `h`. The complete sequence of steps is given in the paper mentioned below. References ========== - E.S. Cheb-Terrab, A.D. Roche, Symmetries and First Order ODE Patterns, pp. 10 - pp. 12 rprqr2rr/r-r.rN) r;r r?rrrrrr>rB)r4rurprqr2rHr/r-r.rrrAxAyAxyAxxAyyDE1E2E3rxivals r[#lie_heuristic_abaco2_unique_generalrsv tB tB =D ! A c A $4 B (5/!T "C  A  RUA  RUA ! B B ''!*C ''!*C ''!*C3BB&"R%!A#+q89!;ad2gEA aAg"a%!A#+q1S5!8! ;; < 1S5AaC"a%K?2A5"a%?@BB2aA-BqD2I>?"''!*Q,qRStBSSU#Qq!tVR"Q$Y%7"bdRi.%H1Q4PQ6RT9$UVFP%(61)=%>F%'q!tGFN2$5E ~)+UCQ9M(N'O O .' $qu!b!e Q.1Ab!eG; < !Q$q1a4"quA! Q'>&AAb!eG&K"LLNBqS6"''!*$bd):A(="Q(FrTAbD["$)%&(())*#adRi^rAbDy!m%Cad1fQh$OPFP%(61)=%>F&(CJqLE ~)+UCQ9M(N'O O .'   3! !* 3! !s$7M46N4 N?N NNc |d}|d}|d}|d}|jd}|d}td||}td||} i} td t } t | d D cgc] } t | } } | \}}}}}}|||z |zz||z||zz|z|zz ||z||zz|z|zz ||d zzz }|j \}}tt|}|jr|j}|D]}|jrPt|jDcgc]}|j||r|c}}||z }|| vr|| |<Q| |xx|z cc<_|| vrtj| |<w| |xxtjz cc<| j}t!|| }|rt#|t$r|d}|j}t'd |Drt)t+| dgd z}||z||zz|z}||z||zz|z} |j-|}| j-|} |j-|}| j-|} ||| | igSyycc} wcc}w)a This heuristic assumes 1. `\xi = ax + by + c` and 2. `\eta = fx + gy + h` After substituting the following assumptions in the determining PDE, it reduces to .. math:: f + (g - a)h - bh^{2} - (ax + by + c)\frac{\partial h}{\partial x} - (fx + gy + c)\frac{\partial h}{\partial y} Solving the reduced PDE obtained, using the method of characteristics, becomes impractical. The method followed is grouping similar terms and solving the system of linear equations obtained. The difference between the bivariate heuristic is that `h` need not be a rational function in this case. References ========== - E.S. Cheb-Terrab, A.D. Roche, Symmetries and First Order ODE Patterns, pp. 10 - pp. 12 r0rprqr2rr/r-r.c)clsrc3 K|]}|yw)N).0ts r[ z'lie_heuristic_linear.. s!Qq!s r!N)r;r rrrnextrrr rrrrrrrrrwrcrr9zipr>)!r4rur0rprqr2rHr/r-r. coeffdictrrsymlistC0r7C2C3C4C5rrVtermstermmremxypartsollistrsubvalonedictrrs! r[lie_heuristic_linearrs0 c A tB tB =D ! A c A $4 B (5/!T "CIs.G&,Wa&89tG}9G9$BBB R{ bdRTkB.2 2bdRTkB6F5J JRPQSTPTW TC##%JC &+ C zz -D{{tyyD!a ADEc*(+If%f%,%y(&'eeIdOdOquu,O - GGW%G gt $ajG! !&! !3wA./GqD2d7NR'ETBtG^b(FJJw'E[[)FJJw'E[[)FV,- - " /:Es.I/&I4 >I4 ct|tr|jdS|jr2|j t}|r|D]}|j |d}|S|j r.|j\}}t|}t|}||zS|jrHg}|j}|D]-}t|tr|jt|/t|S|S)a This function is strictly meant for internal use by the Lie group ODE solving method. It replaces arbitrary functions returned by pdsolve as follows: 1] If coords is an arbitrary function, then its argument is returned. 2] An arbitrary function in an Add object is replaced by zero. 3] An arbitrary function in a Mul object is replaced by one. 4] If there is no arbitrary function coords is returned unchanged. Examples ======== >>> from sympy.solvers.ode.lie_group import _lie_group_remove >>> from sympy import Function >>> from sympy.abc import x, y >>> F = Function("F") >>> eq = x**2*y >>> _lie_group_remove(eq) x**2*y >>> eq = F(x**2*y) >>> _lie_group_remove(eq) x**2*y >>> eq = x*y**2 + F(x**3) >>> _lie_group_remove(eq) x*y**2 >>> eq = (F(x**3) + y)*x**4 >>> _lie_group_remove(eq) x**4*y r) rwr r;rrr>is_PowrrArrCr)coordssubfuncr2rexprmulargs coordargsrs r[rArAs>&,'{{1~ ,,|,  .T1- . '') d & &Tz KK  7Cfl3056 7G} Mri)NNrvN)F)>__doc__ itertoolsr sympy.corerrrrsympy.core.exprtoolsrsympy.core.functionr r r sympy.core.relationalr r sympy.core.symbolrrrrsympy.functionsrrsympy.integrals.integralsr sympy.polysrsympy.polys.polytoolsrrsympy.simplifyrrrr sympy.solversrsympy.solvers.pdersympy.utilitiesrsympy.solvers.deutilsrr oder"rar\rhr<rrrrrrrrrrArrir[r6s&''->>.::$/-%,8 EP!HI-XeNGRF!PE%NXtiLXK?\HPVF.R3ri