-
Notifications
You must be signed in to change notification settings - Fork 257
[draft] Polynomial #2821
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: master
Are you sure you want to change the base?
[draft] Polynomial #2821
Changes from 1 commit
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,82 @@ | ||
open import Algebra.Bundles using (Ring) | ||
open import Data.Nat.Base as ℕ using (ℕ; _⊔_; suc; pred) | ||
open import Data.Product.Base using (_,_) | ||
open import Data.Vec.Base as Vec using ([]; _∷_) | ||
import Level as L | ||
|
||
module Algebra.Polynomial.Base1 | ||
{ℓ₁ ℓ₂} (R : Ring ℓ₁ ℓ₂) | ||
where | ||
|
||
open import Algebra.Polynomial.Poly.Base1 R as Poly | ||
using (Poly; zeros) | ||
|
||
open Ring R | ||
using (0#; 1#) | ||
renaming (Carrier to A) | ||
|
||
private | ||
variable | ||
m n k : ℕ | ||
p : Poly m | ||
q : Poly n | ||
r : Poly k | ||
|
||
--------------------------------------------------- | ||
-- Types | ||
|
||
record Polynomial : Set ℓ₁ where | ||
constructor _,_ | ||
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 strongly object to overloading |
||
field | ||
degree : ℕ | ||
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. There should be a comment here that the "degree" is off-by-one from the usual notion of the degree of a polynomial. It is more like a length than a degree. |
||
polynomial : Poly degree | ||
|
||
private | ||
variable | ||
P Q W : Polynomial | ||
|
||
-- Equivalence relation for representations of polynomials | ||
infix 4 _≈_ | ||
_≈_ : Polynomial → Polynomial → Set (ℓ₁ L.⊔ ℓ₂) | ||
(m , p) ≈ (n , q) = p Poly.≈ q | ||
|
||
refl : P ≈ P | ||
refl = Poly.refl | ||
|
||
sym : P ≈ Q → Q ≈ P | ||
sym = Poly.sym | ||
|
||
trans : P ≈ Q → Q ≈ W → P ≈ W | ||
trans = Poly.trans | ||
|
||
-------------------------------------------------- | ||
-- Constants | ||
|
||
zero : Polynomial | ||
zero = (0 , []) | ||
|
||
one : Polynomial | ||
one = (1 , (1# ∷ [])) | ||
|
||
--------------------------------------------------- | ||
-- Operations | ||
|
||
-- Multiply the polynomial by a factor of x | ||
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'd say "by x" rather than "by a factor of x", as I wondering "what factor?" And why not implement `shift :: ℕ → Polynomial → Polynomial instread? |
||
shift : Polynomial → Polynomial | ||
shift (m , p) = (suc m , Poly.shift p) | ||
|
||
-- Negation | ||
-_ : Polynomial → Polynomial | ||
- (m , p) = (m , Poly.- p) | ||
|
||
-- Scaling | ||
_·_ : A → Polynomial → Polynomial | ||
a · (m , p) = (m , a Poly.· p) | ||
|
||
-- Addition | ||
_+_ : Polynomial → Polynomial → Polynomial | ||
(m , p) + (n , q) = (m ⊔ n , p Poly.+ q) | ||
|
||
-- Multiplication | ||
_*_ : Polynomial → Polynomial → Polynomial | ||
(m , p) * (n , q) = (pred (m ℕ.+ n) , p Poly.* q) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
open import Algebra.Bundles using (CommutativeRing) | ||
open import Data.Nat.Base as ℕ using (ℕ; _⊔_; suc; pred) | ||
open import Data.Product.Base using (_,_) | ||
open import Data.Vec.Base as Vec using ([]; _∷_) | ||
import Level as L | ||
|
||
module Algebra.Polynomial.Base2 | ||
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. Same comment about the name |
||
{ℓ₁ ℓ₂} (CR : CommutativeRing ℓ₁ ℓ₂) | ||
where | ||
|
||
open import Algebra.Polynomial.Poly.Base2 CR as Poly | ||
using (Poly; zeros) | ||
|
||
open CommutativeRing CR | ||
using (0#; 1#) | ||
renaming (Carrier to A) | ||
|
||
private | ||
variable | ||
m n k : ℕ | ||
p : Poly m | ||
q : Poly n | ||
r : Poly k | ||
|
||
--------------------------------------------------- | ||
-- Types | ||
|
||
record Polynomial : Set ℓ₁ where | ||
constructor _,_ | ||
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. and the name of this constructor (won't repeat other comments that also apply) |
||
field | ||
degree : ℕ | ||
polynomial : Poly degree | ||
|
||
private | ||
variable | ||
P Q R : Polynomial | ||
|
||
-- Equivalence relation for representations of polynomials | ||
infix 4 _≈_ | ||
_≈_ : Polynomial → Polynomial → Set (ℓ₁ L.⊔ ℓ₂) | ||
(m , p) ≈ (n , q) = p Poly.≈ q | ||
|
||
refl : P ≈ P | ||
refl = Poly.refl | ||
|
||
sym : P ≈ Q → Q ≈ P | ||
sym = Poly.sym | ||
|
||
trans : P ≈ Q → Q ≈ R → P ≈ R | ||
trans = Poly.trans | ||
|
||
-------------------------------------------------- | ||
-- Constants | ||
|
||
zero : Polynomial | ||
zero = (0 , []) | ||
|
||
one : Polynomial | ||
one = (1 , (1# ∷ [])) | ||
|
||
--------------------------------------------------- | ||
-- Operations | ||
|
||
-- Multiply the polynomial by a factor of x | ||
shift : Polynomial → Polynomial | ||
shift (m , p) = (suc m , Poly.shift p) | ||
|
||
-- Negation | ||
-_ : Polynomial → Polynomial | ||
- (m , p) = (m , Poly.- p) | ||
|
||
-- Scaling | ||
_·_ : A → Polynomial → Polynomial | ||
a · (m , p) = (m , a Poly.· p) | ||
|
||
-- Addition | ||
_+_ : Polynomial → Polynomial → Polynomial | ||
(m , p) + (n , q) = (m ⊔ n , p Poly.+ q) | ||
|
||
-- Multiplication | ||
_*_ : Polynomial → Polynomial → Polynomial | ||
(m , p) * (n , q) = (pred (m ℕ.+ n) , p Poly.* q) |
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.
Base1
is quite a rotten name. I'm sure we can help find a better name, once we know the intent?