-
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.
Merge pull request #2 from JuliaAlgebra/bl/orthogonal
Add classical multiple orthogonal basis
- Loading branch information
Showing
16 changed files
with
454 additions
and
44 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,5 +1,6 @@ | ||
[deps] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
MultivariateBases = "be282fd4-ad43-11e9-1d11-8bd9d7e43378" | ||
|
||
[compat] | ||
Documenter = "~0.21" |
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,11 +1,42 @@ | ||
```@meta | ||
DocTestSetup = quote | ||
using MultivariateBases | ||
end | ||
``` | ||
|
||
# MultivariateBases | ||
|
||
[MultivariateBases.jl](https://github.com/JuliaAlgebra/MultivariateBases.jl) is a standardized API for multivariate polynomial bases | ||
based on the [MultivariatePolynomials](https://github.com/JuliaAlgebra/MultivariatePolynomials.jl) API. | ||
|
||
```@docs | ||
AbstractPolynomialBasis | ||
maxdegree_basis | ||
basis_covering_monomials | ||
FixedPolynomialBasis | ||
``` | ||
|
||
## Monomial basis | ||
|
||
```@docs | ||
MonomialBasis | ||
ScaledMonomialBasis | ||
``` | ||
|
||
## Orthogonal basis | ||
|
||
```@docs | ||
AbstractMultipleOrthogonalBasis | ||
univariate_orthogonal_basis | ||
reccurence_first_coef | ||
reccurence_second_coef | ||
reccurence_third_coef | ||
reccurence_deno_coef | ||
ProbabilistsHermiteBasis | ||
PhysicistsHermiteBasis | ||
LaguerreBasis | ||
AbstractGegenbauerBasis | ||
LegendreBasis | ||
ChebyshevBasisFirstKind | ||
ChebyshevBasisSecondKind | ||
``` |
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,26 +1,35 @@ | ||
struct ChebyshevBasis{P} <: AbstractPolynomialVectorBasis{P, Vector{P}} | ||
abstract type AbstractChebyshevBasis{P} <: AbstractGegenbauerBasis{P} end | ||
|
||
polynomial_type(::Type{<:AbstractChebyshevBasis}, V::Type) = MP.polynomialtype(V, Float64) | ||
|
||
reccurence_first_coef(::Type{<:AbstractChebyshevBasis}, degree) = 2 | ||
reccurence_third_coef(::Type{<:AbstractChebyshevBasis}, degree) = -1 | ||
reccurence_deno_coef(::Type{<:AbstractChebyshevBasis}, degree) = 1 | ||
|
||
""" | ||
struct ChebyshevBasisFirstKind{P} <: AbstractChebyshevBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
Orthogonal polynomial with respect to the univariate weight function ``w(x) = \\frac{1}{\\sqrt{1 - x^2}}`` over the interval ``[-1, 1]``. | ||
""" | ||
struct ChebyshevBasisFirstKind{P} <: AbstractChebyshevBasis{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 | ||
const ChebyshevBasis{P} = ChebyshevBasisFirstKind{P} | ||
|
||
degree_one_univariate_polynomial(::Type{<:ChebyshevBasisFirstKind}, variable::MP.AbstractVariable) = MA.@rewrite(variable + 0) | ||
|
||
""" | ||
struct ChebyshevBasisSecondKind{P} <: AbstractChebyshevBasis{P} | ||
polynomials::Vector{P} | ||
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)]) | ||
Orthogonal polynomial with respect to the univariate weight function ``w(x) = \\sqrt{1 - x^2}`` over the interval ``[-1, 1]``. | ||
""" | ||
struct ChebyshevBasisSecondKind{P} <: AbstractChebyshevBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
|
||
degree_one_univariate_polynomial(::Type{<:ChebyshevBasisSecondKind}, variable::MP.AbstractVariable) = MA.@rewrite(2variable + 0) |
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,36 @@ | ||
abstract type AbstractHermiteBasis{P} <: AbstractMultipleOrthogonalBasis{P} end | ||
|
||
polynomial_type(::Type{<:AbstractHermiteBasis}, V::Type) = MP.polynomialtype(V, Int) | ||
|
||
even_odd_separated(::Type{<:AbstractHermiteBasis}) = true | ||
|
||
reccurence_second_coef(::Type{<:AbstractHermiteBasis}, degree) = 0 | ||
reccurence_deno_coef(::Type{<:AbstractHermiteBasis}, degree) = 1 | ||
|
||
""" | ||
struct ProbabilistsHermiteBasis{P} <: AbstractHermiteBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
Orthogonal polynomial with respect to the univariate weight function ``w(x) = \\exp(-x^2/2)`` over the interval ``[-\\infty, \\infty]``. | ||
""" | ||
struct ProbabilistsHermiteBasis{P} <: AbstractHermiteBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
reccurence_first_coef(::Type{<:ProbabilistsHermiteBasis}, degree) = 1 | ||
reccurence_third_coef(::Type{<:ProbabilistsHermiteBasis}, degree) = -(degree - 1) | ||
degree_one_univariate_polynomial(::Type{<:ProbabilistsHermiteBasis}, variable::MP.AbstractVariable) = MA.@rewrite(1variable) | ||
|
||
""" | ||
struct PhysicistsHermiteBasis{P} <: AbstractHermiteBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
Orthogonal polynomial with respect to the univariate weight function ``w(x) = \\exp(-x^2)`` over the interval ``[-\\infty, \\infty]``. | ||
""" | ||
struct PhysicistsHermiteBasis{P} <: AbstractHermiteBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
reccurence_first_coef(::Type{<:PhysicistsHermiteBasis}, degree) = 2 | ||
reccurence_third_coef(::Type{<:PhysicistsHermiteBasis}, degree) = -2(degree - 1) | ||
degree_one_univariate_polynomial(::Type{<:PhysicistsHermiteBasis}, variable::MP.AbstractVariable) = MA.@rewrite(2variable) |
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,21 @@ | ||
""" | ||
struct LaguerreBasis{P} <: AbstractMultipleOrthogonalBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
Orthogonal polynomial with respect to the univariate weight function ``w(x) = \\exp(-x)`` over the interval ``[0, \\infty]``. | ||
""" | ||
struct LaguerreBasis{P} <: AbstractMultipleOrthogonalBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
|
||
polynomial_type(::Type{<:LaguerreBasis}, V::Type) = MP.polynomialtype(V, Float64) | ||
|
||
even_odd_separated(::Type{<:LaguerreBasis}) = false | ||
|
||
reccurence_first_coef(::Type{<:LaguerreBasis}, degree) = -1 | ||
reccurence_second_coef(::Type{<:LaguerreBasis}, degree) = (2degree - 1) | ||
reccurence_third_coef(::Type{<:LaguerreBasis}, degree) = -(degree - 1) | ||
reccurence_deno_coef(::Type{<:LaguerreBasis}, degree) = degree | ||
|
||
degree_one_univariate_polynomial(::Type{<:LaguerreBasis}, variable::MP.AbstractVariable) = MA.@rewrite(1 - variable) |
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,30 @@ | ||
""" | ||
struct AbstractGegenbauerBasis{P} <: AbstractMultipleOrthogonalBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
Orthogonal polynomial with respect to the univariate weight function ``w(x) = (1 - x^2)^{\\alpha - 1/2}`` over the interval ``[-1, 1]``. | ||
""" | ||
abstract type AbstractGegenbauerBasis{P} <: AbstractMultipleOrthogonalBasis{P} end | ||
|
||
even_odd_separated(::Type{<:AbstractGegenbauerBasis}) = true | ||
reccurence_second_coef(::Type{<:AbstractGegenbauerBasis}, degree) = 0 | ||
|
||
""" | ||
struct LegendreBasis{P} <: AbstractGegenbauerBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
Orthogonal polynomial with respect to the univariate weight function ``w(x) = 1`` over the interval ``[-1, 1]``. | ||
""" | ||
struct LegendreBasis{P} <: AbstractGegenbauerBasis{P} | ||
polynomials::Vector{P} | ||
end | ||
|
||
polynomial_type(::Type{<:LegendreBasis}, V::Type) = MP.polynomialtype(V, Float64) | ||
|
||
reccurence_first_coef(::Type{<:LegendreBasis}, degree) = (2degree - 1) | ||
reccurence_third_coef(::Type{<:LegendreBasis}, degree) = -(degree - 1) | ||
reccurence_deno_coef(::Type{<:LegendreBasis}, degree) = degree | ||
|
||
degree_one_univariate_polynomial(::Type{<:LegendreBasis}, variable::MP.AbstractVariable) = MA.@rewrite(variable + 0) |
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
Oops, something went wrong.