| Hosted by CoCalc | Download

###Bug in Sage Integral Computations?###

# Better version of FriCAS mode for SageMathCloud os.environ['PATH'] = '%s/bin:%s'%(os.environ['HOME'],os.environ['PATH']) from fricas import fricas execfile('fricas_md.py') %default_mode fricas_md
)version )clear completely )set output tex on )set output algebra off

Value = "FriCAS 2014-12-18 compiled at Tue May 5 18:13:01 UTC 2015"

All user variables and function definitions have been cleared.

All )browse facility databases have been cleared.

Internally cached functions and constructors have been cleared.

)clear completely is finished.

FriCAS agrees with Sage that the value of the integral is 0.

ex:=sqrt( cot(x)^2 )
$$\sqrt {{{{\cot \left( {x} \right)}} ^{2}}}$$

Type: Expression(Integer)

i1:=integrate(ex, x = %pi/4 .. 3*%pi/4,"noPole")
00

Type: Union(f1: OrderedCompletion(Expression(Integer)),...)

%sage typeset_mode(true) s1=integrate(sqrt( cot(x)^2 ), x,pi/4,3*pi/4);s1
00

Consider the indefinite integral

i2:=integrate(ex, x)
$${{2 \ {\log \left( {{{\sin \left( {{2 \ x}} \right)} \over {{\cos \left( {{2 \ x}} \right)}+1}}} \right)}} -{\log \left( {{2 \over {{\cos \left( {{2 \ x}} \right)}+1}}} \right)}} \over 2$$

Type: Union(Expression(Integer),...)

%sage s2=fricas('i2::Expression Integer').sage();s2
log(sin(2x)cos(2x)+1)12log(2cos(2x)+1)\log\left(\frac{\sin\left(2 \, x\right)}{\cos\left(2 \, x\right) + 1}\right) - \frac{1}{2} \, \log\left(\frac{2}{\cos\left(2 \, x\right) + 1}\right)
%sage plot(s2,x,pi/4,2*pi/4)

There is a pole at π/2\pi/2 and the branch becomes complex after that point.

eval(i2,x=2*%pi/4-0.0001)
0.4999955155E8-{0.4999955155 E -8}

Type: Expression(Float)

eval(i2,x=3*%pi/4)
$${-{\log \left( {2} \right)}+{2 \ {\log \left( {-1} \right)}}} \over 2$$

Type: Expression(Integer)

complexNumeric %
0.3465735902_7997265471+3.1415926535_897932385 i-{0.3465735902\_7997265471}+{{3.1415926535\_897932385} \ i}

Type: Complex(Float)

Both  \sqrt \ and log(x)\log(x) for x<0x<0 are "multi-valued functions". In the case of log, the branches for negative numbers differ by iπi\pi, so we can choose a branch that is real-valued.

i3:=i2-%pi*%i
$${{2 \ {\log \left( {{{\sin \left( {{2 \ x}} \right)} \over {{\cos \left( {{2 \ x}} \right)}+1}}} \right)}} -{\log \left( {{2 \over {{\cos \left( {{2 \ x}} \right)}+1}}} \right)} -{2 \ i \ \pi}} \over 2$$

Type: Expression(Complex(Integer))

eval(i3,x=3*%pi/4)
$${-{\log \left( {2} \right)}+{2 \ {\log \left( {-1} \right)}} -{2 \ i \ \pi}} \over 2$$

Type: Expression(Complex(Integer))

complexNumeric %
0.3465735902_7997265471-{0.3465735902\_7997265471}

Type: Complex(Float)

%sage s3=fricas('i2::Expression Integer').sage()-pi*i;s3
iπ+log(sin(2x)cos(2x)+1)12log(2cos(2x)+1)-i \, \pi + \log\left(\frac{\sin\left(2 \, x\right)}{\cos\left(2 \, x\right) + 1}\right) - \frac{1}{2} \, \log\left(\frac{2}{\cos\left(2 \, x\right) + 1}\right)
%sage s3.substitute(x=3*pi/4)
12log(2)-\frac{1}{2} \, \log\left(2\right)
%sage def ss(x0): return s3.substitute(x=x0).N()
%sage ss(2*pi/4+0.0001)
-3.62865471004170e-9
%sage plot(ss,2*pi/4+0.0001,3*pi/4)

We expect the derivative of the indefinite integral to be equal to the original expression.

d1:=differentiate(i2,x)
$${{{{\sin \left( {{2 \ x}} \right)}} ^{2}}+{2 \ {{{\cos \left( {{2 \ x}} \right)}} ^{2}}}+{2 \ {\cos \left( {{2 \ x}} \right)}}} \over {{\left( {\cos \left( {{2 \ x}} \right)}+1 \right)} \ {\sin \left( {{2 \ x}} \right)}}$$

Type: Expression(Integer)

In FriCAS normalize rewites an expression "using the least possible number of algebraically independent kernels".

normalize(ex-d1)
00

Type: Expression(Integer)

%sage s2=integrate( sqrt( cot(x)^2 ), x); s2
12log(tan(x)2+1)+log(tan(x))-\frac{1}{2} \, \log\left(\tan\left(x\right)^{2} + 1\right) + \log\left(\tan\left(x\right)\right)
%sage (fricas(s2)-fricas('i2')).normalize().sage()
00

The conclusion is that although these results are not identical they are nonetheless algebraically dependent.