Skip to content

Commit 67ae0a6

Browse files
authored
Lagrange basis (#47)
* Lagrange basis * up * up * Fixes * Fix format * Add tests * Fix format * Add Random * Fix doc * Fixes * Fix
1 parent 36c3156 commit 67ae0a6

File tree

17 files changed

+322
-394
lines changed

17 files changed

+322
-394
lines changed

docs/src/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ end
1111
based on the [MultivariatePolynomials](https://github.com/JuliaAlgebra/MultivariatePolynomials.jl) API.
1212

1313
```@docs
14-
AbstractPolynomialBasis
1514
maxdegree_basis
1615
explicit_basis_covering
1716
```

src/MultivariateBases.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MutableArithmetics as MA
44
import StarAlgebras as SA
55
import MultivariatePolynomials as MP
66

7-
export AbstractPolynomialBasis, FullBasis, SubBasis
7+
export FullBasis, SubBasis
88
export maxdegree_basis, explicit_basis_covering, empty_basis, monomial_index
99
include("interface.jl")
1010

@@ -55,15 +55,14 @@ export algebra_element,
5555
reccurence_second_coef,
5656
reccurence_third_coef,
5757
reccurence_deno_coef
58-
#include("fixed.jl")
5958

6059
import LinearAlgebra
61-
#include("orthonormal.jl")
6260
include("orthogonal.jl")
6361
include("hermite.jl")
6462
include("laguerre.jl")
6563
include("legendre.jl")
6664
include("chebyshev.jl")
65+
include("lagrange.jl")
6766
include("quotient.jl")
6867

6968
function algebra(

src/chebyshev.jl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ function SA.coeffs!(
8989
return res
9090
end
9191

92+
function transformation_to(
93+
source::SubBasis{Chebyshev},
94+
target::SubBasis{Monomial},
95+
)
96+
A = zeros(Float64, length(target), length(source))
97+
for (i, cheby) in enumerate(source)
98+
A[:, i] = SA.coeffs(algebra_element(cheby), target)
99+
end
100+
return LinearAlgebra.UpperTriangular(A)
101+
end
102+
92103
function SA.coeffs(
93104
cfs,
94105
source::SubBasis{Monomial},
@@ -97,17 +108,13 @@ function SA.coeffs(
97108
sub = explicit_basis_covering(target, source)
98109
# Need to make A square so that it's UpperTriangular
99110
extended = SubBasis{Monomial}(sub.monomials)
100-
A = zeros(Float64, length(extended), length(sub))
101-
for (i, cheby) in enumerate(sub)
102-
A[:, i] = SA.coeffs(algebra_element(cheby), extended)
103-
end
104111
ext = SA.coeffs(algebra_element(cfs, source), extended)
105112
return SA.SparseCoefficients(
106113
sub.monomials,
107-
#LinearAlgebra.UpperTriangular(A) \ ext, # Julia v1.6 converts `A` to the eltype of the `result` which is bad for JuMP
114+
#transformation_to(sub, extended) \ ext, # Julia v1.6 converts the matrix to the eltype of the `result` which is bad for JuMP
108115
LinearAlgebra.ldiv!(
109-
zeros(_promote_coef(eltype(ext), Chebyshev), size(A, 2)),
110-
LinearAlgebra.UpperTriangular(A),
116+
zeros(_promote_coef(eltype(ext), Chebyshev), length(sub)),
117+
transformation_to(sub, extended),
111118
ext,
112119
),
113120
)
@@ -121,10 +128,7 @@ function SA.coeffs(cfs, ::FullBasis{Monomial}, target::FullBasis{Chebyshev})
121128
)
122129
end
123130

124-
function degree_one_univariate_polynomial(
125-
::Type{Chebyshev},
126-
variable::MP.AbstractVariable,
127-
)
131+
function degree_one_univariate_polynomial(::Type{Chebyshev}, variable)
128132
MA.@rewrite(variable + 0)
129133
end
130134

@@ -146,10 +150,7 @@ Orthogonal polynomial with respect to the univariate weight function ``w(x) = \\
146150
"""
147151
struct ChebyshevSecondKind <: AbstractChebyshev end
148152

149-
function degree_one_univariate_polynomial(
150-
::Type{ChebyshevSecondKind},
151-
variable::MP.AbstractVariable,
152-
)
153+
function degree_one_univariate_polynomial(::Type{ChebyshevSecondKind}, variable)
153154
MA.@rewrite(2variable + 0)
154155
end
155156

src/fixed.jl

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/hermite.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ reccurence_first_coef(::Type{ProbabilistsHermite}, degree) = 1
1919
function reccurence_third_coef(::Type{ProbabilistsHermite}, degree)
2020
return -(degree - 1)
2121
end
22-
function degree_one_univariate_polynomial(
23-
::Type{ProbabilistsHermite},
24-
variable::MP.AbstractVariable,
25-
)
22+
function degree_one_univariate_polynomial(::Type{ProbabilistsHermite}, variable)
2623
MA.@rewrite(1variable)
2724
end
2825

@@ -47,10 +44,7 @@ Orthogonal polynomial with respect to the univariate weight function ``w(x) = \\
4744
struct PhysicistsHermite <: AbstractHermite end
4845
reccurence_first_coef(::Type{PhysicistsHermite}, degree) = 2
4946
reccurence_third_coef(::Type{PhysicistsHermite}, degree) = -2(degree - 1)
50-
function degree_one_univariate_polynomial(
51-
::Type{PhysicistsHermite},
52-
variable::MP.AbstractVariable,
53-
)
47+
function degree_one_univariate_polynomial(::Type{PhysicistsHermite}, variable)
5448
MA.@rewrite(2variable)
5549
end
5650

src/interface.jl

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
"""
2-
abstract type AbstractPolynomialBasis end
3-
4-
Polynomial basis of a subspace of the polynomials [Section~3.1.5, BPT12].
5-
6-
[BPT12] Blekherman, G.; Parrilo, P. A. & Thomas, R. R.
7-
*Semidefinite Optimization and Convex Algebraic Geometry*.
8-
Society for Industrial and Applied Mathematics, **2012**.
9-
"""
10-
abstract type AbstractPolynomialBasis end
11-
12-
# TODO breaking Should be underscore and only for internal use
13-
generators(basis::AbstractPolynomialBasis) = basis.polynomials
14-
15-
function Base.getindex(
16-
basis::AbstractPolynomialBasis,
17-
I::AbstractVector{<:Integer},
18-
)
19-
return typeof(basis)(generators(basis)[I])
20-
end
21-
221
"""
232
maxdegree_basis(basis::StarAlgebras.AbstractBasis, variables, maxdegree::Int)
243

@@ -27,7 +6,6 @@ Return the explicit version of `basis`generating all polynomials of degree up to
276
"""
287
function maxdegree_basis end
298

30-
# TODO remove, not needed anymore
319
"""
3210
explicit_basis_covering(basis::StarAlgebras.AbstractBasis, target::StarAlgebras.ExplicitBasis)
3311

0 commit comments

Comments
 (0)