�
��g � �V � d dl mZ d dlmZ d dlmZ d dlmZmZ ddl m
Z
mZ d� Zd� Z
d S )
� )�Mul)�S)�default_sort_key)�
DiracDelta� Heaviside� )�Integral� integratec �� � g }d}| � � � \ }}t |t �� � }|� |� � |D ]�}|j rWt |j t � � r=|� |� |j |j
dz
� � � � |j }|�-t |t � � r|� |� � r|}��|� |� � ��|s�g }|D ]�}t |t � � r+|� |� d|�� � � � �B|j rct |j t � � rI|� |� |j � d|�� � |j
� � � � ��|� |� � ��||k rt |� � � � }nd}d|fS |t |� fS )a� change_mul(node, x)
Rearranges the operands of a product, bringing to front any simple
DiracDelta expression.
Explanation
===========
If no simple DiracDelta expression was found, then all the DiracDelta
expressions are simplified (using DiracDelta.expand(diracdelta=True, wrt=x)).
Return: (dirac, new node)
Where:
o dirac is either a simple DiracDelta expression or None (if no simple
expression was found);
o new node is either a simplified DiracDelta expressions or None (if it
could not be simplified).
Examples
========
>>> from sympy import DiracDelta, cos
>>> from sympy.integrals.deltafunctions import change_mul
>>> from sympy.abc import x, y
>>> change_mul(x*y*DiracDelta(x)*cos(x), x)
(DiracDelta(x), x*y*cos(x))
>>> change_mul(x*y*DiracDelta(x**2 - 1)*cos(x), x)
(None, x*y*cos(x)*DiracDelta(x - 1)/2 + x*y*cos(x)*DiracDelta(x + 1)/2)
>>> change_mul(x*y*DiracDelta(cos(x))*cos(x), x)
(None, None)
See Also
========
sympy.functions.special.delta_functions.DiracDelta
deltaintegrate
N)�keyr T��
diracdelta�wrt)�args_cnc�sortedr �extend�is_Pow�
isinstance�baser �append�func�exp� is_simple�expandr ) �node�x�new_args�dirac�c�nc�sorted_args�arg�nnodes �n/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/integrals/deltafunctions.py�
change_mulr% s� � �N �H��E�
�M�M�O�O�E�A�r��� 0�1�1�1�K����r����� !� !���:� �*�S�X�z�:�:� ��O�O�C�H�H�S�X�s�w��{�;�;�<�<�<��(�C��=�j��j�9�9�=�c�m�m�A�>N�>N�=��E�E��O�O�C� � � � ��
���� %� %�C��#�z�*�*�
%�����
�
�d��
� B� B�C�C�C�C���
%�
�3�8�Z� @� @�
%�����������D�a��)P�)P�RU�RY� Z� Z�[�[�[�[�����$�$�$�$��{�"�"���N�)�)�+�+�E�E��E��e�}���3��>�"�"� c �R � | � t � � sdS | j t k r�| � d|�� � }|| k r�| � |� � r�t | j � � dk s| j d dk rt | j d � � S t | j d | j d dz
� � | j d � � � � � � z S �n�t ||� � }|S | j s| j �r�| � � � }| |k r+t ||� � }|�t |t � � s|S �nBt | |� � \ }}|s|rt ||� � }|S �nddlm} |� d|�� � }|j rt ||� � \ }}||z } ||j d |� � d } t |j � � dk rdn|j d }
d}|
dk r�t$ j |
z |� ||
� � � || � � z }|j r|
dz }
|dz
}n1|dk r|t || z
� � z S |t ||dz
� � z S |
dk ��t$ j S dS )a�
deltaintegrate(f, x)
Explanation
===========
The idea for integration is the following:
- If we are dealing with a DiracDelta expression, i.e. DiracDelta(g(x)),
we try to simplify it.
If we could simplify it, then we integrate the resulting expression.
We already know we can integrate a simplified expression, because only
simple DiracDelta expressions are involved.
If we couldn't simplify it, there are two cases:
1) The expression is a simple expression: we return the integral,
taking care if we are dealing with a Derivative or with a proper
DiracDelta.
2) The expression is not simple (i.e. DiracDelta(cos(x))): we can do
nothing at all.
- If the node is a multiplication node having a DiracDelta term:
First we expand it.
If the expansion did work, then we try to integrate the expansion.
If not, we try to extract a simple DiracDelta term, then we have two
cases:
1) We have a simple DiracDelta term, so we return the integral.
2) We didn't have a simple term, but we do have an expression with
simplified DiracDelta terms, so we integrate this expression.
Examples
========
>>> from sympy.abc import x, y, z
>>> from sympy.integrals.deltafunctions import deltaintegrate
>>> from sympy import sin, cos, DiracDelta
>>> deltaintegrate(x*sin(x)*cos(x)*DiracDelta(x - 1), x)
sin(1)*cos(1)*Heaviside(x - 1)
>>> deltaintegrate(y**2*DiracDelta(x - z)*DiracDelta(y - z), y)
z**2*DiracDelta(x - z)*Heaviside(y - z)
See Also
========
sympy.functions.special.delta_functions.DiracDelta
sympy.integrals.integrals.Integral
NTr
r r )�solve)�hasr r r r �len�argsr �as_poly�LCr
�is_Mulr r r r% �
sympy.solversr( r �NegativeOne�diff�subs�is_zero�Zero)
�fr �h�fh�g� deltaterm� rest_multr( �rest_mult_2�point�n�m�rs
r$ �deltaintegrater@ Q s� � �p
�5�5���� ��t� �v����
�H�H��!�H�,�,����6�6� �{�{�1�~�~�
2����K�K�1�$�$���q� �Q���$�Q�V�A�Y�/�/�/�&�q�v�a�y�!�&��)�a�-�@�@���q� �)�)�+�+�.�.�0�0�1� 2�
2� �1�a���B��I�
�� -�Q�X� -�
�H�H�J�J����6�6��1�a���B��~�j��X�&>�&>�~�� �� $.�a��#3�#3� �I�y�� #
�� �"�9�a�0�0�B��I�� 0�/�/�/�/�/�%�,�,��!�,�D�D� ��#� 6�-7� �1�-E�-E�*�I�{� )�+� 5�I���i�n�Q�/��3�3�A�6�� �i�n�-�-�q�0�0�Q�Q�i�n�Q�6G�����1�f�f��
�q�(�����1�)=�)=�)B�)B�1�e�)L�)L�L�A��y� 7��Q����Q������6�6�#$�Y�q�5�y�%9�%9�#9�9�#$�Z��!�A�#�%6�%6�#6�6� �1�f�f� �v�
��4r&