-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace
ite
and dite
shortcircuit theorems with simproc
Motivation: better `simp` cache behavior. Recall that `simp` cache uses `dischargeDepth`.
- Loading branch information
1 parent
c54807d
commit 7d72ad0
Showing
4 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/- | ||
Copyright (c) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura | ||
-/ | ||
import Lean.Meta.Tactic.Simp.Simproc | ||
|
||
open Lean Meta Simp | ||
|
||
builtin_simproc ↓ reduceIte (ite _ _ _) := fun e => do | ||
unless e.isAppOfArity' ``ite 5 do return none | ||
let c := e.getArg! 1 | ||
let r ← simp c | ||
if r.expr.isConstOf ``True then | ||
let eNew := e.getArg! 3 | ||
let pr := mkApp (mkAppN (mkConst ``ite_cond_eq_true e.getAppFn.constLevels!) e.getAppArgs) (← r.getProof) | ||
return some (.visit { expr := eNew, proof? := pr }) | ||
if r.expr.isConstOf ``False then | ||
let eNew := e.getArg! 4 | ||
let pr := mkApp (mkAppN (mkConst ``ite_cond_eq_false e.getAppFn.constLevels!) e.getAppArgs) (← r.getProof) | ||
return some (.visit { expr := eNew, proof? := pr }) | ||
return none | ||
|
||
builtin_simproc ↓ reduceDite (dite _ _ _) := fun e => do | ||
unless e.isAppOfArity' ``dite 5 do return none | ||
let c := e.getArg! 1 | ||
let r ← simp c | ||
if r.expr.isConstOf ``True then | ||
let pr ← r.getProof | ||
let h := mkApp2 (mkConst ``of_eq_true) e pr | ||
let eNew := mkApp (e.getArg! 3) h |>.headBeta | ||
let prNew := mkApp (mkAppN (mkConst ``dite_cond_eq_true e.getAppFn.constLevels!) e.getAppArgs) pr | ||
return some (.visit { expr := eNew, proof? := prNew }) | ||
if r.expr.isConstOf ``False then | ||
let pr ← r.getProof | ||
let h := mkApp2 (mkConst ``of_eq_false) e pr | ||
let eNew := mkApp (e.getArg! 4) h |>.headBeta | ||
let prNew := mkApp (mkAppN (mkConst ``dite_cond_eq_false e.getAppFn.constLevels!) e.getAppArgs) pr | ||
return some (.visit { expr := eNew, proof? := prNew }) | ||
return none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters