+#
+# @function integrate
+# @purpose integrate function numerically over a range of arguments
+#
+def integrate(f, xmin, xmax, dx):
+ x = xmin
+ result = 0.00
+ while (x <= xmax):
+ result += f(x) * dx
+ x += dx
+ return result
+
+# @function derivative
+# @purpose get derivative of a function at a value
+def der(f, x, dx):
+ return (f(x + dx) - f(x)) / dx
+
+#
+# @function tcs
+# @purpose Model S(E)
+def tcs(f, sigma, Emin, Emax, dE):
+ results = []
+ E = Emin
+ while (E < Emax):
+ results.append([E, (1.0 - sigma(0)) * f(-E) - integrate(lambda e : f(e - E) * der(sigma, E, dE), Emin, Emax, dE)])
+ E += dE
+ return results
+
+def delta(x):
+ if (x == 0):
+ return 1.0
+ else:
+ return 0.0
+
+def table(f, xmin, xmax, dx):
+ result = []
+ x = xmin
+ while (x <= xmax):
+ result.append([x, f(x)])
+ x += dx
+ return result
+
+def gaussian(x, sigma):
+ return math.exp(- (x**2.0)/(2.0 * sigma**2.0)) / (sigma * (2.0 * math.pi)**0.50)
+
+def step(x, sigma, T):
+ return 1.0 / (math.exp((x - sigma)/T) + 1.0)
+