Question:Maple's default integrate result is not always the best. How to select the best one

Question:Maple's default integrate result is not always the best. How to select the best one

Maple 2024

Maple int gives one result, called the "default" result unless one uses method=_RETURNVERBOSE to look for other results.

First, how does Maple decide what is "default" i.e. given all the methods listed, what method then used for "default".

Here is an example where default result makes it hard to solve for a differential equation. The integrand is

`1/(y+sqrt(y))`

Maple int default gives anti as ln(y - 1) + 2*arctanh(sqrt(y))  which is complex valued for all y. The arctanh is only defined for argument between -1 and 1 also. Having sqrt there makes it now valid for 0 to 1. But ln(y-1) is negative in this region also. Hence complex.

Using method=_RETURNVERBOSE we see much better anti derivatives hidding there and given by "derivativedivides" and "meijerg" as 2*ln(1 + sqrt(y)) which is complex valued only for negative y and real for all positive y. Same for "trager"  ln(2*sqrt(y) + 1 + y)

So it would have been much better if Maple picks the best anti-derivative automatically and use that for default instead and give this to the user.

Why is this important? Try to solve   the ode y'/(y+sqrt(y))=2 with IC y(0)=1 and you see we can't solve for the constant of integration using  ln(y - 1) + 2*arctanh(sqrt(y))=2x+c since at y=1 we get division by zero. If Maple had returned 2*ln(1 + sqrt(y)) instead then solving for constant of integration is trivial now since anti is real and defined at y=1

This is just one example of many.

My question is, How does Maple integrate decide what is "default" and why it does not try harder to pick better one (using number of known metrices for this sort of thing) from the other solvers it already has access to?

What is the point of having all these other nice integrate methods, if the default used is not the "best" one?

Should user then always use method=_RETURNVERBOSE and then try to pick the "best" one themselves? This will be too much work for user to do.

I think Maple should do this automatically. Btw, I tried few other CAS integrators and the all give the better result given above by "meijerg" automatically.

Maple 2024

Update

Here is a quick function, called it smart_int() which returns the anti-derivative with the smallest leaf size from Maple.

Ofcourse smallest leaf size does not mean the anti-derivative is necessarily the "best" using other measures. But this function already allowed me to solve some ode's I could not solve before using Maple's defaullt int result because it made solving for constant of integration easier now.

Feel free to improve and change. If you find any bugs please let me know

The test here shows the result of smart_int compared to int on few integrals. You see on many of them smart_int gives smaller result. Additional criteria for selection can ofcourse be added and I will probably do that.

For example, do not pick ones with complex numbers if there is one without even though leaf size is smaller. This check has been added also.

Check the last integral in this test. The difference is so large.

 > restart:

 > #smart_int picks the anti-derivative with smallest leaf count #version June 1, 2024. Maple 2024 #change: added check not to pick one with complex even is smaller #change: added percentage reduction smart_int:=proc(integrand,x::symbol) local anti,result_of_int,a,b;     local F:=proc(a,b)::truefalse;               if (has(a,I) and has(b,I)) or ( not has(a,I)  and not has(b,I)) then            evalb(MmaTranslator:-Mma:-LeafCount(a)rhs(X),result_of_int);     result_of_int := sort(result_of_int,(a,b)->F(a,b));     #return the one with smallest leaf size     RETURN(result_of_int[1]);      end proc:
 > #TESTS tests:=[1/(x+sqrt(x)),1/(sin(x)),1/(cos(x)),sin(x)/(sin(x)+1),1/((1+x)^(2/3)-(1+x)^(1/2)),1/x^3/(1+x)^(3/2),1/(1-x)^(7/2)/x^5,x*((-a+x)/(b-x))^(1/2),x/(-x^2+5)/(-x^2+3)^(1/2),exp(arcsin(x))*x^3/(-x^2+1)^(1/2),x*arctan(x)^2*ln(x^2+1),(x^2+1)/(-x^2+1)/(x^4+1)^(1/2),(a+b*f*x+b*sin(f*x+e))/(a+a*cos(f*x+e)),x*ln(1/x+1),1/x/(x^5+1)]; result:=map(X->[Int(X,x),int(X,x),smart_int(X,x)],tests): for item in result do     print("###################################\nintegral",item[1]);     print("maple default result ",item[2]);     print("smart int result ",item[3]);     PERCENTAGE:=MmaTranslator:-Mma:-LeafCount(item[3])*100/MmaTranslator:-Mma:-LeafCount(item[2]):     print("smart int percentage size relative to default ",sprintf("%.2f",PERCENTAGE)); od:

 >