-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some specialized methods for universal polynomials (#2013)
- Loading branch information
1 parent
7f1f323
commit 4df8c91
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
############################################################################### | ||
# | ||
# Specialized methods for universal polynomials | ||
# | ||
############################################################################### | ||
|
||
# These methods speed up some computations with specific universal | ||
# polynomial rings which would otherwise be handled by more generic | ||
# code. This mainly concerns rings over the rationals. | ||
|
||
denominator(f::UniversalPolyRingElem{QQFieldElem}) = denominator(data(f)) | ||
|
||
function +(p::Generic.UnivPoly{T}, n::ZZRingElem) where {T} | ||
S = parent(p) | ||
return Generic.UnivPoly{T}(data(p)+n, S) | ||
end | ||
|
||
+(n::ZZRingElem, p::Generic.UnivPoly) = p+n | ||
|
||
function -(p::Generic.UnivPoly{T}, n::ZZRingElem) where {T} | ||
S = parent(p) | ||
return Generic.UnivPoly{T}(data(p)-n, S) | ||
end | ||
|
||
function -(n::ZZRingElem, p::Generic.UnivPoly{T}) where {T} | ||
S = parent(p) | ||
return Generic.UnivPoly{T}(n-data(p), S) | ||
end | ||
|
||
function *(p::Generic.UnivPoly{T}, n::ZZRingElem) where {T} | ||
S = parent(p) | ||
return Generic.UnivPoly{T}(data(p)*n, S) | ||
end | ||
|
||
*(n::ZZRingElem, p::Generic.UnivPoly) = p*n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
include("generic/Poly-test.jl") | ||
include("generic/MPoly-test.jl") | ||
include("generic/UnivPoly-test.jl") | ||
include("generic/Matrix-test.jl") | ||
include("generic/Module-test.jl") | ||
include("generic/AbsMSeries-test.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@testset "UnivPoly.specialized_methods" begin | ||
R = universal_polynomial_ring(QQ) | ||
x = gen(R, :x) | ||
|
||
@test denominator(1//2*x+1//3*x^2) == 6 | ||
@test denominator(2//3*x) == 3 | ||
|
||
@test ZZ(1)+x == 1+x | ||
@test x+ZZ(1) == x+1 | ||
|
||
@test x-ZZ(1) == x-1 | ||
@test ZZ(1)-x == 1-x | ||
|
||
@test ZZ(2)*x == 2*x | ||
@test x*ZZ(2) == x*2 | ||
end |