"""Exact synthetic residual-wait bounds with an unfinished inspection gap. A complete log begins with a detecting check of one block. Hypothetical fault onset is uniform over the observation window. This is not measured MTTD. """ import argparse from datetime import datetime, timezone from fractions import Fraction import hashlib import json from pathlib import Path def nonnegative(value, name): if type(value) not in (int, Fraction) or value < 0: raise ValueError(f"{name} must be a nonnegative integer or Fraction in days") return Fraction(value) def window_checked(completed_gaps, age): if not isinstance(completed_gaps, (list, tuple)): raise ValueError("completed_gaps must be a list or tuple") if any(type(gap) is not int or gap <= 0 for gap in completed_gaps): raise ValueError("completed gaps must be positive integer days") age = nonnegative(age, "age") horizon = sum(completed_gaps) + age if not horizon: raise ValueError("observation window must have positive duration") return tuple(completed_gaps), age, horizon def mean_wait_lower_bound(completed_gaps, age): gaps, age, horizon = window_checked(completed_gaps, age) return (sum(gap * gap for gap in gaps) + age * age) / (2 * horizon) def mean_wait_if_next(completed_gaps, age, future_delay): gaps, age, horizon = window_checked(completed_gaps, age) delay = nonnegative(future_delay, "future_delay") return mean_wait_lower_bound(gaps, age) + age * delay / horizon def tail_bounds(completed_gaps, age, threshold): gaps, age, horizon = window_checked(completed_gaps, age) threshold = nonnegative(threshold, "threshold") complete_area = sum((max(Fraction(gap) - threshold, 0) for gap in gaps), Fraction(0)) return ((complete_area + max(age - threshold, 0)) / horizon, (complete_area + age) / horizon) def tail_if_next(completed_gaps, age, future_delay, threshold): gaps, age, horizon = window_checked(completed_gaps, age) delay = nonnegative(future_delay, "future_delay") threshold = nonnegative(threshold, "threshold") complete_area = sum((max(Fraction(gap) - threshold, 0) for gap in gaps), Fraction(0)) return (complete_area + min(age, max(age + delay - threshold, 0))) / horizon def encode(value): value = Fraction(value) return {"numerator": value.numerator, "denominator": value.denominator, "decimal": float(value)} def result(): gaps, age, threshold = [14, 14], 28, 14 lower, upper = tail_bounds(gaps, age, threshold) return { "schema_version": 1, "evidence_type": "exact-arithmetic-on-synthetic-schedules", "completed_checks_days": [0, 14, 28], "observation_cutoff_day": 56, "unfinished_age_days": age, "onset_distribution": "uniform over [0, 56]; hypothetical, not inferred from failure logs", "assumptions": [ "Complete inspection log for one fixed block and detection property, starting at a known check.", "No further detecting check through cutoff; u=0 is a limiting bound, not an observed check.", "Persistent fault; next check detects it; no intervening reads, repair, overwrite or missed records.", "Future-delay scenarios concern the same original 56-day onset window, not an extended sample.", ], "limitations": [ "Not measured MTTD, a fleet estimator, a paper replication or a data-loss probability.", "No finite upper bound on mean wait with an unfinished gap and unbounded next-check delay.", "Exact constructed inputs: no sampling confidence interval.", "Unknown initial inspection, health-dependent onset or imperfect detection require another model.", ], "mean_wait_lower_bound_days": encode(mean_wait_lower_bound(gaps, age)), "mean_wait_upper_bound_days": None, "upper_bound_status": "unbounded", "threshold_days": threshold, "tail_lower_bound": encode(lower), "tail_upper_bound": encode(upper), "formula_mean": "(sum(d_i**2) + a**2 + 2*a*u) / (2*H), H=sum(d_i)+a", "formula_tail": "(sum(max(d_i-h,0)) + min(a,max(a+u-h,0))) / H", "scenarios": [ {"label": "Drop unfinished gap", "onset_window_days": 28, "status": "different population", "future_delay_days": None, "mean_wait_days": encode(mean_wait_if_next(gaps, 0, 0)), "tail_probability": encode(tail_if_next(gaps, 0, 0, threshold))}, {"label": "Cutoff lower bound", "onset_window_days": 56, "status": "infimum, not completion", "future_delay_days": 0, "mean_wait_days": encode(mean_wait_lower_bound(gaps, age)), "tail_probability": encode(lower)}, {"label": "Next check on day 70", "onset_window_days": 56, "status": "assumed future", "future_delay_days": 14, "mean_wait_days": encode(mean_wait_if_next(gaps, age, 14)), "tail_probability": encode(tail_if_next(gaps, age, 14, threshold))}, {"label": "Next check on day 98", "onset_window_days": 56, "status": "assumed future", "future_delay_days": 42, "mean_wait_days": encode(mean_wait_if_next(gaps, age, 42)), "tail_probability": encode(tail_if_next(gaps, age, 42, threshold))}, ], "generator_sha256": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), "sources": [ {"url": "https://ocw.mit.edu/courses/6-262-discrete-stochastic-processes-spring-2011/931ffa0940899c27f34b71ad64fd2bb0_MIT6_262S11_chap04.pdf", "role": "residual-wait area derivation background; finite censored worksheet is Hesela's", "accessed": "2026-10-20"}, {"url": "https://www.itl.nist.gov/div898/handbook/apr/section1/apr131.htm", "role": "censoring terminology, not a measured scrub-delay model", "accessed": "2026-10-20"}, {"url": "https://www.usenix.org/legacy/events/fast10/tech/full_papers/schroeder.pdf", "role": "storage onset versus discovery-time limitations, sections 2 and 5.1", "accessed": "2026-10-20"}, ], } def main(): parser = argparse.ArgumentParser(description=__doc__) actions = parser.add_mutually_exclusive_group() actions.add_argument("--write", action="store_true") actions.add_argument("--check", action="store_true") args = parser.parse_args() path = Path(__file__).with_name("results.json") expected = result() if args.check: stored = json.loads(path.read_text()) stamp = datetime.fromisoformat(stored.pop("generated_at")) if stamp.utcoffset() is None or stored != expected: raise SystemExit("Results, timestamp or generator hash invalid") print("Censored-window arithmetic and provenance verified") else: expected["generated_at"] = datetime.now(timezone.utc).isoformat() output = json.dumps(expected, indent=2) + "\n" if args.write: path.write_text(output) else: print(output, end="") if __name__ == "__main__": main()