Skip to content

Add checked Fp geometric inverse CDF support - #217

Merged
jmh530 merged 4 commits into
libmir:masterfrom
jmh530:codex/fp-geometric-inverse-audit
Oct 28, 2026
Merged

jmh530 merged 4 commits into
libmir:masterfrom
jmh530:codex/fp-geometric-inverse-audit

Conversation

@jmh530

@jmh530 jmh530 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Add geometricInvCDFChecked for Fp probabilities, returning a proven integer quantile or an explicit endpoint, count-limit, or precision-limit outcome. Searching rounded CDF values can select the wrong count near a jump even when the CDF is correctly rounded; the checked inverse instead compares outward-rounded intervals against the exact represented query.

Implementation

  • Bracket and binary-search integer counts using exact wide-integer products and outward-rounded fixed-point intervals.
  • Return a count only when comparisons prove it is the least nonnegative integer whose exact CDF reaches the query.
  • Preserve the existing inverse's endpoint precedence, including infinity for q == 1 even when p == 1.
  • Expose GeometricInverseResult and GeometricInverseStatus, with conditional count extraction through tryGetCount.
  • Export the API through the inverse-CDF convenience module while leaving the existing hardware-floating inverse unchanged.

Limits

The inclusive count limit defaults to size_t.max. countLimit proves that a finite quantile exceeds that limit; it does not mean infinity.

Comparisons use bits+128 fractional bits, then bits+512 when necessary. precisionLimit reports an unresolved comparison and supplies no approximate count. Tiny probabilities near small-count jumps can reach this limit even when the quantile fits the count budget.

Validation

  • Full LDC suite: 70 modules passed.
  • Focused DMD tests: 15 modules passed.
  • Optimized external-caller import and execution check passed.
  • DMD documentation build and whitespace checks passed.
  • Committed references cover exact-rational queries across Fp!64, Fp!128, and Fp!256, rounded-CDF counterexamples, and a large-count reference stabilized at 250 and 350 decimal digits.
  • An additional 432 exact-rational boundary cases exercised the public API: 379 correct counts and 53 explicit precision limits, with no incorrect returned counts.
  • Tests cover endpoint precedence, count-limit retries, precision exhaustion during bracketing and binary search, exponent-floor inputs, and invalid parameters.

Progress toward #157; this does not complete the broader Fp distribution work.

AI-Assisted-By: Codex (GPT-6 Astra Medium)

Use outward-rounded fixed-point intervals to prove inverse-CDF
comparisons at represented Fp probabilities. Bracket and search
integer counts without relying on rounded CDF values or hardware
logarithms, preserving full-width count arithmetic.

Return explicit outcomes for proven counts, endpoint conventions,
count limits, and unresolved precision. Preserve the existing
endpoint precedence and provide conditional count extraction.
Document the precision budget and handling of unresolved results.

Add exact-rational references across Fp!64, Fp!128, and Fp!256,
rounded-CDF counterexamples, and a stabilized large-count reference.
Cover count-limit retries, precision exhaustion during bracketing
and binary search, exponent-floor inputs, and parameter contracts.

AI-Assisted-By: Codex (GPT-6 Astra Medium)
Add geometricInvCDFChecked to the geometric distribution module
and export it through the inverse-CDF convenience module. Publish
the result and status types while retaining the bounded interval
search in the internal implementation.

Document the exact-count guarantee, endpoint precedence, inclusive
size_t count limit, and fixed working-precision budget. Distinguish
unresolved precision and finite counts beyond the limit from the
existing infinity convention.

Add public examples for conditional count extraction, count-limit
retries, and endpoint and precision outcomes. Test Fp widths,
parameter contracts, and compatibility with the existing hardware
floating-point inverse.

AI-Assisted-By: Codex (GPT-6 Astra Medium)
Import Fp inside both examples so extracted documentation tests
compile independently of the module-level imports.

AI-Assisted-By: Codex (GPT-6 Astra Medium)
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Handle zero only at the search entry point; all comparator probes
are positive. Remove the redundant branch and document that invariant.

AI-Assisted-By: Codex (GPT-6 Astra Medium)
@jmh530
jmh530 merged commit 392ff14 into libmir:master Oct 28, 2026
26 checks passed
@jmh530
jmh530 deleted the codex/fp-geometric-inverse-audit branch October 28, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant