agentleFS
rainoftimerainoftime/pl-skills/invariant-generator/SKILL.md

invariant-generator

Skill17 starsChanged 9 months agoApache-2.0View on GitHub

Infers loop invariants automatically. Use when: (1) Proving program

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Start with simple bounds

    line 55
  2. Distinctive:

    Use counterexamples to guide search

    line 57
  3. Distinctive:

    Template selection: Must choose right templates

    line 104

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Invariant Generator

Automatically infers loop invariants for program verification.

When to Use

  • Proving program correctness
  • Automating verification
  • Loop analysis
  • Counterexample generation

What This Skill Does

  1. Analyzes loops - Examines loop structure
  2. Infers candidates - Generates invariant candidates
  3. Verifies - Checks if invariant holds
  4. Refines - Improves invariants

Key Concepts

ConceptDescription
Loop invariantTrue before and after each iteration
InitializationHolds initially
PreservationMaintained by body
UsefulnessHelps prove postcondition

Techniques

  • Template-based inference
  • Abstract interpretation
  • Counterexample-guided
  • Iterative refinement

Tips

  • Start with simple bounds
  • Handle accumulators carefully
  • Use counterexamples to guide search
  • Combine multiple techniques

Related Skills

  • hoare-logic-verifier - Verify with invariants
  • loop-termination-prover - Prove termination
  • symbolic-execution-engine - Symbolic execution

Canonical References

ReferenceWhy It Matters
Ernst et al., "The Daikon System for Dynamic Detection of Likely Invariants" (SCP 2007)Daikon invariant detector
Sankaranarayanan et al., "Non-Linear Loop Invariant Generation using Gröbner Bases" (POPL 2004)Template-based invariant generation
Csallner & Xie, "DynaMine: Finding Common Error Patterns by Mining Software Repositories" (ICSE 2005)Dynamic invariant mining
Gulwani et al., "Generating Numerical Invariants with Polynomials" (POPL 2009)Counterexample-guided invariant generation
Sharma & Aiken, "From Invariants to Code" (POPL 2014)Interpolants-based invariant generation

Tradeoffs and Limitations

Invariant Inference Approach Tradeoffs

ApproachProsCons
DynamicPrecise, fastMay miss bugs
StaticSoundComplex
CEGARIterative refinementMay diverge
TemplateGuided searchTemplate-dependent

When NOT to Use Automatic Invariant Inference

  • For simple loops: Manual specification may be faster
  • For proving liveness: Different techniques needed
  • For complex data structures: Hard to infer

Complexity Considerations

  • Template-based: Exponential in template variables
  • Abstract interpretation: Lattice height × program size
  • CEGAR: May require many iterations

Limitations

  • Completeness: May miss important invariants
  • Precision: May infer too weak or too strong
  • Scalability: Hard for large programs
  • Template selection: Must choose right templates
  • Arithmetic: Nonlinear invariants hard
  • Data structures: Complex invariants needed

Research Tools & Artifacts

Invariant detection tools:

ToolWhat to Learn
DaikonDynamic invariants
ArminStatic invariants

Research Frontiers

1. CEGAR for Invariants

  • Approach: Counterexample-guided

Implementation Pitfalls

PitfallReal ConsequenceSolution
Weak invariantsFailed proofsRefine templates

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.