Repository navigation
beta(a, b) and norm(v, p) - #2486
Merged
Merged
Conversation
beta(a, b) and norm(v, p) were parse errors, and are now Entity.Betaf and Entity.Normf, built by
MathS.Beta and MathS.Norm. With one argument each is still what it was, beta(x) the product beta * x
and norm([3, 4]) the product norm * [3, 4]: the parser hands a call without a second argument back as
the name and a bracket, so it binds as before, norm(x)^2 being norm * x ^ 2. beta alone and beta (x)
with a space are as gamma's are.
The beta function is Gamma(a) Gamma(b)/Gamma(a + b), DLMF 5.12.1. It is exact at a whole argument,
(n - 1)!/(b (b + 1) ... (b + n - 1)), so beta(1, b) is 1/b, and at two half-whole ones, a rational times
pi. It has no value where a or b is 0, -1, -2, ..., unless a + b is one too: the other argument is then
whole and the value is the rational function's, beta(2, -3) = 1/6, the limit along a whole n, as
mpmath's beta takes it. Where only a + b is one it is 0. Elsewhere it is the ratio of the library's
gamma functions at the working precision, real or complex, taken with sixteen more digits and no
bound on the exponent, so B(100.5, 100.25) is 1.3e-61 where each gamma is past 1e156. It agrees with
mpmath to 1e-58 at ten points, negative, complex and large among them, and with the gamma ratio to
1e-195 at 200 digits. Its arguments are put in one order, beta(b, a) simplifying to the node beta(a, b),
and its derivative is B(a, b)(psi(a) - psi(a + b)) in a. It draws as \operatorname{B}, exports to
sympy.beta, and compiles in both compilers, through a double-precision ratio of gammas taken through
their logarithms past the doubles; MathS.Shaders declines it, as it does x!.
The norm is (|v_1|^p + ... + |v_n|^p)^(1/p) for a real p >= 1 and the largest modulus at p = +oo, taken
when simplified of a vector written out, a column or a row, real or complex; norm(v, 2) is computed as
abs(v), the same expression. A p that is a number below 1, where there is no norm, or off the real line,
and a matrix written out that is not a vector, are refused when parsed; a symbolic p stays as written
with the condition p >= 1, and is NaN below 1 once given. It draws as \left\| v \right\|_{p} and
exports to the SymPy matrix's norm. The node left where the vector is not written out has no compiled
form, and Binders.Refusal says to simplify first.
Part of #2182.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its check of whether a name is a function parses name(x), which for beta and norm is still the product it was, so beta(a, b) was warned about as a variable times a bracket. A call with a comma at its own depth is now asked of name(x, y), which no product parses, and beta(z) is still warned about. Part of #2182. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 16, 2026
Open
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.
The last two rows of #2182's register, decided for 2.8 (each a parse error before, so adding it changes nothing that parses):
beta(a, b)andnorm(v, p). Two commits, meant to be merged as they are (rebase, not squash).beta(a, b)The Beta function, B(a, b) = Γ(a)Γ(b)/Γ(a + b) (DLMF 5.12), read like
gamma:betaalone,beta (x)with a space, andbeta(x)with one argument stay the products they were, as the decided comment puts one-argument forms on #1019. LaTeX\operatorname{B}\left(a, b\right); SymPysympy.beta(a, b); compiled throughCombinatorialFunctions.Beta(MathS.Shaders declines it, as it declinesx!).beta(2, 3)1/12beta(1/2, 1/2)pibeta(2.5, 1.3),.Evaledbeta(1, b)1 / bbeta(2, -3)1/6beta(0, 1/2)NaNExact at a whole argument (for any rational other) and at two half-whole ones; numerically the ratio of the library's gamma with 16 extra digits and no exponent bound (B(1e5, 1e5) was NaN and B(100.5, 100.25) flushed to 0 without that). The arguments are put in one canonical order, so
beta(b, a)andbeta(a, b)simplify to the same node.Poles:
NaNwhereaorbis a non-positive whole number anda + bis not, and where both are. Wherea + bis one too, the other argument is a whole n ≥ 1, and the value is that of B(n, b) = Γ(n)/(b(b+1)…(b+n−1)), a rational function ofbregular there:beta(2, -3)is1/6,beta(1, -1)is-1, as mpmath gives. It keeps B(1, b) = 1/b wherever either side has a value. As a function of both arguments together the limit at such a point depends on the direction of approach; the value is the continuation inbwith the whole argument held fixed. Where onlya + bis a pole, the value is 0. The domain condition encodes all of it.norm(v, p)The p-norm, (Σ|vᵢ|^p)^(1/p),
p = +oothe largest modulus.norm(v, 2)is built asabs(v)itself (#2431). LaTeX\left\| v \right\|_{p}.norm([3, 4], 1)/3/+oo/27/91 ^ (1/3)/4/5norm([x, y], p)norm([x, y], p), with the conditionp >= 1norm(v, 1/2),norm([[1, 2], [3, 4]], 2)norm([3, 4])[3 * norm, 4 * norm]A numeric
pmust be real and at least 1, or+oo; a symbolicpkeeps the node and givesNaNonce apbelow 1 is put in. Row and column vectors both work, complex entries are taken by modulus, a number is its own modulus. A matrix that is not a vector is refused. A node left unevaluated is refused byBinders.Refusal("simplify first"), so Compile and Shaders decline it with one message.Records and checks
BREAKING-CHANGES.md, measured on the 2.7.0 package. The grammar gains two rules; master's grammar was regenerated unchanged first and matched byte for byte. The second commit makes the MCP server readbeta(a, b)andnorm(v, p)as calls (Parsing.IsFunctionOfSeveralArguments), sobeta(a, b) + norm(v, 3)gets no unknown-name warning whilebeta(z)still does.BetaTestandNormTest, 114 cases: mpmath at 80 digits for real, negative, complex and large arguments; the gamma ratio at 200 digits; exact values, poles, the domain condition, symmetry, the derivative against a central difference, the limit between poles; compiled results against evaluation at 17×17 points;normagainst hand computation andabs.Full check on the first commit: 21,019 unit tests, 0 failed; Terminal 69, F# 135, Interactive 19; AOT OK; BoundCheck 0 disagreements, RootCheck 596/596, CasBench 120/121 with 0 wrong, SimpSweep 10463/10463, RuleCheck clean, CanonCheck, Confluence and the Modenov corpus at their baselines. MCP failed 2 there (the one-argument probe of every grammar function); fixed by the second commit, after which MCP: 459 passed.
Closes #2182.
🤖 Generated with Claude Code