Zulip Chat Archive

Stream: lean4

Topic: convert the index set of the summation into an assumption?


Yifan Bai (Sep 21 2024 at 16:55):

Excuse me~ This is my first time using zulip, seeking for some help :face_holding_back_tears:
How to convert the index set of the summation into a hypothesis?

def φ_sum (t : Set E) (ht : t.Finite) (φ : (x : E)  x  ht.toFinset    ) :=
   x  ht.toFinset, φ x _

Here the position of the placeholder needs the assumption x ∈ ht.toFinset, how to achieve this?

Ruben Van de Velde (Sep 21 2024 at 17:10):

Probably ht.toFinset.attach

Etienne Marion (Sep 21 2024 at 17:12):

I don't know how to do exactly this, but let me give you two different ways to write it which I think are more idiomatic.

The first one is to use a function which is defined everywhere, event if out of the set you're interested in you put a junk value:

import Mathlib

variable {E : Type*}

noncomputable def φ_sum (t : Set E) (ht : t.Finite) (φ : E    ) :=
   x  ht.toFinset, φ x

The second way is to consider a function whose domain is the set you're interested in, namely something like φ : ht.toFinset → ℝ → ℝ. This works because ht.toFinset will automatically be considered as a type, and an element x : ht.toFinset is a pair whose first component is the underlying element in E, and the second one is a proof that this element is in ht.toFinset. Those can be obtained via x.1 : E and x.2 : x.1 ∈ ht.toFinset. If you use such a function you can directly write a sum indexed by the type ht.toFinset:

import Mathlib

variable {E : Type*}

noncomputable def φ_sum (t : Set E) (ht : t.Finite) (φ : ht.toFinset    ) :=
   x : ht.toFinset, φ x

The noncomputable is just here to tell Lean that you're definition needs some classical reasoning to be defined.

Moritz Firsching (Sep 21 2024 at 17:19):

you could also consider using ∑'

noncomputable def φ_sum (t : Set E) (ht : t.Finite) (g : (x : E)  x  ht.toFinset    ) :=
   ∑' x : t, g x (by aesop)

Yifan Bai (Sep 22 2024 at 02:37):

Etienne Marion said:

I don't know how to do exactly this, but let me give you two different ways to write it which I think are more idiomatic.

The first one is to use a function which is defined everywhere, event if out of the set you're interested in you put a junk value:

import Mathlib

variable {E : Type*}

noncomputable def φ_sum (t : Set E) (ht : t.Finite) (φ : E    ) :=
   x  ht.toFinset, φ x

The second way is to consider a function whose domain is the set you're interested in, namely something like φ : ht.toFinset → ℝ → ℝ. This works because ht.toFinset will automatically be considered as a type, and an element x : ht.toFinset is a pair whose first component is the underlying element in E, and the second one is a proof that this element is in ht.toFinset. Those can be obtained via x.1 : E and x.2 : x.1 ∈ ht.toFinset. If you use such a function you can directly write a sum indexed by the type ht.toFinset:

import Mathlib

variable {E : Type*}

noncomputable def φ_sum (t : Set E) (ht : t.Finite) (φ : ht.toFinset    ) :=
   x : ht.toFinset, φ x

The noncomputable is just here to tell Lean that you're definition needs some classical reasoning to be defined.

Yeah if the type is like this then it will be convenient, but here I get ϕ\phi by such a theorem: ∀ x ∈ t.toFinset, ∃ η ∈ ℝ, ∃ φ ∈ A η, ..., where AA is a set of function. I use choose to get η\eta and ϕ\phi, then the type of $\eta$ will be (x : E) → x ∈ t.toFinset → ℝ automatically, and the type of ϕ\phi will be (x : E) → x ∈ t.toFinset → ℝ → ℝ..

Yifan Bai (Sep 22 2024 at 02:39):

Moritz Firsching said:

you could also consider using ∑'

noncomputable def φ_sum (t : Set E) (ht : t.Finite) (g : (x : E)  x  ht.toFinset    ) :=
   ∑' x : t, g x (by aesop)

This method truly works, thank you very much! :saluting_face:

Etienne Marion (Sep 22 2024 at 06:32):

What you want to do in that case is rather to use the tactic choose!, which will get rid of the dependency

Yifan Bai (Sep 23 2024 at 03:22):

@Etienne Marion Thank you! It's amazing, this is what I really needs, thank you very much!


Last updated: May 02 2025 at 03:31 UTC