I am trying to define piecewise linear functions, and then integrate them. 
 But I get an error
   AttributeError: 'sage.rings.integer.Integer' object has no attribute 
'function'
when one of the pieces is a constant function.  Strangely, the same code 
works when
the function is non-constant.

Here is a printout of a session exhibiting both the error (for a constant 
piece), and correct
behavior (for a non-constant piece).

----------------------------------------------------------------------------------------------------------------------------------
06:11:51 notes $ /Applications/sage/sage
Detected SAGE64 flag
Building Sage on OS X in 64-bit mode
----------------------------------------------------------------------
| Sage Version 4.6.1, Release Date: 2011-01-11                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: f0(x) = 0
sage: type(f0)
<type 'sage.symbolic.expression.Expression'>
sage: f = Piecewise([[(0,1),f0]])
sage: f
Piecewise defined function with 1 parts, [[(0, 1), x |--> 0]]
sage: f.integral(x,0,1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/Users/rivest/notes/<ipython console> in <module>()

/Applications/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.pyc
 
in integral(self, x, a, b, definite)
    789         """
    790         if a != None and b != None:
--> 791             F = self.integral(x)
    792             return F(b) - F(a)
    793 

/Applications/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.pyc
 
in integral(self, x, a, b, definite)
    831                 if definite or end != infinity:
    832                     area += fun.integral(x, start, end)
--> 833             new_pieces.append([(start, end), 
fun_integrated.function(x)])
    834 
    835         if definite:

/Applications/sage/local/lib/python2.6/site-packages/sage/structure/element.so 
in sage.structure.element.Element.__getattr__ 
(sage/structure/element.c:2666)()

/Applications/sage/local/lib/python2.6/site-packages/sage/structure/parent.so 
in sage.structure.parent.getattr_from_other_class 
(sage/structure/parent.c:2840)()

/Applications/sage/local/lib/python2.6/site-packages/sage/structure/parent.so 
in sage.structure.parent.raise_attribute_error 
(sage/structure/parent.c:2611)()

AttributeError: 'sage.rings.integer.Integer' object has no attribute 
'function'
sage: f.integral()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/Users/rivest/notes/<ipython console> in <module>()

/Applications/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.pyc
 
in integral(self, x, a, b, definite)
    831                 if definite or end != infinity:
    832                     area += fun.integral(x, start, end)
--> 833             new_pieces.append([(start, end), 
fun_integrated.function(x)])
    834 
    835         if definite:

/Applications/sage/local/lib/python2.6/site-packages/sage/structure/element.so 
in sage.structure.element.Element.__getattr__ 
(sage/structure/element.c:2666)()

/Applications/sage/local/lib/python2.6/site-packages/sage/structure/parent.so 
in sage.structure.parent.getattr_from_other_class 
(sage/structure/parent.c:2840)()

/Applications/sage/local/lib/python2.6/site-packages/sage/structure/parent.so 
in sage.structure.parent.raise_attribute_error 
(sage/structure/parent.c:2611)()

AttributeError: 'sage.rings.integer.Integer' object has no attribute 
'function'

Sage: fx(x) = x
sage: type(fx)
<type 'sage.symbolic.expression.Expression'>
sage: g = Piecewise([[(0,1),fx]])
sage: g
Piecewise defined function with 1 parts, [[(0, 1), x |--> x]]
sage: g.integral()
Piecewise defined function with 1 parts, [[(0, 1), x |--> 1/2*x^2]]
sage: 

This looks like a bug.

Is there a work-around??

Cheers,
Ron Rivest

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to