Opened 12 years ago

Closed 12 years ago

# piecewise integrals of 0 fail

Reported by: Owned by: D.S. McNeil Burcin Erocal minor sage-4.7 symbolics Karl-Dieter Crisman sage-4.7.alpha3 Douglas McNeil David Joyner, Karl-Dieter Crisman N/A

### Description (last modified by Karl-Dieter Crisman)

As reported in a sage-support thread, in 4.6.1 we see that

```sage: # succeeds
sage: f = Piecewise([[(0,1),1]])
sage: f.integral(x,0,1)
1
sage: # fails
sage: f = Piecewise([[(0,1),0]])
sage: f.integral(x,0,1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/Applications/sage/local/lib/python2.6/site-packages/sage/all_cmdline.pyc 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'
```

ultimately because 0 is special-cased:

```sage: type(SR(0).integral(x))
<type 'sage.rings.integer.Integer'>
sage: type(SR(1).integral(x))
<type 'sage.symbolic.expression.Expression'>
```

and the code path for a zero in PiecewisePolynomial?.integral never coerces to SR, so .function fails.

### comment:1 Changed 12 years ago by D.S. McNeil

Component: PLEASE CHANGE → symbolics changed from tbd to Burcin Erocal major → minor PLEASE CHANGE → defect

### comment:2 Changed 12 years ago by D.S. McNeil

Description: modified (diff)

### comment:3 follow-up:  4 Changed 12 years ago by Karl-Dieter Crisman

Cc: Karl-Dieter Crisman added

I don't have time to review this now, but hopefully not too long. Do all long tests pass with this change?

Also, you should feel free to ask the webmaster (Harald Schilly) to add you to http://www.sagemath.org/development-map.html.

### comment:4 in reply to:  3 Changed 12 years ago by David Joyner

Status: new → needs_review

I don't have time to review this now, but hopefully not too long. Do all long tests pass with this change?

Also, you should feel free to ask the webmaster (Harald Schilly) to add you to http://www.sagemath.org/development-map.html.

I've tested this on one machine on an older version of Sage and sage -testall passed, except for failing the (presumably unrelated) R-interface file. Also, the code looks good, has the appropriate doctests and seems to do what is claimed. I want to test it on one more machine before giving it a positive review though.

### comment:5 Changed 12 years ago by David Joyner

Status: needs_review → positive_review

This applies fine to 4.6.2.rc0 and passes sage -testall -long. Patch reads okay and does what it claims to do.

Thanks very much for making the patch!

### comment:6 Changed 12 years ago by Jeroen Demeyer

Authors: → Douglas McNeil → sage-4.7 → David Joyner

### comment:7 Changed 12 years ago by Jeroen Demeyer

Status: positive_review → needs_work

Problems while building the documentation:

```dochtml.log:/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.alpha3/local/lib/python2.6/site-packages/sage/functions/piecewise.py:docstring of sage.functions.piecewise.PiecewisePolynomial.integral:83: (WARNING/2) Literal block expected; none found.
```

### Changed 12 years ago by Karl-Dieter Crisman

Apply only this patch

### comment:8 Changed 12 years ago by Karl-Dieter Crisman

Description: modified (diff) needs_work → needs_review

This should fix the problem.

### comment:9 Changed 12 years ago by Karl-Dieter Crisman

Reviewers: David Joyner → David Joyner, Karl-Dieter Crisman needs_review → positive_review

Yes, it does.

Note to DSM: it turns out that you only need the double colon in front of doctests. So if there is verbiage between the `EXAMPLES` or `TESTS` and the actual indented tests, you only use a single colon there.

### comment:10 Changed 12 years ago by D.S. McNeil

Okay, so just so I'm clear: you must use only one colon after EXAMPLE[S] or TESTS if you're going to follow it with text at the indentation level of EXAMPLES and TESTS and not a more deeply indented code section. If you use two colons, then what comes after *must* be an indented code section, whether you've used "EXAMPLES::" or "EXAMPLE:" and then text and then a bare "::" on a line.

[update: just read kcrisman's explanation. `:^)`]

So does this mean that the merger of my patch for trac #10088 broke the docs?

### comment:11 Changed 12 years ago by Karl-Dieter Crisman

Well, you'd think so, but it didn't - here's why. It doesn't 'break' them, just causes a warning. And if they aren't in the reference manual - as that file apparently isn't - it won't break them, since there is no warning, since they are never actually built.

### comment:12 Changed 12 years ago by Karl-Dieter Crisman

That's not to say such things shouldn't be fixed eventually. But that would happen when such files are put into the reference manual; even I wouldn't do a ticket for something that trivial.

### comment:13 Changed 12 years ago by Jeroen Demeyer

Merged in: → sage-4.7.alpha3 → fixed positive_review → closed
Note: See TracTickets for help on using tickets.