You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This looks like a simp cache error. This is the term:
_example : ∀ (b : Bool), (if b = true then 1 else if b = true then 1 else 0) = if b = true then 1 else 0 :=
fun b =>
Or.casesOn (Classical.em (b = true))
(fun h =>
Eq.mpr
(id
(congr
(congrArg Eq
(Eq.trans (ite_congr (Eq.refl (b = true)) (fun a => Eq.refl 1) fun a => if_pos h) (if_pos h)))
(if_pos h)))
(Eq.refl 1))
fun h =>
Eq.mpr
(id
(congr
(congrArg Eq
(Eq.trans (ite_congr (Eq.refl (b = true)) (fun a => Eq.refl 1) fun a => if_neg a) (if_neg h)))
(if_neg _uniq.495)))
(Eq.refl 0)
Note the if_neg _uniq.495 conspicuously following the if_neg a above.
Changing the if b then 1 else 0 terms a bit (e.g. changing the numbers) unbreaks it.
Also writing
example (b : Bool) :
(if b then 1 else 0) = (if b then 1 else if b then 1 else 0) := by
where the outer (if b then 1 else 0) is visited first unbreaks it.
I did not manage to reproduce it with just a call to simp, but I can by exposing simpIfTarget:
import Lean
open Lean Meta Elab Tactic in
elab "simp_if" : tactic => do
withMainContext do
replaceMainGoal [ ← simpIfTarget (← getMainGoal) ]
set_option trace.Elab.definition true
example (b : Bool) (h : ¬ (b = true)) :
(if b then 1 else if b then 1 else 0) = (if b then 1 else 0) := by
simp_if
rfl
/--
Default `discharge?` function for `simpIf` methods.
It only uses hypotheses from the local context. It is effective
after a case-split. -/
def discharge? (useDecide := false) : Simp.Discharge := fun prop => do
let prop ← instantiateMVars prop
trace[Meta.Tactic.splitIf] "discharge? {prop}, {prop.notNot?}"
if useDecide then …
(← getLCtx).findDeclRevM? fun localDecl => do
if localDecl.isAuxDecl then
return none
else if (← isDefEq prop localDecl.type) then
return some localDecl.toExpr
else match prop.notNot? with
| none => return none
| some arg =>
if (← isDefEq arg localDecl.type) then
return some (mkApp2 (mkConst ``not_not_intro) arg localDecl.toExpr)
else
return none
It seems that caching based on expressions is inherently incompatible with this kind of “peeking at the context”.
A blunt fix would be to set
let ctx := { ctx with config := { ctx.config with memoize := false }}
in SplitIf.getSimpContext.
A more careful fix would be to let a the discharger method to set cache := false, and have that propagate to the Simp.Result.
Although I probably don’t have the full picture yet, given that dischargeUsingAssumption? exists as well…
So maybe some dischargeDepth bump is missing?
(BTW, this is not a regression; this bug existed for at least a year.)
Activity
nomeata commentedon Feb 2, 2024
Looking into this; partial debugging update:
This looks like a simp cache error. This is the term:
Note the
if_neg _uniq.495conspicuously following theif_neg aabove.Changing the
if b then 1 else 0terms a bit (e.g. changing the numbers) unbreaks it.Also writing
where the outer
(if b then 1 else 0)is visited first unbreaks it.I did not manage to reproduce it with just a call to
simp, but I can by exposingsimpIfTarget:nomeata commentedon Feb 2, 2024
Could this code be blamed:
It seems that caching based on expressions is inherently incompatible with this kind of “peeking at the context”.
A blunt fix would be to set
in
SplitIf.getSimpContext.A more careful fix would be to let a the discharger method to set
cache := false, and have that propagate to theSimp.Result.Although I probably don’t have the full picture yet, given that
dischargeUsingAssumption?exists as well…So maybe some
dischargeDepthbump is missing?(BTW, this is not a regression; this bug existed for at least a year.)
fix: cache issue at `split` tatic
fix: cache issue at `split` tatic (#3258)
chore: adaptation PR for leanprover/lean4#3258 (fixing cache isssue i…
chore: adaptation PR for leanprover/lean4#3258 (fixing cache isssue i…