The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V02. Numbers

Mathlib.Data.Fin.Tuple.Curry

22 declarations. Mathlib docs · Source

Currying and uncurrying of n-ary functions

A function of n arguments can either be written as f a₁ a₂ ⋯ aₙ or f' ![a₁, a₂, ⋯, aₙ]. This file provides the currying and uncurrying operations that convert between the two, as n-ary generalizations of the binary curry and uncurry.

Main definitions

  • Function.OfArity.uncurry: convert an n-ary function to a function from Fin n → α.
  • Function.OfArity.curry: convert a function from Fin n → α to an n-ary function.
  • Function.FromTypes.uncurry: convert an p-ary heterogeneous function to a function from (i : Fin n) → p i.
  • Function.FromTypes.curry: convert a function from (i : Fin n) → p i to a p-ary heterogeneous function.

def Function.FromTypes.uncurry E3 #

{n : ℕ} → {p : Fin n → Type u} → {τ : Type u} → Function.FromTypes p τ → ((i : Fin n) → p i) → τ

Uncurry all the arguments of Function.FromTypes p τ to get a function from a tuple.

Note this can be used on raw functions if used.

def Function.FromTypes.curry E3 #

{n : ℕ} → {p : Fin n → Type u} → {τ : Type u} → (((i : Fin n) → p i) → τ) → Function.FromTypes p τ

Curry all the arguments of Function.FromTypes p τ to get a function from a tuple.

theorem Function.FromTypes.uncurry_apply_cons E0 #

∀ {n : ℕ} {α : Type u} {p : Fin n → Type u} {τ : Type u} (f : Function.FromTypes (Matrix.vecCons α p) τ) (a : α)
  (args : (i : Fin n) → p i), f.uncurry (Fin.cons a args) = (f a).uncurry args

theorem Function.FromTypes.uncurry_apply_succ E0 #

∀ {n : ℕ} {p : Fin (n + 1) → Type u} {τ : Type u} (f : Function.FromTypes p τ) (args : (i : Fin (n + 1)) → p i),
  f.uncurry args = (f (args 0)).uncurry (Fin.tail args)

theorem Function.FromTypes.curry_apply_cons E0 #

∀ {n : ℕ} {α : Type u} {p : Fin n → Type u} {τ : Type u} (f : ((i : Fin (n + 1)) → Matrix.vecCons α p i) → τ) (a : α),
  Function.FromTypes.curry f a = Function.FromTypes.curry ((fun {x} ↦ f) ∘' Fin.cons a)

theorem Function.FromTypes.curry_apply_succ E0 #

∀ {n : ℕ} {p : Fin (n + 1) → Type u} {τ : Type u} (f : ((i : Fin (n + 1)) → p i) → τ) (a : p 0),
  Function.FromTypes.curry f a = Function.FromTypes.curry (f ∘ Fin.cons a)

theorem Function.FromTypes.curry_uncurry E0 #

∀ {n : ℕ} {p : Fin n → Type u} {τ : Type u} (f : Function.FromTypes p τ), Function.FromTypes.curry f.uncurry = f

theorem Function.FromTypes.uncurry_curry E0 #

∀ {n : ℕ} {p : Fin n → Type u} {τ : Type u} (f : ((i : Fin n) → p i) → τ), (Function.FromTypes.curry f).uncurry = f

def Function.FromTypes.curryEquiv E1 #

{n : ℕ} → {τ : Type u} → (p : Fin n → Type u) → (((i : Fin n) → p i) → τ) ≃ Function.FromTypes p τ

Equiv.curry for p-ary heterogeneous functions.

theorem Function.FromTypes.curryEquiv_symm_apply E0 #

∀ {n : ℕ} {τ : Type u} (p : Fin n → Type u) (f : Function.FromTypes p τ) (a : (i : Fin n) → p i),
  (Function.FromTypes.curryEquiv p).symm f a = f.uncurry a

theorem Function.FromTypes.curryEquiv_apply E0 #

∀ {n : ℕ} {τ : Type u} (p : Fin n → Type u) (a : ((i : Fin n) → p i) → τ),
  (Function.FromTypes.curryEquiv p) a = Function.FromTypes.curry a

theorem Function.FromTypes.curry_two_eq_curry E1 #

∀ {p : Fin 2 → Type u} {τ : Type u} (f : ((i : Fin 2) → p i) → τ),
  Function.FromTypes.curry f = Function.curry (f ∘ ⇑(piFinTwoEquiv p).symm)

theorem Function.FromTypes.uncurry_two_eq_uncurry E1 #

∀ (p : Fin 2 → Type u) (τ : Type u) (f : Function.FromTypes p τ), f.uncurry = Function.uncurry f ∘ ⇑(piFinTwoEquiv p)

def Function.OfArity.uncurry E3 #

{α β : Type u} → {n : ℕ} → Function.OfArity α β n → (Fin n → α) → β

Uncurry all the arguments of Function.OfArity α n to get a function from a tuple.

Note this can be used on raw functions if used.

def Function.OfArity.curry E3 #

{α β : Type u} → {n : ℕ} → ((Fin n → α) → β) → Function.OfArity α β n

Curry all the arguments of Function.OfArity α β n to get a function from a tuple.

theorem Function.OfArity.curry_uncurry E0 #

∀ {α β : Type u} {n : ℕ} (f : Function.OfArity α β n), Function.OfArity.curry f.uncurry = f

theorem Function.OfArity.uncurry_curry E0 #

∀ {α β : Type u} {n : ℕ} (f : (Fin n → α) → β), (Function.OfArity.curry f).uncurry = f

def Function.OfArity.curryEquiv E1 #

{α β : Type u} → (n : ℕ) → ((Fin n → α) → β) ≃ Function.OfArity α β n

Equiv.curry for n-ary functions.

theorem Function.OfArity.curryEquiv_symm_apply E0 #

∀ {α β : Type u} (n : ℕ) (f : Function.FromTypes (fun a ↦ α) β) (a : Fin n → α),
  (Function.OfArity.curryEquiv n).symm f a = f.uncurry a

theorem Function.OfArity.curryEquiv_apply E0 #

∀ {α β : Type u} (n : ℕ) (a : (Fin n → α) → β), (Function.OfArity.curryEquiv n) a = Function.FromTypes.curry a

theorem Function.OfArity.curry_two_eq_curry E1 #

∀ {α β : Type u} (f : (Fin 2 → α) → β), Function.OfArity.curry f = Function.curry (f ∘ ⇑(finTwoArrowEquiv α).symm)

theorem Function.OfArity.uncurry_two_eq_uncurry E1 #

∀ {α β : Type u} (f : Function.OfArity α β 2), f.uncurry = Function.uncurry f ∘ ⇑(finTwoArrowEquiv α)