qat.pbo.VAR

class qat.pbo.VAR

This class is useful to create mathematical expressions. Each instance of VAR represent an abstract variable.

Static functions:
Member functions:
Operators:
  • add (+)

  • sub (-)

  • mul (*)

  • div (/ or //)

  • pow (**)

Example of use:
>>> # Init VAR objects
>>> x = VAR()
>>> y = VAR()
...
>>> # Math expression (x and y have no value)
>>> z = x + y
...
>>> # Setting value for x and y
>>> x.set_value(2)
>>> y.set_value(3)
...
>>> # The value of z in updated
>>> z
5
...
>>> # The value of z can change
>>> x.set_value(0)
>>> z
3
...
>>> # Lock the value of z
>>> val = z.eval()
>>> y.set_value(0)
...
>>> (val, z)
(3, 0)
classmethod add_function(fun)

Define a function which accept VAR objects

Parameters

fun (function) – function which do not accept VAR objects

Returns

the same function that could be applied on VAR

Return type

function

classmethod copy(*args)

Copy several VAR objects preserving links between them

Example of use:
>>> x = VAR()
>>> y = VAR()
>>> z = x + y
...
>>> x_cp, y_cp, z_cp = VAR.copy(x, y, z)
>>> # equivalent to z_cp = x_cp + y_cp
Parameters

*args (* VAR) – VAR objects to copy

Returns

copied VAR objects

Return type

tuple<VAR>

set_value(value)

Change the value of the VAR object

Parameters

value – value of the VAR

eval()

Return the evaluation of the expression

Returns

value of the VAR object

Return type

any

add_prohibited_value(value)

Add a prohibited value - if the VAR is NOT a formula, the method set_value() will refuse a value close to the given prohibited one

Parameters

value – the prohibited value

pop_prohibited_value(value)

Remove a prohibited value

Parameters

value – the prohibited value