#15071: Make it easy to have automatic numerical evaluation of symbolic 
functions
on inexact input
-------------------------------+-------------------------------
       Reporter:  eviatarbach  |        Owner:
           Type:  enhancement  |       Status:  positive_review
       Priority:  major        |    Milestone:  sage-5.12
      Component:  symbolics    |   Resolution:
       Keywords:               |    Merged in:
        Authors:               |    Reviewers:
Report Upstream:  N/A          |  Work issues:
         Branch:               |       Commit:
   Dependencies:               |     Stopgaps:
-------------------------------+-------------------------------
Changes (by benjaminfjones):

 * status:  needs_review => positive_review


Old description:

> This ticket is for making it easy to have symbolic functions
> automatically evaluate on inexact input. This is already the behaviour of
> most symbolic functions and as such it would be good to have a standard
> way of implementing it.
>
> This ticket modifies `Function._eval_default` to accept an arbitrary
> number of arguments. To have the numeric evaluation work, `_eval_default`
> can be assigned to `_eval_`, or it can be called from within `_eval_`
> and, if it returns `None`, leaves opportunity for exact simplification.
> For example,
>
> {{{
> sage: from sage.symbolic.function import BuiltinFunction
> sage: class Test(BuiltinFunction):
> ....:     def __init__(self):
> ....:         BuiltinFunction.__init__(self, 'test', nargs=1)
> ....:     def _evalf_(self, x, parent):
> ....:         return 0.5
> ....:     def _eval_(self, x):
> ....:         y = self._eval_default(x)
> ....:         if y:
> ....:             return y
> ....:         else:
> ....:             return 3
> sage: test = Test()
> sage: test(1.3)
> 0.500000000000000
> sage: test(pi)
> 3
> }}}

New description:

 This ticket is for making it easy to have symbolic functions automatically
 evaluate on inexact input. This is already the behaviour of most symbolic
 functions and as such it would be good to have a standard way of
 implementing it.

 This ticket modifies `Function._eval_default` to accept an arbitrary
 number of arguments. To have the numeric evaluation work, `_eval_default`
 can be assigned to `_eval_`, or it can be called from within `_eval_` and,
 if it returns `None`, leaves opportunity for exact simplification. For
 example,

 {{{
 sage: from sage.symbolic.function import BuiltinFunction
 sage: class Test(BuiltinFunction):
 ....:     def __init__(self):
 ....:         BuiltinFunction.__init__(self, 'test', nargs=1)
 ....:     def _evalf_(self, x, parent):
 ....:         return 0.5
 ....:     def _eval_(self, x):
 ....:         y = self._eval_default(x)
 ....:         if y:
 ....:             return y
 ....:         else:
 ....:             return 3
 sage: test = Test()
 sage: test(1.3)
 0.500000000000000
 sage: test(pi)
 3
 }}}

 ----

 Apply trac15071_4.patch

--

Comment:

 All tests pass! Positive review.

--
Ticket URL: <http://trac.sagemath.org/ticket/15071#comment:13>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to