API Reference

Functions

SymKit.CheckDivisionLimitsMethod
CheckDivisionLimits(expr::SymExpr, var::Sym)

Check for division by zero and compute left/right-handed limits at singularities.

Returns a dictionary with:

  • :Singularity::Bool - whether division by zero exists
  • :Singularities::Vector - list of singularity information
  • :LeftLimit - left-handed limit at each singularity
  • :RightLimit - right-handed limit at each singularity

Example: x = Sym(:x) expr = 1 / (x - 2) result = checkdivisionlimits(expr, x) # Returns info about singularity at x=2

source
SymKit.DenominatorMethod
Denominator(expr::SymExpr)

Extract the denominator from a division expression. If expr is not a division, returns nothing.

Example: x = Sym(:x) expr = (x+1) / (x-1) denom = Denominator(expr) # Returns BinaryOp(:-, Sym(:x), Const(1))

source
SymKit.DerivativeMethod
Derivative(expr::SymExpr, var::Sym)

Compute the symbolic derivative of an expression with respect to a variable.

The function recursively applies differentiation rules and automatically simplifies the result. Supports basic operations (+, -, *, /, ^) and unary operations (-, sqrt, abs).

Arguments:

  • expr::SymExpr: The expression to differentiate
  • var::Sym or var::Symbol: The variable to differentiate with respect to

Returns:

  • A simplified SymExpr representing the derivative

Differentiation Rules:

  • Constant rule: d/dx(c) = 0
  • Variable rule: d/dx(x) = 1, d/dx(y) = 0 (if differentiating w.r.t. x)
  • Sum rule: d/dx(f + g) = f' + g'
  • Difference rule: d/dx(f - g) = f' - g'
  • Product rule: d/dx(fg) = f'g + f*g'
  • Quotient rule: d/dx(f/g) = (f'g - fg') / g²
  • Power rule: d/dx(f^n) = nf^(n-1)f' (for constant exponents)
  • Chain rules for unary operations:
    • d/dx(√f) = f' / (2√f)
    • d/dx(|f|) = f' * sgn(f)
    • d/dx(-f) = -f'

Examples:

x = Sym(:x)

# Simple polynomial
expr = x^2 + 3*x + 2
result = Derivative(expr, x)  # Returns BinaryOp(:+, BinaryOp(:+, BinaryOp(:*, ...), 3), 0)
# After simplification: 2*x + 3

# Quotient rule
expr = 1 / x
result = Derivative(expr, x)  # Returns -1/x²

# Product rule
expr = x^2 * (x + 1)
result = Derivative(expr, x)  # Returns 3*x² + 2*x
source
SymKit.DivisionBehaviorMethod
DivisionBehavior(expr::SymExpr, var::Sym)

Provide a human-readable description of division behavior at singularities.

Returns a string describing the limits and behavior.

Example: x = Sym(:x) expr = 1 / (x - 2) describedivisionbehavior(expr, x) # Returns: "Division by zero at x=2. Left limit: -∞, Right limit: +∞"

source
SymKit.LimitMethod
Limit(expr::SymExpr, var::Sym, point::Number; direction=:both, epsilon=1e-6)

Calculate the limit of an expression as a variable approaches a point.

Arguments:

  • expr: The expression to evaluate
  • var: The variable approaching the point
  • point: The point being approached
  • direction: :left (x→point⁻), :right (x→point⁺), or :both (check both)
  • epsilon: Step size for numerical approximation

Returns:

  • A symbolic value or :undefined, :inf, :-inf, :nan
  • For :both direction, returns (:leftresult, :rightresult)

Example: x = Sym(:x) expr = 1 / x limit(expr, x, 0; direction=:left) # Approaches -∞ limit(expr, x, 0; direction=:right) # Approaches +∞

source
SymKit.SimplifyMethod
Simplify(expr::SymExpr; ratio=1.7, max_iterations=100)

Simplify a symbolic expression using various simplification strategies.

The simplification process recursively applies simplification rules until a fixed point is reached or the maximum number of iterations is exceeded.

Arguments

  • expr::SymExpr: The expression to simplify
  • ratio::Float64: Maximum ratio of result complexity to input complexity (default: 1.7)
  • max_iterations::Int: Maximum number of simplification iterations (default: 100)

Returns

  • SymExpr: The simplified expression

Examples

x = Sym(:x)
expr = sin(asin(x))
simplified = Simplify(expr)  # Returns x

expr2 = log(exp(x))
simplified2 = Simplify(expr2)  # Returns x

expr3 = sin(x)^2 + cos(x)^2
simplified3 = Simplify(expr3)  # Returns Const(1)

Inspired by SymPy's simplify function, this implementation tries multiple simplification strategies and selects the result with the fewest operations, while ensuring the result is not too much more complex than the input.

source
SymKit.SingularitiesMethod
Singularities(expr::SymExpr, _var::Sym)

Find potential singularities (points where denominator = 0) in an expression. For polynomial denominators, tries to find roots.

Returns a vector of potential singularity points (as Numbers or symbols). For complex expressions, may return an empty vector or approximate solutions.

Example: x = Sym(:x) expr = 1 / (x - 2) singularities = Singularities(expr, x) # Returns [2] or similar

source

Index