
    \hK(                     ^    S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SS jr
S rSS	S
.S jjrg)zUtility functions for classifying and solving
ordinary and partial differential equations.

Contains
========
_preprocess
ode_order
_desolve

    )Pow)
DerivativeAppliedUndef)Equality)WildNc                    [        U [        5      (       a'  U R                  R                  (       a  U R                  n U R                  [        5      nU(       dg  [        5       R                  " U Vs/ s H  oDR                  [        5      PM     sn6 n[        U5      S:w  a  [        SU -  5      eUR                  5       n[        UR                  5      nUc  X4$ U Vs/ s H^  oBR                  S5      (       a5  UR                  U5      (       d  [        UR                   5      U-  (       d  MM  XDR#                  5       4PM`     nnU R%                  U5      nX4$ s  snf s  snf )a  Prepare expr for solving by making sure that differentiation
is done so that only func remains in unevaluated derivatives and
(if hint does not end with _Integral) that doit is applied to all
other derivatives. If hint is None, do not do any differentiation.
(Currently this may cause some simple differential equations to
fail.)

In case func is None, an attempt will be made to autodetect the
function to be solved for.

>>> from sympy.solvers.deutils import _preprocess
>>> from sympy import Derivative, Function
>>> from sympy.abc import x, y, z
>>> f, g = map(Function, 'fg')

If f(x)**p == 0 and p>0 then we can solve for f(x)=0
>>> _preprocess((f(x).diff(x)-4)**5, f(x))
(Derivative(f(x), x) - 4, f(x))

Apply doit to derivatives that contain more than the function
of interest:

>>> _preprocess(Derivative(f(x) + x, x))
(Derivative(f(x), x) + 1, f(x))

Do others if the differentiation variable(s) intersect with those
of the function of interest or contain the function of interest:

>>> _preprocess(Derivative(g(x), y, z), f(y))
(0, f(y))
>>> _preprocess(Derivative(f(y), z), f(y))
(0, f(y))

Do others if the hint does not end in '_Integral' (the default
assumes that it does):

>>> _preprocess(Derivative(g(x), y), f(x))
(Derivative(g(x), y), f(x))
>>> _preprocess(Derivative(f(x), y), f(x), hint='')
(0, f(x))

Do not do any derivatives if hint is None:

>>> eq = Derivative(f(x) + 1, x) + Derivative(f(x), y)
>>> _preprocess(eq, f(x), hint=None)
(Derivative(f(x) + 1, x) + Derivative(f(x), y), f(x))

If it's not clear what the function of interest is, it must be given:

>>> eq = Derivative(f(x) + g(x), x)
>>> _preprocess(eq, g(x))
(Derivative(f(x), x) + Derivative(g(x), x), g(x))
>>> try: _preprocess(eq)
... except ValueError: print("A ValueError was raised.")
A ValueError was raised.

   z5The function cannot be automatically detected for %s.	_Integral)
isinstancer   expis_positivebaseatomsr   setunionr   len
ValueErrorpopargsendswithhas	variablesdoitsubs)	exprfunchintderivsdfuncsfvarsrepseqs	            M/var/www/auris/envauris/lib/python3.13/site-packages/sympy/solvers/deutils.py_preprocessr%      s   t $HH!!99DZZ
#FVDVggl3VDEu:? 1378 9 9yy{		NE|z#) 56a{1K1KEE$KK3q{{+e3 QM6D 5	4B8O E5s   1EAE/Ec                   ^ [        ST/S9nU R                  U5      (       a  g[        U [        5      (       aw  U R                  S   T:X  a  [        U R                  5      $ U R                  S   R                  n[        U R                  5      nU(       a  U[        U4S jU 5       5      -  nU$ U R                  (       a  [        U4S jU R                   5       5      $ S$ )a  
Returns the order of a given differential
equation with respect to func.

This function is implemented recursively.

Examples
========

>>> from sympy import Function
>>> from sympy.solvers.deutils import ode_order
>>> from sympy.abc import x
>>> f, g = map(Function, ['f', 'g'])
>>> ode_order(f(x).diff(x, 2) + f(x).diff(x)**2 +
... f(x).diff(x), f(x))
2
>>> ode_order(f(x).diff(x, 2) + g(x).diff(x, 3), f(x))
2
>>> ode_order(f(x).diff(x, 2) + g(x).diff(x, 3), g(x))
3

a)excluder   c              3   <   >#    U  H  n[        UT5      v   M     g 7fN	ode_order.0_r   s     r$   	<genexpr>ode_order.<locals>.<genexpr>   s     ;d)At,,d   c              3   <   >#    U  H  n[        UT5      v   M     g 7fr*   r+   r-   s     r$   r0   r1      s     9y!9Q%%yr2   )r   matchr   r   r   r   r   max)r   r   r'   r   rvs    `   r$   r,   r,   ^   s    . 	S4&!Azz!}}$
##99Q<4t~~&&99Q<$$DT^^$Bc;d;;;I=AYYs9tyy99MAM    T)prepc                   [        U [        5      (       a  U R                  U R                  -
  n U(       d  Uc  [	        X5      u  pSnUR                  SS5      nUR                  S5      nUR                  S5      n	UR                  SS5      n
UR                  S5      nUS	:X  a  SS
KJnJn  UnSnSnOUS:X  a  SSK	J
nJn  UnSnSnUR                  SS5      (       a  W" XSX8U	XX%S9
nOUR                  SSUX&S   SUS   05      nUS   (       d  UW;  a  US:w  a  [        SU-   5      eUUS   ;  a#  US:w  a  [        W[        U 5      -   S-   U-   5      eUS   S:X  a#  [        [        U 5      S-   [        U5      -   5      e[        WS-   S-   [        U 5      -   5      eUS:X  a  [        XUUS   UXZSUS   UUS      XXS9$ US;   a  0 n[        U5      1 S k-
  nUS!:X  ac  U H;  nUR!                  S"5      (       d  M  UR#                  UR%                  S"5      5        M=     S# H  nUU;   d  M  UR#                  U5        M     U H   n[        XUUXUSUUS   UU   US$9nUUU'   M"     SUS%'   U US&'   U$ UW;  a  [        SU-   5      eUU;  a  [        W[        U 5      -   S-   U-   5      eUUS'   UR'                  XS'.5        U$ )(a  This is a helper function to dsolve and pdsolve in the ode
and pde modules.

If the hint provided to the function is "default", then a dict with
the following keys are returned

'func'    - It provides the function for which the differential equation
            has to be solved. This is useful when the expression has
            more than one function in it.

'default' - The default key as returned by classifier functions in ode
            and pde.py

'hint'    - The hint given by the user for which the differential equation
            is to be solved. If the hint given by the user is 'default',
            then the value of 'hint' and 'default' is the same.

'order'   - The order of the function as returned by ode_order

'match'   - It returns the match as given by the classifier functions, for
            the default hint.

If the hint provided to the function is not "default" and is not in
('all', 'all_Integral', 'best'), then a dict with the above mentioned keys
is returned along with the keys which are returned when dict in
classify_ode or classify_pde is set True

If the hint given is in ('all', 'all_Integral', 'best'), then this function
returns a nested dict, with the keys, being the set of classified hints
returned by classifier functions, and the values being the dict of form
as mentioned above.

Key 'eq' is a common key to all the above mentioned hints which returns an
expression if eq given by user is an Equality.

See Also
========
classify_ode(ode.py)
classify_pde(pde.py)
NFtypexietax0r   node)classify_odeallhintszODE  pde)classify_pderA   zPDE pclassifyT)dicticsr;   r<   r>   r=   r   r8   r   defaultr4   orderzHint not recognized: ordered_hintsz does not match hint z, is not a solvable differential equation in solvez: Cannot solve )rH   r   simplifyr8   r=   rF   rJ   r4   r;   r<   r>   r:   )allall_Integralbest>   rJ   rI   rK   rO   r
   )1st_homogeneous_coeff_best1st_power_series	lie_group2nd_power_series_ordinary2nd_power_series_regular)
rH   r   r=   rM   r8   rF   r>   rJ   r4   r:   rN   r#   )r   r#   )r   r   lhsrhsr%   getsympy.solvers.oder@   rA   sympy.solvers.pderD   r   strNotImplementedError_desolver   r   removeremovesuffixupdate)r#   r   r   rH   rM   r8   kwargsr:   r;   r<   r=   termsr@   rA   
classifierstringdummyrD   hintsretdictgethintsiksols                           r$   r]   r]      s.   R "hVVbff_ t|r( ::fd#D	D	B
**U
C	D!	BJJsOEu}<!
	<!

 zz*d##2$CC
T.  

6%t /#VG_67 xDI$54t;<<//DI4EVc"g-0GG$NOO 7^q BHH3t9TV V &ego8I&ICPRG&STTyci0@8eGn!%	"23uY 	Y 
0	0u: EE>!::k**OOANN;$?@ V=OOA&V A21UY%uW~U1XTXZCGAJ  	X	04788	U	#b'),CCdJKK f	LL$)*Lr7   )Nr
   )NrI   NT)__doc__
sympy.corer   sympy.core.functionr   r   sympy.core.relationalr   sympy.core.symbolr   r%   r,   r]    r7   r$   <module>rr      s4   	  8 * "K\%NPKT Kr7   