New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
move roots solving of univariate SR polynomial ring #24942
Comments
comment:1
I'm on it. |
comment:2
(I'll review when ready) |
comment:4
Although this is a straight move, with addition of two examples, now 3 doctests fail:
There must be some fuzziness on if SR is the base ring, or the ring argument of roots(). New commits:
|
Commit: |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Author: Ralf Stephan |
comment:6
Found and fixed a bug in roots(). Please review. |
comment:7
The following is wrong
You do want to delegate to the base ring of the polynomial (not to the target for the roots). You can check that at the end of the
|
Changed branch from u/rws/move_roots_solving_of_univariate_sr_polynomial_ring to u/rws/24942 |
comment:9
Still missing fixes for QQbar doctest fails. New commits:
|
comment:10
I am not sure we want to support the BTW, in the doctest |
comment:11
There may be some serious inefficiencies involved up to now because the polys that get transferred in the call to SR._roots... have coefficients in SR BUT they are actually embedded algebraic numbers. I need to have a further look. |
comment:12
Agree with ignoring the ring argument. Here is a problem:
That is, the result from |
comment:13
Replying to @rwst:
Another bug (mostly disjoint from this ticket)
I guess that the |
comment:14
I think I can work around it, and the following:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:16
Replying to @videlec:
Not disjoint because I need a special case to work with these polynomials that get thrown at the _roots...() function. Please have a look. Tests pass so far. |
comment:17
Note there is a performance hit, |
comment:18
Replying to @rwst:
The roots code first calls |
comment:19
Replying to @videlec:
No, the result from |
comment:20
Replying to @rwst:
- roots = poly.roots(SR, multiplicities=False)
+ roots = poly.change_ring(SR).roots(multiplicities=False) |
comment:21
Replying to @videlec:
Is nearly as slow, despite being more correct. I tried converting to SR, or calling |
comment:22
Replying to @rwst:
Conversion from ZZ can already be improved
which is basically the same x15 ratio as in
|
comment:23
I'm able to reduce |
comment:24
Note that speeding up |
comment:25
|
comment:26
Replying to @rwst:
These are different operations. You seem to confuse polynomials with coefficients in SR like If you have a polynomial |
comment:27
Replying to @videlec:
The biggest part (230µs) of these 300µs is spent in |
comment:28
Replying to @rwst:
Why on earth the code would you check that |
comment:29
Replying to @videlec:
I have, and I have traced what happens. I will document this clearly and confirmable, but this takes time. |
comment:30
Please see #24965, which we might depend on here. |
Dependencies: #24965 |
comment:32
It seems I mentally did put your comment:13 in a different slot than comment:12. Anyway, we should depend on the coming fix in #24965 and revert the commit 0c791d0 here. |
Changed dependencies from #24965 to none |
comment:33
Replying to @rwst:
This was a cul-de-sac. So the alternative, doing something about the comparison of objects with zero (where the comparison explicitly needs no simplification) looks like an alternative. The problem is outlined in https://trac.sagemath.org/wiki/symbolics/nonzero and #21201 looks like the best start at it. |
comment:34
With #21201 and patching |
comment:35
Actually, moving the code to
Now if you convert first to My conclusion (for now): SR is terribly intrusive and does not play nicely with anything else from Sage. |
comment:36
The only intrusion I see is in roots, and well, if you request symbolic output then you need a special case. QQbar could simply convert to SR, and call solve on the resulting expression. |
comment:37
Replying to @rwst:
It is in
and there is no special casing for them. |
comment:40
Replying to @rwst:
You can at least give your opinion. "My" solution consists in removing three lines of code in --- a/src/sage/symbolic/ring.pyx
+++ b/src/sage/symbolic/ring.pyx
@@ -199,9 +199,6 @@ cdef class SymbolicRing(CommutativeRing):
if ComplexField(mpfr_prec_min()).has_coerce_map_from(R):
# Almost anything with a coercion into any precision of CC
return R not in (RLF, CLF)
- elif is_PolynomialRing(R) or is_MPolynomialRing(R) or is_FractionField(R) or is_LaurentPolynomialRing(R):
- base = R.base_ring()
- return base is not self and self.has_coerce_map_from(base)
elif (R is InfinityRing or R is UnsignedInfinityRing
or is_RealIntervalField(R) or is_ComplexIntervalField(R)
or isinstance(R, RealBallField) |
comment:41
I see. The main consequence is that some symbolic functions that traditionally supported polynomials as arguments will need a separation into an interface taking all sorts of arguments, and the symbolic function class. Accidentally, for the orthogonal poly functions there is already a ticket that does that (#24554 needing review). For binomial there is already an interface (in arith) and a symbolic function, the only problem being that the import of the symbolic version overwrites the arith version on startup. There is #24178 for that but Jeroen opposed it. The split into global interface / symbolic function is inherently necessary because the symbolic function creation/call code restricts what is allowed as argument (even which kwds may be given), and I get no support to change that. The other doctest failures I get are minor. All in all I support this change. |
comment:42
Replying to @videlec:
Are you going to upload a branch with this? What's the plan? |
comment:43
Simpler solution is to fix |
Dependencies: #25022 |
Move the root finding code of polynomial ring over SR from the generic method
roots
inrings/polynomial/polynomial_element.pyx
to the specialized_roots_univariate_polynomial
that has to be put directly in the base ringSR
(code insymbolic/ring.pyx
).Depends on #25022
CC: @rwst
Component: symbolics
Author: Ralf Stephan
Branch/Commit: u/rws/24942 @
0c791d0
Issue created by migration from https://trac.sagemath.org/ticket/24942
The text was updated successfully, but these errors were encountered: