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:
v⟦:m⟧takes the firstmelementsv⟦m:⟧drops the firstmelementsv⟦m₁:m₂⟧takes elements from indexm₁tom₂ - 1
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:
v⟦:m⟧'hfor explicit proof in take operationsv⟦m:⟧'hfor explicit proof in drop operationsv⟦m₁:m₂⟧'⟨h₁, h₂⟩for explicit proofs in range operations
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 #
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):
!v[a, b, c]- basic homogeneous vector!v⟨α⟩[a, b, c]- with explicit type ascription
Heterogeneous Tuples (elements can have different types):
!h[a, b, c]- basic heterogeneous tuple (useshcons)!h⟨α⟩[a, b, c]- heterogeneous tuple with type vector ascription!h⦃F⦄[a, b, c]- functorial with explicit unary functor F but implicit type vector!h⦃F⦄⟨α⟩[a, b, c]- functorial with unary functor F and type vector α!h⦃F⦄⟨α₁⟩⟨α₂⟩[a, b, c]- functorial with binary functor F and type vectors α₁ and α₂
Dependent Tuples (with explicit motive specification):
!d[a, b, c]- basic dependent tuple (usesdcons)!d⟨motive⟩[a, b, c]- with explicit motive
Infix Operations: #
Cons Operations (prepend element):
a ::ᵛ v- homogeneous consa ::ᵛ⟨α⟩ v- homogeneous cons with explicit type ascriptiona ::ʰ t- heterogeneous consa ::ʰ⟨α; β⟩ t- heterogeneous cons with explicit type ascriptiona ::ʰ⦃F⦄ t- functorial cons (unary) with type besidesFinferreda ::ʰ⦃F⦄⟨α; β⟩ t- functorial cons (unary) with explicit type ascriptiona ::ʰ⦃F⦄⟨α₁; β₁⟩⟨α₂; β₂⟩ t- functorial cons (binary) with explicit type ascriptiona ::ᵈ t- dependent consa ::ᵈ⟨motive⟩ t- dependent cons with explicit motive
Concat Operations (append element):
v :+ᵛ a- homogeneous concatv :+ᵛ⟨α⟩ a- homogeneous concat with explicit type ascriptiont :+ʰ a- heterogeneous concatt :+ʰ⟨α; β⟩ a- heterogeneous concat with explicit type ascriptiont :+ʰ⦃F⦄ a- functorial concat (unary) with type besidesFinferredt :+ʰ⦃F⦄⟨α; β⟩ a- functorial concat (unary)t :+ʰ⦃F⦄⟨α₁; β₁⟩⟨α₂; β₂⟩ a- functorial concat (binary)t :+ᵈ a- dependent concatt :+ᵈ⟨motive⟩ a- dependent concat with explicit motive
Append Operations (concatenate two tuples):
u ++ᵛ v- homogeneous appendu ++ᵛ⟨α⟩ v- homogeneous append with explicit type ascriptionu ++ʰ v- heterogeneous appendu ++ʰ⟨α; β⟩ v- heterogeneous append with explicit type ascriptionu ++ʰ⦃F⦄ v- functorial append (unary) with type besidesFinferredu ++ʰ⦃F⦄⟨α; β⟩ v- functorial append (unary)u ++ʰ⦃F⦄⟨α₁; β₁⟩⟨α₂; β₂⟩ v- functorial append (binary)u ++ᵈ v- dependent appendu ++ᵈ⟨motive⟩ v- dependent append with explicit motive
Design Principles: #
Better Definitional Equality: All operations use pattern matching instead of
cases,addCases, or conditional statements for superior computational behavior.Unified
hSuperscript: All heterogeneous and functorial operations use thehsuperscript with explicit type ascriptions when needed.Semicolon Separators: Functorial operations use
α; βsyntax to clearly distinguish the two type arguments required for functor application.Consistent Type Ascriptions: Explicit type information uses
⟨...⟩brackets throughout.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
::ʰ⟨α; β⟩ 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
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⦄⟨α₁; β₁⟩⟨α₂; β₂⟩