7 py::class_<BooleanFunction> py_boolean_function(m,
10 A BooleanFunction represents a symbolic expression (e.g., ``A & B``) in order to abstract the (semantic) functionality of a single netlist gate (or even a complex subcircuit comprising multiple gates) in a formal manner. To this end, the ``BooleanFunction`` class is able to construct and display arbitrarily-nested expressions, enable symbolic simplification (e.g., simplify ``A & 0`` to ``0``), and translate Boolean functions to the SAT / SMT solver domain to use the solve constraint formulas.
13 py::enum_<BooleanFunction::Value> py_boolean_function_value(py_boolean_function, "Value", R
"(
14 Represents the logic value that a Boolean function operates on.
17 py_boolean_function_value.value("ZERO", BooleanFunction::Value::ZERO, R
"(Represents a logical 0.)")
18 .value("ONE", BooleanFunction::Value::ONE, R
"(Represents a logical 1.)")
19 .value("Z", BooleanFunction::Value::Z, R
"(Represents a high-impedance value.)")
20 .value("X", BooleanFunction::Value::X, R
"(Represents an undefined value.)")
24 Translates the Boolean function value into its string representation.
26 :returns: The value as a string.
30 py_boolean_function.def_static(
32 [](
const std::vector<BooleanFunction::Node>& nodes) -> std::optional<BooleanFunction> {
33 std::vector<BooleanFunction::Node> nodes_cloned;
34 for (
const auto& node : nodes)
36 nodes_cloned.push_back(node.clone());
46 log_error(
"python_context",
"{}", res.get_error().get());
52 Builds a Boolean function from a list of nodes.
54 :param list[hal_py.BooleanFunction.Node] nodes: The nodes to build the Boolean function from.
55 :returns: The Boolean function on success, None otherwise.
56 :rtype: hal_py.BooleanFunction or None
59 py_boolean_function.def_static(
61 [](
const std::vector<BooleanFunction::Value>& value,
u8 base = 2) -> std::optional<std::string> {
69 log_error(
"python_context",
"{}", res.get_error().get());
76 Convert the given bit-vector to its string representation in the given base.
78 :param list[hal_py.BooleanFunction.Value] value: The value as a bit-vector.
79 :param int base: The base that the values should be converted to. Valid values are 2 (default), 8, 10, and 16.
80 :returns: A string representing the values in the given base on success, None otherwise.
84 py_boolean_function.def_static(
86 [](
const std::vector<BooleanFunction::Value>& value) -> std::optional<u64> {
94 log_error(
"python_context",
"{}", res.get_error().get());
100 Convert the given bit-vector to its unsigned 64-bit integer representation.
102 :param list[hal_py.BooleanFunction.Value] value: The value as a bit-vector.
103 :returns: A 64-bit integer representing the values on success, None otherwise.
107 py_boolean_function.def(py::init<>(), R"(
108 Constructs an empty / invalid Boolean function.
111 py_boolean_function.def_static("Var", &
BooleanFunction::Var, py::arg(
"name"), py::arg(
"size") = 1, R
"(
112 Creates a multi-bit Boolean function of the given bit-size comprising only a variable of the specified name.
114 :param str name: The name of the variable.
115 :param int size: The bit-size. Defaults to 1.
116 :returns: The BooleanFunction.
117 :rtype: hal_py.BooleanFunction
120 py_boolean_function.def_static("Const", py::overload_cast<const BooleanFunction::Value&>(&
BooleanFunction::Const), py::arg(
"value"), R
"(
121 Creates a constant single-bit Boolean function from a value.
123 :param hal_py.BooleanFunction.Value value: The value.
124 :returns: The Boolean function.
125 :rtype: hal_py.BooleanFunction
128 py_boolean_function.def_static("Const", py::overload_cast<
const std::vector<BooleanFunction::Value>&>(&
BooleanFunction::Const), py::arg(
"value"), R
"(
129 Creates a constant multi-bit Boolean function from a list of values.
131 :param list[hal_py.BooleanFunction.Value] value: The list of values.
132 :returns: The Boolean function.
133 :rtype: hal_py.BooleanFunction
136 py_boolean_function.def_static("Const", py::overload_cast<u64, u16>(&
BooleanFunction::Const), py::arg(
"value"), py::arg(
"size"), R
"(
137 Creates a constant multi-bit Boolean function of the given bit-size from an integer value.
139 :param int value: The integer value.
140 :param int size: The bit-size.
141 :returns: The Boolean function.
142 :rtype: hal_py.BooleanFunction
146 Creates an index for a Boolean function of the given bit-size from an integer value.
148 :param int index: The integer value.
149 :param int size: The bit-size.
150 :returns: The Boolean function.
151 :rtype: hal_py.BooleanFunction
154 py_boolean_function.def_static(
164 log_error(
"python_context",
"{}", res.get_error().get());
172 Joins two Boolean functions by applying an AND operation.
173 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
175 :param hal_py.BooleanFunction p0: First Boolean function.
176 :param hal_py.BooleanFunction p1: Second Boolean function.
177 :param int size: Bit-size of the operation.
178 :returns: The joined Boolean function on success, None otherwise.
179 :rtype: hal_py.BooleanFunction or None
182 py_boolean_function.def_static(
192 log_error(
"python_context",
"{}", res.get_error().get());
200 Joins two Boolean functions by applying an OR operation.
201 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
203 :param hal_py.BooleanFunction p0: First Boolean function.
204 :param hal_py.BooleanFunction p1: Second Boolean function.
205 :param int size: Bit-size of the operation.
206 :returns: The joined Boolean function on success, None otherwise.
207 :rtype: hal_py.BooleanFunction or None
210 py_boolean_function.def_static(
220 log_error(
"python_context",
"{}", res.get_error().get());
227 Negates the given Boolean function.
228 Requires the Boolean function to be of the specified bit-size and produces a new Boolean function of the same bit-size.
230 :param hal_py.BooleanFunction p0: The Boolean function to negate.
231 :param int size: Bit-size of the operation.
232 :returns: The negated Boolean function on success, None otherwise.
233 :rtype: hal_py.BooleanFunction or None
236 py_boolean_function.def_static(
246 log_error(
"python_context",
"{}", res.get_error().get());
254 Joins two Boolean functions by applying an XOR operation.
255 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
257 :param hal_py.BooleanFunction p0: First Boolean function.
258 :param hal_py.BooleanFunction p1: Second Boolean function.
259 :param int size: Bit-size of the operation.
260 :returns: The joined Boolean function on success, None otherwise.
261 :rtype: hal_py.BooleanFunction or None
264 py_boolean_function.def_static(
274 log_error(
"python_context",
"{}", res.get_error().get());
282 Joins two Boolean functions by applying an ADD operation.
283 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
285 :param hal_py.BooleanFunction p0: First Boolean function.
286 :param hal_py.BooleanFunction p1: Second Boolean function.
287 :param int size: Bit-size of the operation.
288 :returns: The joined Boolean function on success, None otherwise.
289 :rtype: hal_py.BooleanFunction or None
292 py_boolean_function.def_static(
302 log_error(
"python_context",
"{}", res.get_error().get());
310 Joins two Boolean functions by applying an SUB operation.
311 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
313 :param hal_py.BooleanFunction p0: First Boolean function.
314 :param hal_py.BooleanFunction p1: Second Boolean function.
315 :param int size: Bit-size of the operation.
316 :returns: The joined Boolean function on success, None otherwise.
317 :rtype: hal_py.BooleanFunction or None
320 py_boolean_function.def_static(
330 log_error(
"python_context",
"{}", res.get_error().get());
338 Joins two Boolean functions by applying an MUL operation.
339 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
341 :param hal_py.BooleanFunction p0: First Boolean function.
342 :param hal_py.BooleanFunction p1: Second Boolean function.
343 :param int size: Bit-size of the operation.
344 :returns: The joined Boolean function on success, None otherwise.
345 :rtype: hal_py.BooleanFunction or None
348 py_boolean_function.def_static(
358 log_error(
"python_context",
"{}", res.get_error().get());
366 Joins two Boolean functions by applying an SDIV operation.
367 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
369 :param hal_py.BooleanFunction p0: First Boolean function.
370 :param hal_py.BooleanFunction p1: Second Boolean function.
371 :param int size: Bit-size of the operation.
372 :returns: The joined Boolean function on success, None otherwise.
373 :rtype: hal_py.BooleanFunction or None
376 py_boolean_function.def_static(
386 log_error(
"python_context",
"{}", res.get_error().get());
394 Joins two Boolean functions by applying an UDIV operation.
395 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
397 :param hal_py.BooleanFunction p0: First Boolean function.
398 :param hal_py.BooleanFunction p1: Second Boolean function.
399 :param int size: Bit-size of the operation.
400 :returns: The joined Boolean function on success, None otherwise.
401 :rtype: hal_py.BooleanFunction or None
404 py_boolean_function.def_static(
414 log_error(
"python_context",
"{}", res.get_error().get());
422 Joins two Boolean functions by applying an SREM operation.
423 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
425 :param hal_py.BooleanFunction p0: First Boolean function.
426 :param hal_py.BooleanFunction p1: Second Boolean function.
427 :param int size: Bit-size of the operation.
428 :returns: The joined Boolean function on success, None otherwise.
429 :rtype: hal_py.BooleanFunction or None
432 py_boolean_function.def_static(
442 log_error(
"python_context",
"{}", res.get_error().get());
450 Joins two Boolean functions by applying an UREM operation.
451 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
453 :param hal_py.BooleanFunction p0: First Boolean function.
454 :param hal_py.BooleanFunction p1: Second Boolean function.
455 :param int size: Bit-size of the operation.
456 :returns: The joined Boolean function on success, None otherwise.
457 :rtype: hal_py.BooleanFunction or None
460 py_boolean_function.def_static(
470 log_error(
"python_context",
"{}", res.get_error().get());
479 Returns the slice ``[i:j]`` of a Boolean function specified by a start index ``i`` and an end index ``j`` beginning at 0.
480 Note that slice ``[i:j]`` includes positions ``i`` and ``j`` as well.
482 :param hal_py.BooleanFunction p0: Boolean function to slice.
483 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding start index ``i``.
484 :param hal_py.BooleanFunction p2: Boolean function of type ``Index`` encoding end index ``j``.
485 :param int size: Bit-size of the resulting Boolean function slice, i.e., ``j - i + 1``.
486 :returns: The Boolean function slice on success, None otherwise.
487 :rtype: hal_py.BooleanFunction or None
490 py_boolean_function.def_static(
500 log_error(
"python_context",
"{}", res.get_error().get());
508 Concatenates two Boolean functions of bit-sizes ``n`` and ``m`` to form a single Boolean function of bit-size ``n + m``.
510 :param hal_py.BooleanFunction p0: First Boolean function (MSBs).
511 :param hal_py.BooleanFunction p1: Second Boolean function (LSBs).
512 :param int size: Bit-size of the concatenated Boolean function, i.e., ``n + m``.
513 :returns: The concatenated Boolean function on success, None otherwise.
514 :rtype: hal_py.BooleanFunction or None
517 py_boolean_function.def_static(
527 log_error(
"python_context",
"{}", res.get_error().get());
535 Zero-extends a Boolean function to the specified bit-size.
537 :param hal_py.BooleanFunction p0: Boolean function to extend.
538 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the bit-size of the zero-extended result.
539 :param int size: Bit-size of the zero-extended Boolean function.
540 :returns: The zero-extended Boolean function on success, None otherwise.
541 :rtype: hal_py.BooleanFunction or None
544 py_boolean_function.def_static(
554 log_error(
"python_context",
"{}", res.get_error().get());
562 Sign-extends a Boolean function to the specified bit-size.
564 :param hal_py.BooleanFunction p0: Boolean function to extend.
565 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the bit-size of the sign-extended result.
566 :param int size: Bit-size of the sign-extended Boolean function.
567 :returns: The sign-extended Boolean function on success, None otherwise.
568 :rtype: hal_py.BooleanFunction or None
571 py_boolean_function.def_static(
581 log_error(
"python_context",
"{}", res.get_error().get());
589 Shifts a Boolean function to the left by the specified number of bits.
591 :param hal_py.BooleanFunction p0: Boolean function to shift.
592 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to shift.
593 :param int size: Bit-size of the shifted Boolean function.
594 :returns: The shifted Boolean function on success, None otherwise.
595 :rtype: hal_py.BooleanFunction or None
598 py_boolean_function.def_static(
608 log_error(
"python_context",
"{}", res.get_error().get());
616 Logically shifts a Boolean function to the right by the specified number of bits.
618 :param hal_py.BooleanFunction p0: Boolean function to shift.
619 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to shift.
620 :param int size: Bit-size of the shifted Boolean function.
621 :returns: The shifted Boolean function on success, None otherwise.
622 :rtype: hal_py.BooleanFunction or None
625 py_boolean_function.def_static(
635 log_error(
"python_context",
"{}", res.get_error().get());
643 Arithmetically shifts a Boolean function to the right by the specified number of bits.
645 :param hal_py.BooleanFunction p0: Boolean function to shift.
646 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to shift.
647 :param int size: Bit-size of the shifted Boolean function.
648 :returns: The shifted Boolean function on success, None otherwise.
649 :rtype: hal_py.BooleanFunction or None
652 py_boolean_function.def_static(
662 log_error(
"python_context",
"{}", res.get_error().get());
670 Rotates a Boolean function to the left by the specified number of bits.
672 :param hal_py.BooleanFunction p0: Boolean function to rotate.
673 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to rotate.
674 :param int size: Bit-size of the rotated Boolean function.
675 :returns: The rotated Boolean function on success, None otherwise.
676 :rtype: hal_py.BooleanFunction or None
679 py_boolean_function.def_static(
689 log_error(
"python_context",
"{}", res.get_error().get());
697 Rotates a Boolean function to the right by the specified number of bits.
699 :param hal_py.BooleanFunction p0: Boolean function to rotate.
700 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to rotate.
701 :param int size: Bit-size of the rotated Boolean function.
702 :returns: The rotated Boolean function on success, None otherwise.
703 :rtype: hal_py.BooleanFunction or None
706 py_boolean_function.def_static(
716 log_error(
"python_context",
"{}", res.get_error().get());
724 Joins two Boolean functions by an equality check that produces a single-bit result.
726 :param hal_py.BooleanFunction p0: First Boolean function.
727 :param hal_py.BooleanFunction p1: Second Boolean function.
728 :param int size: Bit-size of the operation (always =1).
729 :returns: The joined Boolean function on success, None otherwise.
730 :rtype: hal_py.BooleanFunction or None
733 py_boolean_function.def_static(
743 log_error(
"python_context",
"{}", res.get_error().get());
751 Joins two Boolean functions by a signed less-than-equal check that produces a single-bit result.
753 :param hal_py.BooleanFunction p0: First Boolean function.
754 :param hal_py.BooleanFunction p1: Second Boolean function.
755 :param int size: Bit-size of the operation (always =1).
756 :returns: The joined Boolean function on success, None otherwise.
757 :rtype: hal_py.BooleanFunction or None
760 py_boolean_function.def_static(
770 log_error(
"python_context",
"{}", res.get_error().get());
778 Joins two Boolean functions by a signed less-than check that produces a single-bit result.
780 :param hal_py.BooleanFunction p0: First Boolean function.
781 :param hal_py.BooleanFunction p1: Second Boolean function.
782 :param int size: Bit-size of the operation (always =1).
783 :returns: The joined Boolean function on success, None otherwise.
784 :rtype: hal_py.BooleanFunction or None
787 py_boolean_function.def_static(
797 log_error(
"python_context",
"{}", res.get_error().get());
805 Joins two Boolean functions by an unsigned less-than-equal check that produces a single-bit result.
807 :param hal_py.BooleanFunction p0: First Boolean function.
808 :param hal_py.BooleanFunction p1: Second Boolean function.
809 :param int size: Bit-size of the operation (always =1).
810 :returns: The joined Boolean function on success, None otherwise.
811 :rtype: hal_py.BooleanFunction or None
814 py_boolean_function.def_static(
824 log_error(
"python_context",
"{}", res.get_error().get());
832 Joins two Boolean functions by an unsigned less-than check that produces a single-bit result.
834 :param hal_py.BooleanFunction p0: First Boolean function.
835 :param hal_py.BooleanFunction p1: Second Boolean function.
836 :param int size: Bit-size of the operation (always =1).
837 :returns: The joined Boolean function on success, None otherwise.
838 :rtype: hal_py.BooleanFunction or None
841 py_boolean_function.def_static(
851 log_error(
"python_context",
"{}", res.get_error().get());
860 Joins three Boolean functions by an if-then-else operation with p0 as the condition, p1 as true-case, and p2 as false-case.
861 Requires ``p1`` to be of bit-size 1 and both Boolean functions ``p1`` and ``p2`` to be of the same bit-size.
862 Produces a new Boolean function of the specified bit-size that must be equal to the size of ``p1`` and ``p2``.
864 :param hal_py.BooleanFunction p0: Boolean function condition.
865 :param hal_py.BooleanFunction p1: Boolean function for ``true``-case.
866 :param hal_py.BooleanFunction p1: Boolean function for ``false``-case.
867 :param int size: Bit-size of the operation, i.e., size of ``p1`` and ``p2``.
868 :returns: The joined Boolean function on success, None otherwise.
869 :rtype: hal_py.BooleanFunction or None
872 py_boolean_function.def(py::self & py::self, R"(
873 Joins two Boolean functions by an AND operation.
874 Requires both Boolean functions to be of the same bit-size.
876 **Warning:** fails if the Boolean functions have different bit-sizes.
878 :returns: The joined Boolean Bunction.
879 :rtype: hal_py.BooleanFunction
882 py_boolean_function.def(py::self &= py::self, R"(
883 Joins two Boolean functions by an AND operation in-place.
884 Requires both Boolean functions to be of the same bit-size.
886 **Warning:** fails if the Boolean functions have different bit-sizes.
888 :returns: The joined Boolean Bunction.
889 :rtype: hal_py.BooleanFunction
892 py_boolean_function.def(py::self | py::self, R"(
893 Joins two Boolean functions by an OR operation.
894 Requires both Boolean functions to be of the same bit-size.
896 **Warning:** fails if the Boolean functions have different bit-sizes.
898 :returns: The joined Boolean Bunction.
899 :rtype: hal_py.BooleanFunction
902 py_boolean_function.def(py::self |= py::self, R"(
903 Joins two Boolean functions by an OR operation in-place.
904 Requires both Boolean functions to be of the same bit-size.
906 **Warning:** fails if the Boolean functions have different bit-sizes.
908 :returns: The joined Boolean Bunction.
909 :rtype: hal_py.BooleanFunction
912 py_boolean_function.def(~py::self, R"(
913 Negates the Boolean function.
915 :returns: The negated Boolean function.
916 :rtype: hal_py.BooleanFunction
919 py_boolean_function.def(py::self ^ py::self, R"(
920 Joins two Boolean functions by an XOR operation.
921 Requires both Boolean functions to be of the same bit-size.
923 **Warning:** fails if the Boolean functions have different bit-sizes.
925 :returns: The joined Boolean Bunction.
926 :rtype: hal_py.BooleanFunction
929 py_boolean_function.def(py::self ^= py::self, R"(
930 Joins two Boolean functions by an XOR operation in-place.
931 Requires both Boolean functions to be of the same bit-size.
933 **Warning:** fails if the Boolean functions have different bit-sizes.
935 :returns: The joined Boolean Bunction.
936 :rtype: hal_py.BooleanFunction
939 py_boolean_function.def(py::self + py::self, R"(
940 Joins two Boolean functions by an ADD operation.
941 Requires both Boolean functions to be of the same bit-size.
943 **Warning:** fails if the Boolean functions have different bit-sizes.
945 :returns: The joined Boolean Bunction.
946 :rtype: hal_py.BooleanFunction
949 py_boolean_function.def(py::self += py::self, R"(
950 Joins two Boolean functions by an ADD operation in-place.
951 Requires both Boolean functions to be of the same bit-size.
953 **Warning:** fails if the Boolean functions have different bit-sizes.
955 :returns: The joined Boolean Bunction.
956 :rtype: hal_py.BooleanFunction
959 py_boolean_function.def(py::self - py::self, R"(
960 Joins two Boolean functions by an SUB operation.
961 Requires both Boolean functions to be of the same bit-size.
963 **Warning:** fails if the Boolean functions have different bit-sizes.
965 :returns: The joined Boolean Bunction.
966 :rtype: hal_py.BooleanFunction
969 py_boolean_function.def(py::self -= py::self, R"(
970 Joins two Boolean functions by an SUB operation in-place.
971 Requires both Boolean functions to be of the same bit-size.
973 **Warning:** fails if the Boolean functions have different bit-sizes.
975 :returns: The joined Boolean Bunction.
976 :rtype: hal_py.BooleanFunction
979 py_boolean_function.def(py::self * py::self, R"(
980 Joins two Boolean functions by an MUL operation.
981 Requires both Boolean functions to be of the same bit-size.
983 **Warning:* fails if the Boolean functions have different bit-sizes.
985 :returns: The joined Boolean Bunction.
986 :rtype: hal_py.BooleanFunction
989 py_boolean_function.def(py::self *= py::self, R"(
990 Joins two Boolean functions by an MUL operation in-place.
991 Requires both Boolean functions to be of the same bit-size.
993 **Warning:** fails if the Boolean functions have different bit-sizes.
995 :returns: The joined Boolean Bunction.
996 :rtype: hal_py.BooleanFunction
999 py_boolean_function.def(py::self == py::self, R"(
1000 Checks whether two Boolean functions are equal.
1002 :returns: True if both Boolean functions are equal, False otherwise.
1006 py_boolean_function.def(py::self != py::self, R"(
1007 Checks whether two Boolean functions are unequal.
1009 :returns: True if both Boolean functions are unequal, False otherwise.
1013 py_boolean_function.def(py::self < py::self, R"(
1014 Checks whether this Boolean function is 'smaller' than the ``other`` Boolean function.
1016 :returns: True if this Boolean function is 'smaller', False otherwise.
1021 Checks whether the Boolean function is empty.
1023 :returns: True if the Boolean function is empty, False otherwise.
1028 Clones the Boolean function.
1030 :returns: The cloned Boolean function.
1031 :rtype: hal_py.BooleanFunction
1035 The bit-size of the Boolean function.
1041 Returns the bit-size of the Boolean function.
1043 :returns: The bit-size of the Boolean function.
1048 Checks whether the top-level node of the Boolean function is of a specific type.
1050 :param int type: The type to check for.
1051 :returns: True if the node is of the given type, False otherwise.
1056 Checks whether the top-level node of the Boolean function is of type ``Variable`` and holds a specific variable name.
1058 :returns: True if the top-level node of the Boolean function is of type Variable, False otherwise.
1063 Checks whether the top-level node of the Boolean function is of type Variable and holds a specific variable name.
1065 :param int value: The variable name to check for.
1066 :returns: True if the top-level node of the Boolean function is of type Variable and holds the given variable name, False otherwise.
1070 py_boolean_function.def(
1071 "get_variable_name",
1073 auto res =
self.get_variable_name();
1080 log_error(
"python_context",
"{}", res.get_error().get());
1081 return std::nullopt;
1085 Get the variable name of the top-level node of the Boolean function of type Variable.
1087 :returns: The variable name on success, None otherwise.
1092 Checks whether the top-level node of the Boolean function is of type Constant.
1094 :returns: True if the top-level node of the Boolean function is of type Constant, False otherwise.
1099 Checks whether the top-level node of the Boolean function is of type Constant and holds a specific value.
1101 :param list[hal_py.BooleanFunction.Value] value: The constant value to check for.
1102 :returns: True if the top-level node of the Boolean function is of type Constant and holds the given value, False otherwise.
1107 Checks whether the top-level node of the Boolean function is of type Constant and holds a specific value.
1109 :param int value: The constant value to check for.
1110 :returns: True if the top-level node of the Boolean function is of type Constant and holds the given value, False otherwise.
1114 py_boolean_function.def(
1115 "get_constant_value",
1116 [](
const BooleanFunction&
self) -> std::optional<std::vector<BooleanFunction::Value>> {
1117 auto res =
self.get_constant_value();
1124 log_error(
"python_context",
"{}", res.get_error().get());
1125 return std::nullopt;
1129 Get the constant value of the top-level node of the Boolean function of type Constant as a list of ``hal_py.BooleanFunction.Value``.
1131 :returns: The constant value on success, None otherwise.
1132 :rtype: list[hal_py.BooleanFunction.Value] or None
1135 py_boolean_function.def(
1136 "get_constant_value_u64",
1138 auto res =
self.get_constant_value_u64();
1145 log_error(
"python_context",
"{}", res.get_error().get());
1146 return std::nullopt;
1150 Get the constant value of the top-level node of the Boolean function of type Constant as long as it has a size <= 64-bit.
1152 :returns: The constant value on success, None otherwise.
1157 Checks whether the top-level node of the Boolean function is of type Index.
1159 :returns: True if the top-level node of the Boolean function is of type Index, False otherwise.
1164 Checks whether the top-level node of the Boolean function is of type Index and holds a specific value.
1166 :param int value: The index value to check for.
1167 :returns: True if the top-level node of the Boolean function is of type Index and holds the given value, False otherwise.
1171 py_boolean_function.def(
1174 auto res =
self.get_index_value();
1181 log_error(
"python_context",
"{}", res.get_error().get());
1182 return std::nullopt;
1186 Get the index value of the top-level node of the Boolean function of type Index.
1188 :returns: The index value on success, None otherwise.
1193 The top-level node of the Boolean function.
1195 **Warning:** fails if the Boolean function is empty.
1197 :type: hal_py.BooleanFunction.Node
1201 Returns the top-level node of the Boolean function.
1203 **Warning:** fails if the Boolean function is empty.
1205 :returns: The top-level node.
1206 :rtype: hal_py.BooleanFunction.Node
1210 The number of nodes in the Boolean function.
1216 Returns the number of nodes in the Boolean function.
1218 :returns: The number of nodes.
1223 The reverse polish notation list of the Boolean function nodes.
1225 :type: list[hal_py.BooleanFunction.Node]
1229 Returns the reverse polish notation list of the Boolean function nodes.
1231 :returns: A list of nodes.
1232 :rtype: list[hal_py.BooleanFunction.Node]
1236 The parameter list of the top-level node of the Boolean function.
1238 :type: list[hal_py.BooleanFunction]
1242 Returns the parameter list of the top-level node of the Boolean function.
1244 :returns: A vector of Boolean functions.
1245 :rtype: list[hal_py.BooleanFunction]
1249 The set of variable names used by the Boolean function.
1255 Returns the set of variable names used by the Boolean function.
1257 :returns: A set of variable names.
1262 Translates the Boolean function into its string representation.
1264 :returns: The Boolean function as a string.
1268 py_boolean_function.def_static(
1278 log_error(
"python_context",
"{}", res.get_error().get());
1282 py::arg(
"expression"),
1284 Parses a Boolean function from a string expression.
1286 :param str expression: Boolean function string.
1287 :returns: The Boolean function on success, an empty Boolean function otherwise.
1288 :rtype: hal_py.BooleanFunction
1292 Simplifies the Boolean function.
1294 :returns: The simplified Boolean function.
1295 :rtype: hal_py.BooleanFunction
1298 py_boolean_function.def(
1299 "substitute", py::overload_cast<const std::string&, const std::string&>(&
BooleanFunction::substitute, py::const_), py::arg(
"old_variable_name"), py::arg(
"new_variable_name"), R
"(
1300 Substitute a variable name with another one, i.e., renames the variable.
1301 The operation is applied to all instances of the variable in the function.
1303 :param str old_variable_name: The old variable name to substitute.
1304 :param str new_variable_name: The new variable name.
1305 :returns: The resulting Boolean function.
1306 :rtype: hal_py.BooleanFunction
1309 py_boolean_function.def(
1312 auto res =
self.substitute(variable_name,
function);
1319 log_error(
"python_context",
"{}", res.get_error().get());
1320 return std::nullopt;
1323 py::arg(
"variable_name"),
1324 py::arg(
"function"),
1326 Substitute a variable with another Boolean function.
1327 The operation is applied to all instances of the variable in the function.
1329 :param str variable_name: The variable to substitute.
1330 :param hal_py.BooleanFunction function: The function replace the variable with.
1331 :returns: The resulting Boolean function on success, None otherwise.
1332 :rtype: hal_py.BooleanFunction or None
1335 py_boolean_function.def("substitute",
1337 py::arg(
"substitutions"),
1339 Substitute multiple variable names with different names at once, i.e., rename the variables.
1340 The operation is applied to all instances of the variable in the function.
1342 :param dict[str,str] substitutions: A dict from old variable names to new variable names.
1343 :returns: The resulting Boolean function.
1344 :rtype: hal_py.BooleanFunction
1347 py_boolean_function.def(
1349 [](
const BooleanFunction&
self,
const std::map<std::string, BooleanFunction>& substitutions) -> std::optional<BooleanFunction> {
1350 auto res =
self.substitute(substitutions);
1357 log_error(
"python_context",
"{}", res.get_error().get());
1358 return std::nullopt;
1361 py::arg(
"substitutions"),
1363 Substitute multiple variables with other boolean functions at once.
1364 The operation is applied to all instances of the variable in the function.
1366 :param dict substitutions: A map from the variable names to the function to replace the variable with.
1367 :returns: The resulting Boolean function on success, None otherwise.
1368 :rtype: hal_py.BooleanFunction or None
1371 py_boolean_function.def(
1373 [](
const BooleanFunction&
self,
const std::unordered_map<std::string, BooleanFunction::Value>& inputs) -> std::optional<BooleanFunction::Value> {
1374 auto res =
self.evaluate(inputs);
1381 log_error(
"python_context",
"{}", res.get_error().get());
1382 return std::nullopt;
1387 Evaluates a Boolean function comprising only single-bit variables using the given input values.
1389 :param dict[str,hal_py.BooleanFunction.Value] inputs: A dict from variable name to input value.
1390 :returns: The resulting value on success, None otherwise.
1391 :rtype: hal_py.BooleanFunction.Value or None
1394 py_boolean_function.def(
1396 [](
const BooleanFunction&
self,
const std::unordered_map<std::string, std::vector<BooleanFunction::Value>>& inputs) -> std::optional<std::vector<BooleanFunction::Value>> {
1397 auto res =
self.evaluate(inputs);
1404 log_error(
"python_context",
"{}", res.get_error().get());
1405 return std::nullopt;
1410 Evaluates a Boolean function comprising multi-bit variables using the given input values.
1412 :param dict[str,list[hal_py.BooleanFunction.Value]] inputs: A dict from variable name to a list of input values.
1413 :returns: A vector of values on success, None otherwise.
1414 :rtype: list[hal_py.BooleanFunction.Value] or None
1417 py_boolean_function.def(
1418 "compute_truth_table",
1419 [](
const BooleanFunction&
self,
const std::vector<std::string>& ordered_variables,
bool remove_unknown_variables) -> std::optional<std::vector<std::vector<BooleanFunction::Value>>> {
1420 auto res =
self.compute_truth_table(ordered_variables, remove_unknown_variables);
1427 log_error(
"python_context",
"{}", res.get_error().get());
1428 return std::nullopt;
1431 py::arg(
"ordered_variables") = std::vector<std::string>(),
1432 py::arg(
"remove_unknown_variables") =
false,
1434 Computes the truth table outputs for a Boolean function that comprises <= 10 single-bit variables.
1436 **Warning:** The generation of the truth table is exponential in the number of parameters.
1438 :param list[str] ordered_variables: A list describing the order of input variables used to generate the truth table. Defaults to an empty list.
1439 :param bool remove_unknown_variables: Set True to remove variables from the truth table that are not present within the Boolean function, False otherwise. Defaults to False.
1440 :returns: A list of values representing the truth table output on success, None otherwise.
1441 :rtype: list[list[hal_py.BooleanFunction.Value]] or None
1444 py_boolean_function.def(
1445 "get_truth_table_as_string",
1446 [](
const BooleanFunction&
self,
const std::vector<std::string>& ordered_variables, std::string function_name,
bool remove_unknown_variables) -> std::optional<std::string> {
1447 auto res =
self.get_truth_table_as_string(ordered_variables, function_name, remove_unknown_variables);
1454 log_error(
"python_context",
"{}", res.get_error().get());
1455 return std::nullopt;
1458 py::arg(
"ordered_variables") = std::vector<std::string>(),
1459 py::arg(
"function_name") = std::string(
""),
1460 py::arg(
"remove_unknown_variables") =
false,
1462 Prints the truth table for a Boolean function that comprises <= 10 single-bit variables.
1464 **Warning:** The generation of the truth table is exponential in the number of parameters.
1466 :param list[str] ordered_variables: A list describing the order of input variables used to generate the truth table. Defaults to an empty list.
1467 :param str function_name: The name of the Boolean function to be printed as header of the output columns.
1468 :param bool remove_unknown_variables: Set True to remove variables from the truth table that are not present within the Boolean function, False otherwise. Defaults to False.
1469 :returns: A string representing the truth table on success, None otherwise.
1473 py::class_<BooleanFunction::Node> py_boolean_function_node(py_boolean_function, "Node", R
"(
1474 Node refers to an abstract syntax tree node of a Boolean function. A node is an abstract base class for either an operation (e.g., AND, XOR) or an operand (e.g., a signal name variable).
1478 The type of the node.
1484 The bit-size of the node.
1490 The (optional) constant value of the node.
1492 :type: list[hal_py.BooleanFunction.Value]
1496 The (optional) index value of the node.
1502 The (optional) variable name of the node.
1508 Constructs an 'operation' node.
1510 :param int type: The type of the operation.
1511 :param int size: The bit-size of the operation.
1513 :rtype: hal_py.BooleanFunction.Node
1517 Constructs a 'constant' node.
1519 :param list[hal_py.BooleanFunction.Value] value: The constant value of the node.
1521 :rtype: hal_py.BooleanFunction.Node
1525 Constructs an 'index' node.
1527 :param int value: The index value of the node.
1528 :param int size: The bit-size of the node.
1530 :rtype: hal_py.BooleanFunction.Node
1534 Constructs a 'variable' node.
1536 :param int value: The variable name of the node.
1537 :param int size: The bit-size of the node.
1539 :rtype: hal_py.BooleanFunction.Node
1542 py_boolean_function_node.def(py::self == py::self, R"(
1543 Checks whether two Boolean function nodes are equal.
1545 :returns: True if both Boolean function nodes are equal, False otherwise.
1549 py_boolean_function_node.def(py::self != py::self, R"(
1550 Checks whether two Boolean function nodes are unequal.
1552 :returns: True if both Boolean function nodes are unequal, False otherwise.
1556 py_boolean_function_node.def(py::self < py::self, R"(
1557 Checks whether this Boolean function node is 'smaller' than the ``other`` Boolean function node.
1559 :returns: True if this Boolean function node is 'smaller', False otherwise.
1564 Clones the Boolean function node.
1566 :returns: The cloned Boolean function node.
1567 :rtype: hal_py.BooleanFunction.Node
1571 Translates the Boolean function node into its string representation.
1573 :returns: The Boolean function node as a string.
1578 The arity of the Boolean function node, i.e., the number of parameters.
1584 Returns the arity of the Boolean function node, i.e., the number of parameters.
1586 :returns: The arity.
1591 Returns the arity for a Boolean function node of the given type, i.e., the number of parameters.
1593 :returns: The arity.
1598 Checks whether the Boolean function node is of a specific type.
1600 :param int type: The type to check for.
1601 :returns: True if the node is of the given type, False otherwise.
1606 Checks whether the Boolean function node is of type Constant.
1608 :returns: True if the Boolean function node is of type Constant, False otherwise.
1613 Checks whether the Boolean function node is of type Constant and holds a specific value.
1615 :param list[hal_py.BooleanFunction.Value] value: The value to check for.
1616 :returns: True if the Boolean function node is of type Constant and holds the given value, False otherwise.
1621 Checks whether the Boolean function node is of type Constant and holds a specific value.
1623 :param int value: The value to check for.
1624 :returns: True if the Boolean function node is of type Constant and holds the given value, False otherwise.
1628 py_boolean_function_node.def(
1629 "get_constant_value",
1631 if (
const auto res =
self.get_constant_value(); res.is_ok())
1637 log_error(
"python_context",
"could not get constant value:\n{}", res.get_error().get());
1638 return std::nullopt;
1642 Get the constant value of the node of type ``Constant`` as a list of ``hal_py.BooleanFunction.Value``.
1644 :returns: The constant value on success, None otherwise.
1645 :rtype: list[hal_py.BooleanFunction.Value] or None
1648 py_boolean_function_node.def(
1649 "get_constant_value_u64",
1651 if (
const auto res =
self.get_constant_value_u64(); res.is_ok())
1657 log_error(
"python_context",
"could not get constant value:\n{}", res.get_error().get());
1658 return std::nullopt;
1662 Get the constant value of the node of type ``Constant`` as long as it has a size <= 64-bit.
1664 :returns: The constant value on success, None otherwise.
1669 Checks whether the Boolean function node is of type Index.
1671 :returns: True if the Boolean function node is of type Index, False otherwise.
1676 Checks whether the Boolean function node is of type Index and holds a specific value.
1678 :param int value: The value to check for.
1679 :returns: True if the Boolean function node is of type Index and holds the given value, False otherwise.
1683 py_boolean_function_node.def(
1686 if (
const auto res =
self.get_index_value(); res.is_ok())
1692 log_error(
"python_context",
"could not get index value:\n{}", res.get_error().get());
1693 return std::nullopt;
1697 Get the index value of node of type ``Index``.
1699 :returns: The index value on success, None otherwise.
1704 Checks whether the Boolean function node is of type Variable.
1706 :returns: True if the Boolean function node is of type Variable, False otherwise.
1711 Checks whether the Boolean function node is of type Variable and holds a specific variable name.
1713 :param str variable_name: The variable name to check for.
1714 :returns: True if the Boolean function node is of type Variable and holds the given variable name, False otherwise.
1718 py_boolean_function_node.def(
1719 "get_variable_name",
1721 if (
const auto res =
self.get_variable_name(); res.is_ok())
1727 log_error(
"python_context",
"could not get variable name:\n{}", res.get_error().get());
1728 return std::nullopt;
1732 Get the variable name of node of type ``Variable``.
1734 :returns: The variable name on success, None otherwise.
1739 Checks whether the Boolean function node is an operation node.
1741 :returns: True if the Boolean function node is an operation node, False otherwise.
1746 Checks whether the Boolean function node is an operand node.
1748 :returns: True if the Boolean function node is an operand node, False otherwise.
1753 Checks whether the Boolean function node is commutative.
1755 :returns: True if the Boolean function node is commutative, False otherwise.
1759 py::class_<BooleanFunction::NodeType> py_boolean_function_node_type(py_boolean_function, "NodeType", R
"(
1760 Holds all node types available in a Boolean function.
static Result< BooleanFunction > Slt(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
bool has_index_value(u16 index) const
static Result< BooleanFunction > Ite(BooleanFunction &&p0, BooleanFunction &&p1, BooleanFunction &&p2, u16 size)
static Result< BooleanFunction > Eq(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static BooleanFunction Var(const std::string &name, u16 size=1)
static Result< BooleanFunction > Xor(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
const BooleanFunction::Node & get_top_level_node() const
static Result< BooleanFunction > Add(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
std::set< std::string > get_variable_names() const
static Result< BooleanFunction > Lshr(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
bool has_constant_value(const std::vector< Value > &value) const
static Result< BooleanFunction > Zext(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Mul(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
bool has_variable_name(const std::string &variable_name) const
static Result< BooleanFunction > Ule(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Sub(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Sext(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Udiv(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Concat(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Ult(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static BooleanFunction Index(u16 index, u16 size)
static Result< BooleanFunction > Sle(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > build(std::vector< Node > &&nodes)
static Result< BooleanFunction > from_string(const std::string &expression)
static Result< BooleanFunction > Slice(BooleanFunction &&p0, BooleanFunction &&p1, BooleanFunction &&p2, u16 size)
const std::vector< BooleanFunction::Node > & get_nodes() const
BooleanFunction simplify() const
BooleanFunction clone() const
Value
represents the type of the node
static Result< BooleanFunction > Or(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Urem(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Ror(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Sdiv(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static std::string to_string(Value value)
static BooleanFunction Const(const BooleanFunction::Value &value)
static Result< BooleanFunction > Ashr(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< u64 > to_u64(const std::vector< BooleanFunction::Value > &value)
static Result< BooleanFunction > Not(BooleanFunction &&p0, u16 size)
static Result< BooleanFunction > And(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
std::vector< BooleanFunction > get_parameters() const
BooleanFunction substitute(const std::string &old_variable_name, const std::string &new_variable_name) const
static Result< BooleanFunction > Shl(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Rol(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static Result< BooleanFunction > Srem(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
void boolean_function_init(py::module &m)
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)
std::vector< BooleanFunction::Value > constant
The (optional) constant value of the node.
u16 type
The type of the node.
bool is_operation() const
u16 size
The bit-size of the node.
static u16 get_arity_of_type(u16 type)
static Node Constant(const std::vector< BooleanFunction::Value > value)
bool has_index_value(u16 value) const
std::string variable
The (optional) variable name of the node.
bool has_variable_name(const std::string &variable_name) const
static Node Operation(u16 type, u16 size)
bool has_constant_value(const std::vector< Value > &value) const
bool is_commutative() const
static Node Index(u16 index, u16 size)
u16 index
The (optional) index value of the node.
static Node Variable(const std::string variable, u16 size)
static constexpr u16 Constant
static constexpr u16 Srem
static constexpr u16 Udiv
static constexpr u16 Sdiv
static constexpr u16 Urem
static constexpr u16 Lshr
static constexpr u16 Sext
static constexpr u16 Ashr
static constexpr u16 Index
static constexpr u16 Concat
static constexpr u16 Slice
static constexpr u16 Zext
static constexpr u16 Variable