Documentation

PolyFun.PFunctor.Lens.Basic

More properties about lenses between polynomial functors #

theorem heq_forall_iff {α : Sort u} {β γ : αSort v} (h : ∀ (a : α), β a = γ a) {f : (a : α) → β a} {g : (a : α) → γ a} :
f g ∀ (a : α), f a g a
theorem PFunctor.Lens.ext {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} (l₁ l₂ : P.Lens Q) (h₁ : ∀ (a : P.A), l₁.toFunA a = l₂.toFunA a) (h₂ : ∀ (a : P.A), l₁.toFunB a = Eq.rec (motive := fun (x : Q.A) (h : l₂.toFunA a = x) => Q.B xP.B a) (l₂.toFunB a) ) :
l₁ = l₂
theorem PFunctor.Lens.ext_heq {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} (l₁ l₂ : P.Lens Q) (hA : l₁.toFunA = l₂.toFunA) (hB : l₁.toFunB l₂.toFunB) :
l₁ = l₂

Heterogeneous extensionality for lenses: equal position maps and heterogeneously equal direction maps identify two lenses. Useful when the direction families are equal only after rewriting along the position map.

@[reducible]

The identity lens

Instances For

    Composition of lenses

    Instances For

      Composition of lenses

      Instances For
        def PFunctor.Lens.mapObj {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} (l : P.Lens Q) {α : Type v} (x : P α) :
        Q α

        Apply a polynomial lens to an element of the source polynomial's extension. The position is sent forward and the payload is pulled back along the lens's direction map.

        Instances For
          @[simp]
          theorem PFunctor.Lens.mapObj_id {P : PFunctor.{uA, uB}} {α : Type v} (x : P α) :
          (Lens.id P).mapObj x = x
          @[simp]
          theorem PFunctor.Lens.mapObj_comp {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} {R : PFunctor.{uA₃, uB₃}} (g : Q.Lens R) (f : P.Lens Q) {α : Type v} (x : P α) :
          (g ∘ₗ f).mapObj x = g.mapObj (f.mapObj x)
          theorem PFunctor.Lens.ext_mapObj {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} (l₁ l₂ : P.Lens Q) (h : ∀ (a : P.A), l₁.mapObj (Obj.mk a id) = l₂.mapObj (Obj.mk a id)) :
          l₁ = l₂

          Two lenses are equal when they act equally on every source position equipped with its identity direction labelling. This packages the dependent position equality and direction-map transport needed by Lens.ext.

          structure PFunctor.Lens.Equiv (P : PFunctor.{uA₁, uB₁}) (Q : PFunctor.{uA₂, uB₂}) :
          Type (max (max (max uA₁ uA₂) uB₁) uB₂)

          An equivalence between two polynomial functors P and Q, using lenses. This corresponds to an isomorphism in the category PFunctor with Lens morphisms.

          Instances For
            theorem PFunctor.Lens.Equiv.ext {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} {x y : P ≃ₗ Q} (toLens : x.toLens = y.toLens) (invLens : x.invLens = y.invLens) :
            x = y

            An equivalence between two polynomial functors P and Q, using lenses. This corresponds to an isomorphism in the category PFunctor with Lens morphisms.

            Instances For

              The identity equivalence on P, built from the identity lens in both directions.

              Instances For

                The inverse equivalence, swapping the forward and backward lenses of e.

                Instances For

                  The composite equivalence P ≃ₗ R obtained by chaining e₁ : P ≃ₗ Q and e₂ : Q ≃ₗ R.

                  Instances For

                    Cancel postcomposition with the forward lens of a lens equivalence.

                    The (unique) initial lens from the zero functor to any functor P.

                    Instances For

                      The (unique) terminal lens from any functor P to the unit functor 1.

                      Instances For

                        Alias of PFunctor.Lens.initial.


                        The (unique) initial lens from the zero functor to any functor P.

                        Instances For

                          Alias of PFunctor.Lens.terminal.


                          The (unique) terminal lens from any functor P to the unit functor 1.

                          Instances For

                            Construct a lens from the variable polynomial by selecting a position. The backward map is uniquely determined by the unit direction of y.

                            Instances For
                              @[simp]
                              @[deprecated PFunctor.Lens.fromY (since := "2026-08-17")]

                              Alias of PFunctor.Lens.fromY.


                              Construct a lens from the variable polynomial by selecting a position. The backward map is uniquely determined by the unit direction of y.

                              Instances For
                                @[deprecated PFunctor.Lens.fromY_toFunA (since := "2026-08-17")]

                                Alias of PFunctor.Lens.fromY_toFunA.

                                @[deprecated PFunctor.Lens.fromY_toFunB (since := "2026-08-17")]

                                Alias of PFunctor.Lens.fromY_toFunB.

                                def PFunctor.Lens.toConst {P : PFunctor.{uA, uB}} {A : Type uA₂} (f : P.AA) :
                                P.Lens (C A)

                                Construct a lens into a constant polynomial from its position map. The backward map is uniquely determined by the empty direction type.

                                Instances For
                                  @[simp]
                                  theorem PFunctor.Lens.toConst_toFunA {P : PFunctor.{uA, uB}} {A : Type uA₂} (f : P.AA) (a : P.A) :
                                  (toConst f).toFunA a = f a
                                  def PFunctor.Lens.toLinear {P : PFunctor.{uA, uB}} {A : Type uA₂} (f : P.AA) (choose : (a : P.A) → P.B a) :
                                  P.Lens (linear A)

                                  Construct a lens into a linear polynomial from a position map and a choice of source direction over every position.

                                  Instances For
                                    @[simp]
                                    theorem PFunctor.Lens.toLinear_toFunA {P : PFunctor.{uA, uB}} {A : Type uA₂} (f : P.AA) (choose : (a : P.A) → P.B a) (a : P.A) :
                                    (toLinear f choose).toFunA a = f a
                                    @[simp]
                                    theorem PFunctor.Lens.toLinear_toFunB {P : PFunctor.{uA, uB}} {A : Type uA₂} (f : P.AA) (choose : (a : P.A) → P.B a) (a : P.A) (u : PUnit.{uB₁ + 1}) :
                                    (toLinear f choose).toFunB a u = choose a

                                    Left injection lens inl : P → P + Q

                                    Instances For

                                      Right injection lens inr : Q → P + Q

                                      Instances For

                                        Copairing of lenses [l₁, l₂]ₗ : P + Q → R

                                        Instances For

                                          Parallel application of lenses for coproduct l₁ ⊎ l₂ : P + Q → R + W

                                          Instances For
                                            def PFunctor.Lens.sigmaExists {I : Type v} {F : IPFunctor.{uA₁, uB₁}} {R : PFunctor.{uA₂, uB₂}} (l : (i : I) → (F i).Lens R) :
                                            (sigma F).Lens R

                                            Dependent copairing of lenses over sigma: Σ i, F i → R.

                                            Instances For
                                              def PFunctor.Lens.sigmaMap {I : Type v} {F : IPFunctor.{uA₁, uB₁}} {G : IPFunctor.{uA₂, uB₂}} (l : (i : I) → (F i).Lens (G i)) :
                                              (sigma F).Lens (sigma G)

                                              Pointwise mapping of lenses over sigma.

                                              Instances For

                                                Projection lens fst : P * Q → P

                                                Instances For

                                                  Projection lens snd : P * Q → Q

                                                  Instances For

                                                    Pairing of lenses ⟨l₁, l₂⟩ₗ : P → Q * R

                                                    Instances For

                                                      Parallel application of lenses for product l₁ ×ₗ l₂ : P * Q → R * W

                                                      Instances For
                                                        def PFunctor.Lens.piForall {I : Type v} {P : PFunctor.{uA₁, uB₁}} {F : IPFunctor.{uA₂, uB₂}} (l : (i : I) → P.Lens (F i)) :
                                                        P.Lens (pi F)

                                                        Dependent pairing of lenses into a pi: P → ∀ i, F i.

                                                        Instances For
                                                          def PFunctor.Lens.piMap {I : Type v} {F : IPFunctor.{uA₁, uB₁}} {G : IPFunctor.{uA₂, uB₂}} (l : (i : I) → (F i).Lens (G i)) :
                                                          (pi F).Lens (pi G)

                                                          Pointwise mapping of lenses over pi.

                                                          Instances For

                                                            Apply lenses to both sides of a composition: l₁ ◃ₗ l₂ : (P ◃ Q ⇆ R ◃ W)

                                                            Instances For
                                                              @[implicit_reducible]

                                                              Apply lenses to both sides of a tensor / parallel product: l₁ ⊗ₗ l₂ : (P ⊗ Q ⇆ R ⊗ W)

                                                              Instances For

                                                                Lens to introduce y on the right: P → P ◃ y

                                                                Instances For

                                                                  Lens to introduce y on the left: P → y ◃ P

                                                                  Instances For

                                                                    Lens from P ◃ y to P

                                                                    Instances For

                                                                      Lens from y ◃ P to P

                                                                      Instances For

                                                                        Apply lenses to both sides of a composition: l₁ ◃ₗ l₂ : (P ◃ Q ⇆ R ◃ W)

                                                                        Instances For

                                                                          Parallel application of lenses for product l₁ ×ₗ l₂ : P * Q → R * W

                                                                          Instances For

                                                                            Parallel application of lenses for coproduct l₁ ⊎ l₂ : P + Q → R + W

                                                                            Instances For

                                                                              Apply lenses to both sides of a tensor / parallel product: l₁ ⊗ₗ l₂ : (P ⊗ Q ⇆ R ⊗ W)

                                                                              Instances For

                                                                                Notation for the copairing sumPair l₁ l₂ of two lenses out of a sum.

                                                                                Instances For

                                                                                  Notation for the pairing prodPair l₁ l₂ of two lenses into a product.

                                                                                  Instances For
                                                                                    def PFunctor.Lens.enclose (P : PFunctor.{uA, uB}) :
                                                                                    Type (max uA uA₁ uB uB₁)

                                                                                    The type of lenses from a polynomial functor P to y

                                                                                    Instances For

                                                                                      The transition lens δ : Sy^S ⇆ Sy^S ◃ Sy^S on the self-monomial state polynomial (Spivak–Niu Example 6.44): δ = (id, tgt, run) remembers the start state, relabels each direction by the state it targets, and composes two hops into one. It is the comultiplication of the state comonoid stateComonoid S, and the helper behind speedup.

                                                                                      Instances For

                                                                                        The speedup lens operation: Lens (S y^S) P → Lens (S y^S) (P ◃ P)

                                                                                        Instances For

                                                                                          Commutativity of coproduct

                                                                                          Instances For

                                                                                            Associativity of coproduct

                                                                                            Instances For

                                                                                              Coproduct with 0 is identity (right)

                                                                                              Instances For

                                                                                                Coproduct with 0 is identity (left)

                                                                                                Instances For

                                                                                                  Commutativity of product

                                                                                                  Instances For

                                                                                                    Associativity of product

                                                                                                    Instances For

                                                                                                      Product with 1 is identity (right)

                                                                                                      Instances For

                                                                                                        Product with 1 is identity (left)

                                                                                                        Instances For

                                                                                                          Product with 0 is zero (right)

                                                                                                          Instances For

                                                                                                            Product with 0 is zero (left)

                                                                                                            Instances For

                                                                                                              Left distributive law for product over coproduct

                                                                                                              Instances For

                                                                                                                Right distributive law for coproduct over product

                                                                                                                Instances For
                                                                                                                  theorem PFunctor.Lens.compMap_comp {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} {R : PFunctor.{uA₃, uB₃}} {P' : PFunctor.{uA₄, uB₄}} {Q' : PFunctor.{uA₅, uB₅}} {R' : PFunctor.{uA₆, uB₆}} (l₁ : P.Lens P') (l₂ : Q.Lens Q') (l₁' : P'.Lens R) (l₂' : Q'.Lens R') :
                                                                                                                  l₁' ∘ₗ l₁ ◃ₗ (l₂' ∘ₗ l₂) = l₁' ◃ₗ l₂' ∘ₗ (l₁ ◃ₗ l₂)

                                                                                                                  Associativity of composition

                                                                                                                  Instances For

                                                                                                                    Composition with y is identity (right)

                                                                                                                    Instances For

                                                                                                                      Composition with y is identity (left)

                                                                                                                      Instances For
                                                                                                                        @[deprecated PFunctor.Lens.Equiv.compY (since := "2026-08-17")]

                                                                                                                        Alias of PFunctor.Lens.Equiv.compY.


                                                                                                                        Composition with y is identity (right)

                                                                                                                        Instances For
                                                                                                                          @[deprecated PFunctor.Lens.Equiv.yComp (since := "2026-08-17")]

                                                                                                                          Alias of PFunctor.Lens.Equiv.yComp.


                                                                                                                          Composition with y is identity (left)

                                                                                                                          Instances For

                                                                                                                            Distributivity of composition over coproduct on the right

                                                                                                                            Instances For
                                                                                                                              theorem PFunctor.Lens.tensorMap_comp {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} {R : PFunctor.{uA₃, uB₃}} {P' : PFunctor.{uA₄, uB₄}} {Q' : PFunctor.{uA₅, uB₅}} {R' : PFunctor.{uA₆, uB₆}} (l₁ : P.Lens P') (l₂ : Q.Lens Q') (l₁' : P'.Lens R) (l₂' : Q'.Lens R') :
                                                                                                                              l₁' ∘ₗ l₁ ⊗ₗ (l₂' ∘ₗ l₂) = l₁' ⊗ₗ l₂' ∘ₗ (l₁ ⊗ₗ l₂)

                                                                                                                              Commutativity of tensor product

                                                                                                                              Instances For

                                                                                                                                Associativity of tensor product

                                                                                                                                Instances For
                                                                                                                                  @[simp]
                                                                                                                                  theorem PFunctor.Lens.Equiv.tensorAssoc_toFunA {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} {R : PFunctor.{uA₃, uB₃}} (position : ((P.tensor Q).tensor R).A) :
                                                                                                                                  tensorAssoc.toLens.toFunA position = (position.1.1, position.1.2, position.2)
                                                                                                                                  @[simp]
                                                                                                                                  theorem PFunctor.Lens.Equiv.tensorAssoc_toFunB {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uA₂, uB₂}} {R : PFunctor.{uA₃, uB₃}} (position : ((P.tensor Q).tensor R).A) (direction : (P.tensor (Q.tensor R)).B (tensorAssoc.toLens.toFunA position)) :
                                                                                                                                  tensorAssoc.toLens.toFunB position direction = ((direction.1, direction.2.1), direction.2.2)

                                                                                                                                  Tensor product with y is identity (right)

                                                                                                                                  Instances For

                                                                                                                                    Tensor product with y is identity (left)

                                                                                                                                    Instances For
                                                                                                                                      @[deprecated PFunctor.Lens.Equiv.tensorY (since := "2026-08-17")]

                                                                                                                                      Alias of PFunctor.Lens.Equiv.tensorY.


                                                                                                                                      Tensor product with y is identity (right)

                                                                                                                                      Instances For
                                                                                                                                        @[deprecated PFunctor.Lens.Equiv.yTensor (since := "2026-08-17")]

                                                                                                                                        Alias of PFunctor.Lens.Equiv.yTensor.


                                                                                                                                        Tensor product with y is identity (left)

                                                                                                                                        Instances For

                                                                                                                                          Tensor product with 0 is zero (left)

                                                                                                                                          Instances For

                                                                                                                                            Tensor product with 0 is zero (right)

                                                                                                                                            Instances For

                                                                                                                                              Left distributivity of tensor product over coproduct

                                                                                                                                              Instances For

                                                                                                                                                Right distributivity of tensor product over coproduct

                                                                                                                                                Instances For

                                                                                                                                                  The unique comparison between two possibly differently instantiated copies of the common tensor/composition unit y.

                                                                                                                                                  Instances For

                                                                                                                                                    Naturality of the left tensor unitor. The unit component is the canonical comparison between the independently instantiated source and target copies of y.

                                                                                                                                                    Naturality of the right tensor unitor. The unit component is the canonical comparison between the independently instantiated source and target copies of y.

                                                                                                                                                    @[deprecated PFunctor.Lens.yTensor_natural (since := "2026-08-17")]

                                                                                                                                                    Alias of PFunctor.Lens.yTensor_natural.


                                                                                                                                                    Naturality of the left tensor unitor. The unit component is the canonical comparison between the independently instantiated source and target copies of y.

                                                                                                                                                    @[deprecated PFunctor.Lens.tensorY_natural (since := "2026-08-17")]

                                                                                                                                                    Alias of PFunctor.Lens.tensorY_natural.


                                                                                                                                                    Naturality of the right tensor unitor. The unit component is the canonical comparison between the independently instantiated source and target copies of y.

                                                                                                                                                    Naturality of the tensor associator across lenses whose source and target polynomials may occupy six independent universe pairs.

                                                                                                                                                    Convert an equivalence between two polynomial functors P and Q to a lens.

                                                                                                                                                    Instances For
                                                                                                                                                      instance PFunctor.Lens.instIsEmptyBSigma {I : Type v} [IsEmpty I] {F : IPFunctor.{u, u_1}} {a : (sigma F).A} :
                                                                                                                                                      IsEmpty ((sigma F).B a)

                                                                                                                                                      Sigma of an empty family is the zero functor.

                                                                                                                                                      Instances For

                                                                                                                                                        Sigma of a PUnit-indexed family is equivalent to the functor itself (up to ulift).

                                                                                                                                                        Instances For

                                                                                                                                                          Sigma of a unique-indexed family is equivalent to the default fiber (up to ulift).

                                                                                                                                                          Instances For

                                                                                                                                                            Left distributivity of product over sigma.

                                                                                                                                                            Instances For

                                                                                                                                                              Right distributivity of product over sigma.

                                                                                                                                                              Instances For

                                                                                                                                                                Left distributivity of tensor product over sigma.

                                                                                                                                                                Instances For

                                                                                                                                                                  Right distributivity of tensor product over sigma.

                                                                                                                                                                  Instances For

                                                                                                                                                                    Right distributivity of composition over sigma.

                                                                                                                                                                    Instances For

                                                                                                                                                                      Pi over a PUnit-indexed family is equivalent to the functor itself.

                                                                                                                                                                      Instances For
                                                                                                                                                                        def PFunctor.Lens.piZero {I : Type v} [Inhabited I] {F : IPFunctor.{uA, uB}} (F_zero : ∀ (i : I), F i = 0) :

                                                                                                                                                                        Pi of a family of zero functors over an inhabited type is the zero functor.

                                                                                                                                                                        Instances For

                                                                                                                                                                          ULift equivalence for lenses

                                                                                                                                                                          Instances For