@@ -6,10 +6,8 @@ Authors: Sebastian Graf
66module
77
88prelude
9- public import Lean.Meta.Tactic.Simp.Types
9+ public import Lean.Meta.Tactic.FunInd
1010public import Lean.Meta.Match.MatcherApp.Transform
11- public import Lean.Data.Array
12- import Lean.Meta.Match.Rewrite
1311import Lean.Meta.Tactic.Simp.Rewrite
1412import Lean.Meta.Tactic.Assumption
1513
@@ -51,40 +49,36 @@ def altInfos (info : SplitInfo) : Array (Nat × Expr) := match info with
5149 | matcher matcherApp => matcherApp.altNumParams.mapIdx fun idx numParams =>
5250 (numParams, matcherApp.alts[idx]!)
5351
54- def splitWith
52+ def splitWithConstantMotive
5553 {n} [MonadLiftT MetaM n] [MonadControlT MetaM n] [Monad n] [MonadError n] [MonadEnv n] [MonadLog n]
5654 [AddMessageContext n] [MonadOptions n]
57- (info : SplitInfo) (resTy : Expr) (onAlt : Name → Expr → Nat → Array Expr → n Expr) (useSplitter := false ) : n Expr := match info with
55+ (info : SplitInfo) (resTy : Expr) (onAlt : Name → Nat → Array Expr → n Expr) (useSplitter := false ) : n Expr := match info with
5856 | ite e => do
5957 let u ← getLevel resTy
6058 let c := e.getArg! 1
6159 let h := e.getArg! 2
6260 if useSplitter then -- dite is the "splitter" for ite
6361 let n ← liftMetaM <| mkFreshUserName `h
64- let t ← withLocalDecl n .default c fun h => do mkLambdaFVars #[h] (← onAlt `isTrue resTy 0 #[])
65- let e ← withLocalDecl n .default (mkNot c) fun h => do mkLambdaFVars #[h] (← onAlt `isFalse resTy 1 #[])
62+ let t ← withLocalDecl n .default c fun h => do mkLambdaFVars #[h] (← onAlt `isTrue 0 #[])
63+ let e ← withLocalDecl n .default (mkNot c) fun h => do mkLambdaFVars #[h] (← onAlt `isFalse 1 #[])
6664 return mkApp5 (mkConst ``_root_.dite [u]) resTy c h t e
6765 else
68- let t ← onAlt `isTrue resTy 0 #[]
69- let e ← onAlt `isFalse resTy 1 #[]
66+ let t ← onAlt `isTrue 0 #[]
67+ let e ← onAlt `isFalse 1 #[]
7068 return mkApp5 (mkConst ``_root_.ite [u]) resTy c h t e
7169 | dite e => do
7270 let u ← getLevel resTy
7371 let c := e.getArg! 1
7472 let h := e.getArg! 2
7573 let n ← liftMetaM <| mkFreshUserName `h
76- let t ← withLocalDecl n .default c fun h => do mkLambdaFVars #[h] (← onAlt `isTrue resTy 0 #[h])
77- let e ← withLocalDecl n .default (mkNot c) fun h => do mkLambdaFVars #[h] (← onAlt `isFalse resTy 1 #[h])
74+ let t ← withLocalDecl n .default c fun h => do mkLambdaFVars #[h] (← onAlt `isTrue 0 #[h])
75+ let e ← withLocalDecl n .default (mkNot c) fun h => do mkLambdaFVars #[h] (← onAlt `isFalse 1 #[h])
7876 return mkApp5 (mkConst ``_root_.dite [u]) resTy c h t e
7977 | matcher matcherApp => do
80- let mask := matcherApp.discrs.map (·.isFVar)
81- let maskedDiscrs := Array.mask mask matcherApp.discrs
82- let absMotiveBody ← resTy.abstractM maskedDiscrs
8378 (·.toExpr) <$> matcherApp.transform
8479 (useSplitter := useSplitter) (addEqualities := useSplitter) -- (freshenNames := true)
85- (onMotive := fun xs _body => pure (absMotiveBody.instantiateRev (Array.mask mask xs)))
86- (onAlt := fun idx expAltType params _alt => do
87- onAlt ((`h).appendIndexAfter (idx+1 )) expAltType idx params)
80+ (onMotive := fun _xs _motive => pure resTy)
81+ (onAlt := fun idx _ty params _alt => onAlt ((`h).appendIndexAfter (idx+1 )) idx params)
8882
8983def simpDiscrs? (info : SplitInfo) (e : Expr) : SimpM (Option Simp.Result) := match info with
9084 | dite _ | ite _ => return none -- Tricky because we need to simultaneously rewrite `[Decidable c]`
@@ -108,6 +102,6 @@ def rwIfOrMatcher (idx : Nat) (e : Expr) : MetaM Simp.Result := do
108102 let c := if idx = 0 then c else mkNot c
109103 let .some fv ← findLocalDeclWithType? c
110104 | throwError "Failed to find proof for if condition {c}"
111- rwIfWith (mkFVar fv) e
105+ FunInd. rwIfWith (mkFVar fv) e
112106 else
113- rwMatcher idx e
107+ FunInd. rwMatcher idx e
0 commit comments