o
    8Va-                     @   sb  d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZmZmZ ddlmZmZ dd	lmZmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddl m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(Z(dZ)d2ddZ*dd Z+dd Z,d3ddddZ-d4dd Z.d!d" Z/d#d$ Z0d%d& Z1d'd( Z2d5d*d+Z3d,d- Z4d.d/ Z5d0d1 Z6dS )6a  
This module contains pdsolve() and different helper functions that it
uses. It is heavily inspired by the ode module and hence the basic
infrastructure remains the same.

**Functions in this module**

    These are the user functions in this module:

    - pdsolve()     - Solves PDE's
    - classify_pde() - Classifies PDEs into possible hints for dsolve().
    - pde_separate() - Separate variables in partial differential equation either by
                       additive or multiplicative separation approach.

    These are the helper functions in this module:

    - pde_separate_add() - Helper function for searching additive separable solutions.
    - pde_separate_mul() - Helper function for searching multiplicative
                           separable solutions.

**Currently implemented solver methods**

The following methods are implemented for solving partial differential
equations.  See the docstrings of the various pde_hint() functions for
more information on each (run help(pde)):

  - 1st order linear homogeneous partial differential equations
    with constant coefficients.
  - 1st order linear general partial differential equations
    with constant coefficients.
  - 1st order linear partial differential equations with
    variable coefficients.

    )reduce)combinations_with_replacement)simplify)AddS)is_sequence)FunctionexpandAppliedUndefSubs)EqualityEq)SymbolWildsymbols)exp)Integral)has_dups)
filldedent)_preprocess	ode_order_desolve)solve)collectN)%1st_linear_constant_coeff_homogeneous1st_linear_constant_coeff"1st_linear_constant_coeff_Integral1st_linear_variable_coeffdefaultFc                 K   s  |st d}t| f||ddd|}|dd} |dd}|rui }i }	t| dd}
||
d	 |
d
 d |D ]4}zt| ||| d || d	 || | |}W n tyh } z
||	|< W Y d}~q9d}~ww |||< q9||	 |S t| |d |d |d	 ||d  |S )a  
    Solves any (supported) kind of partial differential equation.

    **Usage**

        pdsolve(eq, f(x,y), hint) -> Solve partial differential equation
        eq for function f(x,y), using method hint.

    **Details**

        ``eq`` can be any supported partial differential equation (see
            the pde docstring for supported methods).  This can either
            be an Equality, or an expression, which is assumed to be
            equal to 0.

        ``f(x,y)`` is a function of two variables whose derivatives in that
            variable make up the partial differential equation. In many
            cases it is not necessary to provide this; it will be autodetected
            (and an error raised if it couldn't be detected).

        ``hint`` is the solving method that you want pdsolve to use.  Use
            classify_pde(eq, f(x,y)) to get all of the possible hints for
            a PDE.  The default hint, 'default', will use whatever hint
            is returned first by classify_pde().  See Hints below for
            more options that you can use for hint.

        ``solvefun`` is the convention used for arbitrary functions returned
            by the PDE solver. If not set by the user, it is set by default
            to be F.

    **Hints**

        Aside from the various solving methods, there are also some
        meta-hints that you can pass to pdsolve():

        "default":
                This uses whatever hint is returned first by
                classify_pde(). This is the default argument to
                pdsolve().

        "all":
                To make pdsolve apply all relevant classification hints,
                use pdsolve(PDE, func, hint="all").  This will return a
                dictionary of hint:solution terms.  If a hint causes
                pdsolve to raise the NotImplementedError, value of that
                hint's key will be the exception object raised.  The
                dictionary will also include some special keys:

                - order: The order of the PDE.  See also ode_order() in
                  deutils.py
                - default: The solution that would be returned by
                  default.  This is the one produced by the hint that
                  appears first in the tuple returned by classify_pde().

        "all_Integral":
                This is the same as "all", except if a hint also has a
                corresponding "_Integral" hint, it only returns the
                "_Integral" hint.  This is useful if "all" causes
                pdsolve() to hang because of a difficult or impossible
                integral.  This meta-hint will also be much faster than
                "all", because integrate() is an expensive routine.

        See also the classify_pde() docstring for more info on hints,
        and the pde docstring for a list of all supported hints.

    **Tips**
        - You can declare the derivative of an unknown function this way:

            >>> from sympy import Function, Derivative
            >>> from sympy.abc import x, y # x and y are the independent variables
            >>> f = Function("f")(x, y) # f is a function of x and y
            >>> # fx will be the partial derivative of f with respect to x
            >>> fx = Derivative(f, x)
            >>> # fy will be the partial derivative of f with respect to y
            >>> fy = Derivative(f, y)

        - See test_pde.py for many tests, which serves also as a set of
          examples for how to use pdsolve().
        - pdsolve always returns an Equality class (except for the case
          when the hint is "all" or "all_Integral"). Note that it is not possible
          to get an explicit solution for f(x, y) as in the case of ODE's
        - Do help(pde.pde_hintname) to get help more information on a
          specific hint


    Examples
    ========

    >>> from sympy.solvers.pde import pdsolve
    >>> from sympy import Function, Eq
    >>> from sympy.abc import x, y
    >>> f = Function('f')
    >>> u = f(x, y)
    >>> ux = u.diff(x)
    >>> uy = u.diff(y)
    >>> eq = Eq(1 + (2*(ux/u)) + (3*(uy/u)), 0)
    >>> pdsolve(eq)
    Eq(f(x, y), F(3*x - 2*y)*exp(-2*x/13 - 3*y/13))

    FTpde)funchintr   typeeqFall)dictorderr   )r'   r   r!   Nr"   )r   r   popclassify_pdeupdate_helper_simplifyNotImplementedError)r$   r!   r"   r&   solvefunkwargsZhintsZall_ZpdedictZfailed_hintsZgethintsZrvZdetail r/   3/usr/lib/python3/dist-packages/sympy/solvers/pde.pypdsolve@   s>   f


r1   c                 C   sP   | drt d|dtd    }nt d|  }t|| |||||||S )zHelper function of pdsolve that calls the respective
    pde functions to solve for the partial differential
    equations. This minimizes the computation in
    calling _desolve multiple times.
    	_IntegralZpde_N)endswithglobalslen_handle_Integral)r$   r"   r!   r'   matchr-   Z	solvefuncr/   r/   r0   r+      s   

r+   c                 C   s&   | dr| S |dkrt|  S | S )z|
    Converts a solution with integrals in it into an actual solution.

    Simplifies the integral mainly using doit()
    r2   r   )r3   r   doit)exprr!   r'   r"   r/   r/   r0   r6      s
   
r6   T)prepc                   sV  |rt |jdkrtd|s|du r t| |\}}|du r |}t| tr6| jdkr3t| j| j |S | j} |j	}|jd }|jd }|||
|}	|||
|}
t| |||}d|i}|sk|rid|d< |S dS t| } td	|||gd
}td||||	|
||gd
}td||||	|
||gd
}td||||	|
||gd
}td||||	|
gd
}td||gd
}d}| jrMtt||f|}| }d}|D ]3}| |||j
| }|dkr||||||  }|r|| r|| }||  n|| q|D ]2}| |||j
| }|dkr5||||||  }|r5|| r5|| |k r5|| }q|rM||||  t fdd| jD  }|sR| }|dkrt||||}|||	 ||
  ||||  | }|r|| s||||d ||d< nk|| d || d  dkr|||||d ||d< ||d< nItd||||	|
gd
}td||||	|
gd
}td||||	|
gd
}|||	 ||
  ||||  | }|r|||||d ||d< g }tD ]}||v r|| q|r'd|d< t||d< tD ]}||v r#||d<  |S q|S t|S )a  
    Returns a tuple of possible pdsolve() classifications for a PDE.

    The tuple is ordered so that first item is the classification that
    pdsolve() uses to solve the PDE by default.  In general,
    classifications near the beginning of the list will produce
    better solutions faster than those near the end, though there are
    always exceptions.  To make pdsolve use a different classification,
    use pdsolve(PDE, func, hint=<classification>).  See also the pdsolve()
    docstring for different meta-hints you can use.

    If ``dict`` is true, classify_pde() will return a dictionary of
    hint:match expression terms. This is intended for internal use by
    pdsolve().  Note that because dictionaries are ordered arbitrarily,
    this will most likely not be in the same order as the tuple.

    You can get help on different hints by doing help(pde.pde_hintname),
    where hintname is the name of the hint without "_Integral".

    See sympy.pde.allhints or the sympy.pde docstring for a list of all
    supported hints that can be returned from classify_pde.


    Examples
    ========

    >>> from sympy.solvers.pde import classify_pde
    >>> from sympy import Function, Eq
    >>> from sympy.abc import x, y
    >>> f = Function('f')
    >>> u = f(x, y)
    >>> ux = u.diff(x)
    >>> uy = u.diff(y)
    >>> eq = Eq(1 + (2*(ux/u)) + (3*(uy/u)), 0)
    >>> classify_pde(eq)
    ('1st_linear_constant_coeff_homogeneous',)
       zLRight now only partial differential equations of two variables are supportedNr      r'   r   r/   a)Zexcludebcdenc                    s   g | ]}|  qS r/   r/   ).0argZdenr/   r0   
<listcomp>S  s    z classify_pde.<locals>.<listcomp>)r>   r?   r@   r   )r>   r?   r@   rA   r   r   r   Zordered_hints)r5   argsr,   r   
isinstancer   rhsr)   lhsr!   diffr   r	   r   Zis_Addsetr   copycoeffr7   remover   r   r*   allhintsappendtuple)r$   r!   r&   r:   r.   Zfunc_fxyZfxZfyr'   Zmatching_hintsr=   r>   r?   r@   rA   rB   Z
reduced_eqvarZdummyvarZpowerirN   r7   rZretlistr/   rE   r0   r)      s   '






(

(


r)   c                    s  t ts
td du rDz	tj\} W n, tyC   dd t|tr(|n|gD }t |}t	|dkr=td|
  Y nw t|trXt| fdd|D S t |tsct |}n|j krk|j}|j kov|j  }r|st| }|rt	|dkrtt |d  dd	S t fd
d|D  dd	S |j krjj t |j }|tju |fS ttd|f )a  
    Checks if the given solution satisfies the partial differential
    equation.

    pde is the partial differential equation which can be given in the
    form of an equation or an expression. sol is the solution for which
    the pde is to be checked. This can also be given in an equation or
    an expression form. If the function is not provided, the helper
    function _preprocess from deutils is used to identify the function.

    If a sequence of solutions is passed, the same sort of container will be
    used to return the result for each solution.

    The following methods are currently being implemented to check if the
    solution satisfies the PDE:

        1. Directly substitute the solution in the PDE and check. If the
           solution hasn't been solved for f, then it will solve for f
           provided solve_for_func hasn't been set to False.

    If the solution satisfies the PDE, then a tuple (True, 0) is returned.
    Otherwise a tuple (False, expr) where expr is the value obtained
    after substituting the solution in the PDE. However if a known solution
    returns False, it may be due to the inability of doit() to simplify it to zero.

    Examples
    ========

    >>> from sympy import Function, symbols
    >>> from sympy.solvers.pde import checkpdesol, pdsolve
    >>> x, y = symbols('x y')
    >>> f = Function('f')
    >>> eq = 2*f(x,y) + 3*f(x,y).diff(x) + 4*f(x,y).diff(y)
    >>> sol = pdsolve(eq)
    >>> assert checkpdesol(eq, sol)[0]
    >>> eq = x*f(x,y) + f(x,y).diff(x)
    >>> checkpdesol(eq, sol)
    (False, (x*F(4*x - 3*y) - 6*F(4*x - 3*y)/25 + 4*Subs(Derivative(F(_xi_1), _xi_1), _xi_1, 4*x - 3*y))*exp(-6*x/25 - 8*y/25))
    r   Nc                 S   s   g | ]}| tqS r/   )Zatomsr
   )rC   sr/   r/   r0   rF         zcheckpdesol.<locals>.<listcomp>r<   z0must pass func arg to checkpdesol for this case.c                    s   g | ]
}t | d qS )r!   solve_for_func)checkpdesol)rC   rW   r!   r    r\   r/   r0   rF     s    
Fr[   c                    s   g | ]}t  |qS r/   )r   )rC   t)r!   r/   r0   rF     rZ   z2
        Unable to test if %s is a solution to %s.)rH   r   r   r   rJ   
ValueErrorr   rL   unionr5   r(   r#   rI   reversedhasr   r]   r   subsr8   r   ZZeror,   r   )r    solr!   r\   _ZfuncsZsolvedrY   r/   r^   r0   r]     sT   
*





r]   c                 C   s   |j }|jd }|jd }||d  }||d  }	||d  }
t|||tt|
 |d |	d   || |	|   ||	| ||   S )a  
    Solves a first order linear homogeneous
    partial differential equation with constant coefficients.

    The general form of this partial differential equation is

    .. math:: a \frac{\partial f(x,y)}{\partial x}
              + b \frac{\partial f(x,y)}{\partial y} + c f(x,y) = 0

    where `a`, `b` and `c` are constants.

    The general solution is of the form:

    .. math::
        f(x, y) = F(- a y + b x ) e^{- \frac{c (a x + b y)}{a^2 + b^2}}

    and can be found in SymPy with ``pdsolve``::

        >>> from sympy.solvers import pdsolve
        >>> from sympy.abc import x, y, a, b, c
        >>> from sympy import Function, pprint
        >>> f = Function('f')
        >>> u = f(x,y)
        >>> ux = u.diff(x)
        >>> uy = u.diff(y)
        >>> genform = a*ux + b*uy + c*u
        >>> pprint(genform)
          d               d
        a*--(f(x, y)) + b*--(f(x, y)) + c*f(x, y)
          dx              dy

        >>> pprint(pdsolve(genform))
                                 -c*(a*x + b*y)
                                 ---------------
                                      2    2
                                     a  + b
        f(x, y) = F(-a*y + b*x)*e

    Examples
    ========

    >>> from sympy import pdsolve
    >>> from sympy import Function, pprint
    >>> from sympy.abc import x,y
    >>> f = Function('f')
    >>> pdsolve(f(x,y) + f(x,y).diff(x) + f(x,y).diff(y))
    Eq(f(x, y), F(x - y)*exp(-x/2 - y/2))
    >>> pprint(pdsolve(f(x,y) + f(x,y).diff(x) + f(x,y).diff(y)))
                          x   y
                        - - - -
                          2   2
    f(x, y) = F(x - y)*e

    References
    ==========

    - Viktor Grigoryan, "Partial Differential Equations"
      Math 124A - Fall 2010, pp.7

    r   r<   r>   r?   r@   r;   )r!   rG   r   r   r   )r$   r!   r'   r7   r-   rS   rT   rU   r>   r?   r@   r/   r/   r0   )pde_1st_linear_constant_coeff_homogeneous  s   A

Nrg   c              	   C   s2  t d\}}|j}|jd }|jd }	||d  }
||d  }||d  }||d   }tt| |
d |d   | }||}t|
| ||	  | || |
|	  | f||	}dt|
d |d   td| | |||
| ||	  f }t|||	t	|||  ||f|| |
|	  |
| ||	  fS )	aW  
    Solves a first order linear partial differential equation
    with constant coefficients.

    The general form of this partial differential equation is

    .. math:: a \frac{\partial f(x,y)}{\partial x}
              + b \frac{\partial f(x,y)}{\partial y}
              + c f(x,y) = G(x,y)

    where `a`, `b` and `c` are constants and `G(x, y)` can be an arbitrary
    function in `x` and `y`.

    The general solution of the PDE is:

    .. math::
        f(x, y) = \left. \left[F(\eta) + \frac{1}{a^2 + b^2}
        \int\limits^{a x + b y} G\left(\frac{a \xi + b \eta}{a^2 + b^2},
        \frac{- a \eta + b \xi}{a^2 + b^2} \right)
        e^{\frac{c \xi}{a^2 + b^2}}\, d\xi\right]
        e^{- \frac{c \xi}{a^2 + b^2}}
        \right|_{\substack{\eta=- a y + b x\\ \xi=a x + b y }}\, ,

    where `F(\eta)` is an arbitrary single-valued function. The solution
    can be found in SymPy with ``pdsolve``::

        >>> from sympy.solvers import pdsolve
        >>> from sympy.abc import x, y, a, b, c
        >>> from sympy import Function, pprint
        >>> f = Function('f')
        >>> G = Function('G')
        >>> u = f(x,y)
        >>> ux = u.diff(x)
        >>> uy = u.diff(y)
        >>> genform = a*ux + b*uy + c*u - G(x,y)
        >>> pprint(genform)
          d               d
        a*--(f(x, y)) + b*--(f(x, y)) + c*f(x, y) - G(x, y)
          dx              dy
        >>> pprint(pdsolve(genform, hint='1st_linear_constant_coeff_Integral'))
                  //          a*x + b*y                                             \
                  ||              /                                                 |
                  ||             |                                                  |
                  ||             |                                       c*xi       |
                  ||             |                                     -------      |
                  ||             |                                      2    2      |
                  ||             |      /a*xi + b*eta  -a*eta + b*xi\  a  + b       |
                  ||             |     G|------------, -------------|*e        d(xi)|
                  ||             |      |   2    2         2    2   |               |
                  ||             |      \  a  + b         a  + b    /               |
                  ||             |                                                  |
                  ||            /                                                   |
                  ||                                                                |
        f(x, y) = ||F(eta) + -------------------------------------------------------|*
                  ||                                  2    2                        |
                  \\                                 a  + b                         /
        <BLANKLINE>
                \|
                ||
                ||
                ||
                ||
                ||
                ||
                ||
                ||
          -c*xi ||
         -------||
          2    2||
         a  + b ||
        e       ||
                ||
                /|eta=-a*y + b*x, xi=a*x + b*y


    Examples
    ========

    >>> from sympy.solvers.pde import pdsolve
    >>> from sympy import Function, pprint, exp
    >>> from sympy.abc import x,y
    >>> f = Function('f')
    >>> eq = -2*f(x,y).diff(x) + 4*f(x,y).diff(y) + 5*f(x,y) - exp(x + 3*y)
    >>> pdsolve(eq)
    Eq(f(x, y), (F(4*x + 2*y) + exp(x/2 + 4*y)/15)*exp(x/2 - y))

    References
    ==========

    - Viktor Grigoryan, "Partial Differential Equations"
      Math 124A - Fall 2010, pp.7

    xi etar   r<   r>   r?   r@   rA   r;   )
r   r!   rG   r   r   r   r   rd   r   r   )r$   r!   r'   r7   r-   xietarS   rT   rU   r>   r?   r@   rA   ZexptermZfunctermZ	solvedictZgentermr/   r/   r0   pde_1st_linear_constant_coeff.  s"   b

"0"$rk   c                 C   s  ddl m} ddlm} td\}}|j}	|jd }
|jd }||d  }||d  }||d  }||d	   }|s|r>|s|raz	||| |}W n tyT   td
w t|	|
|||
| S |rz	||| |
}W n tyw   td
w t|	|
|||| S |s|	|
	|
| ||	|
  | }|||	|
}|j
|j
 |
|h }t|j|||}t|	|
||S |s|	|	|| ||	|  | }|||	|}|j
|j
 |
|h }t|j|||
}t|	|
||S td}|| |||
}|||
	|
| ||
}t|tr|d }|j
|j
 |
|h }t|dkr| }t||d ||
|}t|| |d }||	|
	|
 ||	|
  | ||}|||	|
ddj}t|trf|d }|j
|j
 |
|h }t||||}t|	|
||S td)a  
    Solves a first order linear partial differential equation
    with variable coefficients. The general form of this partial
    differential equation is

    .. math:: a(x, y) \frac{\partial f(x, y)}{\partial x}
                + b(x, y) \frac{\partial f(x, y)}{\partial y}
                + c(x, y) f(x, y) = G(x, y)

    where `a(x, y)`, `b(x, y)`, `c(x, y)` and `G(x, y)` are arbitrary
    functions in `x` and `y`. This PDE is converted into an ODE by
    making the following transformation:

    1. `\xi` as `x`

    2. `\eta` as the constant in the solution to the differential
       equation `\frac{dy}{dx} = -\frac{b}{a}`

    Making the previous substitutions reduces it to the linear ODE

    .. math:: a(\xi, \eta)\frac{du}{d\xi} + c(\xi, \eta)u - G(\xi, \eta) = 0

    which can be solved using ``dsolve``.

    >>> from sympy.abc import x, y
    >>> from sympy import Function, pprint
    >>> a, b, c, G, f= [Function(i) for i in ['a', 'b', 'c', 'G', 'f']]
    >>> u = f(x,y)
    >>> ux = u.diff(x)
    >>> uy = u.diff(y)
    >>> genform = a(x, y)*u + b(x, y)*ux + c(x, y)*uy - G(x,y)
    >>> pprint(genform)
                                         d                     d
    -G(x, y) + a(x, y)*f(x, y) + b(x, y)*--(f(x, y)) + c(x, y)*--(f(x, y))
                                         dx                    dy


    Examples
    ========

    >>> from sympy.solvers.pde import pdsolve
    >>> from sympy import Function, pprint
    >>> from sympy.abc import x,y
    >>> f = Function('f')
    >>> eq =  x*(u.diff(x)) - y*(u.diff(y)) + y**2*u - y**2
    >>> pdsolve(eq)
    Eq(f(x, y), F(x*y)*exp(y**2/2) + 1)

    References
    ==========

    - Viktor Grigoryan, "Partial Differential Equations"
      Math 124A - Fall 2010, pp.7

    r   )	integrate)dsolverh   r<   r>   r?   r@   rA   z7Unable to find a solution due to inability of integrateZ
1st_linear)r"   zOCannot solve the partial differential equation due to inability of constantsimp)sympy.integrals.integralsrl   Zsympy.solvers.oderm   r   r!   rG   r,   r   rK   Zfree_symbols_simplify_variable_coeffrI   r   rd   rH   listr5   r(   r   )r$   r!   r'   r7   r-   rl   rm   ri   rj   rS   rT   rU   r>   r?   r@   rA   ZtsolZplodere   symsrI   ZdummyhZsolsymZetatZysubZdeqfinalZfinsymsr/   r/   r0   pde_1st_linear_variable_coeff  sp   8

""*rt   c                 C   s`   t d}t|dkr| }| |||}nt|D ]\}}| |||}qt|||S )zX
    Helper function to replace constants by functions in 1st_linear_variable_coeff
    rj   r<   )r   r5   r(   rd   	enumerater   )re   rq   r!   Zfuncargrj   Zsymrs   keyr/   r/   r0   ro   %  s   ro   mulc                 C   sv  d}|dkr	d}n|dkrd}nt d| t| tr/| jdkr.tt| j| j d|||S n
tt| d|||S | jdkrBt dt|j}g }|D ]}t	dt
|jD ]
}||j|  qUqK|rjttj|}	nttj|}	t
|t
|kr|t dt|rt d	t|t|krt d
| j||	 }
|sd} |
jD ]}| ||	 7 } q| }
|d }|dd }t|
||S )a  Separate variables in partial differential equation either by additive
    or multiplicative separation approach. It tries to rewrite an equation so
    that one of the specified variables occurs on a different side of the
    equation than the others.

    :param eq: Partial differential equation

    :param fun: Original function F(x, y, z)

    :param sep: List of separated functions [X(x), u(y, z)]

    :param strategy: Separation strategy. You can choose between additive
        separation ('add') and multiplicative separation ('mul') which is
        default.

    Examples
    ========

    >>> from sympy import E, Eq, Function, pde_separate, Derivative as D
    >>> from sympy.abc import x, t
    >>> u, X, T = map(Function, 'uXT')

    >>> eq = Eq(D(u(x, t), x), E**(u(x, t))*D(u(x, t), t))
    >>> pde_separate(eq, u(x, t), [X(x), T(t)], strategy='add')
    [exp(-X(x))*Derivative(X(x), x), exp(T(t))*Derivative(T(t), t)]

    >>> eq = Eq(D(u(x, t), x, 2), D(u(x, t), t, 2))
    >>> pde_separate(eq, u(x, t), [X(x), T(t)], strategy='mul')
    [Derivative(X(x), (x, 2))/X(x), Derivative(T(t), (t, 2))/T(t)]

    See Also
    ========
    pde_separate_add, pde_separate_mul
    FaddTrw   zUnknown strategy: %sr   zValue should be 0zVariable counts do not matchz)Duplicate substitution arguments detectedzArguments do not matchr<   N)r`   rH   r   rI   pde_separater   rJ   rp   rG   ranger5   rQ   r   operatorrx   rw   r   rL   rd   r8   	_separate)r$   funsepstrategyZdo_addZ	orig_argsZ	subs_argsrY   jZ	functionsresultrW   ZsvarZdvarr/   r/   r0   ry   5  sJ   $




ry   c                 C      t | ||ddS )a{  
    Helper function for searching additive separable solutions.

    Consider an equation of two independent variables x, y and a dependent
    variable w, we look for the product of two functions depending on different
    arguments:

    `w(x, y, z) = X(x) + y(y, z)`

    Examples
    ========

    >>> from sympy import E, Eq, Function, pde_separate_add, Derivative as D
    >>> from sympy.abc import x, t
    >>> u, X, T = map(Function, 'uXT')

    >>> eq = Eq(D(u(x, t), x), E**(u(x, t))*D(u(x, t), t))
    >>> pde_separate_add(eq, u(x, t), [X(x), T(t)])
    [exp(-X(x))*Derivative(X(x), x), exp(T(t))*Derivative(T(t), t)]

    rx   r   ry   r$   r}   r~   r/   r/   r0   pde_separate_add     r   c                 C   r   )at  
    Helper function for searching multiplicative separable solutions.

    Consider an equation of two independent variables x, y and a dependent
    variable w, we look for the product of two functions depending on different
    arguments:

    `w(x, y, z) = X(x)*u(y, z)`

    Examples
    ========

    >>> from sympy import Function, Eq, pde_separate_mul, Derivative as D
    >>> from sympy.abc import x, y
    >>> u, X, Y = map(Function, 'uXY')

    >>> eq = Eq(D(u(x, y), x, 2), D(u(x, y), y, 2))
    >>> pde_separate_mul(eq, u(x, y), [X(x), Y(y)])
    [Derivative(X(x), (x, 2))/X(x), Derivative(Y(y), (y, 2))/Y(y)]

    rw   r   r   r   r/   r/   r0   pde_separate_mul  r   r   c                 C   s  t  }| jD ]'}|jr |jD ]}|jr|j| s|| qqq|jr-|j| s-|| qt  }|D ]}| |\}}|j| rF dS || q3t|dkrod}	| jD ]}d}
|D ]}|
|| 7 }
q]|	t	|
7 }	qW|	} t  }d }}| jD ](}|j| s||7 }qy| |\}}|j| r dS || || 8 }qyt
tj|}t	||  }t	||  }|j| s||rdS ||gS )zFSeparate expression into two parts based on dependencies of variables.Nr   )rL   rG   Zis_MulZis_Derivativerc   rx   r	   Zas_independentr5   r   r   r{   )r$   ZdepZothersZtermsZtermrW   Zdivextr~   rs   ZeqnrJ   rI   ZtempZfulldivr/   r/   r0   r|     sV   









r|   )Nr   FN)NF)NT)rw   )7__doc__	functoolsr   	itertoolsr   Zsympy.simplifyr   Z
sympy.corer   r   Zsympy.core.compatibilityr   Zsympy.core.functionr   r	   r
   r   Zsympy.core.relationalr   r   Zsympy.core.symbolr   r   r   Zsympy.functionsr   rn   r   Zsympy.utilities.iterablesr   Zsympy.utilities.miscr   Zsympy.solvers.deutilsr   r   r   Zsympy.solvers.solversr   Zsympy.simplify.radsimpr   r{   rP   r1   r+   r6   r)   r]   rg   rk   rt   ro   ry   r   r   r|   r/   r/   r/   r0   <module>   sD    "
  
 ^Ju 
Z