Zulip Chat Archive
Stream: general
Topic: Binding power
Patrick Massot (May 10 2019 at 06:54):
I still don't know enough binding power wizardry to do what I want. Say I have a binary operation #
. How can I define it so that f a # b
is parsed as f (a # b)
? I tried putting random numbers where I expect Lean to expect binding powers, but failed.
Patrick Massot (May 10 2019 at 06:54):
Of course f
is meant to be a function
Kenny Lau (May 10 2019 at 06:57):
is there any such operation in Lean?
Kenny Lau (May 10 2019 at 06:57):
iirc not even *
has that priority
Patrick Massot (May 10 2019 at 06:58):
There are a lot of such operations in maths
Johan Commelin (May 10 2019 at 06:58):
They probably want us to use $
...
Patrick Massot (May 10 2019 at 06:59):
I understand that, and actually I've get used to $
and use it a lot now. But the context for this question forbids this trick (we want one file from the perfectoid project to be readable by mathematicians who never saw any proof assistant or functional programming language)
Kenny Lau (May 10 2019 at 07:01):
I'm just pointing out that nothing overrides function application iirc
Rob Lewis (May 10 2019 at 07:10):
You just need to set the binding precedence high enough. But this isn't intended for mathlib, right? This goes against the normal notation customs and I think it would be very confusing.
infix `#`:10000 := has_add.add def f : ℕ → bool := λ x, x < 5 #eval f 2 # 3
Mario Carneiro (May 10 2019 at 07:15):
Application is at precedence level 1024
Mario Carneiro (May 10 2019 at 07:15):
also known confusingly as max
Mario Carneiro (May 10 2019 at 07:16):
many unary prefix and postfix notations are at precedence "max_plus" which is max + 10
Patrick Massot (May 10 2019 at 07:18):
I tried with notation
instead of infix
, I guess this explains I couldn't do it
Patrick Massot (May 10 2019 at 07:18):
but with infix
I get weird type class search issues
Patrick Massot (May 10 2019 at 07:19):
Lean doesn't seem to resolve instances when I use my notation (this has nothing to do with the precedence thing)
Mario Carneiro (May 10 2019 at 07:22):
does using local
notation/infix help?
Patrick Massot (May 10 2019 at 07:22):
Do I need to define a class has_
?
Patrick Massot (May 10 2019 at 07:22):
I'll try the local thing
Patrick Massot (May 10 2019 at 07:23):
it changes nothing
Mario Carneiro (May 10 2019 at 07:23):
details
Patrick Massot (May 10 2019 at 07:26):
notation R `∕` x := ideal.quotient (ideal.span ({x} : set R))
works fine but does not take precedence over function application. infix `∕`:max_plus := λ R x, (ideal.quotient (ideal.span ({x} : set R)))
fails to find comm_ring R
which is obvious
Patrick Massot (May 10 2019 at 07:27):
Note that this is not a regular /
but unicode division sign
Rob Lewis (May 10 2019 at 08:03):
Does it work if you do def idq := λ R x, (ideal.quotient (ideal.span ({x} : set R)))
and then infix `∕`:max_plus := idq
?
Rob Lewis (May 10 2019 at 08:04):
With whatever type class instances you need in idq
.
Rob Lewis (May 10 2019 at 08:05):
Make idq
reducible if necessary.
Last updated: Dec 20 2023 at 11:08 UTC