Skip to content

Commit 623846b

Browse files
committed
Fix quadratic form with non-symmetric matrix and non-commutative variables
1 parent dbfb540 commit 623846b

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicPolynomials"
22
uuid = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
33
repo = "https://github.com/JuliaAlgebra/DynamicPolynomials.jl.git"
4-
version = "0.3.13"
4+
version = "0.3.14"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

src/poly.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,12 @@ function MP.polynomial(Q::AbstractMatrix, mv::MonomialVector{C}, ::Type{T}) wher
228228
# for j in 1:n wouldn't be cache friendly for Q
229229
for j in i:n
230230
k = trimap(i, j, n)
231-
q = Q[i, j]
232231
x[offset+k] = mv[i] * mv[j]
233-
a[offset+k] = q
232+
a[offset+k] = Q[i, j]
234233
if i != j
235234
offset += 1
236235
x[offset+k] = mv[j] * mv[i]
237-
a[offset+k] = q
236+
a[offset+k] = Q[j, i]
238237
end
239238
end
240239
end

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ using MultivariatePolynomials
33
using Test
44
using LinearAlgebra
55

6+
# TODO move to MP
7+
@testset "Noncommutative quadratic" begin
8+
@ncpolyvar x[1:2]
9+
Q = Hermitian([1 2 + 3im; 2 - 3im 4])
10+
p = 1x[1]^2 + (2 + 3im) * x[1] * x[2] + (2 - 3im) * x[2] * x[1] + 4x[2]^2
11+
@test polynomial(Q, x) == p
12+
@test polynomial(Q, monovec(x)) == p
13+
end
14+
615
include("mono.jl")
716
include("poly.jl")
817
include("comp.jl")

0 commit comments

Comments
 (0)