Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage:
precision: 2
round: down
range: 85...95 # FIXME: We should set this one to about 90...95
8 changes: 0 additions & 8 deletions src/KnownProperties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,3 @@ ERROR: MethodError: no method matching is_known(::typeof(dim), ::AbstractAlgebra
```
"""
function is_known end

# A generic implementation to look up attributes. This can be used to implement
# `is_known` for a specific type of arguments of unary functions.
function _is_known_via_attributes(f::Function, x::Any)
@req is_attribute_storing(x) "objects of type $(typeof(x)) do not support attribute storage"
return has_attribute(x, nameof(f))
end

11 changes: 8 additions & 3 deletions src/NCPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ number_of_generators(R::NCPolyRing) = 1
#
###############################################################################

function show(io::IO, p::NCPolyRing)
function show(io::IO, p::Union{NCPolyRing, PolyRing})
@show_name(io, p)
@show_special(io, p)
print(io, "Univariate polynomial ring in ", var(p), " over ")
print(terse(pretty(io)), Lowercase(), base_ring(p))
if is_terse(io)
print(io, "Univariate polynomial ring")
else
io = pretty(io)
print(io, "Univariate polynomial ring in ", var(p), " over ")
print(terse(io), Lowercase(), base_ring(p))
end
end

###############################################################################
Expand Down
12 changes: 0 additions & 12 deletions src/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,18 +495,6 @@ end

@enable_all_show_via_expressify Union{PolynomialElem, NCPolyRingElem}

function show(io::IO, p::PolyRing)
@show_name(io, p)
@show_special(io, p)
if is_terse(io)
print(io, "Univariate polynomial ring")
else
io = pretty(io)
print(io, "Univariate polynomial ring in ", var(p), " over ")
print(terse(io), Lowercase(), base_ring(p))
end
end

pretty_eq(x::PolyRingElem, y::PolyRingElem) = x == y
function pretty_lt(x::PolyRingElem, y::PolyRingElem)
if length(x) < length(y)
Expand Down
2 changes: 1 addition & 1 deletion src/generic/Misc/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function is_power(a::PolyRingElem, n::Int)
fl || return false, a
f = factor(a)
all(i % n == 0 for (_, i) in f) || return false, a
return true, x*prod(p^div(k, n) for (p, k) = f)
return true, f.unit * prod(p^div(k, n) for (p, k) = f)
end

################################################################################
Expand Down
11 changes: 11 additions & 0 deletions test/Rings-test.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("julia/Integers-test.jl")
include("julia/Matrix-test.jl")
include("broadcasting-test.jl")

# artificially low cutoffs for testing purposes
Expand Down Expand Up @@ -62,6 +63,16 @@ end
end
end

@testset "sqrt" begin
Base.sqrt(a::EuclideanRingResidueRingElem{BigInt}) = parent(a)(BigInt(sqrt(a.data)))
R = residue_ring(ZZ, 101)[1]

@test sqrt(R(81), check=true) == R(9)
@test_throws ErrorException sqrt(R(82), check=true)
@test is_square_with_sqrt(R(16)) == (true, R(4))
@test is_square_with_sqrt(R(15))[1] == false
end

@testset "properties" begin
@test is_perfect(QQ)
@test is_perfect(GF(2))
Expand Down
63 changes: 63 additions & 0 deletions test/generic/Poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3063,3 +3063,66 @@ end
@test is_separable(x)
@test !is_separable(x^2)
end

@testset "Generic.Poly.Misc" begin
# factor function is required for is_power. Implement naive ones here.
function AbstractAlgebra.factor(a::Integer)
R = parent(a)
f = Fac{typeof(a)}()
f.unit = sign(a)
a = abs(a)
for ix in [R(2), R(3), R(5), R(7), R(11)]
if is_zero(a % ix)
a /= ix
f.fac[ix] = 1
end
while is_zero(a % ix)
a /= ix
f.fac[ix] += 1
end
end
if !is_one(a)
error()
end
return f
end
function AbstractAlgebra.factor(p::PolyRingElem)
P = parent(p)
x = gen(P)
f = Fac{typeof(p)}()
ct = content(p)
cf = factor(ct)
ut = sign(leading_coefficient(p))
for (t, k) in cf
f.fac[P(t)] = k
end
f.unit = P(ut)
p /= ut * ct
for y in [x + c for c in -2:2]
if is_zero(p % y)
p /= y
f.fac[y] = 1
end
while is_zero(p % y)
p /= y
f.fac[y] += 1
end
end
if !is_one(p)
error()
end
return f
end
ZZx, x = ZZ[:x]
@test is_power(x, 2) == (false, x)
@test is_power(x, 3) == (false, x)
@test is_power(x^2, 2) == (true, x)
@test is_power(3 * x^2, 2) == (false, 3 * x^2)
@test is_power(2^2 * x^2, 2) == (true, 2 * x)
@test is_power(2^3 * x^3, 3) == (true, 2 * x)
@test is_power(3^4 * x^4, 2) == (true, 9 * x^2)
@test is_power(-3^4 * x^4, 2) == (false, -81 * x^4)
@test is_power(-3^3 * x^3, 3) == (true, -3 * x)
@test is_power(3^2 * (x + 1)^2 * x^2, 2) == (true, 3 * (x + 1) * x)
@test is_power(-3^2 * (x + 1)^2 * x^2, 2) == (false, -3^2 * (x + 1)^2 * x^2)
end
36 changes: 36 additions & 0 deletions test/julia/Matrix-test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@testset "Julia.Matrix.manipulation" begin
r, c = 1, 2
A = zero_matrix(Int, r, c)
A[1, :] = [10, -2]
B = Int[10 -2]

@test A == B
@test number_of_rows(A) == r
@test number_of_columns(A) == c
end

@testset "Julia.Matrix.array_creation" begin
M = matrix_ring(ZZ, 2)
m1 = M(ZZ[1 2; 3 4])
m2 = M(ZZ[1 0; 0 1])
arr = Array(M, 2)
arr[1] = deepcopy(m1)
arr[2] = deepcopy(m2)
@test arr[1] == m1
@test arr[2] == m2
end

@testset "Julia.Matrix.permutations" begin
M = matrix_ring(ZZ, 2)
m0 = M([1 2; 3 4])
m1 = M([2 3; 4 5])
m2 = M([3 4; 5 6])
m3 = M([4 5; 6 7])
m = elem_type(M)[m0 m1; m2 m3]
Rm = elem_type(M)[m2 m3; m0 m1]
Cm = elem_type(M)[m1 m0; m3 m2]
rm = swap_rows(m, 2, 1)
cm = swap_cols(m, 1, 2)
@test rm == Rm
@test cm == Cm
end
Loading