oxp = Symbol("Omega_x'")
b = Symbol("b")
n = Symbol("n")
theta = Symbol("theta")
w = Symbol("w")
s = Symbol("s")
a = Symbol("a")

subsampledOmega = (binomial(s, b) * binomial(n - s, a - b)) / binomial(n, a)
subsampledFpF = Sum(subsampledOmega, (b, theta, s))
subsampledOmegaSlow = (binomial(s, b) * binomial(n - s, a - b)) 
subsampledFpFSlow = Sum(subsampledOmegaSlow, (b, theta, s))/ binomial(n, a)

display(subsampledFpF)
display(subsampledFpFSlow)




"""
Explanation: Equation for Neuron Paper
  A dendritic segment can robustly classify a pattern by subsampling a small number of cells from a larger population.  Assuming a random distribution of patterns, the exact probability of a false match is given by the following equation:
End of explanation
"""


display("n=1024, a=8, s=4, omega=2", subsampledFpF.subs(s, 4).subs(n, 1024).subs(a, 8).subs(theta, 2).evalf())

display("n=200000, a=2000, s=20, theta=10", subsampledFpF.subs(theta, 10).subs(s, 20).subs(n, 200000).subs(a, 2000).evalf())

display("n=200000, a=2000, s=40, theta=10", subsampledFpF.subs(theta, 15).subs(s, 120).subs(n, 200000).subs(a, 2000).evalf())

"""
Explanation: where n refers to the size of the population of cells, a is the number of active cells at any instance in time, s is the number of actual synapses on a dendritic segment, and θ is the threshold for NMDA spikes. Following   (Ahmad &amp; Hawkins, 2015), the numerator counts the number of possible ways θ or more cells can match a fixed set of s synapses. The denominator counts the number of ways a cells out of n can be active.

Example usage
End of explanation
"""


