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

Slow elaboration of simple equation with overloaded operator #5540

Closed
nomeata opened this issue Sep 30, 2024 · 1 comment
Closed

Slow elaboration of simple equation with overloaded operator #5540

nomeata opened this issue Sep 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@nomeata
Copy link
Contributor

nomeata commented Sep 30, 2024

In the context of Terry Tao’s equational_theories project, we are look at a few thousand equations defined like Equation374794 here:

universe u

class Magma (α : Type u) where
  /-- `a ∘ b` computes a binary operation of `a` and `b`. -/
  op : α → α → α

@[inherit_doc] infixl:65 ""   => Magma.op

-- 48ms
abbrev Equation374794 (G : Type u) [Magma G] := ∀ x y z : G, x = (((y ∘ y) ∘ y) ∘ x) ∘ ((y ∘ y) ∘ z)

-- 1ms
abbrev Equation374794_ (G : Type u) [inst: Magma G] := ∀ x y z : G, x = inst.op (inst.op (inst.op (inst.op y y)  y) x) (inst.op (inst.op y y) z)

Unfortunately, elaboration is surprisingly slow for these relative simple definitions, and I had to work around it by writing a custom elaborator that replaces with op.inst, so likely the issue is with type class inference.

Is there some low-hanging fruit we can pluck in lean here so that such definitions work just fine? Probably needs someone with good profiling skills to have a look.

Versions

4.12.0-nightly-2024-09-30

Impact

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

@nomeata nomeata added the bug Something isn't working label Sep 30, 2024
@nomeata
Copy link
Contributor Author

nomeata commented Oct 1, 2024

Ok, had a closer look, and the reason this is slow because already exists as function composition, and it tries both in each instance, so probably something exponential is going on. Using a different symbol it elaborates in 3ms. Still slower than the explicit one, but at least bearable.

@nomeata nomeata closed this as completed Oct 1, 2024
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

No branches or pull requests

1 participant