This PR fixes a kernel error in `grind` when propagating a `Nat`
equality to an order structure whose carrier type is not `Int` (e.g.
`Rat`). The auxiliary `Lean.Grind.Order.of_nat_eq` lemma was specialized
to `Int`, so the kernel rejected the application when the cast
destination differed.
We add a polymorphic `of_natCast_eq` lemma over `{α : Type u} [NatCast
α]` and cache the cast destination type in `TermMapEntry`.
`processNewEq` now uses the original `of_nat_eq` when the destination is
`Int` (the common case) and the new lemma otherwise. The symmetric
`nat_eq` propagation (deriving `Nat` equality from a derived cast
equality) is now guarded to fire only when the destination is `Int`,
since the `nat_eq` lemma is still specialized to `Int`.
Closes #13265.
35 lines
1.4 KiB
Text
35 lines
1.4 KiB
Text
open Lean Grind Std
|
||
|
||
example [LE α] [IsPartialOrder α] (a b : α) (f : α → Nat) : a ≤ b → b ≤ c → c ≤ a → f a = f b := by
|
||
grind (splits := 0)
|
||
|
||
example [CommRing α] [LE α] [LT α] [LawfulOrderLT α] [IsPartialOrder α] [OrderedRing α]
|
||
(a b : α) (f : α → Int) : a ≤ b + 1 → b ≤ a - 1 → f a = f (2 + b - 1) := by
|
||
grind -mbtc -lia -linarith (splits := 0)
|
||
|
||
example (a b : Int) (f : Int → Int) : a ≤ b + 1 → b ≤ a - 1 → f a = f (2 + b - 1) := by
|
||
grind -mbtc -lia -linarith (splits := 0)
|
||
|
||
example (a b : Nat) (f : Nat → Int) : a ≤ b + 1 → b + 1 ≤ a → f a = f (1 + b + 0) := by
|
||
grind -mbtc -lia -linarith (splits := 0)
|
||
|
||
example (a b : Nat) (f : Nat → Int) : a ≤ b + 1 → b + 1 ≤ c → c ≤ a → f a = f c := by
|
||
grind -mbtc -lia -linarith (splits := 0)
|
||
|
||
example (a b : Nat) (f : Nat → Int) : a ≤ b + 1 → b + 1 ≤ a → f (1 + a) = f (1 + b + 1) := by
|
||
grind -mbtc -lia -linarith (splits := 0)
|
||
|
||
example
|
||
: 2*n_1 + a = 1 → 2*n_1 + a = n_2 + 1 → n = 1 → n = n_3 + 1 → n_2 ≠ n_3 → False := by
|
||
grind -lia -linarith -ring (splits := 0)
|
||
|
||
example
|
||
: a = b → a ≤ b + 1 := by
|
||
grind -lia -linarith -ring (splits := 0) only
|
||
|
||
example
|
||
: a = b + 1 → a ≤ b + 2 := by
|
||
grind -lia -linarith -ring (splits := 0) only
|
||
|
||
-- Issue #13265: kernel error from `of_nat_eq` when the cast is to a non-`Int` type.
|
||
example (j k : Nat) (h : j = k) : (j + 1 : Rat) = (k + 1 : Rat) := by grind
|