Expression

This is a derived class from Parameter that can hold mathematical expressions. An Expression is automatically generated when using operators on Parameter or Expression.

>>> import perceval as pcvl
>>> a, b = pcvl.Parameter("a"), pcvl.Parameter("b")
>>> e = a + b
>>> e.spv
a + b
>>> a.set_value(1)
>>> b.set_value(2)
>>> float(e)
3.0

They can also be created manually to accept more general mathematical functions (using the sympy expression parsing)

>>> phi = pcvl.Parameter("phi")
>>> e = pcvl.Expression("cos(phi)", {phi})  # Declares phi as a sub-parameter. Equivalent to pcvl.E("cos(phi)", {phi})
>>> phi.set_value(0)
>>> float(e)
1.0
class perceval.utils.parameter.Expression(name, parameters)

Symbolic math expression This class allows arithmetic manipulation of the Parameter class.

Example:
>>> p_a = Parameter("A")
>>> p_b = Parameter("B")
>>> sum_ab = Expression("A**2 + B", {p_a, p_b})
>>> p_a.set_value(2)
>>> p_b.set_value(3)
>>> print(float(sum_ab))  # Prints 7.0
Parameters:
  • name (str) – string specifying equation, acts as name of Expression parameter.

  • parameters (set[Parameter]) – set of sub parameter instances used in the expression

property defined: bool

Return True if the parameter has a value (fixed or non fixed)

property fixed: bool

Return True if the parameter is fixed

property is_periodic: bool

Expressions are not considered periodic

property parameters: list[perceval.utils.parameter.Parameter]

Returns list of sub parameters in alphabetical order