Custom Fin tuple operations with better definitional equality #
This file provides custom tuple operations that use pattern matching for better definitional
equality, replacing standard library functions that rely on complex constructions like cases,
addCases, and conditional statements with casts.
Utility operations: #
Fin.rtake: Taking from the right (i.e. the end) of a tupleFin.drop: Dropping from the left (i.e. the beginning) of a tupleFin.rdrop: Dropping from the right (i.e. the end) of a tupleFin.extract: Extract a sub-tuple from a given rangeFin.rightpad: Padding (or truncation) on the right of a tupleFin.leftpad: Padding (or truncation) on the left of a tuple
Three-Tier Construction System: #
Dependent operations (d*): Work with a unified motive Fin n → Sort* that determines the type
at each position. These are the foundational operations.
Homogeneous operations (v*): Specialize the dependent operations to constant-type motives fun _ => α, creating vectors where all elements have the same type.
Functorial operations (f*): Apply a type constructor F uniformly across all positions of a
heterogeneous tuple, with the return type constructed using v* operations at the type level. We
define versions for both the unary and binary versions of F (arbitrary arity version?)
Heterogeneous operations (h*): Specialize the unary functorial operations to the identity
functor, allowing different types at each position without requiring an explicit motive.
Empty tuples: #
Fin.dempty/Fin.vempty: Empty tuples for dependent and homogeneous cases
Drop the last m elements of an n-tuple where m ≤ n, returning an (n - m)-tuple.
This is defined to be taking the first n - m elements of the tuple. Thus, one should not use this
and use Fin.take instead.
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
Dependent append with unified motive: concatenates two dependent tuples under a shared motive using pattern matching for better definitional equality.
This is meant to replace Fin.addCases for dependent tuples with a unified motive.
Notation: u ++ᵈ v or u ++ᵈ⟨motive⟩ v for explicit motive specification.
Instances For
Functorial cons: prepends a : F α to a functorial tuple (i : Fin n) → F (β i),
with the return type constructed as (i : Fin (n + 1)) → F (vcons α β i) where F is applied
to the motive built by vcons at the type level.
Unlike dcons which requires an explicit unified motive, fcons uses vcons to automatically
construct the motive from the input types and applies functor F uniformly. When F is the
identity functor, this reduces to hcons.
Notation: a ::ʰ⦃F⦄⟨α; β⟩ b with explicit functor and type ascriptions.
Instances For
Functorial cons with two arguments: prepends a : F α₁ α₂ to a functorial tuple
(i : Fin n) → F (β₁ i) (β₂ i), with the return type constructed as
(i : Fin (n + 1)) → F (vcons α₁ β₁ i) (vcons α₂ β₂ i) where F is applied to the two motives
built by vcons at the type level.
Notation: a ::ʰ⦃F⦄⟨α₁; β₁⟩⟨α₂; β₂⟩ b with explicit binary functor and type ascriptions.
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
Functorial snoc: appends a : F β to the end of a functorial tuple (i : Fin n) → F (α i),
with the return type constructed as (i : Fin (n + 1)) → F (vconcat α β i) where F is applied
to the motive built by vconcat at the type level.
Unlike dconcat which requires an explicit unified motive, fconcat uses vconcat to
automatically construct the motive from the input types and applies functor F uniformly. When F
is the identity functor, this reduces to hconcat.
Notation: u :+ʰ⦃F⦄⟨α; β⟩ a with explicit functor and type ascriptions.
Instances For
Functorial snoc with two arguments: appends a : F β₁ β₂ to the end of a functorial tuple
(i : Fin n) → F (α₁ i) (α₂ i), with the return type constructed as
(i : Fin (n + 1)) → F (vconcat α₁ β₁ i) (vconcat α₂ β₂ i) where F is applied
to the two motives built by vconcat at the type level.
Notation: u :+ʰ⦃F⦄⟨α₁; β₁⟩⟨α₂; β₂⟩ a with explicit binary functor and type ascriptions.
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
Functorial append: concatenates functorial tuples (i : Fin m) → F (α i) and (i : Fin n) → F (β i), with the return type constructed as (i : Fin (m + n)) → F (vappend α β i) where F is
applied to the motive built by vappend at the type level.
Unlike dappend which requires an explicit unified motive, fappend uses vappend to
automatically construct the motive from the input types and applies functor F uniformly. When F
is the identity functor, this reduces to happend.
Notation: u ++ʰ⦃F⦄⟨α; β⟩ v with explicit functor and type ascriptions.
Instances For
Functorial append with two arguments: concatenates functorial tuples (i : Fin m) → F (α i) and
(i : Fin n) → F (β i), with the return type constructed as
(i : Fin (m + n)) → F (vappend α₁ β₁ i) (vappend α₂ β₂ i) where F is applied to the two motives
built by vappend at the type level.
Notation: u ++ʰ⦃F⦄⟨α₁; β₁⟩⟨α₂; β₂⟩ v with explicit binary functor and type ascriptions.
Instances For
Heterogeneous append: concatenates tuples (i : Fin m) → α i and (i : Fin n) → β i,
with the return type constructed as (i : Fin (m + n)) → vappend α β i where vappend builds
the motive at the type level.
This is a specialization of fappend to the identity functor.
Notation: u ++ʰ v.
Instances For
Cast a dependent or heterogeneous vector across an equality n' = n and a family of equalities
∀ i, α (Fin.cast h i) = α' i.
This is meant to replace Fin.cast for our use cases, as this definition offers better
definitional equality.