Opened 5 years ago
Last modified 5 years ago
#17547 new defect
BuiltinFunction overriding GiNaC function
Reported by: | rws | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-6.5 |
Component: | symbolics | Keywords: | |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
The attempt to create a symbolic function that prints with a name that is also used by a reserved GiNaC function results in unexpected behaviour when evaluating. The following should output x^2
but completely bypasses AFunction.eval
:
sage: from sage.symbolic.function import BuiltinFunction sage: class AFunction(BuiltinFunction): ....: def __init__(self, name, exp=1): ....: self.exponent=exp ....: BuiltinFunction.__init__(self, name, nargs=1) ....: def _eval_(self, arg): ....: return arg**self.exponent sage: p2 = AFunction('exp', 2) sage: p2(x) e^x
If the name is however e.g. p2
then AFunction.eval
gets called as expected. Compare the above with
... sage: p2 = AFunction('p2', 2) sage: p2(x) x^2
This prevents creation of BuiltinFunction
s as wrapper for functions reserved by Pynac with the same name like factorial
(#17489), and forces every change into Pynac.
Change History (5)
comment:1 Changed 5 years ago by
- Description modified (diff)
comment:2 Changed 5 years ago by
comment:3 in reply to: ↑ description Changed 5 years ago by
Replying to rws:
The attempt at creation should give an error
I don't understand the problem, what's wrong?
comment:4 Changed 5 years ago by
- Description modified (diff)
If the name is e.g. p2
AFunction.eval
gets called, but not with name equal to a function provided with GiNaC. Compare the above with
... sage: p2 = AFunction('p2', 2) sage: p2(x) x^2
comment:5 Changed 5 years ago by
- Description modified (diff)
- Summary changed from BuiltinFunction overriding GiNaC function is allowed to BuiltinFunction overriding GiNaC function
I came to this from #17489 when I tried to create a symbolic
factorial
function without usage ofGinacFunction
, which wreaks havoc when expression conversion to/from e.g. Maxima is involved.