-
Notifications
You must be signed in to change notification settings - Fork 185
feat(PFunctor): redefine PFunctor.FreeM in terms of PFunctor.W
#731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8be5d5e
fce6853
12769cf
0e1c43d
3e6282b
e0440af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, do we need both here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| @[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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ill-typed, because |
||
|
|
||
| @[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 | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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