Ask Your Question
1

Basic integral error

asked 6 years ago

Vincent 87 gravatar image

updated 6 years ago

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.

Preview: (hide)

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 ( 6 years ago )

3 Answers

Sort by » oldest newest most voted
2

answered 6 years ago

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

Preview: (hide)
link
1

answered 6 years ago

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.

Preview: (hide)
link
0

answered 5 years ago

Vincent 87 gravatar image

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

Preview: (hide)
link

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: 6 years ago

Seen: 468 times

Last updated: Mar 17 '19