Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cslib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public import Cslib.Foundations.Data.OmegaSequence.Flatten
public import Cslib.Foundations.Data.OmegaSequence.InfOcc
public import Cslib.Foundations.Data.OmegaSequence.Init
public import Cslib.Foundations.Data.OmegaSequence.Temporal
public import Cslib.Foundations.Data.PFunctor.Basic
public import Cslib.Foundations.Data.PFunctor.Free
public import Cslib.Foundations.Data.RelatesInSteps
public import Cslib.Foundations.Data.Set.Saturation
Expand Down
97 changes: 97 additions & 0 deletions Cslib/Foundations/Data/PFunctor/Basic.lean

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I suggest you first make a PR that just adds this file, without the link to FreeM yet?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split this off into #803

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/-
Copyright (c) 2026 PolyFun Contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Devon Tuma, Quang Dao
-/
module

public import Cslib.Init
public import Mathlib.Data.PFunctor.Univariate.Basic

/-!
# Polynomial Functors

This file defines additional constructions on `PFunctor` that don't belong in core mathlib.
The main definitions is `monomial A B` for the `PFunctor` with constant family `B` over `A`,
as well as special cases of this such as a canonical choice of `0` and `1`.

We also define the sum `P + Q` whose shapes are a sum of the shapes of `P` and `Q`,
with a type family defined by sum elimination into the individual child types of `P` and `Q`.
-/

@[expose] public section

universe uA uB uA₁ uA₂

namespace PFunctor

section monomial

/-- The monomial `PFunctor` with head type `A` and constant `B` for any `a : A`. -/
abbrev monomial (A : Type uA) (B : Type uB) : PFunctor := ⟨A, fun _ => B⟩

lemma monomial_A (A : Type uA) (B : Type uB) : (monomial A B).A = A := rfl

lemma monomial_B (A : Type uA) (B : Type uB) (a : (monomial A B).A) :
(monomial A B).B a = B := rfl

end monomial

section zero

/-- The zero polynomial functor, defined as `A = PEmpty` and `B _ = PEmpty`, is the identity with
respect to sum (up to equivalence) -/
instance instZeroPFunctor : Zero PFunctor where zero := monomial PEmpty PEmpty

@[simp] lemma zero_A : (0 : PFunctor).A = PEmpty := rfl

@[simp] lemma zero_B (a : (0 : PFunctor).A) : (0 : PFunctor).B a = PEmpty := rfl

end zero

section one

/-- The unit polynomial functor, defined as `A = PUnit` and `B _ = PEmpty`, is the identity with
respect to product (up to equivalence) -/
instance instOnePFunctor : One PFunctor where one := monomial PUnit PEmpty

@[simp] lemma one_A : (1 : PFunctor).A = PUnit := rfl

@[simp] lemma one_B (a : (1 : PFunctor).A) : (1 : PFunctor).B a = PEmpty := rfl
Comment thread
dtumad marked this conversation as resolved.

end one

/-- The constant polynomial functor `P(X) = A X^ PEmpty = A` -/
abbrev const (A : Type uA) : PFunctor := monomial A PEmpty

/-- The linear polynomial functor `P(X) = A X` -/
abbrev linear (A : Type uA) : PFunctor := monomial A PUnit

/-- The self monomial polynomial functor `P(X) = S X^ S` -/
abbrev selfMonomial (S : Type uA) : PFunctor.{uA, uA} := monomial S S

/-- The pure power polynomial functor `P(X) = X^ B` -/
abbrev purePower (B : Type uB) : PFunctor := monomial PUnit B

section add

/-- The sum of two polynomial functors `P` and `Q`, written as `P + Q`,
defined as the sum of the head types and the sum case analysis for the child types. -/
def add (P : PFunctor.{uA₁, uB}) (Q : PFunctor.{uA₂, uB}) :
PFunctor.{max uA₁ uA₂, uB} := ⟨P.A ⊕ Q.A, Sum.elim P.B Q.B⟩

instance instHAddPFunctor :
HAdd PFunctor.{uA₁, uB} PFunctor.{uA₂, uB} PFunctor.{max uA₁ uA₂, uB} where
hAdd := add
Comment on lines +78 to +85

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, do we need both here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, or at least it seems useful with universe level changes because + notation seems to unify earlier (see tests in #803).


@[simp] lemma add_A (P Q : PFunctor) : (add P Q).A = (P.A ⊕ Q.A) := rfl

@[simp] lemma add_B_inl (P : PFunctor.{uA₁, uB}) (Q : PFunctor.{uA₂, uB}) (a : P.A) :
(add P Q).B (.inl a) = P.B a := rfl
Comment on lines +89 to +90

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ill-typed, because (add P Q).B is not a function from Sum _ _ but from (add P Q).A which isn't reducible


@[simp] lemma add_B_inr (P : PFunctor.{uA₁, uB}) (Q : PFunctor.{uA₂, uB}) (a : Q.A) :
(add P Q).B (.inr a) = Q.B a := rfl

end add

end PFunctor
Loading
Loading