lean4-htt/src
Robert J. Simmons 75d79819c3
feat: catch and provide context for misuse of NNG-style induction pattern (#11347)
This PR adds a focused error explanation aimed at the case where someone
tries to use Natural-Numbers-Game-style `induction` proofs directly in
Lean, where such proofs are not syntactically valid.

## Discussion

The natural numbers game uses a syntax that overlaps with Lean's
`induction` syntax despite having more structural similarity to
`induction'`. This means that fully correct proofs in the natural
numbers game, like this...

```lean4
import Mathlib
theorem zero_mul (m : ℕ) : 0 * m = 0 := by
  induction m with n n_ih
  rw [mul_zero]
  rfl
  rw [mul_succ]
  rw [add_zero]
  rw [n_ih]
  rfl
```

...have completely baffling error messages from a newcomers'
perspective:

```
notNaturalNumbersGame.lean:3:20: error: unknown tactic
notNaturalNumbersGame.lean:3:2: error: Alternative `zero` has not been provided
notNaturalNumbersGame.lean:3:2: error: Alternative `succ` has not been provided
```

(the Mathlib import here only provides the `ℕ` syntax here; equivalently
`ℕ` could be renamed to `Nat` and the import could be removed, [like
this](https://live.lean-lang.org/#codez=C4Cwpg9gTmC2AEAvMUIH1YFcA28AUCAXPAHICGwAlPMQAzwBU8CAvPPYWwEYCeAUPHgBLAHYATTAGNgQiCObwA7kNDx5ItEJAD4URfADaWbGmSoAujqgAzbFf1GcaAM5TJlwXsNkxY0yggPXQcNLSCbbCA))

There are many problems with this proof from the perspective of "stock"
Lean, but the error messages in the `induction` case are particularly
unfriendly and provide no guidance from a NNG learner's perspective.

This PR provides more information about what is wrong:

```
notNaturalNumbersGame.lean:3:20: error: unknown tactic
notNaturalNumbersGame.lean:3:14: error(lean.inductionWithNoAlts): Invalid syntax for induction tactic: The `with` keyword must followed by a tactic or by an alternative (e.g. `| zero =>`), but here it is followed by the identifier `n`.
```

The error explanation it links to explicitly flags the transition of
NNG-style proofs to Lean as the likely culprit, and gives an example of
an effective translation.
2025-11-25 18:44:40 +00:00
..
bin
cmake chore: fix spelling errors (#10042) 2025-08-22 07:23:12 +00:00
include/lean perf: less allocations when using string patterns (#11255) 2025-11-19 13:06:27 +00:00
Init feat: String.Slice.toInt? (#11358) 2025-11-25 15:48:41 +00:00
initialize feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
kernel chore: use String.ofList instead of String.mk in elaborator+kernel (#11048) 2025-11-01 14:44:16 +00:00
lake fix: move the monad argument for ForIn, ForIn', and ForM (#10204) 2025-11-25 12:20:37 +00:00
Lean feat: catch and provide context for misuse of NNG-style induction pattern (#11347) 2025-11-25 18:44:40 +00:00
library fix: symbol clashes between packages (#11082) 2025-11-19 02:24:44 +00:00
runtime chore: CI: re-enable fsanitize job (#11258) 2025-11-24 11:12:25 +00:00
shell chore: tests: use filenames as test names (#11302) 2025-11-21 12:40:58 +00:00
Std fix: move the monad argument for ForIn, ForIn', and ForM (#10204) 2025-11-25 12:20:37 +00:00
util feat: document that backward options may disappear (#11304) 2025-11-24 17:49:46 +00:00
cadical.mk
CMakeLists.txt chore: begin dev cycle for v4.27.0 (#11229) 2025-11-18 08:12:49 +00:00
config.h.in
githash.h.in
Init.lean chore: more reorganization of strings (#10928) 2025-10-23 11:56:11 +00:00
lakefile.toml.in feat: USE_LAKE_CACHE CMake option (#10708) 2025-10-08 08:56:53 +00:00
lean-toolchain
Lean.lean chore: use 'library suggestions' rather than 'premise selection' (#11029) 2025-10-31 04:07:49 +00:00
lean.mk.in chore: further split libleanshared on Windows to avoid symbol limit (#10136) 2025-08-26 16:01:57 +00:00
Leanc.lean fix: Unicode path support for Lean Windows executables (#10133) 2025-08-27 11:28:55 +00:00
out feat: ac normalization in grind (#10146) 2025-08-27 03:28:30 +00:00
Std.lean chore: more module system fixes and refinements for finishing batteries port (#10819) 2025-10-21 08:19:50 +00:00
stdlib.make.in chore: further split libleanshared on Windows to avoid symbol limit (#10136) 2025-08-26 16:01:57 +00:00
stdlib_flags.h feat: implement grind_annotated command (#11332) 2025-11-25 02:12:35 +00:00
version.h.in