Skip to content

refactor symbolic functions #7490

@burcin

Description

@burcin

Attached patch refactors the symbolic function code in sage/symbolic/function.pyx.

  • evalf() now accepts a parent argument instead of a precision
    This allows us to use the numeric evaluation framework in ginac for
    evaluating things with RIF, CIF as well, not just RealField, or ComplexField with the given precision.

  • python arguments passed to custom methods of sfunctions are not
    wrapped in Expression objects any more. No need to call .pyobject()
    to unwrap these.

  • custom methods support calling methods on self.
    This would be useful if you need access to other function of the
    defining class, or store tables of data calculated on demand.

  • __call__ method supports hold parameter
    This works:

        sage: exp(log(x))
        x
        sage: exp(log(x), hold=True)
        e^log(x)
  • Custom methods for symbolic functions (_eval_, _evalf_, _conjugate_,
    _derivative_, etc.) can be
    written in Cython for builtin functions (that are provided by the
    Sage library)

  • New class hiearchy:

Function
  GinacFunction
  CustomizableFunction
    BuiltinFunction
    SymbolicFunction

We have 4 different types of functions, those defined by

  • ginac (sin, cos, ...),
  • the Sage library (cot)
  • the user (in a python file, subclassing the new
    SymbolicFunction)
  • the command line function_factory (by calling function('f') )

Things we need to do for these functions different for each of these,
perhaps similar for the last two. Normally initializing a function
means checking if it's already defined, if not, initializing a
structure from ginac called function_options, and registering this in
a table. There are also issues with pickling.

For ginac functions, we don't need any of this, since we can't change
it at python level. We only need to look up the serial number (the
indicator in the table) of the function. We don't need to do anything
to pickle or unpickle these either.

Pickling and unpickling library functions only needs an identifier
for the class to initialize it again if necessary.

User defined functions need to lookup if there is an existing
function in the table, since we should try to keep the table small.

There is also a new function_factory() function in sage.symbolic.function_factory
(it needs to be in a python file) that creates NewSymbolicFunction
classes on the fly for the function() calls from the command line.

The pynac package here is required for this patch:

http://sage.math.washington.edu/home/burcin/pynac/pynac-0.1.10.a0.spkg

CC: @mwhansen @jasongrout

Component: symbolics

Keywords: pynac

Author: Burcin Erocal

Reviewer: Mike Hansen

Merged: sage-4.3.alpha1

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions