Skip to content

Commit

Permalink
Implement Hessian matrix for polynomials.
Browse files Browse the repository at this point in the history
  • Loading branch information
HechtiDerLachs committed Sep 28, 2023
1 parent fb50c7d commit e21a56d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Rings/mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1294,3 +1294,20 @@ end

# assure compatibility with generic code for MPolyQuos:
lift(f::MPolyRingElem) = f

### Hessian matrix
function hessian_matrix(f::MPolyElem)
R = parent(f)
n = nvars(R)
df = jacobi_matrix(f)
result = zero(MatrixSpace(R, n, n))
for i in 1:n
for j in i:n
result[i, j] = result[j, i] = derivative(df[i], j)
end
end
return result
end

hessian(f::MPolyElem) = det(hessian_matrix(f))

2 changes: 2 additions & 0 deletions src/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ export helper_images
export helper_kappa
export helper_ring
export hermitian_form
export hessian
export hessian_matrix
export hilbert_basis
export hilbert_function
export hilbert_polynomial
Expand Down
8 changes: 8 additions & 0 deletions test/Rings/mpoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,11 @@ end
equidimensional_decomposition_weak(I)
end

@testset "Hessian matrix" begin
R, (x, y, z) = QQ[:x, :y, :z]
f = x^2 + x*y^2 - z^3
H = hessian_matrix(f)
@test H == R[2 2*y 0; 2*y 2*x 0; 0 0 -6*z]
@test hessian(f) == -24*x*z + 24*y^2*z
end

0 comments on commit e21a56d

Please sign in to comment.