LIMIT

This function computes the symbolic limit of an expression as a variable approaches a specified point.

For expression f(x), the limit is:

\lim_{x \to a} f(x)

One-sided behavior can be selected by direction to evaluate left-hand or right-hand limits.

Excel Usage

=LIMIT(expression, variable, point, direction)
  • expression (str, required): Expression whose limit is computed.
  • variable (str, optional, default: “x”): Variable name approaching the point.
  • point (float, optional, default: 0): Point the variable approaches.
  • direction (str, optional, default: “+”): Direction of approach, either + or -.

Returns (str): String representation of the symbolic limit value.

Example 1: Limit of sin(x)/x at zero

Inputs:

expression variable point direction
sin(x)/x x 0 +

Excel formula:

=LIMIT("sin(x)/x", "x", 0, "+")

Expected output:

"1"

Example 2: Right-hand reciprocal limit at zero

Inputs:

expression variable point direction
1/x x 0 +

Excel formula:

=LIMIT("1/x", "x", 0, "+")

Expected output:

"oo"

Example 3: Right-hand limit of rational expression

Inputs:

expression variable point direction
(x**2 - 1)/(x - 1) x 1 +

Excel formula:

=LIMIT("(x**2 - 1)/(x - 1)", "x", 1, "+")

Expected output:

"2"

Example 4: Left-hand limit of rational expression

Inputs:

expression variable point direction
(x**2 - 1)/(x - 1) x 1 -

Excel formula:

=LIMIT("(x**2 - 1)/(x - 1)", "x", 1, "-")

Expected output:

"2"

Python Code

from sympy import Symbol
from sympy import sympify
from sympy import limit as sympy_limit

def limit(expression, variable='x', point=0, direction='+'):
    """
    Compute the symbolic limit of an expression.

    See: https://docs.sympy.org/latest/modules/series/series.html#sympy.series.limits.limit

    This example function is provided as-is without any representation of accuracy.

    Args:
        expression (str): Expression whose limit is computed.
        variable (str, optional): Variable name approaching the point. Default is 'x'.
        point (float, optional): Point the variable approaches. Default is 0.
        direction (str, optional): Direction of approach, either + or -. Default is '+'.

    Returns:
        str: String representation of the symbolic limit value.
    """
    try:
        if direction not in ["+", "-"]:
            return "Error: direction must be '+' or '-'"

        variable_symbol = Symbol(variable)
        normalized_expression = expression.replace("^", "**")
        expr = sympify(normalized_expression)
        result = sympy_limit(expr, variable_symbol, point, dir=direction)
        return str(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Expression whose limit is computed.
Variable name approaching the point.
Point the variable approaches.
Direction of approach, either + or -.