qiskit-documentation/docs/api/qiskit/0.31/qiskit.aqua.components.orac...

79 lines
4.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: TruthTableOracle
description: API reference for qiskit.aqua.components.oracles.TruthTableOracle
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.aqua.components.oracles.TruthTableOracle
---
# TruthTableOracle
<Class id="qiskit.aqua.components.oracles.TruthTableOracle" isDedicatedPage={true} github="https://github.com/qiskit-community/qiskit-aqua/tree/stable/0.9/qiskit/aqua/components/oracles/truth_table_oracle.py" signature="TruthTableOracle(bitmaps, optimization=False, mct_mode='basic')" modifiers="class">
Bases: `qiskit.aqua.components.oracles.oracle.Oracle`
The Truth Table-based Quantum Oracle.
Besides logical expressions, (see [`LogicalExpressionOracle`](qiskit.aqua.components.oracles.LogicalExpressionOracle "qiskit.aqua.components.oracles.LogicalExpressionOracle")) another common way of specifying boolean functions is using truth tables, which is basically an exhaustive mapping from input binary bit-strings of length $n$ to corresponding output bit-strings of length $m$. For example, the following is a simple truth table that corresponds to the XOR of two variables:
| Inputs | | Output |
| ------ | - | ------- |
| A | B | A xor B |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
In this case $n=2$, and $m=1$. Often, for brevity, the input bit-strings are omitted because they can be easily derived for any given $n$. So to completely specify a truth table, we only need a Length-2 n bit-string for each of the $m$ outputs. In the above example, a single bit-string 0110 would suffice. Besides 0 and 1, one can also use x in the output string to indicate do-not-care entries. For example, 101x specifies a truth table (again $n=2$ and $m=1$) for which the output upon input 11 doesnt matter. The truth table oracle takes either a single string or a list of equal-length strings for truth table specifications.
Regarding circuit optimization and mct usages, the truth table oracle is similar to the [`LogicalExpressionOracle`](qiskit.aqua.components.oracles.LogicalExpressionOracle "qiskit.aqua.components.oracles.LogicalExpressionOracle"). One difference is that, unlike the logical expression oracle which builds circuits out of CNF or DNF, the truth table oracle uses Exclusive Sum of Products (ESOP), which is similar to DNF, with the only difference being the outermost operation being XOR as opposed to a disjunction. Because of this difference, an implicant-based method is used here for circuit optimization: First, the [Quine-McCluskey algorithm](https://en.wikipedia.org/wiki/Quine-McCluskey_algorithm) is used to find all prime implicants of the input truth table; then an [Exact Cover](https://en.wikipedia.org/wiki/Knuth%27s_Algorithm_X) is found among all prime implicants and truth table onset row entries. The exact cover is then used to build the corresponding oracle circuit.
**Parameters**
* **bitmaps** (`Union`\[`str`, `List`\[`str`]]) A single binary string or a list of binary strings representing the desired single- and multi-value truth table.
* **optimization** (`bool`) Boolean flag for attempting circuit optimization. When set, the Quine-McCluskey algorithm is used to compute the prime implicants of the truth table, and then its exact cover is computed to try to reduce the circuit.
* **mct\_mode** (`str`) The mode to use when constructing multiple-control Toffoli.
**Raises**
[**AquaError**](qiskit.aqua.AquaError "qiskit.aqua.AquaError") Invalid input
## Methods
### construct\_circuit
<Function id="qiskit.aqua.components.oracles.TruthTableOracle.construct_circuit" signature="TruthTableOracle.construct_circuit()">
construct circuit
</Function>
### evaluate\_classically
<Function id="qiskit.aqua.components.oracles.TruthTableOracle.evaluate_classically" signature="TruthTableOracle.evaluate_classically(measurement)">
evaluate classical
</Function>
## Attributes
### ancillary\_register
<Attribute id="qiskit.aqua.components.oracles.TruthTableOracle.ancillary_register">
returns ancillary register
</Attribute>
### circuit
<Attribute id="qiskit.aqua.components.oracles.TruthTableOracle.circuit" />
### output\_register
<Attribute id="qiskit.aqua.components.oracles.TruthTableOracle.output_register">
returns output register
</Attribute>
### variable\_register
<Attribute id="qiskit.aqua.components.oracles.TruthTableOracle.variable_register">
returns variable register
</Attribute>
</Class>