leanprover / leanprover/lean4

`induction` passes wrong instance to function application

Open
#6,544 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

induction will use instances on the original variable in function applications on the new variable. The tactic will succeed, and indeed create new goals, but the proof will have a type error.

Context

This was discovered during usage of https://github.com/leanprover-community/repl, where we found a successful sequence of tactics resulting in an unsuccessful proof.

Steps to Reproduce
/--
warning: declaration uses 'sorry'
---
error: application type mismatch
  @Fin.instOfNat n inst✝
argument has type
  NeZero n✝
but function has type
  [inst : NeZero n] → {i : Nat} → OfNat (Fin n) i
-/
#guard_msgs in
example (n: Nat) [NeZero n] : (0 : Fin n) = 0 := by
  induction n <;> sorry

Expected behavior: An error on the tactic as it should try to synthesize NeZero 0 and NeZero n (where the original n is succ of this n) and both should fail.

Actual behavior: The tactic uses the original NeZero n✝ instance to synthesize Fin.instOfNat, for the new (0 : Fin n), which is not type-correct. Yet the tactic does not fail.

Versions

Lean 4.16.0-rc1
Target: x86_64-unknown-linux-gnu
live.lean-lang.org

Additional Information

Initially, https://github.com/leanprover/lean4/issues/4246 looked similar, but I think it's not the same.

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal Lean example in the issue and inspect the induction tactic's handling of instances for the new variable. Done means the tactic reports an error when it cannot synthesize NeZero 0 or NeZero n, rather than creating a proof that later has a type error.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.