Repository navigation
math: fixing liquid_MarcumQf() returning values outside [0,1] - #470
Open
cthornDSP14 wants to merge 1 commit into
Open
cthornDSP14 wants to merge 1 commit into
cthornDSP14 wants to merge 1 commit into
Conversation
cthornDSP14
force-pushed
the
fix-marcumq
branch
from
November 14, 2026 00:34
d5b0474 to
5022669
Compare
* previous erfc() approximation returned values outside [0,1] (e.g. Q_1(1,2) returned 1.0 instead of 0.269) * compute as Poisson-weighted mixture of central chi-square terms, evaluated in the log domain to avoid overflow for large arguments; stop once a bound on the remaining Poisson tail is negligible relative to the sum * validate input (M >= 1, alpha and beta non-negative and not NaN); limit alpha to 1000 to bound run time, as the number of terms grows as alpha^2 * Q_M(a,inf) = 0 * enables MarcumQf autotest checks; adds higher-order, large-argument, alpha-limit, and special-case checks, plus invalid-input checks in math_config
cthornDSP14
force-pushed
the
fix-marcumq
branch
from
November 14, 2026 01:08
5022669 to
3290cf4
Compare
cthornDSP14
marked this pull request as ready for review
November 14, 2026 01:23
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.
Problem
liquid_MarcumQf()uses anerfc()approximation. This can return valuesanywhere in [0, 2]. The Marcum Q function returns a probability, so this is a problem.
Solution
Q_M(a,b)is the probability that a non-central chi-square variable with2M degrees of freedom and non-centrality a² exceeds b². This fix computes it
as a Poisson-weighted mixture of central chi-square tail probabilities:
with λ = a²/2 and x = b²/2.
Q_M(a,0) = 1, andQ_M(0,b)usesits closed form.
alphais limited to 1000 (about 57 dB SNR) to bound run time (~0.2 s);the number of terms grows as alpha².
Q_M(a,inf) = 0.Tests
MarcumQfchecks.Related Issues
liquid_MarcumQ1f()returnsinf/NaNfor larger arguments, e.g.liquid_MarcumQ1f(10, 9)returnsinf.liquid_lnbesselif()overflows toinffor z above ~90.