#11900: Serious regression caused by #9138
----------------------------------------------------------------------------------------+
Reporter: SimonKing
| Owner: tbd
Type: defect
| Status: needs_work
Priority: critical
| Milestone: sage-4.8
Component: performance
| Keywords: categories regression
Work_issues: Laurent series rings are fields. Add docs. Don't use is_ring and
friends | Upstream: N/A
Reviewer: Jeroen Demeyer, Nicolas M. Thiéry
| Author: Simon King
Merged:
| Dependencies: #9138 #11911
----------------------------------------------------------------------------------------+
Comment(by SimonKing):
What I now did: `Fields.__contains__` uses a helper that compares parent
classes (the same that is used by `Category_singleton`). If that fails,
then `is_field()` is called. If it turns out to be a field then the
category is updated.
Without the singleton patch:
{{{
sage: P.<x> = QQ[]
sage: Q = P.quotient(x^2+2)
sage: Q in Fields()
True
sage: _Fields = Fields()
sage: %timeit Q in _Fields
625 loops, best of 3: 21.1 µs per loop
sage: isinstance(Q, Fields().parent_class)
False
}}}
It is so slow, because `Q.category()` gives the wrong answer, thus
`is_Field` must be called, hence, `Q.is_field()` is called, and it is not
cached.
With my experimental (not yet published) patch, we would get
{{{
sage: P.<x> = QQ[]
sage: Q = P.quotient(x^2+2)
sage: isinstance(Q, Fields().parent_class)
False
sage: Q in Fields()
True
sage: isinstance(Q, Fields().parent_class)
True
sage: _Fields = Fields()
sage: %timeit Q in _Fields
625 loops, best of 3: 662 ns per loop
}}}
In other words: In the first place, Q is not initialised as a field. But
if `Q in Fields()` returns true (which is because of calling `is_Field`)
then the category of Q is refined. Hence, the next time of calling `Q in
Fields()` the shortcut of Category_singleton can be used.
What do you think?
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11900#comment:120>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.