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

Nested dot notation x.B.C does not work #6491

Closed
3 tasks done
MichaelStollBayreuth opened this issue Jan 1, 2025 · 6 comments
Closed
3 tasks done

Nested dot notation x.B.C does not work #6491

MichaelStollBayreuth opened this issue Jan 1, 2025 · 6 comments
Labels
RFC Request for comments

Comments

@MichaelStollBayreuth
Copy link

MichaelStollBayreuth commented Jan 1, 2025

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

If there is a declaration A.B.C taking an argument of type A and x : A, then x.B.C results in an error.

Context

See this thread on Zulip.

This comes up in the context of Mathlib, where, e.g.,

def Ideal.Quotient.mk {R : Type u} [CommRing R] (I : Ideal R) : R →+* R ⧸ I

and one would like to write I.Quotient.mk where I : Ideal R.

Steps to Reproduce

def A : Type := Nat

def A.B.C (a : A) : Nat := a

/- invalid field 'B', the environment does not contain 'A.B' -/
example (x : A) : x.B.C = x := rfl

Expected behavior:

x.B.C is interpreted as A.B.C x.

Actual behavior:

An error results.

Versions

4.15.0-rc1 (on (live.lean-lang.org)[https://live.lean-lang.org/#codez=CYUwZgBAghBcEBUCeAHEcC8EByBDALgFCGiRQB0AQuQMIQAUuc0AlM3vphLsQPQC0EAJYA7AG64ANkOAQwQkJNkBySsoA0EfAAt0IcUIBOAexEBbfZ2DGQAZwgjjnAMan8uURGUU1Efr0IQAA9cMxRJdHog5ig2eCCqWggsaNgsQzBJQiA]

Additional Information

May be related to lean4#6400.

In Lean 3, it was possible to write x^.B.C to achieve the desired behavior. This does no longer work (and neither does x.(B.C)). Could x.B.C elaborate as A.B.C x when A.B x does not make sense?

Impact

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

@MichaelStollBayreuth MichaelStollBayreuth added the bug Something isn't working label Jan 1, 2025
@nomeata
Copy link
Collaborator

nomeata commented Jan 1, 2025

Thanks for your input. I'd say this isn't a bug (as the behavior is intended by whoever built it), and more a proposal to change the design.

@nomeata nomeata added RFC Request for comments and removed bug Something isn't working labels Jan 1, 2025
@kmill
Copy link
Collaborator

kmill commented Jan 1, 2025

Given that this is an RFC, I think there needs to be a strong argument why renaming the function to Ideal.quotientMk (or Ideal.quotientMap?) is insufficient.

Algorithmically, the full resolution problem suggested in this RFC is O(C(n)) (where C(n) is the Catalan numbers), which is O(4^n / n^{3/2}). If we allowed x.B.C for A.B.C x, we would need to support the full resolution algorithm because users would be surprised if either of y.D.B.C and x.B.C.E were not resolvable as (y.D).B.C and (x.B.C).E, right?

When there is ambiguity in dot notation resolution, what takes precedence over what? It's easy to come up with examples where both interpretations x.(B.C) and (x.B).C would resolve to something.

In Lean 3, it was possible to write x^.B.C to achieve the desired behavior.

IIRC, the ^. notation was the original notation in Lean 3, which was extended at some point to have the current current behavior. Lean 4 decided to only take the current notation.

Perhaps x.(B.C) would be reasonable modern notation, since it chains with things such as x.(B.C).(D.E).F, and it also would support using swift notation like .(B.C).

@MichaelStollBayreuth
Copy link
Author

Thanks for your input. I'd say this isn't a bug (as the behavior is intended by whoever built it), and more a proposal to change the design.

OK. I find the binary choice between "bug" and "RFC" sometimes a bit inconvenient...

@MichaelStollBayreuth
Copy link
Author

Perhaps x.(B.C) would be reasonable modern notation, since it chains with things such as x.(B.C).(D.E).F, and it also would support using swift notation like .(B.C).

That looks reasonable to me.

@kmill
Copy link
Collaborator

kmill commented Jan 1, 2025

Never mind, I forgot that .(x) is Lean.Parser.Term.inaccessible, so that's not a good choice.

@nomeata
Copy link
Collaborator

nomeata commented Jan 10, 2025

We discussed this proposal, and decided that although there are use-cases where this would be nice to have, but given the increased complexity (e.g. more ambiguities) we decided to reject this proposal.

@Kha Kha closed this as not planned Won't fix, can't repro, duplicate, stale Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request for comments
Projects
None yet
Development

No branches or pull requests

4 participants