Skip to content

Commit

Permalink
partly reorganized tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gpogudin committed Jan 26, 2024
1 parent 13cac29 commit 0789d73
Show file tree
Hide file tree
Showing 39 changed files with 4,063 additions and 4,140 deletions.
66 changes: 32 additions & 34 deletions test/RationalFunctionFields/RationalFunctionField.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
if GROUP == "All" || GROUP == "Core"
@testset "RationalFunctionField" begin
p = 0.99
R, (a, b, c) = QQ["a", "b", "c"]
@testset "RationalFunctionField" begin
p = 0.99
R, (a, b, c) = QQ["a", "b", "c"]

f1 = [a, b, a + b + c]
f2 = [2c, 3b, 5a]
rff1 = StructuralIdentifiability.RationalFunctionField(f1)
rff2 = StructuralIdentifiability.RationalFunctionField(f2)
@test StructuralIdentifiability.fields_equal(rff1, rff2, p)
@test all(StructuralIdentifiability.field_contains(rff1, [zero(R), one(R)], p))
@test all(StructuralIdentifiability.field_contains(rff1, [7a, 9b, 11c], p))
@test all(StructuralIdentifiability.field_contains(rff2, [7a, 9b, 11c], p))
f1 = [a, b, a + b + c]
f2 = [2c, 3b, 5a]
rff1 = StructuralIdentifiability.RationalFunctionField(f1)
rff2 = StructuralIdentifiability.RationalFunctionField(f2)
@test StructuralIdentifiability.fields_equal(rff1, rff2, p)
@test all(StructuralIdentifiability.field_contains(rff1, [zero(R), one(R)], p))
@test all(StructuralIdentifiability.field_contains(rff1, [7a, 9b, 11c], p))
@test all(StructuralIdentifiability.field_contains(rff2, [7a, 9b, 11c], p))

s1, s2 = a + b + c, a^2 + b^2 + c^2
f1 = [s1, s2]
rff1 = StructuralIdentifiability.RationalFunctionField(f1)
@test !any(
StructuralIdentifiability.field_contains(rff1, [a, b + c, a * b + b * c], p),
)
@test all(
StructuralIdentifiability.field_contains(rff1, [a * b + b * c + a * c], p),
)
@test all(StructuralIdentifiability.field_contains(rff1, [(s1)^8 - (s2)^9 + 89], p))
s1, s2 = a + b + c, a^2 + b^2 + c^2
f1 = [s1, s2]
rff1 = StructuralIdentifiability.RationalFunctionField(f1)
@test !any(
StructuralIdentifiability.field_contains(rff1, [a, b + c, a * b + b * c], p),
)
@test all(
StructuralIdentifiability.field_contains(rff1, [a * b + b * c + a * c], p),
)
@test all(StructuralIdentifiability.field_contains(rff1, [(s1)^8 - (s2)^9 + 89], p))

# Example in Section 5 from
# https://mediatum.ub.tum.de/doc/685465/685465.pdf
R, (x1, x2) = QQ["x1", "x2"]
g1 = (x1^3 + x1 * x2 - 2) // (x1^2 - x2 - 1)
g2 = (x1^2 + x1^2 * x2 + 7) // (x1 - x1^2 * x2^2)
g3 = x1^2 + 3x1 * x2
g4 = x1 * x2^2 + 5x1 * x2
g5 = x1^3 * x2 - x2
rff1 = StructuralIdentifiability.RationalFunctionField([g1, g2, g3, g4, g5])
rff2 = StructuralIdentifiability.RationalFunctionField([x1, x2])
@test StructuralIdentifiability.fields_equal(rff1, rff2, p)
end
# Example in Section 5 from
# https://mediatum.ub.tum.de/doc/685465/685465.pdf
R, (x1, x2) = QQ["x1", "x2"]
g1 = (x1^3 + x1 * x2 - 2) // (x1^2 - x2 - 1)
g2 = (x1^2 + x1^2 * x2 + 7) // (x1 - x1^2 * x2^2)
g3 = x1^2 + 3x1 * x2
g4 = x1 * x2^2 + 5x1 * x2
g5 = x1^3 * x2 - x2
rff1 = StructuralIdentifiability.RationalFunctionField([g1, g2, g3, g4, g5])
rff2 = StructuralIdentifiability.RationalFunctionField([x1, x2])
@test StructuralIdentifiability.fields_equal(rff1, rff2, p)
end
146 changes: 72 additions & 74 deletions test/RationalFunctionFields/normalforms.jl
Original file line number Diff line number Diff line change
@@ -1,83 +1,81 @@
if GROUP == "All" || GROUP == "Core"
eq_up_to_the_order(a, b) = issubset(a, b) && issubset(b, a)
eq_up_to_the_order(a, b) = issubset(a, b) && issubset(b, a)

@testset "Linear relations over the rationals" begin
R, (a, b, c) = QQ["a", "b", "c"]
@testset "Linear relations over the rationals" begin
R, (a, b, c) = QQ["a", "b", "c"]

f = [a + 9]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test eq_up_to_the_order(relations, [a])
f = [a + 9]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test eq_up_to_the_order(relations, [a])

f = [a * b // R(1), (b * c + a * b) // (a * b)]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test eq_up_to_the_order(relations, [a * b // R(1), b * c // R(1)])
f = [a * b // R(1), (b * c + a * b) // (a * b)]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test eq_up_to_the_order(relations, [a * b // R(1), b * c // R(1)])

R, (a, b, c) = QQ["a", "b", "c"]
f = [a^2 + b^2, a^3 + b^3, a^4 + b^4]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 1)
@test eq_up_to_the_order(relations, [a + b])
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test eq_up_to_the_order(relations, [a + b, a * b, a^2 + b^2])
R, (a, b, c) = QQ["a", "b", "c"]
f = [a^2 + b^2, a^3 + b^3, a^4 + b^4]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 1)
@test eq_up_to_the_order(relations, [a + b])
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test eq_up_to_the_order(relations, [a + b, a * b, a^2 + b^2])

f = [9a^7 + 10b^6, b^10 - 5b^2]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 1)
@test eq_up_to_the_order(relations, empty(f))
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 7)
@test eq_up_to_the_order(relations, [a^7 + (10 // 9) * b^6])
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 12)
@test eq_up_to_the_order(relations, [a^7 + (10 // 9) * b^6, b^10 - 5b^2])
f = [9a^7 + 10b^6, b^10 - 5b^2]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 1)
@test eq_up_to_the_order(relations, empty(f))
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 7)
@test eq_up_to_the_order(relations, [a^7 + (10 // 9) * b^6])
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 12)
@test eq_up_to_the_order(relations, [a^7 + (10 // 9) * b^6, b^10 - 5b^2])

# Regression tests
###
# LV model.
R, (x1, p2, p4, y1, x2, x3, u, p1, p3) =
QQ["x1", "p2", "p4", "y1", "x2", "x3", "u", "p1", "p3"]
f = [
x3 // one(R),
x2 * x1 // one(R),
p1 * p3 // one(R),
p2 * p4 // one(R),
p1 + p3 // one(R),
(p2 * x2 + p4 * x1) // (x2 * x1),
(p2 * x2 - p4 * x1) // (p1 - p3),
]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(
rff,
2,
strategy = :monte_carlo,
)
@test (x1 * p4 + p2 * x2) // one(R) in relations
# Regression tests
###
# LV model.
R, (x1, p2, p4, y1, x2, x3, u, p1, p3) =
QQ["x1", "p2", "p4", "y1", "x2", "x3", "u", "p1", "p3"]
f = [
x3 // one(R),
x2 * x1 // one(R),
p1 * p3 // one(R),
p2 * p4 // one(R),
p1 + p3 // one(R),
(p2 * x2 + p4 * x1) // (x2 * x1),
(p2 * x2 - p4 * x1) // (p1 - p3),
]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(
rff,
2,
strategy = :monte_carlo,
)
@test (x1 * p4 + p2 * x2) // one(R) in relations

###
R, (a, b, c) = QQ["a", "b", "c"]
f = [a, a * b + b * c]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test eq_up_to_the_order(relations, [a, a * b + b * c])
###
R, (a, b, c) = QQ["a", "b", "c"]
f = [a, a * b + b * c]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test eq_up_to_the_order(relations, [a, a * b + b * c])

###
# Some arbitrary generators for the SLIQR model
R, (b, e, In, S, Ninv, s, Q, g, u, a, y, L) =
polynomial_ring(QQ, [:b, :e, :In, :S, :Ninv, :s, :Q, :g, :u, :a, :y, :L])
f = [
In // one(R),
s // one(R),
Ninv // one(R),
b // one(R),
(g + a) // one(R),
(e * s * g - s * g + g * a) // one(R),
(e * S - S) // (e * Q),
(e * S * s - S * s + S * a) // e,
(s * Q^2 - Q^2 * a) // (e * g - g),
(e * In + e * L - In - Q - L) // (e * Q),
]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test s * Q - Q * a in relations
end
###
# Some arbitrary generators for the SLIQR model
R, (b, e, In, S, Ninv, s, Q, g, u, a, y, L) =
polynomial_ring(QQ, [:b, :e, :In, :S, :Ninv, :s, :Q, :g, :u, :a, :y, :L])
f = [
In // one(R),
s // one(R),
Ninv // one(R),
b // one(R),
(g + a) // one(R),
(e * s * g - s * g + g * a) // one(R),
(e * S - S) // (e * Q),
(e * S * s - S * s + S * a) // e,
(s * Q^2 - Q^2 * a) // (e * g - g),
(e * In + e * L - In - Q - L) // (e * Q),
]
rff = StructuralIdentifiability.RationalFunctionField(f)
relations = StructuralIdentifiability.monomial_generators_up_to_degree(rff, 2)
@test s * Q - Q * a in relations
end
55 changes: 27 additions & 28 deletions test/check_field_membership.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
if GROUP == "All" || GROUP == "Core"
@testset "Check field membership" begin
R, (x, y, z) = Nemo.polynomial_ring(Nemo.QQ, ["x", "y", "z"])
@testset "Check field membership" begin
R, (x, y, z) = Nemo.polynomial_ring(Nemo.QQ, ["x", "y", "z"])

@test field_contains(
RationalFunctionField([[R(1), x + y], [R(1), x * y], [z, (x + y)^2]]),
[(x^2 + y^2) // R(1), (x^3 + y^3) // (z - x * y), R(1) // (z + x + y), z // x],
0.99,
) == [true, true, true, false]
@test field_contains(
RationalFunctionField([[R(1), x + y], [R(1), x * y], [z, (x + y)^2]]),
[(x^2 + y^2) // R(1), (x^3 + y^3) // (z - x * y), R(1) // (z + x + y), z // x],
0.99,
) == [true, true, true, false]

@test field_contains(
RationalFunctionField([[
x + y + z,
x^2 + y^2 + z^2,
(x + y + z)^2,
x^3 + y^3 + z^3,
]]),
[x + y + z // 1, x * y * z // 1, x + y + 2 * z // 1, x // (y + z)],
0.99,
) == [true, true, false, false]
@test field_contains(
RationalFunctionField([[
x + y + z,
x^2 + y^2 + z^2,
(x + y + z)^2,
x^3 + y^3 + z^3,
]]),
[x + y + z // 1, x * y * z // 1, x + y + 2 * z // 1, x // (y + z)],
0.99,
) == [true, true, false, false]

@test field_contains(
RationalFunctionField([
x + y + z // 1,
x * y + y * z + z * x // 1,
x * y * z // 1,
]),
[x^2 + y^2 + z^2, x^6 + y^6 + z^6, x - y + z, x^2 - y^2 + z^2],
0.99,
) == [true, true, false, false]
end
@test field_contains(
RationalFunctionField([
x + y + z // 1,
x * y + y * z + z * x // 1,
x * y * z // 1,
]),
[x^2 + y^2 + z^2, x^6 + y^6 + z^6, x - y + z, x^2 - y^2 + z^2],
0.99,
) == [true, true, false, false]
end

Loading

0 comments on commit 0789d73

Please sign in to comment.