Skip to content
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

conv: "cannot select argument" with funlike coercions #5871

Closed
kmill opened this issue Oct 28, 2024 · 0 comments · Fixed by #5894
Closed

conv: "cannot select argument" with funlike coercions #5871

kmill opened this issue Oct 28, 2024 · 0 comments · Fixed by #5894
Labels
bug Something isn't working

Comments

@kmill
Copy link
Collaborator

kmill commented Oct 28, 2024

Description

Function coercions are almost impossible to navigate in conv mode.

Context

In this Zulip thread, there's an example of an expression using a function coercion where it's impossible to access the argument to that coerced function using conv mode. Issue #2942 was meant to address this, but it wasn't the root issue, which is instead that the congr lemma generated in this case is too strict.

Steps to Reproduce

class DFunLike (F : Sort _) (α : outParam (Sort _)) (β : outParam <| α → Sort _) where
  /-- The coercion from `F` to a function. -/
  coe : F → ∀ a : α, β a

structure MyFun (α β : Type) where
  toFun : α → β

instance : DFunLike (MyFun α β) α (fun _ => β) where
  coe f := f.toFun

example (a b : Nat) (h : a = b) (f : MyFun Nat Int) : DFunLike.coe f a = DFunLike.coe f b := by
  conv =>
    enter [1, 2] -- cannot select argument

Expected behavior: We select the a argument of the LHS.

Actual behavior: "cannot select argument"

Additional information

It's possible to navigate to the argument by breaking up the application in some way:

example (a b : Nat) (h : a = b) (f : MyFun Nat Int) : DFunLike.coe f a = DFunLike.coe f b := by
  conv =>
    enter [1]
    change (fun a => DFunLike.coe f a) a
    enter [1]
    rw [h]

Versions

Lean 4.12.0, commit c57d054
Target: arm64-apple-darwin24.0.0 macOS

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@kmill kmill added the bug Something isn't working label Oct 28, 2024
github-merge-queue bot pushed a commit that referenced this issue Nov 1, 2024
Specializes the congr lemma generated for the `arg` conv tactic to only
rewrite the chosen argument. This makes it much more likely that the
chosen argument is able to be accessed.

Lets `arg` access the domain and codomain of pi types via `arg 1` and
`arg 2` in more situations. Upstreams `pi_congr` for this from mathlib.

Adds a negative indexing option, where `arg -2` accesses the
second-to-last argument for example, making the behavior of `lhs`
available to `arg`. This works for `enter` as well.

Other improvement: when there is an error in the `enter [...]` tactic,
individual locations get underlined with the error. The tactic info now
also is like `rw`, so you can see the intermediate conv states.

Closes #5871
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant