Zulip Chat Archive

Stream: new members

Topic: How to use Finset.Nonempty.cons_induction in induction using


Kevin Cheung (Jun 04 2024 at 14:42):

I have the following which works:

import Mathlib.Algebra.BigOperators.Basic

open BigOperators
open Finset

def p := fun (T : Finset )  fun (_ : T.Nonempty)  ( s  T, s > 0)  ( s in T, s) > 0

example (T : Finset ) (g : T.Nonempty) : p T g := by
  apply Nonempty.cons_induction
  . simp [p]
  . intro a s
    intro a' hs ih
    simp [p]
    intro a'' _
    have :  x in insert a s, x = a +  x in  s, x  := by exact sum_insert a'
    rw [this]
    simp [p] at ih
    exact Nat.add_pos_left a'' ( x in s, x)

It seems to me that apply Nonempty.cons_induction can be replaced with induction...using. My attempt is

example (T : Finset ) (g : T.Nonempty) : p T g := by
  induction g using Nonempty.cons_induction with
  | _ a => sorry

But I have a feeling that this is wrong. First, g is not a set so the induction on g doesn't seem to make sense. But putting T there gives the error
target T has type Finset ℕ : Type but is expected to have type ?m.12030.Nonempty : Prop
Second, I cannot replace the underscore in | _ a with any letter as it would complain that it is an invalid alternate name. I don't know what is supposed to be a valid alternate name there.

In any case, I am probably not understanding how to make use of induction...using in this context. Any help is greatly appreciated.

Yaël Dillies (Jun 04 2024 at 14:44):

What does induction T using g.cons_induction with do?

Kevin Cheung (Jun 04 2024 at 14:45):

It says unknown constant 'g.cons_induction'

Yaël Dillies (Jun 04 2024 at 14:46):

That's what I thought as well. I think it's safe to say it's not supported.

Yaël Dillies (Jun 04 2024 at 14:46):

Try induction T using Nonempty.cons_induction with, just in case

Kevin Cheung (Jun 04 2024 at 14:47):

That gives the error message I quoted:

target
  T
has type
  Finset  : Type
but is expected to have type
  ?m.12030.Nonempty : Prop

Yaël Dillies (Jun 04 2024 at 14:49):

I give up :sad:

Kevin Cheung (Jun 04 2024 at 14:50):

That's ok. I am just puzzled by what induction...using expects from an induction principle. I don't think I get what it actually does.

Eric Wieser (Jun 04 2024 at 18:01):

Your mwe doesn't work for me, the imports don't exist

Ruben Van de Velde (Jun 04 2024 at 18:02):

That's probably Yaël's fault :)

Eric Wieser (Jun 04 2024 at 18:02):

induction g using Nonempty.cons_induction works for me

Kevin Cheung (Jun 04 2024 at 18:03):

Lean doesn't complain about that as I mentioned in the post. But I couldn't figure out how to proceed.

Kevin Cheung (Jun 04 2024 at 18:05):

I don't understand what the underscore in | _ a => is doing; I couldn't figure out what that hole could stand for.

Ruben Van de Velde (Jun 04 2024 at 18:10):

Oh, you need

| singleton a => sorry
| cons a s ha hs ih => sorry

Kevin Cheung (Jun 04 2024 at 18:11):

Thanks. How did you figure that out? (Or maybe, how should I have figured that out?)

Kevin Cheung (Jun 04 2024 at 18:11):

Hmm. I wonder why the import of Mathlib.Algebra.BigOperators.Basic worked in my VScode but not on the web lean 4 playground.

Kevin Cheung (Jun 04 2024 at 18:13):

import Mathlib.Algebra.BigOperators.Fin works in both. How did I even end up with .Basic?

Ruben Van de Velde (Jun 04 2024 at 18:14):

The file was moved very recently

Kevin Cheung (Jun 04 2024 at 18:15):

Oh. So it no longer exists?

Ruben Van de Velde (Jun 04 2024 at 18:15):

I looked at docs#Finset.Nonempty.cons_induction , which has two explicit arguments - singleton and cons

Ruben Van de Velde (Jun 04 2024 at 18:16):

#13277

Ruben Van de Velde (Jun 04 2024 at 18:16):

Split into Algebra.BigOperators.Group.Finset and Algebra.BigOperators.GroupWithZero.Finset

Kevin Cheung (Jun 04 2024 at 18:16):

So that means the Mathlib in my project is outdated. Now I guess I have to dig up how to update it.

Ruben Van de Velde (Jun 04 2024 at 18:17):

https://github.com/leanprover-community/mathlib4/wiki/Using-mathlib4-as-a-dependency#updating-mathlib4

Kevin Cheung (Jun 04 2024 at 18:20):

Ruben Van de Velde said:

I looked at docs#Finset.Nonempty.cons_induction , which has two explicit arguments - singleton and cons

induction...using seems a bit magical to me. When it is invoked, does it create as many cases as there are things before the colon in the induction principle?

Ruben Van de Velde (Jun 04 2024 at 18:32):

That's as far as my understanding goes as well

Ruben Van de Velde (Jun 04 2024 at 18:33):

I only use it, I don't claim to understand it :)

Kevin Cheung (Jun 04 2024 at 18:33):

Thank you for your help. Maybe I should not try to understand it too much.


Last updated: May 02 2025 at 03:31 UTC