From lean-collab
Provides Lean 4 syntax guide for creating valid `--goal-type` and `--hypotheses` with `./bin/lc create-goal`. Covers function juxtaposition, real constants, set intervals, `;;`-separated hypotheses, and operators.
npx claudepluginhub mutable-state-inc/lean-collabThis skill uses the workspace's default tool permissions.
**Use this skill when creating goals with `./bin/lc create-goal`.**
Assists with Lean 4 theorem proving: editing .lean files, debugging builds (type mismatches, sorries, axioms, lake errors), searching mathlib lemmas, formalizing mathematics, and learning concepts via commands like /lean4:prove and /lean4:formalize.
Provides Mathlib tactic references and lemma naming patterns for Lean-prover agents. Consult after MATH CARD analysis for syntax, lemmas, and strategies.
Fills Lean4 sorry holes in proofs, generates counterexamples for false statements, and handles English/Lean4 inputs via Harmonic API. For formal verification with Mathlib/lake.
Share bugs, ideas, or general feedback.
Use this skill when creating goals with ./bin/lc create-goal.
This ensures your --goal-type and --hypotheses are syntactically valid Lean 4.
Lean 4 uses juxtaposition, not parentheses:
| WRONG | CORRECT |
|---|---|
sin(x) | Real.sin x |
cos(y) | Real.cos y |
exp(x) | Real.exp x |
log(x) | Real.log x |
sqrt(x) | Real.sqrt x |
abs(x) | ` |
f(x, y) | f x y |
Multi-argument functions:
-- WRONG
max(a, b)
min(x, y)
-- CORRECT
max a b
min x y
| WRONG | CORRECT |
|---|---|
π | Real.pi |
e | Real.exp 1 |
0.5 | 1/2 (prefer rationals) |
pi/2 | Real.pi / 2 |
| Interval | Lean 4 Syntax |
|---|---|
[a, b] | Set.Icc a b |
(a, b) | Set.Ioo a b |
[a, b) | Set.Ico a b |
(a, b] | Set.Ioc a b |
Examples:
-- WRONG
x ∈ [0, π/2]
x ∈ (0, 1)
-- CORRECT
x ∈ Set.Icc 0 (Real.pi / 2)
x ∈ Set.Ioo 0 1
-- WRONG
x ∈ {y | P(y)}
-- CORRECT (simple predicate)
x ∈ {y | P y}
-- BETTER (avoid set-builder in goal types - decompose instead)
-- Instead of: x ∈ {c | ∀ y ∈ S, f c y}
-- Create separate goals:
-- 1. "∀ y ∈ S, f x y" (the membership condition)
-- 2. The remaining proof
Format: Double-semicolon (;;) separated name : type pairs
--hypotheses "x : ℝ;;hx : x ∈ Set.Icc 0 Real.pi"
Why ;;? Commas appear inside Lean types (like ∀ x ∈ S, P x), so we use ;; which never appears in valid Lean.
With ;; delimiter, quantified hypotheses work correctly:
# WORKS - ;; delimiter handles internal commas
--hypotheses "c : ℝ;;hc : ∀ x ∈ Set.Icc 0 (Real.pi / 2), Real.sin x ≤ c * x"
# This correctly becomes TWO hypotheses:
# 1. c : ℝ
# 2. hc : ∀ x ∈ Set.Icc 0 (Real.pi / 2), Real.sin x ≤ c * x
| After decomposition | Hypotheses to pass |
|---|---|
intro x hx | --hypotheses "x : ℝ;;hx : x ∈ Set.Icc 0 Real.pi" |
intro c hc (membership) | --hypotheses "c : ℝ;;hc : ∀ x ∈ S, P x" |
| Multiple intros | --hypotheses "a : ℝ;;ha : a > 0;;b : ℝ;;hb : b < 1" |
Count your parentheses! Common error:
-- WRONG (unmatched paren)
--hypotheses "h : (4 / Real.pi ^ 2) * (Real.pi - x) * x"
^ missing close?
-- CORRECT
--hypotheses "h : (4 / Real.pi ^ 2) * (Real.pi - x) * x ≥ 0"
-- WRONG (causes syntax error)
--hypotheses ""
-- CORRECT (omit entirely for root goals)
./bin/lc create-goal --id "my-goal" --goal-type "P" --parent "root" --depth 1
| Symbol | Lean 4 |
|---|---|
≤ | ≤ (Unicode) or <= |
≥ | ≥ (Unicode) or >= |
< | < |
> | > |
≠ | ≠ (Unicode) or != |
∧ | ∧ (Unicode) or /\ |
∨ | ∨ (Unicode) or \/ |
→ | → (Unicode) or -> |
∀ | ∀ (Unicode) or forall |
∃ | ∃ (Unicode) or exists |
-- Division
4 / Real.pi -- division
(4 : ℝ) / Real.pi -- explicit type annotation if needed
-- Powers
Real.pi ^ 2 -- pi squared
x ^ (1/2) -- square root (or use Real.sqrt x)
Real.exp x -- e^x
-- WRONG
π²
pi**2
-- CORRECT
Real.pi ^ 2
-- Goal type for IsGreatest
IsGreatest {c | ∀ x ∈ Set.Icc 0 (Real.pi / 2), c * x ≤ Real.sin x} (2 / Real.pi)
-- After `constructor`, children are:
-- 1. Membership: (2 / Real.pi) ∈ {c | ∀ x ∈ ..., c * x ≤ Real.sin x}
-- 2. Upper bound: ∀ c ∈ {c | ...}, c ≤ 2 / Real.pi
-- Parent: ∀ x ∈ Set.Icc 0 (Real.pi / 2), P x
-- After `intro x hx`:
-- Child goal: P x
-- Child hypotheses: "x : ℝ,hx : x ∈ Set.Icc 0 (Real.pi / 2)"
-- Parent: P ∧ Q
-- After `constructor`:
-- Child 1: P
-- Child 2: Q
-- (hypotheses inherited from parent)
Before calling ./bin/lc create-goal, verify:
( and ), must be equalReal.sin x not sin(x)Set.Icc a b not [a, b]Real.pi not πa ≤ b not a≤bLLMs frequently guess lemma names that don't exist. Use ./bin/lc suggest to get real ones, or consult this table.
| WRONG (Hallucinated) | CORRECT (Mathlib) | Notes |
|---|---|---|
Metric.Sphere.infinite | Metric.sphere_infinite | Lowercase, underscore |
Set.Infinite.diff | Set.Infinite.diff | Check signature - needs Finite second arg |
Set.infinite_sphere | Metric.sphere_infinite | In Metric namespace |
Metric.sphere.nonempty | Metric.nonempty_sphere | Prefix not suffix |
Set.Infinite.inter | Set.Infinite.inter_of_left | Needs side specification |
| WRONG (Hallucinated) | CORRECT (Mathlib) | Notes |
|---|---|---|
EuclideanGeometry.sphere_infinite | Metric.sphere_infinite | It's in Metric |
Affine.Simplex.circumcenter | Affine.Simplex.circumcenter | ✓ exists, check args |
circumcenter_mem_sphere | Affine.Simplex.circumsphere_center_eq_circumcenter | Different name |
Simplex.monochromatic | N/A | You need to define this |
| WRONG (Hallucinated) | CORRECT (Mathlib) | Notes |
|---|---|---|
Real.sin_le_one | Real.sin_le_one | ✓ exists |
Real.two_div_pi_mul_le_sin | Real.two_div_pi_mul_le_sin | ✓ exists (Jordan) |
sin_pos_of_pos_of_lt_pi | Real.sin_pos_of_pos_of_lt_pi | Need Real. prefix |
sin_nonneg_of_nonneg_of_le_pi | Real.sin_nonneg_of_nonneg_of_le_pi | Need Real. prefix |
cos_pos_of_mem_Ioo | Real.cos_pos_of_mem_Ioo | Need Real. prefix |
| WRONG (Hallucinated) | CORRECT (Mathlib) | Notes |
|---|---|---|
Finset.card_le_three | N/A | Use Finset.card_le_of_subset |
Set.nontrivial_of_card_ge_two | Set.nontrivial_of_two_le_card | Reversed name |
Finite.of_card_le | Set.Finite.of_card_le | Need Set. prefix |
| WRONG (Hallucinated) | CORRECT (Mathlib) | Notes |
|---|---|---|
ConcaveOn.sin | strictConcaveOn_sin_Icc | Different structure |
concave_sin_Icc | strictConcaveOn_sin_Icc.concaveOn | Need .concaveOn |
ConvexOn.le_right | ConvexOn.le_right_of_lt_left | Full name needed |
Naming conventions in Mathlib:
snake_case not camelCase for lemmasReal.sin_zero not sin_zero_of_ for implications: sin_pos_of_pos_Icc, _Ioo suffixWhen you get "unknown identifier":
# 1. ALWAYS try suggest first
./bin/lc suggest --goal $GOAL_ID
# 2. Search for similar patterns
./bin/lc search "sphere infinite" --prefix tactics/
# 3. Check the actual Mathlib namespace (in Lean REPL)
#check @Metric.sphere_infinite -- see the real signature
-- Trigonometric
Real.sin x, Real.cos x, Real.tan x
-- Arithmetic
a + b, a - b, a * b, a / b, a ^ n
-- Comparisons
a ≤ b, a < b, a = b, a ≠ b
-- Logic
P ∧ Q, P ∨ Q, P → Q, ¬P
-- Quantifiers (in goal types)
∀ x, P x
∀ x ∈ S, P x
∃ x, P x
-- Sets
x ∈ S
Set.Icc a b -- [a, b]
Set.Ioo a b -- (a, b)
-- Special structures
IsGreatest S x
IsLeast S x
ConcaveOn ℝ S f
ConvexOn ℝ S f