Zulip Chat Archive

Stream: new members

Topic: the "have" tactic


Sarah El Boustany (Nov 06 2025 at 19:08):

I am working through Mathematics in Lean and I still haven’t grasped how “have” works exactly. In particular, there’s the solution to this example in section 3 of chapter 1:

import MIL.Common
import Mathlib.Data.Real.Basic
namespace C03S03

section
variable (a b : )

def FnLb (f :   ) (a : ) : Prop :=
   x, a  f x

def FnHasLb (f :   ) :=
   a, FnLb f a

variable (f :   )

example (h :  a,  x, f x < a) : ¬FnHasLb f := by
  rintro a, ha
  rcases h a with x, hx
  have := ha x
  linarith

I don’t know how to unpack what the "have := ha x" means. How come “have” is followed by “:=“ and not “:” like it usually is?

Yaël Dillies (Nov 06 2025 at 19:10):

have := ha x is shorthand for have : _ := ha x. In general, the syntax is have name : type := value and means "Let name be the proof of type as provided by value"

Yaël Dillies (Nov 06 2025 at 19:11):

If you only give value, then Lean can oftentimes recover what type is just from value. This is indeed what's going on in the have name := value syntax

Arthur Paulino (Nov 06 2025 at 19:14):

It's the second time this question comes up btw

Sarah El Boustany (Nov 06 2025 at 19:18):

Thank you for the explanation! I'm sorry I missed the original question, I did try searching through the topics but I guess I didn't know exactly what to filter for

Arthur Paulino (Nov 06 2025 at 19:19):

Oh, I didn't mean you were expected to find the original question, sorry. I'm just saying that #mil doesn't seem to be self-contained enough yet

Arthur Paulino (Nov 06 2025 at 19:24):

Oh, the tactic have has a comprehensive docstring, which shows up on hover:
image.png

Sarah El Boustany (Nov 07 2025 at 09:46):

When I hovered over have I wasn't really sure which case have := ha x fell under. Would it be have pat := e then?

Michael Rothgang (Nov 07 2025 at 09:48):

Hm, that looks like an opportunity to improve the have tactic doc-string!

Philippe Duchon (Nov 07 2025 at 09:49):

Looks like the have := e version: you provide a value (and let Lean figure out the type) and the name will be the default this.

Michael Rothgang (Nov 07 2025 at 09:52):

By the way: have you seen the mathlib tactic manual? It has documentation for all mathlib tactics: https://leanprover-community.github.io/mathlib-manual/html-multi/Tactics/#tactics
If you want to get an overview of "what tactic could help me here", that might be useful.

Michael Rothgang (Nov 07 2025 at 09:52):

There is also a cheat sheet, which is a bit more compact: https://leanprover-community.github.io/papers/lean-tactics.pdf

Sarah El Boustany (Nov 07 2025 at 10:35):

Oh, I hadn't seen that cheatsheet, thank you!


Last updated: Dec 20 2025 at 21:32 UTC