Skip to content

Commit 3895f98

Browse files
authored
Merge pull request #1064 from lean-ja/Seasawher/issue758
「index in target's type is not a variable」エラーはいつ起こるのか?
2 parents 79f24de + e3f5f13 commit 3895f98

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

LeanByExample/Reference/Tactic/Induction.lean

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,35 @@ def bar : Nat → Nat
186186
#guard_msgs (drop warning) in --#
187187
#check_failure bar.induct
188188

189+
/- ## よくあるエラー
190+
`induction` タクティクを使ったときに、`index in target's type is not a variable` というエラーが出ることがあります。
191+
-/
192+
193+
/-- 偶数であることを表す帰納的述語 -/
194+
inductive MyEven : Nat → Prop where
195+
| zero : MyEven 0
196+
| succ : {n : Nat} → MyEven n → MyEven (n + 2)
197+
198+
/--
199+
error: index in target's type is not a variable (consider using the `cases` tactic instead)
200+
0
201+
-/
202+
#guard_msgs in
203+
example (h : MyEven 0) : True := by
204+
induction h
205+
206+
/- これは型族の添え字が変数ではないから起こることです。その証拠に、変数にするとエラーにならなくなります。-/
207+
208+
example (n m : Nat) (h : MyEven (n + m)) : True := by
209+
/-
210+
index in target's type is not a variable (consider using the `cases` tactic instead)
211+
n + m
212+
-/
213+
generalize n + m = x at h
214+
induction h
215+
· trivial
216+
· trivial
217+
189218
/-
190219
[^recursive]: [lean公式ブログの Functional induction についての記事](https://lean-lang.org/blog/2024-5-17-functional-induction/) で recursive theorem という言葉が使われています。
191220
-/

0 commit comments

Comments
 (0)