few grover's hints
This commit is contained in:
parent
08bce98b6d
commit
67cd000f5a
15
grover.py
15
grover.py
@ -1,3 +1,5 @@
|
|||||||
|
# Full circuit + example: https://cstheory.stackexchange.com/questions/38538/oracle-construction-for-grovers-algorithm
|
||||||
|
# X-Axis control: https://algassert.com/post/1706
|
||||||
# http://twistedoakstudios.com/blog/Post2644_grovers-quantum-search-algorithm
|
# http://twistedoakstudios.com/blog/Post2644_grovers-quantum-search-algorithm
|
||||||
import itertools
|
import itertools
|
||||||
import random
|
import random
|
||||||
@ -32,8 +34,7 @@ def classical_func_search_single_rv(func, input_range):
|
|||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
||||||
def _3sat(params):
|
def _3sat_old(params):
|
||||||
# https://cstheory.stackexchange.com/questions/38538/oracle-construction-for-grovers-algorithm
|
|
||||||
# 3-SAT from here: https://qiskit.org/textbook/ch-applications/satisfiability-grover.html
|
# 3-SAT from here: https://qiskit.org/textbook/ch-applications/satisfiability-grover.html
|
||||||
x1, x2, x3 = params
|
x1, x2, x3 = params
|
||||||
return (not x1 or not x2 or not x3) and \
|
return (not x1 or not x2 or not x3) and \
|
||||||
@ -42,10 +43,18 @@ def _3sat(params):
|
|||||||
(x1 or not x2 or not x3) and \
|
(x1 or not x2 or not x3) and \
|
||||||
(not x1 or x2 or x3)
|
(not x1 or x2 or x3)
|
||||||
|
|
||||||
|
def _3sat(params):
|
||||||
|
# 3-SAT from here: https://cstheory.stackexchange.com/questions/38538/oracle-construction-for-grovers-algorithm
|
||||||
|
x1, x2, x3, x4 = params
|
||||||
|
return (not x1 or not x3 or not x4) and \
|
||||||
|
(x2 or x3 or not x4) and \
|
||||||
|
(x1 or not x2 or x4) and \
|
||||||
|
(x1 or x3 or x4) and \
|
||||||
|
(not x1 or x2 or not x3)
|
||||||
|
|
||||||
def classical_3sat(func):
|
def classical_3sat(func):
|
||||||
# Generate all possible true/false tupples for the 3-sat problem
|
# Generate all possible true/false tupples for the 3-sat problem
|
||||||
input_range = list(itertools.product([True, False], repeat=3))
|
input_range = list(itertools.product([True, False], repeat=4))
|
||||||
random.shuffle(input_range)
|
random.shuffle(input_range)
|
||||||
return classical_func_search_multi_rv(func, input_range)
|
return classical_func_search_multi_rv(func, input_range)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user