Skip to content

BuiltinFunction overriding GiNaC function #17547

Open
@rwst

Description

@rwst

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions