leanprover / leanprover/lean4

Using split on if-then-else simplifies unrelated nested if-then-else

Open
#3,245 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This is rather minor, but I stumbled over this while debugging #3229, and I’d like to record it as an instance of a non-finishing tactic doing possibly unexpected things on the side.

Consider this example:

example (b1 b2 : Bool) :
  (match b1 with
  | true => 0
  | false => (if b2 then 0 else if b2 then 42 else 0)) = 0 := by
  split
  rfl

Now the goal is, as expected

b2 b1✝: Bool
⊢ (if b2 = true then 0 else if b2 = true then 42 else 0) = 0

The split tactic split the match, and leaves the branch in place.

Using if-then-else however:

example (b1 b2 : Bool) :
  (if b1
  then 0
  else (if b2 then 0 else if b2 then 42 else 0)) = 0 := by
  split
  rfl

the goal becomes

b1b2: Bool
h✝: ¬b1 = true
⊢ (if b2 = true then 0 else 0) = 0

Note that suddenly, the totally unrelated nested if b2 was reduced.

The problem lies is with Lean.Meta.simpIfTarget, which

  • uses the if-then-else congruence theorems and
  • a discharger that looks into the hypotheses.

I wonder if it really needs to enable ite_congr – after all, for the if-then-else that was split the condition is already in the context, so no need for the “better” congruence rule and the standard rule should suffice?

Versions

v4.5.0

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 with Lean.Meta.simpIfTarget, identified in the report as the source of the behavior, and reproduce both split examples from the issue. Compare how the discharger and if-then-else congruence affect unrelated nested conditions; done means the nested if b2 is not simplified when splitting the unrelated condition.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.