Documentation

Starlib.Data.Fin.Tuple.Notation

Slice notation instances for Fin tuples #

This file provides instances of the generic slice type classes (SliceLT, SliceGE, Slice) for Fin tuples, enabling Python-like slice notation:

The instances work for both homogeneous (Fin n → α) and heterogeneous ((i : Fin n) → α i) Fin tuples, delegating to the existing Fin.take and Fin.drop operations.

Each notation also supports manual proof syntax with 'h:

Examples #

variable (v : Fin 10 → ℕ)

#check v⟦:5⟧   -- Takes first 5 elements: Fin 5 → ℕ
#check v⟦3:⟧   -- Drops first 3 elements: Fin 7 → ℕ
#check v⟦2:8⟧  -- Elements 2 through 7: Fin 6 → ℕ

Instances for Fin tuples #

@[implicit_reducible]
instance Fin.instSliceLTForallNatLeForallCastLE {n : } {α : Fin nType u_1} :
SliceLT ((i : Fin n) → α i) (fun (x : (i : Fin n) → α i) (stop : ) => stop n) fun (x : (i : Fin n) → α i) (stop : ) (h : stop n) => (i : Fin stop) → α (castLE h i)
@[implicit_reducible]
instance Fin.instSliceGEForallNatLeForallCastAddNat {n : } {α : Fin nType u_1} :
SliceGE ((i : Fin n) → α i) (fun (x : (i : Fin n) → α i) (start : ) => start n) fun (x : (i : Fin n) → α i) (start : ) (h : start n) => (i : Fin (n - start)) → α (Fin.cast (i.addNat start))
@[implicit_reducible]
instance Fin.instSliceForallNatAndLeForallCastLECastAddNat {n : } {α : Fin nType u_1} :
Slice ((i : Fin n) → α i) (fun (x : (i : Fin n) → α i) (start stop : ) => start stop stop n) fun (x : (i : Fin n) → α i) (start stop : ) (h : start stop stop n) => (i : Fin (stop - start)) → α (castLE (Fin.cast (i.addNat start)))

Examples showing the Python-like slice notation works correctly #

Comprehensive Tuple Notation System with Better Definitional Equality #

This file provides a unified notation system for Fin-indexed tuples with better definitional equality through pattern matching. The system supports homogeneous vectors, heterogeneous tuples, dependent tuples, and functorial operations, all with consistent notation patterns.

Vector and Tuple Construction Notation: #

Homogeneous Vectors (all elements have the same type):

Heterogeneous Tuples (elements can have different types):

Dependent Tuples (with explicit motive specification):

Infix Operations: #

Cons Operations (prepend element):

Concat Operations (append element):

Append Operations (concatenate two tuples):

Design Principles: #

  1. Better Definitional Equality: All operations use pattern matching instead of cases, addCases, or conditional statements for superior computational behavior.

  2. Unified h Superscript: All heterogeneous and functorial operations use the h superscript with explicit type ascriptions when needed.

  3. Semicolon Separators: Functorial operations use α; β syntax to clearly distinguish the two type arguments required for functor application.

  4. Consistent Type Ascriptions: Explicit type information uses ⟨...⟩ brackets throughout.

  5. Unexpander Conflict Resolution: Each construction function (hcons, dcons, etc.) has its own dedicated notation to prevent pretty-printing ambiguities.

This system replaces Mathlib's Matrix.vecCons/Matrix.vecEmpty approach with our custom functions that provide better definitional equality and a more comprehensive type hierarchy.

Homogeneous cons: prepends a : α to a vector by specializing dcons to the constant-type motive fun _ => α.

Notation: a ::ᵛ v (using standard :: for vectors).

Instances For

    Homogeneous snoc: appends a : α to the end of a vector by specializing dconcat to the constant-type motive fun _ => α.

    Notation: v :+ᵛ a.

    Instances For

      ::ᵛ⟨α⟩ notation for homogeneous cons with explicit element type.

      Instances For

        :+ᵛ⟨α⟩ notation for homogeneous concat with explicit element type.

        Instances For

          ++ᵛ⟨α⟩ notation for homogeneous append with explicit element type.

          Instances For

            !v[...] notation constructs a vector using our custom functions. Uses !v[...] to distinguish from standard ![].

            Instances For

              !v⟨α⟩[...] notation constructs a vector with explicit type ascription. Uses angle brackets to specify the element type, then square brackets for values.

              Instances For

                Unexpander for the !v[x, y, ...] notation.

                Instances For

                  Unexpander for the !v[] notation.

                  Instances For

                    Heterogeneous cons: prepends a : α to a tuple (i : Fin n) → β i, with the return type constructed as (i : Fin (n + 1)) → vcons α β i where vcons builds the motive at the type level.

                    This is a specialization of fcons to the identity functor, allowing different types at each position without requiring an explicit motive.

                    Notation: a ::ʰ b.

                    Instances For

                      Heterogeneous snoc: appends a : β to the end of a tuple (i : Fin n) → α i, with the return type constructed as (i : Fin (n + 1)) → vconcat α β i where vconcat builds the motive at the type level.

                      This is a specialization of fconcat to the identity functor.

                      Notation: u :+ʰ a.

                      Instances For

                        ::ʰ⟨α; β⟩ notation for hcons with explicit type ascriptions

                        Instances For

                          :+ʰ⟨α; β⟩ notation for hconcat with explicit type ascriptions

                          Instances For

                            Functorial cons with explicit functor but inferred type families: ::ʰ⦃F⦄.

                            Instances For

                              Functorial cons (unary) with explicit types: ::ʰ⦃F⦄⟨α; β⟩.

                              Instances For

                                Functorial cons (binary) with explicit types: ::ʰ⦃F⦄⟨α₁; β₁⟩⟨α₂; β₂⟩.

                                Instances For

                                  Dependent cons with unified motive: prepends a : motive 0 to a dependent tuple (i : Fin n) → motive i.succ using pattern matching for better definitional equality.

                                  This is meant to replace Fin.cons for dependent tuples with a unified motive.

                                  Notation: a ::ᵈ b or a ::ᵈ⟨motive⟩ b for explicit motive specification.

                                  Instances For

                                    Dependent snoc with unified motive: appends a : motive (last n) to the end of a dependent tuple (i : Fin n) → motive i.castSucc using pattern matching for better definitional equality.

                                    This is meant to replace Fin.snoc for dependent tuples with a unified motive.

                                    Notation: u :+ᵈ a or u :+ᵈ⟨motive⟩ a for explicit motive specification.

                                    Instances For

                                      ::ᵈ⟨motive⟩ notation for dcons with explicit motive specification

                                      Instances For

                                        :+ᵈ⟨motive⟩ notation for dconcat with explicit motive specification

                                        Instances For

                                          !h[...] notation constructs a heterogeneous tuple using hcons. For automatic type inference without explicit motive.

                                          Instances For

                                            !h⟨α⟩[...] notation constructs a heterogeneous tuple with explicit type vector ascription. Uses angle brackets to specify the type vector, then square brackets for values.

                                            Instances For

                                              !h⦃F⦄[...] functorial heterogeneous tuple with explicit functor and implicit type vectors.

                                              Instances For

                                                !d[...] notation constructs a dependent tuple using our custom dependent functions. Uses !d[...] for dependent tuples with explicit motives.

                                                Instances For

                                                  !d⟨motive⟩[...] notation constructs a dependent tuple with explicit motive specification. Uses angle brackets to specify the motive, then square brackets for values.

                                                  Instances For

                                                    Functorial heterogeneous tuple constructors with explicit type vectors

                                                    Unary functorial: !h⦃F⦄⟨α⟩[...] where α : Fin n → Sort _.

                                                    Instances For

                                                      Binary functorial: !h⦃F⦄⟨α₁⟩⟨α₂⟩[...] where α₁, α₂ : Fin n → Sort _.

                                                      Instances For

                                                        Functorial concat infix forms to match documentation

                                                        Unexpander for the !h[x, y, ...] notation using hcons.

                                                        Instances For

                                                          Unexpander for the !h[] and !d[] notation.

                                                          Instances For

                                                            Unexpander for the !d[x, y, ...] notation using dcons with explicit motive.

                                                            Instances For

                                                              Homogeneous vector append notation ++ᵛ

                                                              Instances For

                                                                Dependent append notation ++ᵈ

                                                                Instances For

                                                                  Heterogeneous append notation ++ʰ

                                                                  Instances For

                                                                    Heterogeneous append with explicit type ascriptions: ++ʰ⟨α; β⟩

                                                                    Instances For

                                                                      Dependent append with explicit motive: ++ᵈ⟨motive⟩

                                                                      Instances For

                                                                        Functorial heterogeneous append with explicit functor but inferred types: ++ʰ⦃F⦄.

                                                                        Instances For

                                                                          Functorial heterogeneous append with unary functor: ++ʰ⦃F⦄⟨α; β⟩

                                                                          Instances For

                                                                            Functorial heterogeneous append with binary functor: ++ʰ⦃F⦄⟨α₁; β₁⟩⟨α₂; β₂⟩

                                                                            Instances For
                                                                              def Mymotive :
                                                                              Fin 3Type
                                                                              Instances For
                                                                                def MyTypeVec :
                                                                                Fin 3Type
                                                                                Instances For