Opened 8 years ago
Closed 7 years ago
#6523 closed defect (fixed)
.is_zero() method raises error for symbolic expression involving derivative
Reported by: | gmhossain | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-4.3 |
Component: | symbolics | Keywords: | |
Cc: | mhansen | Merged in: | sage-4.3.rc0 |
Authors: | Burcin Erocal | Reviewers: | Mike Hansen |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
If a symbolic expression contains symbolic derivative then checking whether it is zero, raises error:
sage: x.diff(x,2).is_zero() True sage: f(x) = function('f',x) sage: f(x).diff(x).is_zero() .... NotImplementedError: derivative
This fails because new symbolics tries to convert it to maxima expression for checking the relation.
Update:
* A patch to fix the issue is attached. The patch
adds a new method ".has_fderivative()" for symbolic expressions
and in __nonzero__
method adds a check whether it has fderivative.
Comments (for future works): A simple timing comparison that illustrates why we should avoid calling maxima to assert nonzero even for symbolic functions
sage: f(x) = function('f',x) sage: timeit('sin(f(x)).is_zero()') 5 loops, best of 3: 85.8 ms per loop sage: timeit('sin(f(x).diff(x)).is_zero()') 625 loops, best of 3: 132 µs per loop
It seems pynac is 400 times faster than maxima in this case.
Attachments (2)
Change History (6)
Changed 8 years ago by
comment:1 Changed 8 years ago by
- Description modified (diff)
- Summary changed from .is_zero() method raises error for symbolic expression involving derivative to [with patch, needs review] .is_zero() method raises error for symbolic expression involving derivative
comment:2 Changed 8 years ago by
- Cc mhansen added
- Milestone set to sage-4.1.1
- Summary changed from [with patch, needs review] .is_zero() method raises error for symbolic expression involving derivative to .is_zero() method raises error for symbolic expression involving derivative
comment:3 Changed 7 years ago by
- Status changed from new to needs_review
This is fixed by #7490, since we don't use the expression_conversions
module to convert to RIF
any more.
attachment:trac_6523-derivative_is_zero.patch adds a doctest with the example in the description.
comment:4 Changed 7 years ago by
- Merged in set to sage-4.3.rc0
- Report Upstream set to N/A
- Resolution set to fixed
- Reviewers set to Mike Hansen
- Status changed from needs_review to closed
Looks good to me.
Merged trac_6523-derivative_is_zero.patch.
Unfortunately, the fact that an expression contains a symbolic derivative doesn't guarantee that it is nonzero:
The right fix for this is to either implement the
.derivative()
method insage/symbolic/expression_conversions.py
or to change pynac to allow different parents inevalf()
, so that conversion toCIF
can be done without the code inexpression_conversions.pyx
.I was planning to do this for #6243, but ended up using a different/better fix there.