Ask Your Question
1

Sage for (very) undergrad students

asked 2012-02-02 07:58:11 +0100

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2012-02-02 16:11:15 +0100

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)
edit flag offensive delete link more
0

answered 2012-02-02 10:20:34 +0100

kcrisman gravatar image

updated 2012-02-02 21:04:01 +0100

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.

edit flag offensive delete link more

Comments

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

achrzesz gravatar imageachrzesz ( 2012-02-02 14:09:28 +0100 )edit

Ah, the many Maxima flags!

kcrisman gravatar imagekcrisman ( 2012-02-02 21:02:25 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-02-02 07:58:11 +0100

Seen: 436 times

Last updated: Feb 02 '12