Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


Quelle  Curry.lean   Sprache: Lean

 

/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/

module

public import Mathlib.Data.Fintype.Sort
public import Mathlib.LinearAlgebra.Multilinear.Basic

/-!
# Currying of multilinear maps

We register isomorphisms corresponding to currying or uncurrying variables, transforming a
multilinear function `f` on `n+1` variables into a linear function taking values in multilinear
functions in `n` variables, and into a multilinear function in `n` variables taking values in linear
functions. These operations are called `f.curryLeft` and `f.curryRight` respectively
(with inverses `f.uncurryLeft` and `f.uncurryRight`). These operations induce linear equivalences
between spaces of multilinear functions in `n+1` variables and spaces of linear functions into
multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values
in linear functions), called respectively `multilinearCurryLeftEquiv` and
`multilinearCurryRightEquiv`.
-/


@[expose] public section

open Fin Function Finset

universe uR uS uι uι' v v' v₁ v₂ v₃

variable {R : Type uR} {S : Type uS} [Semiring R] [CommSemiring S] {σ : R →+* S}
  {ι : Type uι} {ι' : Type uι'} {n : ℕ}
  {M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M' : Type v'}
  [∀ i, AddCommMonoid (M i)] [AddCommMonoid M'] [AddCommMonoid M₂]
  [∀ i, Module R (M i)] [Module R M'] [Module S M₂]

/-!
### Currying

We associate to a multilinear map in `n+1` variables (i.e., based on `Fin n.succ`) two
curried functions, named `f.curryLeft` (which is a linear map on `E 0` taking values
in multilinear maps in `n` variables) and `f.curryRight` (which is a multilinear map in `n`
variables taking values in linear maps on `E 0`). In both constructions, the variable that is
singled out is `0`, to take advantage of the operations `cons` and `tail` on `Fin n`.
The inverse operations are called `uncurryLeft` and `uncurryRight`.

We also register linear equiv versions of these correspondences, in
`multilinearCurryLeftEquiv` and `multilinearCurryRightEquiv`.
-/



open MultilinearMap


/-! #### Left currying -/


/-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables,
construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (m 0) (tail m)` -/

def LinearMap.uncurryLeft (f : M 0 →ₛₗ[σ] (Π i : Fin n, M i.succ) →ₘₛₗ[σ] M₂) :
    (Π i, M i) →ₘₛₗ[σ] M₂ :=
  MultilinearMap.mk' (fun m ↦ f (m 0) (tail m))
    (fun m i x y ↦ by cases i using Fin.cases <;> simp [Ne.symm])
    (fun m i c x ↦ by cases i using Fin.cases <;> simp [Ne.symm])

@[simp]
theorem LinearMap.uncurryLeft_apply (f : M 0 →ₛₗ[σ] (Π i : Fin n, M i.succ) →ₘₛₗ[σ] M₂)
    (m : ∀ i, M i) : f.uncurryLeft m = f (m 0) (tail m) :=
  rfl

/-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain
a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/

def MultilinearMap.curryLeft (f : (Π i, M i) →ₘₛₗ[σ] M₂) :
    M 0 →ₛₗ[σ] (Π i : Fin n, M i.succ) →ₘₛₗ[σ] M₂ where
  toFun x := MultilinearMap.mk' fun m => f (cons x m)
  map_add' x y := by
    ext m
    exact cons_add f m x y
  map_smul' c x := by
    ext m
    exact cons_smul f m c x

@[simp]
theorem MultilinearMap.curryLeft_apply (f : (Π i, M i) →ₘₛₗ[σ] M₂) (x : M 0)
    (m : ∀ i : Fin n, M i.succ) : f.curryLeft x m = f (cons x m) :=
  rfl

@[simp]
theorem LinearMap.curry_uncurryLeft (f : M 0 →ₛₗ[σ] (Π i : Fin n, M i.succ) →ₘₛₗ[σ] M₂) :
    f.uncurryLeft.curryLeft = f :=
  rfl

@[simp]
theorem MultilinearMap.uncurry_curryLeft (f : (Π i, M i) →ₘₛₗ[σ] M₂) :
    f.curryLeft.uncurryLeft = f := by
  ext m
  simp

variable (σ M M₂)

/-- The space of multilinear maps on `Π (i : Fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from `M 0` to the space of multilinear maps on
`Π (i : Fin n), M i.succ`, by separating the first variable. We register this isomorphism as a
linear isomorphism in `multilinearCurryLeftEquiv R M M₂`.

The direct and inverse maps are given by `f.curryLeft` and `f.uncurryLeft`. Use these
unless you need the full framework of linear equivs. -/

@[simps]
def multilinearCurryLeftEquiv :
    ((Π i, M i) →ₘₛₗ[σ] M₂) ≃ₗ[S] M 0 →ₛₗ[σ] (Π i : Fin n, M i.succ) →ₘₛₗ[σ] M₂ where
  toFun := MultilinearMap.curryLeft
  map_add' _ _ := rfl
  map_smul' _ _ := rfl
  invFun := LinearMap.uncurryLeft
  left_inv := MultilinearMap.uncurry_curryLeft
  right_inv := LinearMap.curry_uncurryLeft

variable {σ M M₂}

/-! #### Right currying -/

/-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to
`M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (init m) (m (last n))` -/

def MultilinearMap.uncurryRight
    (f : (Π i : Fin n, M (castSucc i)) →ₘₛₗ[σ] M (last n) →ₛₗ[σ] M₂) : (Π i, M i) →ₘₛₗ[σ] M₂ :=
  MultilinearMap.mk' (fun m ↦ f (init m) (m (last n)))
    (fun m i x y ↦ by cases i using Fin.lastCases <;> simp [Ne.symm])
    (fun m i c x ↦ by cases i using Fin.lastCases <;> simp [Ne.symm])

@[simp]
theorem MultilinearMap.uncurryRight_apply
    (f : (Π i : Fin n, M (castSucc i)) →ₘₛₗ[σ] M (last n) →ₛₗ[σ] M₂) (m : ∀ i, M i) :
    f.uncurryRight m = f (init m) (m (last n)) :=
  rfl

/-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain
a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by
`m ↦ (x ↦ f (snoc m x))`. -/

def MultilinearMap.curryRight (f : (Π i, M i) →ₘₛₗ[σ] M₂) :
    (Π i : Fin n, M (Fin.castSucc i)) →ₘₛₗ[σ] M (last n) →ₛₗ[σ] M₂ :=
  MultilinearMap.mk' fun m ↦
    { toFun := fun x => f (snoc m x)
      map_add' := fun x y => by simp_rw [f.snoc_add]
      map_smul' := fun c x => by simp only [f.snoc_smul] }

@[simp]
theorem MultilinearMap.curryRight_apply (f : (Π i, M i) →ₘₛₗ[σ] M₂)
    (m : ∀ i : Fin n, M (castSucc i)) (x : M (last n)) : f.curryRight m x = f (snoc m x) :=
  rfl

@[simp]
theorem MultilinearMap.curry_uncurryRight
    (f : (Π i : Fin n, M (castSucc i)) →ₘₛₗ[σ] M (last n) →ₛₗ[σ] M₂) :
    f.uncurryRight.curryRight = f := by
  ext m x
  simp only [snoc_last, MultilinearMap.curryRight_apply, MultilinearMap.uncurryRight_apply]
  rw [init_snoc]

@[simp]
theorem MultilinearMap.uncurry_curryRight (f : (Π i, M i) →ₘₛₗ[σ] M₂) :
    f.curryRight.uncurryRight = f := by
  ext m
  simp

variable (σ M M₂)

/-- The space of multilinear maps on `Π (i : Fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from the space of multilinear maps on `Π (i : Fin n), M (castSucc i)` to
the space of linear maps on `M (last n)`, by separating the last variable. We register this
isomorphism as a linear isomorphism in `multilinearCurryRightEquiv R M M₂`.

The direct and inverse maps are given by `f.curryRight` and `f.uncurryRight`. Use these
unless you need the full framework of linear equivs. -/

def multilinearCurryRightEquiv :
    ((Π i, M i) →ₘₛₗ[σ] M₂) ≃ₗ[S] (Π i : Fin n, M (castSucc i)) →ₘₛₗ[σ] M (last n) →ₛₗ[σ] M₂ where
  toFun := MultilinearMap.curryRight
  map_add' _ _ := rfl
  map_smul' _ _ := rfl
  invFun := MultilinearMap.uncurryRight
  left_inv := MultilinearMap.uncurry_curryRight
  right_inv := MultilinearMap.curry_uncurryRight

variable {σ M M₂}

/-- Given a linear map from `M p` to the space of multilinear maps
in `n` variables `M 0`, ..., `M n` with `M p` removed,
returns a multilinear map in all `n + 1` variables. -/

@[simps!]
def LinearMap.uncurryMid (p : Fin (n + 1)) (f : M p →ₛₗ[σ] (Π i, M (p.succAbove i)) →ₘₛₗ[σ] M₂) :
    (Π i, M i) →ₘₛₗ[σ] M₂ :=
  .mk' (fun m ↦ f (m p) (p.removeNth m))
    (fun m i x y ↦ by cases i using Fin.succAboveCases p <;> simp)
    (fun m i x y ↦ by cases i using Fin.succAboveCases p <;> simp)

/-- Interpret a multilinear map in `n + 1` variables
as a linear map in `p`th variable with values in the multilinear maps in the other variables. -/

@[simps!]
def MultilinearMap.curryMid (p : Fin (n + 1)) (f : (Π i, M i) →ₘₛₗ[σ] M₂) :
    M p →ₛₗ[σ] (Π i, M (p.succAbove i)) →ₘₛₗ[σ] M₂ where
  toFun x := .mk' fun m ↦ f (p.insertNth x m)
  map_add' x y := by ext; simp [map_insertNth_add]
  map_smul' c x := by ext; simp [map_insertNth_smul]

@[simp]
theorem LinearMap.curryMid_uncurryMid (i : Fin (n + 1))
    (f : M i →ₛₗ[σ] (Π j, M (i.succAbove j)) →ₘₛₗ[σ] M₂) : (f.uncurryMid i).curryMid i = f := by
  ext; simp

@[simp]
theorem MultilinearMap.uncurryMid_curryMid (i : Fin (n + 1)) (f : (Π i, M i) →ₘₛₗ[σ] M₂) :
    (f.curryMid i).uncurryMid i = f := by ext; simp

variable (σ M M₂)

/-- `MultilinearMap.curryMid` as a linear equivalence. -/
@[simps]
def MultilinearMap.curryMidLinearEquiv (p : Fin (n + 1)) :
    ((Π i, M i) →ₘₛₗ[σ] M₂) ≃ₗ[S] M p →ₛₗ[σ] (Π i, M (p.succAbove i)) →ₘₛₗ[σ] M₂ where
  toFun := MultilinearMap.curryMid p
  map_add' _ _ := rfl
  map_smul' _ _ := rfl
  invFun := LinearMap.uncurryMid p
  left_inv := MultilinearMap.uncurryMid_curryMid p
  right_inv := LinearMap.curryMid_uncurryMid p

namespace MultilinearMap

variable {σ M₂} {N : (ι ⊕ ι') → Type*}
  [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)]

/-- Given a family of modules `N : (ι ⊕ ι') → Type*`, a multilinear map
on `(fun _ : ι ⊕ ι' => M')` induces a multilinear map on
`(fun (i : ι) ↦ N (.inl i))` taking values in the space of
linear maps on `(fun (i : ι') ↦ N (.inr i))`. -/

def currySum (f : (Π i, N i) →ₘₛₗ[σ] M₂) :
    (Π i : ι, N (.inl i)) →ₘₛₗ[σ] (Π i : ι', N (.inr i)) →ₘₛₗ[σ] M₂ where
  toFun u :=
    { toFun v := f (Sum.rec u v)
      map_update_add' := by let := Classical.decEq ι; simp
      map_update_smul' := by let := Classical.decEq ι; simp }
  map_update_add' u i x y :=
    ext fun _ ↦ by let := Classical.decEq ι'; simp
  map_update_smul' u i c x :=
    ext fun _ ↦ by let := Classical.decEq ι'; simp

@[simp low]
theorem currySum_apply (f : (Π i, N i) →ₘₛₗ[σ] M₂)
    (u : (i : ι) → N (Sum.inl i)) (v : (i : ι') → N (Sum.inr i)) :
    currySum f u v = f (Sum.rec u v) := rfl

@[simp]
theorem currySum_apply' {N : Type*} [AddCommMonoid N] [Module R N]
    (f : (ι ⊕ ι' → N) →ₘₛₗ[σ] M₂) (u : ι → N) (v : ι' → N) :
    currySum f u v = f (Sum.elim u v) := rfl

@[simp]
lemma currySum_add (f₁ f₂ : (Π i, N i) →ₘₛₗ[σ] M₂) :
    currySum (f₁ + f₂) = currySum f₁ + currySum f₂ := rfl

@[simp]
lemma currySum_smul (r : S) (f : (Π i, N i) →ₘₛₗ[σ] M₂) :
    currySum (r • f) = r • currySum f := rfl

/-- Given a family of modules `N : (ι ⊕ ι') → Type*`, a multilinear map on
`(fun (i : ι) ↦ N (.inl i))` taking values in the space of
linear maps on `(fun (i : ι') ↦ N (.inr i))` induces a multilinear map
on `(fun _ : ι ⊕ ι' => M')` induces. -/

def uncurrySum (g : (Π i : ι, N (.inl i)) →ₘₛₗ[σ] (Π i : ι', N (.inr i)) →ₘₛₗ[σ] M₂) :
    (Π i, N i) →ₘₛₗ[σ] M₂ where
  toFun u := g (fun i ↦ u (.inl i)) (fun i' ↦ u (.inr i'))
  map_update_add' := by
    let := Classical.decEq ι
    let := Classical.decEq ι'
    rintro _ _ (_ | _) _ _ <;> simp
  map_update_smul' := by
    let := Classical.decEq ι
    let := Classical.decEq ι'
    rintro _ _ (_ | _) _ _ <;> simp

@[simp]
theorem uncurrySum_apply (g : (Π i : ι, N (.inl i)) →ₘₛₗ[σ] (Π i : ι', N (.inr i)) →ₘₛₗ[σ] M₂) (u) :
    g.uncurrySum u = g (fun i ↦ u (.inl i)) (fun i' ↦ u (.inr i')) :=
  rfl

@[simp]
lemma uncurrySum_add (g₁ g₂ : (Π i : ι, N (.inl i)) →ₘₛₗ[σ] (Π i : ι', N (.inr i)) →ₘₛₗ[σ] M₂) :
    uncurrySum (g₁ + g₂) = uncurrySum g₁ + uncurrySum g₂ :=
  rfl

lemma uncurrySum_smul
    (r : S) (g : (Π i : ι, N (.inl i)) →ₘₛₗ[σ] (Π i : ι', N (.inr i)) →ₘₛₗ[σ] M₂) :
    uncurrySum (r • g) = r • uncurrySum g :=
  rfl

@[simp]
lemma uncurrySum_currySum (f : (Π i, N i) →ₘₛₗ[σ] M₂) : uncurrySum (currySum f) = f := by
  ext
  simp only [uncurrySum_apply, currySum_apply]
  congr
  ext (_ | _) <;> simp

@[simp]
lemma currySum_uncurrySum (g : (Π i : ι, N (.inl i)) →ₘₛₗ[σ] (Π i : ι', N (.inr i)) →ₘₛₗ[σ] M₂) :
    currySum (uncurrySum g) = g :=
  rfl

/-- Multilinear maps on `N : (ι ⊕ ι') → Type*` identify to multilinear maps
from `(fun (i : ι) ↦ N (.inl i))` taking values in the space of
linear maps on `(fun (i : ι') ↦ N (.inr i))`. -/

@[simps]
def currySumEquiv :
    ((Π i, N i) →ₘₛₗ[σ] M₂) ≃ₗ[S]
      (Π i : ι, N (.inl i)) →ₘₛₗ[σ] (Π i : ι', N (.inr i)) →ₘₛₗ[σ] M₂ where
  toFun := currySum
  invFun := uncurrySum
  left_inv _ := by simp
  map_add' := by aesop
  map_smul' := by aesop

@[simp]
theorem coe_currySumEquiv : ⇑(currySumEquiv (σ := σ) (N := N) (M₂ := M₂)) = currySum :=
  rfl

@[simp]
theorem coe_currySumEquiv_symm : ⇑(currySumEquiv (σ := σ) (N := N) (M₂ := M₂)).symm = uncurrySum :=
  rfl

variable (σ M₂ M')

/-- If `s : Finset (Fin n)` is a finite set of cardinality `k` and its complement has cardinality
`l`, then the space of multilinear maps on `fun i : Fin n => M'` is isomorphic to the space of
multilinear maps on `fun i : Fin k => M'` taking values in the space of multilinear maps
on `fun i : Fin l => M'`. -/

def curryFinFinset {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l) :
    ((Fin n → M') →ₘₛₗ[σ] M₂) ≃ₗ[S] (Fin k → M') →ₘₛₗ[σ] (Fin l → M') →ₘₛₗ[σ] M₂ :=
  (domDomCongrLinearEquiv S σ M' M₂ (finSumEquivOfFinset hk hl).symm).trans currySumEquiv

variable {σ M₂ M'}

@[simp]
theorem curryFinFinset_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l)
    (f : (Fin n → M') →ₘₛₗ[σ] M₂) (mk : Fin k → M') (ml : Fin l → M') :
    curryFinFinset σ M₂ M' hk hl f mk ml =
      f fun i => Sum.elim mk ml ((finSumEquivOfFinset hk hl).symm i) :=
  rfl

@[simp]
theorem curryFinFinset_symm_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l)
    (f : (Fin k → M') →ₘₛₗ[σ] (Fin l → M') →ₘₛₗ[σ] M₂) (m : Fin n → M') :
    (curryFinFinset σ M₂ M' hk hl).symm f m =
      f (fun i => m <| finSumEquivOfFinset hk hl (Sum.inl i)) fun i =>
        m <| finSumEquivOfFinset hk hl (Sum.inr i) :=
  rfl

theorem curryFinFinset_symm_apply_piecewise_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k)
    (hl : #sᶜ = l) (f : (Fin k → M') →ₘₛₗ[σ] (Fin l → M') →ₘₛₗ[σ] M₂) (x y : M') :
    (curryFinFinset σ M₂ M' hk hl).symm f (s.piecewise (fun _ => x) fun _ => y) =
      f (fun _ => x) fun _ => y := by
  rw [curryFinFinset_symm_apply]; congr
  · ext
    rw [finSumEquivOfFinset_inl, Finset.piecewise_eq_of_mem]
    apply Finset.orderEmbOfFin_mem
  · ext
    rw [finSumEquivOfFinset_inr, Finset.piecewise_eq_of_notMem]
    exact Finset.mem_compl.1 (Finset.orderEmbOfFin_mem _ _ _)

@[simp]
theorem curryFinFinset_symm_apply_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k)
    (hl : #sᶜ = l) (f : (Fin k → M') →ₘₛₗ[σ] (Fin l → M') →ₘₛₗ[σ] M₂) (x : M') :
    ((curryFinFinset σ M₂ M' hk hl).symm f fun _ => x) = f (fun _ => x) fun _ => x :=
  rfl

theorem curryFinFinset_apply_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k)
    (hl : #sᶜ = l) (f : (Fin n → M') →ₘₛₗ[σ] M₂) (x y : M') :
    (curryFinFinset σ M₂ M' hk hl f (fun _ => x) fun _ => y) =
      f (s.piecewise (fun _ => x) fun _ => y) := by
  rw [← curryFinFinset_symm_apply_piecewise_const hk hl, LinearEquiv.symm_apply_apply]

end MultilinearMap

Messung
CHZG
9210010097

¤ Dauer der Verarbeitung: 0.19 Sekunden  ¤

*© Formatika GbR, Deutschland







                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

Open Source Software


Gedichte
Musik
Bilder

Jenseits des Üblichen

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1,188,113
#Domains=863,270