integration

11 views
Skip to first unread message

68th

unread,
Jul 23, 2023, 12:53:22 PM7/23/23
to fricas...@googlegroups.com
Okay, here's the integrand:

ex1 := (1+tan(gamma/2)^2)/(k^2+l^2*tan(gamma/2)^2)

Let's find the antiderivative:

ex2 := integrate(ex1,gamma)

And this is a simpler variant of the antiderivative:

ex3 := (2*atan(l/k*tan(gamma/2)))/(k*l)

Let's do a simple comparison:

normalize(ex2-ex3)

Oops, the difference is -π/(2kl). However:

D(ex2,gamma)-D(ex3,gamma)

returns zero.

How can make FriCAS find the simpler antiderivative?

Waldek Hebisch

unread,
Jul 23, 2023, 4:36:42 PM7/23/23
to '68th' via FriCAS - computer algebra system
Ideally FriCAS sould automatically find simpler form. ATM we
are getting more complex one, depending on point of view this
is a bug or missing feature. I you want more info, you
can see intermediate results of integration. Namely do:

)trace INTEF )math

and then issue integration command. This produces a bit
more of output, but the important part is:

2 2 2 2 %i gamma 2 2
--+ 2 %i k l (l - k )%e - l - k
> %E log(--------- %E + -----------------------------)
--+ 2 2 2 2
2 1 l - k l - k
%E + ---- = 0
2 2
k l

The sum part means sum over roots of polynomial below the summation
sign. This is quadratic polynomial with two purely imaginary
roots. So we get expression in terms logarithms with complex
arguments. Theory says that this is simplest possible expression
of similar form.

The final result is obtained transforming complex logaritms into
sums of atan and real logarithm. Above real logarithm cancel
and what remains is sum of two identical atans, so has only
one term. When done naively, this transformation results in
effect that you see (some people call it "atan doubling").

Transformation code performs extra computation designed to avoid
this effect. But in this case it does not work.

--
Waldek Hebisch

68th

unread,
Jul 24, 2023, 1:12:46 PM7/24/23
to fricas...@googlegroups.com
------- Original Message -------
On Sunday, July 23rd, 2023 at 8:36 PM, Waldek Hebisch <de...@fricas.math.uni.wroc.pl> wrote:

> )trace INTEF )math

Can ')trace' be somehow used for 'normalize' to see its intermediate steps?

> Theory says that this is simplest possible expression
> of similar form.

That's not how I found the simpler antiderivative. I don't use complex exponential functions. It only takes a right u-substitution.

> But in this case it does not work.

Okay, FriCAS magic doesn't work. The question is: is it still possible to make FriCAS find the simpler antiderivative? Can a user have any control over the integration process? Let's say:

u := l/k*tan(gamma/2)

If I will be able to do all the necessary transformation to the integrand, can I then use u as the second argument in the 'integrate' command?

Waldek Hebisch

unread,
Jul 25, 2023, 11:10:46 AM7/25/23
to '68th' via FriCAS - computer algebra system
On Mon, Jul 24, 2023 at 05:12:37PM +0000, '68th' via FriCAS - computer algebra system wrote:
> ------- Original Message -------
> On Sunday, July 23rd, 2023 at 8:36 PM, Waldek Hebisch <de...@fricas.math.uni.wroc.pl> wrote:
>
> > )trace INTEF )math
>
> Can ')trace' be somehow used for 'normalize' to see its intermediate steps?

Try

)trace EFSTRUC )math

But you will see that there are two steps, one transforms function
to standard form, for example expressing trignomentric functions
in terms of tangents, and the second one i normalization proper.

You will get more info using

)trace LINDEP )math

For example,

normalize(exp(2*x) - exp(x)^2)

tries to find linear dependence over integrs between 1 and 2.

But trace does not say why this system? Well, the rule is:
look arguments of all expnential and logaritms which appear
in your expression. In this case you get exp(x) and exp(2*x)
as exponentials and there are no logratims. Arguments of
exponentials are x and 2x. Then we form derivatives of arguments,
that is 1 and 2 and we try to find releation over integers.
Well, 2*1 = 2. From this we infer that exp(2*x)/exp(x)^2 is
a constant, if fact 1. So we replace exp(2*x) by exp(x)^2
and we get

exp(x)^2 - exp(x)^2

that is zero (internally replacement and simplifiaction
is done together.

Note that things like EFSTRUC or LINDEP are abbreviations,
FriCAS hyperdoc browse command or )show command show that
full name is ElementaryFunctionStructurePackage. From
browse you can go to source and see what each function is
doing.

> > Theory says that this is simplest possible expression
> > of similar form.
>
> That's not how I found the simpler antiderivative. I don't use complex exponential functions. It only takes a right u-substitution.

But in general substitutions are hard to find. Expressing trigonometic
functions in terms of complex exponential is much easier (purely
mechanical).
> > But in this case it does not work.
>
> Okay, FriCAS magic doesn't work. The question is: is it still possible to make FriCAS find the simpler antiderivative? Can a user have any control over the integration process? Let's say:
>
> u := l/k*tan(gamma/2)
>
> If I will be able to do all the necessary transformation to the integrand, can I then use u as the second argument in the 'integrate' command?

Well, you can do substitution, pass that to integrate and do
backsubstitution. But 'integrate' is an algorithm, it dully
performs all its steps. And FriCAS gives you warranty that
when there are no algebraics and antiderivative is elementary
than FriCAS will find an antiderivative. If you deviate from
prescribed steps, then there is no such warranty, So FriCAS
can not allow variation for elementary integrals. Once
integral is determined to be nonelementry, than there is
some possibility for variation. But there is another aspect:
allowing more things internally means more code in integrator.
For example, in the past FriCAS would handle your integral
directly in terms of tangent, whithout introducing complex
numbers. I think that this version would automatically find
equvalent of you substitution. Corresponding code was
developed it the hope that working it terms of tangents
would give better integrals. But while using tangents would
give improvement, in other cases tangents lead to more
complicated integration. On avergage complex transformation
seem to give better results. So code for handling tangent
was removed, it is better to improve/fix transformation
stage.

--
Waldek Hebisch

68th

unread,
Jul 26, 2023, 10:51:35 AM7/26/23
to fricas...@googlegroups.com
------- Original Message -------
On Tuesday, July 25th, 2023 at 3:10 PM, Waldek Hebisch <de...@fricas.math.uni.wroc.pl> wrote:

> Well, you can do substitution, pass that to integrate and do
> backsubstitution.

If I do

u := l/k*tan(gamma/2)

then I can't use it in

integrate(1/(1+u^2),u)
Cannot find a definition or applicable library operation named integrate with argument type(s)
Expression(Integer)
Expression(Integer)

How to do u-substitution in FriCAS?

Waldek Hebisch

unread,
Jul 27, 2023, 8:30:28 AM7/27/23
to '68th' via FriCAS - computer algebra system
ex1 := (1+tan(gamma/2)^2)/(k^2+l^2*tan(gamma/2)^2)
d_subst := (k/l)*u
inv_subst := l/k*tan(gamma/2)
exs := subst(ex1/D(inv_subst, gamma), tan(gamma/2)= d_subst)
iis := integrate(exs, u)
subst(iis, u = inv_subst)

Note that you need to provide both direct substitution and an inverse
one. And you can substitute only for kernels, that is things like
tan(x/2), exp(x^2), etc. With that constraints commands above will
work for many substitutions. You just need to give the kernel
(tan(gamma/2) in this case), new variable (u int this case),
direct substitution and inverse substitution.

As I wrote, when FriCAS thinks that substitutions are useful
it finds and applies them automatically. In general equation
u = f(k) may be not solvable for k, but you can do substitutions
essentially via pattern matching. In FriCAS this gets messy
because user would have to supply appropriate rewrite rules.

Still, the case above where we substitute for kernels and
both substitutions are give by formulas covers many important
special cases.

--
Waldek Hebisch

68th

unread,
Jul 29, 2023, 3:00:54 AM7/29/23
to fricas...@googlegroups.com
------- Original Message -------
On Thursday, July 27th, 2023 at 12:30 PM, Waldek Hebisch <de...@fricas.math.uni.wroc.pl> wrote:

> ex1 := (1+tan(gamma/2)^2)/(k^2+l^2*tan(gamma/2)^2)
> d_subst := (k/l)u
> inv_subst := l/ktan(gamma/2)
> exs := subst(ex1/D(inv_subst, gamma), tan(gamma/2)= d_subst)
> iis := integrate(exs, u)
> subst(iis, u = inv_subst)

Thank you very much! Now I can do all my calculations in FriCAS.

Waldek Hebisch

unread,
Jul 30, 2023, 5:41:18 AM7/30/23
to '68th' via FriCAS - computer algebra system
Glad to hear this.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages