arabelatso/skills-4-se/abstract-invariant-generator
- community
Checking that the SKILL.md file is still in the repository.
Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.
Install
npx vskill@latest install arabelatso/skills-4-se/abstract-invariant-generatorSKILL.md
Abstract Invariant Generator
Overview
This skill uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions. It generates formal specifications that support verification and reasoning about program correctness.
Invariant Generation Workflow
Step 1: Identify Specification Points
Analyze the code to identify where invariants are needed:
Loop Invariants: For each loop
Function Contracts: For each function
Assertions: For verification points
Step 2: Perform Abstract Interpretation
Use abstract domains to infer properties:
Interval Analysis: Infer numeric ranges
Relational Analysis: Infer relationships between variables
Shape Analysis: Infer data structure properties
Step 3: Generate Loop Invariants
For each loop, generate an invariant that:
- Holds before the loop (initialization)
- Is preserved by the loop body (maintenance)
- Combined with loop exit, implies desired property (termination)
Template-Based Generation:
Counter Loop:
Generated Invariant:
Accumulator Loop:
Generated Invariant:
Search Loop:
Generated Invariant:
Step 4: Generate Function Preconditions
Infer what must be true for the function to work correctly:
Array Access Function:
Generated Precondition:
Division Function:
Generated Precondition:
Linked List Function:
Generated Precondition:
Step 5: Generate Function Postconditions
Infer what the function guarantees on exit:
Maximum Function:
Generated Postcondition:
Sorting Function:
Generated Postcondition:
Search Function:
Generated Postcondition:
Step 6: Express in Target Language
Format invariants for the target verification system:
Dafny:
Isabelle/HOL:
Coq:
ACSL (for C):
Complete Example
Input Code (Python):
Analysis:
Outer Loop (for i in range(1, len(arr))):
- i ranges from 1 to len(arr)
- After each iteration, arr[0..i] is sorted
- Elements are permutation of original
Inner Loop (while j >= 0 and arr[j] > key):
- j decreases from i-1 to -1
- Shifts elements greater than key to the right
- Maintains: arr[j+2..i+1] contains elements > key
Generated Invariants (Dafny):
Explanation:
Outer Loop Invariants:
1 <= i <= arr.Length: Loop counter boundssorted(arr[..i]): First i elements are sortedmultiset(arr[..]) == multiset(old(arr[..])): Permutation preservation
Inner Loop Invariants:
-1 <= j < i: Loop counter boundssorted(arr[..j+1]): Elements before j+1 remain sortedsorted(arr[j+2..i+1]): Shifted elements remain sortedforall k :: j+2 <= k <= i ==> arr[k] > key: Shifted elements are greater than keymultiset(arr[..]) == multiset(old(arr[..])): Permutation preservation
Invariant Patterns
Numeric Bounds
Array Properties
Relationships
Data Structure Properties
Permutation
Strengthening Weak Invariants
Sometimes initial invariants are too weak. Strengthen them:
Weak:
Strengthened:
Technique: Add properties about what has been accomplished so far.
Handling Complex Loops
Nested Loops
Generate invariants for each level:
Invariants:
Multiple Exit Conditions
Handle all exit paths:
Invariants:
References
For detailed invariant generation techniques and patterns:
- references/loop_invariants.md: Loop invariant patterns and generation strategies
- references/function_contracts.md: Precondition and postcondition inference
- references/invariant_templates.md: Common invariant templates by algorithm type
- references/verification_languages.md: Syntax for different verification systems
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/abstract-invariant-generator/SKILL.md
Popularity
- Repository stars
- 63
- Repository forks
- 5
- 7-day trend score
- 21
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 20 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/arabelatso/skills-4-se/abstract-invariant-generator)