Zulip Chat Archive

Stream: general

Topic: How to get the name of the inductive hypothesis


Bolton Bailey (Sep 10 2023 at 04:30):

After mathport, my lemma looks like this, and shows an error.

theorem MvPolynomial.mul_x_pow_eq_zero {σ R : Type _} [CommSemiring R] {s : σ} (d : )
    (p : MvPolynomial σ R) (h : MvPolynomial.X s ^ d * p = 0) : p = 0 :=
  by
  induction d
  · simp at h
    exact h
  · apply d_ih -- unknown identifier 'd_ih'
    rw [pow_succ] at h
    apply MvPolynomial.mul_x_eq_zero s
    rw [ mul_assoc]
    exact h

When I mouse over induction I get a docstring saying "You can use with to provide the variables names for each constructor." But how do I do this?

theorem MvPolynomial.mul_x_pow_eq_zero {σ R : Type _} [CommSemiring R] {s : σ} (d : )
    (p : MvPolynomial σ R) (h : MvPolynomial.X s ^ d * p = 0) : p = 0 :=
  by
  induction d with d d_ih -- unknown tactic
  · simp at h
    exact h
  · apply d_ih
    rw [pow_succ] at h
    apply MvPolynomial.mul_x_eq_zero s
    rw [ mul_assoc]
    exact h

Bolton Bailey (Sep 10 2023 at 04:33):

Seems like the right way is

theorem MvPolynomial.mul_x_pow_eq_zero {σ R : Type _} [CommSemiring R] {s : σ} (d : )
    (p : MvPolynomial σ R) (h : MvPolynomial.X s ^ d * p = 0) : p = 0 :=
  by
  induction d with
  | zero =>
    simp at h
    exact h
  | succ x' d_ih =>
    apply d_ih
    rw [pow_succ] at h
    apply MvPolynomial.mul_x_eq_zero s
    rw [ mul_assoc]
    exact h

Bolton Bailey (Sep 10 2023 at 04:35):

I was very confused by the docstring, in the last bullet point it seems like it's saying I can only use one tactic to close my goal for each case.

Bolton Bailey (Sep 10 2023 at 04:46):

I'm not actually sure where that docstring lives, I can't find it in either of the lean4 or mathlib4 repos.

Damiano Testa (Sep 10 2023 at 06:45):

This is not exactly an answer to your question, but, if you leave the cursor at the end of the "inducted" variable, you should get a code-action.
image.png

If you click on the lightbulb and then on Generate... you will get a template that you can fill in. This is what the template looks like:

example (d : Nat) : d = 0 := by
  induction d with
  | zero => sorry
  | succ n ih => sorry

Bolton Bailey (Sep 22 2023 at 12:48):

I almost never use this feature, so it is not very helpful to me.

I want to point out that cases also has the same problem. I would really like to make a PR to whatever thing provides the text for these tooltips but I can't find it.

Bolton Bailey (Sep 22 2023 at 12:53):

Also now that I try it, this lightbulb is destroying the line of code after where it inserts the example.

Henrik Böving (Sep 22 2023 at 12:54):

Damiano Testa said:

This is not exactly an answer to your question, but, if you leave the cursor at the end of the "inducted" variable, you should get a code-action.
image.png

If you click on the lightbulb and then on Generate... you will get a template that you can fill in. This is what the template looks like:

example (d : Nat) : d = 0 := by
  induction d with
  | zero => sorry
  | succ n ih => sorry

Are these code actions defined by std, mathlib or built-in?

Patrick Massot (Sep 22 2023 at 14:15):

std

Henrik Böving (Sep 22 2023 at 14:16):

Do we have plans to upstream this eventually?

Patrick Massot (Sep 22 2023 at 14:19):

You'll need to ask Mario.

Henrik Böving (Sep 22 2023 at 14:19):

@Mario Carneiro bonk

Patrick Massot (Sep 22 2023 at 14:20):

More specific answer to "where is it?" is here

Mario Carneiro (Sep 22 2023 at 19:52):

what's the question?

Patrick Massot (Sep 22 2023 at 20:18):

Henrik Böving said:

Do we have plans to upstream this eventually?

Mario Carneiro (Sep 22 2023 at 20:20):

to core? no

Mario Carneiro (Sep 22 2023 at 20:21):

this seems like an example of something that is suitable for std long-term: it's not necessary for the compiler but is a clear value add on the language

Mario Carneiro (Sep 22 2023 at 20:23):

I mean, it would be nice to have it in core development but only insofar as anything in std is a nice to have. I would rather solve that by putting std in the bootstrap and that's a far future thing

Bolton Bailey (Sep 23 2023 at 13:32):

When I use the tooltip doing induction on a list, I get

  induction l generalizing n with
  | α => sorry
  | nil => sorry
  | cons head tail ih => sorry

What is this | α => sorry part? Evidently I don't need it, because I can delete it and prove the other ones normally.

Eric Wieser (Sep 23 2023 at 13:35):

https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Nonsense.20autocomplete.20of.20.60cases.20with.60/near/391116492

Kevin Buzzard (Sep 23 2023 at 13:54):

Is there an open issue for this? Where does it go, if not?

Bolton Bailey (Sep 23 2023 at 13:56):

Well according to Patrick's comment, this lives in std4.

Bolton Bailey (Sep 23 2023 at 13:57):

I'm not sure if this is separate from or related to the tooltip eating my code. Maybe there need to be two issues?

Kevin Buzzard (Sep 23 2023 at 14:05):

std4#270 , hopefully this is useful and in the right place.

Patrick Massot (Sep 23 2023 at 14:11):

You wrote "tooltip" where you meant "code action".

Kevin Buzzard (Sep 23 2023 at 14:30):

oh jeez I just copied from someone else. What do these mean, and which is which?

Kevin Buzzard (Sep 23 2023 at 14:31):

Hopefully I fixed it. So a code action is a lightbulb and a tooltip is...not sure.

Patrick Massot (Sep 23 2023 at 14:38):

Tooltip is whatever you see when you let your mouse pointer over something and a little piece of information shows up.


Last updated: Dec 20 2023 at 11:08 UTC