Ticket #7490 (closed defect: fixed)
refactor symbolic functions
|Reported by:||burcin||Owned by:||burcin|
|Cc:||mhansen, jason||Work issues:|
|Report Upstream:||N/A||Reviewers:||Mike Hansen|
|Authors:||Burcin Erocal||Merged in:||sage-4.3.alpha1|
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
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 SymbolicFunctionWe 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:
Changed 3 years ago by burcin
- attachment trac_7490-refactor_symbolic_functions.rebase-4.3.alpha0.patch added
- Status changed from needs_review to needs_work
- Reviewers set to Mike Hansen
- Status changed from needs_work to needs_review