HAL  v4.5.0-257-ge24279b4e
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
boolean_function.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  py::class_<BooleanFunction> py_boolean_function(m,
8  "BooleanFunction",
9  R"(
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.
11  )");
12 
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.
15  )");
16 
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.)")
21  .export_values();
22 
23  py_boolean_function_value.def("__str__", [](const BooleanFunction::Value& v) { return BooleanFunction::to_string(v); }, R"(
24  Translates the Boolean function value into its string representation.
25 
26  :returns: The value as a string.
27  :rtype: str
28  )");
29 
30  py_boolean_function.def_static(
31  "build",
32  [](const std::vector<BooleanFunction::Node>& nodes) -> std::optional<BooleanFunction> {
33  std::vector<BooleanFunction::Node> nodes_cloned;
34  for (const auto& node : nodes)
35  {
36  nodes_cloned.push_back(node.clone());
37  }
38 
39  auto res = BooleanFunction::build(std::move(nodes_cloned));
40  if (res.is_ok())
41  {
42  return res.get();
43  }
44  else
45  {
46  log_error("python_context", "{}", res.get_error().get());
47  return std::nullopt;
48  }
49  },
50  py::arg("nodes"),
51  R"(
52  Builds and validates a Boolean function from a list of nodes.
53 
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
57  )");
58 
59  py_boolean_function.def_static(
60  "to_string",
61  [](const std::vector<BooleanFunction::Value>& value, u8 base = 2) -> std::optional<std::string> {
62  auto res = BooleanFunction::to_string(value, base);
63  if (res.is_ok())
64  {
65  return res.get();
66  }
67  else
68  {
69  log_error("python_context", "{}", res.get_error().get());
70  return std::nullopt;
71  }
72  },
73  py::arg("value"),
74  py::arg("base") = 2,
75  R"(
76  Convert the given bit-vector to its string representation in the given base.
77 
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.
81  :rtype: str or None
82  )");
83 
84  py_boolean_function.def_static(
85  "to_u64",
86  [](const std::vector<BooleanFunction::Value>& value) -> std::optional<u64> {
87  auto res = BooleanFunction::to_u64(value);
88  if (res.is_ok())
89  {
90  return res.get();
91  }
92  else
93  {
94  log_error("python_context", "{}", res.get_error().get());
95  return std::nullopt;
96  }
97  },
98  py::arg("value"),
99  R"(
100  Convert the given bit-vector to its unsigned 64-bit integer representation.
101 
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.
104  :rtype: int or None
105  )");
106 
107  py_boolean_function.def(py::init<>(), R"(
108  Constructs an empty / invalid Boolean function.
109  )");
110 
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.
113 
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
118  )");
119 
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.
122 
123  :param hal_py.BooleanFunction.Value value: The value.
124  :returns: The Boolean function.
125  :rtype: hal_py.BooleanFunction
126  )");
127 
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.
130 
131  :param list[hal_py.BooleanFunction.Value] value: The list of values.
132  :returns: The Boolean function.
133  :rtype: hal_py.BooleanFunction
134  )");
135 
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.
138 
139  :param int value: The integer value.
140  :param int size: The bit-size.
141  :returns: The Boolean function.
142  :rtype: hal_py.BooleanFunction
143  )");
144 
145  py_boolean_function.def_static("Index", &BooleanFunction::Index, py::arg("index"), py::arg("size"), R"(
146  Creates an index for a Boolean function of the given bit-size from an integer value.
147 
148  :param int index: The integer value.
149  :param int size: The bit-size.
150  :returns: The Boolean function.
151  :rtype: hal_py.BooleanFunction
152  )");
153 
154  py_boolean_function.def_static(
155  "And",
156  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
157  auto res = BooleanFunction::And(std::move(p0), std::move(p1), size);
158  if (res.is_ok())
159  {
160  return res.get();
161  }
162  else
163  {
164  log_error("python_context", "{}", res.get_error().get());
165  return std::nullopt;
166  }
167  },
168  py::arg("p0"),
169  py::arg("p1"),
170  py::arg("size"),
171  R"(
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.
174 
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
180  )");
181 
182  py_boolean_function.def_static(
183  "Or",
184  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
185  auto res = BooleanFunction::Or(std::move(p0), std::move(p1), size);
186  if (res.is_ok())
187  {
188  return res.get();
189  }
190  else
191  {
192  log_error("python_context", "{}", res.get_error().get());
193  return std::nullopt;
194  }
195  },
196  py::arg("p0"),
197  py::arg("p1"),
198  py::arg("size"),
199  R"(
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.
202 
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
208  )");
209 
210  py_boolean_function.def_static(
211  "Not",
212  [](BooleanFunction p0, u16 size) -> std::optional<BooleanFunction> {
213  auto res = BooleanFunction::Not(std::move(p0), size);
214  if (res.is_ok())
215  {
216  return res.get();
217  }
218  else
219  {
220  log_error("python_context", "{}", res.get_error().get());
221  return std::nullopt;
222  }
223  },
224  py::arg("p0"),
225  py::arg("size"),
226  R"(
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.
229 
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
234  )");
235 
236  py_boolean_function.def_static(
237  "Xor",
238  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
239  auto res = BooleanFunction::Xor(std::move(p0), std::move(p1), size);
240  if (res.is_ok())
241  {
242  return res.get();
243  }
244  else
245  {
246  log_error("python_context", "{}", res.get_error().get());
247  return std::nullopt;
248  }
249  },
250  py::arg("p0"),
251  py::arg("p1"),
252  py::arg("size"),
253  R"(
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.
256 
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
262  )");
263 
264  py_boolean_function.def_static(
265  "Add",
266  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
267  auto res = BooleanFunction::Add(std::move(p0), std::move(p1), size);
268  if (res.is_ok())
269  {
270  return res.get();
271  }
272  else
273  {
274  log_error("python_context", "{}", res.get_error().get());
275  return std::nullopt;
276  }
277  },
278  py::arg("p0"),
279  py::arg("p1"),
280  py::arg("size"),
281  R"(
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.
284 
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
290  )");
291 
292  py_boolean_function.def_static(
293  "Sub",
294  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
295  auto res = BooleanFunction::Sub(std::move(p0), std::move(p1), size);
296  if (res.is_ok())
297  {
298  return res.get();
299  }
300  else
301  {
302  log_error("python_context", "{}", res.get_error().get());
303  return std::nullopt;
304  }
305  },
306  py::arg("p0"),
307  py::arg("p1"),
308  py::arg("size"),
309  R"(
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.
312 
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
318  )");
319 
320  py_boolean_function.def_static(
321  "Mul",
322  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
323  auto res = BooleanFunction::Mul(std::move(p0), std::move(p1), size);
324  if (res.is_ok())
325  {
326  return res.get();
327  }
328  else
329  {
330  log_error("python_context", "{}", res.get_error().get());
331  return std::nullopt;
332  }
333  },
334  py::arg("p0"),
335  py::arg("p1"),
336  py::arg("size"),
337  R"(
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.
340 
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
346  )");
347 
348  py_boolean_function.def_static(
349  "Sdiv",
350  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
351  auto res = BooleanFunction::Sdiv(std::move(p0), std::move(p1), size);
352  if (res.is_ok())
353  {
354  return res.get();
355  }
356  else
357  {
358  log_error("python_context", "{}", res.get_error().get());
359  return std::nullopt;
360  }
361  },
362  py::arg("p0"),
363  py::arg("p1"),
364  py::arg("size"),
365  R"(
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.
368 
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
374  )");
375 
376  py_boolean_function.def_static(
377  "Udiv",
378  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
379  auto res = BooleanFunction::Udiv(std::move(p0), std::move(p1), size);
380  if (res.is_ok())
381  {
382  return res.get();
383  }
384  else
385  {
386  log_error("python_context", "{}", res.get_error().get());
387  return std::nullopt;
388  }
389  },
390  py::arg("p0"),
391  py::arg("p1"),
392  py::arg("size"),
393  R"(
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.
396 
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
402  )");
403 
404  py_boolean_function.def_static(
405  "Srem",
406  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
407  auto res = BooleanFunction::Srem(std::move(p0), std::move(p1), size);
408  if (res.is_ok())
409  {
410  return res.get();
411  }
412  else
413  {
414  log_error("python_context", "{}", res.get_error().get());
415  return std::nullopt;
416  }
417  },
418  py::arg("p0"),
419  py::arg("p1"),
420  py::arg("size"),
421  R"(
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.
424 
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
430  )");
431 
432  py_boolean_function.def_static(
433  "Urem",
434  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
435  auto res = BooleanFunction::Urem(std::move(p0), std::move(p1), size);
436  if (res.is_ok())
437  {
438  return res.get();
439  }
440  else
441  {
442  log_error("python_context", "{}", res.get_error().get());
443  return std::nullopt;
444  }
445  },
446  py::arg("p0"),
447  py::arg("p1"),
448  py::arg("size"),
449  R"(
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.
452 
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
458  )");
459 
460  py_boolean_function.def_static(
461  "Slice",
462  [](BooleanFunction p0, BooleanFunction p1, BooleanFunction p2, u16 size) -> std::optional<BooleanFunction> {
463  auto res = BooleanFunction::Slice(std::move(p0), std::move(p1), std::move(p2), size);
464  if (res.is_ok())
465  {
466  return res.get();
467  }
468  else
469  {
470  log_error("python_context", "{}", res.get_error().get());
471  return std::nullopt;
472  }
473  },
474  py::arg("p0"),
475  py::arg("p1"),
476  py::arg("p2"),
477  py::arg("size"),
478  R"(
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.
481 
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
488  )");
489 
490  py_boolean_function.def_static(
491  "Concat",
492  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
493  auto res = BooleanFunction::Concat(std::move(p0), std::move(p1), size);
494  if (res.is_ok())
495  {
496  return res.get();
497  }
498  else
499  {
500  log_error("python_context", "{}", res.get_error().get());
501  return std::nullopt;
502  }
503  },
504  py::arg("p0"),
505  py::arg("p1"),
506  py::arg("size"),
507  R"(
508  Concatenates two Boolean functions of bit-sizes ``n`` and ``m`` to form a single Boolean function of bit-size ``n + m``.
509 
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
515  )");
516 
517  py_boolean_function.def_static(
518  "Zext",
519  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
520  auto res = BooleanFunction::Zext(std::move(p0), std::move(p1), size);
521  if (res.is_ok())
522  {
523  return res.get();
524  }
525  else
526  {
527  log_error("python_context", "{}", res.get_error().get());
528  return std::nullopt;
529  }
530  },
531  py::arg("p0"),
532  py::arg("p1"),
533  py::arg("size"),
534  R"(
535  Zero-extends a Boolean function to the specified bit-size.
536 
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
542  )");
543 
544  py_boolean_function.def_static(
545  "Sext",
546  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
547  auto res = BooleanFunction::Sext(std::move(p0), std::move(p1), size);
548  if (res.is_ok())
549  {
550  return res.get();
551  }
552  else
553  {
554  log_error("python_context", "{}", res.get_error().get());
555  return std::nullopt;
556  }
557  },
558  py::arg("p0"),
559  py::arg("p1"),
560  py::arg("size"),
561  R"(
562  Sign-extends a Boolean function to the specified bit-size.
563 
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
569  )");
570 
571  py_boolean_function.def_static(
572  "Shl",
573  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
574  auto res = BooleanFunction::Shl(std::move(p0), std::move(p1), size);
575  if (res.is_ok())
576  {
577  return res.get();
578  }
579  else
580  {
581  log_error("python_context", "{}", res.get_error().get());
582  return std::nullopt;
583  }
584  },
585  py::arg("p0"),
586  py::arg("p1"),
587  py::arg("size"),
588  R"(
589  Shifts a Boolean function to the left by the specified number of bits.
590 
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
596  )");
597 
598  py_boolean_function.def_static(
599  "Lshr",
600  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
601  auto res = BooleanFunction::Lshr(std::move(p0), std::move(p1), size);
602  if (res.is_ok())
603  {
604  return res.get();
605  }
606  else
607  {
608  log_error("python_context", "{}", res.get_error().get());
609  return std::nullopt;
610  }
611  },
612  py::arg("p0"),
613  py::arg("p1"),
614  py::arg("size"),
615  R"(
616  Logically shifts a Boolean function to the right by the specified number of bits.
617 
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
623  )");
624 
625  py_boolean_function.def_static(
626  "Ashr",
627  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
628  auto res = BooleanFunction::Ashr(std::move(p0), std::move(p1), size);
629  if (res.is_ok())
630  {
631  return res.get();
632  }
633  else
634  {
635  log_error("python_context", "{}", res.get_error().get());
636  return std::nullopt;
637  }
638  },
639  py::arg("p0"),
640  py::arg("p1"),
641  py::arg("size"),
642  R"(
643  Arithmetically shifts a Boolean function to the right by the specified number of bits.
644 
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
650  )");
651 
652  py_boolean_function.def_static(
653  "Rol",
654  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
655  auto res = BooleanFunction::Rol(std::move(p0), std::move(p1), size);
656  if (res.is_ok())
657  {
658  return res.get();
659  }
660  else
661  {
662  log_error("python_context", "{}", res.get_error().get());
663  return std::nullopt;
664  }
665  },
666  py::arg("p0"),
667  py::arg("p1"),
668  py::arg("size"),
669  R"(
670  Rotates a Boolean function to the left by the specified number of bits.
671 
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
677  )");
678 
679  py_boolean_function.def_static(
680  "Ror",
681  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
682  auto res = BooleanFunction::Ror(std::move(p0), std::move(p1), size);
683  if (res.is_ok())
684  {
685  return res.get();
686  }
687  else
688  {
689  log_error("python_context", "{}", res.get_error().get());
690  return std::nullopt;
691  }
692  },
693  py::arg("p0"),
694  py::arg("p1"),
695  py::arg("size"),
696  R"(
697  Rotates a Boolean function to the right by the specified number of bits.
698 
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
704  )");
705 
706  py_boolean_function.def_static(
707  "Eq",
708  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
709  auto res = BooleanFunction::Eq(std::move(p0), std::move(p1), size);
710  if (res.is_ok())
711  {
712  return res.get();
713  }
714  else
715  {
716  log_error("python_context", "{}", res.get_error().get());
717  return std::nullopt;
718  }
719  },
720  py::arg("p0"),
721  py::arg("p1"),
722  py::arg("size"),
723  R"(
724  Joins two Boolean functions by an equality check that produces a single-bit result.
725 
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
731  )");
732 
733  py_boolean_function.def_static(
734  "Sle",
735  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
736  auto res = BooleanFunction::Sle(std::move(p0), std::move(p1), size);
737  if (res.is_ok())
738  {
739  return res.get();
740  }
741  else
742  {
743  log_error("python_context", "{}", res.get_error().get());
744  return std::nullopt;
745  }
746  },
747  py::arg("p0"),
748  py::arg("p1"),
749  py::arg("size"),
750  R"(
751  Joins two Boolean functions by a signed less-than-equal check that produces a single-bit result.
752 
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
758  )");
759 
760  py_boolean_function.def_static(
761  "Slt",
762  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
763  auto res = BooleanFunction::Slt(std::move(p0), std::move(p1), size);
764  if (res.is_ok())
765  {
766  return res.get();
767  }
768  else
769  {
770  log_error("python_context", "{}", res.get_error().get());
771  return std::nullopt;
772  }
773  },
774  py::arg("p0"),
775  py::arg("p1"),
776  py::arg("size"),
777  R"(
778  Joins two Boolean functions by a signed less-than check that produces a single-bit result.
779 
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
785  )");
786 
787  py_boolean_function.def_static(
788  "Ule",
789  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
790  auto res = BooleanFunction::Ule(std::move(p0), std::move(p1), size);
791  if (res.is_ok())
792  {
793  return res.get();
794  }
795  else
796  {
797  log_error("python_context", "{}", res.get_error().get());
798  return std::nullopt;
799  }
800  },
801  py::arg("p0"),
802  py::arg("p1"),
803  py::arg("size"),
804  R"(
805  Joins two Boolean functions by an unsigned less-than-equal check that produces a single-bit result.
806 
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
812  )");
813 
814  py_boolean_function.def_static(
815  "Ult",
816  [](BooleanFunction p0, BooleanFunction p1, u16 size) -> std::optional<BooleanFunction> {
817  auto res = BooleanFunction::Ult(std::move(p0), std::move(p1), size);
818  if (res.is_ok())
819  {
820  return res.get();
821  }
822  else
823  {
824  log_error("python_context", "{}", res.get_error().get());
825  return std::nullopt;
826  }
827  },
828  py::arg("p0"),
829  py::arg("p1"),
830  py::arg("size"),
831  R"(
832  Joins two Boolean functions by an unsigned less-than check that produces a single-bit result.
833 
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
839  )");
840 
841  py_boolean_function.def_static(
842  "Ite",
843  [](BooleanFunction p0, BooleanFunction p1, BooleanFunction p2, u16 size) -> std::optional<BooleanFunction> {
844  auto res = BooleanFunction::Ite(std::move(p0), std::move(p1), std::move(p2), size);
845  if (res.is_ok())
846  {
847  return res.get();
848  }
849  else
850  {
851  log_error("python_context", "{}", res.get_error().get());
852  return std::nullopt;
853  }
854  },
855  py::arg("p0"),
856  py::arg("p1"),
857  py::arg("p2"),
858  py::arg("size"),
859  R"(
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``.
863 
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
870  )");
871 
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.
875 
876  **Warning:** fails if the Boolean functions have different bit-sizes.
877 
878  :returns: The joined Boolean function.
879  :rtype: hal_py.BooleanFunction
880  )");
881 
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.
885 
886  **Warning:** fails if the Boolean functions have different bit-sizes.
887 
888  :returns: The joined Boolean function.
889  :rtype: hal_py.BooleanFunction
890  )");
891 
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.
895 
896  **Warning:** fails if the Boolean functions have different bit-sizes.
897 
898  :returns: The joined Boolean function.
899  :rtype: hal_py.BooleanFunction
900  )");
901 
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.
905 
906  **Warning:** fails if the Boolean functions have different bit-sizes.
907 
908  :returns: The joined Boolean function.
909  :rtype: hal_py.BooleanFunction
910  )");
911 
912  py_boolean_function.def(~py::self, R"(
913  Negates the Boolean function.
914 
915  :returns: The negated Boolean function.
916  :rtype: hal_py.BooleanFunction
917  )");
918 
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.
922 
923  **Warning:** fails if the Boolean functions have different bit-sizes.
924 
925  :returns: The joined Boolean function.
926  :rtype: hal_py.BooleanFunction
927  )");
928 
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.
932 
933  **Warning:** fails if the Boolean functions have different bit-sizes.
934 
935  :returns: The joined Boolean function.
936  :rtype: hal_py.BooleanFunction
937  )");
938 
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.
942 
943  **Warning:** fails if the Boolean functions have different bit-sizes.
944 
945  :returns: The joined Boolean function.
946  :rtype: hal_py.BooleanFunction
947  )");
948 
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.
952 
953  **Warning:** fails if the Boolean functions have different bit-sizes.
954 
955  :returns: The joined Boolean function.
956  :rtype: hal_py.BooleanFunction
957  )");
958 
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.
962 
963  **Warning:** fails if the Boolean functions have different bit-sizes.
964 
965  :returns: The joined Boolean function.
966  :rtype: hal_py.BooleanFunction
967  )");
968 
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.
972 
973  **Warning:** fails if the Boolean functions have different bit-sizes.
974 
975  :returns: The joined Boolean function.
976  :rtype: hal_py.BooleanFunction
977  )");
978 
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.
982 
983  **Warning:** fails if the Boolean functions have different bit-sizes.
984 
985  :returns: The joined Boolean function.
986  :rtype: hal_py.BooleanFunction
987  )");
988 
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.
992 
993  **Warning:** fails if the Boolean functions have different bit-sizes.
994 
995  :returns: The joined Boolean function.
996  :rtype: hal_py.BooleanFunction
997  )");
998 
999  py_boolean_function.def(py::self == py::self, R"(
1000  Checks whether two Boolean functions are equal.
1001 
1002  :returns: ``True`` if both Boolean functions are equal, ``False`` otherwise.
1003  :rtype: bool
1004  )");
1005 
1006  py_boolean_function.def(py::self != py::self, R"(
1007  Checks whether two Boolean functions are unequal.
1008 
1009  :returns: ``True`` if both Boolean functions are unequal, ``False`` otherwise.
1010  :rtype: bool
1011  )");
1012 
1013  py_boolean_function.def(py::self < py::self, R"(
1014  Checks whether this Boolean function is 'smaller' than the ``other`` Boolean function.
1015 
1016  :returns: ``True`` if this Boolean function is 'smaller', ``False`` otherwise.
1017  :rtype: bool
1018  )");
1019 
1020  py_boolean_function.def("is_empty", &BooleanFunction::is_empty, R"(
1021  Checks whether the Boolean function is empty.
1022 
1023  :returns: ``True`` if the Boolean function is empty, ``False`` otherwise.
1024  :rtype: bool
1025  )");
1026 
1027  py_boolean_function.def("clone", &BooleanFunction::clone, R"(
1028  Clones the Boolean function.
1029 
1030  :returns: The cloned Boolean function.
1031  :rtype: hal_py.BooleanFunction
1032  )");
1033 
1034  py_boolean_function.def_property_readonly("size", &BooleanFunction::size, R"(
1035  The bit-size of the Boolean function.
1036 
1037  :type: int
1038  )");
1039 
1040  py_boolean_function.def("get_size", &BooleanFunction::size, R"(
1041  Returns the bit-size of the Boolean function.
1042 
1043  :returns: The bit-size of the Boolean function.
1044  :rtype: int
1045  )");
1046 
1047  py_boolean_function.def("is", &BooleanFunction::is, py::arg("type"), R"(
1048  Checks whether the top-level node of the Boolean function is of a specific type.
1049 
1050  :param int type: The type to check for.
1051  :returns: ``True`` if the node is of the given type, ``False`` otherwise.
1052  :rtype: bool
1053  )");
1054 
1055  py_boolean_function.def("is_variable", &BooleanFunction::is_variable, R"(
1056  Checks whether the top-level node of the Boolean function is of type ``Variable``.
1057 
1058  :returns: ``True`` if the top-level node of the Boolean function is of type Variable, ``False`` otherwise.
1059  :rtype: bool
1060  )");
1061 
1062  py_boolean_function.def("has_variable_name", &BooleanFunction::has_variable_name, py::arg("value"), R"(
1063  Checks whether the top-level node of the Boolean function is of type Variable and holds a specific variable name.
1064 
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.
1067  :rtype: bool
1068  )");
1069 
1070  py_boolean_function.def(
1071  "get_variable_name",
1072  [](const BooleanFunction& self) -> std::optional<std::string> {
1073  auto res = self.get_variable_name();
1074  if (res.is_ok())
1075  {
1076  return res.get();
1077  }
1078  else
1079  {
1080  log_error("python_context", "{}", res.get_error().get());
1081  return std::nullopt;
1082  }
1083  },
1084  R"(
1085  Get the variable name of the top-level node of the Boolean function of type Variable.
1086 
1087  :returns: The variable name on success, ``None`` otherwise.
1088  :rtype: str or None
1089  )");
1090 
1091  py_boolean_function.def("is_constant", &BooleanFunction::is_constant, R"(
1092  Checks whether the top-level node of the Boolean function is of type Constant.
1093 
1094  :returns: ``True`` if the top-level node of the Boolean function is of type Constant, ``False`` otherwise.
1095  :rtype: bool
1096  )");
1097 
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.
1100 
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.
1103  :rtype: bool
1104  )");
1105 
1106  py_boolean_function.def("has_constant_value", py::overload_cast<u64>(&BooleanFunction::has_constant_value, py::const_), py::arg("value"), R"(
1107  Checks whether the top-level node of the Boolean function is of type Constant and holds a specific value.
1108 
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.
1111  :rtype: bool
1112  )");
1113 
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();
1118  if (res.is_ok())
1119  {
1120  return res.get();
1121  }
1122  else
1123  {
1124  log_error("python_context", "{}", res.get_error().get());
1125  return std::nullopt;
1126  }
1127  },
1128  R"(
1129  Get the value of the top-level node of the Boolean function of type ``Constant`` as a list of ``hal_py.BooleanFunction.Value``.
1130 
1131  :returns: The constant value on success, ``None`` otherwise.
1132  :rtype: list[hal_py.BooleanFunction.Value] or None
1133  )");
1134 
1135  py_boolean_function.def(
1136  "get_constant_value_u64",
1137  [](const BooleanFunction& self) -> std::optional<u64> {
1138  auto res = self.get_constant_value_u64();
1139  if (res.is_ok())
1140  {
1141  return res.get();
1142  }
1143  else
1144  {
1145  log_error("python_context", "{}", res.get_error().get());
1146  return std::nullopt;
1147  }
1148  },
1149  R"(
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.
1151 
1152  :returns: The constant value on success, ``None`` otherwise.
1153  :rtype: int or None
1154  )");
1155 
1156  py_boolean_function.def("is_index", &BooleanFunction::is_index, R"(
1157  Checks whether the top-level node of the Boolean function is of type Index.
1158 
1159  :returns: ``True`` if the top-level node of the Boolean function is of type Index, ``False`` otherwise.
1160  :rtype: bool
1161  )");
1162 
1163  py_boolean_function.def("has_index_value", &BooleanFunction::has_index_value, py::arg("value"), R"(
1164  Checks whether the top-level node of the Boolean function is of type Index and holds a specific value.
1165 
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.
1168  :rtype: bool
1169  )");
1170 
1171  py_boolean_function.def(
1172  "get_index_value",
1173  [](const BooleanFunction& self) -> std::optional<u16> {
1174  auto res = self.get_index_value();
1175  if (res.is_ok())
1176  {
1177  return res.get();
1178  }
1179  else
1180  {
1181  log_error("python_context", "{}", res.get_error().get());
1182  return std::nullopt;
1183  }
1184  },
1185  R"(
1186  Get the index value of the top-level node of the Boolean function of type Index.
1187 
1188  :returns: The index value on success, ``None`` otherwise.
1189  :rtype: int or None
1190  )");
1191 
1192  py_boolean_function.def_property_readonly("top_level_node", &BooleanFunction::get_top_level_node, R"(
1193  The top-level node of the Boolean function.
1194 
1195  **Warning:** fails if the Boolean function is empty.
1196 
1197  :type: hal_py.BooleanFunction.Node
1198  )");
1199 
1200  py_boolean_function.def("get_top_level_node", &BooleanFunction::get_top_level_node, R"(
1201  Returns the top-level node of the Boolean function.
1202 
1203  **Warning:** fails if the Boolean function is empty.
1204 
1205  :returns: The top-level node.
1206  :rtype: hal_py.BooleanFunction.Node
1207  )");
1208 
1209  py_boolean_function.def_property_readonly("length", &BooleanFunction::length, R"(
1210  The number of nodes in the Boolean function.
1211 
1212  :type: int
1213  )");
1214 
1215  py_boolean_function.def("get_length", &BooleanFunction::length, R"(
1216  Returns the number of nodes in the Boolean function.
1217 
1218  :returns: The number of nodes.
1219  :rtype: int
1220  )");
1221 
1222  py_boolean_function.def_property_readonly("nodes", &BooleanFunction::get_nodes, R"(
1223  The reverse polish notation list of the Boolean function nodes.
1224 
1225  :type: list[hal_py.BooleanFunction.Node]
1226  )");
1227 
1228  py_boolean_function.def("get_nodes", &BooleanFunction::get_nodes, R"(
1229  Returns the reverse polish notation list of the Boolean function nodes.
1230 
1231  :returns: A list of nodes.
1232  :rtype: list[hal_py.BooleanFunction.Node]
1233  )");
1234 
1235  py_boolean_function.def_property_readonly("parameters", &BooleanFunction::get_parameters, R"(
1236  The parameter list of the top-level node of the Boolean function.
1237 
1238  :type: list[hal_py.BooleanFunction]
1239  )");
1240 
1241  py_boolean_function.def("get_parameters", &BooleanFunction::get_parameters, R"(
1242  Returns the parameter list of the top-level node of the Boolean function.
1243 
1244  :returns: A list of Boolean functions.
1245  :rtype: list[hal_py.BooleanFunction]
1246  )");
1247 
1248  py_boolean_function.def_property_readonly("variable_names", &BooleanFunction::get_variable_names, R"(
1249  The set of variable names used by the Boolean function.
1250 
1251  :type: set[str]
1252  )");
1253 
1254  py_boolean_function.def("get_variable_names", &BooleanFunction::get_variable_names, R"(
1255  Returns the set of variable names used by the Boolean function.
1256 
1257  :returns: A set of variable names.
1258  :rtype: set[str]
1259  )");
1260 
1261  py_boolean_function.def("__str__", [](const BooleanFunction& f) { return f.to_string(); }, R"(
1262  Translates the Boolean function into its string representation.
1263 
1264  :returns: The Boolean function as a string.
1265  :rtype: str
1266  )");
1267 
1268  py_boolean_function.def_static(
1269  "from_string",
1270  [](const std::string& expression, const std::map<std::string, u16>& var_sizes) -> BooleanFunction {
1271  auto res = BooleanFunction::from_string(expression, var_sizes);
1272  if (res.is_ok())
1273  {
1274  return res.get();
1275  }
1276  else
1277  {
1278  log_error("python_context", "{}", res.get_error().get());
1279  return BooleanFunction();
1280  }
1281  },
1282  py::arg("expression"),
1283  py::arg("var_sizes") = std::map<std::string, u16>{},
1284  R"(
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.
1287 
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
1292  )");
1293 
1294  py_boolean_function.def("simplify", &BooleanFunction::simplify, R"(
1295  Simplifies the Boolean function.
1296 
1297  :returns: The simplified Boolean function.
1298  :rtype: hal_py.BooleanFunction
1299  )");
1300 
1301  py_boolean_function.def("simplify_local", &BooleanFunction::simplify_local, R"(
1302  Simplifies the Boolean function using only the local simplification, i.e., without invoking ABC.
1303 
1304  :returns: The simplified Boolean function.
1305  :rtype: hal_py.BooleanFunction
1306  )");
1307 
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.
1312 
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
1317  )");
1318 
1319  py_boolean_function.def(
1320  "substitute",
1321  [](const BooleanFunction& self, const std::string& variable_name, const BooleanFunction& function) -> std::optional<BooleanFunction> {
1322  auto res = self.substitute(variable_name, function);
1323  if (res.is_ok())
1324  {
1325  return res.get();
1326  }
1327  else
1328  {
1329  log_error("python_context", "{}", res.get_error().get());
1330  return std::nullopt;
1331  }
1332  },
1333  py::arg("variable_name"),
1334  py::arg("function"),
1335  R"(
1336  Substitute a variable with another Boolean function.
1337  The operation is applied to all instances of the variable in the function.
1338 
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
1343  )");
1344 
1345  py_boolean_function.def("substitute",
1346  py::overload_cast<const std::map<std::string, std::string>&>(&BooleanFunction::substitute, py::const_),
1347  py::arg("substitutions"),
1348  R"(
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.
1351 
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
1355  )");
1356 
1357  py_boolean_function.def(
1358  "substitute",
1359  [](const BooleanFunction& self, const std::map<std::string, BooleanFunction>& substitutions) -> std::optional<BooleanFunction> {
1360  auto res = self.substitute(substitutions);
1361  if (res.is_ok())
1362  {
1363  return res.get();
1364  }
1365  else
1366  {
1367  log_error("python_context", "{}", res.get_error().get());
1368  return std::nullopt;
1369  }
1370  },
1371  py::arg("substitutions"),
1372  R"(
1373  Substitute multiple variables with Boolean functions at once.
1374  The operation is applied to all instances of the variable in the function.
1375 
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
1379  )");
1380 
1381  py_boolean_function.def(
1382  "evaluate",
1383  [](const BooleanFunction& self, const std::unordered_map<std::string, BooleanFunction::Value>& inputs) -> std::optional<BooleanFunction::Value> {
1384  auto res = self.evaluate(inputs);
1385  if (res.is_ok())
1386  {
1387  return res.get();
1388  }
1389  else
1390  {
1391  log_error("python_context", "{}", res.get_error().get());
1392  return std::nullopt;
1393  }
1394  },
1395  py::arg("inputs"),
1396  R"(
1397  Evaluates a Boolean function comprising only single-bit variables using the given input values.
1398 
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
1402  )");
1403 
1404  py_boolean_function.def(
1405  "evaluate",
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);
1408  if (res.is_ok())
1409  {
1410  return res.get();
1411  }
1412  else
1413  {
1414  log_error("python_context", "{}", res.get_error().get());
1415  return std::nullopt;
1416  }
1417  },
1418  py::arg("inputs"),
1419  R"(
1420  Evaluates a Boolean function comprising multi-bit variables using the given input values.
1421 
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
1425  )");
1426 
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);
1431  if (res.is_ok())
1432  {
1433  return res.get();
1434  }
1435  else
1436  {
1437  log_error("python_context", "{}", res.get_error().get());
1438  return std::nullopt;
1439  }
1440  },
1441  py::arg("ordered_variables") = std::vector<std::string>(),
1442  py::arg("remove_unknown_variables") = false,
1443  R"(
1444  Computes the truth table outputs for a Boolean function that comprises <= 20 single-bit variables.
1445 
1446  **Warning:** The generation of the truth table is exponential in the number of parameters.
1447 
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
1452  )");
1453 
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);
1458  if (res.is_ok())
1459  {
1460  return res.get();
1461  }
1462  else
1463  {
1464  log_error("python_context", "{}", res.get_error().get());
1465  return std::nullopt;
1466  }
1467  },
1468  py::arg("ordered_variables") = std::vector<std::string>(),
1469  py::arg("function_name") = std::string(""),
1470  py::arg("remove_unknown_variables") = false,
1471  R"(
1472  Prints the truth table for a Boolean function that comprises <= 20 single-bit variables.
1473 
1474  **Warning:** The generation of the truth table is exponential in the number of parameters.
1475 
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.
1480  :rtype: str or None
1481  )");
1482 
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).
1485  )");
1486 
1487  py_boolean_function_node.def_readwrite("type", &BooleanFunction::Node::type, R"(
1488  The type of the node.
1489 
1490  :type: int
1491  )");
1492 
1493  py_boolean_function_node.def_readwrite("size", &BooleanFunction::Node::size, R"(
1494  The bit-size of the node.
1495 
1496  :type: int
1497  )");
1498 
1499  py_boolean_function_node.def_readwrite("constant", &BooleanFunction::Node::constant, R"(
1500  The (optional) constant value of the node.
1501 
1502  :type: list[hal_py.BooleanFunction.Value]
1503  )");
1504 
1505  py_boolean_function_node.def_readwrite("index", &BooleanFunction::Node::index, R"(
1506  The (optional) index value of the node.
1507 
1508  :type: int
1509  )");
1510 
1511  py_boolean_function_node.def_readwrite("variable", &BooleanFunction::Node::variable, R"(
1512  The (optional) variable name of the node.
1513 
1514  :type: str
1515  )");
1516 
1517  py_boolean_function_node.def_static("Operation", BooleanFunction::Node::Operation, py::arg("type"), py::arg("size"), R"(
1518  Constructs an 'operation' node.
1519 
1520  :param int type: The type of the operation.
1521  :param int size: The bit-size of the operation.
1522  :returns: The node.
1523  :rtype: hal_py.BooleanFunction.Node
1524  )");
1525 
1526  py_boolean_function_node.def_static("Constant", BooleanFunction::Node::Constant, py::arg("value"), R"(
1527  Constructs a 'constant' node.
1528 
1529  :param list[hal_py.BooleanFunction.Value] value: The constant value of the node.
1530  :returns: The node.
1531  :rtype: hal_py.BooleanFunction.Node
1532  )");
1533 
1534  py_boolean_function_node.def_static("Index", BooleanFunction::Node::Index, py::arg("index"), py::arg("size"), R"(
1535  Constructs an 'index' node.
1536 
1537  :param int value: The index value of the node.
1538  :param int size: The bit-size of the node.
1539  :returns: The node.
1540  :rtype: hal_py.BooleanFunction.Node
1541  )");
1542 
1543  py_boolean_function_node.def_static("Variable", BooleanFunction::Node::Variable, py::arg("variable"), py::arg("size"), R"(
1544  Constructs a 'variable' node.
1545 
1546  :param int value: The variable name of the node.
1547  :param int size: The bit-size of the node.
1548  :returns: The node.
1549  :rtype: hal_py.BooleanFunction.Node
1550  )");
1551 
1552  py_boolean_function_node.def(py::self == py::self, R"(
1553  Checks whether two Boolean function nodes are equal.
1554 
1555  :returns: ``True`` if both Boolean function nodes are equal, ``False`` otherwise.
1556  :rtype: bool
1557  )");
1558 
1559  py_boolean_function_node.def(py::self != py::self, R"(
1560  Checks whether two Boolean function nodes are unequal.
1561 
1562  :returns: ``True`` if both Boolean function nodes are unequal, ``False`` otherwise.
1563  :rtype: bool
1564  )");
1565 
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.
1568 
1569  :returns: ``True`` if this Boolean function node is 'smaller', ``False`` otherwise.
1570  :rtype: bool
1571  )");
1572 
1573  py_boolean_function_node.def("clone", &BooleanFunction::Node::clone, R"(
1574  Clones the Boolean function node.
1575 
1576  :returns: The cloned Boolean function node.
1577  :rtype: hal_py.BooleanFunction.Node
1578  )");
1579 
1580  py_boolean_function_node.def("__str__", [](const BooleanFunction::Node& n) { return n.to_string(); }, R"(
1581  Translates the Boolean function node into its string representation.
1582 
1583  :returns: The Boolean function node as a string.
1584  :rtype: str
1585  )");
1586 
1587  py_boolean_function_node.def_property_readonly("arity", &BooleanFunction::Node::get_arity, R"(
1588  The arity of the Boolean function node, i.e., the number of parameters.
1589 
1590  :type: int
1591  )");
1592 
1593  py_boolean_function_node.def("get_arity", &BooleanFunction::Node::get_arity, R"(
1594  Returns the arity of the Boolean function node, i.e., the number of parameters.
1595 
1596  :returns: The arity.
1597  :rtype: int
1598  )");
1599 
1600  py_boolean_function_node.def_static("get_arity_of_type", &BooleanFunction::Node::get_arity_of_type, py::arg("type"), R"(
1601  Returns the arity for a Boolean function node of the given type, i.e., the number of parameters.
1602 
1603  :returns: The arity.
1604  :rtype: int
1605  )");
1606 
1607  py_boolean_function_node.def("is", &BooleanFunction::Node::is, py::arg("type"), R"(
1608  Checks whether the Boolean function node is of a specific type.
1609 
1610  :param int type: The type to check for.
1611  :returns: ``True`` if the node is of the given type, ``False`` otherwise.
1612  :rtype: bool
1613  )");
1614 
1615  py_boolean_function_node.def("is_constant", &BooleanFunction::Node::is_constant, R"(
1616  Checks whether the Boolean function node is of type Constant.
1617 
1618  :returns: ``True`` if the Boolean function node is of type Constant, ``False`` otherwise.
1619  :rtype: bool
1620  )");
1621 
1622  py_boolean_function_node.def("has_constant_value", py::overload_cast<const std::vector<BooleanFunction::Value>&>(&BooleanFunction::Node::has_constant_value, py::const_), py::arg("value"), R"(
1623  Checks whether the Boolean function node is of type Constant and holds a specific value.
1624 
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.
1627  :rtype: bool
1628  )");
1629 
1630  py_boolean_function_node.def("has_constant_value", py::overload_cast<u64>(&BooleanFunction::Node::has_constant_value, py::const_), py::arg("value"), R"(
1631  Checks whether the Boolean function node is of type Constant and holds a specific value.
1632 
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.
1635  :rtype: bool
1636  )");
1637 
1638  py_boolean_function_node.def(
1639  "get_constant_value",
1640  [](const BooleanFunction::Node& self) -> std::optional<std::vector<BooleanFunction::Value>> {
1641  if (const auto res = self.get_constant_value(); res.is_ok())
1642  {
1643  return res.get();
1644  }
1645  else
1646  {
1647  log_error("python_context", "could not get constant value:\n{}", res.get_error().get());
1648  return std::nullopt;
1649  }
1650  },
1651  R"(
1652  Get the constant value of the node of type ``Constant`` as a list of ``hal_py.BooleanFunction.Value``.
1653 
1654  :returns: The constant value on success, ``None`` otherwise.
1655  :rtype: list[hal_py.BooleanFunction.Value] or None
1656  )");
1657 
1658  py_boolean_function_node.def(
1659  "get_constant_value_u64",
1660  [](const BooleanFunction::Node& self) -> std::optional<u64> {
1661  if (const auto res = self.get_constant_value_u64(); res.is_ok())
1662  {
1663  return res.get();
1664  }
1665  else
1666  {
1667  log_error("python_context", "could not get constant value:\n{}", res.get_error().get());
1668  return std::nullopt;
1669  }
1670  },
1671  R"(
1672  Get the constant value of the node of type ``Constant`` as long as it has a size <= 64-bit.
1673 
1674  :returns: The constant value on success, ``None`` otherwise.
1675  :rtype: int or None
1676  )");
1677 
1678  py_boolean_function_node.def("is_index", &BooleanFunction::Node::is_index, R"(
1679  Checks whether the Boolean function node is of type Index.
1680 
1681  :returns: ``True`` if the Boolean function node is of type Index, ``False`` otherwise.
1682  :rtype: bool
1683  )");
1684 
1685  py_boolean_function_node.def("has_index_value", &BooleanFunction::Node::has_index_value, py::arg("value"), R"(
1686  Checks whether the Boolean function node is of type Index and holds a specific value.
1687 
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.
1690  :rtype: bool
1691  )");
1692 
1693  py_boolean_function_node.def(
1694  "get_index_value",
1695  [](const BooleanFunction::Node& self) -> std::optional<u64> {
1696  if (const auto res = self.get_index_value(); res.is_ok())
1697  {
1698  return res.get();
1699  }
1700  else
1701  {
1702  log_error("python_context", "could not get index value:\n{}", res.get_error().get());
1703  return std::nullopt;
1704  }
1705  },
1706  R"(
1707  Get the index value of node of type ``Index``.
1708 
1709  :returns: The index value on success, ``None`` otherwise.
1710  :rtype: int or None
1711  )");
1712 
1713  py_boolean_function_node.def("is_variable", &BooleanFunction::Node::is_variable, R"(
1714  Checks whether the Boolean function node is of type Variable.
1715 
1716  :returns: ``True`` if the Boolean function node is of type Variable, ``False`` otherwise.
1717  :rtype: bool
1718  )");
1719 
1720  py_boolean_function_node.def("has_variable_name", &BooleanFunction::Node::has_variable_name, py::arg("variable_name"), R"(
1721  Checks whether the Boolean function node is of type Variable and holds a specific variable name.
1722 
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.
1725  :rtype: bool
1726  )");
1727 
1728  py_boolean_function_node.def(
1729  "get_variable_name",
1730  [](const BooleanFunction::Node& self) -> std::optional<std::string> {
1731  if (const auto res = self.get_variable_name(); res.is_ok())
1732  {
1733  return res.get();
1734  }
1735  else
1736  {
1737  log_error("python_context", "could not get variable name:\n{}", res.get_error().get());
1738  return std::nullopt;
1739  }
1740  },
1741  R"(
1742  Get the variable name of node of type ``Variable``.
1743 
1744  :returns: The variable name on success, ``None`` otherwise.
1745  :rtype: str or None
1746  )");
1747 
1748  py_boolean_function_node.def("is_operation", &BooleanFunction::Node::is_operation, R"(
1749  Checks whether the Boolean function node is an operation node.
1750 
1751  :returns: ``True`` if the Boolean function node is an operation node, ``False`` otherwise.
1752  :rtype: bool
1753  )");
1754 
1755  py_boolean_function_node.def("is_operand", &BooleanFunction::Node::is_operand, R"(
1756  Checks whether the Boolean function node is an operand node.
1757 
1758  :returns: ``True`` if the Boolean function node is an operand node, ``False`` otherwise.
1759  :rtype: bool
1760  )");
1761 
1762  py_boolean_function_node.def("is_commutative", &BooleanFunction::Node::is_commutative, R"(
1763  Checks whether the Boolean function node is commutative.
1764 
1765  :returns: ``True`` if the Boolean function node is commutative, ``False`` otherwise.
1766  :rtype: bool
1767  )");
1768 
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.
1771  )");
1772 
1773  py_boolean_function_node_type.def_readonly_static("And", &BooleanFunction::NodeType::And);
1774  py_boolean_function_node_type.def_readonly_static("Or", &BooleanFunction::NodeType::Or);
1775  py_boolean_function_node_type.def_readonly_static("Not", &BooleanFunction::NodeType::Not);
1776  py_boolean_function_node_type.def_readonly_static("Xor", &BooleanFunction::NodeType::Xor);
1777 
1778  py_boolean_function_node_type.def_readonly_static("Add", &BooleanFunction::NodeType::Add);
1779  py_boolean_function_node_type.def_readonly_static("Sub", &BooleanFunction::NodeType::Sub);
1780  py_boolean_function_node_type.def_readonly_static("Mul", &BooleanFunction::NodeType::Mul);
1781  py_boolean_function_node_type.def_readonly_static("Sdiv", &BooleanFunction::NodeType::Sdiv);
1782  py_boolean_function_node_type.def_readonly_static("Udiv", &BooleanFunction::NodeType::Udiv);
1783  py_boolean_function_node_type.def_readonly_static("Srem", &BooleanFunction::NodeType::Srem);
1784  py_boolean_function_node_type.def_readonly_static("Urem", &BooleanFunction::NodeType::Urem);
1785 
1786  py_boolean_function_node_type.def_readonly_static("Concat", &BooleanFunction::NodeType::Concat);
1787  py_boolean_function_node_type.def_readonly_static("Slice", &BooleanFunction::NodeType::Slice);
1788  py_boolean_function_node_type.def_readonly_static("Zext", &BooleanFunction::NodeType::Zext);
1789  py_boolean_function_node_type.def_readonly_static("Sext", &BooleanFunction::NodeType::Sext);
1790 
1791  py_boolean_function_node_type.def_readonly_static("Shl", &BooleanFunction::NodeType::Shl);
1792  py_boolean_function_node_type.def_readonly_static("Lshr", &BooleanFunction::NodeType::Lshr);
1793  py_boolean_function_node_type.def_readonly_static("Ashr", &BooleanFunction::NodeType::Ashr);
1794  py_boolean_function_node_type.def_readonly_static("Rol", &BooleanFunction::NodeType::Rol);
1795  py_boolean_function_node_type.def_readonly_static("Ror", &BooleanFunction::NodeType::Ror);
1796 
1797  py_boolean_function_node_type.def_readonly_static("Eq", &BooleanFunction::NodeType::Eq);
1798  py_boolean_function_node_type.def_readonly_static("Sle", &BooleanFunction::NodeType::Sle);
1799  py_boolean_function_node_type.def_readonly_static("Slt", &BooleanFunction::NodeType::Slt);
1800  py_boolean_function_node_type.def_readonly_static("Ule", &BooleanFunction::NodeType::Ule);
1801  py_boolean_function_node_type.def_readonly_static("Ult", &BooleanFunction::NodeType::Ult);
1802  py_boolean_function_node_type.def_readonly_static("Ite", &BooleanFunction::NodeType::Ite);
1803 
1804  py_boolean_function_node_type.def_readonly_static("Constant", &BooleanFunction::NodeType::Constant);
1805  py_boolean_function_node_type.def_readonly_static("Index", &BooleanFunction::NodeType::Index);
1806  py_boolean_function_node_type.def_readonly_static("Variable", &BooleanFunction::NodeType::Variable);
1807  }
1808 } // namespace hal
u32 size
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
bool is(u16 type) 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)
uint16_t u16
Definition: defines.h:40
uint8_t u8
Definition: defines.h:39
void boolean_function_init(py::module &m)
#define log_error(channel,...)
Definition: log.h:78
const Module * module(const Gate *g, const NodeBoxes &boxes)
Definition: defines.h:45
std::vector< BooleanFunction::Value > constant
The (optional) constant value of the node.
u16 type
The type of the node.
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
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)