mirror of
https://github.com/hanzoai/skills.git
synced 2026-11-19 00:47:36 +00:00
hanzoskills.com/llms.txt now opens with the install line, the API reference index and the company index, so an agent that lands on any one of the three can find the rest. robots.txt claimed 537 documents while llms.txt counts 920. The number is gone from robots.txt; llms.txt derives it. public/ is regenerated from scripts/site.py, which it had fallen behind: the copy-prompt menu and agent bar were in the generator and not in the committed pages. tests/site.mjs passes against the result. Co-authored-by: Hanzo Dev <[email protected]>
443 lines
27 KiB
HTML
443 lines
27 KiB
HTML
<!doctype html>
|
||
<html lang="en"><head>
|
||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||
<title>formal-lean-proof-basics</title>
|
||
<meta name="color-scheme" content="dark">
|
||
<style>
|
||
/* Committed to one visual world: a dark instrument panel. No light variant —
|
||
the dot field and the hairline rules only read on black, and a naive
|
||
inversion would wash both out. Every colour is painted explicitly so the page
|
||
never borrows a host background. */
|
||
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
||
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
||
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
||
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
||
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
|
||
|
||
:root{
|
||
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
|
||
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
|
||
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
|
||
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
|
||
--font-zen-pixel-square:'Zen Pixel Square',monospace;
|
||
--mono:var(--font-zen-mono);
|
||
--sans:var(--font-zen-sans);
|
||
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
|
||
--r:999px; --r-soft:14px;
|
||
}
|
||
*{box-sizing:border-box}
|
||
html{-webkit-text-size-adjust:100%}
|
||
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
|
||
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
|
||
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
|
||
|
||
/* The dot field. A halftone made of one repeating radial-gradient, faded out
|
||
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
|
||
/* No overflow clip here: the dot field is inset to the box already, and a clip
|
||
would cut off the copy-prompt menu. */
|
||
.hero{position:relative;border-bottom:1px solid var(--line)}
|
||
.hero::before{content:"";position:absolute;inset:0;
|
||
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
|
||
background-size:7px 7px;
|
||
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
||
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
||
pointer-events:none}
|
||
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
|
||
|
||
nav{border-bottom:1px solid var(--line)}
|
||
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
|
||
justify-content:space-between;align-items:center;gap:1rem}
|
||
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
|
||
text-transform:uppercase;color:var(--ink);text-decoration:none;
|
||
display:inline-flex;align-items:center;gap:.6rem}
|
||
.brand i{font-style:normal;color:var(--faint)}
|
||
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
|
||
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
|
||
text-transform:uppercase;color:var(--soft);text-decoration:none}
|
||
nav a.up:hover{color:var(--ink)}
|
||
|
||
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
|
||
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
|
||
h1 em{font-style:normal;color:var(--faint)}
|
||
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
|
||
|
||
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
|
||
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
|
||
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
|
||
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
|
||
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
|
||
line-height:1.2;font-weight:400}
|
||
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
|
||
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
|
||
.btn.solid:hover{background:#d8d8d4}
|
||
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
|
||
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
|
||
|
||
/* Copy-prompt selector. Each row copies the prompt for its own target. */
|
||
.copy{position:relative;display:inline-flex}
|
||
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
|
||
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
|
||
padding:.4rem;display:flex;flex-direction:column;
|
||
box-shadow:0 12px 32px rgba(0,0,0,.75)}
|
||
.menu[hidden]{display:none}
|
||
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
|
||
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
|
||
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
|
||
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
|
||
white-space:nowrap}
|
||
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
|
||
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
|
||
.mi:hover .mark{color:var(--ink)}
|
||
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
|
||
letter-spacing:.1em;text-transform:uppercase}
|
||
|
||
/* Works-with bar: one scrolling row, name and mark per agent. */
|
||
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
|
||
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
|
||
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
|
||
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
|
||
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
|
||
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
|
||
display:flex;align-items:center}
|
||
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
|
||
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
|
||
-webkit-overflow-scrolling:touch;
|
||
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
|
||
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
|
||
.bar::-webkit-scrollbar{display:none}
|
||
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
|
||
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
|
||
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
|
||
text-decoration:none;background:var(--ground)}
|
||
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
|
||
.agent .mark{width:.95rem;height:.95rem}
|
||
|
||
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
|
||
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
|
||
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
|
||
p{margin:0 0 1rem;max-width:70ch}
|
||
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
|
||
li{margin:.22rem 0}
|
||
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
|
||
text-decoration-color:var(--line-hi)}
|
||
a:hover{text-decoration-color:var(--ink)}
|
||
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
|
||
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
|
||
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
|
||
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
|
||
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
|
||
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
|
||
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
|
||
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
|
||
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
|
||
display:block;overflow-x:auto}
|
||
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
|
||
|
||
.curl{display:block;background:var(--panel);border:1px solid var(--line);
|
||
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
|
||
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
|
||
white-space:pre;line-height:1.9}
|
||
.curl b{color:var(--ink);font-weight:400}
|
||
.curl i{font-style:normal;color:var(--faint)}
|
||
|
||
/* index */
|
||
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
|
||
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
|
||
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
|
||
#q:focus{outline:none;border-color:var(--soft)}
|
||
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
|
||
text-transform:uppercase;margin:0 0 2rem}
|
||
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
|
||
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
|
||
padding-bottom:.45rem}
|
||
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
|
||
border-radius:var(--r-soft);text-decoration:none}
|
||
.row:hover{background:#0a0a0a}
|
||
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
|
||
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
|
||
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
|
||
color:var(--faint);font-size:.85rem}
|
||
footer a{color:var(--soft)}
|
||
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
|
||
margin:0 0 2rem;font-size:.85rem}
|
||
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
|
||
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
|
||
border-bottom:1px solid var(--line);padding-bottom:.4rem}
|
||
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
|
||
.fmap a:hover{text-decoration:underline}
|
||
.fmap div{color:var(--faint);line-height:1.5}
|
||
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
|
||
|
||
@media (max-width:640px){
|
||
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
|
||
.btns{gap:.5rem}
|
||
.btn{padding:.75rem 1.15rem;font-size:.68rem}
|
||
.copy,.copy .btn{width:100%;justify-content:center}
|
||
.menu{left:0;right:0;min-width:0}
|
||
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
|
||
.strip b{border-right:0;padding-right:0}
|
||
.bar{width:100%}
|
||
}
|
||
</style>
|
||
<link rel="alternate" type="text/markdown" href="/formal-lean-proof-basics.md">
|
||
|
||
<link rel="icon" href="/favicon.svg">
|
||
<link rel="canonical" href="https://hanzoskills.com/formal-lean-proof-basics">
|
||
</head>
|
||
<!-- Reading this with a machine? Every page here is also plain markdown.
|
||
This one: https://hanzoskills.com/formal-lean-proof-basics.md
|
||
Index: https://hanzoskills.com/llms.txt
|
||
Corpus: https://hanzoskills.com/all.md
|
||
Append .md to any path for the markdown twin. -->
|
||
<body>
|
||
<nav><div class="in">
|
||
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
|
||
<a class="up" href="/">All skills</a>
|
||
</div></nav>
|
||
|
||
<div class="wrap">
|
||
<h1>formal-lean-proof-basics</h1><p class="lede">Learning Lean 4 from scratch</p><h1>Lean 4 Proof Basics</h1>
|
||
<h2>Overview</h2>
|
||
<p>Fundamental concepts and patterns for writing proofs in Lean 4, covering propositions as types, proof terms, basic tactics, and simple proof structures.</p>
|
||
<h2>Scope</h2>
|
||
<p><strong>Included:</strong></p>
|
||
<ul><li>Propositions as types (Curry-Howard correspondence)</li><li>Proof terms vs tactic mode</li><li>Basic tactics (intro, exact, apply, rw)</li><li>Function and implication proofs</li><li>Conjunction, disjunction, negation</li><li>Universal and existential quantifiers</li><li>Simple induction proofs</li><li>Lean 4 syntax and conventions</li></ul>
|
||
<p><strong>Excluded:</strong></p>
|
||
<ul><li>Advanced tactics (see <code>lean-tactics.md</code>)</li><li>mathlib4 library usage (see <code>lean-mathlib4.md</code>)</li><li>Complex formalization strategies (see <code>lean-theorem-proving.md</code>)</li><li>Type class mechanics</li><li>Metaprogramming and custom tactics</li></ul>
|
||
<h2>When to Use This Skill</h2>
|
||
<p><strong>Primary use cases:</strong></p>
|
||
<ul><li>Learning Lean 4 from scratch</li><li>Writing simple mathematical proofs</li><li>Understanding proof term representation</li><li>Teaching formal verification basics</li><li>Converting paper proofs to Lean</li></ul>
|
||
<p><strong>Indicators you need this:</strong></p>
|
||
<ul><li>"How do I prove X in Lean 4?"</li><li>"What's the difference between term mode and tactic mode?"</li><li>"How do I use intro/exact/apply?"</li><li>"How do I prove basic logical statements?"</li></ul>
|
||
<p><strong>When to use other skills instead:</strong></p>
|
||
<ul><li>Complex tactic automation → <code>lean-tactics.md</code></li><li>Using mathlib4 theorems → <code>lean-mathlib4.md</code></li><li>Advanced formalization → <code>lean-theorem-proving.md</code></li></ul>
|
||
<h2>Prerequisites</h2>
|
||
<p><strong>Required knowledge:</strong></p>
|
||
<ul><li>Basic functional programming (types, functions)</li><li>Propositional logic (and, or, implies, not)</li><li>First-order logic (forall, exists)</li></ul>
|
||
<p><strong>Required setup:</strong></p>
|
||
<pre><code class="lang-bash"># Install Lean 4 (via elan)
|
||
⚠️ **SECURITY**: Piping curl to shell is dangerous. For production:</code></pre>
|
||
<h1>Download script first</h1>
|
||
<p>curl -O https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh</p>
|
||
<h1>Verify checksum</h1>
|
||
<p>sha256sum elan-init.sh</p>
|
||
<h1>Review content</h1>
|
||
<p>less elan-init.sh</p>
|
||
<h1>Then execute</h1>
|
||
<p>bash elan-init.sh</p>
|
||
<pre><code>For development/learning only:</code></pre>
|
||
<p>curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh</p>
|
||
<h1>Create new project</h1>
|
||
<p>lake new my_project cd my_project</p>
|
||
<h1>Build project</h1>
|
||
<p>lake build</p>
|
||
<h1>Open in VS Code (with Lean 4 extension)</h1>
|
||
<p>code .</p>
|
||
<pre><code>
|
||
**Dependencies:**
|
||
- Lean 4.0.0+ (preferably latest stable)
|
||
- VS Code with Lean 4 extension
|
||
- mathlib4 (optional, for library access)
|
||
|
||
## Core Concepts
|
||
|
||
### 1. Propositions as Types (Curry-Howard)
|
||
In Lean, propositions are types, and proofs are terms of those types.
|
||
</code></pre>
|
||
<p>-- Proposition: 2 + 2 = 4 #check (2 + 2 = 4 : Prop)</p>
|
||
<p>-- Proof: a term of type "2 + 2 = 4" example : 2 + 2 = 4 := rfl</p>
|
||
<p>-- Type of a proof #check (rfl : 2 + 2 = 4)</p>
|
||
<pre><code>
|
||
**Key principle:** To prove proposition P, construct a term of type P.
|
||
|
||
### 2. Term Mode vs Tactic Mode
|
||
|
||
**Term mode** (direct proof construction):</code></pre>
|
||
<p>-- Prove implication directly example : p → q → p := fun hp hq => hp</p>
|
||
<p>-- Prove conjunction example : p ∧ q → q ∧ p := fun ⟨hp, hq⟩ => ⟨hq, hp⟩</p>
|
||
<pre><code>
|
||
**Tactic mode** (interactive proof construction):</code></pre>
|
||
<p>example : p → q → p := by intro hp hq exact hp</p>
|
||
<p>example : p ∧ q → q ∧ p := by intro ⟨hp, hq⟩ exact ⟨hq, hp⟩</p>
|
||
<pre><code>
|
||
**When to use each:**
|
||
- Term mode: Simple proofs, direct constructions, obvious terms
|
||
- Tactic mode: Complex proofs, exploratory proving, step-by-step reasoning
|
||
|
||
### 3. Basic Proof Structure
|
||
|
||
**Anatomy of a proof:**</code></pre>
|
||
<p>-- Theorem statement theorem my_theorem (assumptions : Type) : conclusion := by -- Tactic 1 -- Tactic 2 -- ... -- Tactic N (closes goal)</p>
|
||
<pre><code>
|
||
**Example:**</code></pre>
|
||
<p>theorem and_comm (p q : Prop) : p ∧ q → q ∧ p := by intro ⟨hp, hq⟩ -- Introduce hypothesis, destructure exact ⟨hq, hp⟩ -- Provide exact proof term</p>
|
||
<pre><code>
|
||
### 4. Function Types and Implication
|
||
Functions and implications are the same (Π-types).
|
||
</code></pre>
|
||
<p>-- These are equivalent example : ∀ (n : Nat), n + 0 = n := fun n => Nat.add_zero n example : ∀ (n : Nat), n + 0 = n := by intro n; exact Nat.add_zero n</p>
|
||
<p>-- Implication is a function example : p → q := fun hp => _ -- hp : p, goal: q</p>
|
||
<pre><code>
|
||
## Common Patterns
|
||
|
||
### Pattern 1: Proving Implications</code></pre>
|
||
<p>-- Template theorem impl_proof : P → Q := by intro hP -- Assume P (hypothesis hP) -- Now prove Q using hP sorry</p>
|
||
<p>-- Example theorem modus_ponens : p → (p → q) → q := by intro hp hpq apply hpq exact hp</p>
|
||
<pre><code>
|
||
### Pattern 2: Proving Conjunctions</code></pre>
|
||
<p>-- Template theorem conj_proof : P ∧ Q := by constructor · -- Prove P sorry · -- Prove Q sorry</p>
|
||
<p>-- Example theorem and_intro : p → q → p ∧ q := by intro hp hq constructor · exact hp · exact hq</p>
|
||
<pre><code>
|
||
### Pattern 3: Using Conjunctions</code></pre>
|
||
<p>-- Destructuring in intro theorem and_left : p ∧ q → p := by intro ⟨hp, hq⟩ exact hp</p>
|
||
<p>-- Using cases theorem and_right : p ∧ q → q := by intro h cases h with | intro hp hq => exact hq</p>
|
||
<pre><code>
|
||
### Pattern 4: Proving Disjunctions</code></pre>
|
||
<p>-- Template: prove one side theorem disj_left : P → P ∨ Q := by intro hP left exact hP</p>
|
||
<p>theorem disj_right : Q → P ∨ Q := by intro hQ right exact hQ</p>
|
||
<pre><code>
|
||
### Pattern 5: Case Analysis on Disjunctions</code></pre>
|
||
<p>-- Template theorem disj_elim : P ∨ Q → (P → R) → (Q → R) → R := by intro hPQ hPR hQR cases hPQ with | inl hP => exact hPR hP | inr hQ => exact hQR hQ</p>
|
||
<p>-- Example theorem or_comm : p ∨ q → q ∨ p := by intro h cases h with | inl hp => right; exact hp | inr hq => left; exact hq</p>
|
||
<pre><code>
|
||
### Pattern 6: Negation and Contradiction</code></pre>
|
||
<p>-- Negation is implication to False #check (¬p : Prop) -- p → False</p>
|
||
<p>-- Proof by contradiction theorem not_not_intro : p → ¬¬p := by intro hp hnp exact hnp hp</p>
|
||
<p>-- Using contradiction theorem contradiction : p → ¬p → q := by intro hp hnp exfalso exact hnp hp</p>
|
||
<pre><code>
|
||
### Pattern 7: Universal Quantification</code></pre>
|
||
<p>-- Template theorem forall_intro : ∀ (x : α), P x := by intro x -- Prove P x for arbitrary x sorry</p>
|
||
<p>-- Example theorem forall_impl : (∀ x, P x → Q x) → (∀ x, P x) → (∀ x, Q x) := by intro hPQ hP x apply hPQ exact hP x</p>
|
||
<pre><code>
|
||
### Pattern 8: Existential Quantification</code></pre>
|
||
<p>-- Proving existence theorem exists_intro : P a → ∃ x, P x := by intro hPa use a exact hPa</p>
|
||
<p>-- Using existential hypothesis theorem exists_elim : (∃ x, P x) → (∀ x, P x → Q) → Q := by intro ⟨x, hPx⟩ hPQ exact hPQ x hPx</p>
|
||
<pre><code>
|
||
### Pattern 9: Equality and Rewriting</code></pre>
|
||
<p>-- Reflexivity example : a = a := rfl</p>
|
||
<p>-- Symmetry example (h : a = b) : b = a := h.symm</p>
|
||
<p>-- Transitivity example (h1 : a = b) (h2 : b = c) : a = c := by rw [h1, h2]</p>
|
||
<p>-- Rewriting in goal example (h : a = b) : f a = f b := by rw [h]</p>
|
||
<p>-- Rewriting in hypothesis example (h1 : a = b) (h2 : f a = c) : f b = c := by rw [h1] at h2 exact h2</p>
|
||
<pre><code>
|
||
### Pattern 10: Simple Induction</code></pre>
|
||
<p>-- Template theorem nat_induction (P : Nat → Prop) (base : P 0) (step : ∀ n, P n → P (n + 1)) : ∀ n, P n := by intro n induction n with | zero => exact base | succ n ih => exact step n ih</p>
|
||
<p>-- Example theorem zero_add (n : Nat) : 0 + n = n := by induction n with | zero => rfl | succ n ih => rw [Nat.add_succ, ih]</p>
|
||
<pre><code>
|
||
## Basic Tactics Reference
|
||
|
||
### Core Tactics</code></pre>
|
||
<p>-- intro: Introduce hypothesis or variable intro h -- Name hypothesis h intro -- Auto-generate name intro ⟨h1, h2⟩ -- Destructure simultaneously</p>
|
||
<p>-- exact: Provide exact proof term exact h -- Use hypothesis h exact rfl -- Reflexivity for equality</p>
|
||
<p>-- apply: Apply function/theorem (backward reasoning) apply f -- If goal is Q and f : P → Q, new goal is P</p>
|
||
<p>-- constructor: Build constructors (and, exists, etc.) constructor -- For ∧, split into two goals</p>
|
||
<p>-- left/right: Choose disjunction branch left -- Prove P for goal P ∨ Q right -- Prove Q for goal P ∨ Q</p>
|
||
<p>-- cases: Case analysis cases h -- Split on hypothesis h</p>
|
||
<p>-- exfalso: Proof by contradiction exfalso -- Change goal to False</p>
|
||
<p>-- rfl: Reflexivity rfl -- Prove a = a</p>
|
||
<p>-- rw: Rewrite using equality rw [h] -- Rewrite goal using h : a = b rw [h] at h2 -- Rewrite in hypothesis h2 rw [←h] -- Rewrite backwards (b to a)</p>
|
||
<pre><code>
|
||
### Tactic Combinators</code></pre>
|
||
<p>-- Sequential execution tac1; tac2 -- Do tac1 then tac2</p>
|
||
<p>-- All goals all_goals tac -- Apply tac to all goals</p>
|
||
<p>-- Focus on goals · tac -- Focus on first goal next => tac -- Focus on next goal</p>
|
||
<p>-- Repetition repeat tac -- Repeat until failure</p>
|
||
<pre><code>
|
||
## Quick Reference
|
||
|
||
### Logical Connectives</code></pre>
|
||
<p>-- Implication P → Q -- Function type fun h => ... -- Proof (term mode) intro h -- Proof (tactic mode)</p>
|
||
<p>-- Conjunction P ∧ Q -- And.intro : P → Q → P ∧ Q ⟨hp, hq⟩ -- Construct (term mode) constructor -- Construct (tactic mode)</p>
|
||
<p>-- Disjunction P ∨ Q -- Or.inl : P → P ∨ Q, Or.inr : Q → P ∨ Q Or.inl hp -- Construct left (term mode) left; exact hp -- Construct left (tactic mode)</p>
|
||
<p>-- Negation ¬P -- P → False fun h => ... -- Prove negation</p>
|
||
<p>-- Universal ∀ x, P x -- (x : α) → P x fun x => ... -- Proof (term mode) intro x -- Proof (tactic mode)</p>
|
||
<p>-- Existential ∃ x, P x -- Exists.intro : ∀ (a : α), P a → ∃ x, P x ⟨a, ha⟩ -- Construct (term mode) use a; exact ha -- Construct (tactic mode)</p>
|
||
<pre><code>
|
||
### Equality</code></pre>
|
||
<p>rfl -- a = a h.symm -- a = b → b = a rw [h] -- Rewrite using h : a = b rw [←h] -- Rewrite backwards calc -- Chain equalities a = b := h1 _ = c := h2</p>
|
||
<pre><code>
|
||
### Common Proof Structures</code></pre>
|
||
<p>-- By cases cases h with | case1 => ... | case2 => ...</p>
|
||
<p>-- By induction induction n with | zero => ... | succ n ih => ...</p>
|
||
<p>-- Let binding let x := value show goal</p>
|
||
<pre><code>
|
||
## Anti-Patterns
|
||
|
||
### Anti-Pattern 1: Over-Complicating Simple Proofs</code></pre>
|
||
<p>-- BAD: Verbose tactic proof example : p → p := by intro h have h2 : p := h exact h2</p>
|
||
<p>-- GOOD: Direct term example : p → p := fun h => h</p>
|
||
<p>-- GOOD: Minimal tactics example : p → p := by intro h; exact h</p>
|
||
<pre><code>
|
||
### Anti-Pattern 2: Ignoring Type Inference</code></pre>
|
||
<p>-- BAD: Explicit types everywhere example : (fun (x : Nat) => (x : Nat) + (0 : Nat)) = (fun (x : Nat) => x) := by funext (x : Nat) simp</p>
|
||
<p>-- GOOD: Let Lean infer example : (fun x => x + 0) = (fun x => x) := by funext x simp</p>
|
||
<pre><code>
|
||
### Anti-Pattern 3: Manual Term Construction</code></pre>
|
||
<p>-- BAD: Building complex terms manually example : p ∧ q → q ∧ p := fun h => And.intro (And.right h) (And.left h)</p>
|
||
<p>-- GOOD: Use tactics for clarity example : p ∧ q → q ∧ p := by intro ⟨hp, hq⟩ exact ⟨hq, hp⟩</p>
|
||
<pre><code>
|
||
### Anti-Pattern 4: Not Using Structured Proofs</code></pre>
|
||
<p>-- BAD: All tactics at same level example : p ∨ q → q ∨ p := by intro h cases h right assumption left assumption</p>
|
||
<p>-- GOOD: Use bullets for structure example : p ∨ q → q ∨ p := by intro h cases h with | inl hp => right exact hp | inr hq => left exact hq</p>
|
||
<pre><code>
|
||
### Anti-Pattern 5: Overuse of sorry</code></pre>
|
||
<p>-- BAD: Leaving sorries theorem important_theorem : P := by sorry -- TODO: prove this later</p>
|
||
<p>-- GOOD: Use admit only for exploration, remove before committing -- GOOD: Break into lemmas with clear sorry locations lemma helper_lemma : Q := by sorry -- Needs complex proof, tracked in issue #123</p>
|
||
<p>theorem important_theorem : P := by have hq := helper_lemma -- ... rest of proof</p>
|
||
<pre><code>
|
||
## Related Skills
|
||
- **lean-tactics.md**: Advanced tactics, tactic combinators, automation
|
||
- **lean-mathlib4.md**: Using mathlib4 library, finding theorems
|
||
- **lean-theorem-proving.md**: Advanced formalization strategies
|
||
- **smt-theory-applications.md**: Automated theorem proving with SMT solvers
|
||
|
||
## References
|
||
- [Lean 4 Manual](https://lean-lang.org/lean4/doc/)
|
||
- [Theorem Proving in Lean 4](https://lean-lang.org/theorem_proving_in_lean4/)
|
||
- [Functional Programming in Lean](https://lean-lang.org/functional_programming_in_lean/)
|
||
- [Natural Number Game (Lean 4 version)](https://adam.math.hhu.de/#/g/leanprover-community/nng4)
|
||
|
||
## Examples
|
||
|
||
### Example 1: Classical Logic Theorems</code></pre>
|
||
<p>-- Modus tollens theorem modus_tollens : (p → q) → ¬q → ¬p := by intro hpq hnq hp exact hnq (hpq hp)</p>
|
||
<p>-- Hypothetical syllogism theorem hyp_syllogism : (p → q) → (q → r) → (p → r) := by intro hpq hqr hp exact hqr (hpq hp)</p>
|
||
<p>-- De Morgan's laws (one direction) theorem not_and_of_not_or_not : ¬p ∨ ¬q → ¬(p ∧ q) := by intro h ⟨hp, hq⟩ cases h with | inl hnp => exact hnp hp | inr hnq => exact hnq hq</p>
|
||
<pre><code>
|
||
### Example 2: Quantifier Manipulation</code></pre>
|
||
<p>-- Swap quantifiers theorem forall_swap : (∀ x y, P x y) → (∀ y x, P x y) := by intro h y x exact h x y</p>
|
||
<p>-- Distribute quantifier over conjunction theorem forall_and : (∀ x, P x ∧ Q x) → (∀ x, P x) ∧ (∀ x, Q x) := by intro h constructor · intro x; exact (h x).left · intro x; exact (h x).right</p>
|
||
<pre><code>
|
||
### Example 3: Simple Arithmetic</code></pre>
|
||
<p>-- Addition is commutative (using built-in) example (m n : Nat) : m + n = n + m := Nat.add_comm m n</p>
|
||
<p>-- Zero is right identity theorem add_zero (n : Nat) : n + 0 = n := by induction n with | zero => rfl | succ n ih => rw [Nat.add_succ, ih]</p>
|
||
<p>-- Successor relationship theorem succ_add (m n : Nat) : (m + 1) + n = (m + n) + 1 := by induction n with | zero => rfl | succ n ih => rw [Nat.add_succ, Nat.add_succ, ih, Nat.add_succ]</p>
|
||
<pre><code>
|
||
---
|
||
|
||
**Skill Metadata:**
|
||
- Scope: Lean 4 proof fundamentals
|
||
- Complexity: Beginner to intermediate
|
||
- Prerequisites: Basic logic and functional programming
|
||
- Related: lean-tactics.md, lean-mathlib4.md, lean-theorem-proving.md
|
||
</code></pre>
|
||
<footer>
|
||
<div class="fmap">
|
||
<div><b>Build</b>
|
||
<a href="https://hanzo.app">hanzo.app</a> app builder
|
||
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
|
||
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
|
||
<div><b>Run</b>
|
||
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
|
||
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
|
||
<div><b>Account</b>
|
||
<a href="https://hanzo.id">hanzo.id</a> sign in
|
||
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
|
||
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
|
||
<div><b>Company</b>
|
||
<a href="https://hanzo.ai">hanzo.ai</a> canonical
|
||
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
|
||
</div>
|
||
<div class="fend"><a href="/formal-lean-proof-basics.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
|
||
</footer>
|
||
</div></body></html> |