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
- 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
- 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
- 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
- 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
- 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
- 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:
left (Expression) – the numerator
right (Expression) – the denominator
- 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
- 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
DomainErrorif the base is zero or negative. For an alternative that allows a negative base, seeNthPower.- Parameters:
left (Expression) – the base
right (Expression) – the exponent
- 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
- 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
DomainErrorat zero unless n is one. Will raise aDomainErrorfor 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
- 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
- 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
DomainErrorat 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
- 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
- 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