Files
stack/lean/Pay
kert a15bccb8c5
Some checks failed
CI / lint (push) Failing after 53s
CI / notebooks-smoke (push) Successful in 2m12s
Deploy / changes (push) Successful in 18s
CI / test (push) Successful in 4m54s
Infra CI / docs (push) Successful in 23s
Infra CI / api (push) Successful in 1m13s
Infra CI / bcda (push) Successful in 1m59s
Infra CI / notebooks (push) Successful in 1m19s
Infra CI / zotero (push) Successful in 17s
Infra CI / llm (push) Successful in 1m0s
Infra CI / mc (push) Successful in 22s
Package Supply Chain / pkg-supply-chain (push) Successful in 3m9s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Lean Pay / pay (push) Successful in 3m33s
Deploy / api (push) Successful in 1m32s
Deploy / bcda (push) Successful in 1m51s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 1m9s
Deploy / report (push) Successful in 15s
feat(pay): fence every payment input the formulas can take
src/pay/bounds.json records each numeric rule field, the Lean
constants, and the per-period min and max from the replica.
allows() rejects proposed NPRM numbers, unstated nulls, a missing
wage index, and a calculated fee. A new numeric field fails the
test until the snapshot is rebuilt.
2026-11-17 16:00:44 -05:00
..

Pay

Lean 4 ceilings for the Medicare payment formulas this repo already computes. Python joins the CMS files. These definitions are the exact rational values those calculations have to meet.

Toolchain leanprover/lean4:v4.34.0, the same pin as the vendored Mathematics in Lean textbook. Mathlib is required at v4.34.0. Pay/Basic.lean checks the rational identities with norm_num and ring. pay-cases imports only the definitions, so printing the cases does not link mathlib.

What is a formula

Method Ceiling Where Python computes it
PFS fee schedule pfsPayment pfs.calcs.payment.payment
Non-PAR limiting charge limitingCharge pfs.calcs.payment.limiting_charge
OPPS wage adjustment oppsAdjusted opps.calcs.payment.payment
Part B drug limit aspPaymentLimit opps.express.payment.skin_sub_impact (ASP × 1.06)
Equipment cost / minute equipmentCostPerMinute pfs.calcs.payment.equipment_cost_per_use
MPPR on later PE ranks mpprPe pfs.calcs.payment.mppr_reduction
QPP year offset paymentYear qpp (payment_year = performance_year + 2)
REACH quality earn-back reachEarnBack Documented on the REACH quality table; CMS publishes the column

A missing OPPS wage index is 1. oppsAdjusted_wageIndex_one says the labor share then cancels.

What is not a formula here

ceiling records the rest.

  • MSSP and REACH settlements are the published CMS tables under src/aco. There is no shared-savings function to put a maximum on.
  • IPPS has no pricer in this repo.
  • LEAD in this repo is the review application (src/lead), not a payment model. No LEAD pricer is invented here.
  • QPP thresholds stay in src/qpp, cited to the Federal Register. Only the two-year offset is a formula in this slice.

Bounds

src/pay/bounds.json is the fence for a later search. Published constants (a year's conversion factor, ASP + 6%, the limiting-charge factor, the 60% labor share, the two-year QPP offset) are points, not knobs. Observed rows are the per-period minimum and maximum in the replica for the columns the formulas read. A global span is not stored. The free knobs are a tag confidence in [0, 1], a REACH quality score in [0, 1], and an MPPR rank that is an integer of at least 1. The year window is whichever periods the file lists.

pay.bounds.allows rejects a point outside that row. It also rejects proposed NPRM numbers, an unstated null (nothing is imputed), a missing wage index, a missing equipment maintenance factor, and a limiting-charge fee, which is an output of pfsPayment. IPPS and LEAD have no pricer. MSSP and REACH settlements stay published tables. The budget-neutrality adjustor is already inside the conversion factor.

Rebuild the file from the registries and data/replica/aco.ro.duckdb when either changes. A checkout without the replica still checks the registries against the committed file.

Check

lake exe cache get   # mathlib oleans; do not build mathlib from source
lake build
lake exe pay-cases > cases.json

.gitea/workflows/lean-pay.yml runs that check when lean/ or the workflow file changes. The runner downloads Lean 4.34.0 from the GitHub release (releases.lean-lang.org times out from this network) and uses the mathlib olean cache.

tests/pay/test_ceiling.py runs the Python functions on these inputs and requires the rationals in cases.json. When lake is on PATH it also requires pay-cases to reprint that file.