Nodes API¶
Warning
In this version of Oraqle, the API is still prone to changes. Paths and names can change between any version.
Boolean operations¶
AND operation
And
¶
Bases: CommutativeUniqueReducibleNode
Performs an AND operation over several operands. The user must ensure that the operands are Booleans.
__init__(operands, gf)
¶
Initialize a node with the given set as the operands. None of the operands can be a constant.
apply_function_to_operands(function)
¶
replace_operands_using_function(function)
¶
evaluate(actual_inputs)
¶
clear_cache(already_cleared)
¶
Clears any cached values of the node and any of its operands.
to_graph(graph_builder)
¶
Adds this node to the graph as well as its edges.
Returns:

int
–The identifier of this
Node
in theDotFile
.
__hash__()
¶
is_equivalent(other)
¶
eliminate_common_subexpressions(terms)
¶
Eliminates duplicate subexpressions that are equivalent (as defined by a node's __eq__
and __hash__
method).
Returns:

Node
–A
Node
that must replace the previous expression.
count_parents()
¶
Counts the total number of nodes in this subcircuit.
reset_parent_count()
¶
Resets the cached number of nodes in this subcircuit to 0.
arithmetize(strategy)
¶
arithmetize_depth_aware(cost_of_squaring)
¶
to_arithmetic()
¶
Outputs this node's equivalent ArithmeticNode. Errors if this node does not have a direct arithmetic equivalent.
Raises:

Exception
–If there is no direct arithmetic equivalent.
add(other, flatten=True)
¶
Performs a summation between self
and other
, possibly flattening any sums.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Sum
node or aConstant
representing self & other.
__add__(other)
¶
__radd__(other)
¶
mul(other, flatten=True)
¶
Performs a multiplication between self
and other
, possibly flattening any products.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Product
node or aConstant
representing self & other.
__mul__(other)
¶
bool_or(other, flatten=True)
¶
Performs an OR operation between self
and other
, possibly flattening the result into an OR operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Or
node or aConstant
representing self & other.
__or__(other)
¶
bool_and(other, flatten=True)
¶
Performs an AND operation between self
and other
, possibly flattening the result into an AND operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
And
node or aConstant
representing self & other.
__and__(other)
¶
__lt__(other)
¶
__gt__(other)
¶
__le__(other)
¶
__ge__(other)
¶
__neg__()
¶
__invert__()
¶
__pow__(other)
¶
__sub__(other)
¶
__rsub__(other)
¶
__eq__(other)
¶
and_flatten(other)
¶
Performs an AND operation with other
, flattening the And
node if either of the two is also an And
and absorbing Constant
s.
Returns:

Node
–An
And
node containing the flattened AND operation, or aConstant
node.
OR operation
Or
¶
Bases: CommutativeUniqueReducibleNode
Performs an OR operation over several operands. The user must ensure that the operands are Booleans.
__init__(operands, gf)
¶
Initialize a node with the given set as the operands. None of the operands can be a constant.
apply_function_to_operands(function)
¶
replace_operands_using_function(function)
¶
evaluate(actual_inputs)
¶
clear_cache(already_cleared)
¶
Clears any cached values of the node and any of its operands.
to_graph(graph_builder)
¶
Adds this node to the graph as well as its edges.
Returns:

int
–The identifier of this
Node
in theDotFile
.
__hash__()
¶
is_equivalent(other)
¶
eliminate_common_subexpressions(terms)
¶
Eliminates duplicate subexpressions that are equivalent (as defined by a node's __eq__
and __hash__
method).
Returns:

Node
–A
Node
that must replace the previous expression.
count_parents()
¶
Counts the total number of nodes in this subcircuit.
reset_parent_count()
¶
Resets the cached number of nodes in this subcircuit to 0.
arithmetize(strategy)
¶
arithmetize_depth_aware(cost_of_squaring)
¶
to_arithmetic()
¶
Outputs this node's equivalent ArithmeticNode. Errors if this node does not have a direct arithmetic equivalent.
Raises:

Exception
–If there is no direct arithmetic equivalent.
add(other, flatten=True)
¶
Performs a summation between self
and other
, possibly flattening any sums.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Sum
node or aConstant
representing self & other.
__add__(other)
¶
__radd__(other)
¶
mul(other, flatten=True)
¶
Performs a multiplication between self
and other
, possibly flattening any products.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Product
node or aConstant
representing self & other.
__mul__(other)
¶
bool_or(other, flatten=True)
¶
Performs an OR operation between self
and other
, possibly flattening the result into an OR operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Or
node or aConstant
representing self & other.
__or__(other)
¶
bool_and(other, flatten=True)
¶
Performs an AND operation between self
and other
, possibly flattening the result into an AND operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
And
node or aConstant
representing self & other.
__and__(other)
¶
__lt__(other)
¶
__gt__(other)
¶
__le__(other)
¶
__ge__(other)
¶
__neg__()
¶
__invert__()
¶
__pow__(other)
¶
__sub__(other)
¶
__rsub__(other)
¶
__eq__(other)
¶
or_flatten(other)
¶
Performs an OR operation with other
, flattening the Or
node if either of the two is also an Or
and absorbing Constant
s.
Returns:

Node
–An
Or
node containing the flattened OR operation, or aConstant
node.
NEG operation
Neg
¶
Bases: UnivariateNode
A node that negates a Boolean input.
__init__(node, gf)
¶
Initialize a univariate node.
apply_function_to_operands(function)
¶
replace_operands_using_function(function)
¶
evaluate(actual_inputs)
¶
clear_cache(already_cleared)
¶
Clears any cached values of the node and any of its operands.
to_graph(graph_builder)
¶
__hash__()
¶
is_equivalent(other)
¶
Check whether self
is semantically equivalent to other
.
This function may have false negatives but it should never return false positives.
`True` if `self` is semantically equivalent to `other`, `False` if they are not or that they cannot be shown to be equivalent.
eliminate_common_subexpressions(terms)
¶
Eliminates duplicate subexpressions that are equivalent (as defined by a node's __eq__
and __hash__
method).
Returns:

Node
–A
Node
that must replace the previous expression.
count_parents()
¶
Counts the total number of nodes in this subcircuit.
reset_parent_count()
¶
Resets the cached number of nodes in this subcircuit to 0.
arithmetize(strategy)
¶
arithmetize_depth_aware(cost_of_squaring)
¶
to_arithmetic()
¶
Outputs this node's equivalent ArithmeticNode. Errors if this node does not have a direct arithmetic equivalent.
Raises:

Exception
–If there is no direct arithmetic equivalent.
add(other, flatten=True)
¶
Performs a summation between self
and other
, possibly flattening any sums.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Sum
node or aConstant
representing self & other.
__add__(other)
¶
__radd__(other)
¶
mul(other, flatten=True)
¶
Performs a multiplication between self
and other
, possibly flattening any products.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Product
node or aConstant
representing self & other.
__mul__(other)
¶
bool_or(other, flatten=True)
¶
Performs an OR operation between self
and other
, possibly flattening the result into an OR operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Or
node or aConstant
representing self & other.
__or__(other)
¶
bool_and(other, flatten=True)
¶
Performs an AND operation between self
and other
, possibly flattening the result into an AND operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
And
node or aConstant
representing self & other.
__and__(other)
¶
__lt__(other)
¶
__gt__(other)
¶
__le__(other)
¶
__ge__(other)
¶
__neg__()
¶
__invert__()
¶
__pow__(other)
¶
__sub__(other)
¶
__rsub__(other)
¶
__eq__(other)
¶
operands()
¶
set_operands(operands)
¶
operation(operands)
¶
Arithmetic operations¶
These operations are fundamental arithmetic operations, so they will stay the same when they are arithmetized.
Highlevel arithmetic operations¶
Subtraction
Subtraction
¶
Bases: NonCommutativeBinaryNode
Represents a subtraction, which can be arithmetized using addition and constantmultiplication.
__init__(left, right, gf)
¶
Initialize a Node that performs an operation between two operands that is not commutative.
apply_function_to_operands(function)
¶
replace_operands_using_function(function)
¶
evaluate(actual_inputs)
¶
clear_cache(already_cleared)
¶
Clears any cached values of the node and any of its operands.
to_graph(graph_builder)
¶
__hash__()
¶
is_equivalent(other)
¶
eliminate_common_subexpressions(terms)
¶
Eliminates duplicate subexpressions that are equivalent (as defined by a node's __eq__
and __hash__
method).
Returns:

Node
–A
Node
that must replace the previous expression.
count_parents()
¶
Counts the total number of nodes in this subcircuit.
reset_parent_count()
¶
Resets the cached number of nodes in this subcircuit to 0.
arithmetize(strategy)
¶
arithmetize_depth_aware(cost_of_squaring)
¶
to_arithmetic()
¶
Outputs this node's equivalent ArithmeticNode. Errors if this node does not have a direct arithmetic equivalent.
Raises:

Exception
–If there is no direct arithmetic equivalent.
add(other, flatten=True)
¶
Performs a summation between self
and other
, possibly flattening any sums.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Sum
node or aConstant
representing self & other.
__add__(other)
¶
__radd__(other)
¶
mul(other, flatten=True)
¶
Performs a multiplication between self
and other
, possibly flattening any products.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Product
node or aConstant
representing self & other.
__mul__(other)
¶
bool_or(other, flatten=True)
¶
Performs an OR operation between self
and other
, possibly flattening the result into an OR operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Or
node or aConstant
representing self & other.
__or__(other)
¶
bool_and(other, flatten=True)
¶
Performs an AND operation between self
and other
, possibly flattening the result into an AND operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
And
node or aConstant
representing self & other.
__and__(other)
¶
__lt__(other)
¶
__gt__(other)
¶
__le__(other)
¶
__ge__(other)
¶
__neg__()
¶
__invert__()
¶
__pow__(other)
¶
__sub__(other)
¶
__rsub__(other)
¶
__eq__(other)
¶
operands()
¶
set_operands(operands)
¶
operation(operands)
¶
Exponentiation
Power
¶
Bases: UnivariateNode
Represents an exponentiation: x ** constant.
apply_function_to_operands(function)
¶
replace_operands_using_function(function)
¶
evaluate(actual_inputs)
¶
clear_cache(already_cleared)
¶
Clears any cached values of the node and any of its operands.
to_graph(graph_builder)
¶
__hash__()
¶
is_equivalent(other)
¶
Check whether self
is semantically equivalent to other
.
This function may have false negatives but it should never return false positives.
`True` if `self` is semantically equivalent to `other`, `False` if they are not or that they cannot be shown to be equivalent.
eliminate_common_subexpressions(terms)
¶
Eliminates duplicate subexpressions that are equivalent (as defined by a node's __eq__
and __hash__
method).
Returns:

Node
–A
Node
that must replace the previous expression.
count_parents()
¶
Counts the total number of nodes in this subcircuit.
reset_parent_count()
¶
Resets the cached number of nodes in this subcircuit to 0.
arithmetize(strategy)
¶
arithmetize_depth_aware(cost_of_squaring)
¶
to_arithmetic()
¶
Outputs this node's equivalent ArithmeticNode. Errors if this node does not have a direct arithmetic equivalent.
Raises:

Exception
–If there is no direct arithmetic equivalent.
add(other, flatten=True)
¶
Performs a summation between self
and other
, possibly flattening any sums.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Sum
node or aConstant
representing self & other.
__add__(other)
¶
__radd__(other)
¶
mul(other, flatten=True)
¶
Performs a multiplication between self
and other
, possibly flattening any products.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Product
node or aConstant
representing self & other.
__mul__(other)
¶
bool_or(other, flatten=True)
¶
Performs an OR operation between self
and other
, possibly flattening the result into an OR operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Or
node or aConstant
representing self & other.
__or__(other)
¶
bool_and(other, flatten=True)
¶
Performs an AND operation between self
and other
, possibly flattening the result into an AND operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
And
node or aConstant
representing self & other.
__and__(other)
¶
__lt__(other)
¶
__gt__(other)
¶
__le__(other)
¶
__ge__(other)
¶
__neg__()
¶
__invert__()
¶
__pow__(other)
¶
__sub__(other)
¶
__rsub__(other)
¶
__eq__(other)
¶
operands()
¶
set_operands(operands)
¶
operation(operands)
¶
__init__(node, exponent, gf)
¶
Initialize a Power
node that exponentiates node
with exponent
.
Polynomial evaluation¶
Univariate polynomial evaluation
UnivariatePoly
¶
Bases: UnivariateNode
Evaluation of a univariate polynomial.
apply_function_to_operands(function)
¶
replace_operands_using_function(function)
¶
evaluate(actual_inputs)
¶
clear_cache(already_cleared)
¶
Clears any cached values of the node and any of its operands.
to_graph(graph_builder)
¶
__hash__()
¶
is_equivalent(other)
¶
Check whether self
is semantically equivalent to other
.
This function may have false negatives but it should never return false positives.
`True` if `self` is semantically equivalent to `other`, `False` if they are not or that they cannot be shown to be equivalent.
eliminate_common_subexpressions(terms)
¶
Eliminates duplicate subexpressions that are equivalent (as defined by a node's __eq__
and __hash__
method).
Returns:

Node
–A
Node
that must replace the previous expression.
count_parents()
¶
Counts the total number of nodes in this subcircuit.
reset_parent_count()
¶
Resets the cached number of nodes in this subcircuit to 0.
arithmetize(strategy)
¶
arithmetize_depth_aware(cost_of_squaring)
¶
to_arithmetic()
¶
Outputs this node's equivalent ArithmeticNode. Errors if this node does not have a direct arithmetic equivalent.
Raises:

Exception
–If there is no direct arithmetic equivalent.
add(other, flatten=True)
¶
Performs a summation between self
and other
, possibly flattening any sums.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Sum
node or aConstant
representing self & other.
__add__(other)
¶
__radd__(other)
¶
mul(other, flatten=True)
¶
Performs a multiplication between self
and other
, possibly flattening any products.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Product
node or aConstant
representing self & other.
__mul__(other)
¶
bool_or(other, flatten=True)
¶
Performs an OR operation between self
and other
, possibly flattening the result into an OR operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Or
node or aConstant
representing self & other.
__or__(other)
¶
bool_and(other, flatten=True)
¶
Performs an AND operation between self
and other
, possibly flattening the result into an AND operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
And
node or aConstant
representing self & other.
__and__(other)
¶
__lt__(other)
¶
__gt__(other)
¶
__le__(other)
¶
__ge__(other)
¶
__neg__()
¶
__invert__()
¶
__pow__(other)
¶
__sub__(other)
¶
__rsub__(other)
¶
__eq__(other)
¶
operands()
¶
set_operands(operands)
¶
operation(operands)
¶
__init__(node, coefficients, gf)
¶
Initialize a univariate polynomial with the given coefficients from least to highest order.
from_function(node, gf, function)
classmethod
¶
Interpolate a univariate polynomial for the given function.
Returns:¶
A UnivariatePoly whose coefficients compute the function
on all inputs.
arithmetize_custom(strategy)
¶
Compute an arithmetization along with a dictionary of precomputed powers.
Returns:¶
An arithmetization and a dictionary of previously computed powers.
arithmetize_depth_aware_custom(cost_of_squaring)
¶
Compute a depthaware arithmetization as well as a dictionary indexed by the depth of the nodes in the front. The dictionary stores precomputed powers.
Returns:¶
A CostParetoFront with the depthaware arithmetization and a dictionary indexed by the depth of the nodes in the front, returning a dictionary with previously computed powers.
Control flow¶
Ifelse statement
IfElse
¶
Bases: FixedNode
A node representing an ifelse clause.
apply_function_to_operands(function)
¶
replace_operands_using_function(function)
¶
evaluate(actual_inputs)
¶
clear_cache(already_cleared)
¶
Clears any cached values of the node and any of its operands.
to_graph(graph_builder)
¶
Adds this node to the graph as well as its edges.
Returns:

int
–The identifier of this
Node
in theDotFile
.
eliminate_common_subexpressions(terms)
¶
Eliminates duplicate subexpressions that are equivalent (as defined by a node's __eq__
and __hash__
method).
Returns:

Node
–A
Node
that must replace the previous expression.
count_parents()
¶
Counts the total number of nodes in this subcircuit.
reset_parent_count()
¶
Resets the cached number of nodes in this subcircuit to 0.
arithmetize(strategy)
¶
arithmetize_depth_aware(cost_of_squaring)
¶
to_arithmetic()
¶
Outputs this node's equivalent ArithmeticNode. Errors if this node does not have a direct arithmetic equivalent.
Raises:

Exception
–If there is no direct arithmetic equivalent.
add(other, flatten=True)
¶
Performs a summation between self
and other
, possibly flattening any sums.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Sum
node or aConstant
representing self & other.
__add__(other)
¶
__radd__(other)
¶
mul(other, flatten=True)
¶
Performs a multiplication between self
and other
, possibly flattening any products.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Product
node or aConstant
representing self & other.
__mul__(other)
¶
bool_or(other, flatten=True)
¶
Performs an OR operation between self
and other
, possibly flattening the result into an OR operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
Or
node or aConstant
representing self & other.
__or__(other)
¶
bool_and(other, flatten=True)
¶
Performs an AND operation between self
and other
, possibly flattening the result into an AND operation between many operands.
It is possible to disable flattening by setting flatten=False
.
Returns:

Node
–A possibly flattened
And
node or aConstant
representing self & other.
__and__(other)
¶
__lt__(other)
¶
__gt__(other)
¶
__le__(other)
¶
__ge__(other)
¶
__neg__()
¶
__invert__()
¶
__pow__(other)
¶
__sub__(other)
¶
__rsub__(other)
¶
__eq__(other)
¶
__init__(condition, positive, negative, gf)
¶
Initialize an ifelse node: If condition evaluates to true, then it outputs positive, otherwise it outputs negative.