-
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.
- Loading branch information
Showing
10 changed files
with
173 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
module MultivariateBases | ||
|
||
import MutableArithmetics | ||
const MA = MutableArithmetics | ||
|
||
using MultivariatePolynomials | ||
const MP= MultivariatePolynomials | ||
const MP = MultivariatePolynomials | ||
|
||
export AbstractPolynomialBasis | ||
export FixedPolynomialBasis, ScaledMonomialBasis, MonomialBasis | ||
|
||
export maxdegree_basis, empty_basis | ||
include("interface.jl") | ||
|
||
export AbstractMonomialBasis, MonomialBasis, ScaledMonomialBasis | ||
include("monomial.jl") | ||
include("fixed.jl") | ||
include("scaled.jl") | ||
|
||
export FixedPolynomialBasis, ChebyshevBasis | ||
include("fixed.jl") | ||
include("chebyshev.jl") | ||
|
||
end # module |
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,26 @@ | ||
struct ChebyshevBasis{P} <: AbstractPolynomialVectorBasis{P, Vector{P}} | ||
polynomials::Vector{P} | ||
end | ||
|
||
function chebyshev_polynomial_first_kind(variable::MP.AbstractVariable, degree::Integer) | ||
@assert degree >= 0 | ||
if degree == 0 | ||
return [MA.@rewrite(0 * variable + 1)] | ||
elseif degree == 1 | ||
return push!(chebyshev_polynomial_first_kind(variable, 0), | ||
MA.@rewrite(1 * variable + 0)) | ||
else | ||
previous = chebyshev_polynomial_first_kind(variable, degree - 1) | ||
next = MA.@rewrite(2variable * previous[degree] - previous[degree - 1]) | ||
push!(previous, next) | ||
return previous | ||
end | ||
end | ||
|
||
function maxdegree_basis(B::Type{ChebyshevBasis}, variables, maxdegree::Int) | ||
univariate = [chebyshev_polynomial_first_kind(variable, maxdegree) for variable in variables] | ||
return ChebyshevBasis([ | ||
prod(i -> univariate[i][degree(mono, variables[i]) + 1], | ||
eachindex(variables)) | ||
for mono in MP.monomials(variables, 0:maxdegree)]) | ||
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
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,16 @@ | ||
using Test | ||
using MultivariateBases | ||
using DynamicPolynomials | ||
@polyvar x y | ||
|
||
@testset "Univariate" begin | ||
basis = maxdegree_basis(ChebyshevBasis, (x,), 3) | ||
@test basis.polynomials[4] == 1 | ||
@test basis.polynomials[3] == x | ||
@test basis.polynomials[2] == 2x^2 - 1 | ||
@test basis.polynomials[1] == 4x^3 - 3x | ||
end | ||
|
||
@testset "API degree = $degree" for degree in 0:3 | ||
api_test(ChebyshevBasis, degree) | ||
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
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
6e62d70
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.
@JuliaRegistrator register
6e62d70
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.
Registration pull request created: JuliaRegistries/General/8353
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via: