ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 02 Feb 2012 14:02:25 -0600Sage for (very) undergrad studentshttp://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/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) ?
Thu, 02 Feb 2012 00:58:11 -0600http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/Answer by John Palmieri for <p>Hi all</p>
<p>Today I had hard time with Sage because</p>
<pre><code>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)
</code></pre>
<p>This is not the primitive my students are expecting : they expect 1-x on the denominator.
In particular they are not expecting :</p>
<pre><code>sage: ln(-1)
I*pi
</code></pre>
<p>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").</p>
<p>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» ?</p>
<p>Do you have experience/habits to prevent Sage to mislead students by its unexpected answers (however mathematically correct) ?</p>
http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/?answer=13230#post-id-13230If 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)
Thu, 02 Feb 2012 09:11:15 -0600http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/?answer=13230#post-id-13230Answer by kcrisman for <p>Hi all</p>
<p>Today I had hard time with Sage because</p>
<pre><code>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)
</code></pre>
<p>This is not the primitive my students are expecting : they expect 1-x on the denominator.
In particular they are not expecting :</p>
<pre><code>sage: ln(-1)
I*pi
</code></pre>
<p>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").</p>
<p>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» ?</p>
<p>Do you have experience/habits to prevent Sage to mislead students by its unexpected answers (however mathematically correct) ?</p>
http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/?answer=13227#post-id-13227I 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](http://pascal.iseg.utl.pt/~ncrato/Math/Churchill.htm) 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](http://groups.google.com/group/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.Thu, 02 Feb 2012 03:20:34 -0600http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/?answer=13227#post-id-13227Comment by achrzesz for <p>I suspect there is a way to address your first question, but I'll concentrate on the meta-questions.</p>
<p>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. </p>
<p>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 <code>ln(-1)</code> exists than your Belgian ones. Certainly the idea of <code>Inf</code> having meaning is useful for vertical asymptotes (see <a href="http://pascal.iseg.utl.pt/~ncrato/Math/Churchill.htm">Winston Churchill's thoughts</a> on this).</p>
<p>I take it as a teaching opportunity, and also make <strong>sure</strong> 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.</p>
<p>I encourage you to subscribe/post to <a href="http://groups.google.com/group/sage-edu">sage-edu</a>, where people definitely have opinions and ideas about such things.</p>
<p>As to the specific example you gave, I agree <em>that</em> 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.</p>
<pre><code>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
</code></pre>
<p>So probably there isn't an easy way around this; no primitive will be nice for all values of $x$.</p>
<p>Edit: Naturally, jhpalmieri is right and I was not thinking clearly.</p>
http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/?comment=20363#post-id-20363sage: 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
Thu, 02 Feb 2012 07:09:28 -0600http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/?comment=20363#post-id-20363Comment by kcrisman for <p>I suspect there is a way to address your first question, but I'll concentrate on the meta-questions.</p>
<p>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. </p>
<p>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 <code>ln(-1)</code> exists than your Belgian ones. Certainly the idea of <code>Inf</code> having meaning is useful for vertical asymptotes (see <a href="http://pascal.iseg.utl.pt/~ncrato/Math/Churchill.htm">Winston Churchill's thoughts</a> on this).</p>
<p>I take it as a teaching opportunity, and also make <strong>sure</strong> 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.</p>
<p>I encourage you to subscribe/post to <a href="http://groups.google.com/group/sage-edu">sage-edu</a>, where people definitely have opinions and ideas about such things.</p>
<p>As to the specific example you gave, I agree <em>that</em> 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.</p>
<pre><code>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
</code></pre>
<p>So probably there isn't an easy way around this; no primitive will be nice for all values of $x$.</p>
<p>Edit: Naturally, jhpalmieri is right and I was not thinking clearly.</p>
http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/?comment=20359#post-id-20359Ah, the many Maxima flags!Thu, 02 Feb 2012 14:02:25 -0600http://ask.sagemath.org/question/8689/sage-for-very-undergrad-students/?comment=20359#post-id-20359