# Definite and Indefinite integral give different results for piecewise function

I have the following function:

$$f(q,y)= \begin{cases} \tfrac{11720+p}{37791360} & -11720<p<-7720 \\ 0 & \text{True} \end{cases}$$

where $p = 443\ y-777600\ \sin^{-1}\left(\frac{q \lambda }{4 \pi }\right)$.

Mathematica Code:

f[q_,y_]=Piecewise[
{{(11720+443 y-777600 ArcSin[(q λ)/(4 π)])/37791360,
-11720<443 y-777600 ArcSin[(q λ)/(4 π)]<-7720}},
0]


Now, if I take an indefinite integral over y,

weird[q_, y_] = Integrate[f[q, y], y]


which gives

$$g(q,y)= \begin{cases} \frac{293 y}{944784}+\frac{443 y^2}{75582720}-\frac{5}{243} y\ \sin^{-1}\left(\frac{\text{qy} \lambda }{4 \pi }\right) & -11720<p<-7720 \\ 0 & \text{True} \end{cases}$$

I can then evaluate this function at my endpoints {-1,1} to get the definite integral.

However, I could also have Mathematica run the definite integral directly.

weirder[q_, y_] = Integrate[f[q, y], {y, -1, 1}]


which gives

Plain Text Version:

\[Piecewise]    (293-19440 ArcSin[(q \[Lambda])/(4 \[Pi])])/472392             907/86400<ArcSin[(q \[Lambda])/(4 \[Pi])]<=1253/86400
(1/33483144960)(-111170729+29544134400 ArcSin[(q \[Lambda])/(4 \[Pi])]-1209323520000     ArcSin[(q \[Lambda])/(4 \[Pi])]^2-12006144000 I Log[4     \[Pi]]-604661760000 Log[4 \[Pi]]^2+12006144000 I Log[I q \[Lambda]+Sqrt[16 \[Pi]^2-q^2 \[Lambda]^2]]+1209323520000 Log[4 \[Pi]] Log[I q \[Lambda]+Sqrt[16 \[Pi]^2-q^2 \[Lambda]^2]]-604661760000 Log[I q \[Lambda]+Sqrt[16 \[Pi]^2-q^2 \[Lambda]^2]]^2)  7277/777600<ArcSin[(q \[Lambda])/(4 \[Pi])]<=907/86400
(1/33483144960)(147938569-37142841600 ArcSin[(q \[Lambda])/(4 \[Pi])]+1209323520000 ArcSin[(q \[Lambda])/(4 \[Pi])]^2+18226944000 I Log[4 \[Pi]]+604661760000 Log[4 \[Pi]]^2-18226944000 I Log[I q \[Lambda]+Sqrt[16 \[Pi]^2-q^2 \[Lambda]^2]]-1209323520000 Log[4 \[Pi]] Log[I q \[Lambda]+Sqrt[16 \[Pi]^2-q^2 \[Lambda]^2]]+604661760000 Log[I q \[Lambda]+Sqrt[16 \[Pi]^2-q^2 \[Lambda]^2]]^2)   1253/86400<ArcSin[(q \[Lambda])/(4 \[Pi])]<12163/777600
0   True


This result, depending on my value of q, is different that the result given by the indefinite integral. Specifically of note are the log terms, which did not appear in the indefinite integral.

Why is the definite integral different from subtracting the end points of the indefinite integral? Which of these results should I trust?

-
Can you give a value of $q$ and $\lambda$ that actually give a different numerical result? –  Simon Feb 24 '12 at 1:35
When the indefinite integral has discontunities, substituting the endpoints in the indefinite integral expression gives incorrect results. You get the correct result for the definite integral. Check the section Possible Issues subsection Definite Integral under Integrate in documentation. –  kguler Feb 24 '12 at 2:05

When the indefinite integral has discontunities (as is the case for your integrand for some values of q and alpha), substituting the endpoints in the indefinite integral expression gives incorrect results. To get the correct result you need to use the definite integral.
Please see the section Possible Issues subsection Definite Integral under Integrate in docs.
A particularly nasty example is $$\int^\infty_0 \frac{e^{−x}}{\sin x}dx$$ which is discussed here. Of particular relevance is this answer which discusses how the changing the limits effected the outcome. –  rcollyer Mar 2 '12 at 19:37