Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 4 additions & 8 deletions src/Algebra/Polynomial/Base.agda
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
open import Algebra.Bundles using (CommutativeRing)
open import Algebra.Bundles using (Semiring)
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.Base
{ℓ₁ ℓ₂} (CR : CommutativeRing ℓ₁ ℓ₂)
{ℓ₁ ℓ₂} (SR : Semiring ℓ₁ ℓ₂)
where

open import Algebra.Polynomial.Poly.Base CR as Poly
open import Algebra.Polynomial.Poly.Base SR as Poly
using (Poly; zeros)

open CommutativeRing CR
open Semiring SR
using (0#; 1#)
renaming (Carrier to A)

Expand Down Expand Up @@ -65,10 +65,6 @@ one = (1 , (1# ∷ []))
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)
Expand Down
82 changes: 82 additions & 0 deletions src/Algebra/Polynomial/Base1.agda
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
Copy link
Contributor

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?

{ℓ₁ ℓ₂} (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 _,_
Copy link
Contributor

Choose a reason for hiding this comment

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

I strongly object to overloading _,_ for this constructor!

field
degree : ℕ
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
82 changes: 82 additions & 0 deletions src/Algebra/Polynomial/Base2.agda
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 _,_
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Loading