Hi all

Today I had hard time with Sage because

sage: f(x)=1/(1-x**2)
sage: g(x)=f.integrate(x)
sage: g(0.5)
0.549306144334055 - 1.57079632679490*I
sage: g
x |--> -1/2*log(x - 1) + 1/2*log(x + 1)


This is not the primitive my students are expecting : they expect 1-x on the denominator. In particular they are not expecting :

sage: ln(-1)
I*pi


I had other some small problems like that with Sage like the difference between +Inf,-Inf and Inf when computing a limit (in the latter case my students are expecting "does not exist").

So my question is : is there a way to ask Sage to behave like a very undergrad student is expected to behave ? (ex : ln(-1) does not exist) Is there a way to say «I'm an undergrad student and I want Sage to solve my homework of basics calculus» ?

Do you have experience/habits to prevent Sage to mislead students by its unexpected answers (however mathematically correct) ?

edit retag close merge delete

Sort by » oldest newest most voted

If you do

sage: f(x)=1/(1-x**2)
sage: g(x)=f.integrate(x)
sage: g(0.5)


why should you expect anything at all? g(x) is only defined up to a constant summand, so g(0.5) could be literally anything. Perhaps you should do

sage: g(0.5) - g(0.0)


Note that since the integrand is undefined when x is 1 or -1, it should not be a surprise that

sage: g(1.5) - g(0.5)


returns something that is not real.

Alternatively, you can do this:

sage: g(x) = f.integrate(x)
sage: h(x) = g(x) - g(0.0)  # h is the integral of f from 0 to x
sage: h(0.5)
0.549306144334055


or

sage: var('t')
sage: h(t) = f.integrate(x, 0, t)


At this point Sage complains, so you can tell it

sage: assume(t>0)


and then (since it still complains if you do f.integrate(x, 0, t)):

sage: assume(t<1)
sage: h(t) = f.integrate(x, 0, t)
sage: h(0.5)

more

I suspect there is a way to address your first question, but I'll concentrate on the meta-questions.

The short answer is that we have had long, long discussions in the past about this, and the consensus among the developers was always that we did not want to support this. I don't think anyone was opposed to someone developing a "calculus mode", but thus far no one has implemented it; I don't think it would be trivial to do.

I was usually on the losing end in such discussions 3 or 4 years ago, but I now have seen the utility of having the "mathematically correct" answer - and I suspect that my American students are no more, or perhaps rather less, ready to see that ln(-1) exists than your Belgian ones. Certainly the idea of Inf having meaning is useful for vertical asymptotes (see Winston Churchill's thoughts on this).

I take it as a teaching opportunity, and also make sure that I try my examples ahead of time! Early in my Sage use in class, not trying things ahead of time led to surprises more than once.

I encourage you to subscribe/post to sage-edu, where people definitely have opinions and ideas about such things.

As to the specific example you gave, I agree that is very annoying. One would want primitives to be real if possible, but I don't know that Maxima would consider this to be a bug. You could try one of the other algorithms.

sage: g = integrate(f,x,algorithm='sympy')
sage: g
x |--> -1/2*log(x - 1) + 1/2*log(x + 1)  # same as Maxima
sage: g = integrate(f,x,algorithm='mathematica_free')  # Wolfram Alpha
sage: g
x |--> 1/2*log(-x - 1) - 1/2*log(x - 1)
sage: g(0.5)
0.549306144334055
sage: g(1.1)
1.52226121886171 + 1.57079632679490*I


So probably there isn't an easy way around this; no primitive will be nice for all values of $x$.

Edit: Naturally, jhpalmieri is right and I was not thinking clearly.

more

sage: maxima('logabs:true') sage: f(x)=maxima('integrate(1/(1-x^2),x)').sage() sage: f(x) -1/2*log(abs(x - 1)) + 1/2*log(abs(x + 1)) sage: f(0.5) 0.549306144334055 sage: f(1.1) 1.52226121886171

( 2012-02-02 07:09:28 -0500 )edit

Ah, the many Maxima flags!

( 2012-02-02 14:02:25 -0500 )edit