You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Substitutions in the fraction field of a polynomial ring are much slower than necessary:
sage: P = PolynomialRing(QQ, ["x%s" % i for i in range(1000)])
sage: PF = P.fraction_field()
sage: p = sum(i*P.gen(i) for i in range(50,52)) / sum(i*P.gen(i) for i in range(51,53)); v = P.gen(51)
sage: %time p.subs({v: 100})
CPU times: user 55.4 ms, sys: 0 ns, total: 55.4 ms
Wall time: 55.4 ms
(50*x50 + 5100)/(52*x52 + 5100)
sage: %time p.numerator().subs({v: 100}) / p.denominator().subs({v: 100})
CPU times: user 3.32 ms, sys: 0 ns, total: 3.32 ms
Wall time: 3.33 ms
(50*x50 + 5100)/(52*x52 + 5100)
Expected Behavior
There should be not much difference in timing.
Actual Behavior
The method called is Element.subs, which, first of all, creates a dictionary containing all the gens of the parent.
sagemathgh-37143: special subs for fractions
We create a specialised method `subs` for `FractionFieldElements`, for
better performance. In particular, the generic `Element.subs` method
insists on replacing all gens, which is a problem in polynomial rings
with many variables, such as (potentially) the `InfinitePolynomialRing`.
Fixessagemath#37122.
URL: sagemath#37143
Reported by: Martin Rubey
Reviewer(s): Martin Rubey, Travis Scrimshaw
vbraun
pushed a commit
to vbraun/sage
that referenced
this issue
Feb 11, 2024
sagemathgh-37143: special subs for fractions
We create a specialised method `subs` for `FractionFieldElements`, for
better performance. In particular, the generic `Element.subs` method
insists on replacing all gens, which is a problem in polynomial rings
with many variables, such as (potentially) the `InfinitePolynomialRing`.
Fixessagemath#37122.
URL: sagemath#37143
Reported by: Martin Rubey
Reviewer(s): Martin Rubey, Travis Scrimshaw
Steps To Reproduce
Substitutions in the fraction field of a polynomial ring are much slower than necessary:
Expected Behavior
There should be not much difference in timing.
Actual Behavior
The method called is
Element.subs
, which, first of all, creates a dictionary containing all thegens
of the parent.Additional Information
#1381 seems to be orthogonal to this.
Environment
Checklist
The text was updated successfully, but these errors were encountered: