Approximating an Integral for Numerical Computation I have a program that involves computing a definite integral many times, and have been struggling to find a way to do so quickly. The integrals I need to solve are of the following form:
$$\int_{a(r)}^{b}f(x)g(x-r)dx$$
where I need to compute the integral for many different values of r.  At the moment I am stuck figuring at a programming solution and instead am looking for a way to mathematically approximate this integral.  Does anyone have any ideas/tricks/resources?  If it helps, the function g is a lognormal pdf, so I am actually taking the expected value of function f. 
Thanks!
EDITED:
Thank you to everyone who has commented so far.  A few people have asked about including additional information about the problem.
$a(r)$ is the root of the following equation:
$$\theta*(a-\theta)^2-\frac{1-f(r+a-\theta)}{f(r+a-\theta)}$$
where $\theta $ and $r$ are parameters
$f(x)$ is equal to the following:
$$f(x)=Pr(\sum z*I(z)>r)$$
where $z$ is a random variable with a lognormal distribution, and $I(z)$ is the indicator function equal to 1 when $z>a(r)$
$g(x)$ is the pdf of a lognormal distribution
This is complicated and very specific problem, which is why I at first looked for general ways to approximate the integral, but I hope the additional information is helpful. Thanks again for all your input.
 A: Since you do not give much details about the analytical expressions of functions f(x) and g(x-r), I should admit (?) that the analytical integration cannot be performed [if you post your expressions, I shall have a look at the problem of the analytical integration]. Then, the only solution left is numerical integration. There are a lot of methods which are available for point values integration                                                  (see for example http://en.wikipedia.org/wiki/Newton-Cotes_formulas - higher orders are available). Otherwise, use a Runge-Kutta method                                         (see for example http://en.wikipedia.org/wiki/Runge-Kutta_methods).
All these methods are easy to implement and they are quite fast.
A: Based on the latest snippet of information from you, you are just summing the function at multiple equidistant sample points and multiplying by h. That is incredibly bad because the error is proportional to h.
Simply summing using trapezoidal should do it:
$integ = h*(f(a) + f(b)) * .5 +  \dots \text{sum the rest}$
Then, to dramatically reduce the number of slices needed, use first stage Romberg:
$I1 = \text{// compute using trapezoidal with n slices}$
$I2 = \text{// compute using same, 2n slices.}$
$$R1 = \frac{(4I2 - I1)}{3};  \text{// error is now proportional to } h^4 $$
You keep doubling the number of slices, and stop when
$$ |R2 - R1| < eps$$
where eps is the absolute error you want, or
$$\left|\frac{(R2-R1)}{R2}\right| < eps$$
relative error is safer if your answers can be near zero.
You can confirm this by telling everyone a before and after.  How many slices are you using with the current method, and how many once you switch over?
It sounds like you have a single function $f(x)$ and $g(x)$.  If that is true, simply post the functions so that everyone can look at them. It's much simpler than you talking about them.  If it's not true, at least post an example of both functions.
Give an example of a and b for the specific example.  And most important, what accuracy do you need?
You claim to be getting an answer in 15ms and need more like 1.  I have written numerical integration routines in C++ which varied by a factor of 4 based on implementation, so optimization alone won't get you there.  But with 4 CPUs operating in parallel, that alone could easily solve your problem because this problem is almost completely CPU-based. Just split the loop in OpenMP.  If you are writing the code in anything but a compiled, statically typed language, then that is your solution. For example, if you were using python, you could gain a factor of 100 just by switching to C.
I realize that the implementation details are a bit off topic here.
I would recommend one of two approaches: either trapezoidal (2nd order) with Romberg (stage 1 will give you $h^4$, and step 2 will give you $h^6$.
Or Gaussian Quadrature, 3rd order, giving $h^6$ accuracy with 3 points.
Since your function is some sort of distribution, it may be that you have too big of a tail to numerically integrate efficiently.  In that case you need to first transform the limits to a finite form.
