#12121: floor/ceil can be very slow at integral values
-------------------------------------+-------------------------------------
Reporter: dsm | Owner: AlexGhitza
Type: defect | Status: needs_review
Priority: major | Milestone: sage-7.2
Component: basic arithmetic | Resolution:
Keywords: | Merged in:
Authors: Vincent Delecroix | Reviewers: Marc Mezzarobba
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/vdelecroix/12121 | 0e9b2f21d6a6bc42e35302316ac0f6b3b7451450
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by vdelecroix):
I removed the `__call__` in both `Function_floor` and `Function_ceil`. The
code is now much simpler. Though there was some adaptation needed in
`symbolic/expression.pyx`.
Replying to [comment:39 mmezzarobba]:
> I fear I won't have time to review your new version in the next few days
at least, but from a quick look at it there are a lot of things I don't
understand. In no particular order:
> * why do you make `maximum_bits` an `Integer`?
all right. `int` is fine as well.
> * what don't you like about `unique_integer()`?
an `assert` does not cost anything. And `unique_integer` silently fails if
the interval does not enclose a unique integer.
> * is it really better to have an absolute bound for the diameter that
makes us suspect we found an exact integer, rather than something that
depends on the precision?
the precision of what? there is the field used for the evaluation which is
different from the diameter of the interval. If you have more than one
integer in your interval which one are you using to test equality?
> * why do you insist on using `==` on symbolic expressions instead of
`is_trivial_zero()`?
Because I want to check equality with an integer. Not if it is a trivial
equality.
> * are you sure you want to raise an error when `maximum_bits` does not
suffice to conclude? this is a symbolic function that may be buried deep
in the middle of a symbolic expression; returning unevaluated seems more
reasonable to me...
Done with an example.
> * do we really need two loops that do essentially the same thing
(including raising errors with the exact same message)?
The equality test is potentially costly. And we want to avoid it as much
as possible. In particular, it makes no sense to test this equality within
each step of the loop as it is in your version. On a related note, I
noticed that for `round` you need to test equality with elements of `ZZ +
1/2`.
--
Ticket URL: <http://trac.sagemath.org/ticket/12121#comment:41>
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 https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.