Expressions

In case you create expressions using Python code you probably want to use the convenience function expr() instead of working with the classes provided here directly. Note that this function is still provisional, however, it provides a much more concise way of defining expressions. In any case, instead of constructing objects directly it is recommended to use the constructor functions documented bellow.

class momba.model.Expression[source]

Abstract base class for expressions.

abstract property children

The direct children of the expression.

traverse()[source]

Returns an iterator over the subexpressions.

property subexpressions

A set of subexpressions.

property is_sampling_free

Returns whether the expression is sampling-free.

property used_names

Returns a set of name expressions occuring in the expression.

momba.model.ensure_expr(value_or_expression)[source]

Takes a Python value or expression and returns an expression.

Implicitly converts floats, integers, and booleans to constant expressions.

Raises ConversionError if the conversion fails.

class momba.model.expressions.ConversionError[source]

Unable to convert the provided value.

Constructor Functions

momba.model.expressions.ite(condition, consequence, alternative)[source]

Constructs a conditional expression implicitly converting the arguments.

momba.model.expressions.logic_not(operand)[source]

Constructs a logical negation expression.

momba.model.expressions.logic_any(*expressions)[source]

Constructs a disjunction over the provided expressions.

Returns FALSE if there are no expressions.

momba.model.expressions.logic_or(*expressions)[source]

Constructs a disjunction over the provided expressions.

momba.model.expressions.logic_all(*expressions)[source]

Constructs a conjunction over the provided expressions.

Returns TRUE if there are no expressions.

momba.model.expressions.logic_and(*expressions)[source]

Constructs a conjunction over the provided expressions.

momba.model.expressions.logic_xor(*expressions)[source]

Constructs an exclusive disjunction over the provided expressions.

momba.model.expressions.logic_implies(left, right)[source]

Constructs a logical implication.

momba.model.expressions.logic_equiv(left, right)[source]

Constructs a logical equivalence.

momba.model.expressions.equals(left, right)[source]

Constructs an equality expression.

momba.model.expressions.not_equals(left, right)[source]

Constructs an inequality expression.

momba.model.expressions.less(left, right)[source]

Constructs a less than expression.

momba.model.expressions.less_or_equal(left, right)[source]

Constructs a less than or equal to expression.

momba.model.expressions.greater(left, right)[source]

Constructs a greater than expression.

momba.model.expressions.greater_or_equal(left, right)[source]

Constructs a greater than or equal to expression.

momba.model.expressions.add(left, right)[source]

Constructs an arithmetic addition expression.

momba.model.expressions.sub(left, right)[source]

Constructs an arithmetic substraction expression.

momba.model.expressions.mul(left, right)[source]

Constructs an arithmetic multiplication expression.

momba.model.expressions.mod(left, right)[source]

Constructs an euclidean remainder expression.

momba.model.expressions.real_div(left, right)[source]

Constructs a real-division expression.

momba.model.expressions.log(left, right)[source]

Constructs a logarithm expression.

momba.model.expressions.power(left, right)[source]

Constructs a power expression.

momba.model.expressions.minimum(left, right)[source]

Constructs a minimum expression.

momba.model.expressions.maximum(left, right)[source]

Constructs a maximum expression.

momba.model.expressions.floor_div(left, right)[source]

Constructs an euclidean division expression.

momba.model.expressions.floor(operand)[source]

Constructs a floor expression.

momba.model.expressions.ceil(operand)[source]

Constructs a ceil expression.

momba.model.expressions.absolute(operand)[source]

Constructs an absolute value expression.

momba.model.expressions.sgn(operand)[source]

Constructs a sign expression.

momba.model.expressions.trunc(operand)[source]

Constructs a truncate expression.

momba.model.expressions.name(identifier)[source]

Constructs a name expression.

Class Reference

class momba.model.expressions.BooleanConstant(boolean)[source]

A boolean constant.

boolean

The value of the boolean constant.

expressions.TRUE: momba.model.expressions.Expression = BooleanConstant(boolean=True)
expressions.FALSE: momba.model.expressions.Expression = BooleanConstant(boolean=False)
class momba.model.expressions.NumericConstant[source]

Abstract base class for numeric constants.

abstract property as_float

The numeric constant as a floating-point number.

Note that this may result in a loss of precision.

abstract property as_fraction

The numeric constant as a fraction.

Note that this may result in a loss of precision

class momba.model.expressions.IntegerConstant(integer)[source]

An integer constant.

integer

The value of the integer constant.

property as_float

The numeric constant as a floating-point number.

Note that this may result in a loss of precision.

property as_fraction

The numeric constant as a fraction.

Note that this may result in a loss of precision

class momba.model.expressions.NamedReal(value)[source]

An enum of named reals.

symbol

The mathematical symbol of the real.

float_value

A floating-point approximation of the real.

PI = ('π', 3.141592653589793)

The number π.

E = ('e', 2.718281828459045)

The number e.

class momba.model.expressions.RealConstant(real)[source]

A real constant.

real

The real (either NamedReal or a fraction).

property as_float

The numeric constant as a floating-point number.

Note that this may result in a loss of precision.

property as_fraction

The numeric constant as a fraction.

Note that this may result in a loss of precision

class momba.model.expressions.Name(identifier)[source]

A name expression.

identifier

The identifier.

class momba.model.expressions.BinaryExpression(operator, left, right)[source]

Abstract base class for binary expressions.

operator

The binary operator (BinaryOperator).

left

The left operand.

right

The right operand.

property children

The direct children of the expression.

class momba.model.expressions.Boolean(operator, left, right)[source]

A boolean binary expression.

operator

The boolean operator (BooleanOperator).

class momba.model.expressions.ArithmeticBinary(operator, left, right)[source]

An arithmetic binary expression.

operator

The arithmetic operator (ArithmeticBinaryOperator).

class momba.model.expressions.Equality(operator, left, right)[source]

An equality binary expression.

operator

The equality operator (EqualityOperator).

class momba.model.expressions.Comparison(operator, left, right)[source]

A comparison expression.

operator

The comparison operator (ComparisonOperator).

class momba.model.expressions.Conditional(condition, consequence, alternative)[source]

A ternary conditional expression.

condition

The condition.

consequence

The consequence to be evaluated if the condition is true.

alternative

The alternative to be evaluated if the condition is false.

property children

The direct children of the expression.

class momba.model.expressions.UnaryExpression(operator, operand)[source]

Base class of all unary expressions.

operator

The unary operator (UnaryOperator).

operand

The operand.

property children

The direct children of the expression.

class momba.model.expressions.ArithmeticUnary(operator, operand)[source]

An arithmetic unary expression.

operator

The arithmetic operator (ArithmeticUnaryOperator).

class momba.model.expressions.Not(operator, operand)[source]

Logical negation.

operator

The logical negation operator (NotOperator).

class momba.model.expressions.Sample(distribution, arguments)[source]

A sample expression.

distribution

The type of the distribution to sample from (DistributionType).

arguments

The arguments to the distribution.

property children

The direct children of the expression.

class momba.model.expressions.Selection(variable, condition)[source]

A non-deterministic selection expression.

variable

The identifier to select over.

condition

The condition that should be satisfied.

property children

The direct children of the expression.

class momba.model.expressions.Derivative(identifier)[source]

Derivative of a continuous variable.

identifier

The continuous variable.

property children

The direct children of the expression.

class momba.model.expressions.ArrayAccess(array, index)[source]

An array access expression.

array

The array to access.

index

The index where to access the array.

property children

The direct children of the expression.

class momba.model.expressions.ArrayValue(elements)[source]

An array value expression.

elements

The elements of the array to construct.

property children

The direct children of the expression.

class momba.model.expressions.ArrayConstructor(variable, length, expression)[source]

An array constructor expression.

variable

The identifier to range over.

length

The length of the array.

expression

The expression to compute the elements of the array.

property children

The direct children of the expression.

class momba.model.expressions.Trigonometric(operator, operand)[source]

A trigonometric expression.

operator

The trigonometric function to apply (TrigonometricFunction).

Operators

class momba.model.operators.Operator(symbol)[source]

The base class of all operators.

symbol

Symbol associated with the operator.

class momba.model.operators.BinaryOperator(symbol)[source]

Base class for all binary operators.

class momba.model.operators.BooleanOperator(value)[source]

An enum of boolean operators.

AND = ('∧', <function BooleanOperator.<lambda>>)

Logical conjunction.

OR = ('∨', <function BooleanOperator.<lambda>>)

Logical disjunction.

IMPLY = ('⇒', <function BooleanOperator.<lambda>>)

Logical implication.

XOR = ('⊕', <function BooleanOperator.<lambda>>)

Logical exclusive disjunction.

EQUIV = ('⇔', <function BooleanOperator.<lambda>>)

Logical equivalence.

class momba.model.operators.ArithmeticBinaryOperator(value)[source]

An enum of arithmetic binary operators.

ADD = ('+', <function ArithmeticBinaryOperator.<lambda>>)

Addition.

SUB = ('-', <function ArithmeticBinaryOperator.<lambda>>)

Substraction.

MUL = ('*', <function ArithmeticBinaryOperator.<lambda>>)

Multiplication.

MOD = ('%', <function ArithmeticBinaryOperator.<lambda>>)

Euclidean remainder.

REAL_DIV = ('/', <function ArithmeticBinaryOperator.<lambda>>)

Real devision.

LOG = ('log', <function ArithmeticBinaryOperator.<lambda>>)

Logarithm.

POW = ('pow', <function ArithmeticBinaryOperator.<lambda>>)

Power.

MIN = ('min', <function ArithmeticBinaryOperator.<lambda>>)

Minimum.

MAX = ('max', <function ArithmeticBinaryOperator.<lambda>>)

Maximum.

FLOOR_DIV = ('//', <function ArithmeticBinaryOperator.<lambda>>)

Euclidean division.

class momba.model.operators.EqualityOperator(value)[source]

An enum of equality operators.

EQ = ('=', <function EqualityOperator.<lambda>>)

Is equal.

NEQ = ('≠', <function EqualityOperator.<lambda>>)

Is not equal.

class momba.model.operators.ComparisonOperator(value)[source]

An enum of comparison operators.

LT = ('<', True, <function ComparisonOperator.<lambda>>)

Is less than.

LE = ('≤', False, <function ComparisonOperator.<lambda>>)

Is less than or equal to.

GE = ('≥', False, <function ComparisonOperator.<lambda>>)

Is greater than or equal to.

GT = ('>', True, <function ComparisonOperator.<lambda>>)

Is greater than.

class momba.model.operators.UnaryOperator(symbol)[source]

Base class for all unary operators.

class momba.model.operators.NotOperator(value)[source]

An enumeration.

NOT = '¬'

Logical negation.

class momba.model.operators.ArithmeticUnaryOperator(value)[source]

An enumeration.

CEIL = ('ceil', <function ArithmeticUnaryOperator.<lambda>>, <function ArithmeticUnaryOperator.<lambda>>)

Round up.

FLOOR = ('floor', <function ArithmeticUnaryOperator.<lambda>>, <function ArithmeticUnaryOperator.<lambda>>)

Round down.

ABS = ('abs', <function ArithmeticUnaryOperator.<lambda>>, <function ArithmeticUnaryOperator.<lambda>>)

Absolute value.

SGN = ('sgn', <function ArithmeticUnaryOperator.<lambda>>, <function ArithmeticUnaryOperator.<lambda>>)

Sign.

TRC = ('trc', <function ArithmeticUnaryOperator.<lambda>>, <function ArithmeticUnaryOperator.<lambda>>)

Truncate.

class momba.model.operators.MinMax(value)[source]

Minimum and maximum functions.

MIN = 'min'

Minimum.

MAX = 'max'

Maximum.

class momba.model.operators.Quantifier(value)[source]

Logical quantifier.

FORALL = '∀'

Universal quantifier.

EXISTS = '∃'

Existential quantifier.

class momba.model.operators.BinaryPathOperator(value)[source]

LTL binary path operators.

UNTIL = 'U'

Until.

WEAK_UNTIL = 'W'

Weak until.

RELEASE = 'R'

Release.

class momba.model.operators.UnaryPathOperator(value)[source]

LTL unary path operators.

EVENTUALLY = 'F'

Eventually.

GLOBALLY = 'G'

Globally.

class momba.model.operators.AggregationFunction(value)[source]

Aggregation functions.

MIN = ('min', {RealType()}, <function AggregationFunction.<lambda>>)

Minimum.

MAX = ('max', {RealType()}, <function AggregationFunction.<lambda>>)

Maximum.

SUM = ('sum', {RealType()}, <function AggregationFunction.<lambda>>)

Sum.

AVG = ('avg', {RealType()}, <function AggregationFunction.<lambda>>)

Average.

COUNT = ('count', {BoolType()}, <function AggregationFunction.<lambda>>)

Count.

EXISTS = ('∃', {BoolType()}, <function AggregationFunction.<lambda>>)

Exists.

FORALL = ('∀', {BoolType()}, <function AggregationFunction.<lambda>>)

For all.

ARGMIN = ('argmin', {RealType()}, <function AggregationFunction.<lambda>>)

Minimizing argument.

ARGMAX = ('argmax', {RealType()}, <function AggregationFunction.<lambda>>)

Maximizing argument.

VALUES = ('values', {RealType(), BoolType()}, <function AggregationFunction.<lambda>>)

Values.

class momba.model.operators.TrigonometricFunction(value)[source]

Trigonometric functions.

SIN = 'sin'

Sine.

COS = 'cos'

Cosine.

TAN = 'tan'

Tangent.

COT = 'cot'

Cotangent..

SEC = 'sec'

Secant.

CSC = 'csc'

Cosecant.

ARC_SIN = 'asin'

Inverse sine

ARC_COS = 'acos'

Inverse cosine.

ARC_TAN = 'atan'

Inverse tangent.

ARC_COT = 'acot'

Inverse cotangent.

ARC_SEC = 'asec'

Inverse secant.

ARC_CSC = 'acsc'

Inverse coscant.

Distributions

class momba.model.distributions.DistributionType(value)[source]

An enum of distribution type.

DISCRETE_UNIFORM = ('DiscreteUniform', (IntegerType(), IntegerType()), IntegerType())

Discrete uniform distribution.

BERNOULLI = ('Bernoulli', (RealType(),))

Bernoulli distribution.

BINOMIAL = ('Binomial', (RealType(),))

Binomial distribution.

NEGATIVE_BINOMIAL = ('NegativeBinomial', (RealType(), RealType()))

Negative binomial distribution.

POISSON = ('Poisson', (RealType(),))

Poisson distribution.

GEOMETRIC = ('Geometric', (RealType(),))

Geometric distribution.

HYPERGEOMETRIC = ('Hypergeometric', (IntegerType(), IntegerType(), IntegerType()))

Hypergeometric distribution.

CONWAY_MAXWELL_POISSON = ('ConwayMaxwellPoisson', (RealType(), RealType()))

Conway Maxwell Poisson distribution.

ZIPF = ('ZipF', (RealType(),))

ZipF distribution.

UNIFORM = ('Uniform', (RealType(), RealType()))

Uniform distribution.

NORMAL = ('Normal', (RealType(), RealType()))

Normal distribution.

LOG_NORMAL = ('LogNormal', (RealType(), RealType()))

Logarithmic normal distribution.

BETA = ('Beta', (RealType(), RealType()))

Beta distribution.

CAUCHY = ('Cauchy', (RealType(), RealType()))

Cauchy distribution.

CHI = ('Chi', (IntegerType(),))

Chi distribution.

CHI_SQUARED = ('ChiSquared', (IntegerType(),))

Chi squared distribution.

ERLANG = ('Erlang', (IntegerType(), RealType()))

Erlang distribution.

EXPONENTIAL = ('Exponential', (RealType(),))

Exponential distribution.

FISHER_SNEDECOR = ('FisherSnedecor', (RealType(), RealType()))

Fisher Snedecor distribution.

GAMMA = ('Gamma', (RealType(), RealType()))

Gamma distribution.

INVERSE_GAMMA = ('InverseGamma', (RealType(), RealType()))

Inverse gamma distribution.

LAPLACE = ('Laplace', (RealType(), RealType()))

Laplace distribution.

PARETO = ('Pareto', (RealType(), RealType()))

Pareto distribution.

RAYLEIGH = ('Rayleigh', (RealType(),))

Rayleigh distribution.

STABLE = ('Stable', (RealType(), RealType(), RealType(), RealType()))

Stable distribution.

STUDENT_T = ('StudentT', (RealType(), RealType(), RealType()))

StudentT distribution.

WEIBULL = ('Weibull', (RealType(), RealType()))

Weibull distribution.

TRIANGULAR = ('Triangular', (RealType(), RealType(), RealType()))

Triangular distribution.