Skip to content

beta(a, b) and norm(v, p) - #2486

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
feature/beta-and-norm
Nov 16, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
feature/beta-and-norm

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

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) and norm(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: beta alone, beta (x) with a space, and beta(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); SymPy sympy.beta(a, b); compiled through CombinatorialFunctions.Beta (MathS.Shaders declines it, as it declines x!).

input 2.7.0 now
beta(2, 3) parse error 1/12
beta(1/2, 1/2) parse error pi
beta(2.5, 1.3), .Evaled parse error 0.25415419017646049453…, as mpmath
beta(1, b) parse error 1 / b
beta(2, -3) parse error 1/6
beta(0, 1/2) parse error NaN

Exact 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) and beta(a, b) simplify to the same node.

Poles: NaN where a or b is a non-positive whole number and a + b is not, and where both are. Where a + b is 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 of b regular there: beta(2, -3) is 1/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 in b with the whole argument held fixed. Where only a + b is a pole, the value is 0. The domain condition encodes all of it.

norm(v, p)

The p-norm, (Σ|vᵢ|^p)^(1/p), p = +oo the largest modulus. norm(v, 2) is built as abs(v) itself (#2431). LaTeX \left\| v \right\|_{p}.

input 2.7.0 now
norm([3, 4], 1) / 3 / +oo / 2 parse error 7 / 91 ^ (1/3) / 4 / 5
norm([x, y], p) parse error norm([x, y], p), with the condition p >= 1
norm(v, 1/2), norm([[1, 2], [3, 4]], 2) parse error refused at parse time, with a message
norm([3, 4]) [3 * norm, 4 * norm] unchanged (#1019)

A numeric p must be real and at least 1, or +oo; a symbolic p keeps the node and gives NaN once a p below 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 by Binders.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 read beta(a, b) and norm(v, p) as calls (Parsing.IsFunctionOfSeveralArguments), so beta(a, b) + norm(v, 3) gets no unknown-name warning while beta(z) still does.

BetaTest and NormTest, 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; norm against hand computation and abs.

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

Rafael-SOWNet and others added 2 commits November 16, 2026 09:29
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>
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.05463% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.92%. Comparing base (413e8fc) to head (980e6bf).

Files with missing lines Patch % Lines
.../AngouriMath/Core/Entity/Continuous/Number/Beta.cs 81.25% 5 Missing and 7 partials ⚠️
...ources/AngouriMath/Core/Antlr/AngouriMathParser.cs 99.33% 2 Missing and 1 partial ⚠️
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 92.85% 0 Missing and 3 partials ⚠️
...ntity/Continuous/Entity.Continuous.Norm.Classes.cs 66.66% 2 Missing ⚠️
Sources/AngouriMath/Core/Parser.cs 91.30% 1 Missing and 1 partial ⚠️
...nuous/Solvers/EquationSolver/InvertNode.Classes.cs 0.00% 2 Missing ⚠️
Sources/AngouriMath/Core/Antlr/ParsingHelpers.cs 90.00% 0 Missing and 1 partial ⚠️
...AngouriMath/Functions/TreeAnalyzer/Sort.Classes.cs 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2486      +/-   ##
==========================================
+ Coverage   86.90%   86.92%   +0.02%     
==========================================
  Files         328      331       +3     
  Lines       72957    73194     +237     
  Branches    21262    21325      +63     
==========================================
+ Hits        63400    63625     +225     
- Misses       5145     5148       +3     
- Partials     4412     4421       +9     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.44% <96.05%> (+0.02%) ⬆️
fsharp 32.79% <ø> (ø)
interactive 39.95% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/AngouriMath/Convenience/MathS.cs 91.52% <100.00%> (+0.04%) ⬆️
Sources/AngouriMath/Core/Antlr/AngouriMathLexer.cs 99.28% <ø> (+<0.01%) ⬆️
Sources/AngouriMath/Core/Domains.Classes.cs 100.00% <100.00%> (ø)
...ntity/Continuous/Entity.Continuous.Beta.Classes.cs 100.00% <100.00%> (ø)
...Math/Core/Transformations/Matching/MatchPattern.cs 86.62% <100.00%> (+0.05%) ⬆️
...urces/AngouriMath/Functions/Compilation/Binders.cs 95.91% <100.00%> (+0.26%) ⬆️
...gouriMath/Functions/Compilation/IntoFE/Compiler.cs 87.08% <100.00%> (+0.39%) ⬆️
...ath/Functions/Compilation/IntoFE/FastExpression.cs 96.87% <100.00%> (+0.03%) ⬆️
...ctions/Compilation/IntoLinq/CompilationProtocol.cs 94.77% <100.00%> (+0.02%) ⬆️
...h/Functions/Compilation/IntoLinq/MathAllMethods.cs 76.47% <100.00%> (+0.23%) ⬆️
... and 15 more

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

A register of function names, by what a mathematician calls each

1 participant