
    wgO8                    *   d Z ddlmZmZmZmZmZ ddlmZ ddl	m
Z
mZ ddlmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZ ddlmZmZ dd	lmZmZ dd
l m!Z!m"Z"m#Z#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.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZBmCZCmDZDmEZEmFZF ddlGmHZH ddlImJZJmKZK ddlLmMZM ddlNmOZOmPZPmQZQ ddlRmSZSmTZTmUZU dZVdLdZWdMdZX	 	 dNd!ZYdOd"ZZd# Z[dPd dddd$d%Z\dQd&Z]d' Z^d( Z_d) Z`d* Zad+ Zb ed      d,        ZcdRd-Zdd. Zed/ Zfd0 Zg ed      d1        ZhdSd2Zid3 Zjd4 Zkd5 Zld6 ZmdQd7Znd8 Zod9 Zpd: ZqdSd;Zrd< Zsd= Ztd> Zud? Zvd@ ZwdA ZxdB ZydC ZzdD Z{dE Z|dF Z}dG Z~dH ZdI ZdJ ZddKlmZmZmZ y)Ta4  
This module contains :py:meth:`~sympy.solvers.ode.dsolve` and different helper
functions that it uses.

:py:meth:`~sympy.solvers.ode.dsolve` solves ordinary differential equations.
See the docstring on the various functions for their uses.  Note that partial
differential equations support is in ``pde.py``.  Note that hint functions
have docstrings describing their various methods, but they are intended for
internal use.  Use ``dsolve(ode, func, hint=hint)`` to solve an ODE using a
specific hint.  See also the docstring on
:py:meth:`~sympy.solvers.ode.dsolve`.

**Functions in this module**

    These are the user functions in this module:

    - :py:meth:`~sympy.solvers.ode.dsolve` - Solves ODEs.
    - :py:meth:`~sympy.solvers.ode.classify_ode` - Classifies ODEs into
      possible hints for :py:meth:`~sympy.solvers.ode.dsolve`.
    - :py:meth:`~sympy.solvers.ode.checkodesol` - Checks if an equation is the
      solution to an ODE.
    - :py:meth:`~sympy.solvers.ode.homogeneous_order` - Returns the
      homogeneous order of an expression.
    - :py:meth:`~sympy.solvers.ode.infinitesimals` - Returns the infinitesimals
      of the Lie group of point transformations of an ODE, such that it is
      invariant.
    - :py:meth:`~sympy.solvers.ode.checkinfsol` - Checks if the given infinitesimals
      are the actual infinitesimals of a first order ODE.

    These are the non-solver helper functions that are for internal use.  The
    user should use the various options to
    :py:meth:`~sympy.solvers.ode.dsolve` to obtain the functionality provided
    by these functions:

    - :py:meth:`~sympy.solvers.ode.ode.odesimp` - Does all forms of ODE
      simplification.
    - :py:meth:`~sympy.solvers.ode.ode.ode_sol_simplicity` - A key function for
      comparing solutions by simplicity.
    - :py:meth:`~sympy.solvers.ode.constantsimp` - Simplifies arbitrary
      constants.
    - :py:meth:`~sympy.solvers.ode.ode.constant_renumber` - Renumber arbitrary
      constants.
    - :py:meth:`~sympy.solvers.ode.ode._handle_Integral` - Evaluate unevaluated
      Integrals.

    See also the docstrings of these functions.

**Currently implemented solver methods**

The following methods are implemented for solving ordinary differential
equations.  See the docstrings of the various hint functions for more
information on each (run ``help(ode)``):

  - 1st order separable differential equations.
  - 1st order differential equations whose coefficients or `dx` and `dy` are
    functions homogeneous of the same order.
  - 1st order exact differential equations.
  - 1st order linear differential equations.
  - 1st order Bernoulli differential equations.
  - Power series solutions for first order differential equations.
  - Lie Group method of solving first order differential equations.
  - 2nd order Liouville differential equations.
  - Power series solutions for second order differential equations
    at ordinary and regular singular points.
  - `n`\th order differential equation that can be solved with algebraic
    rearrangement and integration.
  - `n`\th order linear homogeneous differential equation with constant
    coefficients.
  - `n`\th order linear inhomogeneous differential equation with constant
    coefficients using the method of undetermined coefficients.
  - `n`\th order linear inhomogeneous differential equation with constant
    coefficients using the method of variation of parameters.

**Philosophy behind this module**

This module is designed to make it easy to add new ODE solving methods without
having to mess with the solving code for other methods.  The idea is that
there is a :py:meth:`~sympy.solvers.ode.classify_ode` function, which takes in
an ODE and tells you what hints, if any, will solve the ODE.  It does this
without attempting to solve the ODE, so it is fast.  Each solving method is a
hint, and it has its own function, named ``ode_<hint>``.  That function takes
in the ODE and any match expression gathered by
:py:meth:`~sympy.solvers.ode.classify_ode` and returns a solved result.  If
this result has any integrals in it, the hint function will return an
unevaluated :py:class:`~sympy.integrals.integrals.Integral` class.
:py:meth:`~sympy.solvers.ode.dsolve`, which is the user wrapper function
around all of this, will then call :py:meth:`~sympy.solvers.ode.ode.odesimp` on
the result, which, among other things, will attempt to solve the equation for
the dependent variable (the function we are solving for), simplify the
arbitrary constants in the expression, and evaluate any integrals, if the hint
allows it.

**How to add new solution methods**

If you have an ODE that you want :py:meth:`~sympy.solvers.ode.dsolve` to be
able to solve, try to avoid adding special case code here.  Instead, try
finding a general method that will solve your ODE, as well as others.  This
way, the :py:mod:`~sympy.solvers.ode` module will become more robust, and
unhindered by special case hacks.  WolphramAlpha and Maple's
DETools[odeadvisor] function are two resources you can use to classify a
specific ODE.  It is also better for a method to work with an `n`\th order ODE
instead of only with specific orders, if possible.

To add a new method, there are a few things that you need to do.  First, you
need a hint name for your method.  Try to name your hint so that it is
unambiguous with all other methods, including ones that may not be implemented
yet.  If your method uses integrals, also include a ``hint_Integral`` hint.
If there is more than one way to solve ODEs with your method, include a hint
for each one, as well as a ``<hint>_best`` hint.  Your ``ode_<hint>_best()``
function should choose the best using min with ``ode_sol_simplicity`` as the
key argument.  See
:obj:`~sympy.solvers.ode.single.HomogeneousCoeffBest`, for example.
The function that uses your method will be called ``ode_<hint>()``, so the
hint must only use characters that are allowed in a Python function name
(alphanumeric characters and the underscore '``_``' character).  Include a
function for every hint, except for ``_Integral`` hints
(:py:meth:`~sympy.solvers.ode.dsolve` takes care of those automatically).
Hint names should be all lowercase, unless a word is commonly capitalized
(such as Integral or Bernoulli).  If you have a hint that you do not want to
run with ``all_Integral`` that does not have an ``_Integral`` counterpart (such
as a best hint that would defeat the purpose of ``all_Integral``), you will
need to remove it manually in the :py:meth:`~sympy.solvers.ode.dsolve` code.
See also the :py:meth:`~sympy.solvers.ode.classify_ode` docstring for
guidelines on writing a hint name.

Determine *in general* how the solutions returned by your method compare with
other methods that can potentially solve the same ODEs.  Then, put your hints
in the :py:data:`~sympy.solvers.ode.allhints` tuple in the order that they
should be called.  The ordering of this tuple determines which hints are
default.  Note that exceptions are ok, because it is easy for the user to
choose individual hints with :py:meth:`~sympy.solvers.ode.dsolve`.  In
general, ``_Integral`` variants should go at the end of the list, and
``_best`` variants should go before the various hints they apply to.  For
example, the ``undetermined_coefficients`` hint comes before the
``variation_of_parameters`` hint because, even though variation of parameters
is more general than undetermined coefficients, undetermined coefficients
generally returns cleaner results for the ODEs that it can solve than
variation of parameters does, and it does not require integration, so it is
much faster.

Next, you need to have a match expression or a function that matches the type
of the ODE, which you should put in :py:meth:`~sympy.solvers.ode.classify_ode`
(if the match function is more than just a few lines.  It should match the
ODE without solving for it as much as possible, so that
:py:meth:`~sympy.solvers.ode.classify_ode` remains fast and is not hindered by
bugs in solving code.  Be sure to consider corner cases.  For example, if your
solution method involves dividing by something, make sure you exclude the case
where that division will be 0.

In most cases, the matching of the ODE will also give you the various parts
that you need to solve it.  You should put that in a dictionary (``.match()``
will do this for you), and add that as ``matching_hints['hint'] = matchdict``
in the relevant part of :py:meth:`~sympy.solvers.ode.classify_ode`.
:py:meth:`~sympy.solvers.ode.classify_ode` will then send this to
:py:meth:`~sympy.solvers.ode.dsolve`, which will send it to your function as
the ``match`` argument.  Your function should be named ``ode_<hint>(eq, func,
order, match)`.  If you need to send more information, put it in the ``match``
dictionary.  For example, if you had to substitute in a dummy variable in
:py:meth:`~sympy.solvers.ode.classify_ode` to match the ODE, you will need to
pass it to your function using the `match` dict to access it.  You can access
the independent variable using ``func.args[0]``, and the dependent variable
(the function you are trying to solve for) as ``func.func``.  If, while trying
to solve the ODE, you find that you cannot, raise ``NotImplementedError``.
:py:meth:`~sympy.solvers.ode.dsolve` will catch this error with the ``all``
meta-hint, rather than causing the whole routine to fail.

Add a docstring to your function that describes the method employed.  Like
with anything else in SymPy, you will need to add a doctest to the docstring,
in addition to real tests in ``test_ode.py``.  Try to maintain consistency
with the other hint functions' docstrings.  Add your method to the list at the
top of this docstring.  Also, add your method to ``ode.rst`` in the
``docs/src`` directory, so that the Sphinx docs will pull its docstring into
the main SymPy documentation.  Be sure to make the Sphinx documentation by
running ``make html`` from within the doc directory to verify that the
docstring formats correctly.

If your solution method involves integrating, use :py:obj:`~.Integral` instead of
:py:meth:`~sympy.core.expr.Expr.integrate`.  This allows the user to bypass
hard/slow integration by using the ``_Integral`` variant of your hint.  In
most cases, calling :py:meth:`sympy.core.basic.Basic.doit` will integrate your
solution.  If this is not the case, you will need to write special code in
:py:meth:`~sympy.solvers.ode.ode._handle_Integral`.  Arbitrary constants should be
symbols named ``C1``, ``C2``, and so on.  All solution methods should return
an equality instance.  If you need an arbitrary number of arbitrary constants,
you can use ``constants = numbered_symbols(prefix='C', cls=Symbol, start=1)``.
If it is possible to solve for the dependent function in a general way, do so.
Otherwise, do as best as you can, but do not call solve in your
``ode_<hint>()`` function.  :py:meth:`~sympy.solvers.ode.ode.odesimp` will attempt
to solve the solution for you, so you do not need to do that.  Lastly, if your
ODE has a common simplification that can be applied to your solutions, you can
add a special case in :py:meth:`~sympy.solvers.ode.ode.odesimp` for it.  For
example, solutions returned from the ``1st_homogeneous_coeff`` hints often
have many :obj:`~sympy.functions.elementary.exponential.log` terms, so
:py:meth:`~sympy.solvers.ode.ode.odesimp` calls
:py:meth:`~sympy.simplify.simplify.logcombine` on them (it also helps to write
the arbitrary constant as ``log(C1)`` instead of ``C1`` in this case).  Also
consider common ways that you can rearrange your solution to have
:py:meth:`~sympy.solvers.ode.constantsimp` take better advantage of it.  It is
better to put simplification in :py:meth:`~sympy.solvers.ode.ode.odesimp` than in
your method, because it can then be turned off with the simplify flag in
:py:meth:`~sympy.solvers.ode.dsolve`.  If you have any extraneous
simplification in your function, be sure to only run it using ``if
match.get('simplify', True):``, especially if it can be slow or if it can
reduce the domain of the solution.

Finally, as with every contribution to SymPy, your method will need to be
tested.  Add a test for each method in ``test_ode.py``.  Follow the
conventions there, i.e., test the solver using ``dsolve(eq, f(x),
hint=your_hint)``, and also test the solution using
:py:meth:`~sympy.solvers.ode.checkodesol` (you can put these in a separate
tests and skip/XFAIL if it runs too slow/does not work).  Be sure to call your
hint specifically in :py:meth:`~sympy.solvers.ode.dsolve`, that way the test
will not be broken simply by the introduction of another matching hint.  If your
method works for higher order (>1) ODEs, you will need to run ``sol =
constant_renumber(sol, 'C', 1, order)`` for each solution, where ``order`` is
the order of the ODE.  This is because ``constant_renumber`` renumbers the
arbitrary constants by printing order, which is platform dependent.  Try to
test every corner case of your solver, including a range of orders if it is a
`n`\th order solver, but if your solver is slow, such as if it involves hard
integration, try to keep the test run time down.

Feel free to refactor existing hints to avoid duplicating code or creating
inconsistencies.  If you can show that your method exactly duplicates an
existing method, including in the simplicity and speed of obtaining the
solutions, then you can remove the old, less general method.  The existing
code is tested extensively in ``test_ode.py``, so if anything is broken, one
of those tests will surely fail.

    )AddSMulPowoo)Tuple)
AtomicExprExpr)Function
DerivativeAppliedUndefdiffexpand
expand_mulSubs)	vectorize)nanzooNumber)EqualityEq)default_sort_keyordered)SymbolWildDummysymbols)sympify)preorder_traversal)BooleanAtomBooleanTrueBooleanFalse)explogsqrt)	factorial)Integral)Poly	terms_gcdPolynomialErrorlcm)cancel)Order)series)collect
logcombinepowsimpseparatevarssimplifycse)collect_const)checksolsolve)numbered_symbols)uniqsiftiterable)_preprocess	ode_order_desolve)-
factorablenth_algebraic	separable	1st_exact
1st_linear	Bernoulli1st_rational_riccatiRiccati_special_minus21st_homogeneous_coeff_best(1st_homogeneous_coeff_subs_indep_div_dep(1st_homogeneous_coeff_subs_dep_div_indepalmost_linearlinear_coefficientsseparable_reduced1st_power_series	lie_group%nth_linear_constant_coeff_homogeneousnth_linear_euler_eq_homogeneous3nth_linear_constant_coeff_undetermined_coefficients<nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients1nth_linear_constant_coeff_variation_of_parameters:nth_linear_euler_eq_nonhomogeneous_variation_of_parameters	Liouville2nd_linear_airy2nd_linear_bessel2nd_hypergeometric2nd_hypergeometric_Integralnth_order_reducible2nd_power_series_ordinary2nd_power_series_regularnth_algebraic_Integralseparable_Integral1st_exact_Integral1st_linear_IntegralBernoulli_Integral11st_homogeneous_coeff_subs_indep_div_dep_Integral11st_homogeneous_coeff_subs_dep_div_indep_Integralalmost_linear_Integrallinear_coefficients_Integralseparable_reduced_Integral:nth_linear_constant_coeff_variation_of_parameters_IntegralCnth_linear_euler_eq_nonhomogeneous_variation_of_parameters_IntegralLiouville_Integral"2nd_nonlinear_autonomous_conserved+2nd_nonlinear_autonomous_conserved_Integral   c                     t        | ||      }t        |      D cg c]  }t        |       }}|dk(  r|d   S t        |      S c c}w )zJ
    Returns a list of constants that do not occur
    in eq already.
    rl   r   )iter_numbered_constantsrangenexttuple)eqnumstartprefixncsiCss          Z/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/solvers/ode/ode.pyget_numbered_constantsrz   G  sK     ""eV
4C"3Z	($s)	(B	(AXBqE-59- 
)s   Ac           	         t        | t        t        f      r| g} nt        |       st	        d| z         t               j                  | D cg c]  }|j                   c} } t               j                  | D cg c]  }|j                  t               c} }|r/||D ch c]   }t        t        |j                              " c}z  }t        |||      S c c}w c c}w c c}w )zO
    Returns an iterator of constants that do not occur
    in eq already.
    z$Expected Expr or iterable but got %srt   ru   exclude)
isinstancer
   r   r;   
ValueErrorsetunionfree_symbolsatomsr   r   strfuncr8   )rr   rt   ru   rw   atom_setfunc_setfs          ry   rn   rn   R  s     "tRj!Tb\?"DEEsu{{R8Q^^89Hsu{{;1QWWX.;<H(;QVCK(;;%II	 9;;s   C;C"%C$NTc	                    t        |       r(ddlm}
 	  |
| |d      }t        |      dk(  r|d   S |S |}t1        | f|d||d|||d	|	}|j3                  d|       } |j3                  dd      }|ri }i }t5        | dd      }|d   }|D ]  }	 t7        | |||         }|||<    ||   d   t9        t        |j#                               fd      |d<   |dk(  r|d   S |D ]!  }|d   |j;                  |d      k(  s||d<    n |d   |d<   |d   |d<   |j=                  |       |S |d   }t7        | |||      S # t        $ r Y nw xY wt        |       }|d   } |d   }|d   t        t        | d   j                  t                    d   j                  t                    d   }t        t        |             D ]`  }D ]Y  }t        |t              r| |   j                  t        |   |t        | |   |                     j                  sQ| |    | |<   [ b | |d<   t        t!        |j#                                     dk7  rt%        d	      t        |j#                               d   |d<   fd
       t        |       k7  rt%        d      |d   t        |d   dk(  rt'               d|z     }nt'               d|z     } ||      }|rWt)        | j*                  t)        |  j*                  z
  }t-        |||      }|D cg c]  }|j/                  |       c}S c c}w |S # t        $ r}|||<   Y d}~d}~ww xY w)a*&  
    Solves any (supported) kind of ordinary differential equation and
    system of ordinary differential equations.

    For single ordinary differential equation
    =========================================

    It is classified under this when number of equation in ``eq`` is one.
    **Usage**

        ``dsolve(eq, f(x), hint)`` -> Solve ordinary differential equation
        ``eq`` for function ``f(x)``, using method ``hint``.

    **Details**

        ``eq`` can be any supported ordinary differential equation (see the
            :py:mod:`~sympy.solvers.ode` docstring for supported methods).
            This can either be an :py:class:`~sympy.core.relational.Equality`,
            or an expression, which is assumed to be equal to ``0``.

        ``f(x)`` is a function of one variable whose derivatives in that
            variable make up the ordinary differential equation ``eq``.  In
            many cases it is not necessary to provide this; it will be
            autodetected (and an error raised if it could not be detected).

        ``hint`` is the solving method that you want dsolve to use.  Use
            ``classify_ode(eq, f(x))`` to get all of the possible hints for an
            ODE.  The default hint, ``default``, will use whatever hint is
            returned first by :py:meth:`~sympy.solvers.ode.classify_ode`.  See
            Hints below for more options that you can use for hint.

        ``simplify`` enables simplification by
            :py:meth:`~sympy.solvers.ode.ode.odesimp`.  See its docstring for more
            information.  Turn this off, for example, to disable solving of
            solutions for ``func`` or simplification of arbitrary constants.
            It will still integrate with this hint. Note that the solution may
            contain more arbitrary constants than the order of the ODE with
            this option enabled.

        ``xi`` and ``eta`` are the infinitesimal functions of an ordinary
            differential equation. They are the infinitesimals of the Lie group
            of point transformations for which the differential equation is
            invariant. The user can specify values for the infinitesimals. If
            nothing is specified, ``xi`` and ``eta`` are calculated using
            :py:meth:`~sympy.solvers.ode.infinitesimals` with the help of various
            heuristics.

        ``ics`` is the set of initial/boundary conditions for the differential equation.
          It should be given in the form of ``{f(x0): x1, f(x).diff(x).subs(x, x2):
          x3}`` and so on.  For power series solutions, if no initial
          conditions are specified ``f(0)`` is assumed to be ``C0`` and the power
          series solution is calculated about 0.

        ``x0`` is the point about which the power series solution of a differential
          equation is to be evaluated.

        ``n`` gives the exponent of the dependent variable up to which the power series
          solution of a differential equation is to be evaluated.

    **Hints**

        Aside from the various solving methods, there are also some meta-hints
        that you can pass to :py:meth:`~sympy.solvers.ode.dsolve`:

        ``default``:
                This uses whatever hint is returned first by
                :py:meth:`~sympy.solvers.ode.classify_ode`. This is the
                default argument to :py:meth:`~sympy.solvers.ode.dsolve`.

        ``all``:
                To make :py:meth:`~sympy.solvers.ode.dsolve` apply all
                relevant classification hints, use ``dsolve(ODE, func,
                hint="all")``.  This will return a dictionary of
                ``hint:solution`` terms.  If a hint causes dsolve 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 ODE.  See also
                  :py:meth:`~sympy.solvers.deutils.ode_order` in
                  ``deutils.py``.
                - ``best``: The simplest hint; what would be returned by
                  ``best`` below.
                - ``best_hint``: The hint that would produce the solution
                  given by ``best``.  If more than one hint produces the best
                  solution, the first one in the tuple returned by
                  :py:meth:`~sympy.solvers.ode.classify_ode` is chosen.
                - ``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
                  :py:meth:`~sympy.solvers.ode.classify_ode`.

        ``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
                :py:meth:`~sympy.solvers.ode.dsolve` to hang because of a
                difficult or impossible integral.  This meta-hint will also be
                much faster than ``all``, because
                :py:meth:`~sympy.core.expr.Expr.integrate` is an expensive
                routine.

        ``best``:
                To have :py:meth:`~sympy.solvers.ode.dsolve` try all methods
                and return the simplest one.  This takes into account whether
                the solution is solvable in the function, whether it contains
                any Integral classes (i.e.  unevaluatable integrals), and
                which one is the shortest in size.

        See also the :py:meth:`~sympy.solvers.ode.classify_ode` docstring for
        more info on hints, and the :py:mod:`~sympy.solvers.ode` 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 # x is the independent variable
            >>> f = Function("f")(x) # f is a function of x
            >>> # f_ will be the derivative of f with respect to x
            >>> f_ = Derivative(f, x)

        - See ``test_ode.py`` for many tests, which serves also as a set of
          examples for how to use :py:meth:`~sympy.solvers.ode.dsolve`.
        - :py:meth:`~sympy.solvers.ode.dsolve` always returns an
          :py:class:`~sympy.core.relational.Equality` class (except for the
          case when the hint is ``all`` or ``all_Integral``).  If possible, it
          solves the solution explicitly for the function being solved for.
          Otherwise, it returns an implicit solution.
        - Arbitrary constants are symbols named ``C1``, ``C2``, and so on.
        - Because all solutions should be mathematically equivalent, some
          hints may return the exact same result for an ODE. Often, though,
          two different hints will return the same solution formatted
          differently.  The two should be equivalent. Also note that sometimes
          the values of the arbitrary constants in two different solutions may
          not be the same, because one constant may have "absorbed" other
          constants into it.
        - Do ``help(ode.ode_<hintname>)`` to get help more information on a
          specific hint, where ``<hintname>`` is the name of a hint without
          ``_Integral``.

    For system of ordinary differential equations
    =============================================

    **Usage**
        ``dsolve(eq, func)`` -> Solve a system of ordinary differential
        equations ``eq`` for ``func`` being list of functions including
        `x(t)`, `y(t)`, `z(t)` where number of functions in the list depends
        upon the number of equations provided in ``eq``.

    **Details**

        ``eq`` can be any supported system of ordinary differential equations
        This can either be an :py:class:`~sympy.core.relational.Equality`,
        or an expression, which is assumed to be equal to ``0``.

        ``func`` holds ``x(t)`` and ``y(t)`` being functions of one variable which
        together with some of their derivatives make up the system of ordinary
        differential equation ``eq``. It is not necessary to provide this; it
        will be autodetected (and an error raised if it could not be detected).

    **Hints**

        The hints are formed by parameters returned by classify_sysode, combining
        them give hints name used later for forming method name.

    Examples
    ========

    >>> from sympy import Function, dsolve, Eq, Derivative, sin, cos, symbols
    >>> from sympy.abc import x
    >>> f = Function('f')
    >>> dsolve(Derivative(f(x), x, x) + 9*f(x), f(x))
    Eq(f(x), C1*sin(3*x) + C2*cos(3*x))

    >>> eq = sin(x)*cos(f(x)) + cos(x)*sin(f(x))*f(x).diff(x)
    >>> dsolve(eq, hint='1st_exact')
    [Eq(f(x), -acos(C1/cos(x)) + 2*pi), Eq(f(x), acos(C1/cos(x)))]
    >>> dsolve(eq, hint='almost_linear')
    [Eq(f(x), -acos(C1/cos(x)) + 2*pi), Eq(f(x), acos(C1/cos(x)))]
    >>> t = symbols('t')
    >>> x, y = symbols('x, y', cls=Function)
    >>> eq = (Eq(Derivative(x(t),t), 12*t*x(t) + 8*y(t)), Eq(Derivative(y(t),t), 21*x(t) + 7*t*y(t)))
    >>> dsolve(eq)
    [Eq(x(t), C1*x0(t) + C2*x0(t)*Integral(8*exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0(t)**2, t)),
    Eq(y(t), C1*y0(t) + C2*(y0(t)*Integral(8*exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0(t)**2, t) +
    exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0(t)))]
    >>> eq = (Eq(Derivative(x(t),t),x(t)*y(t)*sin(t)), Eq(Derivative(y(t),t),y(t)**2*sin(t)))
    >>> dsolve(eq)
    {Eq(x(t), -exp(C1)/(C2*exp(C1) - cos(t))), Eq(y(t), -1/(C1 - cos(t)))}
    r   )dsolve_systemT)funcsicsdoitrl   rr   orderr   z@It solves only those systems of equations whose orders are equalc                 ,    t        fd| D              S )Nc              3   R   K   | ]  }t        |t              r |      nd    yw)rl   N)r~   list).0item	recur_lens     ry   	<genexpr>z,dsolve.<locals>.recur_len.<locals>.<genexpr>H  s#     U4*T$*?yQFUs   $')sum)lr   s    ry   r   zdsolve.<locals>.recur_lenG  s    USTUUU    z_dsolve() and classify_sysode() work with number of functions being equal to number of equationstype_of_equationN	is_linearz1sysode_linear_%(no_of_equation)seq_order%(order)sz4sysode_nonlinear_%(no_of_equation)seq_order%(order)sode)	r   hintr3   xietatyper   x0nallF)dictr   ordered_hintsc                 "    t        |        S )N
trysolving)ode_sol_simplicity)xr   r3   s    ry   <lambda>zdsolve.<locals>.<lambda>p  s    "1d8|D r   keybest	best_hintdefaultr   )r   )r;   sympy.solvers.ode.systemsr   lenNotImplementedErrorclassify_sysoder   r   r   r   ro   r~   coeffr   r=   is_negativer   valuesr   globalsr   r   	solve_icssubsr>   popclassify_ode_helper_simplifymingetupdate)rr   r   r   r3   r   r   r   r   r   kwargsr   solmatchr   trw   func_	solvefuncsols	constantssolved_constants
given_hinthintsall_retdictfailed_hintsgethintsorderedhintsrvdetailr   s    ` `                          @ry   dsolver   d  s   D |;	$CdCC X]3q633T 
  "$5cQ" " YYtR yy&GL#BT>H#O4L '')"dE$KJB %'GDM' ;v&D!$w~~'7"8 ?E FGFOV#v&! 6?gkk!T&::+,GK( "*)!4GI'0GGNN<(N =D#BeX3GG_ # 		  D)4[gV}bekk*-.q177?@C s2w 	'A 'eT*!u{{4Q)BqE472K#LMYY!#A1'	' ds5<<>"#Q&_``elln-a0g	VT?c"g% E F F#$,%%[!T)#I&Y\a&ab	#I&\_d&de	U#D!4L55r
8O8OO	#,T4C#H >BCs!12CCCK$ + 0)/L&0s4   E E L8	EEL18	MMMc                    |}|d   }|d   }||   }t        |t              r|}	n?|j                  d      rt               d|dt	        d        z      }	nt               d|z      }	| j
                  fd}
|rt        |	t              r|	j                         }n |	| |||      }t        |      rFg }|D ]>  }t        | |||      }t        |      r|j                  |       .|j                  |       @ nzt        | |||      }nkt        |	t              r|	j                  d      }nd|d	<    |	| |||      }t        |t              r|D cg c]  }t        |||       }}nt        |||      }t        |t              rIt        d
 |D              sJ |       |rt        | |||j                  d         }t	        |      dk(  r|d   }|rd|vrt        |t         t"        f      r,t%        |g|d   g |
|      |      }|j'                  |      }|S g }|D ]<  }	 t%        |g|d   g |
|      |      }|j                  |j'                  |             > t	        |      dk(  r|d   S |}|S c c}w # t(        $ r Y fw xY w)a  
    Helper function of dsolve that calls the respective
    :py:mod:`~sympy.solvers.ode` functions to solve for the ordinary
    differential equations. This minimizes the computation in calling
    :py:meth:`~sympy.solvers.deutils._desolve` multiple times.
    r   r   	_Integralode_Nc                 :    | j                   j                        S N)r   
difference)sfrees    ry   r   z"_helper_simplify.<locals>.<lambda>  s    Q^^..t4 r   F)r3   r3   c              3   <   K   | ]  }t        |t                y wr   )r~   r   r   rw   s     ry   r   z#_helper_simplify.<locals>.<genexpr>  s     1:a$1   r   rl   power_series)r~   SingleODESolverendswithr   r   r   get_general_solutionr;   odesimpextendappendr   _handle_Integralr   _remove_redundant_solutionsargsr
   r   r   r   r   )rr   r   r   r3   r   r   rr   r   r   consr   r   r   simpexprsexprr   rv1r   s                      @ry   r   r     s    	AV9DgJEdGE%)		{	#Ift,>c+.>->'??@	Iftm,	??D4D i1113DRue4DD>B $r1dD1D>IIdOIIdO$ T4.B i122E2BE %E*b$u5EeT"AFG"4t4GBG!%t4B"d1b115251,RUDIIaLIBr7a<AB
~T)b4*%("&	{DHcJ)*B I C 5'0!qyk47C'P$ 

166"2345 3x1}1vBI3 H& " s   I*I//	I;:I;c           
         |d   j                   d   }g }g }t               }|j                         D ]5  \  }}	t        |t              r@|j                   d   }
|D cg c]  }|j
                  |j
                  k(  s|  c}d   }| }n\t        |t        t        f      r:t        |t              r|j                         }t        |t              r4|j                  }|j                  d   }
|j                  j                  }|}nLt        |t              r<|}|j                  d   }
|ft        |j                        z  }|j                  |
|      }| D ]q  }|j                  j                  j
                        s)|j                  t!         |j"                  j$                    |j&                  j$                  |              s |j)                         |}nt+        d      |D ]~  }|j                        s|}|j                  |
      }|j                  ||	      }t        |t,              r|rN|D cg c]  }t        |t,              r| }}|j                  |        8 	 t/        ||d      }|st1        d      |dk(  rt1        d      t        |      dkD  rt+        d      |d   S c c}w c c}w # t*        $ r g }Y Rw xY w)	a  
    Solve for the constants given initial conditions

    ``sols`` is a list of solutions.

    ``funcs`` is a list of functions.

    ``constants`` is a list of constants.

    ``ics`` is the set of initial/boundary conditions for the differential
    equation. It should be given in the form of ``{f(x0): x1,
    f(x).diff(x).subs(x, x2):  x3}`` and so on.

    Returns a dictionary mapping constants to values.
    ``solution.subs(constants)`` will replace the constants in ``solution``.

    Example
    =======
    >>> # From dsolve(f(x).diff(x) - f(x), f(x))
    >>> from sympy import symbols, Eq, exp, Function
    >>> from sympy.solvers.ode.ode import solve_ics
    >>> f = Function('f')
    >>> x, C1 = symbols('x C1')
    >>> sols = [Eq(f(x), C1*exp(x))]
    >>> funcs = [f(x)]
    >>> constants = [C1]
    >>> ics = {f(0): 2}
    >>> solved_constants = solve_ics(sols, funcs, constants, ics)
    >>> solved_constants
    {C1: 2}
    >>> sols[0].subs(solved_constants)
    Eq(f(x), 2*exp(x))

    r   zUnrecognized initial conditionTr   z%Couldn't solve for initial conditionsz\Initial conditions did not produce any solutions for constants. Perhaps they are degenerate.rl   z<Initial conditions produced too many solutions for constants)r   r   itemsr~   r   r   r   r   r   r   point	variablesr   r   hasr   r   lhsr   rhsaddr   r    r7   r   )r   r   r   r   r   	diff_sols	subs_solsdiff_variablesfuncargvaluer   r   matching_funcr   derivr   r   sol2r   r   s                       ry   r   r     s   N 	aaAIIUN))+ $+g|,aB(-H17<<1GQHKMA$
!34'4( ",,.'4(]]1%#LL22	 %GZ0&&q)DW%6%6!77	 %

2q 1 ]775::??+$$Ri(@,#'',,PYBZ%[\] y)A%&FGG 	+Cww}%yyB'yy%0!$4I,5 XqZ;=W XI X$$T*	+9$+N IDA @AA4wxx
q !"`aaAm I@ !Y  s*   J4:J48J9J9+J> >KK)prepr   r   r   c          	      z  78 t        |      }|r&t        |j                        dk7  rt        d|z        t	        | t
              r| j                  | j                  z
  } | }	|s|t        | |      \  } }
||
}|j                  d   }|j                  }t        d      }|dn|}t        |  ||            }d|i} ||      j                  |      }t        d ||      g	      }t        d
| ||      j                  |d      g	      }t        d|g	      }t        d| ||      |g	      }t        d|g	      }t        d ||      | ||      j                  |d      g	      }t        d ||      | ||      j                  |d      g	      }t        d ||      | ||      j                  |d      g	      }i }t        d      }||D ]  }t	        |t        t         f      rSt	        |t              r+|j"                  7|j$                  d   }|j&                  d   }n#t	        |t               r|7|}|j$                  d   }t	        7t               rt	        7j                  d   t(              r7j                  d   j                  |k(  rt        7j                  d   j                        dk(  r||k(  rwj+                  |      sft-        7fd7j$                  D              rH|||   j.                  vr7t        7|      }dt1        |      z   }|j3                  |||dz   ||   i       ct        d      t	        |t(              r|j                  |k(  rmt        |j                        dk(  rU|j                  d   j+                  |      s7|||   j.                  vr&|j3                  |j                  d   ||   d       t        d      t        d       t5        |	|||||      } |j7                  dd      }!|!dk(  }"|!j9                  d      r|!dt        d        }!t:        }#|!dvr|!t:        v r|!t:        |!   i}#|#D ]H  }$ |#|$   |       }%|%j=                         s|%||$<   |#|$   j>                  r|%||$dz   <   |s>|"sA|$|d<   |c S  tA        |       } d}&| jB                  r| jE                   ||      j                  ||            }'|'dvrU|'jG                  | ||      |z  z        88r68|   r1 ||      8|   z  }(tI        | j                  D )cg c]  })|)|(z  	 c}) }&|&s| }&|dk(  rtK        | |d !      jG                  |||z  z         88r|8d
<   |8d<   |8d<   8|   jM                   ||      |      8|<   8|   jM                   ||      |      8|<   |j7                  d"d      }*|j7                  d#|      }+tO        8|   8|   z        },|,jM                  ||*||+i      }-|-j+                  tP              sf|-j+                  tR              sP|-j+                  tT              s:|-j+                  tP               s#|-j                  |      jM                  ||*||+i      }.|.j+                  tP              s|.j+                  tR              s|.j+                  tT              s|.j+                  tP               s8jW                         }/|/j3                  ||*|+d$       |/|d%<   nz|dk(  rt| ||      j                  |d      z  ||z  z   | ||      z  z   }0tK        |& ||      j                  |d       ||      j                  |       ||      g      jG                  |0      8d&}18rt-        8fd'8D              sm|&jY                         \  }}tA        |      }&tK        |& ||      j                  |d       ||      j                  |       ||      g      jG                  |0      88rp8|   dk7  rgtO        8|   8|   z        }2tO        8|   8|   z        }3|j7                  d(d      }*|2jM                  ||*      },|,j+                  tP        tT        tR        tP               sU|3jM                  ||*      },|,j+                  tP        tT        tR        tP               sd }18j3                  ||||*|d)       8|d*<   |1stO        ||*z
  |2z        }2|2jM                  ||*      },|,j+                  tP        tT        tR        tP               sWtO        ||*z
  dz  |3z        }3|3jM                  ||*      },|,j+                  tP        tT        tR        tP               s|2|3|*|d+}4|4|d,<   tZ        D 5cg c]	  }5|5|v s|5 }6}5|r|6r|6d   nd|d<   t]        |6      |d-<   |S t]        |6      S c c})w c c}5w ).a:  
    Returns a tuple of possible :py:meth:`~sympy.solvers.ode.dsolve`
    classifications for an ODE.

    The tuple is ordered so that first item is the classification that
    :py:meth:`~sympy.solvers.ode.dsolve` uses to solve the ODE by default.  In
    general, classifications at the near the beginning of the list will
    produce better solutions faster than those near the end, thought there are
    always exceptions.  To make :py:meth:`~sympy.solvers.ode.dsolve` use a
    different classification, use ``dsolve(ODE, func,
    hint=<classification>)``.  See also the
    :py:meth:`~sympy.solvers.ode.dsolve` docstring for different meta-hints
    you can use.

    If ``dict`` is true, :py:meth:`~sympy.solvers.ode.classify_ode` will
    return a dictionary of ``hint:match`` expression terms. This is intended
    for internal use by :py:meth:`~sympy.solvers.ode.dsolve`.  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 executing
    ``help(ode.ode_hintname)``, where ``hintname`` is the name of the hint
    without ``_Integral``.

    See :py:data:`~sympy.solvers.ode.allhints` or the
    :py:mod:`~sympy.solvers.ode` docstring for a list of all supported hints
    that can be returned from :py:meth:`~sympy.solvers.ode.classify_ode`.

    Notes
    =====

    These are remarks on hint names.

    ``_Integral``

        If a classification has ``_Integral`` at the end, it will return the
        expression with an unevaluated :py:class:`~.Integral`
        class in it.  Note that a hint may do this anyway if
        :py:meth:`~sympy.core.expr.Expr.integrate` cannot do the integral,
        though just using an ``_Integral`` will do so much faster.  Indeed, an
        ``_Integral`` hint will always be faster than its corresponding hint
        without ``_Integral`` because
        :py:meth:`~sympy.core.expr.Expr.integrate` is an expensive routine.
        If :py:meth:`~sympy.solvers.ode.dsolve` hangs, it is probably because
        :py:meth:`~sympy.core.expr.Expr.integrate` is hanging on a tough or
        impossible integral.  Try using an ``_Integral`` hint or
        ``all_Integral`` to get it return something.

        Note that some hints do not have ``_Integral`` counterparts. This is
        because :py:func:`~sympy.integrals.integrals.integrate` is not used in
        solving the ODE for those method. For example, `n`\th order linear
        homogeneous ODEs with constant coefficients do not require integration
        to solve, so there is no
        ``nth_linear_homogeneous_constant_coeff_Integrate`` hint. You can
        easily evaluate any unevaluated
        :py:class:`~sympy.integrals.integrals.Integral`\s in an expression by
        doing ``expr.doit()``.

    Ordinals

        Some hints contain an ordinal such as ``1st_linear``.  This is to help
        differentiate them from other hints, as well as from other methods
        that may not be implemented yet. If a hint has ``nth`` in it, such as
        the ``nth_linear`` hints, this means that the method used to applies
        to ODEs of any order.

    ``indep`` and ``dep``

        Some hints contain the words ``indep`` or ``dep``.  These reference
        the independent variable and the dependent function, respectively. For
        example, if an ODE is in terms of `f(x)`, then ``indep`` will refer to
        `x` and ``dep`` will refer to `f`.

    ``subs``

        If a hints has the word ``subs`` in it, it means that the ODE is solved
        by substituting the expression given after the word ``subs`` for a
        single dummy variable.  This is usually in terms of ``indep`` and
        ``dep`` as above.  The substituted expression will be written only in
        characters allowed for names of Python objects, meaning operators will
        be spelled out.  For example, ``indep``/``dep`` will be written as
        ``indep_div_dep``.

    ``coeff``

        The word ``coeff`` in a hint refers to the coefficients of something
        in the ODE, usually of the derivative terms.  See the docstring for
        the individual methods for more info (``help(ode)``).  This is
        contrast to ``coefficients``, as in ``undetermined_coefficients``,
        which refers to the common name of a method.

    ``_best``

        Methods that have more than one fundamental way to solve will have a
        hint for each sub-method and a ``_best`` meta-classification. This
        will evaluate all hints and return the best, using the same
        considerations as the normal ``best`` meta-hint.


    Examples
    ========

    >>> from sympy import Function, classify_ode, Eq
    >>> from sympy.abc import x
    >>> f = Function('f')
    >>> classify_ode(Eq(f(x).diff(x), 0), f(x))
    ('nth_algebraic',
    'separable',
    '1st_exact',
    '1st_linear',
    'Bernoulli',
    '1st_homogeneous_coeff_best',
    '1st_homogeneous_coeff_subs_indep_div_dep',
    '1st_homogeneous_coeff_subs_dep_div_indep',
    '1st_power_series', 'lie_group', 'nth_linear_constant_coeff_homogeneous',
    'nth_linear_euler_eq_homogeneous',
    'nth_algebraic_Integral', 'separable_Integral', '1st_exact_Integral',
    '1st_linear_Integral', 'Bernoulli_Integral',
    '1st_homogeneous_coeff_subs_indep_div_dep_Integral',
    '1st_homogeneous_coeff_subs_dep_div_indep_Integral')
    >>> classify_ode(f(x).diff(x, 2) + 3*f(x).diff(x) + 2*f(x) - 4)
    ('factorable', 'nth_linear_constant_coeff_undetermined_coefficients',
    'nth_linear_constant_coeff_variation_of_parameters',
    'nth_linear_constant_coeff_variation_of_parameters_Integral')

    rl   zLdsolve() and classify_ode() only work with functions of one variable, not %sNr   y   r   ar}   d   er   c1a3b3c3C1c              3   B   K   | ]  }|j                   d    k(    ywr   N)r   )r   rw   r   s     ry   r   zclassify_ode.<locals>.<genexpr>  s#      '%1qEOOA,>'> '%s   r   valz+Invalid boundary conditions for Derivatives)f0f0valz(Invalid boundary conditions for FunctionzfEnter boundary conditions of the form ics={f(point): value, f(x).diff(x, order).subs(x, point): value})r   r   r   r   r   r   )r   r   all_Integralr   )rl   r   T)exactr  r  )termsr  r  rM   Fc              3   D   K   | ]  }|   j                           y wr   )is_polynomial)r   r   r   s     ry   r   zclassify_ode.<locals>.<genexpr>N  s     ;#qv++-;s    r   )r	  r
  r  r   r  r[   )pqr   r  r\   r   )/r   r   r   r   r~   r   r   r   r<   r   r   r=   r   r   r   r   r   r   r   r   r   r   r   r   r   r   SingleODEProblemr   r   
solver_mapmatcheshas_integralr   is_Addr   r   r   r/   r   r,   r   r   r   copyas_numer_denomallhintsrq   )9rr   r   r   r   r   r   r   r   r   eq_origr   r   r   r  r  r   matching_hintsdfr  r  r  r  r	  r
  r  boundaryr  r   oldnewdordertempr   	user_hint
early_exituser_mapr   solver
reduced_eq
deriv_coefdenargr   r   checkcheck1check2rseriesdeqordinaryr  r  
coeff_dictrw   retlistr   r   s9                                                          @@ry   r   r   5  s	   ~ #,CDII!# 68<= > 	> "hVVbff_ Gt|D)	E<D		!A		Ac
AAEb!A$E u%N	
11BS1Q4&!AS2qtyyA/0AS2$AS1adB-(A	dQC	 B	dQqT2qtyyA7	8B	dQqT2qtyyA7	8B	dQqT2qtyyA7	8BH	B  %	KG'D*#56 gt,#LLE!++A.C!--*C4#EC!++A.Cuj1jA 7"&+jjm&8&8A&=

1**+q0SAXGGAJ3 '%OO'% $%)*#g,2K2K)K&ua0FV,DOOT3uc'l$KL$%RSS G\2LLA%#gll*;q*@Q++A.1CL<U<U3UOO7<<?S\$RS$%OPP !  "J  K  KK%	KN 7D!$23
GC

69-I Y&J+&0K 001	H BByT^G^z)45 &$$>>#)N4 ~**5;tk12
,0y)%%& 
BJ	yyXXadii512
V#  1Q48,AQrUdAbEk bgg">s3s7">?

z B$'--a!b&j9AcFAcFAcFQ499QqT1%AaDQ499QqT1%AaD LLq)ELL"-E1Q4!9%EZZE1e 45F::b>&**S/JJsOFJJsO ++a...5!U/CDzz"~fjjo

3

B3ffhGNNU%%#PQ9@N#56	!
 !A$))Aq/"RU*R!W4JqTYYq!_adiilAaD13385: 	
;;;!0021#AY
JqTYYq!_adiilAaD9;;@5: 2!quQrU{#AquQrU{#AJJtQ'EFF1e$E99RcB3/q%(yyS#s3#HHHBb%RWXYBCN#>?
 AIq=)q%(yyS#s3UQ12AFF1e,E 99RcB37+,1EE%R
EO'AB #:Qa>&9q:G: 3:GAJty!*/.'W~g #?V ;s   f3:	f8f8c           	      2   d fd| fD        \  } t        |       D ]2  \  }}t        |t              s|j                  |j                  z
  | |<   4 t        t        | d   j                  t                    d   j                  t                    d   ddz   i}| |d<   |dk(  rt        d      i dgk(  rt        |       t        t                    t              t        |       k7  rt        d	z        i }D ]Y  }j                  |d
      rd}t        |       D ]  \  }}	t        |	|      }
||
k  s|
}|} |v r||   |g||<   n|||<   ||<   [ t        t        |            D cg c]  }||   	 c}|d<   D ]i  }t        |t
              r.|D ](  }t        |j                         dk7  st        d|z         A|sDt        |j                         dk7  s]t        d|z         |d<   fd}i d}t        |       D ]:  \  }}D ]0  }t        |t
              r|D ]  } |||||      } & |||||      }2 < |d<   ||d<   t        t        j#                                     dk(  rt        |d   j#                               d   }|d   dk(  r!|d   dk(  r|dk(  rt%        |       }nGd}nDd}nA|d   dk(  r|dk(  rt'        |       }n&d}n#|d   dk(  r|dk(  rt)        |       }nd}nd}nd}||d<   |S c c}w )a  
    Returns a dictionary of parameter names and values that define the system
    of ordinary differential equations in ``eq``.
    The parameters are further used in
    :py:meth:`~sympy.solvers.ode.dsolve` for solving that system.

    Some parameter names and values are:

    'is_linear' (boolean), which tells whether the given system is linear.
    Note that "linear" here refers to the operator: terms such as ``x*diff(x,t)`` are
    nonlinear, whereas terms like ``sin(t)*diff(x,t)`` are still linear operators.

    'func' (list) contains the :py:class:`~sympy.core.function.Function`s that
    appear with a derivative in the ODE, i.e. those that we are trying to solve
    the ODE for.

    'order' (dict) with the maximum derivative for each element of the 'func'
    parameter.

    'func_coeff' (dict or Matrix) with the coefficient for each triple ``(equation number,
    function, order)```. The coefficients are those subexpressions that do not
    appear in 'func', and hence can be considered constant for purposes of ODE
    solving. The value of this parameter can also be a  Matrix if the system of ODEs are
    linear first order of the form X' = AX where X is the vector of dependent variables.
    Here, this function returns the coefficient matrix A.

    'eq' (list) with the equations from ``eq``, sympified and transformed into
    expressions (we are solving for these expressions to be zero).

    'no_of_equations' (int) is the number of equations (same as ``len(eq)``).

    'type_of_equation' (string) is an internal classification of the type of
    ODE.

    'is_constant' (boolean), which tells if the system of ODEs is constant coefficient
    or not. This key is temporary addition for now and is in the match dict only when
    the system of ODEs is linear first order constant coefficient homogeneous. So, this
    key's value is True for now if it is available else it does not exist.

    'is_homogeneous' (boolean), which tells if the system of ODEs is homogeneous. Like the
    key 'is_constant', this key is a temporary addition and it is True since this key value
    is available only when the system is linear first order constant coefficient homogeneous.

    References
    ==========
    -https://eqworld.ipmnet.ru/en/solutions/sysode/sode-toc1.htm
    -A. D. Polyanin and A. V. Manzhirov, Handbook of Mathematics for Engineers and Scientists

    Examples
    ========

    >>> from sympy import Function, Eq, symbols, diff
    >>> from sympy.solvers.ode.ode import classify_sysode
    >>> from sympy.abc import t
    >>> f, x, y = symbols('f, x, y', cls=Function)
    >>> k, l, m, n = symbols('k, l, m, n', Integer=True)
    >>> x1 = diff(x(t), t) ; y1 = diff(y(t), t)
    >>> x2 = diff(x(t), t, t) ; y2 = diff(y(t), t, t)
    >>> eq = (Eq(x1, 12*x(t) - 6*y(t)), Eq(y1, 11*x(t) + 3*y(t)))
    >>> classify_sysode(eq)
    {'eq': [-12*x(t) + 6*y(t) + Derivative(x(t), t), -11*x(t) - 3*y(t) + Derivative(y(t), t)], 'func': [x(t), y(t)],
     'func_coeff': {(0, x(t), 0): -12, (0, x(t), 1): 1, (0, y(t), 0): 6, (0, y(t), 1): 0, (1, x(t), 0): -11, (1, x(t), 1): 0, (1, y(t), 0): -3, (1, y(t), 1): 1}, 'is_linear': True, 'no_of_equation': 2, 'order': {x(t): 1, y(t): 1}, 'type_of_equation': None}
    >>> eq = (Eq(diff(x(t),t), 5*t*x(t) + t**2*y(t) + 2), Eq(diff(y(t),t), -t**2*x(t) + 5*t*y(t)))
    >>> classify_sysode(eq)
    {'eq': [-t**2*y(t) - 5*t*x(t) + Derivative(x(t), t) - 2, t**2*x(t) - 5*t*y(t) + Derivative(y(t), t)],
     'func': [x(t), y(t)], 'func_coeff': {(0, x(t), 0): -5*t, (0, x(t), 1): 1, (0, y(t), 0): -t**2, (0, y(t), 1): 0,
     (1, x(t), 0): t**2, (1, x(t), 1): 0, (1, y(t), 0): -5*t, (1, y(t), 1): 1}, 'is_linear': True, 'no_of_equation': 2,
      'order': {x(t): 1, y(t): 1}, 'type_of_equation': None}

    c                 `    t        t        t        t        |       r
|             S | g            S r   )r   mapr   r;   )rr   s    ry   _sympifyz!classify_sysode.<locals>._sympify  s'    Cx|>??">??r   c              3   .   K   | ]  } |        y wr    )r   wr<  s     ry   r   z"classify_sysode.<locals>.<genexpr>  s     2!2s   r   no_of_equationrl   rr   zYclassify_sysode() works for systems of ODEs. For scalar ODEs, classify_ode should be usedNzDNumber of functions given is not equal to the number of equations %sFr   zOdsolve() and classify_sysode() work with functions of one variable only, not %sr   c           
         t        |   dz         D ]L  }t        | j                         t        ||      g      j	                  t        ||            
|||f<   |dk(  sP
|||f   dk(  r|dk(  ra| j                  |d      d   }t        dt        | |      dz         D ]&  }|| j                  t        ||      d      d   z  }( |dk7  sd}| j                  t        ||      d      d   sd}D ]b  }t        |t              r,|D ]&  }
|||f   j                  |d      d   }	|	dk7  s%d}( ?
|||f   j                  |d      d   }	|	dk7  sad}d O |S )Nrl   Tr   as_AddF)	ro   r/   r   r   r   as_independentr=   r~   r   )eqsjr   
is_linear_kcoefxrr   
elem_func_dep	func_coefr   r   r   s             ry   linearity_checkz(classify_sysode.<locals>.linearity_check  s   uT{Q' 	3A$+CJJL4a;K:L$M$S$STXY]_`bcTd$eIaqj!T!QaZ(A-Av"11$t1DQG"'9S+>+B"C ZB C$6$6tD!R7HQU$6$VWX$YYDZ19).J--d4A.>t-LQO).J!& 	3%eT2.3 7
&/4
&;&J&J:^b&J&cde&f#&!816J7
 #,AtQJ"7"F"FuUY"F"Z[\"]C"ax-2
	3	30 r   T
func_coeffr   r     r   )	enumerater~   r   r   r   r   r   r   r   r   _extract_funcsr   r   r   r=   ro   r   r   check_linear_2eq_order1check_nonlinear_2eq_order1check_nonlinear_3eq_order1)rr   r   r   rw   fir"  	func_dictr   	max_ordereqs_order_eq_no	func_elemrN  r   rF  rE  order_eqr   r<  rM  r   r   s    `                 @@@@ry   r   r   y  s   T@ 3r5k2IB2 $2b(#FFRVVOBqE$ 	T"Q%++j)*1-33F;<Q?A&qs+NN4!t 7 8 	8 Etf}r"UE
5zSW_bgghh I $yyu%I$R= 4"4-v% &IE	
 	!$-e$4d#;	% #'	% #E$K$ $)Y#89aYq\9E"N6 	AdD!! E	y~~&!+$ &=?C&D E EE
 DII!+  "9;?"@ A A	A $N76 IIB- E3 	ED$%!% NI /Q	9 MIN ,CD)D		EE $-N< "+N; 3u||~1$w/6689!<+&$../14q='>r5)'T$'+$ $(  ./14q='A"eY'W$'+$ 01Q6q='A"eY'W$'+$#' )9N%&} :s   :Lc                    |d   j                   }|d   j                   }|}t        t        | d   j                  t                    d   j                  t                    d   i |d |      df   d<   |d |      df   d<   |d |      df    |d |      df   z  d<   |d |      df    |d |      df   z  d<   |d |      df    |d |      df   z  d<   |d |      df    |d |      df   z  d<   t
        j                  t
        j                  g}t        d	      D ]K  }t        j                  | |         D ].  }|j                   |       |            r"||xx   |z  cc<   0 M |d   j                        s%|d   j                        s|d   d
<   |d   d<   ny d}	d}
t        d   t        d   d   z        j                         d   z        }t        d   t        d   d   z        j                         d   z        }t        ||g      D ]  \  }}t        j                  t        |            D ]l  }|j                        s|}
|
r)|dk(  r$d   |z  d   z
  d   d   |z  z
  z  |k(  s>d}	A|
sD|dk(  sJd   |z  d   z
  d   d   |z  z
  z  |k(  skd	}	n  d
   dk7  sd   dk7  ry t!        fddj#                         D              sy d   d   z  d<   d   d   z  d<   d   d   z  d<   d   d   z  d<   |	ryy)Nr   rl   a1a2b1b2r  c2r  d1d2c              3   F   K   | ]  }|   j                          y wr   r   )r   rH  r   r   s     ry   r   z*check_linear_2eq_order1.<locals>.<genexpr>z  s     D11Q488A;Ds   !za1 a2 b1 b2 c1 c2type6type7)r   r   r   r   r   r   Zeroro   r   	make_argsr   r,   r  rQ  r   r5   anysplit)rr   r   rM  r   r  fcforcingrw   rF  r  r  p1p2r   r   r   s                 @@ry   rS  rS  M  s   QAQA	BT"Q%++j)*1-33F;<Q?A
A 1Q4lAdGr!AaD(|QtW!AaD(|mBq1axL(AdGb1Q4l]2a!Qh<5O1T7!AaD(|mBq1axL(AdGb1Q4l]2a!Qh<5O1T7vvaffoG1X  r!u% 	 A551qt$
a
	   AJNN1!2!*$!*$  	
A	A	$$$0??A!DE	FB	$$$0??A!DE	FB2r(# 	1}Q/0 	A558QTtWQY4(1T7QtWQY+>?AEAq!ttWQY4(1T7QtWQY+>?AEA		 	wzQtWaZD(;(A(A(CDDgagoAdG!D'!D'/$gagoAdG!D'!D'/$ r   c           	      
    t        t         d   j                  t                    d   j                  t                    d   t	        d      t	        d      t        dt              \   fd}|D ]N  }t        |t               s|d   d   j                  }|d   d   j                  } |||      }|s	 |||      }|c S  |d   j                  }|d   j                  }|}t	        d |       |      g	      }	t	        d
g	      }
t	        dg	      }t	        dg	      }t	        dg	      }t        d      D ]7  }d}t        j                   |         D ]  }||||||   df   z  z  } | |<   9  d   j                  t         |             |      |	z  z  z
        }|rt         |             d   z
  |   z  |rj                   |            shj                   |            j                        sA|   j                   |            j                   |            j                        sy d   j                  t         |            t!        |	 |      z        z  z
        }|rt         |             d   z
  |   z  |rj                   |            shj                   |            j                        sA|   j                   |            j                   |            j                        syt	        d       d   j                  t         |            z
        } d   j                  t         |            z
        }|r|r|   j                   |            j                   |            j                        sA|   j                   |            j                   |            j                        sy d   j                  t         |            z
        } d   j                  t         |            z
        }|   j                   |            j                   |            |   j                   |            j                   |            z  j#                         \  }}|j                  |
|z        }|j                  ||z        }|r|ryy )Nr   r   gu, vclsc                    d   j                  t         |             z   |       z
  z         }d   j                  t         |            z   |      z
  z         }|r|sld   j                  t         |              |       z  z
  z  z         }d   j                  t         |             |      z  z
  z  z         }|r|shd    j                  t         |             z   |       z
  z         }d    j                  t         |            z   |      z
  z         }|r|snd    j                  t         |              |       z  z
  z  z         }d    j                  t         |             |      z  z
  z  z         }|r|r|   j                  t         |                   j                  t         |            	      j                        sU|   j                  t         |                   j                  t         |            	      j                        syy )Nr   rl   type5)r   r   r   r   )
r   r  r1r2rr   r   rs  r   uvs
       ry   
check_typez.check_nonlinear_2eq_order1.<locals>.check_type  s!   U[[4!Q<!A$.23U[[4!Q<!A$.23rAT!A$q\AaDF2QqS89BAT!A$q\AaDF2QqS89Bra5&$qtA,1 5 9:Ba5&$qtA,1 5 9:Bra5&QqT!qtAv 5! ;<Ba5&QqT!qtAv 5! ;<B"bejjad1a8==d1Q4l1MQQRSTa5::d1Q4l1%**4!Q<:>>qAr   rl   r   r  f1f2g1g2r  type1type2type3type4)r   r   r   r   r   r   r   r~   r   ro   r   rk  r   r   r   r   r#   r  )rr   r   rM  r}  r   r   r  eq_typern  r   r~  r  r  r  rw   rE  r  r   ry  rz  rs   r/  R1R2r   rs  r   r{  r|  s   `                       @@@@@ry   rT  rT    s   T"Q%++j)*1-33F;<Q?AS	AS	A6u%DAq "  eT"Q
AQ
A A&G$Q*N 	QAQA	BS1Q4!+&A	dQqE	"B	dQqE	"B	dQqE	"B	dQqE	"B1X ]]2a5) 	)E5Ad1gaK((C	)1	
 	1D1aL1Q4719,-A!A$q\BqE!1Q4'!%%!+!Q!3!3A!6!A$))AaD:K:P:PQRSTQUVW:X:\:\]^:_
1D1aL3q1v;q=01A!A$q\BqE!1Q4'!%%!+!Q!3!3A!6!A$))AaD:K:P:PQRSTQUVW:X:\:\]^:_S	A	AT!A$q\A%	&B	AT!A$q\A%	&B	b"Q%**QqT!,11!A$q9==a@qEJJqtAAaD#''*	AT!A$q\A%	&B	AT!A$q\A%	&B	AAaD		 	 1a	(	AAaD		 	 1a	(	*+9>+; C 
2b5	B	2b5	B	br   c                      y r   r>  rr   r   rM  s      ry   check_nonlinear_2eq_order2r        r   c                    |d   j                   }|d   j                   }|d   j                   }|}t        t        | d   j                  t                    d   j                  t                    d   }t        dt              \  }}	}
t        d ||       ||       ||      |g      }t        d ||       ||       ||      |g      }t        d	 ||       ||       ||      |g      }t        d
      }t        d      }t        d      }t        d      }t        d      D ]7  }d}t        j                  | |         D ]  }||||||   df   z  z  } || |<   9 | d   j                  t         ||      |      | ||      z   ||      z  z
        }| d   j                  t         ||      |      | ||      z   ||      z  z
        }| d   j                  t         ||      |      | ||      z   ||      z  z
        }|r||rz|rx||   j                         \  }}||   j                         \  }}||   j                         \  }}t        ||z  ||	|
z
  z  z
  ||	z  ||
|z
  z  z
  ||
z  |||	z
  z  z
  g||	g      ry| d   j                  t         ||      |       ||       ||      z  |z  z
        }|rt        ||         j                  ||z        }t         ||      |      | d   z
  ||   z  j                  | ||      z   ||      z        }t         ||      |      | d   z
  ||   z  j                  | ||      z   ||      z        }|r||rz|rx||   j                         \  }}||   j                         \  }}||   j                         \  }}t        ||z  ||	|
z
  z  z
  ||	z  ||
|z
  z  z
  ||
z  |||	z
  z  z
  g||	g      ry| d   j                  t         ||      |      ||z
  z
        }|rt        ||         j                  ||z        }|j!                  t        ||         j                  ||z               |r| d   j#                  ||         r;| d   j#                  ||         s$||   ||   c||<   ||<   ||    ||    c||<   ||<   | d   j                  t         ||      |      |||   z  z
  ||   |z  z         }|r0| d   t         ||      |      ||   ||   z  z
  ||   ||   z  z   k(  }|r|r|ry| d   j                  t         ||      |       ||      |z  z
   ||      |z  z         }|r6t        ||         j                  ||z        }|j!                  t        ||         j                  ||z               |r| d   j#                  ||         r;| d   j#                  ||         s$||   ||   c||<   ||<   ||    ||    c||<   ||<   t         ||      |      | d   z
  j                  | ||      z  ||   z  ||    ||      z  |z  z
        }|rBt         ||      |      | d   z
  ||    ||      z  ||   z  ||    ||      z  ||   z  z
  k(  }|r|r|ryt         ||      |      | d   z
  j                   ||      ||z
  z        }|r$t        ||         j                  ||z        }|j!                  t        ||         j                  ||z               |r| d   j#                  ||         r;| d   j#                  ||         s$||   ||   c||<   ||<   ||    ||    c||<   ||<   t         ||      |      | d   z
  j                   ||      |||   z  ||   |z  z
  z        }|r9t         ||      |      | d   z
   ||      ||   ||   z  ||   ||   z  z
  z  k(  }|r|r|ryy )Nr   rl   r  u, v, wru  r  r  bcr   F1F2F3rP  r  r  r  r  rx  )r   r   r   r   r   r   r   r   ro   r   rk  r   r   r  r7   r5   r   r   )rr   r   rM  r   r  zrn  r   r{  r|  r?  r  r  r  r   r  r  r  rw   rE  r  ry  rz  r3num1den1num2den2num3den3r   s                                  ry   rU  rU    s   QAQAQA	BT"Q%++j)*1-33F;<Q?AiU+GAq!S1Q41qtQ/0AS1Q41qtQ/0AS1Q41qtQ/0AS	A	dB	dB	dB1X ]]2a5) 	)E5Ad1gaK((C	)1	
 
AT!A$q\AadF1Q4K/	0B	AT!A$q\AadF1Q4K/	0B	AT!A$q\AadF1Q4K/	0B	bRU))+
dU))+
dU))+
d$q&qs#T!VD!A#J%6QtQqSz8IJAq6R
1D1aL1Q4!9Q;./A1Q4 &&qs+AaD|be#RU*11!AaD&1+>AaD|be#RU*11!AaD&1+>	bRU))+
dU))+
dU))+
d$q&qs#T!VD!A#J%6QtQqSz8IJAq6R
1D1aLBrE*+A1R5!''"-
		-"&,,QrT23!uyyB A2b6):!#BB22 "1v1v1r!uAT!A$q\AbfH4r!uRx?@BQ%4!Q<"Q%2,6Ar"vEEB"
1D1aL1Q47*QqT"W45A1R5!''"-
		-"&,,QrT23!uyyB A2b6):!#BB22 "1v1v1r!uqtA,A&--a!fRVmbeAaDjm.KLBqtA,A&"Q%!*RV*;beAaDjB>O*OOB"	ad11	$$QqT27^4A1R5!''"-
		-"&,,QrT23!uyyB A2b6):!#BB22 "1v1v1r!uqtA,A&--adAbfHr!uRx4G.HIBqtA,A&!A$1bfr!uRV|0K*LLB"r   c                      y r   r>  r  s      ry   check_nonlinear_3eq_order2r     r  r   c           	         |j                   d   }|j                  }t        |d      }|j                  | j                  z
  }t	        |||      }|j                  d      rt        |      }t        |t              st        d      |j                  |D ci c]  }|t        d       c}x}	      j                  |	D ci c]  }|	|   |
 c}      }t        ||      }|j                  |k(  r<|j                  j                  |      s!t!        |j                  |j                        g}|j                  |k(  r|j                  j                  |      s|g}n	 t#        d |j%                  t&              D              }
t)        ||d|
rd	nd
      }|st*        	 d }|D cg c]  }t!         ||       ||             }}|j                  d      rtt/        |      D ]f  \  }}t1        |d      }t        |j                  t2              r5|j                  dk(  r&t!        |j                  j                   d   |z  |      }|||<   h t/        |      D ]0  \  }}t        ||      ||<   t5        ||   | j                        ||<   2 t7        |      dk(  r|d   }|S c c}w c c}w c c}w # t*        t,        f$ r |g}Y w xY w)a  
    Simplifies solutions of ODEs, including trying to solve for ``func`` and
    running :py:meth:`~sympy.solvers.ode.constantsimp`.

    It may use knowledge of the type of solution that the hint returns to
    apply additional simplifications.

    It also attempts to integrate any :py:class:`~sympy.integrals.integrals.Integral`\s
    in the expression, if the hint is not an ``_Integral`` hint.

    This function should have no effect on expressions returned by
    :py:meth:`~sympy.solvers.ode.dsolve`, as
    :py:meth:`~sympy.solvers.ode.dsolve` already calls
    :py:meth:`~sympy.solvers.ode.ode.odesimp`, but the individual hint functions
    do not call :py:meth:`~sympy.solvers.ode.ode.odesimp` (because the
    :py:meth:`~sympy.solvers.ode.dsolve` wrapper does).  Therefore, this
    function is designed for mainly internal use.

    Examples
    ========

    >>> from sympy import sin, symbols, dsolve, pprint, Function
    >>> from sympy.solvers.ode.ode import odesimp
    >>> x, u2, C1= symbols('x,u2,C1')
    >>> f = Function('f')

    >>> eq = dsolve(x*f(x).diff(x) - f(x) - x*sin(f(x)/x), f(x),
    ... hint='1st_homogeneous_coeff_subs_indep_div_dep_Integral',
    ... simplify=False)
    >>> pprint(eq, wrap_line=False)
                            x
                           ----
                           f(x)
                             /
                            |
                            |   /        1   \
                            |  -|u1 + -------|
                            |   |        /1 \|
                            |   |     sin|--||
                            |   \        \u1//
    log(f(x)) = log(C1) +   |  ---------------- d(u1)
                            |          2
                            |        u1
                            |
                           /

    >>> pprint(odesimp(eq, f(x), 1, {C1},
    ... hint='1st_homogeneous_coeff_subs_indep_div_dep'
    ... )) #doctest: +SKIP
        x
    --------- = C1
       /f(x)\
    tan|----|
       \2*x /

    r   rl   rs   "nth_linear_euler_eq_nonhomogeneousz$eq should be an instance of EqualityT)nonzeroc              3   4   K   | ]  }|j                     y wr   )is_Floatr   s     ry   r   zodesimp.<locals>.<genexpr>  s     >>   FN)forcerationalc                 |    | j                         \  }}|j                  r| S t        | j                         dd      S )Nr#   T)combinedeep)r  r  r1   r   )r   numerdenoms      ry   _expandzodesimp.<locals>._expand  s5    #224u<<K"4;;=%dKKr   1st_homogeneous_coeff)r  )r   r   rz   r   r   
startswithr3   r~   r   	TypeErrorxreplacer   constantsimpr   r   r   r   rl  r   r   r7   r   r*   rQ  r0   r$   constant_renumberr   )r   rr   r   r   r   r   r  r   rw   _floatseqsolr  r   rF  eqinewis                    ry   r   r   $  s   t 			!A		A		*B#"2"22I 
"dD	)B;<b\b(#>?? 
)DQ!U400DDa	F	O	ObcPd]^QRSTQUWXQXPd	eB 
b)	$B 
vv~bffjj. ! 
vv~bffjj.T	7>RXXf-=>>F"d$&dSE)) 
L 1661"QqT71:&6B6 ??23#B- 3!#T2dhh,QdhhmmA.r126D1	 B- ;3S),1!"Q%)9)9:1; 2w!|UIC EPdX 7 $_5 	B	s%   J?JA J) !J$)J>=J>c                    t        |       r8| D ]  }t        |||      t        k(  st        c S  t        t	        |             S | j                  t              rt        S | j                  |k(  r| j                  j                  |      r*| j                  |k(  r| j                  j                  |      sy|r	 t        | |      }|st        	 yt        t	        |             S # t        $ r Y w xY w)a@  
    Returns an extended integer representing how simple a solution to an ODE
    is.

    The following things are considered, in order from most simple to least:

    - ``sol`` is solved for ``func``.
    - ``sol`` is not solved for ``func``, but can be if passed to solve (e.g.,
      a solution returned by ``dsolve(ode, func, simplify=False``).
    - If ``sol`` is not solved for ``func``, then base the result on the
      length of ``sol``, as computed by ``len(str(sol))``.
    - If ``sol`` has any unevaluated :py:class:`~sympy.integrals.integrals.Integral`\s,
      this will automatically be considered less simple than any of the above.

    This function returns an integer such that if solution A is simpler than
    solution B by above metric, then ``ode_sol_simplicity(sola, func) <
    ode_sol_simplicity(solb, func)``.

    Currently, the following are the numbers returned, but if the heuristic is
    ever improved, this may change.  Only the ordering is guaranteed.

    +----------------------------------------------+-------------------+
    | Simplicity                                   | Return            |
    +==============================================+===================+
    | ``sol`` solved for ``func``                  | ``-2``            |
    +----------------------------------------------+-------------------+
    | ``sol`` not solved for ``func`` but can be   | ``-1``            |
    +----------------------------------------------+-------------------+
    | ``sol`` is not solved nor solvable for       | ``len(str(sol))`` |
    | ``func``                                     |                   |
    +----------------------------------------------+-------------------+
    | ``sol`` contains an                          | ``oo``            |
    | :obj:`~sympy.integrals.integrals.Integral`   |                   |
    +----------------------------------------------+-------------------+

    ``oo`` here means the SymPy infinity, which should compare greater than
    any integer.

    If you already know :py:meth:`~sympy.solvers.solvers.solve` cannot solve
    ``sol``, you can use ``trysolving=False`` to skip that step, which is the
    only potentially slow step.  For example,
    :py:meth:`~sympy.solvers.ode.dsolve` with the ``simplify=False`` flag
    should do this.

    If ``sol`` is a list of solutions, if the worst solution in the list
    returns ``oo`` it returns that, otherwise it returns ``len(str(sol))``,
    that is, the length of the string representation of the whole list.

    Examples
    ========

    This function is designed to be passed to ``min`` as the key argument,
    such as ``min(listofsolutions, key=lambda i: ode_sol_simplicity(i,
    f(x)))``.

    >>> from sympy import symbols, Function, Eq, tan, Integral
    >>> from sympy.solvers.ode.ode import ode_sol_simplicity
    >>> x, C1, C2 = symbols('x, C1, C2')
    >>> f = Function('f')

    >>> ode_sol_simplicity(Eq(f(x), C1*x**2), f(x))
    -2
    >>> ode_sol_simplicity(Eq(x**2 + f(x), C1), f(x))
    -1
    >>> ode_sol_simplicity(Eq(f(x), C1*Integral(2*x, x)), f(x))
    oo
    >>> eq1 = Eq(f(x)/tan(f(x)/(2*x)), C1)
    >>> eq2 = Eq(f(x)/tan(f(x)/(2*x) + f(x)), C2)
    >>> [ode_sol_simplicity(eq, f(x)) for eq in [eq1, eq2]]
    [28, 35]
    >>> min([eq1, eq2], key=lambda i: ode_sol_simplicity(i, f(x)))
    Eq(f(x)/tan(f(x)/(2*x)), C1)

    r   )r;   r   r   r   r   r   r'   r   r   r7   r   )r   r   r   rw   r   s        ry   r   r     s    b } 	A!!TjARG		 3s8}
wwx	 ww$sww{{40GGtOCGGKK$5	d#D)) 
  s3x= # 		s   7C! !	C-,C-c                     g }| D ]m  }t        |      D cg c]  }t        |t              s| }}g }|D ]#  }|t        |j	                  t
                    z  }% |D ]  }|j                  |        o t        t        |            }|S c c}w r   )r   r~   r   r   r   r   r   r9   )rE  r   rr   nodederivsr   r  r   s           ry   rR  rR  +  s    E  #5b#9Z4Zj=Y$ZZ 	0AD.//D	0 	 ELL	   eEL [s
   BBc                 D    t              g fd |        S )Nc                 x   | j                   }|r#|j                        rj                  |        y | j                  t        k(  r| j                  d      } | j                  t        t        fv rZt        | j                  fd      }t        |d         dkD  r | j                  |d    }|j                  sjj                  |       nXt        | t              rH| j                   j                        r-t        d | j                  D              rj                  |        | j                  D ]
  } |        y )NT)mulc                 :    | j                   j                        S r   )r   issubsetrw   rx   s    ry   r   zG_get_constant_subexpressions.<locals>._recursive_walk.<locals>.<lambda>D  s    q~~/F/Fr/J r   rl   c              3   8   K   | ]  }t        |      d k(    yw)rP  N)r   )r   r   s     ry   r   zH_get_constant_subexpressions.<locals>._recursive_walk.<locals>.<genexpr>K  s     AA!As   )r   r  r   r   r#   r   r   r   r:   r   r   	is_numberr~   r'   r   limits)r   	expr_symsr  r   rw   Cesrx   _recursive_walks        ry   r  z5_get_constant_subexpressions.<locals>._recursive_walk<  s    %%	++B/JJt  	 yyC{{t{,yyS#J&$JKqw<!#!		1T7+A;;

1D(+$$--b1AT[[AAJJt$YY #"#r   )r   )r   rx   r  r  s    `@@ry   _get_constant_subexpressionsr  9  s%    	RB
C( DJr   c                   	
 D ci c]  }|| j                  |       c}D cg c]  }|   dkD  s| c}fd		
fd
t        | t              r| j                  D cg c]
  } 
|       c}\  }}fd}t        |t              r|v r||}}|j
                  t        t        fv r|j
                  t        t        fv rt        t        |t              r|gn|j                  |      }t        t        |t              r|gn|j                  |      }dD ]  }||fD ]  }||vsdg||<     t        |d    t        |d    z
  }t        |d    t        |d    z
  }n|j
                  t        t        fv rh|j
                  t        t        fv rPt        t        |t              r|gn|j                  |      }d|v r#d|vrdg|d<   t        |d    }|t        |d    z  }t        ||      S  
|       S c c}w c c}w c c}w )	Nr   c                    t        | t              rĉD cg c]1  }| j                  |      |   k(  sd| j                  |d      k(  r|3 }}i }|D ]0  }| j                  |      }||vrg ||<   ||   j	                  |       2 |D ]L  }t        ||         dkD  s||   j                  t               ||   dd  D ]  }| j                  |d      }  N | S c c}w )Nr   r  rl   r   )	r~   r   countr   r   r   sortr   r   )r   rw   xsr  r   r  rx   cntss         ry   _linearz-__remove_linear_redundancies.<locals>._linearW  s    dC  *4::a=$q'#91a(  *B *A IIaLA:AaD!A	
  /qt9q=aDII#I&qT!"X /#yyA//
 *s
   CCc                     t        | j                        dk7  r- | j                  | j                  D cg c]
  } |       c} }  |       } | S c c}w Nr   )r   r   r   )r   rw   r  r  s     ry   r  z5__remove_linear_redundancies.<locals>._recursive_walkh  sK    tyy>Q499499Eaq1EFDt} Fs   Ac                 0    t        | t              xs | v S r   )r~   r   r  s    ry   r   z.__remove_linear_redundancies.<locals>.<lambda>p  s    jF+6qBw r   )TFFTrl   )r  r~   r   r   r   r   r   r:   r	   r   r   )r   rx   rw   r   r   r   dlhsdrhshsr  r  r  s    `       @@@ry   __remove_linear_redundanciesr  S  s   &()Atzz!})D	'47Q;!	'B" $!04		:1OA&:S6c6"sbyCC88V}$c6])BC!<#((ANDC!<#((AND" $, $B{!"1$$
 tE{#c4;&77CtDz"S$t*%55CXX#v&388V}+DC!<#((ANDt|$#$#DK4;'#tDz**#s|t$$e *	'4 ;s   G;H H )Hc                    	
 |} }t         |      }|D ][  t        j                        }|st         fd|D              s1|j	                  t
                j                  |d          ] 	 t               \  }}|j                          |d   }|D ]  
t        
d   j                  t                    	t        	      dk(  rO	d   |v rH	d   |j                  t              vr.t        	
fd|D              s|j                  
d   	d         } |j                  
 } | t         |       d } |        | k7  rt         |      S  S # t        $ r Y 5w xY w)a
  
    Simplifies an expression with arbitrary constants in it.

    This function is written specifically to work with
    :py:meth:`~sympy.solvers.ode.dsolve`, and is not intended for general use.

    Simplification is done by "absorbing" the arbitrary constants into other
    arbitrary constants, numbers, and symbols that they are not independent
    of.

    The symbols must all have the same name with numbers after it, for
    example, ``C1``, ``C2``, ``C3``.  The ``symbolname`` here would be
    '``C``', the ``startnumber`` would be 1, and the ``endnumber`` would be 3.
    If the arbitrary constants are independent of the variable ``x``, then the
    independent symbol would be ``x``.  There is no need to specify the
    dependent function, such as ``f(x)``, because it already has the
    independent symbol, ``x``, in it.

    Because terms are "absorbed" into arbitrary constants and because
    constants are renumbered after simplifying, the arbitrary constants in
    expr are not necessarily equal to the ones of the same name in the
    returned result.

    If two or more arbitrary constants are added, multiplied, or raised to the
    power of each other, they are first absorbed together into a single
    arbitrary constant.  Then the new constant is combined into other terms if
    necessary.

    Absorption of constants is done with limited assistance:

    1. terms of :py:class:`~sympy.core.add.Add`\s are collected to try join
       constants so `e^x (C_1 \cos(x) + C_2 \cos(x))` will simplify to `e^x
       C_1 \cos(x)`;

    2. powers with exponents that are :py:class:`~sympy.core.add.Add`\s are
       expanded so `e^{C_1 + x}` will be simplified to `C_1 e^x`.

    Use :py:meth:`~sympy.solvers.ode.ode.constant_renumber` to renumber constants
    after simplification or else arbitrary numbers on constants may appear,
    e.g. `C_1 + C_3 x`.

    In rare cases, a single constant can be "simplified" into two constants.
    Every differential equation solution should have as many arbitrary
    constants as the order of the differential equation.  The result here will
    be technically correct, but it may, for example, have `C_1` and `C_2` in
    an expression, when `C_1` is actually equal to `C_2`.  Use your discretion
    in such situations, and also take advantage of the ability to use hints in
    :py:meth:`~sympy.solvers.ode.dsolve`.

    Examples
    ========

    >>> from sympy import symbols
    >>> from sympy.solvers.ode.ode import constantsimp
    >>> C1, C2, C3, x, y = symbols('C1, C2, C3, x, y')
    >>> constantsimp(2*C1*x, {C1, C2, C3})
    C1*x
    >>> constantsimp(C1 + 2 + x, {C1, C2, C3})
    C1 + x
    >>> constantsimp(C1*C2 + 2 + C2 + C3*x, {C1, C2, C3})
    C1 + C3*x

    c              3   d   K   | ]'  }j                  |      j                  |      k(   ) y wr   )r  )r   r  r   xes     ry   r   zconstantsimp.<locals>.<genexpr>  s&     9tzz!}+9s   -0r   r   rl   c              3   8   K   | ]  }|k7  s	d    |v   ywr  r>  )r   excsr   s     ry   r   zconstantsimp.<locals>.<genexpr>  s     Aq1As   
c                     t        | ddd      }|j                  rZd}d}|j                  D ]G  }t        |t              rd}n(|j
                  rt        d |j                  D              }|sA|sD| } |S  |S )NFT)clearr  r   c              3   p   K   | ].  }t        j                  |      D ]  }t        |t                0 y wr   )r   rk  r~   r#   )r   r   rV  s      ry   r   zDconstantsimp.<locals>._conditional_term_factoring.<locals>.<genexpr>  s:       4"%--"2 4 !+2s 3  4 3  4s   46)r)   is_Mulr   r~   r#   r  rl  )r   new_exprinfacasfacms        ry   _conditional_term_factoringz1constantsimp.<locals>._conditional_term_factoring  s    TT%H ??EE]] a% EXX  4QVV  4 4EU#H r   )r  r   r   r   r  r   r   r4   reverser   r   r   rl  
IndexErrorr  r  )r   r   rx   	orig_exprconstant_subexprsxescommonsrexprr  r  r   r  s   `        @@@ry   r  r    sp   N 
BI4T2> )2??#9S99HHH99RQ(D)Ta 	'Aadjj()B2w!|11U[[00AgAA

1Q4A/"

A	'  (b1D$ 't,D DD"%%K7  s   6B9E 	E%$E%c                   
 t        | t        t        t        f      r# t	        |       t        t        |  |            S &t              | j                  }t        |z
        n:t               d }| j                  D cg c]  } ||j                        s| c}|t        dd      }nfd|D        }g D cg c]  }|t        j                  f c}

fdfd |       } D cg c]	  }|vs| c}t        t        |            }	| j                  |	d	
      } | S c c}w c c}w c c}w )a  
    Renumber arbitrary constants in ``expr`` to use the symbol names as given
    in ``newconstants``. In the process, this reorders expression terms in a
    standard way.

    If ``newconstants`` is not provided then the new constant names will be
    ``C1``, ``C2`` etc. Otherwise ``newconstants`` should be an iterable
    giving the new symbols to use for the constants in order.

    The ``variables`` argument is a list of non-constant symbols. All other
    free symbols found in ``expr`` are assumed to be constants and will be
    renumbered. If ``variables`` is not given then any numbered symbol
    beginning with ``C`` (e.g. ``C1``) is assumed to be a constant.

    Symbols are renumbered based on ``.sort_key()``, so they should be
    numbered roughly in the order that they appear in the final, printed
    expression.  Note that this ordering is based in part on hashes, so it can
    produce different results on different machines.

    The structure of this function is very similar to that of
    :py:meth:`~sympy.solvers.ode.constantsimp`.

    Examples
    ========

    >>> from sympy import symbols
    >>> from sympy.solvers.ode.ode import constant_renumber
    >>> x, C1, C2, C3 = symbols('x,C1:4')
    >>> expr = C3 + C2*x + C1*x**2
    >>> expr
    C1*x**2  + C2*x + C3
    >>> constant_renumber(expr)
    C1 + C2*x + C3*x**2

    The ``variables`` argument specifies which are constants so that the
    other symbols will not be renumbered:

    >>> constant_renumber(expr, [C1, x])
    C1*x**2  + C2 + C3*x

    The ``newconstants`` argument is used to specify what symbols to use when
    replacing the constants:

    >>> constant_renumber(expr, [x], newconstants=symbols('E1:4'))
    E1 + E2*x + E3*x**2

    )r   newconstantsc                 N    | j                  d      xr | dd  j                         S )NCrl   )r  isdigit)r   s    ry   r   z#constant_renumber.<locals>.<lambda>F  s     q||C0DQqrU]]_ r   rl   r  r|   c              3   ,   K   | ]  }|vs|  y wr   r>  )r   symr   s     ry   r   z$constant_renumber.<locals>.<genexpr>M  s     N#I9M#Ns   	c                 8    t        | j                              S r   )r   r   )r0  C_1s    ry   r   z#constant_renumber.<locals>.<lambda>U  s    )#((3-8 r   c                    t        | t              r| D cg c]
  } |       }}t        | S t        | t              r,t         | j                         | j
                              S t        |       t        t        t        fvr| j                  s | j                   s| S | j                  r| S | v r| vrj                  |        | S | j                  s| j                  r- | j                  | j                   D cg c]
  } |       c} S t#        | j                         }|j%                          | j                  |D cg c]
  } |       c} S c c}w c c}w c c}w )z@
        We need to have an internal recursive function
        r   )r~   r   r   r   r   r   r   r   r   r   is_Functionr   is_Piecewiser   is_Powr   r   r   r  )	r   r  
renumberedr   
sortedargs_constant_renumberconstants_foundconstantsymbolssort_keys	        ry   r  z-constant_renumber.<locals>._constant_renumberW  sM    dE"9=>A,Q/>J>*%%dH%"488,"488,. . :c3_,T5E5EDHHo. KK_$?*&&t,K49915;A$Q';= = diiJOOO)499jI1!4IJJ3 ?* < Js   E?E!	E&T)simultaneous)r~   r   r   rq   r   r  r   r   namer8   r   Oner   zipr   )r   r   r  r   
isconstantr  iter_constantscir  	subs_dictr  r  r  r   r  s    `        @@@@@ry   r  r    sG   d $dE*+tDz+E4L"+,H I 	I 	N	((|i78 E	D
*.*;*;T3z#((?S3T )#yQNNO
 "1
12B;
1C8H KB d#D #2HQQi5GqHO S.9:I99YT92DKu U 2N Is   D9 D9	D>>	EEc                 b    |dk(  r| }|S |j                  d      s| j                         }|S | }|S )z
    Converts a solution with Integrals in it into an actual solution.

    For most hints, this simply runs ``expr.doit()``.

    rO   r   )r   r   )r   r   r   r   s       ry   r   r     sE     66
 J	 ]];'iik J Jr   c           
      :   |st        d      t        |      }t        |       } | j                  t        t
              ry| j                  s| j                  s| j                  rt        j                  S t        dt              }t               }|D cg c]  }t        |d      s| c}D ]i  }t        |j                        }|j                  |      r yt!        |      }| j#                  ||      } |j%                  |       |j'                  |       k |j)                  |       | j*                  |z  syt-        | t.              r7t1        | j                  d   gt3        |       dk7  rdS t        j                  S t        dd	      }	t5        | j#                  |D cg c]	  }||	|z  f c}      |	gd
      |	   }
|
t        j6                  u rt        j                  S |
j9                  |	d      \  }}|j;                         \  }}||	k(  r|S yc c}w c c}w )a  
    Returns the order `n` if `g` is homogeneous and ``None`` if it is not
    homogeneous.

    Determines if a function is homogeneous and if so of what order.  A
    function `f(x, y, \cdots)` is homogeneous of order `n` if `f(t x, t y,
    \cdots) = t^n f(x, y, \cdots)`.

    If the function is of two variables, `F(x, y)`, then `f` being homogeneous
    of any order is equivalent to being able to rewrite `F(x, y)` as `G(x/y)`
    or `H(y/x)`.  This fact is used to solve 1st order ordinary differential
    equations whose coefficients are homogeneous of the same order (see the
    docstrings of
    :obj:`~sympy.solvers.ode.single.HomogeneousCoeffSubsDepDivIndep` and
    :obj:`~sympy.solvers.ode.single.HomogeneousCoeffSubsIndepDivDep`).

    Symbols can be functions, but every argument of the function must be a
    symbol, and the arguments of the function that appear in the expression
    must match those given in the list of symbols.  If a declared function
    appears with different arguments than given in the list of symbols,
    ``None`` is returned.

    Examples
    ========

    >>> from sympy import Function, homogeneous_order, sqrt
    >>> from sympy.abc import x, y
    >>> f = Function('f')
    >>> homogeneous_order(f(x), f(x)) is None
    True
    >>> homogeneous_order(f(x,y), f(y, x), x, y) is None
    True
    >>> homogeneous_order(f(x), f(x), x)
    1
    >>> homogeneous_order(x**2*f(x)/sqrt(x**2+f(x)**2), x, f(x))
    2
    >>> homogeneous_order(x**2+f(x), x, f(x)) is None
    True

    z)homogeneous_order: no symbols were given.Nr  )ru   rv  r  r   r   T)positiver   FrB  )r   r   r   r   r-   r   	is_Numberis_NumberSymbolr  r   rj  r8   r   getattrr   r   rp   r   remover   r   r   r~   r   homogeneous_orderrq   r2   r  rD  as_base_exp)rr   r   symsetdumnewsymsrF  rw   iargsdummyvarr   rE  r  r  r  s                 ry   r  r    s   T DEE\F	B 
vveZ  	

vv #5
1CeG=A71m#<a= "AFFF#CyHH%BMM!KK!" MM'??V# "h(GGAJ(v(+,-t 	923&&	9 	cD!A
rww&9QAaC9:QCd
KA
NC
aee|vva.DAq==?DAqAv 5 >*  :s   H$H Hc           
         |j                   d   }|j                  }t        | d      \  }}t        dd      }t	        d      }	t	        d|g	      }
|d
   }|d   }||d      }||d      }||d      }i }t        d      } ||      |f| ||      z  |f||dz
  z   ||      z  |fg}t        |      D ]%  \  }}|d   st        t        |d   ||z
  ||z
  z  z  j                  |||z                     }|j                  r|j                   }n|g}|D ]  }|j                  |	||
z  z        }|d   ||	   z  }||
   j                  s*|j                  ||||
   j                  |      d   z
        }||
   j                  ||      }|r;t        t        |            D ]#  }|j                  ||      s|||<   |dz   ||<     t         j"                  ||<    ( t         j"                  }|j%                         }|j'                         }t)        | }t+        |      rCt-        |      } |D ]3  }||   }!|!| k7  st        |!|       D ]  }||j                  ||!      z  } 5 i }"|rk|j/                  t0              }#t3        |#      dk(  rd|"|#j5                         <   n4t-        |#d       }$t7        ||$      }%t9        |%t:              r|%d   }%|%|"|$<   |j/                  t0              }#t-        |#d       }$t=        |#d       }&|&j                   d   j                  rd}'n"|&j                   d   j                  |      d    }'|$}(t7        ||$      })t9        |)t:              r|)d   })t3        |"j%                         D *cg c]  }*|*s|*	 c}*      }+t        |+|dz
        D ]A  },|)j                  ||'      }-|(j                  ||'      }.|-j                  |"      }/|/|"|.<   |'dz  }'C ||||z
  z  z   }0|"D ]I  }|"|   s	|j                   d   }1|0|"|   j                   |d      |f |d      |fg      ||z
  |1z  z  z  }0K t?        tA        |0      ||g      tC        ||z        z   }0tE         ||      |0      S c c}*w )a  
    Gives a power series solution to a second order homogeneous differential
    equation with polynomial coefficients at an ordinary point. A homogeneous
    differential equation is of the form

    .. math :: P(x)\frac{d^2y}{dx^2} + Q(x)\frac{dy}{dx} + R(x) y(x) = 0

    For simplicity it is assumed that `P(x)`, `Q(x)` and `R(x)` are polynomials,
    it is sufficient that `\frac{Q(x)}{P(x)}` and `\frac{R(x)}{P(x)}` exists at
    `x_{0}`. A recurrence relation is obtained by substituting `y` as `\sum_{n=0}^\infty a_{n}x^{n}`,
    in the differential equation, and equating the nth term. Using this relation
    various terms can be generated.


    Examples
    ========

    >>> from sympy import dsolve, Function, pprint
    >>> from sympy.abc import x
    >>> f = Function("f")
    >>> eq = f(x).diff(x, 2) + f(x)
    >>> pprint(dsolve(eq, hint='2nd_power_series_ordinary'))
              / 4    2    \        /     2\
              |x    x     |        |    x |    / 6\
    f(x) = C2*|-- - -- + 1| + C1*x*|1 - --| + O\x /
              \24   2     /        \    6 /


    References
    ==========
    - https://tutorial.math.lamar.edu/Classes/DE/SeriesSolutions.aspx
    - George E. Simmons, "Differential Equations with Applications and
      Historical Notes", p.p 176 - 184

    r   r  r  r   T)integerr   rH  r  r   r  r	  r
  r  r   rl   c                      | j                   d   S r  r   r   s    ry   r   z/ode_2nd_power_series_ordinary.<locals>.<lambda>[	  s    affQi r   r   c                      | j                   d   S r  r  r  s    ry   r   z/ode_2nd_power_series_ordinary.<locals>.<lambda>c	      affQi r   c                      | j                   d   S r  r  r  s    ry   r   z/ode_2nd_power_series_ordinary.<locals>.<lambda>d	  r  r   rP  )#r   r   rz   r   r   r   rQ  r1   r   r   r  r   	is_SymbolrD  reversedro   r   rj  r   keysr   rl  maxr   r   r   r   r7   r~   r   r   r/   r   r-   r   )2rr   r   r   r   r   r   C0r  r   r   rH  r   r  r  r  r   
seriesdictrecurr	coefflistindexr   r  addargsr0  powmtermstartindrw   teqsuminitrkeysreqmaxvalr  	finaldictfargsmaxfr   minf	startiterr   r   r   tcounterr  r1  nlhsnrhsr.   facts2                                                     ry   ode_2nd_power_series_ordinaryr;    s   H 			!A		A#BA.FBc4 AS	AS1#A	tB'NEeDkAeDkAeDkAJc]F )Q!F1I+q!1Aq1uIfQi4G3KLI!), .u8q1r6QY*?!? E EaR PQRByy''$ .yy1a4(QxQ'Aw((99QDG,B,B1,Ea,H(HID7<<51 %eHo6 "#yyA/0Jt,/01uJt,!" ()vvJt$#..6 &&C!GOOE
u+C
7|W 	-DT"Cf}sF+ -A499Q,,C-	- I
		,'u:?%&Ieiik"u$78DT"C#t$!f!IdO IIl#Eu/0Du/0Dyy|	YYq\003A66	
CdC#t!f y//17!QA78H8UQY' I&xx9%zz)$	$Q	 "a"f+F T?99Q<Dy++fQi_vay"o,NOBQ  F
 Z'"b2U1e8_DFadF# 8s   <Q3Q3c                    |j                   d   }|j                  }t        | d      \  }}t        d      }|d   }	|d   }
|d   }|d   }g }||fD ]  }|j	                  |      s|j                  |       &t        ||d	|	
      }t        |t              r |j                  t        j                         e|j                   D ]&  }|j	                  |      r|j                  |          |\  }}t        ||d	z
  z  ||z  z   |z   |      }|rt        |t              rt        d |D              ri }i }t        |      d	k(  rR|j                         x}}|
|z
  d	z
  dk  rt!         ||      t        |
            S t#        |
|z
  d	z
  ||||||	||	      }np|d   }|d	   }||k  r||}}t#        |
|z
  d	z
  ||||||	||	      }||z
  j$                  st#        |
|z
  d	z
  ||||||	||	      }nt#        |
|z
  d	z
  ||||||	|||
      }|r|}|D ]+  }t'        |j(                  d	d       }|||   ||	z
  |z  z  z  }- ||	z
  |z  |z  }t        j                  }|r@|D ]+  }t'        |j(                  d	d       }|||   ||	z
  |z  z  z  }- ||z  }||	z
  |z  |z  }t!         ||      t+        ||z   ||g      t        ||
z        z         S yyyy)ao	  
    Gives a power series solution to a second order homogeneous differential
    equation with polynomial coefficients at a regular point. A second order
    homogeneous differential equation is of the form

    .. math :: P(x)\frac{d^2y}{dx^2} + Q(x)\frac{dy}{dx} + R(x) y(x) = 0

    A point is said to regular singular at `x0` if `x - x0\frac{Q(x)}{P(x)}`
    and `(x - x0)^{2}\frac{R(x)}{P(x)}` are analytic at `x0`. For simplicity
    `P(x)`, `Q(x)` and `R(x)` are assumed to be polynomials. The algorithm for
    finding the power series solutions is:

    1.  Try expressing `(x - x0)P(x)` and `((x - x0)^{2})Q(x)` as power series
        solutions about x0. Find `p0` and `q0` which are the constants of the
        power series expansions.
    2.  Solve the indicial equation `f(m) = m(m - 1) + m*p0 + q0`, to obtain the
        roots `m1` and `m2` of the indicial equation.
    3.  If `m1 - m2` is a non integer there exists two series solutions. If
        `m1 = m2`, there exists only one solution. If `m1 - m2` is an integer,
        then the existence of one solution is confirmed. The other solution may
        or may not exist.

    The power series solution is of the form `x^{m}\sum_{n=0}^\infty a_{n}x^{n}`. The
    coefficients are determined by the following recurrence relation.
    `a_{n} = -\frac{\sum_{k=0}^{n-1} q_{n-k} + (m + k)p_{n-k}}{f(m + n)}`. For the case
    in which `m1 - m2` is an integer, it can be seen from the recurrence relation
    that for the lower root `m`, when `n` equals the difference of both the
    roots, the denominator becomes zero. So if the numerator is not equal to zero,
    a second series solution exists.


    Examples
    ========

    >>> from sympy import dsolve, Function, pprint
    >>> from sympy.abc import x
    >>> f = Function("f")
    >>> eq = x*(f(x).diff(x, 2)) + 2*(f(x).diff(x)) + x*f(x)
    >>> pprint(dsolve(eq, hint='2nd_power_series_regular'))
                                  /   6     4    2    \
                                  |  x     x    x     |
              / 4     2    \   C1*|- --- + -- - -- + 1|
              |x     x     |      \  720   24   2     /    / 6\
    f(x) = C2*|--- - -- + 1| + ------------------------ + O\x /
              \120   6     /              x


    References
    ==========
    - George E. Simmons, "Differential Equations with Applications and
      Historical Notes", p.p 176 - 184

    r   r  r  r  r   r  r  r  rl   )r   r   r   c              3   4   K   | ]  }|j                     y wr   )is_real)r   r   s     ry   r   z/ode_2nd_power_series_regular.<locals>.<genexpr>	  s      5(5(r  )r1  N)r   r   rz   r   r   r   r.   r~   r-   r   rj  r7   r   r   r   r   r   
_frobenius
is_integerintr  r/   )rr   r   r   r   r   r   r$  r  r  r   r  r  r  indicialr+  r0  p0q0sollistserdict1serdict2m1m2finalseries1r   powerfinalseries2s                              ry   ode_2nd_power_series_regularrM  	  sB   l 			!A		A#BA.FBc
A	tB'NEc
Ac
A HA xx{OOD!$!qR0D$&'99 C771: , FBAq1uI"$r)1-G:gt, 5(&5( 2(w<1kkm#BRxzQ!eEl++!%(1*b"b!QArJH BBBwRB "%(1*b"b!QArJHG''%eBhqj"b"aB2N &eBhqj"b"aB2UWXL >CHHQRL)q2vo ==> FR<4L66L# BC-E HSM1r6E/$AALB " !B|L8adGL<$?R!!U(O, - - 52(,wr   c
                 ,   t        |       } |	}
t        d      }t        dd      }t        | dz         D cg c]  }t	        |       }}g }||fD ]  }|j                  |      rOt        ||      j                         | k  r2|r|j                  |||z         }t        ||      j                         }nJt        ||| dz         }t        t        t        |j                              dd |      j                         }t        | dz         D ]  }|f|vs	t        j                  ||f<    |j!                  |        |d   }|d   }||dz
  z  ||z  z   |z   }i }t        d| dz         D ]  }||||f   z  ||f   z   z  }t        d|      D ];  }t#        dt%        |      z         }|||   ||z   |||z
  f   z  |||z
  f   z   z  z  }= |
#||
|z
  k(  r|r y	t        j                  |||   <   | |j                  |||z         z  |||   <    |S c c}w )
z\
    Returns a dict with keys as coefficients and values as their values in terms of C0
    r  r  r   )rt   rl   )r   r   Nr  F)rA  r   r8   ro   rp   r  r(   degreer   as_dictr.   r   r   r   r   rj  r   r   r   )r   r  rC  rD  r  r  r   r   r  r1  rI  r  numsymsrw   serlistserdict_tseriespseriesqseriesrB  frobdictrs   rF  r  s                            ry   r?  r?  	  sQ    	AA	Bc
As!,G&+AEl3tG}3G3G1v QDaL$7$7$9Q$>hhq!b&)aL((*E SB!A#.Gggll34Tr:A>FFHEq1u 	%At5 ffqd	% 	u" ajGajG!a%y1R4"$HH1a!e_ @7A4=7A4=01q! 	QAs1v&C8C=1q5'1q5(*;";gq1uh>O"OPPC	Q >a26k'(vv$$'4q!A#)>#?HWQZ @" OQ 4s   Hc                       fd}g }|D ]C  }|dd D ](  } |||      r  |||      s|j                  |       * |j                  |       E |S )ax  
    Remove redundant solutions from the set of solutions.

    This function is needed because otherwise dsolve can return
    redundant solutions. As an example consider:

        eq = Eq((f(x).diff(x, 2))*f(x).diff(x), 0)

    There are two ways to find solutions to eq. The first is to solve f(x).diff(x, 2) = 0
    leading to solution f(x)=C1 + C2*x. The second is to solve the equation f(x).diff(x) = 0
    leading to the solution f(x) = C1. In this particular case we then see
    that the second solution is a special case of the first and we do not
    want to return it.

    This does not always happen. If we have

        eq = Eq((f(x)**2-4)*(f(x).diff(x)-4), 0)

    then we get the algebraic solution f(x) = [-2, 2] and the integral solution
    f(x) = x + C1 and in this case the two solutions are not equivalent wrt
    initial conditions so both should be returned.
    c                 "    t        | |      S r   )_is_special_case_of)soln1soln2rr   r   vars     ry   is_special_case_ofz7_remove_redundant_solutions.<locals>.is_special_case_ofI
  s    "5%UC@@r   N)r  r   )rr   solnsr   r^  r_  unique_solnsr\  r]  s   ` ``    ry   r   r   2
  so    .A L '!!_ 	'E!%/#E51##E*		' &' r   c                 0   | j                   | j                  z
  } |j                   |j                  z
  }| j                  t              rX|j                  t              rC| j	                         |j	                         k(  r!| j                         } |j                         }n,y| j                  t              s|j                  t              ry| j                  j                  |j                        }|j                  j                  |j                        }t        t        | |      t        |            }t        |      dk(  r|h}t        ||      D ]  \  }}	| j                  ||	      }  | }
|}t        |
|      g}t        d|      D ]A  }|
j                        }
|j                        }t        |
|      }|j!                  |       C t#        d |D              ry|D cg c]  }t%        |t&              r| }}	 t)        ||      }t%        |t,              r|g}|D ]3  }|D ],  }|j                   |j                  z
  }t/        ||      dus+  y 5 |D ]&  }t#        fd|j1                         D              r& y yc c}w # t*        $ r Y yw xY w)z
    True if soln1 is found to be a special case of soln2 wrt some value of the
    constants that appear in soln2. False otherwise.
    Frl   c              3   <   K   | ]  }t        |t                y wr   )r~   r"   )r   rr   s     ry   r   z&_is_special_case_of.<locals>.<genexpr>
  s     
7B:b,'
7r   Tc              3   @   K   | ]  }|j                          y wr   rg  )r   r  r^  s     ry   r   z&_is_special_case_of.<locals>.<genexpr>
  s     >!155:>s   )r   r   r   r-   getOremoveOr   r   rz   r   r   r  r   r   ro   r   r   rl  r~   r!   r7   r   r   r6   r   )r\  r]  rr   r   r^  
constants1
constants2constants1_newc_oldc_newr   r   eqnsr   constant_solnsconstant_solns       `           ry   r[  r[  X
  sQ   & II		!EII		!E yyEIIe,::<5::<'MMOEMMOE	5	UYYu-##..r?J##..r?J+E%,?ZQN
:!()J7 )u

5%() C
CsCL>D1e_ hhsmhhsmS\B	 
7$
77A2ZK%@BADAtZ0
 .$'() (  	Bvvbff}BM*$6	 ( >}';';'=>> 1 B  s   $J:JJ	 		JJc                    |j                   d   }|d   }|j                  }||d       ||d      z  }|d   }|d   }	|d   }
|}|st         ||      |	      S |	}|
dkD  rw|j                  ||||	i      }|j	                  t
              s*|j	                  t              s|j	                  t              rt         ||      t
              S |r||||z
  z  z  }t        d	|
      D ]  }|j                  |      |j                  |      |z  z   }|j                  ||||	i      }|j	                  t
              s@|j	                  t              s+|j	                  t
               s|j	                  t              rt         ||      t
              c S ||||z
  |z  z  t        |      z  z  }|} |t        ||
z        z  }t         ||      |      S )
aH  
    The power series solution is a method which gives the Taylor series expansion
    to the solution of a differential equation.

    For a first order differential equation `\frac{dy}{dx} = h(x, y)`, a power
    series solution exists at a point `x = x_{0}` if `h(x, y)` is analytic at `x_{0}`.
    The solution is given by

    .. math:: y(x) = y(x_{0}) + \sum_{n = 1}^{\infty} \frac{F_{n}(x_{0},b)(x - x_{0})^n}{n!},

    where `y(x_{0}) = b` is the value of y at the initial value of `x_{0}`.
    To compute the values of the `F_{n}(x_{0},b)` the following algorithm is
    followed, until the required number of terms are generated.

    1. `F_1 = h(x_{0}, b)`
    2. `F_{n+1} = \frac{\partial F_{n}}{\partial x} + \frac{\partial F_{n}}{\partial y}F_{1}`

    Examples
    ========

    >>> from sympy import Function, pprint, exp, dsolve
    >>> from sympy.abc import x
    >>> f = Function('f')
    >>> eq = exp(x)*(f(x).diff(x)) - f(x)
    >>> pprint(dsolve(eq, hint='1st_power_series'))
                           3       4       5
                       C1*x    C1*x    C1*x     / 6\
    f(x) = C1 + C1*x - ----- + ----- + ----- + O\x /
                         6       24      60


    References
    ==========

    - Travis W. Walker, Analytic power series technique for solving first-order
      differential equations, p.p 17, 18

    r   r  r  r  r  r  r  rl   r  )r   r   r   r   r   r   r   r   ro   r   r&   r-   )rr   r   r   r   r   r  r   hr   r   r  Fr.   hc	factcountFnewFnewcs                    ry   ode_1st_power_seriesrv  
  s   N 			!Ac
A		A	uSz	5s,,A$KE'NE'NE 	
A!A$ FqyVVQq%()66":sadB<b!e)n$F1e_ 	vvay166!9Q;&		1eQ./99R=EIIcNeiin		#adB<%!e)i/091EEE eAuHoFadFr   c                 D   t        | t              r| j                  | j                  z
  } |st	        |       \  } }|j
                  }t        |      dk7  rt        d      |d   }|st        | |      }|dk7  rt        d      |j                  |      }t        d|g      }t        d|g      }t        t        |       |      j                  ||z  |z         }	|	rt        |	|   |	|   z         }
n	 t!        | |      }|d   }
t#        d	      }|
j%                  ||      }
 t'        d
      ||      } t'        d      ||      } t'        d
      ||      } t'        d      ||      }|j                  |      |j                  |      |j                  |      z
  |
z  z   |j                  |      |
dz  z  z
  ||
j                  |      z  z
  ||
j                  |      z  z
  }g }|D ]  }|t)        ||         j%                  ||      |t)        ||         j%                  ||      i}t        |j%                  |      j+                               }|r$|j-                  d|j%                  ||      f       |j-                  d        |S # t        $ r t        d      w xY w)a=  
    This function is used to check if the given infinitesimals are the
    actual infinitesimals of the given first order differential equation.
    This method is specific to the Lie Group Solver of ODEs.

    As of now, it simply checks, by substituting the infinitesimals in the
    partial differential equation.


    .. math:: \frac{\partial \eta}{\partial x} + \left(\frac{\partial \eta}{\partial y}
                - \frac{\partial \xi}{\partial x}\right)*h
                - \frac{\partial \xi}{\partial y}*h^{2}
                - \xi\frac{\partial h}{\partial x} - \eta\frac{\partial h}{\partial y} = 0


    where `\eta`, and `\xi` are the infinitesimals and `h(x,y) = \frac{dy}{dx}`

    The infinitesimals should be given in the form of a list of dicts
    ``[{xi(x, y): inf, eta(x, y): inf}]``, corresponding to the
    output of the function infinitesimals. It returns a list
    of values of the form ``[(True/False, sol)]`` where ``sol`` is the value
    obtained after substituting the infinitesimals in the PDE. If it
    is ``True``, then ``sol`` would be 0.

    rl   z(ODE's have only one independent variabler   zRLie groups solver has been implemented only for first order differential equationsr  r  r  z9Infinitesimals for the first order ODE could not be foundr  r   r   r  F)Tr   )r~   r   r   r   r<   r   r   r   r=   r   r   r   r/   r   r   r3   r7   r   r   r   r   r   r   )rr   infinitesimalsr   r   r   r   r#  r  r  r   rp  r   r  r   r   dxidetapdesoltuptsols                       ry   checkinfsolr~  
  s   4 "hVVbff_r?D		I
9~CDDaLb$'EA:% ': ; ; 1BSRD)ASRD)AF2J+11!B$(;EeAhuQx/00B-C
 AAc
AtQA$1%B!(5/!Q'C (4.D)C"8E?1d+D88A;#((1+
":A!==QT!"$&q	N358!&&)_ECF% -Ac#hK,,T153t9**435sxx~2245MM5#((1d*;"<=MM),- M/ + >- /= > >>s   2J
 
Jc                 t   | d   d   j                   }| d   d   j                   }| d   }| d   }| d   }i }t        t        |d   j                  t                    d   j                  t                    d   }t        d      D ]=  }t        t        j                  ||         D 	cg c]  }	|	||||   df   z   c}	 ||<   ? |d ||      df    |d ||      df   z  |d<   |d ||      df    |d ||      df   z  |d<   |d ||      df    |d ||      df   z  |d	<   |d ||      df    |d ||      df   z  |d
<   t        j                  t        j                  g}
t        d      D ]K  }t        j                  ||         D ].  }|j                   ||       ||            r"|
|xx   |z  cc<   0 M |
d   j                  |      s%|
d   j                  |      s|
d   |d<   |
d   |d<   nt        d      | d   dk(  rt        |||||      }| d   dk(  rt        |||||      }S c c}	w )Nr   r   rl   rO  rr   r  r  r  r  r  k1k2zDOnly homogeneous problems are supported (and constant inhomogeneity)r   rh  ri  )r   r   r   r   r   ro   r   rk  r   rj  r   r   _linear_2eq_order1_type6_linear_2eq_order1_type7)match_r   r  r   rn  rr   r   r   rw   r  ro  rF  r   s                ry   sysode_linear_2eq_order1r  @  s|   vqAvqA&>D		B	B
AT"Q%++j)*1-33F;<Q?A1X Pr!u9MNeBqa{O+NO1P
 1Q4l]2a!Qh<'AcF1Q4l]2a!Qh<'AcF1Q4l]2a!Qh<'AcF1Q4l]2a!Qh<'AcFvvaffoG1X  r!u% 	 A551qt$
a
	   AJNN1!2!*$!*$! #B C 	C  !W,&q!Q26 !W,&q!Q26J1 Os   &H5
c                 ~   t        |d      \  }}}}d}	d}
t        |d   t        |d   |d   z        j                         d   z        }t        |d   t        |d   |d   z        j                         d   z        }t        ||g      D ]  \  }}t	        j
                  t        |            D ]w  }|j                  |      s|}
|
dk7  r+|dk(  r&|d   |z  |d   z
  |d   |d   |z  z
  z  |k(  rd}	|} j|
dk7  sL|dk(  sR|d   |z  |d   z
  |d   |d   |z  z
  z  |k(  ssd	}	|}   |	dk(  rt         | |      |      |d    | |      z  z
  |d    | |      z  |t        | t        |d   |d   |z  z
  |      z        z  z   z  z
  }t        |      d   }t        ||d
z         j                  }||z  |t        | t        |d   |d   |z  z
  |      z        z  z   }n|	d	k(  rt         ||      |      |d    ||      z  z
  |d   z   ||      z  z
  |t        | t        |d   |d   |z  z
  |      z        z  z   }t        |      d   }t        ||d
z         j                  }||z  |t        | t        |d   |d   |z  z
  |      z        z  z   }t         | |            t         ||            gS )ag  
    The equations of this type of ode are .

    .. math:: x' = f(t) x + g(t) y

    .. math:: y' = a [f(t) + a h(t)] x + a [g(t) - h(t)] y

    This is solved by first multiplying the first equation by `-a` and adding
    it to the second equation to obtain

    .. math:: y' - a x' = -a h(t) (y - a x)

    Setting `U = y - ax` and integrating the equation we arrive at

    .. math:: y - ax = C_1 e^{-a \int h(t) \,dt}

    and on substituting the value of y in first equation give rise to first order ODEs. After solving for
    `x`, we can obtain `y` by substituting the value of `x` in second equation.

       r  r   r  r  r  r  rl   r  r   )r   )rz   r,   r  rQ  r   rk  r5   r   r   r#   r'   r   r   r   r   )r   r  r   r   rr   r  C2C3C4r  r  rp  rq  r   rw   rF  r   equhint1sol1r   s                        ry   r  r  c  s   * ,BA6NBB	A	A	#vafQsVm,;;=a@@	AB	#vafQsVm,;;=a@@	AB2r(# 1}Q/0 	A558!t1sVAX#&3!C&():;AAA!t1sVAX#&3!C&():;AAA	 	Av1Q4lQsVAaD[(1S61QqT6BsA2hqQTvXYZ]X^_`X`O`bcFdCd?e<e3e+ffS!!$ck 1266v3r(1S6AcF1H+<a"@@AAA	
Q1Q4lQsVAaD[(1S6!8AaD=82c1"XaPSfWXY\W]^_W_N_abEcBc>d;ddS!!$ck 1266v3r(1S6AcF1H+<a"@@AAAqtTNBqtTN++r   c           	         t        |d      \  }}}}|d   |d   z  |d   z  |d   dz  |d   z  z
  |d   t        |d   |      z  z   t        |d   |      |d   z  z
  }	|d   |d   z  |d   z  |d   |d   dz  z  z
  t        |d   |      |d   z  z   |d   t        |d   |      z  z
  }
|d   |d   z  |d   |d   z  z   t        |d   |      z   }|d   |d   z  |d   |d   z  z   t        |d   |      z   }|	dk(  rt        |d   t         | |      ||      z  |t         | |      |      z  z
        j                  }t        t         ||      |      |d   |z  z
  |d    ||      z  z
        j                  }n|
dk(  rt        |d   t         ||      ||      z  |t         ||      |      z  z
        j                  }t        t         | |      |      |d    | |      z  z
  |d   |z  z
        j                  }n*|	|d   z  j	                  |      s||d   z  j	                  |      st        t         | |      ||      ||d   z  t         | |      |      z  z
  |	|d   z   | |      z  z
        j                  }t        t         ||      |      |d   |z  z
  |d    ||      z  z
        j                  }ni|
|d   z  j	                  |      s||d   z  j	                  |      st        t         ||      ||      ||d   z  t         ||      |      z  z
  |
|d   z   ||      z  z
        j                  }t        t         | |      |      |d    | |      z  z
  |d   |z  z
        j                  }n t        d	      |      } t        d
      |      }t        t        |d   |            }t        t        |d   |            }||z  ||z  t        |d   |z  |z  |dz  z  |      z  z   }||z  |||z  |z  |t        |d   |z  |z  |dz  z  |      z  z   z  z   }t         | |      |      t         ||      |      gS )a  
    The equations of this type of ode are .

    .. math:: x' = f(t) x + g(t) y

    .. math:: y' = h(t) x + p(t) y

    Differentiating the first equation and substituting the value of `y`
    from second equation will give a second-order linear equation

    .. math:: g x'' - (fg + gp + g') x' + (fgp - g^{2} h + f g' - f' g) x = 0

    This above equation can be easily integrated if following conditions are satisfied.

    1. `fgp - g^{2} h + f g' - f' g = 0`

    2. `fgp - g^{2} h + f g' - f' g = ag, fg + gp + g' = bg`

    If first condition is satisfied then it is solved by current dsolve solver and in second case it becomes
    a constant coefficient differential equation which is also solved by current solver.

    Otherwise if the above condition fails then,
    a particular solution is assumed as `x = x_0(t)` and `y = y_0(t)`
    Then the general solution is expressed as

    .. math:: x = C_1 x_0(t) + C_2 x_0(t) \int \frac{g(t) F(t) P(t)}{x_0^{2}(t)} \,dt

    .. math:: y = C_1 y_0(t) + C_2 [\frac{F(t) P(t)}{x_0(t)} + y_0(t) \int \frac{g(t) F(t) P(t)}{x_0^{2}(t)} \,dt]

    where C1 and C2 are arbitrary constants and

    .. math:: F(t) = e^{\int f(t) \,dt}, P(t) = e^{\int p(t) \,dt}

    r  r  r  r  r  r  r  r   r   y0)	rz   r   r   r   r   r   r#   r'   r   )r   r  r   r   rr   r  r  r  r  e1e2rH  rI  r  r   r   r  rq  Ps                      ry   r  r    so   F ,BA6NBB	
3#qv	#	!C& 0	01S6$qva.3H	H4PQRUPVWX>Z[\_Z`K`	`B	
3#qv	#qvqy 0	04#q>!C&3H	H1S6RVWXY\W]^_R`K`	`B	
3#3#	&afQ	7B	
3#3#	&afQ	7B	QwafT!A$q^+bad1o=>BBd1Q4lQsVD[01S6!A$;>?CC	qafT!A$q^+bad1o=>BBd1Q4lQsVAaD[01S6$;>?CC3i__QAcF(:d1Q4!n1S6	4!Q<'??2af9aPQdBRRSWWd1Q4lQsVD[01S6!A$;>?CC3i__QAcF(:d1Q4!n1S6	4!Q<'??2af9aPQdBRRSWWd1Q4lQsVAaD[01S6$;>?CCXd^AXd^A3"#3"#"ur"uXafQhqjQ&6:::"ur1Q3r6Bx#q
2q50@!'D$DDEEqtTNBqtTN++r   c                 Z   | d   }| d   }| d   }t        t        |d   j                  t                    d   j                  t                    d   }| d   dk(  rt	        |||      }|S |d   j
                  }|d   j
                  }t        d      D ]7  }d}	t        j                  ||         D ]  }
|	|
||||   df   z  z  }	 |	||<   9 | d   d	k(  rt        ||||      }|S | d   d
k(  rt        ||||      }|S | d   dk(  rt        ||||      }|S | d   dk(  rt        ||||      }S )Nr   rr   rO  r   r   rx  rl   r  r  r  r  r  )r   r   r   r   _nonlinear_2eq_order1_type5r   ro   r   rk  _nonlinear_2eq_order1_type1_nonlinear_2eq_order1_type2_nonlinear_2eq_order1_type3_nonlinear_2eq_order1_type4)r  r   rr   rn  r   r   r   r  rw   rE  r  s              ry   sysode_nonlinear_2eq_order1r    s~   &>D	B		BT"Q%++j)*1-33F;<Q?A !W,)$26
QAQA1X ]]2a5) 	)E5Ad1gaK((C	)1	
  !W,)!Q26 J 
"	#w	.)!Q26
 J	 
"	#w	.)!Q26 J 
"	#w	.)!Q26Jr   c           
         t        |d      \  }}t        d | |       ||      g      }t        d      }t        d      \  }}	|d   j                  t	         | |      |       | |      |z  |z  z
        }
t	         ||      |      |d   z
  |
|   z  j                   ||      |	      }|
|   j                   | |      |      j                   ||      |	      }|
|   }|dk7  r"|d|z
  t        d|z  |	      z  z   dd|z
  z  z  }n|t        t        d|z  |	            z  }|j                         }t        t        d||j                  ||      z  z  |	      j                         |z
  |z
  |	      }g }|D ]T  }|j                  t         | |      |j                  |	|                   |j                  t         ||      |             V |S )	a  
    Equations:

    .. math:: x' = x^n F(x,y)

    .. math:: y' = g(y) F(x,y)

    Solution:

    .. math:: x = \varphi(y), \int \frac{1}{g(y) F(\varphi(y),y)} \,dy = t + C_2

    where

    if `n \neq 1`

    .. math:: \varphi = [C_1 + (1-n) \int \frac{1}{g(y)} \,dy]^{\frac{1}{1-n}}

    if `n = 1`

    .. math:: \varphi = C_1 e^{\int \frac{1}{g(y)} \,dy}

    where `C_1` and `C_2` are arbitrary constants.

    r  r  r   r  r   rt  r   rl   )rz   r   r   r   r   r   r'   r#   r   r7   r   r   r   r  r   rr   r  r  r   r   r{  r|  r   rs  rq  phir   r   r   s                    ry   r  r    s   2 $BA.FBS1Q4!+&AS	A6?DAq
1D1aL1Q4719,-A
qtA,A
!	$**1Q42A	!		!A$qqtA&A	!A!tQqS(1Q3***a1g6Xac1%&&
((*C!Qqvva}_-q16681<rA1ED
C #

2ad388At,-.

2adD>"# Jr   c           
         t        |d      \  }}t        d | |       ||      g      }t        d      }t        d      \  }}	|d   j                  t	         | |      |      t        | | |      z        |z  z
        }
t	         ||      |      |d   z
  |
|   z  j                   ||      |	      }|
|   j                   | |      |      j                   ||      |	      }|
|   }|r%d	|z  t        ||t        d|z  |	      z  z
        z  }n|t        d|z  |	      z   }|j                         }t        t        d||j                  ||      z  z  |	      j                         |z
  |z
  |	      }g }|D ]T  }|j                  t         | |      |j                  |	|                   |j                  t         ||      |             V |S )
a  
    Equations:

    .. math:: x' = e^{\lambda x} F(x,y)

    .. math:: y' = g(y) F(x,y)

    Solution:

    .. math:: x = \varphi(y), \int \frac{1}{g(y) F(\varphi(y),y)} \,dy = t + C_2

    where

    if `\lambda \neq 0`

    .. math:: \varphi = -\frac{1}{\lambda} log(C_1 - \lambda \int \frac{1}{g(y)} \,dy)

    if `\lambda = 0`

    .. math:: \varphi = C_1 + \int \frac{1}{g(y)} \,dy

    where `C_1` and `C_2` are arbitrary constants.

    r  r  r   r  r   rt  r   rl   r  )rz   r   r   r   r   r#   r   r$   r'   r   r7   r   r   r  s                    ry   r  r    s   2 $BA.FBS1Q4!+&AS	A6?DAq
1D1aL3q1v;q=01A
qtA,A
!	$**1Q42A	!		!A$qqtA&A	!Ad3rAhqsA...//8AaC##
((*C!Qqvva}_-q16681<rA1ED
C #

2ad388At,-.

2adD>"# Jr   c                    t        |d      \  }}}}t        d      }t        d      }	t        d      }
t        d      }|d   j	                  t         | |      |      |
z
        }|d   j	                  t         ||      |      |z
        }||
   j                   | |      |	      j                   ||       ||	            }||   j                   | |      |	      j                   ||       ||	            }t        t        t         ||	      |	      ||z              }t        |t              r|g}|D ]O  }t        t        d|j                   ||	      |j                        z  |	      j                         |z
  |z
  |	      }Q g }D ]^  }|j                  t         | |      |             |j                  t         ||      j                  j                  |	|                   ` |S )	a  
    Autonomous system of general form

    .. math:: x' = F(x,y)

    .. math:: y' = G(x,y)

    Assuming `y = y(x, C_1)` where `C_1` is an arbitrary constant is the general
    solution of the first-order equation

    .. math:: F(x,y) y'_x = G(x,y)

    Then the general solution of the original system of equations has the form

    .. math:: \int \frac{1}{F(x,y(x,C_1))} \,dx = t + C_1

    r  r  r|  r{  r   rs  r   rl   )rz   r   r   r   r   r   r   r   r   r~   r   r7   r'   r   r   r   )r   r  r   rr   r  r  r  r  r|  r{  r   rs  ry  rz  rq  Gsol2rsol2sr  r   r   s                        ry   r  r  J  s   $ ,BA6NBBAsAS	AS	A	AT!A$q\A%	&B	AT!A$q\A%	&B
1

1Q4  1qt,A
1

1Q4  1qt,A2d1Q4mQqS)*E%" PXaqtUYY 77;@@BQFKQOP
C 8

2adD>"

2adUYY,,Q5678 Jr   c                    t        |d      \  }}t        d      \  }}t        dt              \  }}	t        d      }
t        d      }t        d||g	      }t        d
||g	      }t        d||g	      }t        d||g	      }|d   j	                  t         | |      |      |
z
        }|d   j	                  t         ||      |      |z
        }||
   j                   | |      |      j                   ||      |      ||   j                   | |      |      j                   ||      |      z  j                         \  }}|j	                  ||z        }|j	                  ||z        }||
   j                   | |      |      j                   ||      |      |z  }||   }||   }||   }||   }t        t        ||z  |      j                         t        ||z  |      j                         z
  |z
  |      }t        t        ||z  |      j                         t        ||z  |      j                         z
  |z
  |      }g }|D ]  }|j                  t         ||      t        t         |	|      |      |j                  ||      j                  | |	|            |j                  | |	|            z  |j                  ||      j                  | |	|            z  z
        j                                |D ]  }|j                  t         | |      t        t         ||      |      |j                  | ||            |j                  ||      j                  | ||            z  |j                  ||      j                  | ||            z  z
        j                                t        |      S )a  
    Equation:

    .. math:: x' = f_1(x) g_1(y) \phi(x,y,t)

    .. math:: y' = f_2(x) g_2(y) \phi(x,y,t)

    First integral:

    .. math:: \int \frac{f_2(x)}{f_1(x)} \,dx - \int \frac{g_1(y)}{g_2(y)} \,dy = C

    where `C` is an arbitrary constant.

    On solving the first integral for `x` (resp., `y` ) and on substituting the
    resulting expression into either equation of the original solution, one
    arrives at a first-order equation for determining `y` (resp., `x` ).

    r  r  rt  zU, Vru  r   rs  r~  r  r  r  r  r   rl   )rz   r   r   r   r   r   r   r  r7   r'   r   r   r   r   r   r   )r   r  r   rr   r  r  r{  r|  UVr   rs  r~  r  r  r  ry  rz  rs   r/  r  r  r  r  r  G1G2sol1rr  r   r   s                                  ry   r  r  p  s}   & $BA.FB6?DAq6x(DAqS	AS	A	dQqE	"B	dQqE	"B	dQqE	"B	dQqE	"B	AT!A$q\A%	&B	AT!A$q\A%	&B	AAaD		 	 1a	(	AAaD		 	 1a	(	*+9>+; C 
2b5	B	2b5	Ba5::ad1""1Q4*C
/C	BBbf	BBbf(2b5!$))+hr"uQ.?.D.D.FFKQOE(2b5!$))+hr"uQ.?.D.D.FFKQOE
C D

2adF4!Q<"''!D/2F2Fq12NrwwWXYZ[\Y]2^_b_g_ghijn_o_t_tuvwxyzw{_|2|#|}  B  B  C  	DD D

2adF4!Q<"''!AaD/"''!D/BVBVWXYZ[\Y]B^2^_b_g_ghijn_o_t_tuvwxyzw{_|2|#|}  B  B  C  	DDs8Or   c           	      T   t        d      \  }}t        d      t        d      fd}| D ]X  }t        |t              s| d   d   j                  }| d   d   j                  } |||      \  }	}
|	r|
rI |||      \  }	}
||}}Z t                     }t                     }t         |      |z  	   j                  ||      j                  ||      z         t         |      |z  
   j                  ||      j                  ||      z         hS )a  
    Clairaut system of ODEs

    .. math:: x = t x' + F(x',y')

    .. math:: y = t y' + G(x',y')

    The following are solutions of the system

    `(i)` straight lines:

    .. math:: x = C_1 t + F(C_1, C_2), y = C_2 t + G(C_1, C_2)

    where `C_1` and `C_2` are arbitrary constants;

    `(ii)` envelopes of the above lines;

    `(iii)` continuously differentiable lines made up from segments of the lines
    `(i)` and `(ii)`.

    r  r  r   rs  c                 t   d   j                  t         |             z   |       z
  z         }d   j                  t         |            z   |      z
  z         }|r|sld   j                  t         |              |       z  z
  z  z         }d   j                  t         |             |      z  z
  z  z         }|r|shd    j                  t         |             z   |       z
  z         }d    j                  t         |            z   |      z
  z         }|r|snd    j                  t         |              |       z  z
  z  z         }d    j                  t         |             |      z  z
  z  z         }||gS )Nr   rl   )r   r   )r   r  ry  rz  rr   r   rs  r   s       ry   r}  z/_nonlinear_2eq_order1_type5.<locals>.check_type  s   U[[4!Q<!A$.23U[[4!Q<!A$.23rAT!A$q\AaDF2QqS89BAT!A$q\AaDF2QqS89Bra5&$qtA,1 5 9:Ba5&$qtA,1 5 9:Bra5&QqT!qtAv 5! ;<Ba5&QqT!qtAv 5! ;<BBxr   r   rl   )rz   r   r~   r   r   r   r   r   )r   r   rr   r  r  r}  r   r   r  ry  rz  x1y1r   rs  s    ``          @@ry   r  r    s%   , $BA.FBS	AS	A  eT"Q
AQ
A!!Q'HR2%a+R!1 
ad1BD1aLrqtRTBqEJJr"-222b99:BqtRTBqEJJWYZ\L]LbLbcefhLiEi<jkkr   c                    | d   d   j                   }| d   d   j                   }| d   d   j                   }| d   }t        t        |d   j                  t                    d   j                  t                    d   }| d   dk(  rt        |||||      }| d   dk(  rt        |||||      }| d   d	k(  rt        |||||      }| d   d
k(  rt        |||||      }| d   dk(  rt        |||||      }S )Nr   r   rl   r  rr   r   r  r  r  r  rx  )
r   r   r   r   r   _nonlinear_3eq_order1_type1_nonlinear_3eq_order1_type2_nonlinear_3eq_order1_type3_nonlinear_3eq_order1_type4_nonlinear_3eq_order1_type5)r  r   r  r  rr   r   r   s          ry   sysode_nonlinear_3eq_order1r    s   vqAvqAvqA	BT"Q%++j)*1-33F;<Q?A !W,)!Q1b9 !W,)!Q1b9 !W,)!Q1b9 !W,)!Q1b9 !W,)!Q1b9Jr   c                    t        |d      \  }}t        d      \  }}}	t        d | |       ||       ||      |g      }
t        d | |       ||       ||      |g      }t        d | |       ||       ||      |g      }t         | |      |      |d   z
  j	                  |
 ||      z   ||      z        }|j                  t         ||      |      |d	   z
  j	                  | ||      z   | |      z               |j                  t         ||      |      |d   z
  j	                  | | |      z   ||      z               ||
   j                         \  }}||   j                         \  }}||   j                         \  }}t        ||z  ||z  z
  ||	z  z   ||z  ||z  z   ||	z  z
  ||z  ||z  z
  ||	z  z
  g||g      }||   ||   g}t        |d   j                         d	   |d	   j                         d	         }|d   j                  |	|      }|d	   j                  |	|      }t        ||z  |z
  |||z
  z   | |      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   | |      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   ||      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   ||      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   ||      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   ||      dz  z  z
  |||z
  z  z        }t        |t         | |      |      z  ||z
  |z  |z  z
        }t        |t         ||      |      z  ||z
  |z  |z  z
        } t        |t         ||      |      z  ||z
  |z  |z  z
        }!|| |!gS )
a  
    Equations:

    .. math:: a x' = (b - c) y z, \enspace b y' = (c - a) z x, \enspace c z' = (a - b) x y

    First Integrals:

    .. math:: a x^{2} + b y^{2} + c z^{2} = C_1

    .. math:: a^{2} x^{2} + b^{2} y^{2} + c^{2} z^{2} = C_2

    where `C_1` and `C_2` are arbitrary constants. On solving the integrals for `y` and
    `z` and on substituting the resulting expressions into the first equation of the
    system, we arrives at a separable first-order equation on `x`. Similarly doing that
    for other two equations, we will arrive at first order equation on `y` and `z` too.

    References
    ==========
    -https://eqworld.ipmnet.ru/en/solutions/sysode/sode0401.pdf

    r  r  r  r  r  r  r   r   rl   )rz   r   r   r   r   r   r  r7   r+   r   r%   r   )"r   r  r  r   rr   r  r  r{  r|  r?  r  r  r   r   n1rd  n2re  n3d3r  valsr  r  r  y_xz_xz_yx_yx_zy_zr  r   sol3s"                                     ry   r  r    s   , $BA.FBi GAq!S1Q41qtQ/0AS1Q41qtQ/0AS1Q41qtQ/0A	ad11	$$QqtVAaD[1AHHd1Q4lRU"))!AaD&1+67HHd1Q4lRU"))!AaD&1+67qT  "FBqT  "FBqT  "FB
Abd2a4Abd2a4Abd2a4@!A
GCFCFDDG""$Q'a)?)?)A!)DEAQQAQQA
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C!D1aL.AaC9S=01D!D1aL.AaC9S=01D!D1aL.AaC9S=01D$r   c                 B   t        |d      \  }}t        d      \  }}}	t        d | |       ||       ||      |g      }
t        d | |       ||       ||      |g      }t        d | |       ||       ||      |g      }t        d      }t         | |      |      |d	   z
  j	                   ||       ||      z  |z        }t        ||         j	                  |
|z        }|j                  t         ||      |      |d
   z
  ||   z  j	                  | ||      z   | |      z               |j                  t         ||      |      |d   z
  ||   z  j	                  | | |      z   ||      z               ||
   j                         \  }}||   j                         \  }}||   j                         \  }}t        ||z  ||z  z
  ||	z  z   ||z  ||z  z   ||	z  z
  | |z  ||z  z   ||	z  z   g||g      }||   ||   g}t        |d	   j                         d
   |d
   j                         d
         }|d	   j                  |	|      }|d
   j                  |	|      }t        ||z  |z
  |||z
  z   | |      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   | |      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   ||      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   ||      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   ||      dz  z  z
  |||z
  z  z        }t        ||z  |z
  |||z
  z   ||      dz  z  z
  |||z
  z  z        } t        |t         | |      |      z  ||z
  |z  |z  ||   z  z
        }!t        |t         ||      |      z  ||z
  |z  |z  ||   z  z
        }"t        |t         ||      |      z  ||z
  |z  | z  ||   z  z
        }#|!|"|#gS )a  
    Equations:

    .. math:: a x' = (b - c) y z f(x, y, z, t)

    .. math:: b y' = (c - a) z x f(x, y, z, t)

    .. math:: c z' = (a - b) x y f(x, y, z, t)

    First Integrals:

    .. math:: a x^{2} + b y^{2} + c z^{2} = C_1

    .. math:: a^{2} x^{2} + b^{2} y^{2} + c^{2} z^{2} = C_2

    where `C_1` and `C_2` are arbitrary constants. On solving the integrals for `y` and
    `z` and on substituting the resulting expressions into the first equation of the
    system, we arrives at a first-order differential equations on `x`. Similarly doing
    that for other two equations we will arrive at first order equation on `y` and `z`.

    References
    ==========
    -https://eqworld.ipmnet.ru/en/solutions/sysode/sode0402.pdf

    r  r  r  r  r  r  r   r   r   rl   )rz   r   r   r   r   r5   r   r  r7   r+   r   r%   r   )$r   r  r  r   rr   r  r  r{  r|  r?  r  r  r   r   ry  r   r  rd  r  re  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  s$                                       ry   r  r    sZ   4 $BA.FBi GAq!S1Q41qtQ/0AS1Q41qtQ/0AS1Q41qtQ/0AS	A
qtA,A
	%	%ad1Q4ik	2Bbe""1Q3'AHHtAaD|be#QqT)001Q4!=>HHtAaD|be#QqT)001Q4!=>qT  "FBqT  "FBqT  "FB
Abd2a4Abd2a4"Qr!tBqDA1Q%
HCFCFDDG""$Q'a)?)?)A!)DEAQQAQQA
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C
2bAqsGAaD!GO+a1g6
7C!D1aL.AaC9S=1#556D!D1aL.AaC9S=1#556D!D1aL.AaC9S=1#556D$r   c           	         t        |d      }t        d      \  }}}t        dt              \  }	}
}t        d | |       ||       ||      |g      }t        d | |       ||       ||      |g      }t        d | |       ||       ||      |g      }t        d	t              \  }}}t	         | |      |      |d
   z
  j                  ||z
        }t        ||         j                  ||z        }|j                  t        ||         j                  ||z               |d   j                  ||         r;|d   j                  ||         s$||   ||   c||<   ||<   ||    ||    c||<   ||<   |j                  t	         ||      |      |d   z
  j                  |||   z  ||   |z  z
               ||   }||   }||   }||   j                   | |      |      j                   ||      |      j                   ||      |      }||   j                   | |      |      j                   ||      |      j                   ||      |      }||   j                   | |      |      j                   ||      |      j                   ||      |      }|||z  z
  ||z  z
  |z  }|||z  z
  ||z  z
  |z  }|||z  z
  ||z  z
  |z  }t        t	         |
|      |      ||z  ||z  z
  ||z  ||z  z
  z  j                  ||      j                  | |
|            z
        j                  }t        t	         ||      |      ||z  ||z  z
  ||z  ||z  z
  z  j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  ||z  z
  ||z  ||z  z
  z  j                  ||      j                  | ||            z
        j                  }t        t	         |	|      |      ||z  ||z  z
  ||z  ||z  z
  z  j                  ||      j                  | |	|            z
        j                  }t        t	         |
|      |      ||z  ||z  z
  ||z  ||z  z
  z  j                  ||      j                  | |
|            z
        j                  }t        t	         |	|      |      ||z  ||z  z
  ||z  ||z  z
  z  j                  ||      j                  | |	|            z
        j                  }t        t	         |	|      |      ||z  ||z  z
  j                  ||      j                  ||      j                  | |	|            z
        j                  } t        t	         |
|      |      ||z  ||z  z
  j                  ||      j                  ||      j                  | |
|            z
        j                  }!t        t	         ||      |      ||z  ||z  z
  j                  ||      j                  ||      j                  | ||            z
        j                  }"| |!|"gS )a  
    Equations:

    .. math:: x' = c F_2 - b F_3, \enspace y' = a F_3 - c F_1, \enspace z' = b F_1 - a F_2

    where `F_n = F_n(x, y, z, t)`.

    1. First Integral:

    .. math:: a x + b y + c z = C_1,

    where C is an arbitrary constant.

    2. If we assume function `F_n` to be independent of `t`,i.e, `F_n` = `F_n (x, y, z)`
    Then, on eliminating `t` and `z` from the first two equation of the system, one
    arrives at the first-order equation

    .. math:: \frac{dy}{dx} = \frac{a F_3 (x, y, z) - c F_1 (x, y, z)}{c F_2 (x, y, z) -
                b F_3 (x, y, z)}

    where `z = \frac{1}{c} (C_1 - a x - b y)`

    References
    ==========
    -https://eqworld.ipmnet.ru/en/solutions/sysode/sode0404.pdf

    rl   r  r  ru  r  r  r  r   
F1, F2, F3r   )rz   r   r   r   r   r   r5   r   r   r   r   r   )#r   r  r  r   rr   r  r{  r|  r?  fufvfwr  r  r   r  r  r  ry  r   r  r  r  z_xyy_zxx_yzr  r  r  r  r  r  r  r   r  s#                                      ry   r  r  K  s   8 
 	*Bi GAq!1JBBS1Q41qtQ/0AS1Q41qtQ/0AS1Q41qtQ/0A40JBB
qtQ-"Q%
	&	&r"u	-Bbf##AbD)AHH]2b6"((2./	!uyy21		!B% 0uae"qudUQqTE
!adHHd1Q4mbe#**1QrU7QqT"W+<=>	!A!A$aAaD	
2AaD!		!	!!A$q	)	.	.qtQ	7B	
2AaD!		!	!!A$q	)	.	.qtQ	7B	
2AaD!		!	!!A$q	)	.	.qtQ	7BqsF1Q3J>DqsF1Q3J>DqsF1Q3J>D
beA1R4"9qtAbDy"9!?!?$!G!L!LQrRSu!UU
V
Z
ZC
beA1R4"9qtAbDy"9!?!?$!G!L!LQrRSu!UU
V
Z
ZC
beA1R4"9qtAbDy"9!?!?$!G!L!LQrRSu!UU
V
Z
ZC
beA1R4"9qtAbDy"9!?!?$!G!L!LQrRSu!UU
V
Z
ZC
beA1R4"9qtAbDy"9!?!?$!G!L!LQrRSu!UU
V
Z
ZC
beA1R4"9qtAbDy"9!?!?$!G!L!LQrRSu!UU
V
Z
ZC$r!uQ-1R4!B$;"4"4Qs";"@"@3"G"L"LQrRSu"UUVZZD$r!uQ-1R4!B$;"4"4Qs";"@"@3"G"L"LQrRSu"UUVZZD$r!uQ-1R4!B$;"4"4Qs";"@"@3"G"L"LQrRSu"UUVZZD$r   c           	         t        |d      }t        d      \  }}}t        d | |       ||       ||      |g      }	t        d | |       ||       ||      |g      }
t        d | |       ||       ||      |g      }t        dt        	      \  }}}|d
   j                  t	         | |      |       ||      |z  z
   ||      |z  z         }t        ||         j                  ||z        }|j                  t        ||         j                  |
|z               |d   j                  ||         r;|d   j                  ||         s$||   ||   c||<   ||<   ||
    ||    c||<   ||
<   |j                  t	         ||      |      |d   z
  j                  |	 | |      z  ||   z  ||    ||      z  |z  z
               ||	   }||
   }||   }||   j                   | |      |      j                   ||      |      j                   ||      |      }||   j                   | |      |      j                   ||      |      j                   ||      |      }||   j                   | |      |      j                   ||      |      j                   ||      |      }t        |||dz  z  z
  ||dz  z  z
  |z        }t        |||dz  z  z
  ||dz  z  z
  |z        }t        |||dz  z  z
  ||dz  z  z
  |z        }t        t	         ||      |      ||z  |z  ||z  |z  z
  ||z  |z  ||z  |z  z
  z  j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  |z  ||z  |z  z
  ||z  |z  ||z  |z  z
  z  j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  |z  ||z  |z  z
  ||z  |z  ||z  |z  z
  z  j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  |z  ||z  |z  z
  ||z  |z  ||z  |z  z
  z  j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  |z  ||z  |z  z
  ||z  |z  ||z  |z  z
  z  j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  |z  ||z  |z  z
  ||z  |z  ||z  |z  z
  z  j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  |z  ||z  |z  z
  j                  ||      j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  |z  ||z  |z  z
  j                  ||      j                  ||      j                  | ||            z
        j                  }t        t	         ||      |      ||z  |z  ||z  |z  z
  j                  ||      j                  ||      j                  | ||            z
        j                  }|||gS )a  
    Equations:

    .. math:: x' = c z F_2 - b y F_3, \enspace y' = a x F_3 - c z F_1, \enspace z' = b y F_1 - a x F_2

    where `F_n = F_n (x, y, z, t)`

    1. First integral:

    .. math:: a x^{2} + b y^{2} + c z^{2} = C_1

    where `C` is an arbitrary constant.

    2. Assuming the function `F_n` is independent of `t`: `F_n = F_n (x, y, z)`. Then on
    eliminating `t` and `z` from the first two equations of the system, one arrives at
    the first-order equation

    .. math:: \frac{dy}{dx} = \frac{a x F_3 (x, y, z) - c z F_1 (x, y, z)}
                {c z F_2 (x, y, z) - b y F_3 (x, y, z)}

    where `z = \pm \sqrt{\frac{1}{c} (C_1 - a x^{2} - b y^{2})}`

    References
    ==========
    -https://eqworld.ipmnet.ru/en/solutions/sysode/sode0405.pdf

    rl   r  r  r  r  r  r   r  ru  r   r  )rz   r   r   r   r   r5   r   r   r   r%   r   r   ) r   r  r  r   rr   r  r{  r|  r?  r  r  r   r  r  r  ry  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  s                                    ry   r  r    s   8 
 	*Bi GAq!S1Q41qtQ/0AS1Q41qtQ/0AS1Q41qtQ/0A40JBB	AT!A$q\AaDG+ad2g5	6Bbf##AbD)AHH]2b6"((2./	!uyy21		!B% 0uae"qudUQqTE
!adHHd1Q4lRU"))!AaD&2,1ad2*EFG	!A!A$aAaD	
2AaD		 	 1a	(	-	-ad1	5B	
2AaD		 	 1a	(	-	-ad1	5B	
2AaD		 	 1a	(	-	-ad1	5Ba1fqAv%q()Da1fqAv%q()Da1fqAv%q()D
ad1!A#b&1R-!A#b&1R-!@ F Fq N S STUVWXYVZ [[
\
`
`C
ad1!A#b&1R-!A#b&1R-!@ F Fq N S STUVWXYVZ [[
\
`
`C
ad1!A#b&1R-!A#b&1R-!@ F Fq N S STUVWXYVZ [[
\
`
`C
ad1!A#b&1R-!A#b&1R-!@ F Fq N S STUVWXYVZ [[
\
`
`C
ad1!A#b&1R-!A#b&1R-!@ F Fq N S STUVWXYVZ [[
\
`
`C
ad1!A#b&1R-!A#b&1R-!@ F Fq N S STUVWXYVZ [[
\
`
`C$qtA,!A#b&1Q3r6/!7!7#!>!C!CAc!J!O!OPQRSTURV!WWX\\D$qtA,!A#b&1Q3r6/!7!7#!>!C!CAc!J!O!OPQRSTURV!WWX\\D$qtA,!A#b&1Q3r6/!7!7#!>!C!CAc!J!O!OPQRSTURV!WWX\\D$r   c           	      h   t        |d      }t        d      \  }}}t        dt              \  }	}
}t        d | |       ||       ||      |g      }t        d | |       ||       ||      |g      }t        d | |       ||       ||      |g      }t        d	t              \  }}}|d
   j	                  t         | |      |       | |      |z  z
   | |      |z  z         }t        ||         j	                  ||z        }|j                  t        ||         j	                  ||z               |d   j                  ||         r;|d   j                  ||         s$||   ||   c||<   ||<   ||    ||    c||<   ||<   |j                  t         ||      |      |d   z
  j	                   ||      |||   z  ||   |z  z
  z               ||   }||   }||   }||   j                   | |      |      j                   ||      |      j                   ||      |      }||   j                   | |      |      j                   ||      |      j                   ||      |      }||   j                   | |      |      j                   ||      |      j                   ||      |      }||| z  z  || z  z  | z  }||| z  z  || z  z  | z  }||| z  z  || z  z  | z  }t        t         |
|      |      |||z  ||z  z
  z  |||z  ||z  z
  z  z  j                  ||      j                  | |
|            z
        j                  }t        t         ||      |      |||z  ||z  z
  z  |||z  ||z  z
  z  z  j                  ||      j                  | ||            z
        j                  }t        t         ||      |      |||z  ||z  z
  z  |||z  ||z  z
  z  z  j                  ||      j                  | ||            z
        j                  }t        t         |	|      |      |||z  ||z  z
  z  |||z  ||z  z
  z  z  j                  ||      j                  | |	|            z
        j                  }t        t         |
|      |      |||z  ||z  z
  z  |||z  ||z  z
  z  z  j                  ||      j                  | |
|            z
        j                  }t        t         |	|      |      |||z  ||z  z
  z  |||z  ||z  z
  z  z  j                  ||      j                  | |	|            z
        j                  }t        t         |	|      |      |||z  ||z  z
  z  j                  ||      j                  ||      j                  | |	|            z
        j                  } t        t         |
|      |      |||z  ||z  z
  z  j                  ||      j                  ||      j                  | |
|            z
        j                  }!t        t         ||      |      |||z  ||z  z
  z  j                  ||      j                  ||      j                  | ||            z
        j                  }"| |!|"gS )aB  
    .. math:: x' = x (c F_2 - b F_3), \enspace y' = y (a F_3 - c F_1), \enspace z' = z (b F_1 - a F_2)

    where `F_n = F_n (x, y, z, t)` and are arbitrary functions.

    First Integral:

    .. math:: \left|x\right|^{a} \left|y\right|^{b} \left|z\right|^{c} = C_1

    where `C` is an arbitrary constant. If the function `F_n` is independent of `t`,
    then, by eliminating `t` and `z` from the first two equations of the system, one
    arrives at a first-order equation.

    References
    ==========
    -https://eqworld.ipmnet.ru/en/solutions/sysode/sode0406.pdf

    rl   r  r  ru  r  r  r  r   r  r   )rz   r   r   r   r   r   r5   r   r   r   r   r   )#r   r  r  r   rr   r  r{  r|  r?  r  r  r  r  r  r   r  r  r  ry  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  s#                                      ry   r  r    s   & 
 	*Bi GAq!1JBBS1Q41qtQ/0AS1Q41qtQ/0AS1Q41qtQ/0A40JBB	AT!A$]QqT"W,qtBw6	7Bbf##AbD)AHH]2b6"((2./	!uyy21		!B% 0uae"qudUQqTE
!adHHd1Q4mbe#**1Q41R51Q471B+CDE	!A!A$aAaD	
2AaD!		!	!!A$	*	/	/!a	8B	
2AaD!		!	!!A$	*	/	/!a	8B	
2AaD!		!	!!A$	*	/	/!a	8Bq1"uHQUNaRDq1"uHQUNaRDq1"uHQUNaRD
beQAqtad{Oa2"o#F"L"LQPT"U"Z"Z[\^`ab^c"dd
e
i
iC
beQAqtad{Oa2"o#F"L"LQPT"U"Z"Z[\^`ab^c"dd
e
i
iC
beQAqtad{Oa2"o#F"L"LQPT"U"Z"Z[\^`ab^c"dd
e
i
iC
beQAqtad{Oa2"o#F"L"LQPT"U"Z"Z[\^`ab^c"dd
e
i
iC
beQAqtad{Oa2"o#F"L"LQPT"U"Z"Z[\^`ab^c"dd
e
i
iC
beQAqtad{Oa2"o#F"L"LQPT"U"Z"Z[\^`ab^c"dd
e
i
iC$r!ua.Aqtad{O#9#9!S#A#F#Fq##N#S#STUWYZ[W\#]]^bbD$r!ua.Aqtad{O#9#9!S#A#F#Fq##N#S#STUWYZ[W\#]]^bbD$r!ua.Aqtad{O#9#9!S#A#F#Fq##N#S#STUWYZ[W\#]]^bbD$r   )r  r   r  )rl   rl   r  )rl   r  )Nr   TNNNr      )TN)NFNr   )T)NN)__doc__
sympy.corer   r   r   r   r   sympy.core.containersr   sympy.core.exprr	   r
   sympy.core.functionr   r   r   r   r   r   r   sympy.core.multidimensionalr   sympy.core.numbersr   r   r   sympy.core.relationalr   r   sympy.core.sortingr   r   sympy.core.symbolr   r   r   r   sympy.core.sympifyr   sympy.core.traversalr   sympy.logic.boolalgr    r!   r"   sympy.functionsr#   r$   r%   (sympy.functions.combinatorial.factorialsr&   sympy.integrals.integralsr'   sympy.polysr(   r)   r*   r+   sympy.polys.polytoolsr,   sympy.seriesr-   sympy.series.seriesr.   sympy.simplifyr/   r0   r1   r2   r3   r4   sympy.simplify.radsimpr5   sympy.solversr6   r7   sympy.utilitiesr8   sympy.utilities.iterablesr9   r:   r;   sympy.solvers.deutilsr<   r=   r>   r   rz   rn   r   r   r   r   r   rS  rT  r  rU  r  r   r   rR  r  r  r  r  r   r  r;  rM  r?  r   r[  rv  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  singler  r   r  r>  r   ry   <module>r     s  dL , + ' ,   1 / / . 8 : : & 3. . * * > . ? ? (  &! ! 0 ) , : : B B".d.J$ 48*+\H~IXdLAdtQUY] AH
Qh6nEPNb 1G GTyx43%j 1| |~yx&XvNbx-v2h$LNbGTJZ!F3,j;,|4+Z+Z$L-^/lb$/d5n:x9v1j B Ar   