Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuiltinFunction overriding GiNaC function #17547

Open
rwst opened this issue Dec 24, 2014 · 6 comments
Open

BuiltinFunction overriding GiNaC function #17547

rwst opened this issue Dec 24, 2014 · 6 comments

Comments

@rwst
Copy link
Contributor

rwst commented Dec 24, 2014

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 BuiltinFunctions as wrapper for functions reserved by Pynac with the same name like factorial (#17489), and forces every change into Pynac.

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/17547

@rwst rwst added this to the sage-6.5 milestone Dec 24, 2014
@rwst

This comment has been minimized.

@rwst
Copy link
Contributor Author

rwst commented Dec 24, 2014

comment:2

I came to this from #17489 when I tried to create a symbolic factorial function without usage of GinacFunction, which wreaks havoc when expression conversion to/from e.g. Maxima is involved.

@jdemeyer
Copy link
Contributor

Replying to @rwst:

The attempt at creation should give an error

I don't understand the problem, what's wrong?

@rwst

This comment has been minimized.

@rwst
Copy link
Contributor Author

rwst commented Dec 25, 2014

comment:4

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

@rwst

This comment has been minimized.

@rwst rwst changed the title BuiltinFunction overriding GiNaC function is allowed BuiltinFunction overriding GiNaC function Jul 9, 2015
@mkoeppe mkoeppe removed this from the sage-6.5 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants