Was this bug report even taken into consideration by the developers?
This is a major and very serious flaw which can lead to significant integration errors.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
sslavi: Notice that when x is a negative real number, log(x) and log(abs(x)) differ only by a constant (%i*%pi). Please tell us the "significant integration errors" you are referring to. Notice for instance that the following integrals work correctly as expected:
I was not aware of the fact that the log() returns a general result in a complex form, so that the realpart() function has to be used in order to plot the resulting function over the entire range of x values. Thank you for opening my eyes.
Meanwhile, I have seen there is a straightforward way to instruct Maxima to give absolute value of integrals which involve log() function. It can be done by first setting the logabs variable to true (logabs:true). In that way, Maxima does exactly what was asked in the opening post and it is no longer necessary to use the realpart() function.
I would kindly ask the moderator to mark this bug report as closed, as the problem in the OP has turned out to be a false alarm (and I apologize for that).
Cheers
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Maybe there is no easy way to settle this issue as it seems to touch a fundamental limitation of Maxima: According to my knowledge there is no clean and simple way to tell Maxima what kind of solution you expect. In this case I see two relevant scenarios:
a) You are considering real numbers only. In this case the solution of integrate(1/x, x) is log(abs(x)) and log(x) is wrong as this is not defined for x < 0. In this context the use of functions like realpart does not make sense.
b) You are working in the complex domain. Now log(abs(x)) is wrong and I think the solution log(x) is correct for realpart(x) < 0 too.
Maxima seems to use a kind of muddle-through-approach to work around these problems. Unfortunately this quite often leads to results that are unexpected or plain wrong. In my opinion implementing a clean solution to this basic problem would require an effort that is probably out of reach of the few volunteers that maintain the Maxima codebase. So I think we have to live with these problems until someone comes up with a substantial funding of the necessary development work.
You asked for strange effects. Here is one example: In wxMaxima try
The first diagram does not show any values for x < 0 despite the fact that the integral is defined for x < 0 and the values are real. The situation is similar to the second plot where you see a graph for x < 0 too. How do you explain this difference to an unsuspecting user?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Albrecht,
I have discovered in the meanwhile that a clean solution exists and is already available in Maxima. It is the "logabs" flag - check my previous post with an example.
Currently it is set to "false" by default, and hence the results are given in the complex form. IMO, this variable should be set to "true" by default, because that is the common way the function 1/x is integrated into log(x).
If you type logabs:true before the calculations in your example, all subsequent results will be exactly in the form you and me have asked throughout this discussion.
Cheers
Last edit: sslavi 2015-01-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I agree with Albrecht.
This aspect of Maxima (the need to extract real solutions from integrals with log function) should be better documented, or at least stressed out in the help file.
OR
The logabs should be set to True by default, as it is IMO the way an average user (for example, me :P) expects it to be. I am an engineer and the outputs of my calcs are mostly in the domain of real numbers, with few notable exceptions. Perhaps signal-processing folks might disagree with me on this one, however.
OR
Put a major emphasis on the logabs flag in the help file and in the manuals. That will give people a way to make an informed choice of what kind of results they want to obtain.
Cheers
Last edit: sslavi 2015-01-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"The logabs should be set to True by default"
I disagree. There has been a lot of discussion about that point. See for instance:
Michel Beaudin, "Using ln(|x|) as an Antiderivative for 1/x is a Bad Choice!". Computer Algebra in Education, Aulonna Press, 2008, ISBN-978-0-9754541-9-6, pages 55-70.
I'm closing this bug report now.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Was this bug report even taken into consideration by the developers?
This is a major and very serious flaw which can lead to significant integration errors.
log(abs(x)) is not correct in general
integrate(1/(x+%i),x) currently correctly gives log(x+%i)
With your proposal, it would give log(abs(x+%i)) = log(sqrt(x^2+1))
But diff log(sqrt(x^2+1)) => x/(x^2+1), which has lost the imaginary part -%i/(x^2+1) and so is not equal to 1/(x+%i).
What are the "strange effects" you are alluding to? log(x) is fine for calculating definite integrals for negative x:
(%i2) int: integrate(1/x,x);
(%o2) log(x)
(%i3) subst(-1,x,%o2)-subst(-2,x,%o2);
(%o3) log(-1)-log(-2)
(%i4) rectform(%);
(%o4) -log(2)
(%i5) integrate(1/x,x,-2,-1);
(%o5) -log(2)
Last edit: Stavros Macrakis 2015-01-04
sslavi: Notice that when x is a negative real number, log(x) and log(abs(x)) differ only by a constant (%i*%pi). Please tell us the "significant integration errors" you are referring to. Notice for instance that the following integrals work correctly as expected:
Check the discussion which has generated this bug report: https://sourceforge.net/p/wxmaxima/discussion/435775/thread/3ee84e4d.
That is an example of erroneous (because incomplete) integration.
Last edit: sslavi 2015-01-05
The link you gave needs an extra slash at the end. As I have just answered in that list, the correct way to plot g(x):=log(x-2)-log(x-1) in Maxima is:
(or simply, realpart(g)), which shows no problem.
Also notice that:
That's why there is no need to add abs() to the result of integrate(1/x,x)
Stavros, Jaime,
thank you for spending your time to reply.
I was not aware of the fact that the log() returns a general result in a complex form, so that the realpart() function has to be used in order to plot the resulting function over the entire range of x values. Thank you for opening my eyes.
Meanwhile, I have seen there is a straightforward way to instruct Maxima to give absolute value of integrals which involve log() function. It can be done by first setting the logabs variable to true (logabs:true). In that way, Maxima does exactly what was asked in the opening post and it is no longer necessary to use the realpart() function.
Example:
(%i1)
(%o1)
Thanks again,
cheers
Last edit: sslavi 2015-01-07
I would kindly ask the moderator to mark this bug report as closed, as the problem in the OP has turned out to be a false alarm (and I apologize for that).
Cheers
Maybe there is no easy way to settle this issue as it seems to touch a fundamental limitation of Maxima: According to my knowledge there is no clean and simple way to tell Maxima what kind of solution you expect. In this case I see two relevant scenarios:
a) You are considering real numbers only. In this case the solution of integrate(1/x, x) is log(abs(x)) and log(x) is wrong as this is not defined for x < 0. In this context the use of functions like realpart does not make sense.
b) You are working in the complex domain. Now log(abs(x)) is wrong and I think the solution log(x) is correct for realpart(x) < 0 too.
Maxima seems to use a kind of muddle-through-approach to work around these problems. Unfortunately this quite often leads to results that are unexpected or plain wrong. In my opinion implementing a clean solution to this basic problem would require an effort that is probably out of reach of the few volunteers that maintain the Maxima codebase. So I think we have to live with these problems until someone comes up with a substantial funding of the necessary development work.
You asked for strange effects. Here is one example: In wxMaxima try
plot2d([integrate(1/x,x)], [x,-2,+2], [plot_format, gnuplot])$
and
plot2d([integrate(1/(x*x),x)], [x,-2,+2], [plot_format, gnuplot])$
The first diagram does not show any values for x < 0 despite the fact that the integral is defined for x < 0 and the values are real. The situation is similar to the second plot where you see a graph for x < 0 too. How do you explain this difference to an unsuspecting user?
Albrecht,
I have discovered in the meanwhile that a clean solution exists and is already available in Maxima. It is the "logabs" flag - check my previous post with an example.
Currently it is set to "false" by default, and hence the results are given in the complex form. IMO, this variable should be set to "true" by default, because that is the common way the function 1/x is integrated into log(x).
If you type logabs:true before the calculations in your example, all subsequent results will be exactly in the form you and me have asked throughout this discussion.
Cheers
Last edit: sslavi 2015-01-07
I agree with Albrecht.
This aspect of Maxima (the need to extract real solutions from integrals with log function) should be better documented, or at least stressed out in the help file.
OR
The logabs should be set to True by default, as it is IMO the way an average user (for example, me :P) expects it to be. I am an engineer and the outputs of my calcs are mostly in the domain of real numbers, with few notable exceptions. Perhaps signal-processing folks might disagree with me on this one, however.
OR
Put a major emphasis on the logabs flag in the help file and in the manuals. That will give people a way to make an informed choice of what kind of results they want to obtain.
Cheers
Last edit: sslavi 2015-01-07
"The logabs should be set to True by default"
I disagree. There has been a lot of discussion about that point. See for instance:
Michel Beaudin, "Using ln(|x|) as an Antiderivative for 1/x is a Bad Choice!". Computer Algebra in Education, Aulonna Press, 2008, ISBN-978-0-9754541-9-6, pages 55-70.
I'm closing this bug report now.
I will check Beaudin's paper, thanks for the hint. I have learnt a lots through this discussion.
Cheers