-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add QuotientBasis * Add tests * Fix format
- Loading branch information
Showing
5 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
struct QuotientBasis{T,I,B<:SA.AbstractBasis{T,I},D} <: SA.ExplicitBasis{T,I} | ||
basis::B | ||
divisor::D | ||
end | ||
|
||
Base.length(basis::QuotientBasis) = length(basis.basis) | ||
|
||
function MP.coefficients(p, basis::QuotientBasis) | ||
return MP.coefficients(rem(p, basis.divisor), basis.basis) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
struct PlusMinusOne # Reduce modulo `x^2 = 1` | ||
end | ||
function Base.rem(m::AbstractMonomial, ::PlusMinusOne) | ||
return prod(v^mod(e, 2) for (v, e) in powers(m)) | ||
end | ||
function Base.rem(t::AbstractTerm, d::PlusMinusOne) | ||
return coefficient(t) * rem(monomial(t), d) | ||
end | ||
function Base.rem(p::AbstractPolynomial, d::PlusMinusOne) | ||
return sum(rem(t, d) for t in terms(p)) | ||
end | ||
|
||
@testset "PlusMinusOne" begin | ||
@polyvar x y | ||
basis = | ||
MB.QuotientBasis(MB.SubBasis{MB.Monomial}([1, y, x]), PlusMinusOne()) | ||
@test length(basis) == 3 | ||
@test coefficients(x^3 - 2x^2 * y + 3x^2, basis) == [3, -2, 1] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters