circkit.arithmetic¶
- class circkit.arithmetic.Table(iterable=(), /)¶
Bases:
tuple
- class circkit.arithmetic.ArithmeticCircuit(*args, **kwargs)¶
Bases:
CircuitGeneric class for arithmetic circuits.
- class Operations¶
Bases:
OperationsClass gathering
Operation`s of :class:.ArithmeticCircuit`.- class ADD(*values, **kvalues)¶
Bases:
Binary- eval(a, b)¶
Evaluate the operation on given inputs (typically values, not nodes).
- class SUB(*values, **kvalues)¶
Bases:
Binary- eval(a, b)¶
Evaluate the operation on given inputs (typically values, not nodes).
- class MUL(*values, **kvalues)¶
Bases:
Binary- eval(a, b)¶
Evaluate the operation on given inputs (typically values, not nodes).
- class DIV(*values, **kvalues)¶
Bases:
Binary- eval(a, b)¶
Evaluate the operation on given inputs (typically values, not nodes).
- class EXP(*values, **kvalues)¶
Bases:
Unary- eval(a)¶
Evaluate the operation on given inputs (typically values, not nodes).
- class INV(*values, **kvalues)¶
Bases:
Unary- eval(a)¶
Evaluate the operation on given inputs (typically values, not nodes).
- class NEG(*values, **kvalues)¶
Bases:
Unary- eval(a)¶
Evaluate the operation on given inputs (typically values, not nodes).
- to_matrix(zero=0, one=1, n_tests=0)¶
Attempts to express the circuit as an affine map C(x) = A*x + b, where A is a matrix b is a vector, b = 0 when the map is linear
Done by evaluating the circuit at unit-vector inputs and at zero vector. Does not verify that the circuit is actually linear.
- Note: current implementation does batch execution using Array inputs
may be doing single calls is more reliable for some circuit variants.
Todo
add option for non-batch execution
- Parameters
zero (const) – constant representing zero
one (const) – constant representing one
- Returns
matrix A Array: vector b
- Return type
Matrix
- class circkit.arithmetic.OptArithmeticCircuit(*args, **kwargs)¶
Bases:
ArithmeticCircuitOptimized arithmetic circuits.
Optimizations include:
caching operations and nodes;
precomputing annihilator operations, e.g. a*0 = 0;
precomputing identity operations, e.g. a*1 = a, a+0 = 0;
precomputing constant operations;