Skip to content

Fix generic integer alignment#218

Open
orebas wants to merge 1 commit into
sumiya11:masterfrom
orebas:fix-generic-alignment
Open

Fix generic integer alignment#218
orebas wants to merge 1 commit into
sumiya11:masterfrom
orebas:fix-generic-alignment

Conversation

@orebas

@orebas orebas commented May 20, 2026

Copy link
Copy Markdown

Fixes align_up and align_down for non-power-of-two alignments.

The previous bit-mask implementation only works when the alignment is a power of two, but get_next_batch calls align_up(new_batch, composite * tasks). With non-power-of-two task counts, this can produce a batch size that is not divisible by composite * tasks, which can under-allocate task-local primes in the QQ learn-and-apply modular path.

Changes:

  • Use cld(x, n) * n and fld(x, n) * n for generic integer alignment.
  • Strengthen the learn-and-apply batch invariant to check divisibility by composite * tasks.
  • Add regression coverage for non-power-of-two alignments and get_next_batch across tasks=1:16.

Tested with:

  • env JULIA_NUM_THREADS=5 julia --project=. bioh_gb_input.jl
    • Groebner.groebner(polys) completed successfully.
    • The script still fails afterward at quotient_basis(gb) because the ideal is not zero-dimensional.
  • env JULIA_NUM_THREADS=5 julia --project=. -e 'using Pkg; Pkg.test(Groebner)'
    • 130033 / 130033 tests passed.

@orebas

orebas commented May 20, 2026

Copy link
Copy Markdown
Author

Full disclosure: the above PR, including the text, was authored by Codex. It was in response to a crash related to something I was trying, related to the biohydrogenation system. Below is an MWE for the crash.

Obviously, the coefficients are quite large, and you should know that the bug does not surface with "normal" sized coefficients.

I (human Oren) do not understand the bug or the fix.

# Auto-generated by SIAN.jl debug dump.
# Reproduces the Groebner.jl crash on a known polynomial system.
using Nemo
using Groebner
R, _gens = Nemo.polynomial_ring(Nemo.QQ, ["x5_6", "x4_5", "x6_5", "x5_5", "x4_4", "x6_4", "x5_4", "x4_3", "x6_3", "x5_3", "x4_2", "x6_2", "x5_2", "x4_1", "x6_1", "x5_1", "x4_0", "x6_0", "x5_0", "z_aux", "x7_0", "k7_0", "k8_0", "k5_0", "k6_0", "k10_0", "k9_0"], internal_ordering=:degrevlex)
x5_6 = _gens[1]
x4_5 = _gens[2]
x6_5 = _gens[3]
x5_5 = _gens[4]
x4_4 = _gens[5]
x6_4 = _gens[6]
x5_4 = _gens[7]
x4_3 = _gens[8]
x6_3 = _gens[9]
x5_3 = _gens[10]
x4_2 = _gens[11]
x6_2 = _gens[12]
x5_2 = _gens[13]
x4_1 = _gens[14]
x6_1 = _gens[15]
x5_1 = _gens[16]
x4_0 = _gens[17]
x6_0 = _gens[18]
x5_0 = _gens[19]
z_aux = _gens[20]
x7_0 = _gens[21]
k7_0 = _gens[22]
k8_0 = _gens[23]
k5_0 = _gens[24]
k6_0 = _gens[25]
k10_0 = _gens[26]
k9_0 = _gens[27]
polys = [
    -1//2*x5_0 + 4880317582101//2,
    x5_1*x4_0*x6_0 + x5_1*x4_0*x5_0 + 6//5*x4_0*x5_0*k7_0 + 4*x5_1*x4_0*k8_0 - 2*x4_0*x6_0*k5_0 - 2*x4_0*x5_0*k5_0 - 8*x4_0*k8_0*k5_0 + 1//2*x5_1*x6_0*k6_0 + 1//2*x5_1*x5_0*k6_0 + 3//5*x5_0*k7_0*k6_0 + 2*x5_1*k8_0*k6_0,
    -8*x4_0 + 48209756664984,
    x4_1*x4_0 + 1//8*x4_0*k5_0 + 1//2*x4_1*k6_0,
    -1//2*x5_1 + 409269058848616778870403845270905065864//139343436991344010402018855,
    x6_1*x5_1*x4_0 + x5_1^2*x4_0 + x4_1*x5_1*x6_0 + x5_2*x4_0*x6_0 + x4_1*x5_1*x5_0 + x5_2*x4_0*x5_0 + 6//5*x5_1*x4_0*k7_0 + 6//5*x4_1*x5_0*k7_0 + 4*x4_1*x5_1*k8_0 + 4*x5_2*x4_0*k8_0 - 2*x6_1*x4_0*k5_0 - 2*x5_1*x4_0*k5_0 - 2*x4_1*x6_0*k5_0 - 2*x4_1*x5_0*k5_0 - 8*x4_1*k8_0*k5_0 + 1//2*x6_1*x5_1*k6_0 + 1//2*x5_1^2*k6_0 + 1//2*x5_2*x6_0*k6_0 + 1//2*x5_2*x5_0*k6_0 + 3//5*x5_1*k7_0*k6_0 + 2*x5_2*k8_0*k6_0,
    -1//50*x6_0^3*k9_0 - 1//50*x6_0^2*x5_0*k9_0 - 2//25*x6_0^2*k8_0*k9_0 + 2//5*x6_0^2*k10_0*k9_0 + 2//5*x6_0*x5_0*k10_0*k9_0 + 8//5*x6_0*k8_0*k10_0*k9_0 + x6_1*x6_0*k10_0 + x6_1*x5_0*k10_0 - 6//5*x5_0*k7_0*k10_0 + 4*x6_1*k8_0*k10_0,
    -8*x4_1 - 9571718038817124789062058//3153548518895,
    x4_1^2 + x4_2*x4_0 + 1//8*x4_1*k5_0 + 1//2*x4_2*k6_0,
    -1//2*x5_2 - 14109439051198855840348304664214689218404962144636994102589272027671167182732218298215825325770424491//296644081162376242495579934551720237834765136332628598789242776870903991988500,
    2*x4_1*x6_1*x5_1 + 2*x4_1*x5_1^2 + 2*x5_2*x6_1*x4_0 + x6_2*x5_1*x4_0 + 3*x5_2*x5_1*x4_0 + 2*x5_2*x4_1*x6_0 + x4_2*x5_1*x6_0 + x5_3*x4_0*x6_0 + 2*x5_2*x4_1*x5_0 + x4_2*x5_1*x5_0 + x5_3*x4_0*x5_0 + 12//5*x4_1*x5_1*k7_0 + 6//5*x5_2*x4_0*k7_0 + 6//5*x4_2*x5_0*k7_0 + 8*x5_2*x4_1*k8_0 + 4*x4_2*x5_1*k8_0 + 4*x5_3*x4_0*k8_0 - 4*x4_1*x6_1*k5_0 - 4*x4_1*x5_1*k5_0 - 2*x6_2*x4_0*k5_0 - 2*x5_2*x4_0*k5_0 - 2*x4_2*x6_0*k5_0 - 2*x4_2*x5_0*k5_0 - 8*x4_2*k8_0*k5_0 + x5_2*x6_1*k6_0 + 1//2*x6_2*x5_1*k6_0 + 3//2*x5_2*x5_1*k6_0 + 1//2*x5_3*x6_0*k6_0 + 1//2*x5_3*x5_0*k6_0 + 3//5*x5_2*k7_0*k6_0 + 2*x5_3*k8_0*k6_0,
    -3//50*x6_1*x6_0^2*k9_0 - 1//50*x5_1*x6_0^2*k9_0 - 1//25*x6_1*x6_0*x5_0*k9_0 - 4//25*x6_1*x6_0*k8_0*k9_0 + 4//5*x6_1*x6_0*k10_0*k9_0 + 2//5*x5_1*x6_0*k10_0*k9_0 + 2//5*x6_1*x5_0*k10_0*k9_0 + 8//5*x6_1*k8_0*k10_0*k9_0 + x6_1^2*k10_0 + x6_1*x5_1*k10_0 + x6_2*x6_0*k10_0 + x6_2*x5_0*k10_0 - 6//5*x5_1*k7_0*k10_0 + 4*x6_2*k8_0*k10_0,
    -8*x4_2 + 1067558617771569924924858188627476568797421941089//125446498300643216830676606270199069500,
    3*x4_2*x4_1 + x4_3*x4_0 + 1//8*x4_2*k5_0 + 1//2*x4_3*k6_0,
    -1//2*x5_3 + 76860065858484697565538594401685742970632511075807575133062105342768323475594626255438481081350600478195426200413915431990750392614514349630954149451187550061968291//1263033448703247727210485540573994528137545331491467517231722724931844496613846599740786088673792850727889057472356526317929900000,
    6*x5_2*x4_1*x6_1 + 3*x6_2*x4_1*x5_1 + 9*x5_2*x4_1*x5_1 + 3*x4_2*x6_1*x5_1 + 3*x4_2*x5_1^2 + 3*x6_2*x5_2*x4_0 + 3*x5_2^2*x4_0 + 3*x5_3*x6_1*x4_0 + x6_3*x5_1*x4_0 + 4*x5_3*x5_1*x4_0 + 3*x4_2*x5_2*x6_0 + 3*x5_3*x4_1*x6_0 + x4_3*x5_1*x6_0 + x5_4*x4_0*x6_0 + 3*x4_2*x5_2*x5_0 + 3*x5_3*x4_1*x5_0 + x4_3*x5_1*x5_0 + x5_4*x4_0*x5_0 + 18//5*x5_2*x4_1*k7_0 + 18//5*x4_2*x5_1*k7_0 + 6//5*x5_3*x4_0*k7_0 + 6//5*x4_3*x5_0*k7_0 + 12*x4_2*x5_2*k8_0 + 12*x5_3*x4_1*k8_0 + 4*x4_3*x5_1*k8_0 + 4*x5_4*x4_0*k8_0 - 6*x6_2*x4_1*k5_0 - 6*x5_2*x4_1*k5_0 - 6*x4_2*x6_1*k5_0 - 6*x4_2*x5_1*k5_0 - 2*x6_3*x4_0*k5_0 - 2*x5_3*x4_0*k5_0 - 2*x4_3*x6_0*k5_0 - 2*x4_3*x5_0*k5_0 - 8*x4_3*k8_0*k5_0 + 3//2*x6_2*x5_2*k6_0 + 3//2*x5_2^2*k6_0 + 3//2*x5_3*x6_1*k6_0 + 1//2*x6_3*x5_1*k6_0 + 2*x5_3*x5_1*k6_0 + 1//2*x5_4*x6_0*k6_0 + 1//2*x5_4*x5_0*k6_0 + 3//5*x5_3*k7_0*k6_0 + 2*x5_4*k8_0*k6_0,
    -3//25*x6_1^2*x6_0*k9_0 - 2//25*x6_1*x5_1*x6_0*k9_0 - 3//50*x6_2*x6_0^2*k9_0 - 1//50*x5_2*x6_0^2*k9_0 - 1//25*x6_1^2*x5_0*k9_0 - 1//25*x6_2*x6_0*x5_0*k9_0 - 4//25*x6_1^2*k8_0*k9_0 - 4//25*x6_2*x6_0*k8_0*k9_0 + 4//5*x6_1^2*k10_0*k9_0 + 4//5*x6_1*x5_1*k10_0*k9_0 + 4//5*x6_2*x6_0*k10_0*k9_0 + 2//5*x5_2*x6_0*k10_0*k9_0 + 2//5*x6_2*x5_0*k10_0*k9_0 + 8//5*x6_2*k8_0*k10_0*k9_0 + 3*x6_2*x6_1*k10_0 + x5_2*x6_1*k10_0 + 2*x6_2*x5_1*k10_0 + x6_3*x6_0*k10_0 + x6_3*x5_0*k10_0 - 6//5*x5_2*k7_0*k10_0 + 4*x6_3*k8_0*k10_0,
    -1//2*x5_4 + 458517882177903101734911209679018539720563875942963292559534235940453039898464983758817502664647658986541476729730857910488865875026283108160501417089527218191613388035239018644457403026774774508866737592147738230259213229233659//5377668370433502512763376950632568048908562294677487800726728501765858310627819949544983880681369093335742371482553514001380843845033733262655011282018075023618858888820922260000000,
    12*x6_2*x5_2*x4_1 + 12*x5_2^2*x4_1 + 12*x4_2*x5_2*x6_1 + 12*x5_3*x4_1*x6_1 + 6*x4_2*x6_2*x5_1 + 18*x4_2*x5_2*x5_1 +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6_1*x6_0*k9_0 - 3//25*x5_2*x6_1*x6_0*k9_0 - 3//25*x6_2*x5_1*x6_0*k9_0 - 3//50*x6_3*x6_0^2*k9_0 - 1//50*x5_3*x6_0^2*k9_0 - 3//25*x6_2*x6_1*x5_0*k9_0 - 1//25*x6_3*x6_0*x5_0*k9_0 - 12//25*x6_2*x6_1*k8_0*k9_0 - 4//25*x6_3*x6_0*k8_0*k9_0 + 12//5*x6_2*x6_1*k10_0*k9_0 + 6//5*x5_2*x6_1*k10_0*k9_0 + 6//5*x6_2*x5_1*k10_0*k9_0 + 4//5*x6_3*x6_0*k10_0*k9_0 + 2//5*x5_3*x6_0*k10_0*k9_0 + 2//5*x6_3*x5_0*k10_0*k9_0 + 8//5*x6_3*k8_0*k10_0*k9_0 + 3*x6_2^2*k10_0 + 3*x6_2*x5_2*k10_0 + 4*x6_3*x6_1*k10_0 + x5_3*x6_1*k10_0 + 3*x6_3*x5_1*k10_0 + x6_4*x6_0*k10_0 + x6_4*x5_0*k10_0 - 6//5*x5_3*k7_0*k10_0 + 4*x6_4*k8_0*k10_0,
    3*x4_2^2 + 4*x4_3*x4_1 + x4_4*x4_0 + 1//8*x4_3*k5_0 + 1//2*x4_4*k6_0,
    -1//2*x5_5 - 16833291222626600472603619967528380140452113264737492134924964543344289615746421901717382613649373770123335965489900463600074811383984685379818086376751427214884915315245982868073003974938292733436976933545778056421728289828557475442243741312430873962527919992839884125636830777696160934581303//22896715151963940317904916950005900142918955616837872456357564722884774008732038288190372338556653439703735877099500023409448859630678957778713155628103132343460897190557158489427552874663266340017274281333688573940905998124000000000,
    30*x4_2*x6_2*x5_2 + 30*x4_2*x5_2^2 + 30*x5_3*x6_2*x4_1 + 20*x6_3*x5_2*x4_1 + 50*x5_3*x5_2*x4_1 + 30*x5_3*x4_2*x6_1 + 20*x4_3*x5_2*x6_1 + 20*x5_4*x4_1*x6_1 + 10*x6_3*x4_2*x5_1 + 40*x5_3*x4_2*x5_1 + 10*x4_3*x6_2*x5_1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*k6_0,
    -1//2*x5_6 + 2230503213357701357569440907020643973817630698962549348350662729250655449889457673354642280874096489436871587946168655140601401023983404657196226995727560762555964180378041950055367740709808674027261529388384365684009605417002804896233524786236476486842524943013818922830610735730276765570285347120647310652522598122337977161210397249911331395200124487341//3899530641439785758106519031248013429963970214268438235464842731697783528278382630958690014928873154952997481236688863273797382818503720654802833380324793230775125296123999524196161696690367099759313565375256537591412364714890538418076245936124157609372547934041419239011104000000000,
    -8*x4_3 + 9980234898521577864742474945154512255354536124394581060218071638161101613//9980391195254194232908371166727274297961010400800055115489900000,
    -8*x4_4 + 27529340855090325099548923027554684493195513387169307058417215755254308156622223797175741718380427//158805881008472455249978402662551270575313740548855540004693911882975830493225560236000000,
    -8*x4_5 + 499556367342470625025569534582373295139636271001372606136834196241995586886722399915140375746394973158165846793893016126211//12634428525641971425260015905982407389975487650780450039277308668489330286084916530481745199901284447967695200000000,
    x4_0*x6_0*z_aux*k10_0 + x4_0*x5_0*z_aux*k10_0 + 4*x4_0*z_aux*k8_0*k10_0 + 1//2*x6_0*z_aux*k6_0*k10_0 + 1//2*x5_0*z_aux*k6_0*k10_0 + 2*z_aux*k8_0*k6_0*k10_0 - 1,
]

println("Versions: Julia ", VERSION, " Nemo ", pkgversion(Nemo), " Groebner ", pkgversion(Groebner))
println("System: ", length(polys), " polys, ", length(_gens), " vars")
println("Calling Groebner.groebner...")
gb = Groebner.groebner(polys)
println("  ✓ Got GB with ", length(gb), " elements")
println("  quotient_basis dim = ", length(Groebner.quotient_basis(gb)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant