| 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
�8Vas� � @ s� d dl mZ d dlmZ d dlmZmZmZmZm Z m
Z
mZmZm
Z
mZmZmZmZmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZmZ d dlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d d l(m)Z) d d
l*m+Z+ d dl,m-Z-m.Z.m/Z/m0Z0 d dl1m2Z2 d d
l3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> g dddfdd�Z?e+e)fZ@dd� ZAdd� ZBdd�dd�ZCdd � ZDd!aEd"d#� ZFd$d%� ZGd&d'� ZHd(d'� ZId)d'� ZJd*d+� ZKd9d,d-�ZLed9d.d/��ZMdd0�d1d2�ZNd3d4� ZOd5d6� ZPd:d7d8�ZQd!S );� )�defaultdict)�reduce)�sympify�Basic�S�Expr�
expand_mul�factor_terms�Mul�Dummy�igcd�
FunctionClass�Add�symbols�Wild�expand)�cacheit)�iterable�
SYMPY_INTS)� count_ops�_mexpand)�I�Integer) �sin�cos�exp�cosh�tanh�sinh�tan�cot�coth)�HyperbolicFunction)�TrigonometricFunction)�Poly�factor�cancel�parallel_poly_from_expr)�ZZ)�PolificationFailed)�groebner)�cse)�identity)�greedy)�debugF�grlexc
sP dd� �dd� ����fdd�}t d��| �tj��} �tjfg}t| ��� \}�zt|�g�\\}} }
W n ty@ | Y S w td|
j � ||
j |�\}��td |� td
�dt
��� td�dt
��� �sk| S t|��td
�� tdt
� �dt
� �� ddlm�
��r| jt���| j �� �rt|�� d�j�� }g }|�� D ]m\}
}tt|�g�d j ��d}|r�d}|D ]!}t|�}��|j �s�|jt|j ����� s�d}��|�� j � q�|s��fdd��D �}�fdd�� jD �}|�tdd� t�|
�D �� �
|� |�|� t|d��|� � q�t|� S �
| t
� ���� � t|d��|�S )a
Simplify trigonometric expressions using a groebner basis algorithm.
Explanation
===========
This routine takes a fraction involving trigonometric or hyperbolic
expressions, and tries to simplify it. The primary metric is the
total degree. Some attempts are made to choose the simplest possible
expression of the minimal degree, but this is non-rigorous, and also
very slow (see the ``quick=True`` option).
If ``polynomial`` is set to True, instead of simplifying numerator and
denominator together, this function just brings numerator and denominator
into a canonical form. This is much faster, but has potentially worse
results. However, if the input is a polynomial, then the result is
guaranteed to be an equivalent polynomial of minimal degree.
The most important option is hints. Its entries can be any of the
following:
- a natural number
- a function
- an iterable of the form (func, var1, var2, ...)
- anything else, interpreted as a generator
A number is used to indicate that the search space should be increased.
A function is used to indicate that said function is likely to occur in a
simplified expression.
An iterable is used indicate that func(var1 + var2 + ...) is likely to
occur in a simplified .
An additional generator also indicates that it is likely to occur.
(See examples below).
This routine carries out various computationally intensive algorithms.
The option ``quick=True`` can be used to suppress one particularly slow
step (at the expense of potentially more complicated results, but never at
the expense of increased total degree).
Examples
========
>>> from sympy.abc import x, y
>>> from sympy import sin, tan, cos, sinh, cosh, tanh
>>> from sympy.simplify.trigsimp import trigsimp_groebner
Suppose you want to simplify ``sin(x)*cos(x)``. Naively, nothing happens:
>>> ex = sin(x)*cos(x)
>>> trigsimp_groebner(ex)
sin(x)*cos(x)
This is because ``trigsimp_groebner`` only looks for a simplification
involving just ``sin(x)`` and ``cos(x)``. You can tell it to also try
``2*x`` by passing ``hints=[2]``:
>>> trigsimp_groebner(ex, hints=[2])
sin(2*x)/2
>>> trigsimp_groebner(sin(x)**2 - cos(x)**2, hints=[2])
-cos(2*x)
Increasing the search space this way can quickly become expensive. A much
faster way is to give a specific expression that is likely to occur:
>>> trigsimp_groebner(ex, hints=[sin(2*x)])
sin(2*x)/2
Hyperbolic expressions are similarly supported:
>>> trigsimp_groebner(sinh(2*x)/sinh(x))
2*cosh(x)
Note how no hints had to be passed, since the expression already involved
``2*x``.
The tangent function is also supported. You can either pass ``tan`` in the
hints, to indicate that tan should be tried whenever cosine or sine are,
or you can pass a specific generator:
>>> trigsimp_groebner(sin(x)/cos(x), hints=[tan])
tan(x)
>>> trigsimp_groebner(sinh(x)/cosh(x), hints=[tanh(x)])
tanh(x)
Finally, you can use the iterable form to suggest that angle sum formulae
should be tried:
>>> ex = (tan(x) + tan(y))/(1 - tan(x)*tan(y))
>>> trigsimp_groebner(ex, hints=[(tan, x, y)])
tan(x + y)
c
s� d}g g g }}}| D ]P� t � ttf�r� }qt � t�r#|�� � qt� �rW|�� d � dd� f� |�t� fdd�� dd� D �� d t� dd� � �g �d j � q|�� � q||||fS )z-Split hints into (n, funcs, iterables, gens).� r Nc s g | ]}� d |��qS �r � ��.0�x��er2 �9/usr/lib/python3/dist-packages/sympy/simplify/trigsimp.py�
<listcomp>� � z:trigsimp_groebner.<locals>.parse_hints.<locals>.<listcomp>)
�
isinstancer r r
�appendr �extendr'