<commit_before>from sympy.solvers import solve
from sympy.solvers.solveset import solveset
from sympy.simplify import simplify
from sympy import S


def singularities(expr, sym):
    """
    Finds singularities for a function.
    Currently supported functions are:
    - univariate real rational functions

    Examples
    ========

    >>> from sympy.calculus.singularities import singularities
    >>> from sympy import Symbol
    >>> x = Symbol('x', real=True)
    >>> singularities(x**2 + x + 1, x)
    ()
    >>> singularities(1/(x + 1), x)
    (-1,)

    References
    ==========

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

    """
    if not expr.is_rational_function(sym):
        raise NotImplementedError("Algorithms finding singularities for"
                                  " non rational functions are not yet"
                                  " implemented")
    else:
        return tuple(sorted(solveset(simplify(1/expr), sym)))

###########################################################################
###################### DIFFERENTIAL CALCULUS METHODS ######################
###########################################################################


def is_increasing(f, interval):
    """
    Returns if a function is increasing or not, in the given
    `Interval`.

    Examples
    ========

    >>> from sympy.calculus.singularities import is_increasing
    >>> from sympy.abc import x
    >>> 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

    """
    if len(f.free_symbols) > 1:
        raise NotImplementedError
    symbol = f.free_symbols.pop()
    df = f.diff(symbol)
    df_pos_interval = solveset(df >= 0, symbol, domain=S.Reals)
    return interval.is_subset(df_pos_interval)


def is_strictly_increasing(f, interval):
    """
    Returns if a function is strictly increasing or not, in the given
    `Interval`.

    Examples
    ========

    >>> from sympy.calculus.singularities import is_strictly_increasing
    >>> from sympy.abc import x
    >>> from sympy import S, 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<commit_msg>`df_pos_interval` -> `df_nonneg_interval`<commit_after>from sympy.solvers import solve
from sympy.solvers.solveset import solveset
from sympy.simplify import simplify
from sympy import S


def singularities(expr, sym):
    """
    Finds singularities for a function.
    Currently supported functions are:
    - univariate real rational functions

    Examples
    ========

    >>> from sympy.calculus.singularities import singularities
    >>> from sympy import Symbol
    >>> x = Symbol('x', real=True)
    >>> singularities(x**2 + x + 1, x)
    ()
    >>> singularities(1/(x + 1), x)
    (-1,)

    References
    ==========

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

    """
    if not expr.is_rational_function(sym):
        raise NotImplementedError("Algorithms finding singularities for"
                                  " non rational functions are not yet"
                                  " implemented")
    else:
        return tuple(sorted(solveset(simplify(1/expr), sym)))

###########################################################################
###################### DIFFERENTIAL CALCULUS METHODS ######################
###########################################################################


def is_increasing(f, interval):
    """
    Returns if a function is increasing or not, in the given
    `Interval`.

    Examples
    ========

    >>> from sympy.calculus.singularities import is_increasing
    >>> from sympy.abc import x
    >>> 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

    """
    if len(f.free_symbols) > 1:
        raise NotImplementedError
    symbol = f.free_symbols.pop()
    df = f.diff(symbol)
    df_nonneg_interval = solveset(df >= 0, symbol, domain=S.Reals)
    return interval.is_subset(df_nonneg_interval)


def is_strictly_increasing(f, interval):
    """
    Returns if a function is strictly increasing or not, in the given
    `Interval`.

    Examples
    ========

    >>> from sympy.calculus.singularities import is_strictly_increasing
    >>> from sympy.abc import x
    >>> from sympy import S, 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
{'fraction_non_alphanumeric': 0.20343039489429598, 'fraction_numerical': 0.017949740725967292, 'mean_word_length': 3.0772357723577235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 110, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5606445', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1470, 'n_words': 376}