-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DiscrTree doesn't match lemmas with OfNat.ofNat *
to nat literal keys
#2867
Comments
Regarding option B, I'm not sure the raw literals are allowed to exist without an |
Unfortunately there are some automatically-generated simp lemmas with raw nat literals that we expect to work with lean4/tests/lean/run/bugNatLitDiscrTree.lean Lines 1 to 14 in e29c323
In this test case, the lemma I have a branch implementing option B, but I don't know how to address this issue properly. Ideally |
That sounds like a bug in the generated lemmas to me |
Equation lemmas sometimes end up with unenclosed @[simp] def nondep (n : Nat) : Option Nat :=
match n with
| 0 => some 0
| n+1 => match nondep n with
| some m =>
have : m < n+1 := sorry
match nondep m with
| some r => some r
| none => none
| none => none
#check nondep._eq_1 -- nondep._eq_1 : nondep (OfNat.ofNat (nat_lit 0)) = some 0` I've done a bit of investigating, and it looks like what's happening is:
example : nat_lit 2 = sorry := by
simp only
-- ⊢ 2 = sorryAx ℕ
example : nat_lit 2 = sorry := by
dsimp only -- dsimp made no progress It would be easy enough to add the logic for |
Fixes leanprover#2867 by removing special handling of `OfNat.ofNat` numerals from `DiscrTree`. The special handling was added in 2b8e55c to fix a bug represented in the test `tests/lean/run/bugNatLitDiscrTree.lean`, but with leanprover#2916 fixed, that test case passes without the special handling. Some special handling of `Nat.zero` and `Nat.succ` remains.
Fixes leanprover#2867 by removing special handling of `OfNat.ofNat` numerals from `DiscrTree`. The special handling was added in 2b8e55c to fix a bug represented in the test `tests/lean/run/bugNatLitDiscrTree.lean`, but with leanprover#2916 fixed, that test case passes without the special handling. Some special handling of `Nat.zero` and `Nat.succ` remains.
Fixes leanprover#2867 by removing special handling of `OfNat.ofNat` numerals from `DiscrTree`. The special handling was added in 2b8e55c to fix a bug represented in the test `tests/lean/run/bugNatLitDiscrTree.lean`, but with leanprover#2916 fixed, that test case passes without the special handling. Some special handling of `Nat.zero` and `Nat.succ` remains.
Fixes leanprover#2867 by removing special handling of `OfNat.ofNat` numerals from `DiscrTree`. The special handling was added in 2b8e55c to fix a bug represented in the test `tests/lean/run/bugNatLitDiscrTree.lean`, but with leanprover#2916 fixed, that test case passes without the special handling. Some special handling of `Nat.zero` and `Nat.succ` remains.
What’s the status of this issue? There have been a few recent commits, but |
I think all the commits are in the unmerged #3684, which is awaiting someone to prove that mathlib can be adapted to work with it. |
We use `no_index` to work around special-handling of `OfNat.ofNat` in `DiscrTree`, which has been reported as an issue in #2867 and is currently in the process of being fixed in #3684. As the potential fix seems non-trivial and might need some time to arrive in-tree, we meanwhile add the `no_index` keyword to the problematic subterm. --------- Co-authored-by: Eric Wieser <[email protected]>
See the benchmark in #19388, which while not disastrous is not ideal either. Unless the situation changes with leanprover/lean4#2867, the DiscrTree key would apply to all funlike operations applied to any argument, not just applied to numerals.
`ofNat(n)` is a shorthand for `no_index (OfNat.ofNat n)`. Its purpose is: * To make it easier to remember to write the `no_index` * To add a place to put a hoverable docstrings explaining the complexities * To make it easier to remove the `no_index`es in future if `DiscrTree`s stops needing them around `ofNat` (leanprover/lean4#2867). This is not exhaustive, but is a step in the right direction. For now, I only target (some of) the declarations with a `See note [no_index around OfNat.ofNat]`. Some theorem statements have been corrected in passing. This exposed two Lean bugs relating to not using `Expr.consumeMData`: * leanprover/lean4#6438 * leanprover/lean4#6467 These are made more likely by this PR adding `no_index` to the RHS of equalities, but were already possible to trigger by using `simp [<- _]` on existing theorems with `no_index` on the LHS.
This PR ensures `norm_cast` doesn't fail to act in the presence of `no_index` annotations While #2867 exists, it is necessary to put `no_index` around `OfNat.ofNat` in simp lemmas. This results in extra `Expr.mdata` nodes, which must be removed before checking for `ofNat` numerals.
…r#6438) This PR ensures `norm_cast` doesn't fail to act in the presence of `no_index` annotations While leanprover#2867 exists, it is necessary to put `no_index` around `OfNat.ofNat` in simp lemmas. This results in extra `Expr.mdata` nodes, which must be removed before checking for `ofNat` numerals.
…r#6438) This PR ensures `norm_cast` doesn't fail to act in the presence of `no_index` annotations While leanprover#2867 exists, it is necessary to put `no_index` around `OfNat.ofNat` in simp lemmas. This results in extra `Expr.mdata` nodes, which must be removed before checking for `ofNat` numerals.
Prerequisites
Description
When a
@[simp]
lemma is∀ (n : Nat), P (OfNat.ofNat n)
,simp
fails to apply it to targets likeP 2
due to a bug inDiscrTree
.Context
Zulip thread
This has been requiring us to add
no_index
around every explicit invocation ofOfNat.ofNat
. e.g. leanprover-community/mathlib4#8317MWE
Expected behavior:
simp
should be able to solveMyProp 0
Actual behavior:
simp
makes no progressVersions
4.3.0-rc1
Additional Information
My diagnosis of the issue is that in
DiscrTree
, we are stripping off invocations ofOfNat.ofNat
on numerals, but not on variables.Code stripping it off of numerals:
lean4/src/Lean/Meta/DiscrTree.lean
Lines 167 to 173 in 8cfcf7c
It seems like the possible solutions are:
OfNat.ofNat n
similarly ton + 1
, and convert it to*
when inserting in theDiscrTree
. (Equivalent to placingno_index
around everyOfNat.ofNat
invocation)(OfNat.ofNat n : R)
for an arbitrary ringR
will be tried for every single subexpression of the target(5 : R)
in theDiscrTree
to[OfNat.ofNat, R, 5, *]
rather than simply[5]
Nat.zero
, andNat.succ
into this normal formKey.lit (natVal _)
to additionally search the tree forKey.const OfNat.ofNat 3
and then traverse next few keys appropriatelyOfNat
result types are different. e.g. Searching for lemmas about(5 : R)
whereR
is a variable would turn up results for specific rings(5 : Rat)
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: