This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Linear Algebra Game built using the lean4game framework. It's an educational game that teaches linear algebra concepts through interactive theorem proving in Lean 4, based on Sheldon Axler's "Linear Algebra Done Right" textbook.
The project uses Lake (Lean 4's build system):
lake build- Build the entire project (Note: This can take 15+ minutes for full mathlib builds - don't set timeouts)lake clean- Remove build outputslake update- Update dependencies and save to manifestlake exe <exe>- Build and run an executablelake env <cmd>- Execute command in Lake's environment
Important Build Note: When running lake build, do not set time limits. Full builds with mathlib dependencies can take longer than 15 minutes, especially on first compilation.
Game.lean- Main game configuration with title, introduction, and world dependenciesGame/Data.lean- Extensive mathlib imports for mathematical definitionsGame/Metadata/Metadata.lean- Game metadata and server commandsGame/MyTactic.lean- Custom tactic imports for the game
The game is organized into sequential worlds:
- TutorialWorld (
Game/Levels/TutorialWorld/) - Introduction to Lean 4 basics - VectorSpaceWorld (
Game/Levels/VectorSpaceWorld/) - Vector space concepts - LinearIndependenceSpanWorld (
Game/Levels/LinearIndependenceSpanWorld/) - Linear independence and span
Each world:
- Has a main
.leanfile (e.g.,TutorialWorld.lean) that imports all levels - Contains individual level files (
Level01.lean,Level02.lean, etc.) - Uses the
World,Level,Title,Introduction,Statement,Conclusioncommands
sofi.sh- Script for reordering and renaming level files within worlds- Levels must follow
L**.leanorL**_*****.leannaming convention - The script automatically updates level numbers and imports
- Lean 4.21.0 - The proof assistant (latest version)
- mathlib 4.21.0 - Comprehensive mathematics library
- lean4game 4.21.0 - Game framework (local or remote depending on
LEAN4GAMEenv var) - checkdecls - Declaration checking tool for blueprint verification (working)
- Adding New Levels: Create level files following naming convention, then run
./sofi.sh <world_path>to reorder - Level Structure: Each level includes
World,Level,Title,Introduction,Statement,Conclusion - Tactic Documentation: Use
TacticDocandNewTacticcommands to document tactics - World Dependencies: Configure in
Game.lean(e.g., VectorSpaceWorld → LinearIndependenceSpanWorld) - REQUIRED: Always run
lake buildafter making any fixes or changes to ensure changes are visible in the local game
The game covers:
- Vector spaces and their properties
- Linear independence and span
- Bases and linear transformations
- Proof techniques using Lean 4 tactics (
rfl,apply,intro, etc.)
For local development with the game framework:
- Set
LEAN4GAME.local=truein Lake configuration - Ensure the lean4game server is available at
../lean4game/server - Use
lake buildto compile the game - The game generates a web interface for interactive theorem proving
- Game Framework Integration: Uses lean4game's
GameServer.Commandsfor web interface - Tactic System: Imports extensive mathlib tactics while filtering some for educational purposes
- World Organization: Sequential progression with dependency management
- Educational Design: Focuses on proof techniques rather than computation
The blueprint provides comprehensive mathematical documentation for all 43 levels across 5 worlds:
- Tutorial World: 10 levels introducing Lean 4 tactics
- Vector Space World: 5 levels on vector space fundamentals
- Linear Independence & Span World: 9 levels on independence and spanning sets
- Linear Maps World: 11 levels on linear transformations
- Inner Product World: 8 levels on inner products and norms
Note: The game originally had 45 levels, but 2 demo levels were removed after fixing introduction display bugs.
- checkdecls package from PatrickMassot/checkdecls is installed and working
- Verifies all Lean declarations referenced in the blueprint exist in the code
blueprint/lean_declslists 60+ theorem declarations- CI workflow runs
lake exe checkdecls blueprint/lean_declsto verify consistency - Use comments in
lean_declsfile starting with--
Multiple levels had hints that didn't match the actual proof code, causing player confusion:
- Root Cause:
funextwithout explicit variable names defaults tox, notv - LinearIndependenceSpanWorld Level07: Fixed all hints to use
xinstead ofvafterfunext x - Impact: 8+ hint corrections in the most complex proof level
- Root Cause: Hints incorrectly used
{variable}syntax instead of plainvariable - Files Fixed: Level03, Level06, Level09 (LinearIndependenceSpanWorld), Level04 (VectorSpaceWorld)
- Pattern:
obtain ⟨...⟩ := {hypothesis}→obtain ⟨...⟩ := hypothesis - Impact: 5 syntax corrections across multiple levels
Critical issue where proofs would hang after completion:
- Problem: Proofs ending with rewrite tactics (
rw[...]) that create trivial goals - Environment: lean4game framework doesn't auto-close trivial goals like standard Lean
- Symptom: Game freezes/stalls when player completes the final rewrite
-
LinearIndependenceSpanWorld Level07 (Original report)
- Added
rflafterrw[hf0 x hS, hg0 x hT] - Most complex proof in the game
- Added
-
DemoWorld L01_HelloWorld (Discovered during systematic review)
- Added
rflafterrw [g] - Basic introductory level
- Added
-
LinearMapsWorld Level06 (Discovered during systematic review)
- Added
rflafterrw [hT.2 a1 v1, hT.2 a2 v2] - Linear combination preservation proof
- Added
-
VectorSpaceWorld Level01 (Discovered during systematic review)
- Added
rflafterrw[zero_add] - First vector space theorem
- Added
- All proofs ending with rewrites before
Conclusionstatements require explicit closing tactics - Pattern:
rw[...]; rflinstead of justrw[...] - Systematic search methodology developed to find similar issues
- Variable Names: Always specify explicit variable names in tactics (
funext xnotfunext) - Syntax Matching: Ensure hint syntax exactly matches required code
- No Assumptions: Don't assume Lean's default behaviors in educational contexts
- Explicit Closing: Always use explicit closing tactics (
rfl,simp,exact) for trivial goals - Game Environment: lean4game requires more explicit proof steps than standard Lean
- Testing Protocol: Verify proof completion doesn't stall in game environment
- Total Issues Fixed: 11 across 9 different levels
- Stalling Issues: 4 (prevented game freezes)
- Hint Issues: 7 (improved player experience)
- Systematic Approach: One reported issue led to discovering 3 additional similar problems
Default picture folder: /mnt/e/pictures
When asked to examine pictures or screenshots without a specific path, look in /mnt/e/pictures first.
Additional screenshot location: /mnt/c/Users/zrtmr/OneDrive/Pictures/Screenshots