Repository navigation
Upper incomplete gamma for s < -1 at small x; exact square roots of negative integers over integers - #447
Closed
enumeratio wants to merge 1 commit into
Closed
Upper incomplete gamma for s < -1 at small x; exact square roots of negative integers over integers#447enumeratio wants to merge 1 commit into
enumeratio wants to merge 1 commit into
Conversation
…ith DLMF 8.8.2, and the compiled JavaScript Gamma(s, z) that dropped z; build exact pure-imaginary values for negative integer radicals so Sqrt(-13)/3 is not NaN. Fix cortex-js#446
This was referenced Oct 16, 2026
enumeratio
added a commit
to enumeratio/enumeratio
that referenced
this pull request
Oct 16, 2026
Every engine we ship or evaluate examples on now sets compute-engine's `ce.roundingTies = "to-even"` (option since 0.149, cortex-js/compute-engine#417), so `Round(5/2)` is 2 and `Round(-2.5)` is -2, as in Wolfram, SymPy, mpmath, Sage and Julia. CE's own default is untouched. ## Where it is set One function, `setEngineDefaults(ce)` in `@enumeratio/engine`, called from: - `declareEvaluation` (the base library): covers every worker, session/kernel engine, and every planned engine (census `fullEngine`, reference `declaredEngine` and the isolated evaluator's `configure`) - the frontend engine (lazy import, so the page chunk stays engine-free), the CLI `Session`, the site prerender engine, the forms collector - `createEngine` / `createLatexEngine` in `@enumeratio/engine/testing` (not `bareEngine`) Bare engines that snapshot CE's own bindings (census/manifest scripts, ce-patches landed checks, oracle comparison engines) are left as they are. The CLI and web packages gain a workspace dependency on `@enumeratio/engine`. ## Changed rows (Round) Each is a tie; the new value is Wolfram's. Three ids that said the opposite are renamed (no alias): `rounds-half-away-from-zero-not-banker-s-rounding` to `rounds-half-to-even`, `and-by-the-same-convention-2-5-rounds-to-3-not-2` to `minus-2-5-rounds-to-minus-2`, `an-exact-half-rounds-away-from-zero-as-well` to `an-exact-half-rounds-to-even`; the sidecars moved with them. Rows below are listed by their new ids. | row | old | new | | --- | --- | --- | | `round-neg-1-over-2-exact-tie` | -1 | 0 | | `rounds-half-to-even` | 3 | 2 | | `minus-2-5-rounds-to-minus-2` | -3 | -2 | | `round-5-over-2-exact-rational-tie` | 3 | 2 | | `an-exact-half-rounds-to-even` | 1 | 0 | Captions and `index.md` prose now say ties go to even. The `rounding-mode` classification is dropped for Wolfram, Sage, SymPy, mpmath and Julia, whose rows now agree (rescanned: wolfram, sage, sympy, mpmath, julia). Rust's `round` goes away from zero, so those rows are now classified `rounding-mode` for Rust only. No other `known` was touched. The other Round rows (7/2, 3.5, the list row, 19.995 at step 1/100, ...) are unchanged. No other examples.tsv row depends on tie rounding. Also updated: the Ceil and Floor notes, and the site's Wolfram source-output row for `Round(2.5)`, which claimed a divergence. ## Two-argument Gamma compile `Gamma(s, x)` with a symbolic `x` compiled (JS target) to `_SYS.gamma(2, _.x + 1)`, which drops x (cortex-js/compute-engine#447). `declareAnalytic` now lets `Gamma` compile with one operand only, so the two-operand call falls back to the interpreter; a test checks compiled `Gamma` and `GammaRegularized` either decline or match evaluate. `GammaRegularized` compiled correctly and is unchanged. Lift the guard (the `1` in the `Gamma` row of the loop in `declare.ts`) with the CE bump that carries #447. Nothing else in the repo lowers two-argument Gamma (ce-patches WGSL, frontend `complex-eval`, the combinatorics compile scripts and the bench catalogue use only the one-argument form).
Member
|
Landed on main as 38e5d18 with the dual-review fixes: the shift loop is capped at order 4096 and returns Infinity on overflow; two-operand Gamma is a complex-continuation head so the compiled lane agrees with .N() for a real z < 0; 1 − eᵗ is recognized by the new exponential-divisor pole family. Thank you. |
arnog
added a commit
that referenced
this pull request
Oct 17, 2026
…al-divisor poles Lands PR #447 by enumeratio with review fixes, plus one maintainer fix found while reviewing PR #445. - Gamma(s, z) for a non-integer s < −1 and z < 1: start from Γ(s+n, z) with −1 < s+n < 0 and apply DLMF 8.8.2 n times (the Legendre fraction did not converge there; Gamma(-1.5, 0.001) was off by 1.2e-5). The shift is capped at order 4096 and an overflow returns Infinity. Measured against mpmath: relative error below 4e-14 over 132 points. - Compiled Gamma(s, z) keeps its second operand (it compiled as Γ(s)), and is a complex-continuation head: a real z < 0 takes the complex kernel unless s is a positive integer, as .N() does. The interval target declines the two-operand form. - Sqrt(-13)/3 is (√13/3)i, not NaN: a negative integer radical builds the exact pure-imaginary value in _numericValue. Sqrt(-13)/Sqrt(-3) is √39/3, not −√39/3. - Interior-pole detection knows an exponential divisor k·bᵘ + c with u linear (eˣ − 1, 1 − eˣ, 2ᵗ − 8): ∫₋₁¹ eˣ/(eˣ − 1) dx is Indeterminate, where it evaluated to 1. The free-symbol scan still lets an assumption decide 1/(eᵗ − a). New ROADMAP entry: an integer coefficient times √(−c) stays a product, and √(−c) with c ≥ 10⁶ keeps its square factors (correct, unreduced).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #446.
Gamma(s, x)for a non-integers < -1andx < 1. The Legendre continued fraction does not converge in its cap there, and the error grew asxshrank:Gamma(-1.5, 0.001)was21020.691761…where mpmath has21020.937167…(1.2e-5), andGamma(-1.5, 1e-6)was off by 4.2e-5. We now start fromΓ(s+n, x)with-1 < s+n < 0and applyΓ(a-1, x) = (Γ(a, x) - x^{a-1}e^{-x})/(a-1)(DLMF 8.8.2)ntimes; atx < 1the subtracted term dominates, so nothing cancels. Within 0.05 of a pole ofΓ(s+n)the baseΓ(a) - γ(a, x)cancels, so the real kernel defers to the complex kernel there. Measured against mpmath, the relative error is below 3e-15 on s in {-0.5, -1.5, -2.5, -3.5} by x in {1e-6, 1e-3, 1e-2, 0.1, 1}, and below 5e-14 ons = -(k+f)with k up to 12, 0.001 <= f <= 0.999 and 1e-10 <= x < 1. There is no bignum kernel for this head, soce.precisiondoes not change the result.The compiled JavaScript lane had a separate bug:
Gamma(x, y)compiled to_SYS.gamma(x)and droppedy(Gamma(-1.5, 0.001)ran as2.3633). It now calls the upper incomplete gamma, with the complex kernel for a complex operand. The interval target declines the two-operand form, as the GPU targets do.Sqrt(-13)/3and its relatives. A negative integer radical went to the float lane, which tookMath.sqrt(-13).Sqrt(-13)/3,Sqrt(-2)/3,Sqrt(-13)/2,Sqrt(-13)/3.0andSqrt(-13)*Rational(1,3)wereNaN, and so wasArcosh(Sqrt(-13)/3)._numericValuenow builds the exact pure-imaginary value√c·ifor a radical-c, so canonicalization,evaluate()and.N()agree:Sqrt(-13)/3is(√13/3)iandArcosh(Sqrt(-13)/3)is1.0171572086841316 + 1.5707963267948966i. While there,Sqrt(-13)/Sqrt(-3)was-√39/3; it is√39/3.