Opened 10 years ago
Closed 10 years ago
#10841 closed defect (fixed)
piecewise integrals of 0 fail
Reported by: | dsm | Owned by: | burcin |
---|---|---|---|
Priority: | minor | Milestone: | sage-4.7 |
Component: | symbolics | Keywords: | |
Cc: | kcrisman | Merged in: | sage-4.7.alpha3 |
Authors: | Douglas McNeil | Reviewers: | David Joyner, Karl-Dieter Crisman |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
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.
Apply only trac_10841_fix_piecewise_integrals_of_zero.2.patch
Attachments (2)
Change History (15)
comment:1 Changed 10 years ago by
- Component changed from PLEASE CHANGE to symbolics
- Owner changed from tbd to burcin
- Priority changed from major to minor
- Type changed from PLEASE CHANGE to defect
Changed 10 years ago by
comment:2 Changed 10 years ago by
- Description modified (diff)
comment:3 follow-up: ↓ 4 Changed 10 years ago by
- Cc kcrisman added
comment:4 in reply to: ↑ 3 Changed 10 years ago by
- Status changed from new to needs_review
Replying to kcrisman:
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 10 years ago by
- Status changed from needs_review to 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 10 years ago by
- Milestone set to sage-4.7
- Reviewers set to David Joyner
comment:7 Changed 10 years ago by
- Status changed from positive_review to 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.
comment:8 Changed 10 years ago by
- Description modified (diff)
- Status changed from needs_work to needs_review
This should fix the problem.
comment:9 Changed 10 years ago by
- Reviewers changed from David Joyner to David Joyner, Karl-Dieter Crisman
- Status changed from needs_review to 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 10 years ago by
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 10 years ago by
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 10 years ago by
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 10 years ago by
- Merged in set to sage-4.7.alpha3
- Resolution set to fixed
- Status changed from positive_review to closed
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.