@@ -13,21 +13,30 @@ import Init.Grind.Ring.Field
1313public section
1414namespace Lean.Meta.Grind.Arith
1515
16- private def mkSemiringThm (declName : Name) (α : Expr) : MetaM (Option Expr) := do
16+ def mkSemiringThm (declName : Name) (α : Expr) : MetaM (Option Expr) := do
1717 let some u ← getDecLevel? α | return none
1818 let semiring := mkApp (mkConst ``Grind.Semiring [u]) α
1919 let some semiringInst ← synthInstanceMeta? semiring | return none
2020 return mkApp2 (mkConst declName [u]) α semiringInst
2121
2222/--
23- Applies `a^(m+n) = a^m * a^n`, `a^ 0 = 1`, `a^1 = a`.
23+ Applies `a^0 = 1`, `a^1 = a`.
2424
2525We do normalize `a^0` and `a^1` when converting expressions into polynomials,
2626but we need to normalize them here when for other preprocessing steps such as
2727`a / b = a*b⁻¹`. If `b` is of the form `c^1`, it will be treated as an
28- atom in the comm ring module.
28+ atom in the ring module.
29+
30+ **Note** : We used to expand `a^(n+m)` here, but it prevented `grind` from solving
31+ simple problems such as
32+ ```
33+ example {k : Nat} (h : k - 1 + 1 = k) :
34+ 2 ^ (k - 1 + 1) = 2 ^ k := by
35+ grind
36+ ```
37+ We now use a propagator for `a^(n+m)` which adds the `a^n*a^m` to the equivalence class.
2938-/
30- builtin_simproc_decl expandPowAdd (_ ^ _) := fun e => do
39+ builtin_simproc_decl expandPow01 (_ ^ _) := fun e => do
3140 let_expr HPow.hPow α nat α' _ a k := e | return .continue
3241 let_expr Nat ← nat | return .continue
3342 if let some k ← getNatValue? k then
@@ -42,13 +51,7 @@ builtin_simproc_decl expandPowAdd (_ ^ _) := fun e => do
4251 return .done { expr := a, proof? := some (mkApp h a) }
4352 else
4453 return .continue
45- else
46- let_expr HAdd.hAdd _ _ _ _ m n := k | return .continue
47- unless (← isDefEq α α') do return .continue
48- let some h ← mkSemiringThm ``Grind.Semiring.pow_add α | return .continue
49- let pwFn := e.appFn!.appFn!
50- let r ← mkMul (mkApp2 pwFn a m) (mkApp2 pwFn a n)
51- return .visit { expr := r, proof? := some (mkApp3 h a m n) }
54+ return .continue
5255
5356private def notField : Std.HashSet Name :=
5457 [``Nat, ``Int, ``BitVec, ``UInt8, ``UInt16, ``UInt32, ``Int64, ``Int8, ``Int16, ``Int32, ``Int64].foldl (init := {}) (·.insert ·)
@@ -185,7 +188,7 @@ Add additional arithmetic simprocs
185188-/
186189
187190def addSimproc (s : Simprocs) : CoreM Simprocs := do
188- let s ← s.add ``expandPowAdd (post := true )
191+ let s ← s.add ``expandPow01 (post := true )
189192 let s ← s.add ``expandDiv (post := true )
190193 let s ← s.add ``normNatAddInst (post := false )
191194 let s ← s.add ``normNatMulInst (post := false )
0 commit comments