Ask Your Question
1

Basic integral error

asked 2019-03-10 23:37:06 -0500

Vincent 87 gravatar image

updated 2019-03-11 02:15:26 -0500

slelievre gravatar image

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 flag offensive close merge delete

Comments

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

nur_hamid gravatar imagenur_hamid ( 2019-03-11 02:17:59 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2019-03-17 05:41:10 -0500

Vincent 87 gravatar image

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

edit flag offensive delete link more
1

answered 2019-03-11 08:35:05 -0500

Emmanuel Charpentier gravatar image

[ 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"):
    ad=f(x).integrate(x, algorithm=alg)
    check_ad=bool(ad.diff(x)==f(x))
    ub=ad.limit(x=4)
    lb=ad.limit(x=1)
    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"]],
        header_row=["Algorithm", " AD checks", "Def. int. through AD",
                    "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.

edit flag offensive delete link more
2

answered 2019-03-11 02:23:11 -0500

slelievre gravatar image

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).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-03-10 23:37:06 -0500

Seen: 85 times

Last updated: Mar 17