qat.core.Variable

class qat.core.Variable(name, var_type=<class 'float'>)

Class for typed variables. Variables can be used in any python arithmetic expression to build an ArithExpression object.

Parameters
  • name (str) – the variable name

  • var_type (type) – the variable type. Default to float.

Note

For now, the var_type argument is simply ignored.

Warning

Variable with names that can be cast to numerical values are forbidden.

differentiate(other_var)

Differentiate a variable w.r.t. a variable.

from qat.core import Variable
a, b = Variable("a"), Variable("b")
print(a.differentiate("a"))
print(a.differentiate("b"))
1
0
Parameters

other_var (str) – a variable name

Returns

either 0 or 1

Return type

numbers.Number

get_variables()

Returns a single-element list containing the name of the variable .

to_thrift()

Generates a thrift RPN version of the expression. This is used to store the expression in a serializable format.

from qat.core import Variable
a, b = Variable("a"), Variable("b")
expr = a + b
print(expr)
print(expr.to_thrift())
(a + b)
+ a b