from sympy import exp, Symbol, solve, Piecewise
import numpy as np

epsilon = 0.01
ad = 2
t = Symbol('t')
f = pow(ad, 2) * t * exp(-1 * ad * t) - epsilon

#print(solve([f], t, dict=True, quick=True))

def alpha(t, ad):
    if t < 0:
        return 0
    else:
        return pow(ad, 2) * t * np.exp(-1 * ad * t)

def find(function, farg, arange, epsilon):
    xs = []
    for x in arange:
        if function(x, **farg) < epsilon:
            xs.append(x)
    return xs

if __name__ == "__main__":
    import timeit
    """
    print(timeit.timeit("solve([f], t, dict=True)",
                            setup="from __main__ import solve, f, t",
                            number=10000))
    print(timeit.timeit("solve([f], t, dict=True, quick=True)",
                            setup="from __main__ import solve, f, t",
                            number=10000))
    """
    print(timeit.timeit("find(alpha, {'ad':ad}, np.arange(0, 4, 0.01), 0.01)",
                            setup="from __main__ import find, alpha, ad , t, f, np",
                            number=10000))
