#17130: Fix coercion bugs in symbolic functions
-------------------------------------+-------------------------------------
       Reporter:  jdemeyer           |        Owner:
           Type:  defect             |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.4
      Component:  symbolics          |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Jeroen Demeyer     |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/jdemeyer/ticket/17130            |  b6e1ed44a663f7410fddb2e3e4c134aa3a0ce8cf
   Dependencies:  #17131, #17133     |     Stopgaps:
-------------------------------------+-------------------------------------
Description changed by jdemeyer:

Old description:

> This uses coercion correctly:
> {{{
> sage: bessel_Y._eval_(RealField(300)(1), 1.0)
> -0.781212821300289
> }}}
>
> However, it seems that `__call__()` coerces this result back to the first
> parent, giving false precision:
> {{{
> sage: bessel_Y(RealField(300)(1), 1.0)
> -0.781212821300288684511770043172873556613922119140625000000000000000000000000000000000000000
> }}}
>
> Same issue with functions which are evaluated using Maxima, which does
> not support arbitrary precision:
> {{{
> sage: R=RealField(300); elliptic_eu(R(1/2), R(1/8))
> 0.495073732023201484864216581627260893583297729492187500000000000000000000000000000000000000
> }}}
>
> The `gamma_inc()` function also mishandles parents:
> {{{
> sage: gamma_inc(float(0), float(1))
> AttributeError: type object 'float' has no attribute 'precision'
> }}}
>
> Possible follow-ups: #10133, #14766

New description:

 This uses coercion correctly:
 {{{
 sage: bessel_Y._eval_(RealField(300)(1), 1.0)
 -0.781212821300289
 }}}

 However, it seems that `__call__()` coerces this result back to the first
 parent, giving false precision:
 {{{
 sage: bessel_Y(RealField(300)(1), 1.0)
 
-0.781212821300288684511770043172873556613922119140625000000000000000000000000000000000000000
 }}}

 Same issue with functions which are evaluated using Maxima, which does not
 support arbitrary precision:
 {{{
 sage: R=RealField(300); elliptic_eu(R(1/2), R(1/8))
 
0.495073732023201484864216581627260893583297729492187500000000000000000000000000000000000000
 }}}

 The `gamma_inc()` function also mishandles parents:
 {{{
 sage: gamma_inc(float(0), float(1))
 AttributeError: type object 'float' has no attribute 'precision'
 }}}

 ----

 Apart from this, this branch also removes lots of boilerplate from
 `_eval_` like
 {{{
 if not isinstance(x, Expression) and not isinstance(y, Expression) and \
         (is_inexact(x) or is_inexact(y)):
     x, y = coercion_model.canonical_coercion(x, y)
     return self._evalf_(x, y, s_parent(x))
 }}}
 by wrapping `_eval_` inside the new method `_evalf_or_eval_` which
 automatically does this boilerplate.

 ----

 Possible follow-ups: #10133, #14766

--

--
Ticket URL: <http://trac.sagemath.org/ticket/17130#comment:30>
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/d/optout.

Reply via email to