Zulip Chat Archive

Stream: general

Topic: match in defs


Chris Hughes (Apr 02 2018 at 15:46):

Out of the following two definitions, I find the first much easier to use.

private  def  mul_aux : α × S  α × S  loc α S :=
λ x y, x.1  * y.1, x.2.1  * y.2.1, is_submonoid.mul_mem x.2.2 y.2.2

private def mul_aux : α × S  α × S  loc α S :=
λ r₁, s₁, hs₁ r₂, s₂, hs₂, r₁ * r₂, s₁ * s₂, is_submonoid.mul_mem hs₁ hs₂

The first one unfolds much more easily if I give it arguments either of the form x y but also works okay with ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ as arguments. What are the advantages/disadvantages of each approach?

Kevin Buzzard (Apr 02 2018 at 19:07):

Let me make the comment that in the past, when I have used pointy brackets and lambdas when writing a definition, I've found it much more difficult to prove things by rfl because high powered stuff is going on behind the scenes.

Chris Hughes (Apr 02 2018 at 20:52):

Essentially, I think it's because λ ⟨r₁, s₁, hs₁⟩ uses prod.rec and subtype.rec, or the various derived lemmas like subtype.cases_on and these don't reduce to anything unless you give them something of the form subtype.mk _ _ The first def will unfold when the arguments are not of the form subtype.mk _ _

Kenny Lau (Apr 02 2018 at 20:59):

don't use any pointy brackets or tactics in a definition

Simon Hudon (Apr 03 2018 at 00:12):

Any reason not to want this?

private def mul_aux : α × S → α × S → loc α S
| ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ := ⟦⟨r₁ * r₂, s₁ * s₂, is_submonoid.mul_mem hs₁ hs₂⟩⟧

It only unfolds with explicit tuples, unlike the first alternative. In the second alternative, it will unfold to a useless auxiliary definition.

Kenny Lau (Apr 03 2018 at 00:13):

it's private

Simon Hudon (Apr 03 2018 at 00:13):

Why is that relevant?

Kenny Lau (Apr 03 2018 at 00:15):

it isn't

Simon Hudon (Apr 03 2018 at 00:16):

Why was that your response to my question then?

Kenny Lau (Apr 03 2018 at 00:18):

it wasn't

Kenny Lau (Apr 03 2018 at 00:19):

it's relevant because I'm not going to unfold that definition except in the definition of multiplication

Kenny Lau (Apr 03 2018 at 00:20):

and I only need to use its properties, not its definition

Simon Hudon (Apr 03 2018 at 00:21):

Are you saying that the whole conversation is pointless?

Kenny Lau (Apr 03 2018 at 00:22):

he's asking about one of my definitions

Kenny Lau (Apr 03 2018 at 00:22):

I don't know why he's doing that

Simon Hudon (Apr 03 2018 at 00:22):

ok

Kenny Lau (Apr 03 2018 at 00:22):

Are you saying that the whole conversation is pointless?

• <-- there you go, a point

Simon Hudon (Apr 03 2018 at 00:27):

Sorry that, was the wrong place to write that.

Kenny Lau (Apr 03 2018 at 00:27):

sorry


Last updated: Dec 20 2023 at 11:08 UTC