#15786: floor fails for certain expressions.
-------------------------------------+-------------------------------------
       Reporter:  fwclarke           |        Owner:
           Type:  defect             |       Status:  needs_work
       Priority:  major              |    Milestone:  sage-6.8
      Component:  symbolics          |   Resolution:
       Keywords:  floor              |    Merged in:
        Authors:  David Einstein     |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/deinst/15786-floor               |  16e522fb6876ce646af7c52348056b94f3b8dfbc
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by deinst):

 * status:  needs_review => needs_work


Comment:

 After a bit of thought, it seemed like the best thing to do would be to
 move the guts to `_eval_` and replace `__call__` with something like

 {{{
     def __call__(self, *args, **kwds):
         res = super(Function_floor, self).__call__(*args, **kwds)

         # Convert to Integer if the output was of type "int" and any of
         # the inputs was a Sage Element
         if isinstance(res, Expression) and res.is_integer():
             return res.pyobject()
         else:
             return res
 }}}

 This should please everyone that expects floor to return an integer type
 instead of an expression type, while having the functionality routed in
 the standard way.  Unforturnately, we now run into coersion problems on
 the other end, people are calling `floor` with values that
 `BuiltinFunction` cannot handle.  For example, in `prime_pi.py` there is a
 doctest

 {{{
             sage: prime_pi._eval_(str(-2^100))
 }}}

 Which ends up taking `floor(str(-2^100))`.  This works in the current
 implementation, as `str(-2^100)` can be coerced to an element of
 `RealIntervalField`, but if we route the call through
 `BuiltinFunction.__call__` it dies because `str(-2^100)` cannot be coerced
 to an element of `SR` (this somewhat surprises me).

 The obvious answer would be to add some coersion at the front of
 `Function_floor.__call__`, but I don't know how far we should take
 treating `floor` and `ceil` as functions needing special care and
 handling.

 There is still the problem of a potential infinite loop in the recursive
 call
 {{{
                 return floor(SR(x).full_simplify().canonicalize_radical())
 }}}

 I don't know of any `Expression`s that evaluate to integers, but that
 `maxima` cannot simplify, but I'd be surprised if they don't exist.  I'm
 still rummaging about on the border of `pynac` to figure out how to stop
 the recursion.  If nothing else I can use the substitute trick, but that
 seems too kludgy.

--
Ticket URL: <http://trac.sagemath.org/ticket/15786#comment:14>
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