Skip to content

The bigint compile mode lowers Floor(a/b) of two integers, a flattened (a - Mod(a, c))/c, Floor of an integer and (-1)^j - #677

Closed
enumeratio wants to merge 1 commit into
cortex-js:mainfrom
enumeratio:bigint-integer-division
Closed

enumeratio wants to merge 1 commit into
cortex-js:mainfrom
enumeratio:bigint-integer-division

Conversation

@enumeratio

Copy link
Copy Markdown
Contributor

In mode: 'bigint':

  • Floor(a/b) of two integers with a run-time b lowers to floordiv.int
    (bfloorDiv): floor division, so Floor(-7/2) is -4; b = 0 is the same
    pole as Mod.
  • flooredQuotient() takes any Add with one Negate(Mod(m, c)) term whose
    other terms sum to m, so the flattened (x - 1 - Mod(x - 1, 2))/2 is the
    floor division of x - 1 by 2.
  • Floor, Ceil, Round and Truncate of an integer lower to the integer
    (the canonical Floor(2n/2) is Floor(n), which threw).
  • (-1)^j of an integer j lowers to 1 - 2 Mod(j, 2), also for j < 0;
    Power(1, j) is already 1.

Power(2, n) and Power(3, l - m) with integer exponents still decline
(rational at a negative exponent). Ceil, Round and Truncate of a/b
with a run-time b still decline.

Tests in test/compute-engine/ir-bigint.test.ts: each form against evaluate()
on a grid with negative values and b = ±1, past 2^53, with and without
folding; the zero divisor; the declines (Power(2, n), Power(3, n - m),
Ceil(a/b), Floor of a real, a remainder of another dividend).

Fixes #676

@enumeratio
enumeratio force-pushed the bigint-integer-division branch from 662f92b to 974faf4 Compare December 3, 2026 00:27
arnog added a commit that referenced this pull request Dec 3, 2026
… a flattened (a - Mod(a, c))/c, Floor of an integer and (-1)^j; PolyLog(s, 1) is Zeta(s) only for Re s > 1

- #677 (#676): in the bigint compile mode, Floor(a/b) of two integers is
  the floor division; (a - Mod(a, c))/c is recognized when the canonical
  form flattens a sum a around the Mod term; Floor, Ceil, Round and
  Truncate of an integer are the integer; (-1)^j of an integer j is
  1 - 2 Mod(j, 2). Power(2, n) still declines.
- #681 (#680): PolyLog(s, 1) is Zeta(s) for Re s > 1 and a complex
  infinity for Re s < 1, in the interpreter, the numeric kernel and the
  GLSL helpers. A symbolic order not known to exceed 1 stays unevaluated.

Review fixes: on Re s = 1, s != 1, PolyLog(s, 1) is bounded with no limit,
so it stays unevaluated (NaN in compiled code) instead of a complex
infinity; a real order is compared with 1 exactly, not as a double; a
complex order with Re s < 1 gives the unsigned pole in compiled
JavaScript; the GLSL LerchPhi helper tests z = 1 before its route through
PolyLog, so LerchPhi(1, s, 1) keeps the value Zeta(s); flooredQuotient
lowers the dividend of the Mod, a node of the program; the unreachable
z = 1 branches of polylogIntegerOrderComplex are removed.

Co-authored-by: enumeratio <314378874+enumeratio@users.noreply.github.com>
@arnog

arnog commented Dec 3, 2026

Copy link
Copy Markdown
Member

Landed in adae37a. Thank you.

@arnog arnog closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

mode: 'bigint' declines or throws on Floor(a/b), a flattened (a - Mod(a, c))/c, Floor of an integer and (-1)^j

2 participants