Skip to content

Commit f1f4841

Browse files
committed
backport bug fix, others
1 parent 2e7cbb4 commit f1f4841

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Polynomials"
22
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
33
license = "MIT"
44
author = "JuliaMath"
5-
version = "1.2.0"
5+
version = "1.2.1"
66

77
[deps]
88
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"

src/common.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,13 @@ end
273273
Check if either `p` or `q` is constant or if `p` and `q` share the same variable
274274
"""
275275
check_same_variable(p::AbstractPolynomial, q::AbstractPolynomial) =
276-
(Polynomials.isconstant(p) || Polynomials.isconstant(q)) || p.var == q.var
276+
(isconstant(p) || isconstant(q)) || p.var == q.var
277+
function assert_same_variable(p::AbstractPolynomial, q::AbstractPolynomial)
278+
check_same_variable(p,q) || throw(ArgumentError("Polynomials have different indeterminates"))
279+
end
280+
function assert_same_variable(X::Symbol, Y::Symbol)
281+
X == Y || throw(ArgumentError("Polynomials have different indeterminates"))
282+
end
277283

278284
#=
279285
Linear Algebra =#
@@ -412,6 +418,11 @@ Is the polynomial `p` a constant.
412418
"""
413419
isconstant(p::AbstractPolynomial) = degree(p) <= 0
414420

421+
"""
422+
constantterm(p::AbstractPolynomial)
423+
return `p(0)`, the constant term in the standard basis
424+
"""
425+
constantterm(p::AbstractPolynomial{T}) where {T} = p(zero(T))
415426

416427

417428

@@ -510,6 +521,13 @@ Base.hash(p::AbstractPolynomial, h::UInt) = hash(p.var, hash(coeffs(p), h))
510521

511522
#=
512523
zero, one, variable, basis =#
524+
"""
525+
indeterminate(p::AbstractPolynomial)
526+
527+
Return polynomial indeterminate (symbol)
528+
"""
529+
indeterminate(p::AbstractPolynomial) = p.var
530+
513531
"""
514532
zero(::Type{<:AbstractPolynomial})
515533
zero(::AbstractPolynomial)

src/polynomials/ngcd.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In the case `degree(p) ≫ degree(q)`, a heuristic is employed to first call on
1010
function ngcd(p::P, q::Q, args...;kwargs...) where {T, S, P<:StandardBasisPolynomial{T}, Q <: StandardBasisPolynomial{S}}
1111

1212
degree(p) < 0 && return (u=q, v=p, w=one(q), θ=NaN, κ=NaN)
13-
degree(p) == 0 && return (u=one(q), v=p, w=zero(q), θ=NaN, κ=NaN)
13+
degree(p) == 0 && return (u=one(q), v=p, w=q, θ=NaN, κ=NaN)
1414
degree(q) < 0 && return (u=one(q), v=p, w=zero(q), θ=NaN, κ=NaN)
1515
degree(q) == 0 && return (u=one(p), v=p, w=q, θ=NaN, κ=NaN)
1616
check_same_variable(p,q) || throw(ArgumentError("Mis-matched variables"))
@@ -264,8 +264,8 @@ end
264264
# return guess at smallest singular value and right sinuglar value, x
265265
# for an upper triangular matrix, V
266266
function smallest_singular_value(V::AbstractArray{T,2},
267-
atol=eps(T),
268-
rtol=zero(T)) where {T}
267+
atol=eps(real(T)),
268+
rtol=zero(real(T))) where {T}
269269

270270
R = UpperTriangular(V)
271271
k = size(R)[1]/2

src/polynomials/standard-basis.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mapdomain(::Type{<:StandardBasisPolynomial}, x::AbstractArray) = x
2525

2626
## generic test if polynomial `p` is a constant
2727
isconstant(p::StandardBasisPolynomial) = degree(p) <= 0
28+
constantterm(p::StandardBasisPolynomial) = p[0]
2829

2930
Base.convert(P::Type{<:StandardBasisPolynomial}, q::StandardBasisPolynomial) = isa(q, P) ? q : P([q[i] for i in 0:degree(q)], q.var)
3031

0 commit comments

Comments
 (0)