-
Notifications
You must be signed in to change notification settings - Fork 112
/
solving-test.jl
77 lines (70 loc) · 2.44 KB
/
solving-test.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@testset "solving" begin
R, (x1,x2,x3) = polynomial_ring(QQ, ["x1", "x2", "x3"])
I = ideal(R, [x1+2*x2+2*x3-1, x1^2+2*x2^2+2*x3^2-x1, 2*x1*x2+2*x2*x3-x2])
C, x = polynomial_ring(QQ, "x")
elim = 84*x^4 - 40*x^3 + x^2 + x
denom = 336*x^3 - 120*x^2 + 2*x + 1
p1 = -184*x^3 + 80*x^2 - 4*x - 1
p2 = -36*x^3 + 18*x^2 - 2*x
prec = [32,48,64]
for p in prec
res = real_solutions(I, precision=p)
sols = res[1]
for g in gens(I)
for s in sols
@test abs(evaluate(g, s)) < QQFieldElem(2)^(-p+1)
end
end
end
@test res[2].vars == Symbol[:x1, :x2, :x3]
@test res[2].elim == elim
@test res[2].denom == denom
@test res[2].param[1] == -1 * p1
@test res[2].param[2] == -1 * p2
rat_sols = Vector{QQFieldElem}[[1, 0, 0], [1//3, 0, 1//3]]
rat_res = Oscar._rational_solutions(I)
@test length(rat_res) == 2 && issetequal(rat_res, rat_sols)
I = ideal(R,[x1-1,x1-1])
@test_throws ErrorException real_solutions(I)
@test_throws ErrorException Oscar._rational_solutions(I)
# Issue #1040
Qx, (x,) = polynomial_ring(QQ, ["x"])
I = ideal(Qx, [x^2 + 1])
res = real_solutions(I)
C, x = polynomial_ring(QQ, "x")
@test res[1] == []
@test res[2].vars == Symbol[:x]
@test res[2].elim == x^2+1
@test res[2].denom == 2*x
# issue 1743
R, (x1, x2) = polynomial_ring(QQ, ["x1", "x2"])
I = ideal(R, [x1 + ZZRingElem(2)^100, x2 + ZZRingElem(2)^100])
sols = Vector{QQFieldElem}[[-1267650600228229401496703205376, -1267650600228229401496703205376]]
@test sols == real_solutions(I)[1]
end
@testset "Rational solutions" begin
R, (x, y) = QQ["x", "y"]
I = ideal([x - 1, y - 1])
J = ideal([x - 2, y - 3])
pts = rational_solutions(I * J)
@test length(pts) == 2
@test issetequal(pts, Vector{QQFieldElem}[[1, 1], [2, 3]])
k, a = quadratic_field(-1)
R, (x, y) = k["x", "y"]
I = ideal([x^2 + 1, y^3 - 1])
pts = rational_solutions(I)
@test length(pts) == 2
@test issetequal(pts, Vector{elem_type(k)}[k.([a, 1]), k.([-a, 1])])
k = GF(5)
a = k(2)
R, (x, y) = k["x", "y"]
I = ideal([x^2 + 1, y^3 - 1])
pts = rational_solutions(I)
@test length(pts) == 2
@test issetequal(pts, Vector{elem_type(k)}[k.([a, 1]), k.([-a, 1])])
end
@testset "Rational solutions for homogeneous ideals" begin
Q, x = proj_space(QQ, 2)
i = ideal([x[1]-2*x[3], x[2]-3*x[3]])
@test length(rational_solutions(i)) == 1
end