Compare commits

...

1 Commits

Author SHA1 Message Date
Leonardo de Moura
de1e053f6c fix: reduceNeg simproc 2024-12-28 14:42:01 -08:00
2 changed files with 18 additions and 6 deletions

View File

@@ -49,17 +49,13 @@ If they do, they must disable the following `simprocs`.
-/
builtin_dsimproc [simp, seval] reduceNeg ((- _ : Int)) := fun e => do
unless e.isAppOfArity ``Neg.neg 3 do return .continue
let arg := e.appArg!
let_expr Neg.neg _ _ arg e | return .continue
if arg.isAppOfArity ``OfNat.ofNat 3 then
-- We return .done to ensure `Neg.neg` is not unfolded even when `ground := true`.
return .done e
else
let some v fromExpr? arg | return .continue
if v < 0 then
return .done <| toExpr (- v)
else
return .done <| toExpr v
return .done <| toExpr (- v)
/-- Return `.done` for positive Int values. We don't want to unfold in the symbolic evaluator. -/
builtin_dsimproc [seval] isPosValue ((OfNat.ofNat _ : Int)) := fun e => do

16
tests/lean/run/6467.lean Normal file
View File

@@ -0,0 +1,16 @@
theorem confuses_the_user : -(no_index (OfNat.ofNat <| nat_lit 2)) = -2 := by
simp
theorem ex : -(no_index (OfNat.ofNat <| nat_lit 2)) = (2 : Int) := by
simp only [Int.reduceNeg]
guard_target = -2 = 2
sorry
theorem its_true_really : -(no_index (OfNat.ofNat <| nat_lit 2)) = -2 := by
rfl
example : -(-(no_index (OfNat.ofNat <| nat_lit 2))) = 2 := by
simp
example : -(no_index (-(no_index (OfNat.ofNat <| nat_lit 2)))) = -(-(-(-3+1))) := by
simp