Zulip Chat Archive

Stream: general

Topic: avoid typing the same thing 7 times without using let


Kenny Lau (Apr 08 2020 at 20:06):

I've just figured a way to avoid typing the same thing 7 times without using let:

def test :  :=
(λ n, n * n + 2 * n + 1) 123456789

Reid Barton (Apr 08 2020 at 20:15):

I think have is actually syntax for this

Kenny Lau (Apr 08 2020 at 20:25):

but have doesn't remember definition

Kenny Lau (Apr 08 2020 at 20:25):

this is a way to have abbreviations without breaking anything (if you use let, you'll have a hard time working in tactic mode)

Simon Hudon (Apr 08 2020 at 20:39):

What can you do with this that you can't do with a let?

Kenny Lau (Apr 08 2020 at 20:43):

you can substitute this easily using beta reduction, which is automatically performed by many tactics

Kenny Lau (Apr 08 2020 at 20:43):

my personal experience tells me that let is hard to work with

Kevin Buzzard (Apr 08 2020 at 20:47):

If you use let and then go into tactic mode then sometimes your goals come out really kooky.

Ryan Lahfa (Apr 08 2020 at 20:56):

Kenny Lau said:

but have doesn't remember definition

set can work too AFAIK

Kenny Lau (Apr 08 2020 at 20:57):

I'm not abbreviating in the middle of a proof. It's in the definition of some data.

Kenny Lau (Apr 08 2020 at 21:13):

Simon Hudon said:

What can you do with this that you can't do with a let?

to be more specific:

def test :  :=
(λ n, n * n + 2 * n + 1) 123456789

def test' :  :=
let n := 123456789 in n * n + 2 * n + 1

example : test = 0 := by unfold test    -- ⊢ 123456789 * 123456789 + 2 * 123456789 + 1 = 0
example : test' = 0 := by unfold test'  -- ⊢ (let n : ℕ := 123456789 in n * n + 2 * n + 1) = 0

Kevin Buzzard (Apr 08 2020 at 21:15):

kooky goal alert

Kenny Lau (Apr 08 2020 at 21:16):

is "kooky" pronounced the same as "cookie"?

Kevin Buzzard (Apr 08 2020 at 21:19):

It's pronounced the way cookie monster says cookie.

Kenny Lau (Apr 08 2020 at 21:20):

but it's almost spelt the same; English is weird

Reid Barton (Apr 08 2020 at 21:51):

def test'' :  :=
have n :  := 123456789, n * n + 2 * n + 1

example : test'' = 0 := by unfold test''  -- ⊢ 123456789 * 123456789 + 2 * 123456789 + 1 = 0

Reid Barton (Apr 08 2020 at 21:52):

def test₂ :=
(λ n, (rfl : n = 0)) 0          -- invalid type ascription

def test₂' :=
let n := 0 in (rfl : n = 0)

The lambda "forgets" the definition in the same way that have does.

Kenny Lau (Apr 08 2020 at 21:53):

wow. when I use the underscore I don't see 123456789:

def test'' :  :=
have n :  := 123456789, _
/-
don't know how to synthesize placeholder
context:
n : ℕ
⊢ ℕ
-/

Reid Barton (Apr 08 2020 at 21:54):

Inside the body you "don't know" what the value of n is. Outside you do.

Mario Carneiro (Apr 08 2020 at 22:16):

I can confirm Reid's first comment: have is sugar for this expression. let requires additional magic, but morally it is syntax for the result of substituting the variable, which is why you get the defeq inside the body

Mario Carneiro (Apr 08 2020 at 22:19):

Fun fact, have inside tactic mode is neither of these, it is actually performing the substitution. So the result contains no redexes at the end:

def test :  :=
by have n := 123456789; exact n * n + 2 * n + 1

#print test -- 123456789 * 123456789 + 2 * 123456789 + 1

Kevin Buzzard (Apr 08 2020 at 22:26):

What's a redex? This funny (let x = y in z) thing which I sometimes see in goals?

Mario Carneiro (Apr 08 2020 at 22:28):

redex is a shortening for "reducible expression", and it refers to when there is a piece of the term that can be directly simplified by one of the "greek rules". For example 1 + 2 = (\lam x, x) 3 contains a beta redex, and f = g \circ (\lam x, h x) contains an eta redex

Mario Carneiro (Apr 08 2020 at 22:29):

a let expression is always a redex (a zeta redex, if you care) because there is a rule that simplifies it to z[y/x]


Last updated: Dec 20 2023 at 11:08 UTC