Ben Woodruff wrote:
> Hi all. This is my first post to the discussions groups I've been
> following for the last 4 months. I used Sage in my first semester
> calculus class this last semester, and plan to move every class I can
> over to Sage during the next few years. Giving the students something
> they can use anywhere they go without forking over thousands of
> dollars has a huge advantage. As such, I'm going to start doing a
> better job of posting errors when they arise and I can't figure out
> how to resolve them.
>
> Here is the issue. When I evaluate
>
> sage: var('t')
> sage: integrate(sec(t)*tan(t),t,0,pi/3)
>
> I get the error message
>
>> Traceback (click to the left for traceback)
>> ...
>> Is cos(t) positive, negative, or zero?
>
> I can get the correct solution of 1 by executing
>
> sage: var('t')
> sage: F(t)=integrate(sec(t)*tan(t),t)
> sage: F(pi/3)-F(0)
>
> Similar issues arise with other trig functions. The command
>
> sage: integrate(csc(x)*cot(x),x,pi/3,pi/2)
>
> gives the error message
>
>> Traceback (click to the left for traceback)
>> ...
>> Is sin(x) positive, negative, or zero?
>
> Any ideas why Sage cannot complete this definite integral? I would
> prefer to have Sage give the answers without using an assuming
> commands, since by specifying the bounds are between 0 and pi/3 I am
> already declaring cos(x)>0 and x to be real.
>
As others have noted, the assumptions and questions are from maxima.
There has been lots of discussion about this, and one lead maxima
developer has done a lot of work towards removing these questions and
just returning cases, based on the questions. I think at least one
other Sage developer has worked on this sort of thing too.
Here are a few things you can do to get around it:
1. Give the assumption it wants. It mentions this in the error message
(right above the question).
sage: assume(cos(x)>0)
sage: integrate(sec(x)*tan(x),x,0,pi/3)
1
As you point out, in this case, this should be redundant and maxima
should be able to figure it out.
2. Use nintegrate, which uses numerical integration techniques.
sage: (sec(x)*tan(x)).nintegrate(x,0,pi/3)
(0.99999999999999956, 5.3650863533076041e-12, 21, 0)
***NOTE FOR DEVELOPERS*** Why is nintegrate/nintegral not in the
top-level commands???
3. Use an alternative system for evaluating the integral, like sympy or
mathematica_free
***NOTE*** These systems are not documented on the integrate command,
only the integral command.
***NOTE*** There are errors using both of these systems. The
mathematica_free one ignores the bounds of integration. The sympy one
doesn't recognize sec(x). Using sympy with tan(x)/cos(x) also gives an
error because sympy can't do the integral, and Sage doesn't know how to
deal with an unevaluated sympy integral.
sage: integrate(sec(x)*tan(x),x,0,pi/3,algorithm='mathematica_free')
sec(x)
sage: integrate(sec(x)*tan(x),x,0,pi/3,algorithm='sympy')
---------------------------------------------------------------------------
SympifyError Traceback (most recent call last)
/home/grout/.sage/temp/tiny/1970/_home_grout__sage_init_sage_0.py in
<module>()
/home/grout/sage/local/lib/python2.6/site-packages/sage/misc/functional.pyc
in integral(x, *args, **kwds)
566 """
567 if hasattr(x, 'integral'):
--> 568 return x.integral(*args, **kwds)
569 else:
570 from sage.symbolic.ring import SR
/home/grout/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so
in sage.symbolic.expression.Expression.integral
(sage/symbolic/expression.cpp:25344)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/calculus/calculus.pyc
in integral(expression, v, a, b, algorithm)
671 elif algorithm == 'sympy':
672 import sympy
--> 673 ex = expression._sympy_()
674 v = v._sympy_()
675 if a is None:
/home/grout/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so
in sage.symbolic.expression.Expression._sympy_
(sage/symbolic/expression.cpp:5779)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.pyc
in __call__(self, ex)
212 div = self.get_fake_div(ex)
213 return self.arithmetic(div, div.operator())
--> 214 return self.arithmetic(ex, operator)
215 elif operator in relation_operators:
216 return self.relation(ex, operator)
/home/grout/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.pyc
in arithmetic(self, ex, operator)
577 return sympy.Add(*ops)
578 elif operator == "*":
--> 579 return sympy.Mul(*ops)
580 elif operator == "-":
581 return sympy.Sub(*ops)
/home/grout/sage/local/lib/python2.6/site-packages/sympy/core/cache.py
in wrapper(*args, **kw_args)
83 except KeyError:
84 pass
---> 85 func_cache_it_cache[k] = r = func(*args, **kw_args)
86 return r
87
/home/grout/sage/local/lib/python2.6/site-packages/sympy/core/operations.py
in __new__(cls, *args, **assumptions)
30 if len(args)==1:
31 return _sympify(args[0])
---> 32 c_part, nc_part, order_symbols =
cls.flatten(map(_sympify, args))
33 if len(c_part) + len(nc_part) <= 1:
34 if c_part: obj = c_part[0]
/home/grout/sage/local/lib/python2.6/site-packages/sympy/core/sympify.py
in _sympify(a)
191 return v
192
--> 193 raise SympifyError("%r is NOT a valid SymPy expression" % (a,))
194
195
SympifyError: SympifyError: NotImplementedError("SymPy function 'sec'
doesn't exist",) is NOT a valid SymPy expression
sage: integrate(tan(x)/cos(x),x,0,pi/3,algorithm='sympy')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/grout/.sage/temp/tiny/2080/_home_grout__sage_init_sage_0.py in
<module>()
/home/grout/sage/local/lib/python2.6/site-packages/sage/misc/functional.pyc
in integral(x, *args, **kwds)
566 """
567 if hasattr(x, 'integral'):
--> 568 return x.integral(*args, **kwds)
569 else:
570 from sage.symbolic.ring import SR
/home/grout/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so
in sage.symbolic.expression.Expression.integral
(sage/symbolic/expression.cpp:25344)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/calculus/calculus.pyc
in integral(expression, v, a, b, algorithm)
684 return expression.parent()(result)
685 else:
--> 686 return SR(result)
687
688 integrate = integral
/home/grout/sage/local/lib/python2.6/site-packages/sage/structure/parent.so
in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:4241)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/symbolic/ring.so
in sage.symbolic.ring.UnderscoreSageMorphism._call_
(sage/symbolic/ring.cpp:6687)()
AttributeError: 'Integral' object has no attribute '_sage_'
So there still is work to do, even on the alternatives.
Thanks,
Jason
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org