Basic integral error

In Sage 8.6 (Mac OS):

sage: integral(ln(1 + sqrt(x))/sqrt(x), x, 1, 4)
4*log(3) + 2*log(4/3) - 2
sage: n(_)
2.96981329957600

while

sage: numerical_integral(ln(1 + sqrt(x))/sqrt(x), 1, 4)
(1.8190850097688764, 2.0195900615958844e-14).

By hand, the correct result is 6*ln(3) - 4*ln(2) - 2.

edit retag close merge delete

Does 6n(3) - 4ln(2) - 2 mean 6ln(3) - 4ln(2) - 2? If so, it will be same with 1.8190850097688764.

Sort by » oldest newest most voted

Thanks for reporting, this is indeed a bug.

Sage's default integration engine is Maxima and gets this wrong, maybe because we set up maxima to work in the complex domain.

sage: integral(ln(1 + sqrt(x))/sqrt(x), x, 1, 4)
4*log(3) + 2*log(4/3) - 2
sage: integral(ln(1 + sqrt(x))/sqrt(x), x, 1, 4, algorithm='maxima')
4*log(3) + 2*log(4/3) - 2

You can specify which engine you want Sage to call to compute the integral, and the other engines get this right:

sage: integral(ln(1 + sqrt(x))/sqrt(x), x, 1, 4, algorithm='sympy')
6*log(3) - 4*log(2) - 2
sage: integral(ln(1 + sqrt(x))/sqrt(x), x, 1, 4, algorithm='giac')
6*log(3) - 4*log(2) - 2
sage: integral(ln(1 + sqrt(x))/sqrt(x), x, 1, 4, algorithm='fricas')
6*log(3) - 4*log(2) - 2

(the last one depends on installing FriCAS, which can be done by running

sage -i fricas

in a terminal).

more

[ Not really an answer, but a complement to Serge's answer, in order too pinpoint the answer ]

A quick check:

f(x)=log(sqrt(x)+1)/sqrt(x)

def tst1(alg="maxima"):
di=(ub-lb).simplify()
did=f(x).integrate(x,1,4, algorithm=alg)
check_di=bool(di==did)
ndi=di.n()
# return [ad, check_ad, lb, ub, di, did, check_di, ndi]
return [alg, check_ad, di, did, check_di]

T=table(rows=[tst1(alg=u) for u in ["maxima", "sympy", "giac", "fricas"]],
"Def. int. directly", "Def. int. checks"])

shows that the antiderivative (aka primitive, AD) is correct (i.e. derivates back to f(x)) in all cases (and that its limits are correctly evaluated at each bound), but that the direct computation of the definite integral is wrong in Maxima :

Algorithm    AD checks   Def. int. through AD      Def. int. directly          Def. int. checks
+-----------+------------+-------------------------+---------------------------+------------------+
maxima      True         6*log(3) - 4*log(2) - 2   4*log(3) + 2*log(4/3) - 2   False
sympy       True         6*log(3) - 4*log(2) - 2   6*log(3) - 4*log(2) - 2     True
giac        True         6*log(3) - 4*log(2) - 2   6*log(3) - 4*log(2) - 2     True
fricas      True         6*log(3) - 4*log(2) - 2   6*log(3) - 4*log(2) - 2     True

This problem has been encountered more than once, is known to upstream, but does not seem to have been formally reported per se.

more

Thanks for your answers. But now, I just wonder if I shall always use sympy algorithm when computing integrals !

more