Zulip Chat Archive

Stream: new members

Topic: Substitution for equivalent types


Vivek Rajesh Joshi (Jun 25 2024 at 16:28):

import Mathlib.Data.Matrix.Notation

structure ReducedRow (n : Nat) where
  z : Fin n
  k : Nat
  tail : Vector Rat k
  h : n = z + k + 1

def zeroVec (k: Nat) : Vector Rat k := Vector.replicate k 0

def ReducedRow.toVector (row : ReducedRow n): Vector Rat (n) :=
  row.h  (zeroVec row.z).append (Vector.cons 1 row.tail)

inductive RowEchelonForm : Nat  Nat  Type where
| row1 {n : Nat} (row : ReducedRow n) : RowEchelonForm 1 n
| rowAppend (row : ReducedRow n) {m : Nat} (rowlist : RowEchelonForm m n) : RowEchelonForm (m+1) n

#check finOneEquiv

def RowEchelonForm.toMatrix (R : RowEchelonForm m n) : Matrix (Fin m) (Fin n) Rat :=
  match R with
  | row1 row =>  Matrix.row row.toVector.get

In this code, I want to substitute Unit with Fin 1 in the type for the last line. How do I do this?

Yakov Pechersky (Jun 25 2024 at 16:30):

On the most recent mathlib, Matrix.row works across unique types. Can you try updating?

Vivek Rajesh Joshi (Jun 25 2024 at 16:39):

I've updated it to 4.9.0-rc3, and it's still flagging the line, but it now gives a different error message:

application type mismatch
  Matrix.row row.toVector.get
argument
  row.toVector.get
has type
  Fin n   : Type
but is expected to have type
  Type ?u.6899 : Type (?u.6899 + 1)

Jireh Loreaux (Jun 25 2024 at 16:42):

But did you update Mathlib?

Vivek Rajesh Joshi (Jun 25 2024 at 16:43):

Yes, the lean-toolchain file for Mathlib also reads 4.9.0-rc3

Ruben Van de Velde (Jun 25 2024 at 16:50):

Yeah, row now takes an extra argument. Try adding an underscore after row

Vivek Rajesh Joshi (Jun 25 2024 at 16:51):

Yes, that works. Thanks!


Last updated: May 02 2025 at 03:31 UTC