# Classes for symbolic functions¶

class sage.symbolic.function.BuiltinFunction

This is the base class for symbolic functions defined in Sage.

If a function is provided by the Sage library, we don’t need to pickle the custom methods, since we can just initialize the same library function again. This allows us to use Cython for custom methods.

We assume that each subclass of this class will define one symbolic function. Make sure you use subclasses and not just call the initializer of this class.

class sage.symbolic.function.DeprecatedSFunction

EXAMPLES:

sage: from sage.symbolic.function import DeprecatedSFunction
sage: foo = DeprecatedSFunction("foo", 2)
sage: foo
foo
sage: foo(x,2)
foo(x, 2)
sage: foo(2)
Traceback (most recent call last):
...
TypeError: Symbolic function foo takes exactly 2 arguments (1 given)

class sage.symbolic.function.Function

Base class for symbolic functions defined through Pynac in Sage.

This is an abstract base class, with generic code for the interfaces and a __call__() method. Subclasses should implement the _is_registered() and _register_function() methods.

This class is not intended for direct use, instead use one of the subclasses BuiltinFunction or SymbolicFunction.

default_variable()

Returns a default variable.

EXAMPLES:

sage: sin.default_variable()
x

name()

Returns the name of this function.

EXAMPLES:

sage: foo = function("foo", nargs=2)
sage: foo.name()
'foo'

number_of_arguments()

Returns the number of arguments that this function takes.

EXAMPLES:

sage: foo = function("foo", nargs=2)
sage: foo.number_of_arguments()
2
sage: foo(x,x)
foo(x, x)

sage: foo(x)
Traceback (most recent call last):
...
TypeError: Symbolic function foo takes exactly 2 arguments (1 given)

variables()

Returns the variables (of which there are none) present in this SFunction.

EXAMPLES:

sage: sin.variables()
()

class sage.symbolic.function.GinacFunction

This class provides a wrapper around symbolic functions already defined in Pynac/GiNaC.

GiNaC provides custom methods for these functions defined at the C++ level. It is still possible to define new custom functionality or override those already defined.

There is also no need to register these functions.

sage.symbolic.function.PrimitiveFunction

alias of DeprecatedSFunction

sage.symbolic.function.SFunction

alias of DeprecatedSFunction

class sage.symbolic.function.SymbolicFunction

This is the basis for user defined symbolic functions. We try to pickle or hash the custom methods, so subclasses must be defined in Python not Cython.

sage.symbolic.function.get_sfunction_from_serial(serial)

Returns an already created SFunction given the serial. These are stored in the dictionary $$sage.symbolic.function.sfunction_serial_dict$$.

EXAMPLES:

sage: from sage.symbolic.function import get_sfunction_from_serial
sage: get_sfunction_from_serial(65) #random
f

sage.symbolic.function.is_inexact(x)

Returns True if the argument is an inexact object.

TESTS:

sage: from sage.symbolic.function import is_inexact
sage: is_inexact(5)
doctest:...: DeprecationWarning: The is_inexact() function is deprecated, use the _is_numerical() method of the Function class instead
See http://trac.sagemath.org/17130 for details.
False
sage: is_inexact(5.)
True
sage: is_inexact(pi)
True
sage: is_inexact(5r)
False
sage: is_inexact(5.4r)
True

sage.symbolic.function.pickle_wrapper(f)

Returns a pickled version of the function f if f is not None; otherwise, it returns None. This is a wrapper around pickle_function().

EXAMPLES:

sage: from sage.symbolic.function import pickle_wrapper
sage: def f(x): return x*x
sage: pickle_wrapper(f)
"csage...."
sage: pickle_wrapper(None) is None
True

sage.symbolic.function.unpickle_wrapper(p)

Returns a unpickled version of the function defined by p if p is not None; otherwise, it returns None. This is a wrapper around unpickle_function().

EXAMPLES:

sage: from sage.symbolic.function import pickle_wrapper, unpickle_wrapper
sage: def f(x): return x*x
sage: s = pickle_wrapper(f)
sage: g = unpickle_wrapper(s)
sage: g(2)
4
sage: unpickle_wrapper(None) is None
True


#### Previous topic

The symbolic ring

#### Next topic

Factory for symbolic functions