proven-bounds

Convert runtime array bounds checks to statically proven accesses in Lean 4.

112|9|Updated Feb 17, 2026
One-click install
npx skills add https://github.com/kim-em/lean-zip --skill proven-bounds
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: proven-bounds
Source: https://github.com/kim-em/lean-zip/tree/main/.claude/skills/proven-bounds
Command: npx skills add https://github.com/kim-em/lean-zip --skill proven-bounds

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers safely convert runtime array bounds checks (xs[i]!) to statically proven accesses (xs[i]) in Lean 4, preventing runtime errors and improving code reliability.

Core Features & Use Cases

  • Safe Array Access: Learn to use if h : condition then to bind proof hypotheses for array bounds.
  • Loop Integration: Capture loop index bounds for safe access within for loops.
  • Recursion Refactoring: Replace opaque loops with proof-friendly well-founded recursion.
  • Use Case: When refactoring code that uses data[pos]!, apply the techniques in this Skill to ensure pos < data.size is proven, allowing the ! to be removed.

Quick Start

Use the proven-bounds skill to convert the data[pos]! access to data[pos] by adding an if h : pos < data.size guard.

Frequently Asked Questions about proven-bounds

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert runtime array bounds checks to statically proven accesses in Lean 4?

To convert runtime array bounds checks in Lean 4, introduce an `if h : condition then` guard to bind proof hypotheses like `pos < data.size`, enabling the removal of the `!` operator for safe array indexing.

How does Lean 4 proof system handle array bounds checking?

The Lean 4 proof system handles array bounds checking by requiring a statically proven hypothesis like `pos < data.size` to use safe indexing `data[pos]`, replacing runtime checks with compile-time proof obligations.

Can I capture loop index bounds for safe array access in Lean 4 for loops?

Yes, you can capture loop index bounds for safe array access within Lean 4 `for` loops. The Skill provides guidance on binding these bounds to prove accesses and avoid speculative conversion pitfalls.

What is the best way to refactor opaque loops for proof-friendly array access?

The best way to refactor opaque loops for proof-friendly array access is replacing them with well-founded recursion. This structural change allows Lean 4 to properly capture loop bounds and verify safe indexing.

Why does removing the exclamation mark from array access in Lean 4 cause proof repair issues?

Removing the exclamation mark from array access in Lean 4 causes proof repair issues because the compiler requires a valid proof of `pos < data.size`. Without proper guard capture, speculative conversion fails to verify bounds.