Skip to content

Commit

Permalink
use conversion for P(n)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Jul 1, 2020
1 parent ee2e948 commit ea1efb3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "Polynomials"
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
license = "MIT"
author = "JuliaMath"
version = "1.1.1"
version = "1.1.2"

[deps]
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
Expand Down
4 changes: 2 additions & 2 deletions src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ macro register(name)
$poly{T}(x::AbstractVector{S}, var::SymbolLike = :x) where {T,S<:Number} =
$poly(T.(x), Symbol(var))
$poly{T}(n::S, var::SymbolLike = :x) where {T, S<:Number} =
$poly(T[n], Symbol(var))
$poly(n::Number, var::SymbolLike = :x) = $poly([n], Symbol(var))
n * one($poly{T}, Symbol(var))
$poly(n::S, var::SymbolLike = :x) where {S <: Number} = n * one($poly{S}, Symbol(var))
$poly{T}(var::SymbolLike=:x) where {T} = variable($poly{T}, Symbol(var))
$poly(var::SymbolLike=:x) = variable($poly, Symbol(var))
end
Expand Down
2 changes: 1 addition & 1 deletion src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Base.zero(p::P) where {P <: AbstractPolynomial} = zero(P, p.var)
Returns a representation of 1 as the given polynomial.
"""
Base.one(::Type{P}, var=:x) where {P <: AbstractPolynomial} = (P)(ones(eltype(P),1), var)
Base.one(::Type{P}, var=:x) where {P <: AbstractPolynomial} = (P)(ones(eltype(P),1), var) # assumes p₀ = 1
Base.one(p::P) where {P <: AbstractPolynomial} = one(P, p.var)

Base.oneunit(::Type{P}, args...) where {P <: AbstractPolynomial} = one(P, args...)
Expand Down
8 changes: 4 additions & 4 deletions src/polynomials/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Polynomials.@register Poly
Base.convert(P::Type{<:Polynomial}, p::Poly{T}) where {T} = P(p.coeffs, p.var)

Base.eltype(P::Type{<:Poly}) = P
Base.zero(::Type{<:Poly{T}},var=:x) where {T} = Poly{T}(zeros(T,0), var)
Base.zero(::Type{<:Poly},var=:x) where {T} = Poly(zeros(Float64,0), var)
Base.one(::Type{<:Poly{T}},var=:x) where {T} = Poly{T}(ones(T,1), var)
Base.one(::Type{<:Poly},var=:x) where {T} = Poly(ones(Float64,1), var)
_eltype(::Type{<:Poly{T}}) where {T} = T
_eltype(::Type{Poly}) = Float64
Base.zero(P::Type{<:Poly},var=:x) = Poly(zeros(_eltype(P),0), var)
Base.one(P::Type{<:Poly},var=:x) = Poly(ones(_eltype(P),1), var)
function Polynomials.basis(P::Type{<:Poly}, k::Int, _var::Polynomials.SymbolLike=:x; var=_var)
zs = zeros(Int, k+1)
zs[end] = 1
Expand Down
4 changes: 4 additions & 0 deletions test/StandardBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ end
@test iszero(p0)
P != LaurentPolynomial && @test degree(p0) == -1

# P(2) is 2 (not 2p₀) connvert(Polynomial, P(s::Number)) = Polynomial(s)
@test convert(Polynomial, P(2)) Polynomial(2)
@test P(2) 2*one(P)

# variable(), P() to generate `x` in given basis
@test degree(variable(P)) == 1
@test variable(P)(1) == 1
Expand Down

0 comments on commit ea1efb3

Please sign in to comment.