Tuples of types, and their categorical structure. #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Features #
typevec n
- n-tuples of typesα ⟹ β
- n-tuples of mapsf ⊚ g
- composition
Also, support functions for operating with n-tuples of types, such as:
append1 α β
- append typeβ
to n-tupleα
to obtain an (n+1)-tupledrop α
- drops the last element of an (n+1)-tuplelast α
- returns the last element of an (n+1)-tupleappend_fun f g
- appends a function g to an n-tuple of functionsdrop_fun f
- drops the last function from an n+1-tuplelast_fun f
- returns the last function of a tuple.
Since e.g. append1 α.drop α.last
is propositionally equal to α
but not definitionally equal
to it, we need support functions and lemmas to mediate between constructions.
identity of arrow composition
Equations
- typevec.id = λ (i : fin2 n) (x : α i), x
take the last value of a (n+1)-length
vector
Instances for typevec.last
Equations
- typevec.last.inhabited α = {default := show α fin2.fz, from inhabited.default}
arrow in the category of 0-length
vectors
Equations
- typevec.nil_fun = λ (i : fin2 0), i.elim0
turn an equality into an arrow
Equations
- typevec.arrow.mp h i = _.mp
turn an equality into an arrow, with reverse direction
Equations
- typevec.arrow.mpr h i = _.mpr
decompose a vector into its prefix appended with its last element
Equations
stitch two bits of a vector back together
Equations
cases distinction for 0-length type vector
Equations
- typevec.cases_nil f = λ (v : typevec 0), cast _ f
cases distinction for an arrow in the category of 0-length type vectors
cases distinction for an arrow in the category of (n+1)-length type vectors
specialized cases distinction for an arrow in the category of 0-length type vectors
Equations
- typevec.typevec_cases_nil₂ f = λ (g : typevec.arrow fin2.elim0 fin2.elim0), _.mpr f
specialized cases distinction for an arrow in the category of (n+1)-length type vectors
Equations
- typevec.typevec_cases_cons₂ n t t' v v' F = λ (fs : (v ::: t).arrow (v' ::: t')), _.mpr (F (typevec.last_fun fs) (typevec.drop_fun fs))
repeat n t
is a n-length
type vector that contains n
occurences of t
Equations
- typevec.repeat i.succ t = typevec.repeat i t ::: t
- typevec.repeat 0 t = fin2.elim0
const x α
is an arrow that ignores its source and constructs a typevec
that
contains nothing but x
Equations
- typevec.const x α i.fs = typevec.const x α.drop i
- typevec.const x α fin2.fz = λ (_x : α fin2.fz), x
vector of equality on a product of vectors
Equations
predicate on a type vector to constrain only the last object
Equations
- α.pred_last' p = typevec.split_fun (typevec.const true α) p
predicate on the product of two type vectors to constrain only their last object
Equations
- α.rel_last' p = typevec.split_fun α.repeat_eq (function.uncurry p)
given F : typevec.{u} (n+1) → Type u
, curry F : Type u → typevec.{u} → Type u
,
i.e. its first argument can be fed in separately from the rest of the vector of arguments
Equations
- typevec.curry F α β = F (β ::: α)
Instances for typevec.curry
Equations
- typevec.curry.inhabited F α β = I
arrow to remove one element of a repeat
vector
Equations
projection for a repeat vector
Equations
left projection of a prod
vector
Equations
right projection of a prod
vector
Equations
introduce a product where both components are the same
Equations
- typevec.prod.diag i.fs x = typevec.prod.diag i x
- typevec.prod.diag fin2.fz x = (x, x)
constructor for prod
Equations
prod
is functorial
Equations
- typevec.prod.map x y i.fs a = typevec.prod.map (typevec.drop_fun x) (typevec.drop_fun y) i a
- typevec.prod.map x y fin2.fz a = (x fin2.fz a.fst, y fin2.fz a.snd)
given a predicate vector p
over vector α
, subtype_ p
is the type of vectors
that contain an α
that satisfies p
Equations
- typevec.subtype_ p i.fs = typevec.subtype_ (typevec.drop_fun p) i
- typevec.subtype_ p fin2.fz = {x // p fin2.fz x}
projection on subtype_
Equations
arrow that rearranges the type of subtype_
to turn a subtype of vector into
a vector of subtypes
Equations
- typevec.to_subtype p i.fs x = typevec.to_subtype (typevec.drop_fun p) i x
- typevec.to_subtype p fin2.fz x = x
arrow that rearranges the type of subtype_
to turn a vector of subtypes
into a subtype of vector
Equations
- typevec.of_subtype p i.fs x = typevec.of_subtype (typevec.drop_fun p) i x
- typevec.of_subtype p fin2.fz x = x
similar to to_subtype
adapted to relations (i.e. predicate on product)
Equations
- typevec.to_subtype' p i.fs x = typevec.to_subtype' (typevec.drop_fun p) i x
- typevec.to_subtype' p fin2.fz x = ⟨x.val, _⟩
similar to of_subtype
adapted to relations (i.e. predicate on product)
Equations
- typevec.of_subtype' p i.fs x = typevec.of_subtype' (typevec.drop_fun p) i x
- typevec.of_subtype' p fin2.fz x = ⟨x.val, _⟩
similar to diag
but the target vector is a subtype_
guaranteeing the equality of the components
Equations
- typevec.diag_sub i.fs x = typevec.diag_sub i x
- typevec.diag_sub fin2.fz x = ⟨(x, x), _⟩