# octave script to calculate Grover theoretical probabilities vs. iteration
#
# inputs: M = number of states, r = desired optimal integer number of iterations
#
if( exist("M") == 0) M = 8; end

M, theta = 2*asin(1/sqrt(M))

if( exist("IMAX") == 1) imax = IMAX; else imax = ceil((pi/2)/theta-0.5); end

iter = [0:imax]; p=sin((iter+0.5)*theta); p = p.*p;

[iter' p' (1-p)']
#
iteropt = (pi/2)/theta - 0.5
#
# optimize for integer number of iterations, not feasible if (M-1)*a*a > 1
#
if( exist("r") == 0) r = 2; end
r
theta = (pi/2)/(r+0.5)
a = sin(theta/2)
b = sqrt(1-(M-1)*a*a)
