Loop analysis: one proof-rule layer (obligations, rules, candidate sources; strategies as presets)

Open
#552 10 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start with the design note and strategy matrix, then inspect prodigy/analysis/loops/, prodigy/distribution, and the referenced deciders in subinvariant.py, exact/strategies.py, exploration.py, unrolling.py, and bounds/egcalc.py. The first implementation target is the unified obligation chain and operator/rule layer, with existing strategies becoming presets. Done means the listed obligations, operators, Kleene iteration, loop-bound propagation, and certificate checks have single implementations, with golden behavior comparisons and documented justification for any remaining exceptions.

Written by the indexing model from the issue text.

Description

area: analysis priority: high topic: loop strategies

The ten loop strategies in prodigy/analysis/loops/ combine a few building blocks:

  • four proof rules: Kleene (lower), Park (upper), lower induction with finite mass (lower), and both together (exact);
  • two operators: the output transformer Φ and the EVT operator Ψ_g;
  • five candidate sources: the user, template synthesis, LP, a language model, and extrapolation.

Each strategy, however, is implemented as a column of its own. It builds its own operator, checks its own side conditions, derives its own guarantee and prints its own output. Found while planning the complexity work of #512:

  • Ψ is built in four places: invariant_verification.evt_operator, inline in subinvariant.py, inline in exploration.py, and as a separate semantics of the fragment in bounds/egcalc.py.
  • Three non-negativity deciders cover different classes in a different order: subinvariant.decide_nonneg, exact/strategies._positivity and GFCalculus.first_negative. The same function can be proven non-negative under one strategy and stay unknown under another.
  • Three or four finite-mass deciders: exact/strategies.finite_mass, subinvariant.exact_mass/rational_mass, unrolling._finite_mass and GFCalculus.mass.
  • Two arbiters for the same obligation ν ≤ Ψ(ν), |ν| < ∞:
    • evt_subinvariant checks it with the engines.
    • evt_sandwich checks it with verify_certificate, that is, with egcalc's own semantics.
    • So the soundness of sandwich certificates rests on a second implementation of the semantics.
  • Kleene iteration is implemented three times: unroll and mass_threshold are copies apart from the stopping rule; evt_iterate is the same iteration on Ψ.
  • Soundness arguments are scattered. Over-approximated bodies (scope.kind), the series identity (#276, #393) and observe are handled separately in park, exact/strategies, subinvariant and through requires_unconditioned.
  • Three ways carry an upper bound past the loop: LoopOutcome.upper, query_bounds, and auto._upper_query_bounds. In addition, bounds/ has its own program split and its own evaluation of the queries after the loop.
  • exact/heuristics/positivity holds proof rules under a misleading name. Its docstring says they are sound, yet they live in analysis and are imported across packages.

Proposal

The proposal adds a layer between the engines and the strategies:

  1. Obligations in prodigy/distribution.
    • nonneg, finite_mass, leq and equal, each three-valued and with the reason, as one ordered chain of rules for classes.
    • The chain covers the product form, nonneg_by_construction, exp and log polynomials, independent factors, Pringsheim, and the current positivity rules.
    • Engine hooks only for CAS operations.
  2. The operators in one place: Ψ_g, and the Park transformer shared with compare mode.
  3. The proof rules in loops/rules/: kleene (with a stopping policy), park, lower_induction and exact_fixed_point.
    • Each states its theorem and side conditions once.
    • Each handles the approximated body, the series identity and observe in one place.
    • Each returns a Guarantee and the evidence.
  4. Candidate sources only propose. The LP becomes a proposal engine whose final certificates are checked by the shared rules through the engines. egcalc and explicit then carry no soundness.
  5. Strategies become presets (source × rule × stopping × presentation). Names, delivers, CLI and GUI stay.
  6. One path past the loop, through the upper track and the query handler. query_bounds stays only where an upper bound has infinite mass, with that reason.

A design note comes first and must be approved before any code. It includes:

  • the strategy matrix;
  • the unified deciders with their classes;
  • the rule signatures;
  • a timing of the engine check of the final LP certificates on the looping examples (SymPy, GiNaC);
  • the PR cut.

Done when

  • Each obligation has exactly one decider chain, in prodigy/distribution. No strategy keeps its own copy.
  • Ψ_g and the Park transformer are built in one place each.
  • The four rules exist with their side conditions documented once. Every strategy derives its guarantee through them.
  • Certificates of evt_sandwich are accepted only by the shared rules, or a measured and approved reason is recorded for keeping verify_certificate as an arbiter.
  • unroll, mass_threshold and evt_iterate share one Kleene implementation.
  • Upper bounds after a loop take one path. Every remaining exception is justified.
  • Strategies print through the session, not to stdout.
  • Results are behaviour-preserving on both engines (golden comparison). Every result that becomes stronger or weaker is listed and justified.
  • The records and types of #512 that were planned for the calculus are either gone with the reason stated or done as classified there: Exploration, VariableProfile, LoopProblem, TemplateLP, Certificate, SandwichResult, LoopStrategy, and the iteration, reporter and option types.
  • A leftover search for the moved and renamed modules is stated in the PR.

Part of the v0.7.0 architecture pass; #512 is closed only after this.

Dominant language
Python
Stars
6
Forks
2
Avg merge
1h 52m
Merged PRs (30d)
187

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LKlinke/Prodigy

All issues in LKlinke/Prodigy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.