Skip to content

Commit

Permalink
changed the algorithm, adapted doc-tests and runtests.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
KilianBruns committed Nov 6, 2024
1 parent bbd8d0c commit 817d35e
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 94 deletions.
61 changes: 26 additions & 35 deletions experimental/HasseSchmidt/src/HasseSchmidt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,23 @@ julia> f = 5*x^2 + 3*y^5;
julia> hasse_derivatives(f)
8-element Vector{Vector{Any}}:
[[0, 0], 5*x^2 + 3*y^5]
[[0, 1], 15*y^4]
[[0, 2], 30*y^3]
[[0, 3], 30*y^2]
[[0, 4], 15*y]
[[0, 5], 3]
[[1, 0], 10*x]
[[0, 4], 15*y]
[[0, 3], 30*y^2]
[[2, 0], 5]
[[0, 2], 30*y^3]
[[1, 0], 10*x]
[[0, 1], 15*y^4]
[[0, 0], 5*x^2 + 3*y^5]
```
"""
function hasse_derivatives(f::MPolyRingElem)
R = parent(f)
R = parent(f)
x = gens(R)
n = ngens(R)
# define new ring with more variables: R[x1, ..., xn] -> R[y1, ..., yn, t1, ..., tn]
Rtemp, y, t = polynomial_ring(R, :y => 1:n, :t => 1:n)
F = evaluate(f, y + t)
HasseDerivativesList = [[zeros(Int64, n), f]] # initializing with the zero'th HS derivative: f itself
varR = vcat(gens(R), fill(base_ring(R)(1), n))
# getting hasse derivs without extra attention on ordering
for term in terms(F)
if sum(degrees(term)[n+1:2n]) != 0 #
# hasse derivatives are the factors in front of the monomial in t
push!(HasseDerivativesList, [degrees(term)[n+1:2n], evaluate(term, varR)])
end
end
return HasseDerivativesList
Rtemp, t = polynomial_ring(R, :t => 1:n)
F = evaluate(f, x + t)
return [[degrees(monomial(term, 1)), coeff(term, 1)] for term in terms(F)]
end

function hasse_derivatives(f::MPolyQuoRingElem)
Expand Down Expand Up @@ -91,13 +82,13 @@ julia> RQ, phi = quo(R, I);
julia> f = phi(2*y^4);
julia> _hasse_derivatives(f)
julia> Oscar._hasse_derivatives(f)
5-element Vector{Vector{Any}}:
[[0, 0], 2*y^4]
[[0, 1], 8*y^3]
[[0, 2], 12*y^2]
[[0, 3], 8*y]
[[0, 4], 2]
[[0, 3], 8*y]
[[0, 2], 12*y^2]
[[0, 1], 8*y^3]
[[0, 0], 2*y^4]
```
"""
function _hasse_derivatives(f::MPolyQuoRingElem)
Expand All @@ -122,14 +113,14 @@ julia> Rloc, phi = localization(R, U);
julia> f = phi(2*z^5);
julia> _hasse_derivatives(f)
julia> Oscar._hasse_derivatives(f)
6-element Vector{Vector{Any}}:
[[0, 0, 0], 2*z^5]
[[0, 0, 1], 10*z^4]
[[0, 0, 2], 20*z^3]
[[0, 0, 3], 20*z^2]
[[0, 0, 4], 10*z]
[[0, 0, 5], 2]
[[0, 0, 4], 10*z]
[[0, 0, 3], 20*z^2]
[[0, 0, 2], 20*z^3]
[[0, 0, 1], 10*z^4]
[[0, 0, 0], 2*z^5]
```
"""
function _hasse_derivatives(f::Oscar.MPolyLocRingElem)
Expand Down Expand Up @@ -158,12 +149,12 @@ julia> RQL, iota = localization(RQ, U);
julia> f = iota(phi(4*y^3));
julia> _hasse_derivatives(f)
julia> Oscar._hasse_derivatives(f)
4-element Vector{Vector{Any}}:
[[0, 0, 0], 4*y^3]
[[0, 1, 0], 12*y^2]
[[0, 2, 0], 12*y]
[[0, 3, 0], 4]
[[0, 2, 0], 12*y]
[[0, 1, 0], 12*y^2]
[[0, 0, 0], 4*y^3]
```
"""
function _hasse_derivatives(f::Oscar.MPolyQuoLocRingElem)
Expand Down
128 changes: 69 additions & 59 deletions experimental/HasseSchmidt/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,74 @@
@testset "hasse_derivatives" begin
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]);

result_a1 = [ [[0, 0], x^3],
[[1, 0], 3*x^2],
[[2, 0], 3*x],
[[3, 0], 1]]
result_a1 = [ [[3, 0], 1],
[[2, 0], 3*x],
[[1, 0], 3*x^2],
[[0, 0], x^3]]
@test result_a1 == hasse_derivatives(x^3)

result_a2 = [ [[0, 0], 5*x^2 + 3*y^5],
[[0, 1], 15*y^4],
[[0, 2], 30*y^3],
[[0, 3], 30*y^2],
[[0, 4], 15*y],
[[0, 5], 3],
[[1, 0], 10*x],
[[2, 0], 5]]
result_a2 = [ [[0, 5], 3],
[[0, 4], 15*y],
[[0, 3], 30*y^2],
[[2, 0], 5],
[[0, 2], 30*y^3],
[[1, 0], 10*x],
[[0, 1], 15*y^4],
[[0, 0], 5*x^2 + 3*y^5]]
@test result_a2 == hasse_derivatives(5*x^2 + 3*y^5)

result_a3 = [ [[0, 0], x^2*y^3],
[[1, 0], 2*x*y^3],
[[2, 0], y^3],
[[0, 1], 3*x^2*y^2],
[[1, 1], 6*x*y^2],
[[2, 1], 3*y^2],
[[0, 2], 3*x^2*y],
[[1, 2], 6*x*y],
[[2, 2], 3*y],
[[0, 3], x^2],
[[1, 3], 2*x],
[[2, 3], 1]]
result_a3 = [ [[2, 3], 1],
[[2, 2], 3*y],
[[1, 3], 2*x],
[[2, 1], 3*y^2],
[[1, 2], 6*x*y],
[[0, 3], x^2],
[[2, 0], y^3],
[[1, 1], 6*x*y^2],
[[0, 2], 3*x^2*y],
[[1, 0], 2*x*y^3],
[[0, 1], 3*x^2*y^2],
[[0, 0], x^2*y^3]]
@test result_a3 == hasse_derivatives(x^2*y^3)

result_a4 = [ [[0, 0], x^4 + y^2],
[[1, 0], 4*x^3],
[[2, 0], 6*x^2],
[[3, 0], 4*x],
[[4, 0], 1],
[[0, 1], 2*y],
[[0, 2], 1]]
result_a4 = [ [[4, 0], 1],
[[3, 0], 4*x],
[[2, 0], 6*x^2],
[[0, 2], 1],
[[1, 0], 4*x^3],
[[0, 1], 2*y],
[[0, 0], x^4 + y^2]]
@test result_a4 == hasse_derivatives(x^4 + y^2)

result_a5 = [ [[2, 1], 1],
[[1, 2], 1],
[[2, 0], y],
[[1, 1], 2*x + 2*y],
[[0, 2], x],
[[1, 0], 2*x*y + y^2],
[[0, 1], x^2 + 2*x*y],
[[0, 0], x^2*y + x*y^2]]
@test result_a5 == hasse_derivatives(x^2*y + x*y^2)
end

@testset "hasse_derivatives finite fields" begin
R, (x, y, z) = polynomial_ring(GF(3), ["x", "y", "z"]);

result_b1 = [ [[0, 0, 0], x^2 + y^2],
[[1, 0, 0], 2*x],
[[2, 0, 0], 1],
[[0, 1, 0], 2*y],
[[0, 2, 0], 1]]
result_b1 = [ [[2, 0, 0], 1],
[[0, 2, 0], 1],
[[1, 0, 0], 2*x],
[[0, 1, 0], 2*y],
[[0, 0, 0], x^2 + y^2]]
@test result_b1 == hasse_derivatives(x^2 + y^2)

result_b2 = [ [[0, 0, 0], x^2*y + z^6],
[[0, 0, 3], 2*z^3],
[[0, 0, 6], 1],
[[1, 0, 0], 2*x*y],
[[2, 0, 0], y],
[[0, 1, 0], x^2],
[[1, 1, 0], 2*x],
[[2, 1, 0], 1]]
result_b2 = [ [[0, 0, 6], 1],
[[2, 1, 0], 1],
[[0, 0, 3], 2*z^3],
[[2, 0, 0], y],
[[1, 1, 0], 2*x],
[[1, 0, 0], 2*x*y],
[[0, 1, 0], x^2],
[[0, 0, 0], x^2*y + z^6]]
@test result_b2 == hasse_derivatives(x^2*y + z^6)
end

Expand All @@ -79,11 +89,11 @@ end
I = ideal(R, [x^2 - 1]);
RQ, _ = quo(R, I);

result_c1 = [ [[0, 0, 0], 3*y^4],
[[0, 1, 0], 12*y^3],
[[0, 2, 0], 18*y^2],
[[0, 3, 0], 12*y],
[[0, 4, 0], 3]]
result_c1 = [ [[0, 4, 0], 3],
[[0, 3, 0], 12*y],
[[0, 2, 0], 18*y^2],
[[0, 1, 0], 12*y^3],
[[0, 0, 0], 3*y^4]]
@test result_c1 == Oscar._hasse_derivatives(RQ(3y^4))
end

Expand All @@ -93,10 +103,10 @@ end
U = complement_of_prime_ideal(m);
RL, _ = localization(R, U);

result_d1 = [ [[0, 0, 0], 5*x^3],
[[1, 0, 0], 15*x^2],
[[2, 0, 0], 15*x],
[[3, 0, 0], 5]]
result_d1 = [ [[3, 0, 0], 5],
[[2, 0, 0], 15*x],
[[1, 0, 0], 15*x^2],
[[0, 0, 0], 5*x^3]]
@test result_d1 == Oscar._hasse_derivatives(RL(5x^3))
end

Expand All @@ -108,12 +118,12 @@ end
U = complement_of_prime_ideal(m);
RQL, _ = localization(RQ, U);

result_e1 = [ [[0, 0, 0], 2*z^5],
[[0, 0, 1], 10*z^4],
[[0, 0, 2], 20*z^3],
[[0, 0, 3], 20*z^2],
[[0, 0, 4], 10*z],
[[0, 0, 5], 2]]
result_e1 = [ [[0, 0, 5], 2],
[[0, 0, 4], 10*z],
[[0, 0, 3], 20*z^2],
[[0, 0, 2], 20*z^3],
[[0, 0, 1], 10*z^4],
[[0, 0, 0], 2*z^5]]
@test result_e1 == Oscar._hasse_derivatives(RQL(2z^5))
end

0 comments on commit 817d35e

Please sign in to comment.