| Server IP : 93.86.61.54 / Your IP : 216.73.216.206 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/sympy/simplify/__pycache__/ |
Upload File : |
o
�8Vazv � @ s d Z ddlmZmZmZmZmZmZ ddlm Z ddl
mZmZ ddl
mZ ddlmZ ddlmZ ddlmZmZmZmZ d d
lmZ ejejfedfgZdd
� Zdd� Zdd� Zdd� Z dd� Z!G dd� d�Z"G dd� d�Z#dd� Z$d'dd�Z%d(d d!�Z& "d)d#d$�Z'd%d&� Z(dS )*z3 Tools for doing common subexpression elimination.
� )�Basic�Mul�Add�Pow�sympify�Symbol)�iterable)�Tuple�
OrderedSet)�factor_terms)�_coeff_isneg)�S)�numbered_symbols�sift�topological_sort�ordered� )�cse_optsNc sr t � �� g }t� �D ]\}\}}t� �D ]\}\}}||jv r&|�||f� qq
� fdd�ttt� ��|f�D �S )a( Sort replacements ``r`` so (k1, v1) appears before (k2, v2)
if k2 is in v1's free symbols. This orders items in the
way that cse returns its results (hence, in order to use the
replacements in a substitution option it would make sense
to reverse the order).
Examples
========
>>> from sympy.simplify.cse_main import reps_toposort
>>> from sympy.abc import x, y
>>> from sympy import Eq
>>> for l, r in reps_toposort([(x, y + 1), (y, 2)]):
... print(Eq(l, r))
...
Eq(y, 2)
Eq(x, y + 1)
c � g | ]}� | �qS � r ��.0�i��rr �9/usr/lib/python3/dist-packages/sympy/simplify/cse_main.py�
<listcomp>= � z!reps_toposort.<locals>.<listcomp>)r � enumerate�free_symbols�appendr �range�len)r �E�c1�k1�v1�c2�k2�v2r r r �
reps_toposort# s
��"r* c C s8 t |dd� �}| dd� |d D � } |d }t| �|gS )a� Move expressions that are in the form (symbol, expr) out of the
expressions and sort them into the replacements using the reps_toposort.
Examples
========
>>> from sympy.simplify.cse_main import cse_separate
>>> from sympy.abc import x, y, z
>>> from sympy import cos, exp, cse, Eq, symbols
>>> x0, x1 = symbols('x:2')
>>> eq = (x + 1 + exp((x + 1)/(y + 1)) + cos(y + 1))
>>> cse([eq, Eq(x, z + 1), z - 2], postprocess=cse_separate) in [
... [[(x0, y + 1), (x, z + 1), (x1, x + 1)],
... [x1 + exp(x1/x0) + cos(x0), z - 2]],
... [[(x1, y + 1), (x, z + 1), (x0, x + 1)],
... [x0 + exp(x0/x1) + cos(x1), z - 2]]]
...
True
c S s | j o| jjS �N)�is_Equality�lhs� is_Symbol)�wr r r �<lambda>T s zcse_separate.<locals>.<lambda>c S � g | ]}|j �qS r )�args)r r/ r r r r U � z cse_separate.<locals>.<listcomp>TF)r r* )r �e�dr r r �cse_separate@ s r6 c sD | s| � fS ddl m} t| � \��|dt� � �}t|��t���t���t���� �fdd�tt� ��D �� tt� ���fdd�d�� \� �t����� 7 �g }t��d }|dkr���� }�|j @ }|ru|�
d
d� t|td�D �� |t| �kr�|���� |f� n |��| |f� �|8 �|d 8 }|dks\|�
� ||fS )a�
Return tuples giving ``(a, b)`` where ``a`` is a symbol and ``b`` is
either an expression or None. The value of None is used when a
symbol is no longer needed for subsequent expressions.
Use of such output can reduce the memory footprint of lambdified
expressions that contain large, repeated subexpressions.
Examples
========
>>> from sympy import cse
>>> from sympy.simplify.cse_main import cse_release_variables
>>> from sympy.abc import x, y
>>> eqs = [(x + y - 1)**2, x, x + y, (x + y)/(2*x + 1) + (x + y - 1)**2, (2*x + 1)**(x + y)]
>>> defs, rvs = cse_release_variables(*cse(eqs))
>>> for i in defs:
... print(i)
...
(x0, x + y)
(x1, (x0 - 1)**2)
(x2, 2*x + 1)
(_3, x0/x2 + x1)
(_4, x2**x0)
(x2, None)
(_0, x1)
(x1, None)
(_2, x0)
(x0, None)
(_1, x)
>>> print(rvs)
(_0, _1, _2, _3, _4)
r )�symbolsz_:%dc s g | ]
}� | �| f�qS r r r )r4 �symsr r r � s z)cse_release_variables.<locals>.<listcomp>c s$ t ��fdd�| d j� @ D �� S )Nc s g | ]}� �� |� �� �qS r )�index� count_opsr )�p�sr r r � s �z;cse_release_variables.<locals>.<lambda>.<locals>.<listcomp>r )�sumr )�x)�in_user; r<