Skip to content

Commit a5d30a2

Browse files
authored
Merge pull request #25 from ederc/msolve
more features for msolve, also returning rational parametrization as …
2 parents c1711b3 + a4b02f3 commit a5d30a2

4 files changed

Lines changed: 67 additions & 48 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "GroebnerBasis"
22
uuid = "e39c9192-ea4d-5e15-9584-a488c6d614bd"
3-
version = "0.2.0"
3+
version = "0.3.0"
44

55
[deps]
66
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"

deps/msolve-binary

3.21 KB
Binary file not shown.

src/GroebnerBasis.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Singular
1313
import Nemo
1414
import Hecke
1515

16-
export f4, f5, msolve
16+
export f4, f5, msolve, solve_rational_parametrization
1717

1818
include("Benchmarks.jl")
1919
include("Example.jl")
@@ -49,7 +49,7 @@ function __init__()
4949
end
5050

5151
function versioninfo()
52-
print("GroebnerBasis v0.2.0\n")
52+
print("GroebnerBasis v0.3.0\n")
5353
gbrepo = dirname(dirname(@__FILE__))
5454

5555
print("GroebnerBasis: ")

src/Msolve.jl

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function get_rational_parametrization_from_msolve_output(
3030
c[i] = (-1) * param[6][i][2]
3131
end
3232

33-
return elim, denom, p, c
33+
return [elim, denom, p, c]
3434
end
3535

3636
function get_rational_parametrization(
@@ -70,6 +70,51 @@ function get_rational_parametrization(
7070
return elim, denom, p, c
7171
end
7272

73+
function solve_rational_parametrization(rat_param::Array{Any,1}, precision::Int=67)
74+
75+
elim = rat_param[1]
76+
den = rat_param[2]
77+
p = rat_param[3]
78+
c = rat_param[4]
79+
80+
#= get all solutions of elim, also complex ones,
81+
= real ones are isolated =#
82+
sols = []
83+
#= @time =# append!(sols, Hecke._roots(elim, precision))
84+
85+
#= get real solutions =#
86+
del = []
87+
for i in 1:length(sols)
88+
if Nemo.isreal(sols[i]) == false
89+
append!(del, i)
90+
end
91+
end
92+
93+
#= remove non-real solutions =#
94+
deleteat!(sols, del)
95+
96+
#= generate solution set for system =#
97+
variety = Array{Array{Rational{Int}, 1}, 1}(undef, length(sols))
98+
#= @time =# for i in 1:length(sols)
99+
tmp = Array{Rational{Int}}(undef, length(p)+1)
100+
d = Nemo.evaluate(den, sols[i])
101+
for j = 1:length(p)
102+
tmp[j] = rationalize(Int, BigFloat(real(Nemo.evaluate(p[j], sols[i]) / (d*c[j]))))
103+
tmp[length(p)+1] = rationalize(Int, BigFloat(real(sols[i])))
104+
end
105+
variety[i] = tmp
106+
end
107+
108+
return variety
109+
110+
#= for k in 1:nr_gens
111+
= for v in variety
112+
= println(BigInt(numerator(GroebnerBasis.Singular.evaluate(I[k], v)))/BigInt(denominator(GroebnerBasis.Singular.evaluate(I[k], v))))
113+
= end
114+
= println("")
115+
= end =#
116+
end
117+
73118
function msolve_file_interface(
74119
I::Singular.sideal; # input generators
75120
hts::Int=17, # hash table size, default 2^17
@@ -129,9 +174,9 @@ function msolve_file_interface(
129174
end
130175

131176
"""
132-
msolve(I[, hts::Int=17, nthrds::Int=1, maxpairs::Int=0, resetht::Int=0,
133-
laopt::Int=1, reducegb::Int=0, pbmfiles::Int=0,
134-
infolevel::Int=0, monorder::Symbol=:degrevlex])
177+
msolve(I[, initial_hts::Int=17, nr_thrds::Int=1, max_nr_pairs::Int=0,
178+
la_option::Int=1, infolevel::Int=0, input_file::String="/tmp/in.ms",
179+
output_file="/tmp/out.ms", precision::Int=67, get_param::Bool=false])
135180
136181
Compute the solution set of the given ideal I using the msolve C library. The function takes a Singular ideal as input and returns a Singular ideal. At the moment only QQ is supported as ground field..
137182
@@ -143,19 +188,20 @@ Compute the solution set of the given ideal I using the msolve C library. The fu
143188
* `max_nr_pairs::Int=0`: maximal number of pairs selected for one F4 matrix; default is
144189
0, i.e. no restriction. If matrices get too big or consume
145190
too much memory this is a good parameter to play with.
146-
* `la_option::Int=2`: option for linear algebra to be used in F4. there are different
147-
linear algebra routines implemented:
191+
* `la_option::Int=2`: option for linear algebra to be used in F4. there are different linear algebra routines implemented:
148192
- `1`: exact sparse-dense computation,
149193
- `2`: exact sparse computation, (default)
150194
- `42`: probabilistic sparse-dense computation,
151195
- `43`: exact sparse then probabilistic dense computation,
152196
- `44`: probabilistic sparse computation.
153197
* `info_level::Int=0`: info level for printout:
154198
- `0`: no printout (default),
155-
- `1`: a summary of the computational data is printed at the beginning and
156-
the end of the computation,
199+
- `1`: a summary of the computational data is printed at the beginning and the end of the computation,
157200
- `2`: also dynamical information for each round resp. matrix is printed.
201+
* `input_file::String="/tmp/in.ms"`: input file name for msolve binary; default: /tmp/in.ms.
202+
* `output_file::String="/tmp/in.ms"`: output file name for msolve binary; default: /tmp/out.ms.
158203
* `precision::Int=67`: precision for computing solutions; default is 67.
204+
* `get_param::Bool=false`: get rational parametrization of solution set; default is false.
159205
"""
160206
function msolve(
161207
I::Singular.sideal; # input generators
@@ -164,11 +210,12 @@ function msolve(
164210
max_nr_pairs::Int=0, # number of pairs maximally chosen
165211
# in symbolic preprocessing
166212
la_option::Int=2, # linear algebra option
167-
print_gb::Int=0, # printing of modular Groebner basis
168213
info_level::Int=0, # info level for print outs
169214
input_file::String="/tmp/in.ms", # msolve input file
170215
output_file::String="/tmp/out.ms", # msolve output file
171-
precision::Int=67 # precision of the solution set
216+
precision::Int=67, # precision of the solution set
217+
get_param::Bool=false # return rational parametrization of
218+
# solution set
172219
)
173220
R = I.base_ring
174221
# skip zero generators in ideal
@@ -247,7 +294,7 @@ function msolve(
247294
[write(io, string(J[i]),",\n") for i in 1:nr_gens]
248295
write(io, string(J[nr_gens]))
249296
close(io)
250-
cmd = `$dir/msolve-binary -v$info_level -l$la_option -m$max_nr_pairs -s$initial_hts -t $nr_thrds -f $input_file -o $output_file`
297+
#= @time =# cmd = `$dir/msolve-binary -v$info_level -l$la_option -m$max_nr_pairs -s$initial_hts -t $nr_thrds -f $input_file -o $output_file`
251298
run(cmd)
252299

253300
#= read msolve result, i.e. rational parametrization data =#
@@ -286,41 +333,13 @@ function msolve(
286333
end
287334

288335

289-
elim, den, p, c = get_rational_parametrization_from_msolve_output(param)
336+
#= @time =# rat_param = get_rational_parametrization_from_msolve_output(param)
290337

291-
#= get all solutions of elim, also complex ones,
292-
= real ones are isolated =#
293-
sols = []
294-
append!(sols, Hecke._roots(elim, precision))
295-
296-
#= get real solutions =#
297-
del = []
298-
for i in 1:length(sols)
299-
if Nemo.isreal(sols[i]) == false
300-
append!(del, i)
301-
end
302-
end
303-
304-
#= remove non-real solutions =#
305-
deleteat!(sols, del)
338+
variety = solve_rational_parametrization(rat_param)
306339

307-
#= generate solution set for system =#
308-
variety = Array{Array{Rational{Int}, 1}, 1}(undef, length(sols))
309-
for i in 1:length(sols)
310-
tmp = Array{Rational{Int}}(undef, nr_vars)
311-
d = Nemo.evaluate(den, sols[i])
312-
for j = 1:nr_vars-1
313-
tmp[j] = rationalize(Int, BigFloat(real(Nemo.evaluate(p[j], sols[i]) / (d*c[j]))))
314-
tmp[nr_vars] = rationalize(Int, BigFloat(real(sols[i])))
315-
end
316-
variety[i] = tmp
340+
if get_param == true
341+
return rat_param, variety
342+
else
343+
return variety
317344
end
318-
319-
#= for k in 1:nr_gens
320-
= for v in variety
321-
= println(BigInt(numerator(GroebnerBasis.Singular.evaluate(I[k], v)))/BigInt(denominator(GroebnerBasis.Singular.evaluate(I[k], v))))
322-
= end
323-
= println("")
324-
= end =#
325-
return variety
326345
end

0 commit comments

Comments
 (0)