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.)")
23 py_boolean_function_value.def(
25 Translates the Boolean function value into its string representation.
27 :returns: The value as a string.
31 py_boolean_function.def_static(
33 [](
const std::vector<BooleanFunction::Value>& value,
u8 base = 2) -> std::optional<std::string> {
41 log_error(
"python_context",
"{}", res.get_error().get());
48 Convert the given bit-vector to its string representation in the given base.
50 :param list[hal_py.BooleanFunction.Value] value: The value as a bit-vector.
51 :param int base: The base that the values should be converted to. Valid values are 2 (default), 8, 10, and 16.
52 :returns: A string representing the values in the given base on success, None otherwise.
56 py_boolean_function.def_static(
58 [](
const std::vector<BooleanFunction::Value>& value) -> std::optional<u64> {
66 log_error(
"python_context",
"{}", res.get_error().get());
72 Convert the given bit-vector to its unsigned 64-bit integer representation.
74 :param list[hal_py.BooleanFunction.Value] value: The value as a bit-vector.
75 :returns: A 64-bit integer representing the values on success, None otherwise.
79 py_boolean_function.def(py::init<>(), R"(
80 Constructs an empty / invalid Boolean function.
83 py_boolean_function.def_static("Var", &
BooleanFunction::Var, py::arg(
"name"), py::arg(
"size") = 1, R
"(
84 Creates a multi-bit Boolean function of the given bit-size comprising only a variable of the specified name.
86 :param str name: The name of the variable.
87 :param int size: The bit-size. Defaults to 1.
88 :returns: The BooleanFunction.
89 :rtype: hal_py.BooleanFunction
92 py_boolean_function.def_static("Const", py::overload_cast<const BooleanFunction::Value&>(&
BooleanFunction::Const), py::arg(
"value"), R
"(
93 Creates a constant single-bit Boolean function from a value.
95 :param hal_py.BooleanFunction.Value value: The value.
96 :returns: The Boolean function.
97 :rtype: hal_py.BooleanFunction
100 py_boolean_function.def_static("Const", py::overload_cast<
const std::vector<BooleanFunction::Value>&>(&
BooleanFunction::Const), py::arg(
"value"), R
"(
101 Creates a constant multi-bit Boolean function from a list of values.
103 :param list[hal_py.BooleanFunction.Value] value: The list of values.
104 :returns: The Boolean function.
105 :rtype: hal_py.BooleanFunction
108 py_boolean_function.def_static("Const", py::overload_cast<u64, u16>(&
BooleanFunction::Const), py::arg(
"value"), py::arg(
"size"), R
"(
109 Creates a constant multi-bit Boolean function of the given bit-size from an integer value.
111 :param int value: The integer value.
112 :param int size: The bit-size.
113 :returns: The Boolean function.
114 :rtype: hal_py.BooleanFunction
118 Creates an index for a Boolean function of the given bit-size from an integer value.
120 :param int index: The integer value.
121 :param int size: The bit-size.
122 :returns: The Boolean function.
123 :rtype: hal_py.BooleanFunction
126 py_boolean_function.def_static(
136 log_error(
"python_context",
"{}", res.get_error().get());
144 Joins two Boolean functions by applying an AND operation.
145 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
147 :param hal_py.BooleanFunction p0: First Boolean function.
148 :param hal_py.BooleanFunction p1: Second Boolean function.
149 :param int size: Bit-size of the operation.
150 :returns: The joined Boolean function on success, None otherwise.
151 :rtype: hal_py.BooleanFunction or None
154 py_boolean_function.def_static(
164 log_error(
"python_context",
"{}", res.get_error().get());
172 Joins two Boolean functions by applying an OR 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());
199 Negates the given Boolean function.
200 Requires the Boolean function to be of the specified bit-size and produces a new Boolean function of the same bit-size.
202 :param hal_py.BooleanFunction p0: The Boolean function to negate.
203 :param int size: Bit-size of the operation.
204 :returns: The negated Boolean function on success, None otherwise.
205 :rtype: hal_py.BooleanFunction or None
208 py_boolean_function.def_static(
218 log_error(
"python_context",
"{}", res.get_error().get());
226 Joins two Boolean functions by applying an XOR operation.
227 Requires both Boolean functions to be of the specified bit-size and produces a new Boolean function of the same bit-size.
229 :param hal_py.BooleanFunction p0: First Boolean function.
230 :param hal_py.BooleanFunction p1: Second Boolean function.
231 :param int size: Bit-size of the operation.
232 :returns: The joined 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 ADD 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 SUB 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 MUL 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 SDIV 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 UDIV 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 SREM 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 UREM 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());
451 Returns the slice ``[i:j]`` of a Boolean function specified by a start index ``i`` and an end index ``j`` beginning at 0.
452 Note that slice ``[i:j]`` includes positions ``i`` and ``j`` as well.
454 :param hal_py.BooleanFunction p0: Boolean function to slice.
455 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding start index ``i``.
456 :param hal_py.BooleanFunction p2: Boolean function of type ``Index`` encoding end index ``j``.
457 :param int size: Bit-size of the resulting Boolean function slice, i.e., ``j - i + 1``.
458 :returns: The Boolean function slice on success, None otherwise.
459 :rtype: hal_py.BooleanFunction or None
462 py_boolean_function.def_static(
472 log_error(
"python_context",
"{}", res.get_error().get());
480 Concatenates two Boolean functions of bit-sizes ``n`` and ``m`` to form a single Boolean function of bit-size ``n + m``.
482 :param hal_py.BooleanFunction p0: First Boolean function (MSBs).
483 :param hal_py.BooleanFunction p1: Second Boolean function (LSBs).
484 :param int size: Bit-size of the concatenated Boolean function, i.e., ``n + m``.
485 :returns: The concatenated Boolean function on success, None otherwise.
486 :rtype: hal_py.BooleanFunction or None
489 py_boolean_function.def_static(
499 log_error(
"python_context",
"{}", res.get_error().get());
507 Zero-extends a Boolean function to the specified bit-size.
509 :param hal_py.BooleanFunction p0: Boolean function to extend.
510 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the bit-size of the zero-extended result.
511 :param int size: Bit-size of the zero-extended Boolean function.
512 :returns: The zero-extended Boolean function on success, None otherwise.
513 :rtype: hal_py.BooleanFunction or None
516 py_boolean_function.def_static(
526 log_error(
"python_context",
"{}", res.get_error().get());
534 Sign-extends a Boolean function to the specified bit-size.
536 :param hal_py.BooleanFunction p0: Boolean function to extend.
537 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the bit-size of the sign-extended result.
538 :param int size: Bit-size of the sign-extended Boolean function.
539 :returns: The sign-extended Boolean function on success, None otherwise.
540 :rtype: hal_py.BooleanFunction or None
543 py_boolean_function.def_static(
553 log_error(
"python_context",
"{}", res.get_error().get());
561 Shifts a Boolean function to the left by the specified number of bits.
563 :param hal_py.BooleanFunction p0: Boolean function to shift.
564 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to shift.
565 :param int size: Bit-size of the shifted Boolean function.
566 :returns: The shifted Boolean function on success, None otherwise.
567 :rtype: hal_py.BooleanFunction or None
570 py_boolean_function.def_static(
580 log_error(
"python_context",
"{}", res.get_error().get());
588 Logically shifts a Boolean function to the right by the specified number of bits.
590 :param hal_py.BooleanFunction p0: Boolean function to shift.
591 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to shift.
592 :param int size: Bit-size of the shifted Boolean function.
593 :returns: The shifted Boolean function on success, None otherwise.
594 :rtype: hal_py.BooleanFunction or None
597 py_boolean_function.def_static(
607 log_error(
"python_context",
"{}", res.get_error().get());
615 Arithmetically shifts a Boolean function to the right by the specified number of bits.
617 :param hal_py.BooleanFunction p0: Boolean function to shift.
618 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to shift.
619 :param int size: Bit-size of the shifted Boolean function.
620 :returns: The shifted Boolean function on success, None otherwise.
621 :rtype: hal_py.BooleanFunction or None
624 py_boolean_function.def_static(
634 log_error(
"python_context",
"{}", res.get_error().get());
642 Rotates a Boolean function to the left by the specified number of bits.
644 :param hal_py.BooleanFunction p0: Boolean function to rotate.
645 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to rotate.
646 :param int size: Bit-size of the rotated Boolean function.
647 :returns: The rotated Boolean function on success, None otherwise.
648 :rtype: hal_py.BooleanFunction or None
651 py_boolean_function.def_static(
661 log_error(
"python_context",
"{}", res.get_error().get());
669 Rotates a Boolean function to the right by the specified number of bits.
671 :param hal_py.BooleanFunction p0: Boolean function to rotate.
672 :param hal_py.BooleanFunction p1: Boolean function of type ``Index`` encoding the number of bits to rotate.
673 :param int size: Bit-size of the rotated Boolean function.
674 :returns: The rotated Boolean function on success, None otherwise.
675 :rtype: hal_py.BooleanFunction or None
678 py_boolean_function.def_static(
688 log_error(
"python_context",
"{}", res.get_error().get());
696 Joins two Boolean functions by an equality check that produces a single-bit result.
698 :param hal_py.BooleanFunction p0: First Boolean function.
699 :param hal_py.BooleanFunction p1: Second Boolean function.
700 :param int size: Bit-size of the operation (always =1).
701 :returns: The joined Boolean function on success, None otherwise.
702 :rtype: hal_py.BooleanFunction or None
705 py_boolean_function.def_static(
715 log_error(
"python_context",
"{}", res.get_error().get());
723 Joins two Boolean functions by a signed less-than-equal check that produces a single-bit result.
725 :param hal_py.BooleanFunction p0: First Boolean function.
726 :param hal_py.BooleanFunction p1: Second Boolean function.
727 :param int size: Bit-size of the operation (always =1).
728 :returns: The joined Boolean function on success, None otherwise.
729 :rtype: hal_py.BooleanFunction or None
732 py_boolean_function.def_static(
742 log_error(
"python_context",
"{}", res.get_error().get());
750 Joins two Boolean functions by a signed less-than check that produces a single-bit result.
752 :param hal_py.BooleanFunction p0: First Boolean function.
753 :param hal_py.BooleanFunction p1: Second Boolean function.
754 :param int size: Bit-size of the operation (always =1).
755 :returns: The joined Boolean function on success, None otherwise.
756 :rtype: hal_py.BooleanFunction or None
759 py_boolean_function.def_static(
769 log_error(
"python_context",
"{}", res.get_error().get());
777 Joins two Boolean functions by an unsigned less-than-equal check that produces a single-bit result.
779 :param hal_py.BooleanFunction p0: First Boolean function.
780 :param hal_py.BooleanFunction p1: Second Boolean function.
781 :param int size: Bit-size of the operation (always =1).
782 :returns: The joined Boolean function on success, None otherwise.
783 :rtype: hal_py.BooleanFunction or None
786 py_boolean_function.def_static(
796 log_error(
"python_context",
"{}", res.get_error().get());
804 Joins two Boolean functions by an unsigned less-than check that produces a single-bit result.
806 :param hal_py.BooleanFunction p0: First Boolean function.
807 :param hal_py.BooleanFunction p1: Second Boolean function.
808 :param int size: Bit-size of the operation (always =1).
809 :returns: The joined Boolean function on success, None otherwise.
810 :rtype: hal_py.BooleanFunction or None
813 py_boolean_function.def_static(
823 log_error(
"python_context",
"{}", res.get_error().get());
832 Joins three Boolean functions by an if-then-else operation with p0 as the condition, p1 as true-case, and p2 as false-case.
833 Requires ``p1`` to be of bit-size 1 and both Boolean functions ``p1`` and ``p2`` to be of the same bit-size.
834 Produces a new Boolean function of the specified bit-size that must be equal to the size of ``p1`` and ``p2``.
836 :param hal_py.BooleanFunction p0: Boolean function condition.
837 :param hal_py.BooleanFunction p1: Boolean function for ``true``-case.
838 :param hal_py.BooleanFunction p1: Boolean function for ``false``-case.
839 :param int size: Bit-size of the operation, i.e., size of ``p1`` and ``p2``.
840 :returns: The joined Boolean function on success, None otherwise.
841 :rtype: hal_py.BooleanFunction or None
844 py_boolean_function.def(py::self & py::self, R"(
845 Joins two Boolean functions by an AND operation.
846 Requires both Boolean functions to be of the same bit-size.
848 **Warning:** fails if the Boolean functions have different bit-sizes.
850 :returns: The joined Boolean Bunction.
851 :rtype: hal_py.BooleanFunction
854 py_boolean_function.def(py::self &= py::self, R"(
855 Joins two Boolean functions by an AND operation in-place.
856 Requires both Boolean functions to be of the same bit-size.
858 **Warning:** fails if the Boolean functions have different bit-sizes.
860 :returns: The joined Boolean Bunction.
861 :rtype: hal_py.BooleanFunction
864 py_boolean_function.def(py::self | py::self, R"(
865 Joins two Boolean functions by an OR operation.
866 Requires both Boolean functions to be of the same bit-size.
868 **Warning:** fails if the Boolean functions have different bit-sizes.
870 :returns: The joined Boolean Bunction.
871 :rtype: hal_py.BooleanFunction
874 py_boolean_function.def(py::self |= py::self, R"(
875 Joins two Boolean functions by an OR operation in-place.
876 Requires both Boolean functions to be of the same bit-size.
878 **Warning:** fails if the Boolean functions have different bit-sizes.
880 :returns: The joined Boolean Bunction.
881 :rtype: hal_py.BooleanFunction
884 py_boolean_function.def(~py::self, R"(
885 Negates the Boolean function.
887 :returns: The negated Boolean function.
888 :rtype: hal_py.BooleanFunction
891 py_boolean_function.def(py::self ^ py::self, R"(
892 Joins two Boolean functions by an XOR operation.
893 Requires both Boolean functions to be of the same bit-size.
895 **Warning:** fails if the Boolean functions have different bit-sizes.
897 :returns: The joined Boolean Bunction.
898 :rtype: hal_py.BooleanFunction
901 py_boolean_function.def(py::self ^= py::self, R"(
902 Joins two Boolean functions by an XOR operation in-place.
903 Requires both Boolean functions to be of the same bit-size.
905 **Warning:** fails if the Boolean functions have different bit-sizes.
907 :returns: The joined Boolean Bunction.
908 :rtype: hal_py.BooleanFunction
911 py_boolean_function.def(py::self + py::self, R"(
912 Joins two Boolean functions by an ADD operation.
913 Requires both Boolean functions to be of the same bit-size.
915 **Warning:** fails if the Boolean functions have different bit-sizes.
917 :returns: The joined Boolean Bunction.
918 :rtype: hal_py.BooleanFunction
921 py_boolean_function.def(py::self += py::self, R"(
922 Joins two Boolean functions by an ADD operation in-place.
923 Requires both Boolean functions to be of the same bit-size.
925 **Warning:** fails if the Boolean functions have different bit-sizes.
927 :returns: The joined Boolean Bunction.
928 :rtype: hal_py.BooleanFunction
931 py_boolean_function.def(py::self - py::self, R"(
932 Joins two Boolean functions by an SUB operation.
933 Requires both Boolean functions to be of the same bit-size.
935 **Warning:** fails if the Boolean functions have different bit-sizes.
937 :returns: The joined Boolean Bunction.
938 :rtype: hal_py.BooleanFunction
941 py_boolean_function.def(py::self -= py::self, R"(
942 Joins two Boolean functions by an SUB operation in-place.
943 Requires both Boolean functions to be of the same bit-size.
945 **Warning:** fails if the Boolean functions have different bit-sizes.
947 :returns: The joined Boolean Bunction.
948 :rtype: hal_py.BooleanFunction
951 py_boolean_function.def(py::self * py::self, R"(
952 Joins two Boolean functions by an MUL operation.
953 Requires both Boolean functions to be of the same bit-size.
955 **Warning:* fails if the Boolean functions have different bit-sizes.
957 :returns: The joined Boolean Bunction.
958 :rtype: hal_py.BooleanFunction
961 py_boolean_function.def(py::self *= py::self, R"(
962 Joins two Boolean functions by an MUL operation in-place.
963 Requires both Boolean functions to be of the same bit-size.
965 **Warning:** fails if the Boolean functions have different bit-sizes.
967 :returns: The joined Boolean Bunction.
968 :rtype: hal_py.BooleanFunction
971 py_boolean_function.def(py::self == py::self, R"(
972 Checks whether two Boolean functions are equal.
974 :returns: True if both Boolean functions are equal, False otherwise.
978 py_boolean_function.def(py::self != py::self, R"(
979 Checks whether two Boolean functions are unequal.
981 :returns: True if both Boolean functions are unequal, False otherwise.
985 py_boolean_function.def(py::self < py::self, R"(
986 Checks whether this Boolean function is 'smaller' than the ``other`` Boolean function.
988 :returns: True if this Boolean function is 'smaller', False otherwise.
993 Checks whether the Boolean function is empty.
995 :returns: True if the Boolean function is empty, False otherwise.
1000 Clones the Boolean function.
1002 :returns: The cloned Boolean function.
1003 :rtype: hal_py.BooleanFunction
1007 The bit-size of the Boolean function.
1013 Returns the bit-size of the Boolean function.
1015 :returns: The bit-size of the Boolean function.
1020 Checks whether the top-level node of the Boolean function is of a specific type.
1022 :param int type: The type to check for.
1023 :returns: True if the node is of the given type, False otherwise.
1028 Checks whether the top-level node of the Boolean function is of type ``Variable`` and holds a specific variable name.
1030 :returns: True if the top-level node of the Boolean function is of type Variable, False otherwise.
1035 Checks whether the top-level node of the Boolean function is of type Variable and holds a specific variable name.
1037 :param int value: The variable name to check for.
1038 :returns: True if the top-level node of the Boolean function is of type Variable and holds the given variable name, False otherwise.
1042 py_boolean_function.def(
1043 "get_variable_name",
1045 auto res =
self.get_variable_name();
1052 log_error(
"python_context",
"{}", res.get_error().get());
1053 return std::nullopt;
1057 Get the variable name of the top-level node of the Boolean function of type Variable.
1059 :returns: The variable name on success, None otherwise.
1064 Checks whether the top-level node of the Boolean function is of type Constant.
1066 :returns: True if the top-level node of the Boolean function is of type Constant, False otherwise.
1071 Checks whether the top-level node of the Boolean function is of type Constant and holds a specific value.
1073 :param list[hal_py.BooleanFunction.Value] value: The constant value to check for.
1074 :returns: True if the top-level node of the Boolean function is of type Constant and holds the given value, False otherwise.
1079 Checks whether the top-level node of the Boolean function is of type Constant and holds a specific value.
1081 :param int value: The constant value to check for.
1082 :returns: True if the top-level node of the Boolean function is of type Constant and holds the given value, False otherwise.
1086 py_boolean_function.def(
1087 "get_constant_value",
1088 [](
const BooleanFunction&
self) -> std::optional<std::vector<BooleanFunction::Value>> {
1089 auto res =
self.get_constant_value();
1096 log_error(
"python_context",
"{}", res.get_error().get());
1097 return std::nullopt;
1101 Get the constant value of the top-level node of the Boolean function of type Constant as a list of ``hal_py.BooleanFunction.Value``.
1103 :returns: The constant value on success, None otherwise.
1104 :rtype: list[hal_py.BooleanFunction.Value] or None
1107 py_boolean_function.def(
1108 "get_constant_value_u64",
1110 auto res =
self.get_constant_value_u64();
1117 log_error(
"python_context",
"{}", res.get_error().get());
1118 return std::nullopt;
1122 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.
1124 :returns: The constant value on success, None otherwise.
1129 Checks whether the top-level node of the Boolean function is of type Index.
1131 :returns: True if the top-level node of the Boolean function is of type Index, False otherwise.
1136 Checks whether the top-level node of the Boolean function is of type Index and holds a specific value.
1138 :param int value: The index value to check for.
1139 :returns: True if the top-level node of the Boolean function is of type Index and holds the given value, False otherwise.
1143 py_boolean_function.def(
1146 auto res =
self.get_index_value();
1153 log_error(
"python_context",
"{}", res.get_error().get());
1154 return std::nullopt;
1158 Get the index value of the top-level node of the Boolean function of type Index.
1160 :returns: The index value on success, None otherwise.
1165 The top-level node of the Boolean function.
1167 **Warning:** fails if the Boolean function is empty.
1169 :type: hal_py.BooleanFunction.Node
1173 Returns the top-level node of the Boolean function.
1175 **Warning:** fails if the Boolean function is empty.
1177 :returns: The top-level node.
1178 :rtype: hal_py.BooleanFunction.Node
1182 The number of nodes in the Boolean function.
1188 Returns the number of nodes in the Boolean function.
1190 :returns: The number of nodes.
1195 The reverse polish notation list of the Boolean function nodes.
1197 :type: list[hal_py.BooleanFunction.Node]
1201 Returns the reverse polish notation list of the Boolean function nodes.
1203 :returns: A list of nodes.
1204 :rtype: list[hal_py.BooleanFunction.Node]
1208 The parameter list of the top-level node of the Boolean function.
1210 :type: list[hal_py.BooleanFunction]
1214 Returns the parameter list of the top-level node of the Boolean function.
1216 :returns: A vector of Boolean functions.
1217 :rtype: list[hal_py.BooleanFunction]
1221 The set of variable names used by the Boolean function.
1227 Returns the set of variable names used by the Boolean function.
1229 :returns: A set of variable names.
1233 py_boolean_function.def(
1235 Translates the Boolean function into its string representation.
1237 :returns: The Boolean function as a string.
1241 py_boolean_function.def_static(
1251 log_error(
"python_context",
"{}", res.get_error().get());
1255 py::arg(
"expression"),
1257 Parses a Boolean function from a string expression.
1259 :param str expression: Boolean function string.
1260 :returns: The Boolean function on success, an empty Boolean function otherwise.
1261 :rtype: hal_py.BooleanFunction
1265 Simplifies the Boolean function.
1267 :returns: The simplified Boolean function.
1268 :rtype: hal_py.BooleanFunction
1271 py_boolean_function.def(
1272 "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
"(
1273 Substitute a variable name with another one, i.e., renames the variable.
1274 The operation is applied to all instances of the variable in the function.
1276 :param str old_variable_name: The old variable name to substitute.
1277 :param str new_variable_name: The new variable name.
1278 :returns: The resulting Boolean function.
1279 :rtype: hal_py.BooleanFunction
1282 py_boolean_function.def(
1285 auto res =
self.substitute(variable_name,
function);
1292 log_error(
"python_context",
"{}", res.get_error().get());
1293 return std::nullopt;
1296 py::arg(
"variable_name"),
1297 py::arg(
"function"),
1299 Substitute a variable with another Boolean function.
1300 The operation is applied to all instances of the variable in the function.
1302 :param str variable_name: The variable to substitute.
1303 :param hal_py.BooleanFunction function: The function replace the variable with.
1304 :returns: The resulting Boolean function on success, None otherwise.
1305 :rtype: hal_py.BooleanFunction or None
1308 py_boolean_function.def("substitute",
1310 py::arg(
"substitutions"),
1312 Substitute multiple variable names with different names at once, i.e., rename the variables.
1313 The operation is applied to all instances of the variable in the function.
1315 :param dict[str,str] substitutions: A dict from old variable names to new variable names.
1316 :returns: The resulting Boolean function.
1317 :rtype: hal_py.BooleanFunction
1320 py_boolean_function.def(
1322 [](
const BooleanFunction&
self,
const std::map<std::string, BooleanFunction>& substitutions) -> std::optional<BooleanFunction> {
1323 auto res =
self.substitute(substitutions);
1330 log_error(
"python_context",
"{}", res.get_error().get());
1331 return std::nullopt;
1334 py::arg(
"substitutions"),
1336 Substitute multiple variables with other boolean functions at once.
1337 The operation is applied to all instances of the variable in the function.
1339 :param dict substitutions: A map from the variable names to the function to replace the variable with.
1340 :returns: The resulting Boolean function on success, None otherwise.
1341 :rtype: hal_py.BooleanFunction or None
1344 py_boolean_function.def(
1346 [](
const BooleanFunction&
self,
const std::unordered_map<std::string, BooleanFunction::Value>& inputs) -> std::optional<BooleanFunction::Value> {
1347 auto res =
self.evaluate(inputs);
1354 log_error(
"python_context",
"{}", res.get_error().get());
1355 return std::nullopt;
1360 Evaluates a Boolean function comprising only single-bit variables using the given input values.
1362 :param dict[str,hal_py.BooleanFunction.Value] inputs: A dict from variable name to input value.
1363 :returns: The resulting value on success, None otherwise.
1364 :rtype: hal_py.BooleanFunction.Value or None
1367 py_boolean_function.def(
1369 [](
const BooleanFunction&
self,
const std::unordered_map<std::string, std::vector<BooleanFunction::Value>>& inputs) -> std::optional<std::vector<BooleanFunction::Value>> {
1370 auto res =
self.evaluate(inputs);
1377 log_error(
"python_context",
"{}", res.get_error().get());
1378 return std::nullopt;
1383 Evaluates a Boolean function comprising multi-bit variables using the given input values.
1385 :param dict[str,list[hal_py.BooleanFunction.Value]] inputs: A dict from variable name to a list of input values.
1386 :returns: A vector of values on success, None otherwise.
1387 :rtype: list[hal_py.BooleanFunction.Value] or None
1390 py_boolean_function.def(
1391 "compute_truth_table",
1392 [](
const BooleanFunction&
self,
const std::vector<std::string>& ordered_variables,
bool remove_unknown_variables) -> std::optional<std::vector<std::vector<BooleanFunction::Value>>> {
1393 auto res =
self.compute_truth_table(ordered_variables, remove_unknown_variables);
1400 log_error(
"python_context",
"{}", res.get_error().get());
1401 return std::nullopt;
1404 py::arg(
"ordered_variables") = std::vector<std::string>(),
1405 py::arg(
"remove_unknown_variables") =
false,
1407 Computes the truth table outputs for a Boolean function that comprises <= 10 single-bit variables.
1409 **Warning:** The generation of the truth table is exponential in the number of parameters.
1411 :param list[str] ordered_variables: A list describing the order of input variables used to generate the truth table. Defaults to an empty list.
1412 :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.
1413 :returns: A list of values representing the truth table output on success, None otherwise.
1414 :rtype: list[list[hal_py.BooleanFunction.Value]] or None
1417 py_boolean_function.def(
1418 "get_truth_table_as_string",
1419 [](
const BooleanFunction&
self,
const std::vector<std::string>& ordered_variables, std::string function_name,
bool remove_unknown_variables) -> std::optional<std::string> {
1420 auto res =
self.get_truth_table_as_string(ordered_variables, function_name, 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(
"function_name") = std::string(
""),
1433 py::arg(
"remove_unknown_variables") =
false,
1435 Prints the truth table for a Boolean function that comprises <= 10 single-bit variables.
1437 **Warning:** The generation of the truth table is exponential in the number of parameters.
1439 :param list[str] ordered_variables: A list describing the order of input variables used to generate the truth table. Defaults to an empty list.
1440 :param str function_name: The name of the Boolean function to be printed as header of the output columns.
1441 :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.
1442 :returns: A string representing the truth table on success, None otherwise.
1446 py::class_<BooleanFunction::Node> py_boolean_function_node(py_boolean_function, "Node", R
"(
1447 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).
1451 The type of the node.
1457 The bit-size of the node.
1463 The (optional) constant value of the node.
1465 :type: list[hal_py.BooleanFunction.Value]
1469 The (optional) index value of the node.
1475 The (optional) variable name of the node.
1481 Constructs an 'operation' node.
1483 :param int type: The type of the operation.
1484 :param int size: The bit-size of the operation.
1486 :rtype: hal_py.BooleanFunction.Node
1490 Constructs a 'constant' node.
1492 :param list[hal_py.BooleanFunction.Value] value: The constant value of the node.
1494 :rtype: hal_py.BooleanFunction.Node
1498 Constructs an 'index' node.
1500 :param int value: The index value of the node.
1501 :param int size: The bit-size of the node.
1503 :rtype: hal_py.BooleanFunction.Node
1507 Constructs a 'variable' node.
1509 :param int value: The variable name of the node.
1510 :param int size: The bit-size of the node.
1512 :rtype: hal_py.BooleanFunction.Node
1515 py_boolean_function_node.def(py::self == py::self, R"(
1516 Checks whether two Boolean function nodes are equal.
1518 :returns: True if both Boolean function nodes are equal, False otherwise.
1522 py_boolean_function_node.def(py::self != py::self, R"(
1523 Checks whether two Boolean function nodes are unequal.
1525 :returns: True if both Boolean function nodes are unequal, False otherwise.
1529 py_boolean_function_node.def(py::self < py::self, R"(
1530 Checks whether this Boolean function node is 'smaller' than the ``other`` Boolean function node.
1532 :returns: True if this Boolean function node is 'smaller', False otherwise.
1537 Clones the Boolean function node.
1539 :returns: The cloned Boolean function node.
1540 :rtype: hal_py.BooleanFunction.Node
1543 py_boolean_function_node.def(
1545 Translates the Boolean function node into its string representation.
1547 :returns: The Boolean function node as a string.
1552 The arity of the Boolean function node, i.e., the number of parameters.
1558 Returns the arity of the Boolean function node, i.e., the number of parameters.
1560 :returns: The arity.
1565 Returns the arity for a Boolean function node of the given type, i.e., the number of parameters.
1567 :returns: The arity.
1572 Checks whether the Boolean function node is of a specific type.
1574 :param int type: The type to check for.
1575 :returns: True if the node is of the given type, False otherwise.
1580 Checks whether the Boolean function node is of type Constant.
1582 :returns: True if the Boolean function node is of type Constant, False otherwise.
1587 Checks whether the Boolean function node is of type Constant and holds a specific value.
1589 :param list[hal_py.BooleanFunction.Value] value: The value to check for.
1590 :returns: True if the Boolean function node is of type Constant and holds the given value, False otherwise.
1595 Checks whether the Boolean function node is of type Constant and holds a specific value.
1597 :param int value: The value to check for.
1598 :returns: True if the Boolean function node is of type Constant and holds the given value, False otherwise.
1602 py_boolean_function_node.def(
1603 "get_constant_value",
1605 if (
const auto res =
self.get_constant_value(); res.is_ok())
1611 log_error(
"python_context",
"could not get constant value:\n{}", res.get_error().get());
1612 return std::nullopt;
1616 Get the constant value of the node of type ``Constant`` as a list of ``hal_py.BooleanFunction.Value``.
1618 :returns: The constant value on success, None otherwise.
1619 :rtype: list[hal_py.BooleanFunction.Value] or None
1622 py_boolean_function_node.def(
1623 "get_constant_value_u64",
1625 if (
const auto res =
self.get_constant_value_u64(); res.is_ok())
1631 log_error(
"python_context",
"could not get constant value:\n{}", res.get_error().get());
1632 return std::nullopt;
1636 Get the constant value of the node of type ``Constant`` as long as it has a size <= 64-bit.
1638 :returns: The constant value on success, None otherwise.
1643 Checks whether the Boolean function node is of type Index.
1645 :returns: True if the Boolean function node is of type Index, False otherwise.
1650 Checks whether the Boolean function node is of type Index and holds a specific value.
1652 :param int value: The value to check for.
1653 :returns: True if the Boolean function node is of type Index and holds the given value, False otherwise.
1657 py_boolean_function_node.def(
1660 if (
const auto res =
self.get_index_value(); res.is_ok())
1666 log_error(
"python_context",
"could not get index value:\n{}", res.get_error().get());
1667 return std::nullopt;
1671 Get the index value of node of type ``Index``.
1673 :returns: The index value on success, None otherwise.
1678 Checks whether the Boolean function node is of type Variable.
1680 :returns: True if the Boolean function node is of type Variable, False otherwise.
1685 Checks whether the Boolean function node is of type Variable and holds a specific variable name.
1687 :param str variable_name: The variable name to check for.
1688 :returns: True if the Boolean function node is of type Variable and holds the given variable name, False otherwise.
1692 py_boolean_function_node.def(
1693 "get_variable_name",
1695 if (
const auto res =
self.get_variable_name(); res.is_ok())
1701 log_error(
"python_context",
"could not get variable name:\n{}", res.get_error().get());
1702 return std::nullopt;
1706 Get the variable name of node of type ``Variable``.
1708 :returns: The variable name on success, None otherwise.
1713 Checks whether the Boolean function node is an operation node.
1715 :returns: True if the Boolean function node is an operation node, False otherwise.
1720 Checks whether the Boolean function node is an operand node.
1722 :returns: True if the Boolean function node is an operand node, False otherwise.
1727 Checks whether the Boolean function node is commutative.
1729 :returns: True if the Boolean function node is commutative, False otherwise.
1733 py::class_<BooleanFunction::NodeType> py_boolean_function_node_type(py_boolean_function, "NodeType", R
"(
1734 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 > 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