Zulip Chat Archive

Stream: new members

Topic: Need help with element from range having wrong type


Kevin Cheung (Mar 20 2024 at 14:21):

I am trying to do the following:

import Mathlib.Data.Real.Basic
import Mathlib.Data.Finset.Basic

open Finset

example (n : ) (a : range n  ) :  i  range n, a i  abs (a i) := by sorry

Lean is complaining that i has incorrect type:

application type mismatch
  a i
argument
  i
has type
   : Type
but is expected to have type
  { x // x  range n } : TypeLean 4
i : 

To fix it, I could do:

example (n : ) (a :   ) :  i  range n, a i  abs (a i) := by sorry

But is there a way to make the original version work?

Ruben Van de Velde (Mar 20 2024 at 14:26):

If you're going to coerce range n to a type anyway, you might use ∀ i : range n

Kevin Cheung (Mar 20 2024 at 14:38):

It works. Thanks. But I am a bit confused about the difference. So how does i ∈ range n differ from i : range n?

Ruben Van de Velde (Mar 20 2024 at 15:10):

One is i : Nat with a separate membership hypothesis, the other has the membership bundled up in a Subtype

Kevin Cheung (Mar 20 2024 at 20:38):

Does that mean that in ∑ i in range 4, h i, the index i will be a Nat and the property that i satisfies (i.e. 0 <= i < 4) is inaccessible?

Ruben Van de Velde (Mar 20 2024 at 20:44):

In that context, yes. You can use Finset.attach

Yaël Dillies (Mar 20 2024 at 22:02):

I am working to make ∑ hi : i ∈ range 4, h i notation be the version you want


Last updated: May 02 2025 at 03:31 UTC