Skip to content

Commit cac388b

Browse files
authored
Merge pull request #45 from ederc/variable-permutation
Variable permutation
2 parents 4ef3f04 + bcded52 commit cac388b

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AlgebraicSolving"
22
uuid = "66b61cbe-0446-4d5d-9090-1ff510639f9d"
33
authors = ["ederc <[email protected]>", "Mohab Safey El Din <[email protected]", "Rafael Mohr <[email protected]>"]
4-
version = "0.4.11"
4+
version = "0.4.12"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -26,4 +26,4 @@ Markdown = "1.6"
2626
Printf = "1.6"
2727
Random = "1.6"
2828
Test = "1.6"
29-
msolve_jll = "0.6.3"
29+
msolve_jll = "0.6.5"

src/algorithms/solvers.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ function _core_msolve(
141141
jl_cf_lf = reinterpret(Ptr{BigInt}, res_cf_lf[])
142142

143143
jl_vnames = Base.unsafe_wrap(Array, res_vnames[], jl_rp_nr_vars)
144-
145-
vsymbols = [Symbol(unsafe_string(jl_vnames[i])) for i in 1:jl_rp_nr_vars]
144+
vsymbols = [Symbol(unsafe_string(jl_vnames[i])) for i in 1:jl_rp_nr_vars]
145+
#= get possible variable permutation =#
146+
perm = sortperm(vsymbols)
146147

147148
rat_param = _get_rational_parametrization(jl_ld, jl_len,
148149
jl_cf, jl_cf_lf, jl_rp_nr_vars)
@@ -173,9 +174,9 @@ function _core_msolve(
173174
j = 1
174175
tmp = Vector{QQFieldElem}(undef, nr_vars)
175176
while j <= nr_vars
176-
tmp[j] = QQFieldElem(unsafe_load(jl_sols_num, i)) >> Int64(unsafe_load(jl_sols_den, i))
177-
tmp[j] += QQFieldElem(unsafe_load(jl_sols_num, i+1)) >> Int64(unsafe_load(jl_sols_den, i+1))
178-
tmp[j] = tmp[j] >> 1
177+
tmp[perm[j]] = QQFieldElem(unsafe_load(jl_sols_num, i)) >> Int64(unsafe_load(jl_sols_den, i))
178+
tmp[perm[j]] += QQFieldElem(unsafe_load(jl_sols_num, i+1)) >> Int64(unsafe_load(jl_sols_den, i+1))
179+
tmp[perm[j]] = tmp[perm[j]] >> 1
179180
i += 2
180181
j += 1
181182
end

test/algorithms/solvers.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@test sols == real_solutions(I)
1818
@test rat_sols == rational_solutions(I)
1919
@test I.real_sols == real_solutions(I)
20-
20+
2121
C, x = polynomial_ring(QQ, "x")
2222
elim = 128304*x^8 - 93312*x^7 + 15552*x^6 + 3144*x^5 - 1120*x^4 + 36*x^3 + 15*x^2 - x
2323
denom = 1026432*x^7 - 653184*x^6 + 93312*x^5 + 15720*x^4 - 4480*x^3 + 108*x^2 + 30*x - 1
@@ -50,4 +50,13 @@
5050
I = Ideal([x1^2-x2, x1*x3, x2-12])
5151
@test_throws ErrorException real_solutions(I)
5252
@test_throws ErrorException rational_solutions(I)
53+
54+
# check variable permutation
55+
R, (x, y) = polynomial_ring(QQ,["x","y"])
56+
I = Ideal([x^2-1, y])
57+
sols = Vector{QQFieldElem}[
58+
[-1, 0],
59+
[1, 0]
60+
]
61+
@test sols == real_solutions(I)
5362
end

0 commit comments

Comments
 (0)