import math def avg (ns): s = 0 for n in ns: s = s+n return s/len(ns) def reflection(ns): mu = avg(ns) n = len(ns) ns2 = [None]*n for i in range(n): ns2[i] = 2 * mu - ns[i] return ns2 def gen_amplitude(n): a = [1/math.sqrt(2**n)] * (2 ** n) # for i in range(2 ** n): # a[i] = 1/math.sqrt(2**n) return a def flip(ns, i): ns[i] = -1 * ns[i] return ns def iter_ref(l, ns, j): for i in range(l): ns = flip(ns, j) ns = reflection(ns) return ns