Skip to content

symbolic function args prevent forced conversion of result to numeric #17953

@rwst

Description

@rwst

It is generally preferred that the returned result type matches the argument type when calling a builtin function. For example this is as expected:

sage: factorial(8).parent()
Integer Ring
sage: factorial(SR(8)).parent()
Symbolic Ring
sage: exp(0).parent()
Integer Ring
sage: exp(SR(0)).parent()
Symbolic Ring

but this is not:

from sage.symbolic.function import BuiltinFunction

class TestFunction(BuiltinFunction):
    def __init__(self):
        BuiltinFunction.__init__(self, "testfun", nargs=2)
    def _eval_(self, n, x, *args, **kwds):
        print (parent(n), parent(x))
        return SR(5)

sage: TestFunction()(SR(1),GF(2)(1))
(Integer Ring, Finite Field of size 2)
5
sage: type(_)
<type 'int'>

An explanation could be that factorial and exp derive from GinacFunction.

CC: @jdemeyer

Component: symbolics

Author: Ralf Stephan

Branch/Commit: adc230d

Reviewer: Marc Mezzarobba

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions