Zulip Chat Archive

Stream: lean4

Topic: Is it possible to do (Vector n).mk?


Alok Singh (May 09 2024 at 08:20):

I have this:

structure Vector (n : Nat) (Scalar := S) where
  data : Array Scalar
  pf : data.size = n := sorry
  deriving Repr, BEq
def testVector : Vector 2 := {data := #[1.0, 2.0]}

Is there a way to do something like (Vector 2).mk #[1,2]?

Kim Morrison (May 09 2024 at 08:32):

structure Vector (n : Nat) (Scalar := Nat) : Type where
  data : Array Scalar
  pf : data.size = n := by sorry
deriving Repr, BEq

def testVector : Vector 2 := Vector.mk #[3, 7]

Eric Wieser (May 09 2024 at 08:40):

Or even just `def testVector : Vector 2 := .mk #[3, 7] without the repeated Vector

Alok Singh (May 09 2024 at 08:53):

Is there a way that doesn't rely on something inferring the 2 from type
constraints like those examples?

Siddhartha Gadgil (May 09 2024 at 09:11):

May be worse than the above, but one way of not specifying 2 is

def testVector' := @Vector.mk _ _ #[3, 7] rfl

Eric Wieser (May 09 2024 at 11:10):

Does (.mk #[3, 7] : Vector 2) meet your requirement?

Henrik Böving (May 09 2024 at 11:26):

Vector.mk should take n as an implicit argument that you can just explicitly specific with (n := foo) no?

Bolton Bailey (May 09 2024 at 22:26):

docs#Vector.mk

Bolton Bailey (May 09 2024 at 22:31):

Hmm, bit disappointing that we get a 404 link for that

Henrik Böving (May 09 2024 at 22:34):

Why, does that function exist? I don't see it

Adam Topaz (May 09 2024 at 22:40):

Vector.mk = Subtype.mk

Henrik Böving (May 09 2024 at 22:44):

Right, but this function does not exist under this name. if you #check Vector.mk with vector imported you will not get it.

Bolton Bailey (May 09 2024 at 22:44):

I mean it exists in the code that Kim provided above

Bolton Bailey (May 09 2024 at 22:44):

Screenshot-2024-05-09-at-5.44.29PM.png

Bolton Bailey (May 09 2024 at 22:45):

I am able to mouseover it in the lean web editor, so why can't we have a docs entry for it?

Henrik Böving (May 09 2024 at 22:45):

Yeah because Vector up there is a customly defined structure and not an alias for Subtype like the real vector, what's your point with respect to the docs?

Henrik Böving (May 09 2024 at 22:46):

image.png

this is the "real" vector, it's a def, not a structure

Bolton Bailey (May 09 2024 at 22:46):

Ah, I see, I did not realize that this definition was different.

Bolton Bailey (May 09 2024 at 22:52):

Frankly, I somehow didn't make the connection that there was a definition five lines above that has the same name as a Mathlib definition, I guess its only possible because mathlib isn't imported.


Last updated: May 02 2025 at 03:31 UTC