# Quantum Tree Search with Qiskit

## Abstract

**:**

## 1. Introduction

- The long-term memory is modeled by a set of productions.
- The short-term memory or working memory that represents the states. This memory contains a description of the state in a problem-solving process. The state is described by logically structured representation and is simply called a pattern. Whenever a premise is true, the conclusions of the productions change the contents of the working memory.
- The recognize–act cycle is usually based on heuristic search. If several productions can be applied to the working memory, a heuristic function estimates for each production that can be applied the cheapest cost to the goal. The production with the cheapest costs is chosen. Generally, the invention of heuristic functions is difficult, such as functions that describe chemical structures or mathematical expressions. In a quantum production system based on a quantum tree, search heuristics are removed and replaced by all possible translations.

**If**the empty cell is not on the top edge,**then**move the empty cell up;**If**the empty cell is not on the left edge,**then**move the empty cell left;**If**the empty cell is not on the right edge,**then**move the empty cell right;**If**the empty cell is not on the bottom edge,**then**move the empty cell down.

- Halt when the goal is in the working memory.
- Chose a random production.
- Do not allow loops.

#### 1.1. Tree Search and the Path Descriptors

#### 1.2. Quantum Tree Search

#### 1.3. Contribution

## 2. Quantum Tree Search with Qiskit

- The qasm simulator promises to behave like an actual device of today, which is prone to noise resulting from decoherence. It returns counts, which are a sampling of the measured qubits that have to be defined in the circuit, which is much smaller in size and will not increase in size exponentially as the number of qubits increases.
- The statevector simulator performs an ideal execution of qiskit circuits and returns the final state vector off the simulator after application (all qubits). The state vector of the circuit can represent the probability values that correspond to the multiplication of the state vector by the unitary matrix that represents the circuit. The statevector simulator will take longer than other simulation methods and requires more computer memory since the state vector dimension grows exponentially with the number of qubits with $n={2}^{m}$ (with m number of qubits).

#### 2.1. 3-Puzzle

- For a given board, configuration and a production rule determine the new board configuration.
- To determine if the configuration is the goal configuration.

#### 2.1.1. Decomposition of Unitary Operators

#### 2.1.2. Representation

`qc.x(0)`

`qc.x(4)`

`qc.x(5)`

`qc.x(7)`

`qc = QuantumCircuit(14,8)`

`#State Preparation 0-7`

`qc.x(0)`

`qc.x(4)`

`qc.x(5)`

`qc.x(7)`

`#Flag represented by qubit 8`

`#1St Trace represented by qubits 9-12`

`#1St Path descriptor in superposition`

`qc.h(13)`

`qc.barrier()`

#### 2.1.3. Rules and Trace

`#If part of rules marked in trace`

`qc.ccx(0,1,9)`

`qc.ccx(2,3,10)`

`qc.ccx(4,5,11)`

`qc.ccx(6,7,12)`

`simulator = Aer.get_backend(’qasm_simulator’)`

`result=execute(qc,simulator).result()`

`counts = result.get_counts()`

`plot_histogram(counts)`

#### 2.2. Search of Depth Two

`qc = QuantumCircuit(20,2)`

`#State Preparation 0-7`

`# Flag bit 8`

`#1St Trace 9-12`

`#1St Path Descriptor in superposition`

`qc.h(13)`

`#1St Trace 14-17`

`#2th Path Descriptor in superposition`

`qc.h(18)`

`#Aux Bit c indicating the solution is negated`

`# and put in superposition`

`qc.x(19)`

`qc.h(19)`

`def oracle():`

`qc = QuantumCircuit(20)`

`gate = MCXGate(4)`

`#Goal Configurations`

`qc.append(gate,[2, 3, 4, 7, 19])`

`#Alternative Goal Configurations`

`#qc.append(gate,[0, 2, 3, 5, 19])`

`#Grover in depth two cannot resolve this since`

`two solutions out of four are marked.`

`#qc.append(gate,[0, 4, 5, 7, 19])`

`qc.name="O"`

`return qc`

`def rules1_inv():`

`qc=rules1()`

`qc_inv=qc.inverse()`

`qc_inv.name="R1†"`

`return qc_inv`

`def Grover():`

`qc = QuantumCircuit(19)`

`#Diffusor`

`qc.h([13,18])`

`qc.z([13,18])`

`qc.cz(13,18)`

`qc.h([13,18])`

`qc.name="G"`

`return qc`

#### 2.2.1. Search Depth Three

`def Grover():`

`qc = QuantumCircuit(24)`

`#Diffusor`

`qc.h([13,18,23])`

`qc.x([13,18,23])`

`qc.h(13)`

`qc.ccx(18,23,13)`

`qc.h(13)`

`qc.x([13,18,23])`

`qc.h([13,18,23])`

`qc.name="G"`

`return qc`

`simulator = Aer.get_backend(’statevector_simulator’)`

`result=execute(qc,simulator).result()`

`counts = result.get_counts()`

`plot_histogram(counts)`

#### 2.2.2. Search Depth Three with Two Iterations

## 3. Extending to 8-Puzzle

`qc = QuantumCircuit(49,2)`

`#State Preparation 0-35`

`#N3`

`qc.x(0)`

`qc.x(1)`

`#2`

`#3`

`..`

`..`

`#Flag 36`

`#1St Trace 37-45`

`#1St Path Descriptor in superposition 46, 47`

`qc.h(46)`

`qc.h(47)`

`#Preparation of Aux`

`qc.x(48)`

`qc.h(48)`

`def if_rules():`

`qc = QuantumCircuit(46)`

`#Marke the trace indicate the rule group through trace`

`gate = MCXGate(4)`

`#Empty Space in corner, 2 movements`

`qc.append(gate, [0, 1, 2, 3, 37])`

`#Empty Space in edge, 3 movements`

`qc.append(gate, [4, 5, 6, 7, 38])`

`#Empty Space in corner, 2 movements`

`qc.append(gate, [8, 9, 10, 11, 39])`

`#Empty Space in edge, 3 movements`

`qc.append(gate, [12, 13, 14, 15, 40])`

`#Empty Space in center, 4 movements`

`qc.append(gate, [16, 17, 18, 19, 41])`

`#Empty Space in edge, 3 movements`

`qc.append(gate, [20, 21, 22, 23, 42])`

`#Empty Space in corner, 2 movements`

`qc.append(gate, [24, 25, 26, 27, 43])`

`#Empty Space in edge, 3 movements`

`qc.append(gate, [28, 29, 30, 31, 44])`

`#Empty Space in corner, 2 movements`

`qc.append(gate, [32, 33, 34, 35, 45])`

`qc.name="IF"`

`return qc`

- For the path descriptor 00, move right $16,17,18,19\to 12,13,14,15$.
- For the path descriptor 00, move left $16,17,18,19\to 20,21,22,23$.
- For the path descriptor 00, move up $16,17,18,19\to 28,29,30,31$.
- For the path descriptor 00, move down $16,17,18,19\to 4,5,6,7$.

- For the path descriptor 00, move up $12,13,14,15\to 24,25,26,27$.
- For the path descriptor 01, move down $12,13,14,15\to 0,1,2,3$.
- For the path descriptor 10, move left $12,13,14,15\to 16,17,18,19$.
- For the path descriptor 11, move left $12,13,14,15\to 16,17,18,19$.

- For the path descriptor 00, move up $0,1,2,3\to 12,13,14,15$.
- For the path descriptor 01, move up $0,1,2,3\to 12,13,14,15$.
- For the path descriptor 10, move left $0,1,2,3\to 4,5,6,7$.
- For the path descriptor 11, move left $0,1,2,3\to 4,5,6,7$.

#### Number of Iterations

## 4. Blocks World

#### 4.1. Representation

`qc = QuantumCircuit(27)`

`#State Preparation 0-8`

`# Flag 9`

`#1st Trace (ten) 10-22 Rule Classes`

`#1st Path descriptor represented by three qubit`

`qc.h(23)`

`qc.h(24)`

`qc.h(25)`

`#Preparation of Aux`

`qc.x(26)`

`qc.h(26)`

`ef state_floor():`

`qc = QuantumCircuit(9)`

`#All Blocks are on floor`

`#BLOCK A qubits 0-2`

`qc.x(2)`

`#BLOCK B qubits 3-5`

`qc.x(5)`

`#BLOCK C qubits 6-8`

`qc.x(8)`

`qc.name="S_FL"`

`return qc`

`def if_rules():`

`qc = QuantumCircuit(23)`

`gate = MCXGate(3)`

`#All blocks on table`

`qc.append(gate, [2, 5, 8, 10])`

`#ABC tower`

`qc.append(gate, [1, 2, 3, 11])`

`#ACB tower`

`qc.append(gate, [1, 2, 6, 12])`

`#BAC tower`

`qc.append(gate, [4, 5, 1, 13])`

`#BCA tower`

`qc.append(gate, [4, 5, 6, 14])`

`#CAB tower`

`qc.append(gate, [1, 7, 8, 15])`

`#CBA tower`

`qc.append(gate, [4, 7, 8, 16])`

`#BC tower and block A`

`qc.append(gate, [2, 5, 3, 17])`

`#BA tower and block C`

`qc.append(gate, [8, 5, 3, 18])`

`#CA tower and block B`

`qc.append(gate, [8, 6, 5, 19])`

`#CB tower and block A`

`qc.append(gate, [8, 6, 2, 20])`

`#AC tower and block B`

`qc.append(gate, [0, 2, 5, 21])`

`#AB tower and block C`

`qc.append(gate, [0, 2, 8, 22])`

`qc.name="IF"`

`return qc`

`def rules_tw():`

`qc = QuantumCircuit(17)`

`#There is a tower,`

`#6 different towers indicated by 11,12,..,16`

`qc.cswap(11,1,5)`

`qc.cswap(12,1,8)`

`qc.cswap(13,2,4)`

`qc.cswap(14,2,8)`

`qc.cswap(15,2,7)`

`qc.cswap(16,5,7)`

`qc.name="R_TW"`

`return qc`

#### 4.2. Number of Iterations

## 5. Conclusions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Conflicts of Interest

## Appendix A. Qiskit Code

#### Appendix A.1. 3-Puzzle

#### Appendix A.1.1. 3-Puzzle Rules

`#If then rule (1) for empty at 0, 1 -> 4, 5 or 2, 3`

`#Search empty state with the descriptor`

`qc.ccx(9,13,8)`

`#Execute 1st then part by moving the empty space clockwise`

`qc.cswap(8,0,4)`

`qc.cswap(8,1,5)`

`#Secod then part with changed descriptor`

`#Reset Flag`

`qc.ccx(9,13,8)`

`#Fetch second superposition`

`qc.x(13)`

`qc.ccx(9,13,8)`

`#Execute 2th then part by moving the empty space anti-clockwise`

`qc.cswap(8,0,2)`

`qc.cswap(8,1,3)`

`#Reset Flag`

`qc.ccx(9,13,8)`

`#Restore descriptor`

`qc.x(13)`

`qc.barrier()`

`#If then rule (2) for empty at 2, 3 -> 6, 7 or 0, 1`

`#Search empty state with the descriptor`

`qc.ccx(10,13,8)`

`#Execute 1st then part`

`qc.cswap(8,2,6)`

`qc.cswap(8,3,7)`

`#Secod then part with changed descriptor`

`#Reset Flag`

`qc.ccx(10,13,8)`

`#Fetch second superposition`

`qc.x(13)`

`qc.ccx(10,13,8)`

`#Execute 2th then part`

`qc.cswap(8,0,2)`

`qc.cswap(8,1,3)`

`#Reset Flag`

`qc.ccx(10,13,8)`

`#Restore descriptor`

`qc.x(13)`

`qc.barrier()`

`qc.measure(0,0)`

`qc.measure(1,1)`

`qc.measure(2,2)`

`qc.measure(3,3)`

`qc.measure(4,4)`

`qc.measure(5,5)`

`qc.measure(6,6)`

`qc.measure(7,7)`

#### Appendix A.1.2. 3-Puzzle Task

`qc = QuantumCircuit(20,2)`

`#State Preparation 0-7`

`# Flag bit 8`

`#1St Trace 9-12`

`#1St Path Descriptor in superposition`

`qc.h(13)`

`#1St Trace 14-17`

`#2th Path descriptor in superposition`

`qc.h(18)`

`#Aux bit c indicating the solution is negated and`

`# put in superposition`

`qc.x(19)`

`qc.h(19)`

`qc.barrier()`

`#Preperation of state`

`qc.append(state_A(),range(8))`

`#Depth1`

`qc.append(rules1(),range(14))`

`#Depth2`

`qc.append(rules2(),range(19))`

`#Oracle`

`qc.append(oracle(),range(20))`

`#Depth2`

`qc.append(rules2_inv(),range(19))`

`#Depth1`

`qc.append(rules1_inv(),range(14))`

`#Redo Preperation`

`qc.append(state_A(),range(8))`

`qc.barrier()`

`#Redo Superposition of Aux Bit`

`qc.h(19)`

`qc.barrier()`

`qc.append(Grover(),range(19))`

`qc.measure(13,0)`

`qc.measure(18,1)`

#### Appendix A.2. 8-Puzzle

#### Appendix A.2.1. Rules1 8-Puzzle

`def rules1():`

`qc = QuantumCircuit(48)`

`#Flag 36`

`#Path Descriptor 46, 47`

`#Trace 37-45`

`flag_gate = MCXGate(3)`

`#If then rule move right, for~empty at 16, 17, 18, 19 -> 12, 13, 14, 15`

`qc.append(flag_gate, [41, 46, 47, 36])`

`#Move`

`qc.cswap(36,16,12)`

`qc.cswap(36,17,13)`

`qc.cswap(36,18,14)`

`qc.cswap(36,19,15)`

`#Clear Flag`

`qc.append(flag_gate, [41, 46, 47, 36])`

`#If then rule move left, for~empty at 16, 17, 18, 19 -> 20, 21, 22, 23`

`qc.x(46)`

`qc.append(flag_gate, [41, 46, 47, 36])`

`#Move`

`qc.cswap(36,16,20)`

`qc.cswap(36,17,21)`

`qc.cswap(36,18,22)`

`qc.cswap(36,19,23)`

`#Clear Flag`

`qc.append(flag_gate, [41, 46, 47, 36])`

`qc.x(46)`

`#If then rule move up, for~empty at 16, 17, 18, 19 -> 28, 29, 30, 31`

`qc.x(47)`

`qc.append(flag_gate, [41, 46, 47, 36])`

`#Move`

`qc.cswap(36,16,28)`

`qc.cswap(36,17,29)`

`qc.cswap(36,18,30)`

`qc.cswap(36,19,31)`

`#Clear Flag`

`qc.append(flag_gate, [41, 46, 47, 36])`

`qc.x(47)`

`#If then rule move down, for~empty at 16, 17, 18, 19 -> 4, 5, 6, 7`

`qc.x(46)`

`qc.x(47)`

`qc.append(flag_gate, [41, 46, 47, 36])`

`#Move`

`qc.cswap(36,16,4)`

`qc.cswap(36,17,5)`

`qc.cswap(36,18,6)`

`qc.cswap(36,19,7)`

`#Clear Flag`

`qc.append(flag_gate, [41, 46, 47, 36])`

`qc.x(47)`

`qc.x(46)`

`qc.name="R1"`

`return qc`

#### Appendix A.3. ABC Blocks World

#### Appendix A.3.1. Rules Floor

`def rules_floor():`

`qc = QuantumCircuit(26)`

`gate4 = MCXGate(4)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#All blocks on~floor`

`# Moving A`

`#A on B`

`qc.cswap(9,0,5)`

`#Secod then part with changed descriptor`

`#Reset WM (Working Memory)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#Fetch second superposition`

`qc.x(23)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#A on C`

`qc.cswap(9,0,8)`

`#Reset WM`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#Restore descriptor`

`qc.x(23)`

`# Moving B`

`qc.x(24)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`# B on A`

`qc.cswap(9,2,3)`

`#Secod then part with changed descriptor`

`#Reset WM`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`qc.x(24)`

`#Fetch second superposition`

`qc.x(23)`

`qc.x(24)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#B on C`

`qc.cswap(9,3,8)`

`#Reset WM`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#Restore descriptor`

`qc.x(24)`

`qc.x(23)`

`# Moving C`

`qc.x(25)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#C on A`

`qc.cswap(9,6,2)`

`#Secod then part with changed descriptor`

`#Reset WM`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`qc.x(25)`

`#Fetch second superposition`

`qc.x(25)`

`qc.x(23)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`# C on B`

`qc.cswap(9,6,5)`

`#Reset WM`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#Restore descriptor`

`qc.x(23)`

`qc.x(25)`

`#We have only six rules, but~eight possible paths!!!`

`#To get rid of the initial state we will move C again!!!`

`# Moving C Again`

`qc.x(24)`

`qc.x(25)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`# A clear goes to high of B`

`qc.cswap(9,6,2)`

`#Secod then part with changed descriptor`

`#Reset WM`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`qc.x(25)`

`qc.x(24)`

`#Fetch second superposition`

`qc.x(23)`

`qc.x(24)`

`qc.x(25)`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`# C clear goes to high of B`

`qc.cswap(9,6,5)`

`#Reset WM`

`qc.append(gate4, [10, 23, 24, 25, 9])`

`#Restore descriptor`

`qc.x(25)`

`qc.x(24)`

`qc.x(23)`

`qc.name="R_FL"`

`return qc`

#### Appendix A.3.2. Rules tw bl

`def rules_tw_bl():`

`qc = QuantumCircuit(26)`

`gate4 = MCXGate(4)`

`#Flag 9`

`#Path Descriptor 23, 24, 25`

`#The three instantiations`

`#BC tower and block A`

`#qc.append(gate, [2, 5, 3, 17])`

`#Put it on Floor`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.cswap(9,3,8)`

`#Clear WM`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`#Make Tower BCA`

`qc.x(23)`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.cswap(9,5,1)`

`#Clear WM`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.x(23)`

`#Move C on the other block A`

`qc.x(24)`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.cswap(9,2,8)`

`#Clear WM`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.x(24)`

`#Repeat three instantiations again for the states 4-6`

`# of the path descriptor`

`#Put it on Floor`

`qc.x(24)`

`qc.x(23)`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.cswap(9,3,8)`

`#Clear WM`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.x(24)`

`qc.x(23)`

`#Make Tower BCA`

`qc.x(25)`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.cswap(9,5,1)`

`#Clear WM`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.x(25)`

`#Move C on the other block A`

`qc.x(25)`

`qc.x(23)`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.cswap(9,2,8)`

`#Clear WM`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.x(25)`

`qc.x(23)`

`#Repeat two instantiations again for the states 7-8`

`# of the path descriptor`

`#Make Tower BCA`

`qc.x(25)`

`qc.x(24)`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.cswap(9,5,1)`

`#Clear WM`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.x(25)`

`qc.x(24)`

`#Move C on the other block A`

`qc.x(25)`

`qc.x(24)`

`qc.x(23)`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.cswap(9,2,8)`

`#Clear WM`

`qc.append(gate4, [17, 23, 24, 25, 9])`

`qc.x(25)`

`qc.x(24)`

`qc.x(23)`

`#In the same way`

`#BA tower and block C`

`#CA tower and block B`

`#CB tower and block A`

`#AC tower and block B`

`#AB tower and block C`

`.....`

`qc.name="R_TB"`

`return qc`

## References

- Nilsson, N.J. Principles of Artificial Intelligence; Springer: Berlin/Heidelberg, Germany, 1982. [Google Scholar]
- Anderson, J.R. Cognitive Psychology and Its Implications, 4th ed.; W. H. Freeman and Company: New York, NY, USA, 1995. [Google Scholar]
- Brownston, L.; Farell, R.; Kant, E.; Martin, N. Programming Expert Systems in OPS5: An Introduction to Rule-Based Programming; Addison-Wesley: Boston, MA, USA, 1985. [Google Scholar]
- Luger, G.F.; Stubblefield, W.A. Artificial Intelligence, Structures and Strategies for Complex Problem Solving, 3rd ed.; Addison-Wesley: Boston, MA, USA, 1998. [Google Scholar]
- Wichert, A. Principles of Quantum Artificial Intelligence: Quantum Problem Solving and Machine Learning, 2nd ed.; World Scientific: Porto Salvo, Portugal, 2020. [Google Scholar]
- Tarrataca, L.; Wichert, A. Tree search and quantum computation. Quantum Inf. Process.
**2011**, 10, 475–500. [Google Scholar] [CrossRef] - Korf, R.E. Depth-first iterative-deepening: An optimal admissible tree search. Artif. Intell.
**1985**, 27, 97–109. [Google Scholar] [CrossRef] - Russell, S.; Norvig, P. Artificial Intelligence: A Modern Approach; Prentice Hall Series in Artificial Intelligence; Prentice Hall: Hoboken, NJ, USA, 2010. [Google Scholar]
- Tarrataca, L.; Wichert, A. Quantum iterative deepening with an application to the halting problem. PLoS ONE
**2013**, 8, e57309. [Google Scholar] - Eagle, A.; Kato, T.; Minato, Y. Solving tiling puzzles with quantum annealing. arXiv
**2019**, arXiv:1904.01770v1. [Google Scholar] - Hamze, F.; Jacob, D.C.; Ochoa, A.J.; Perera, D.; Wang, W.; Katzgrabe, H.G. From near to eternity: Spin-glass planting, tiling puzzles, and constraint satisfaction problems. arXiv
**2018**, arXiv:1711.04083v2. [Google Scholar] [CrossRef] [PubMed] - Takabatake, K.; Yanagisawa, K.; Akiyama, Y. Solving generalized polyomino puzzles using the ising model. Entropy
**2022**, 24, 354. [Google Scholar] [CrossRef] [PubMed] - Brooke, J.; Bitko, D.; Rosenbaum, T.; Aeppli, G. Quantum annealing of a disordered magnet. Science
**1999**, 284, 779–781. [Google Scholar] [CrossRef] [PubMed] - Johnson, M.W.; Amin, M.H.S.; Gildert, S.; Lanting, T.; Hamze, F.; Dickson, N.; Harris, R.; Berkley, A.J.; Johansson, J.; Bunyk, P.; et al. Quantum annealing with manufactured spins. Nature
**2011**, 473, 194–198. [Google Scholar] [CrossRef] [PubMed] - McGeoch, C.C. Adiabatic Quantum Computation and Quantum Annealing: Theory and Practice; Morgan & Claypool: San Rafael, CA, USA, 2014. [Google Scholar]
- Hertz, J.; Krogh, A.; Palmer, R.G. Introduction to the Theory of Neural Computation; Addison-Wesley: Boston, MA, USA, 1991. [Google Scholar]
- Tarrataca, L.; Wichert, A. Problem-solving and quantum computation. Cogn. Comput.
**2011**, 3, 510–524. [Google Scholar] [CrossRef] - Kolda, T.G.; Bader, B.W. Tensor decompositions and applications. SIAM Rev.
**2009**, 51, 455–500. [Google Scholar] [CrossRef] - Hirvensalo, M. Quantum Computing; Springer: Berlin/Heidelberg, Germany, 2004. [Google Scholar]
- Nielsen, M.A.; Chuang, I.L. Quantum Computation and Quantum Information; Cambridge University Press: Cambridge, MA, USA, 2000. [Google Scholar]

**Figure 1.**The first pattern (upper left) represents the initial configuration and the last (low right) the goal configuration. The series of moves describe the solution to the problem.

**Figure 2.**Search tree for $B=2$ and $m=2$. Each question can be represented by a bit. Each binary number (11, 10, 01, 00) represents a path from the root to the leaf.

**Figure 3.**For branching, factor B from 2 to 4 and the depth of the tree search m from 1 to 10. The costs on a conventional computer are $n={B}^{m}$, upper plane. On a quantum computer, we need only $\sqrt{n}={B}^{\frac{m}{2}}$ steps, plane below.

**Figure 5.**There are twelve possible configurations. For any of these configurations, only two movements are possible. The movement of the empty cell is either a clockwise or counter-clockwise movement.

**Figure 6.**3-puzzle coding representing the state of the Figure 4. The four objects are by a register of eight qubits. We indicate the state, its representation and below the position of the 8 qubits. In this representation, position description (adjective) is fixed and the class descriptors moves.

**Figure 7.**Quantum circuit representing the generation of two instantiations of rules in the 3-puzzle task of one depth search.

**Figure 9.**The quantum circuit of 3-puzzle task of the depth search 2. The circuits depth in the number of quantum gates is 12. The path descriptor has four possible states represented by two qubits. One marked state results in a certain solution 01 off the path descriptor by the qasm simulator after one iteration, since for one marked qubit one requires only one rotation.

**Figure 10.**The quantum circuit for the 3-puzzle task of the depth search 3. Since we are using the statevector simulator, we do not need any measurement since the simulator determines the exact probabilities of each qubit. The circuits depth in the number of quantum gates is 13. The depth of a circuit is a metric that calculates the longest path between the data input and the output. The path descriptor has eight possible states represented by three qubits. One marked state results in a solution after one iteration indicated in the histogram of Figure 11.

**Figure 11.**One marked state results after one iteration is indicated with a probability value $0.781$ and the path descriptor 001 represented by the qubits 13, 18 and 23 by the statevector simulator. All other states are zero due to un-computation. The path descriptor can be verified by measurement using the qasm simulator of the qubits representing the path descriptor as well.

**Figure 12.**The quantum circuit for the 3-puzzle task of the depth search three with two iterations. Since we are using the statevector simulator, we do not need any measurement since the simulator determines the exact probabilities of each qubit. The circuits depth in the number of quantum gates is 25. The path descriptor has eight possible states represented by three qubits. An important operation before the second iteration is the setting of the auxiliary qubit 24 in superposition by a Hadamard gate. One marked state results in a solution after two iteration indicated in the histogram of Figure 13.

**Figure 13.**One marked state results after one iteration is indicated with a probability value $0.945$ by the statevector simulator. This is the optimum theoretical value for one marked solution using Grover’s amplification of eight state. If we apply another rotation, the theoretical probability would decrease.

**Figure 14.**8-puzzle coding. The 9 objects are by a register of 36 qubits. We indicate the state, its representation and below the position of the 36 qubits. In this representation, position description (adjective) is fixed and the class descriptors move.

**Figure 15.**The quantum circuit for the 9-puzzle task of the depth search 1. Simulating 36 qubits requires higher memory capacity, we cannot use the statevector simulator or a search depth of two due to memory constraints. The path descriptor has four possible states represented by two qubits and is measured after applying the function $rules1$.

**Figure 16.**Three qubits (bits) for each block represent its state. The first qubit equaling one indicates that the block is on top of one other block. The second qubit equaling one indicates that the block is on top of two other blocks. The third qubit equaling one indicates that the block is clear with nothing on top of it.

**Figure 17.**Representing a state of A, B, C blocks by 9 qubits (bits). The class descriptor is fixed and the position descriptor (adjective) moves (is changed). Three qubits (bits) for each block represent its state. Their value changes indicating different states. On top, we see the three A, B, C blocks and the 9 positions of the qubits by the index from 0 to 9, x indicates that the qubit is equal to one. Below, we represent the corresponding state and the corresponding binary string.

**Figure 18.**The quantum circuit for the ABC blocks task of the depth search 1. Since we are using the statevector simulator, we do not need any measurement since the simulator determines the exact probabilities of each qubit. The circuit’s depth in the number of quantum gates is 13. The path descriptor has eight possible states represented by three qubits.

**Figure 22.**One marked state results in a solution after one iteration indicated for the initial state all blocks on the floor and the goal states $AC$ and B. The solution is described by the path descriptor by the qubits 23, 24 and 25 with the binary value 101, the fifth branch. There are 8 branches described by 8 possible transitions $0,1\cdots 7$.

**Figure 23.**Three marked states results in a solution after one iteration indicated for the initial state $BC$ and A and the goal states $AC$ and B by the statevector simulator.

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2022 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Wichert, A.
Quantum Tree Search with Qiskit. *Mathematics* **2022**, *10*, 3103.
https://doi.org/10.3390/math10173103

**AMA Style**

Wichert A.
Quantum Tree Search with Qiskit. *Mathematics*. 2022; 10(17):3103.
https://doi.org/10.3390/math10173103

**Chicago/Turabian Style**

Wichert, Andreas.
2022. "Quantum Tree Search with Qiskit" *Mathematics* 10, no. 17: 3103.
https://doi.org/10.3390/math10173103