API: smoothmath.expression

class smoothmath.expression.Variable(name)

A variable.

>>> from smoothmath.expression import Variable
>>> Variable("x")
Variable("x")
Parameters:

name (str) – the variable’s name

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Constant(value)

A constant expression.

>>> from smoothmath.expression import Constant
>>> Constant(11)
Constant(11)
Parameters:

value (float) – the real number value of the constant

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Add(*args)

The sum of several expressions.

>>> from smoothmath import Point
>>> from smoothmath.expression import Variable, Add
>>> z = Add(Variable("w"), Variable("x"), Variable("y"))
>>> z.at(Point(w=1, x=2, y=3))
6.0
Parameters:

*args (Expression) – the expressions being added together

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Minus(left, right)

Subtraction.

>>> from smoothmath import Point
>>> from smoothmath.expression import Variable, Minus
>>> z = Minus(Variable("x"), Variable("y"))
>>> z.at(Point(x=7, y=2))
5.0
Parameters:
  • left (Expression) – the expression being subtracted from

  • right (Expression) – the expression being subtracted

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Negation(inner)

The opposite (negative) of an expression.

>>> from smoothmath.expression import Variable, Negation
>>> z = Negation(Variable("x"))
>>> z.at(7)
-7.0
Parameters:

inner (Expression) – the inner expression

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Multiply(*args)

The product of several expressions.

>>> from smoothmath import Point
>>> from smoothmath.expression import Variable, Multiply
>>> z = Multiply(Variable("w"), Variable("x"), Variable("y"))
>>> z.at(Point(w=1, x=2, y=3))
6.0
Parameters:

*args (Expression) – the expressions being multiplied together

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Divide(left, right)

Division.

>>> from smoothmath import Point
>>> from smoothmath.expression import Variable, Divide
>>> z = Divide(Variable("x"), Variable("y"))
>>> z.at(Point(x=1, y=2))
0.5

Dividing by zero will raise a DomainError.

Parameters:
at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Reciprocal(inner)

The reciprocal of an expression.

>>> from smoothmath.expression import Variable, Reciprocal
>>> z = Reciprocal(Variable("x"))
>>> z.at(10)
0.1

Taking the reciprocal of zero will raise a DomainError.

Parameters:

inner (Expression) – the expression we are taking the reciprocal of

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Power(left, right)

A power expression.

>>> from smoothmath import Point
>>> from smoothmath.expression import Variable, Power
>>> z = Power(Variable("x"), Variable("y"))
>>> z.at(Point(x=2, y=5))
32.0

Will raise a DomainError if the base is zero or negative. For an alternative that allows a negative base, see NthPower.

Parameters:
at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.NthPower(inner, n)

The nth power of an expression.

>>> from smoothmath.expression import Variable, NthPower
>>> z = NthPower(Variable("x"), n=2)
>>> z.at(3)
9.0
Parameters:
  • inner (Expression) – the expression being raised to the nth power

  • n (int) – the exponent, which must be an integer greater or equal to 1

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.NthRoot(inner, n)

The nth root of an expression.

>>> from smoothmath.expression import Variable, NthRoot
>>> z = NthRoot(Variable("x"), n=2)
>>> z.at(25)
5.0

Will raise a DomainError at zero unless n is one. Will raise a DomainError for negative values if n is even.

Parameters:
  • inner (Expression) – the expression we are taking the nth root of

  • n (int) – must be an integer greater or equal to 1

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Exponential(inner, base=2.718281828459045)

An exponential expression.

>>> from smoothmath.expression import Variable, Exponential
>>> z = Exponential(Variable("x"), base=2)
>>> z.at(3)
8.0
Parameters:
  • inner (Expression) – the exponent

  • base (float) – the base, as a positive real number

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Logarithm(inner, base=2.718281828459045)

A logarithmic expression.

>>> from smoothmath.expression import Variable, Logarithm
>>> z = Logarithm(Variable("x"), base=2)
>>> z.at(64)
6.0

Will raise a DomainError at zero or negative values.

Parameters:
  • inner (Expression) – the expression to take the logarithm of

  • base (float) – the base, as a positive real number other than one

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Cosine(inner)

The cosine of an expression.

>>> from smoothmath.expression import Variable, Cosine
>>> z = Cosine(Variable("theta"))
>>> z.at(0)
1.0
Parameters:

inner (Expression) – an expression representing an angle in radians

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float

class smoothmath.expression.Sine(inner)

The sine of an expression.

>>> from smoothmath.expression import Variable, Sine
>>> z = Sine(Variable("theta"))
>>> z.at(0)
0.0
Parameters:

inner (Expression) – an expression representing an angle in radians

at(point)

Evaluates the expression at a point.

Will raise an exception if the point parameter is a float and the expression has more than one variable.

Parameters:

point (Point | float) – where to evaluate

Return type:

float