@@ -253,6 +253,14 @@ variable(::Type{P}, var::SymbolLike = :x) where {P <: AbstractPolynomial} = P([0
253
253
variable (p:: AbstractPolynomial , var:: SymbolLike = p. var) = variable (typeof (p), var)
254
254
variable (var:: SymbolLike = :x ) = variable (Polynomial{Int})
255
255
256
+ """
257
+ check_same_variable(p::AbstractPolynomial, q::AbstractPolynomial)
258
+
259
+ Check if either `p` or `q` is constant or if `p` and `q` share the same variable
260
+ """
261
+ check_same_variable (p:: AbstractPolynomial , q:: AbstractPolynomial ) =
262
+ (Polynomials. isconstant (p) || Polynomials. isconstant (q)) || p. var == q. var
263
+
256
264
#=
257
265
Linear Algebra =#
258
266
"""
@@ -318,6 +326,17 @@ has a nonzero coefficient. The degree of the zero polynomial is defined to be -1
318
326
"""
319
327
degree (p:: AbstractPolynomial ) = iszero (p) ? - 1 : length (p) - 1
320
328
329
+
330
+ """
331
+ isconstant(::AbstractPolynomial)
332
+
333
+ Is the polynomial `p` a constant.
334
+ """
335
+ isconstant (p:: AbstractPolynomial ) = degree (p) <= 0
336
+
337
+
338
+
339
+
321
340
hasnan (p:: AbstractPolynomial ) = any (isnan .(coeffs (p)))
322
341
323
342
"""
@@ -535,9 +554,7 @@ function Base.isapprox(p1::AbstractPolynomial{T},
535
554
rtol:: Real = (Base. rtoldefault (T, S, 0 )),
536
555
atol:: Real = 0 ,) where {T,S}
537
556
p1, p2 = promote (p1, p2)
538
- if p1. var != p2. var
539
- error (" p1 and p2 must have same var" )
540
- end
557
+ check_same_variable (p1, p2) || error (" p1 and p2 must have same var" )
541
558
p1t = truncate (p1; rtol = rtol, atol = atol)
542
559
p2t = truncate (p2; rtol = rtol, atol = atol)
543
560
if length (p1t) ≠ length (p2t)
0 commit comments