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 and validates a Boolean function from a list of nodes.
54 :param list[hal_py.BooleanFunction.Node] nodes: List of Boolean function nodes.
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 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 Boolean function.
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 p2: 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 function.
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 function.
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 function.
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 function.
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 function.
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 function.
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 function.
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 function.
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 function.
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 function.
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 function.
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 function.
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``.
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.
1098 py_boolean_function.def("has_constant_value", py::overload_cast<
const std::vector<BooleanFunction::Value>&>(&
BooleanFunction::has_constant_value, py::const_), py::arg(
"value"), R
"(
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 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 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 list 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(
1270 [](
const std::string& expression,
const std::map<std::string, u16>& var_sizes) ->
BooleanFunction {
1278 log_error(
"python_context",
"{}", res.get_error().get());
1282 py::arg(
"expression"),
1283 py::arg(
"var_sizes") = std::map<std::string, u16>{},
1285 Parses a Boolean function from a string expression. Variables whose bit-width differs
1286 from the default of one bit can be sized via the optional ``var_sizes`` dict.
1288 :param str expression: Boolean function string.
1289 :param dict[str, int] var_sizes: Optional dict from variable name to bit-width.
1290 :returns: The Boolean function on success, an empty Boolean function otherwise.
1291 :rtype: hal_py.BooleanFunction
1295 Simplifies the Boolean function.
1297 :returns: The simplified Boolean function.
1298 :rtype: hal_py.BooleanFunction
1302 Simplifies the Boolean function using only the local simplification, i.e., without invoking ABC.
1304 :returns: The simplified Boolean function.
1305 :rtype: hal_py.BooleanFunction
1308 py_boolean_function.def(
1309 "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
"(
1310 Substitute a variable name with another one, i.e., renames the variable.
1311 The operation is applied to all instances of the variable in the function.
1313 :param str old_variable_name: The old variable name to substitute.
1314 :param str new_variable_name: The new variable name.
1315 :returns: The resulting Boolean function.
1316 :rtype: hal_py.BooleanFunction
1319 py_boolean_function.def(
1322 auto res =
self.substitute(variable_name,
function);
1329 log_error(
"python_context",
"{}", res.get_error().get());
1330 return std::nullopt;
1333 py::arg(
"variable_name"),
1334 py::arg(
"function"),
1336 Substitute a variable with another Boolean function.
1337 The operation is applied to all instances of the variable in the function.
1339 :param str variable_name: The variable to substitute.
1340 :param hal_py.BooleanFunction function: The function replace the variable with.
1341 :returns: The resulting Boolean function on success, ``None`` otherwise.
1342 :rtype: hal_py.BooleanFunction or None
1345 py_boolean_function.def("substitute",
1347 py::arg(
"substitutions"),
1349 Substitute multiple variable names with different names at once, i.e., rename the variables.
1350 The operation is applied to all instances of the variable in the function.
1352 :param dict[str,str] substitutions: A dict from old variable names to new variable names.
1353 :returns: The resulting Boolean function.
1354 :rtype: hal_py.BooleanFunction
1357 py_boolean_function.def(
1359 [](
const BooleanFunction&
self,
const std::map<std::string, BooleanFunction>& substitutions) -> std::optional<BooleanFunction> {
1360 auto res =
self.substitute(substitutions);
1367 log_error(
"python_context",
"{}", res.get_error().get());
1368 return std::nullopt;
1371 py::arg(
"substitutions"),
1373 Substitute multiple variables with Boolean functions at once.
1374 The operation is applied to all instances of the variable in the function.
1376 :param dict[str,hal_py.BooleanFunction] substitutions: A dict from variable names to Boolean functions.
1377 :returns: The resulting Boolean function on success, ``None`` otherwise.
1378 :rtype: hal_py.BooleanFunction or None
1381 py_boolean_function.def(
1383 [](
const BooleanFunction&
self,
const std::unordered_map<std::string, BooleanFunction::Value>& inputs) -> std::optional<BooleanFunction::Value> {
1384 auto res =
self.evaluate(inputs);
1391 log_error(
"python_context",
"{}", res.get_error().get());
1392 return std::nullopt;
1397 Evaluates a Boolean function comprising only single-bit variables using the given input values.
1399 :param dict[str,hal_py.BooleanFunction.Value] inputs: A dict from variable name to input value.
1400 :returns: The resulting value on success, ``None`` otherwise.
1401 :rtype: hal_py.BooleanFunction.Value or None
1404 py_boolean_function.def(
1406 [](
const BooleanFunction&
self,
const std::unordered_map<std::string, std::vector<BooleanFunction::Value>>& inputs) -> std::optional<std::vector<BooleanFunction::Value>> {
1407 auto res =
self.evaluate(inputs);
1414 log_error(
"python_context",
"{}", res.get_error().get());
1415 return std::nullopt;
1420 Evaluates a Boolean function comprising multi-bit variables using the given input values.
1422 :param dict[str,list[hal_py.BooleanFunction.Value]] inputs: A dict from variable name to a list of input values.
1423 :returns: A list of values on success, ``None`` otherwise.
1424 :rtype: list[hal_py.BooleanFunction.Value] or None
1427 py_boolean_function.def(
1428 "compute_truth_table",
1429 [](
const BooleanFunction&
self,
const std::vector<std::string>& ordered_variables,
bool remove_unknown_variables) -> std::optional<std::vector<std::vector<BooleanFunction::Value>>> {
1430 auto res =
self.compute_truth_table(ordered_variables, remove_unknown_variables);
1437 log_error(
"python_context",
"{}", res.get_error().get());
1438 return std::nullopt;
1441 py::arg(
"ordered_variables") = std::vector<std::string>(),
1442 py::arg(
"remove_unknown_variables") =
false,
1444 Computes the truth table outputs for a Boolean function that comprises <= 20 single-bit variables.
1446 **Warning:** The generation of the truth table is exponential in the number of parameters.
1448 :param list[str] ordered_variables: A list describing the order of input variables used to generate the truth table. Defaults to an empty list.
1449 :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``.
1450 :returns: A list of values representing the truth table output on success, ``None`` otherwise.
1451 :rtype: list[list[hal_py.BooleanFunction.Value]] or None
1454 py_boolean_function.def(
1455 "get_truth_table_as_string",
1456 [](
const BooleanFunction&
self,
const std::vector<std::string>& ordered_variables, std::string function_name,
bool remove_unknown_variables) -> std::optional<std::string> {
1457 auto res =
self.get_truth_table_as_string(ordered_variables, function_name, remove_unknown_variables);
1464 log_error(
"python_context",
"{}", res.get_error().get());
1465 return std::nullopt;
1468 py::arg(
"ordered_variables") = std::vector<std::string>(),
1469 py::arg(
"function_name") = std::string(
""),
1470 py::arg(
"remove_unknown_variables") =
false,
1472 Prints the truth table for a Boolean function that comprises <= 20 single-bit variables.
1474 **Warning:** The generation of the truth table is exponential in the number of parameters.
1476 :param list[str] ordered_variables: A list describing the order of input variables used to generate the truth table. Defaults to an empty list.
1477 :param str function_name: The name of the Boolean function to be printed as header of the output columns.
1478 :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``.
1479 :returns: A string representing the truth table on success, ``None`` otherwise.
1483 py::class_<BooleanFunction::Node> py_boolean_function_node(py_boolean_function, "Node", R
"(
1484 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).
1488 The type of the node.
1494 The bit-size of the node.
1500 The (optional) constant value of the node.
1502 :type: list[hal_py.BooleanFunction.Value]
1506 The (optional) index value of the node.
1512 The (optional) variable name of the node.
1518 Constructs an 'operation' node.
1520 :param int type: The type of the operation.
1521 :param int size: The bit-size of the operation.
1523 :rtype: hal_py.BooleanFunction.Node
1527 Constructs a 'constant' node.
1529 :param list[hal_py.BooleanFunction.Value] value: The constant value of the node.
1531 :rtype: hal_py.BooleanFunction.Node
1535 Constructs an 'index' node.
1537 :param int value: The index value of the node.
1538 :param int size: The bit-size of the node.
1540 :rtype: hal_py.BooleanFunction.Node
1544 Constructs a 'variable' node.
1546 :param int value: The variable name of the node.
1547 :param int size: The bit-size of the node.
1549 :rtype: hal_py.BooleanFunction.Node
1552 py_boolean_function_node.def(py::self == py::self, R"(
1553 Checks whether two Boolean function nodes are equal.
1555 :returns: ``True`` if both Boolean function nodes are equal, ``False`` otherwise.
1559 py_boolean_function_node.def(py::self != py::self, R"(
1560 Checks whether two Boolean function nodes are unequal.
1562 :returns: ``True`` if both Boolean function nodes are unequal, ``False`` otherwise.
1566 py_boolean_function_node.def(py::self < py::self, R"(
1567 Checks whether this Boolean function node is 'smaller' than the ``other`` Boolean function node.
1569 :returns: ``True`` if this Boolean function node is 'smaller', ``False`` otherwise.
1574 Clones the Boolean function node.
1576 :returns: The cloned Boolean function node.
1577 :rtype: hal_py.BooleanFunction.Node
1581 Translates the Boolean function node into its string representation.
1583 :returns: The Boolean function node as a string.
1588 The arity of the Boolean function node, i.e., the number of parameters.
1594 Returns the arity of the Boolean function node, i.e., the number of parameters.
1596 :returns: The arity.
1601 Returns the arity for a Boolean function node of the given type, i.e., the number of parameters.
1603 :returns: The arity.
1608 Checks whether the Boolean function node is of a specific type.
1610 :param int type: The type to check for.
1611 :returns: ``True`` if the node is of the given type, ``False`` otherwise.
1616 Checks whether the Boolean function node is of type Constant.
1618 :returns: ``True`` if the Boolean function node is of type Constant, ``False`` otherwise.
1623 Checks whether the Boolean function node is of type Constant and holds a specific value.
1625 :param list[hal_py.BooleanFunction.Value] value: The value to check for.
1626 :returns: ``True`` if the Boolean function node is of type Constant and holds the given value, ``False`` otherwise.
1631 Checks whether the Boolean function node is of type Constant and holds a specific value.
1633 :param int value: The value to check for.
1634 :returns: ``True`` if the Boolean function node is of type Constant and holds the given value, ``False`` otherwise.
1638 py_boolean_function_node.def(
1639 "get_constant_value",
1641 if (
const auto res =
self.get_constant_value(); res.is_ok())
1647 log_error(
"python_context",
"could not get constant value:\n{}", res.get_error().get());
1648 return std::nullopt;
1652 Get the constant value of the node of type ``Constant`` as a list of ``hal_py.BooleanFunction.Value``.
1654 :returns: The constant value on success, ``None`` otherwise.
1655 :rtype: list[hal_py.BooleanFunction.Value] or None
1658 py_boolean_function_node.def(
1659 "get_constant_value_u64",
1661 if (
const auto res =
self.get_constant_value_u64(); res.is_ok())
1667 log_error(
"python_context",
"could not get constant value:\n{}", res.get_error().get());
1668 return std::nullopt;
1672 Get the constant value of the node of type ``Constant`` as long as it has a size <= 64-bit.
1674 :returns: The constant value on success, ``None`` otherwise.
1679 Checks whether the Boolean function node is of type Index.
1681 :returns: ``True`` if the Boolean function node is of type Index, ``False`` otherwise.
1686 Checks whether the Boolean function node is of type Index and holds a specific value.
1688 :param int value: The value to check for.
1689 :returns: ``True`` if the Boolean function node is of type Index and holds the given value, ``False`` otherwise.
1693 py_boolean_function_node.def(
1696 if (
const auto res =
self.get_index_value(); res.is_ok())
1702 log_error(
"python_context",
"could not get index value:\n{}", res.get_error().get());
1703 return std::nullopt;
1707 Get the index value of node of type ``Index``.
1709 :returns: The index value on success, ``None`` otherwise.
1714 Checks whether the Boolean function node is of type Variable.
1716 :returns: ``True`` if the Boolean function node is of type Variable, ``False`` otherwise.
1721 Checks whether the Boolean function node is of type Variable and holds a specific variable name.
1723 :param str variable_name: The variable name to check for.
1724 :returns: ``True`` if the Boolean function node is of type Variable and holds the given variable name, ``False`` otherwise.
1728 py_boolean_function_node.def(
1729 "get_variable_name",
1731 if (
const auto res =
self.get_variable_name(); res.is_ok())
1737 log_error(
"python_context",
"could not get variable name:\n{}", res.get_error().get());
1738 return std::nullopt;
1742 Get the variable name of node of type ``Variable``.
1744 :returns: The variable name on success, ``None`` otherwise.
1749 Checks whether the Boolean function node is an operation node.
1751 :returns: ``True`` if the Boolean function node is an operation node, ``False`` otherwise.
1756 Checks whether the Boolean function node is an operand node.
1758 :returns: ``True`` if the Boolean function node is an operand node, ``False`` otherwise.
1763 Checks whether the Boolean function node is commutative.
1765 :returns: ``True`` if the Boolean function node is commutative, ``False`` otherwise.
1769 py::class_<BooleanFunction::NodeType> py_boolean_function_node_type(py_boolean_function, "NodeType", R
"(
1770 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)
BooleanFunction simplify_local() const
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
std::string to_string() 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