Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toric_ideal(pts::ZZMatrix) is (often) very inefficient #4685

Open
imkhln opened this issue Mar 3, 2025 · 2 comments
Open

toric_ideal(pts::ZZMatrix) is (often) very inefficient #4685

imkhln opened this issue Mar 3, 2025 · 2 comments
Assignees
Labels

Comments

@imkhln
Copy link

imkhln commented Mar 3, 2025

Computing the toric ideal of a tuple of lattice points directly as a homomorphism kernel is much faster than applying toric_ideal to the respective integer matrix. In virtually all cases that are not too small. A random example with 7 points in dimension 2:

A = [[9, 1], [3, 3], [9, 8], [5, 1], [7, 10], [5, 5], [1, 5]]
R, x = polynomial_ring(QQ, "x" => (1:7))
S, z = polynomial_ring(QQ, "z" => (1:2))
f = hom(R, S, [prod(z.^A[i]) for i in (1:7)])
I = kernel(f)

runs almost instantly but a subsequent call of toric_ideal(matrix(ZZ, A)) does not terminate after several minutes. And this happens for all randomly generated examples with the same or larger parameters. (AFAIK, these two calls should output the same ideal, and in small cases where both work fast this is indeed the case.)

This was tested in Oscar 1.3.0 and also in some of the older versions, probably not a recently introduced issue.

@imkhln imkhln added the bug Something isn't working label Mar 3, 2025
@YueRen
Copy link
Member

YueRen commented Mar 4, 2025

I think the problem is caused by the following lines:

function toric_ideal(R::MPolyRing, pts::ZZMatrix)
intkernel = kernel(pts, side=:left)
presat = binomial_exponents_to_ideal(R, intkernel)

Because the kernel is computed over ZZ, the result intkernel has enormous entries, and the resulting ideal presat has enormous exponents:

julia> intkernel = kernel(matrix(QQ,A), side=:left)
[-1//8    -21//8   1   0   0   0   0]
[-1//2     -1//6   0   1   0   0   0]
[ 3//8   -83//24   0   0   1   0   0]
[    0     -5//3   0   0   0   1   0]
[ 1//2    -11//6   0   0   0   0   1]

julia> intkernel = kernel(matrix(ZZ,A), side=:left)
[  -1     -21     8     0   0   0   0]
[  -3     -32    12     3   0   0   0]
[-176   -1992   747   166   1   0   0]
[ -85    -960   360    80   0   1   0]
[ -93   -1056   396    88   0   0   1]

julia> presat = binomial_exponents_to_ideal(R, intkernel)
Ideal generated by
  -x[1]*x[2]^21 + x[3]^8
  -x[1]^3*x[2]^32 + x[3]^12*x[4]^3
  -x[1]^176*x[2]^1992 + x[3]^747*x[4]^166*x[5]
  -x[1]^85*x[2]^960 + x[3]^360*x[4]^80*x[6]
  -x[1]^93*x[2]^1056 + x[3]^396*x[4]^88*x[7]

@HereAround Is a the kernel over ZZ necessary or would an integer matrix from the kernel over QQ suffice?

@lkastner lkastner self-assigned this Mar 4, 2025
@lkastner lkastner added enhancement New feature or request and removed bug Something isn't working labels Mar 4, 2025
@HereAround
Copy link
Member

Computing the toric ideal of a tuple of lattice points directly as a homomorphism kernel is much faster than applying toric_ideal to the respective integer matrix. In virtually all cases that are not too small. A random example with 7 points in dimension 2:

A = [[9, 1], [3, 3], [9, 8], [5, 1], [7, 10], [5, 5], [1, 5]]
R, x = polynomial_ring(QQ, "x" => (1:7))
S, z = polynomial_ring(QQ, "z" => (1:2))
f = hom(R, S, [prod(z.^A[i]) for i in (1:7)])
I = kernel(f)

runs almost instantly but a subsequent call of toric_ideal(matrix(ZZ, A)) does not terminate after several minutes. And this happens for all randomly generated examples with the same or larger parameters. (AFAIK, these two calls should output the same ideal, and in small cases where both work fast this is indeed the case.)

This was tested in Oscar 1.3.0 and also in some of the older versions, probably not a recently introduced issue.

Thank you @imkhln for pointing this out to us. (Also, apologies for my slow response.)

@lkastner will work on improving the toric ideal computation along the lines you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants