�
��gE( � �Z � d Z ddlmZ ddlmZmZ ddlmZ ddlm Z dd�Z
d � Zddd�d
�ZdS )z�Utility functions for classifying and solving
ordinary and partial differential equations.
Contains
========
_preprocess
ode_order
_desolve
� )�Pow)�
Derivative�AppliedUndef)�Equality)�WildN� _Integralc �� ���� t | t � � r| j j r| j } | � t � � }�sY t � � j d� |D � � � }t |� � dk rt d| z � � �|� � � �t �j � � ���| �fS ���fd�|D � � }| �
|� � }|�fS )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.
c �B � g | ]}|� t � � ��S � )�atomsr )�.0�ds �e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/solvers/deutils.py�
<listcomp>z_preprocess.<locals>.<listcomp>P s$ � �D�D�D��a�g�g�l�3�3�D�D�D� � z5The function cannot be automatically detected for %s.Nc � �� g | ]Y}�� d � � r,|� �� � st |j � � �z �C||� � � f��ZS )r )�endswith�has�set� variables�doit)r
r �func�fvars�hints ���r r z_preprocess.<locals>.<listcomp>X sm �� � 5� 5� 5�a����{�1K�1K� 5�
�E�E�$�K�K�5��q�{�+�+�e�3�5�Q������M� 5� 5� 5r )�
isinstancer �exp�is_positive�baser r r �union�len�
ValueError�pop�args�subs)�exprr r �derivs�funcs�reps�eqr s `` @r �_preprocessr+ s ���� �t �$���� ��H�!� ��9�D�
�Z�Z�
�
#�
#�F�� ������D�D�V�D�D�D�E���u�:�:��?�?�� 1�37�8� 9� 9�
9��y�y�{�{���� �N�N�E��|��T�z��5� 5� 5� 5� 5� 5�6� 5� 5� 5�D�
���4���B�
�t�8�Or c � �� t d�g�� � }| � |� � rdS t | t � � rm| j d �k rt | j � � S | j d j }t | j � � }|r|t �fd�|D � � � � z
}|S | j r t �fd�| j D � � � � ndS )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 �8 �K � | ]}t |�� � V � �d S �N�� ode_order�r
�_r s �r � <genexpr>zode_order.<locals>.<genexpr>� s- �� � � �;�;��)�A�t�,�,�;�;�;�;�;�;r c 3 �8 �K � | ]}t |�� � V � �d S r0 r1 r3 s �r r5 zode_order.<locals>.<genexpr>� s- �� � � �9�9�!�9�Q��%�%�9�9�9�9�9�9r )r �matchr r r$ r! r �max)r&