Skip to content

Commit b78ea60

Browse files
authored
Merge pull request #50 from ederc/intervals
Interval solutions
2 parents 27a2c19 + a084a60 commit b78ea60

File tree

2 files changed

+18
-65
lines changed

2 files changed

+18
-65
lines changed

src/algorithms/solvers.jl

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import msolve_jll: libmsolve
22

3-
export inter_solutions, real_solutions, rational_solutions, rational_parametrization
3+
export real_solutions, rational_solutions, rational_parametrization
44

55
@doc Markdown.doc"""
66
_get_rational_parametrization(nr::Int32, lens::Vector{Int32}, cfs::Ptr{BigInt})
@@ -374,6 +374,7 @@ is greater than zero an empty array is returned.
374374
- `la_option::Int=2`: linear algebra option: exact sparse-dense (`1`), exact sparse (`2`, default), probabilistic sparse-dense (`42`), probabilistic sparse(`44`).
375375
- `info_level::Int=0`: info level printout: off (`0`, default), summary (`1`), detailed (`2`).
376376
- `precision::Int=32`: bit precision for the computed solutions.
377+
- `interval::Bool=false`: return real solutions as intervals.
377378
378379
# Examples
379380
```jldoctest
@@ -391,6 +392,13 @@ julia> real_solutions(I)
391392
[1, 0, 0]
392393
[1945971683//8589934592, 972985841//8589934592, 744426424910260862653434112767010536665//2722258935367507707706996859454145691648]
393394
[2863311531//8589934592, 0, 3629678580490010276942662479272194255531//10889035741470030830827987437816582766592]
395+
396+
julia> real_solutions(I, interval=true)
397+
4-element Vector{Vector{Vector{QQFieldElem}}}:
398+
[[1354207349//2147483648, 2708414699//4294967296], [1354207349//4294967296, 677103675//2147483648], [-355532291286331190123863132844989723573//2722258935367507707706996859454145691648, -1422129165145324760495452531379958894291//10889035741470030830827987437816582766592]]
399+
[[1, 1], [0, 0], [0, 0]]
400+
[[972985841//4294967296, 486492921//2147483648], [60811615//536870912, 486492921//4294967296], [93053303113782607831679264095876317083//340282366920938463463374607431768211456, 372213212455130431326717056383505268333//1361129467683753853853498429727072845824]]
401+
[[1431655765//4294967296, 715827883//2147483648], [-1//4294967296, 1//4294967296], [1814839290245005138471331239636097127765//5444517870735015415413993718908291383296, 907419645122502569235665619818048563883//2722258935367507707706996859454145691648]]
394402
```
395403
"""
396404
function real_solutions(
@@ -401,7 +409,8 @@ function real_solutions(
401409
# in symbolic preprocessing
402410
la_option::Int=2, # linear algebra option
403411
info_level::Int=0, # info level for print outs
404-
precision::Int=32 # precision of the solution set
412+
precision::Int=32, # precision of the solution set
413+
interval::Bool=false # return real solutions as intervals
405414
)
406415

407416
isdefined(I, :real_sols) ||
@@ -413,64 +422,9 @@ function real_solutions(
413422
info_level = info_level,
414423
precision = precision)
415424

416-
return I.real_sols
417-
end
418-
419-
@doc Markdown.doc"""
420-
inter_solutions(I::Ideal{T} where T <: MPolyRingElem, <keyword arguments>)
421-
422-
Given an ideal `I` with a finite solution set over the complex numbers, return
423-
the intervals with a given precision (default 32 bits), containing the roots of the ideal.
424-
425-
**Note**: At the moment only QQ is supported as ground field. If the dimension of the ideal
426-
is greater than zero an empty array is returned.
427-
428-
# Arguments
429-
- `I::Ideal{T} where T <: MPolyRingElem`: input generators.
430-
- `initial_hts::Int=17`: initial hash table size `log_2`.
431-
- `nr_thrds::Int=1`: number of threads for parallel linear algebra.
432-
- `max_nr_pairs::Int=0`: maximal number of pairs per matrix, only bounded by minimal degree if `0`.
433-
- `la_option::Int=2`: linear algebra option: exact sparse-dense (`1`), exact sparse (`2`, default), probabilistic sparse-dense (`42`), probabilistic sparse(`44`).
434-
- `info_level::Int=0`: info level printout: off (`0`, default), summary (`1`), detailed (`2`).
435-
- `precision::Int=32`: bit precision for the computed solutions.
436-
437-
# Examples
438-
```jldoctest
439-
julia> using AlgebraicSolving
440-
441-
julia> R,(x1,x2,x3) = polynomial_ring(QQ, ["x1","x2","x3"])
442-
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[x1, x2, x3])
443-
444-
julia> I = Ideal([x1+2*x2+2*x3-1, x1^2+2*x2^2+2*x3^2-x1, 2*x1*x2+2*x2*x3-x2])
445-
QQMPolyRingElem[x1 + 2*x2 + 2*x3 - 1, x1^2 - x1 + 2*x2^2 + 2*x3^2, 2*x1*x2 + 2*x2*x3 - x2]
446-
447-
julia> inter_solutions(I)
448-
4-element Vector{Vector{Vector{QQFieldElem}}}:
449-
[[1354207349//2147483648, 2708414699//4294967296], [1354207349//4294967296, 677103675//2147483648], [-355532291286331190123863132844989723573//2722258935367507707706996859454145691648, -1422129165145324760495452531379958894291//10889035741470030830827987437816582766592]]
450-
[[1, 1], [0, 0], [0, 0]]
451-
[[972985841//4294967296, 486492921//2147483648], [60811615//536870912, 486492921//4294967296], [93053303113782607831679264095876317083//340282366920938463463374607431768211456, 372213212455130431326717056383505268333//1361129467683753853853498429727072845824]]
452-
[[1431655765//4294967296, 715827883//2147483648], [-1//4294967296, 1//4294967296], [1814839290245005138471331239636097127765//5444517870735015415413993718908291383296, 907419645122502569235665619818048563883//2722258935367507707706996859454145691648]]
453-
```
454-
"""
455-
function inter_solutions(
456-
I::Ideal{T} where T <: MPolyRingElem; # input generators
457-
initial_hts::Int=17, # hash table size, default 2^17
458-
nr_thrds::Int=1, # number of threads
459-
max_nr_pairs::Int=0, # number of pairs maximally chosen
460-
# in symbolic preprocessing
461-
la_option::Int=2, # linear algebra option
462-
info_level::Int=0, # info level for print outs
463-
precision::Int=32 # precision of the solution set
464-
)
465-
466-
isdefined(I, :inter_sols) ||
467-
_core_msolve(I,
468-
initial_hts = initial_hts,
469-
nr_thrds = nr_thrds,
470-
max_nr_pairs = max_nr_pairs,
471-
la_option = la_option,
472-
info_level = info_level,
473-
precision = precision)
474-
475-
return I.inter_sols
425+
if interval
426+
return I.inter_sols
427+
else
428+
return I.real_sols
429+
end
476430
end

test/algorithms/solvers.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
rat_sols = Vector{QQFieldElem}[[49, 0, 0, 0], [49//3, 0, 0, 1//3]]
2424

2525
@test sols == real_solutions(I)
26-
@test inter_sols == inter_solutions(I)
26+
@test inter_sols == real_solutions(I, interval=true)
2727
@test rat_sols == rational_solutions(I)
2828
@test I.real_sols == real_solutions(I)
2929

@@ -54,12 +54,11 @@
5454

5555
I = Ideal([x1^2-x2, x1*x3-x4, x2*x4-12, x4^3-x3^2])
5656
real_solutions(I)
57-
inter_solutions(I)
5857
@test I.rat_param.vars == Symbol[]
5958

6059
I = Ideal([x1^2-x2, x1*x3, x2-12])
6160
@test_throws ErrorException real_solutions(I)
62-
@test_throws ErrorException inter_solutions(I)
61+
@test_throws ErrorException real_solutions(I, interval=true)
6362
@test_throws ErrorException rational_solutions(I)
6463

6564
# check variable permutation

0 commit comments

Comments
 (0)