
    Ed-                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZmZ ddlmZ dd
Zej        d	fdZej        d	fdZej        d	fdZej        d	fdZej        d	fdZej        d	fdZd	S )af  
Singularities
=============

This module implements algorithms for finding singularities for a function
and identifying types of functions.

The differential calculus methods in this module include methods to identify
the following function types in the given ``Interval``:
- Increasing
- Strictly Increasing
- Decreasing
- Strictly Decreasing
- Monotonic

    )Pow)S)Symbol)sympify)log)seccsccottancos)
filldedentNc                 6   ddl m} ||j        rt          j        nt          j        }	 t          j        }|                     t          t          t          t          gt                                        t                    D ]6}|j        j        rt"          |j        j        r| ||j        ||          z  }7|                     t(                    D ]}| ||j        d         ||          z  }|S # t"          $ r t#          t-          d                    w xY w)a  
    Find singularities of a given function.

    Parameters
    ==========

    expression : Expr
        The target function in which singularities need to be found.
    symbol : Symbol
        The symbol over the values of which the singularity in
        expression in being searched for.

    Returns
    =======

    Set
        A set of values for ``symbol`` for which ``expression`` has a
        singularity. An ``EmptySet`` is returned if ``expression`` has no
        singularities for any given value of ``Symbol``.

    Raises
    ======

    NotImplementedError
        Methods for determining the singularities of this function have
        not been developed.

    Notes
    =====

    This function does not find non-isolated singularities
    nor does it find branch points of the expression.

    Currently supported functions are:
        - univariate continuous (real or complex) functions

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Mathematical_singularity

    Examples
    ========

    >>> from sympy import singularities, Symbol, log
    >>> x = Symbol('x', real=True)
    >>> y = Symbol('y', real=False)
    >>> singularities(x**2 + x + 1, x)
    EmptySet
    >>> singularities(1/(x + 1), x)
    {-1}
    >>> singularities(1/(y**2 + 1), y)
    {-I, I}
    >>> singularities(1/(y**3 + 1), y)
    {-1, 1/2 - sqrt(3)*I/2, 1/2 + sqrt(3)*I/2}
    >>> singularities(log(x), x)
    {0}

    r   solvesetNzl
            Methods for determining the singularities
            of this function have not been developed.)sympy.solvers.solvesetr   is_realr   Reals	ComplexesEmptySetrewriter   r	   r
   r   r   atomsr   expis_infiniteNotImplementedErroris_negativebaser   argsr   )
expressionsymboldomainr   singsis         <lib/python3.11/site-packages/sympy/calculus/singularities.pysingularitiesr$      s0   x 0///// <"N;;
##S#sC$8#>>DDSII 	: 	:Au  *))u  :!&&&999!!#&& 	9 	9AXXafQi888EE ; ; ;!* .9 #: #: ; ; 	;;s   CC1 1'Dc                 d   ddl m} t          |           } | j        }|"t	          |          dk    rt          d          |p$|r|                                nt          d          }|                     |          } | ||          |t          j
                  }|                    |          S )a  
    Helper function for functions checking function monotonicity.

    Parameters
    ==========

    expression : Expr
        The target function which is being checked
    predicate : function
        The property being tested for. The function takes in an integer
        and returns a boolean. The integer input is the derivative and
        the boolean result should be true if the property is being held,
        and false otherwise.
    interval : Set, optional
        The range of values in which we are testing, defaults to all reals.
    symbol : Symbol, optional
        The symbol present in expression which gets varied over the given range.

    It returns a boolean indicating whether the interval in which
    the function's derivative satisfies given predicate is a superset
    of the given interval.

    Returns
    =======

    Boolean
        True if ``predicate`` is true for all the derivatives when ``symbol``
        is varied in ``range``, False otherwise.

    r   r   N   zKThe function has not yet been implemented for all multivariate expressions.x)r   r   r   free_symbolslenr   popr   diffr   r   	is_subset)	r   	predicateintervalr   r   freevariable
derivativepredicate_intervals	            r#   monotonicity_helperr3   p   s    > 0/////$$J"D t99q= 	%5  
 >=$((***&++H**J!))J"7"717KK0111    c                 (    t          | d ||          S )a  
    Return whether the function is increasing in the given interval.

    Parameters
    ==========

    expression : Expr
        The target function which is being checked.
    interval : Set, optional
        The range of values in which we are testing (defaults to set of
        all real numbers).
    symbol : Symbol, optional
        The symbol present in expression which gets varied over the given range.

    Returns
    =======

    Boolean
        True if ``expression`` is increasing (either strictly increasing or
        constant) in the given ``interval``, False otherwise.

    Examples
    ========

    >>> from sympy import is_increasing
    >>> from sympy.abc import x, y
    >>> from sympy import S, Interval, oo
    >>> is_increasing(x**3 - 3*x**2 + 4*x, S.Reals)
    True
    >>> is_increasing(-x**2, Interval(-oo, 0))
    True
    >>> is_increasing(-x**2, Interval(0, oo))
    False
    >>> is_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval(-2, 3))
    False
    >>> is_increasing(x**2 + y, Interval(1, 2), x)
    True

    c                     | dk    S Nr    r'   s    r#   <lambda>zis_increasing.<locals>.<lambda>   
    Q!V r4   r3   r   r.   r   s      r#   is_increasingr>      s    P z+;+;XvNNNr4   c                 (    t          | d ||          S )at  
    Return whether the function is strictly increasing in the given interval.

    Parameters
    ==========

    expression : Expr
        The target function which is being checked.
    interval : Set, optional
        The range of values in which we are testing (defaults to set of
        all real numbers).
    symbol : Symbol, optional
        The symbol present in expression which gets varied over the given range.

    Returns
    =======

    Boolean
        True if ``expression`` is strictly increasing in the given ``interval``,
        False otherwise.

    Examples
    ========

    >>> from sympy import is_strictly_increasing
    >>> from sympy.abc import x, y
    >>> from sympy import Interval, oo
    >>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.Ropen(-oo, -2))
    True
    >>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.Lopen(3, oo))
    True
    >>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.open(-2, 3))
    False
    >>> is_strictly_increasing(-x**2, Interval(0, oo))
    False
    >>> is_strictly_increasing(-x**2 + y, Interval(-oo, 0), x)
    False

    c                     | dk    S r7   r8   r9   s    r#   r:   z(is_strictly_increasing.<locals>.<lambda>   
    QU r4   r<   r=   s      r#   is_strictly_increasingrB          P z??HfMMMr4   c                 (    t          | d ||          S )a  
    Return whether the function is decreasing in the given interval.

    Parameters
    ==========

    expression : Expr
        The target function which is being checked.
    interval : Set, optional
        The range of values in which we are testing (defaults to set of
        all real numbers).
    symbol : Symbol, optional
        The symbol present in expression which gets varied over the given range.

    Returns
    =======

    Boolean
        True if ``expression`` is decreasing (either strictly decreasing or
        constant) in the given ``interval``, False otherwise.

    Examples
    ========

    >>> from sympy import is_decreasing
    >>> from sympy.abc import x, y
    >>> from sympy import S, Interval, oo
    >>> is_decreasing(1/(x**2 - 3*x), Interval.open(S(3)/2, 3))
    True
    >>> is_decreasing(1/(x**2 - 3*x), Interval.open(1.5, 3))
    True
    >>> is_decreasing(1/(x**2 - 3*x), Interval.Lopen(3, oo))
    True
    >>> is_decreasing(1/(x**2 - 3*x), Interval.Ropen(-oo, S(3)/2))
    False
    >>> is_decreasing(1/(x**2 - 3*x), Interval.Ropen(-oo, 1.5))
    False
    >>> is_decreasing(-x**2, Interval(-oo, 0))
    False
    >>> is_decreasing(-x**2 + y, Interval(-oo, 0), x)
    False

    c                     | dk    S r7   r8   r9   s    r#   r:   zis_decreasing.<locals>.<lambda>#  r;   r4   r<   r=   s      r#   is_decreasingrF      s    X z+;+;XvNNNr4   c                 (    t          | d ||          S )aZ  
    Return whether the function is strictly decreasing in the given interval.

    Parameters
    ==========

    expression : Expr
        The target function which is being checked.
    interval : Set, optional
        The range of values in which we are testing (defaults to set of
        all real numbers).
    symbol : Symbol, optional
        The symbol present in expression which gets varied over the given range.

    Returns
    =======

    Boolean
        True if ``expression`` is strictly decreasing in the given ``interval``,
        False otherwise.

    Examples
    ========

    >>> from sympy import is_strictly_decreasing
    >>> from sympy.abc import x, y
    >>> from sympy import S, Interval, oo
    >>> is_strictly_decreasing(1/(x**2 - 3*x), Interval.Lopen(3, oo))
    True
    >>> is_strictly_decreasing(1/(x**2 - 3*x), Interval.Ropen(-oo, S(3)/2))
    False
    >>> is_strictly_decreasing(1/(x**2 - 3*x), Interval.Ropen(-oo, 1.5))
    False
    >>> is_strictly_decreasing(-x**2, Interval(-oo, 0))
    False
    >>> is_strictly_decreasing(-x**2 + y, Interval(-oo, 0), x)
    False

    c                     | dk     S r7   r8   r9   s    r#   r:   z(is_strictly_decreasing.<locals>.<lambda>N  rA   r4   r<   r=   s      r#   is_strictly_decreasingrI   &  rC   r4   c                 R   ddl m} t          |           } | j        }|"t	          |          dk    rt          d          |p$|r|                                nt          d          } ||                     |          ||          }|	                    |          t          j        u S )a  
    Return whether the function is monotonic in the given interval.

    Parameters
    ==========

    expression : Expr
        The target function which is being checked.
    interval : Set, optional
        The range of values in which we are testing (defaults to set of
        all real numbers).
    symbol : Symbol, optional
        The symbol present in expression which gets varied over the given range.

    Returns
    =======

    Boolean
        True if ``expression`` is monotonic in the given ``interval``,
        False otherwise.

    Raises
    ======

    NotImplementedError
        Monotonicity check has not been implemented for the queried function.

    Examples
    ========

    >>> from sympy import is_monotonic
    >>> from sympy.abc import x, y
    >>> from sympy import S, Interval, oo
    >>> is_monotonic(1/(x**2 - 3*x), Interval.open(S(3)/2, 3))
    True
    >>> is_monotonic(1/(x**2 - 3*x), Interval.open(1.5, 3))
    True
    >>> is_monotonic(1/(x**2 - 3*x), Interval.Lopen(3, oo))
    True
    >>> is_monotonic(x**3 - 3*x**2 + 4*x, S.Reals)
    True
    >>> is_monotonic(-x**2, S.Reals)
    False
    >>> is_monotonic(x**2 + y + 1, Interval(1, 2), x)
    True

    r   r   Nr&   zKis_monotonic has not yet been implemented for all multivariate expressions.r'   )r   r   r   r(   r)   r   r*   r   r+   intersectionr   r   )r   r.   r   r   r/   r0   turning_pointss          r#   is_monotonicrM   Q  s    ` 0/////$$J"D 
#d))a- 
!1
 
 	

 >=$((***&++HXjooh778LLN  00AJ>>r4   )N)__doc__sympy.core.powerr   sympy.core.singletonr   sympy.core.symbolr   sympy.core.sympifyr   &sympy.functions.elementary.exponentialr   (sympy.functions.elementary.trigonometricr   r	   r
   r   r   sympy.utilities.miscr   r$   r   r3   r>   rB   rF   rI   rM   r8   r4   r#   <module>rV      s   " !           " " " " " " $ $ $ $ $ $ & & & & & & 6 6 6 6 6 6 L L L L L L L L L L L L L L + + + + + +M; M; M; M;j 9: .2 .2 .2 .2b ()wt (O (O (O (OV 12 (N (N (N (NV ()wt ,O ,O ,O ,O^ 12 (N (N (N (NV '(gd =? =? =? =? =? =?r4   