@@ -200,30 +200,30 @@ variable(p::Poly{T}) where {T} = variable(T, p.var)
200
200
variable (var:: SymbolLike = :x ) = variable (Float64, var)
201
201
202
202
"""
203
- truncate{T}(p::Poly{T}; reltol ::Real = Base.rtoldefault(real(T)), abstol ::Real = 0)
203
+ truncate{T}(p::Poly{T}; rtol ::Real = Base.rtoldefault(real(T)), atol ::Real = 0)
204
204
205
- Return a polynomial with coefficients `a_i` truncated to zero if `|a_i| <= reltol *maxabs(a)+abstol `.
205
+ Return a polynomial with coefficients `a_i` truncated to zero if `|a_i| <= rtol *maxabs(a)+atol `.
206
206
"""
207
- function truncate (p:: Poly{T} ; reltol :: Real = Base. rtoldefault (real (T)),
208
- abstol :: Real = 0 ) where {T}
207
+ function truncate (p:: Poly{T} ; rtol :: Real = Base. rtoldefault (real (T)),
208
+ atol :: Real = 0 ) where {T}
209
209
a = coeffs (p)
210
210
amax = maximum (abs,a)
211
- thresh = amax * reltol + abstol
211
+ thresh = amax * rtol + atol
212
212
anew = map (ai -> abs (ai) <= thresh ? zero (T) : ai, a)
213
213
return Poly (anew, p. var)
214
214
end
215
215
216
216
"""
217
- chop(p::Poly{T}; reltol ::Real = Base.rtoldefault(real(T)), abstol ::Real = 0)
217
+ chop(p::Poly{T}; rtol ::Real = Base.rtoldefault(real(T)), atol ::Real = 0)
218
218
219
219
Chop off leading values from a polynomial which are approximately zero. The tolerances
220
- `reltol ` and `abstol ` are passed to `isapprox` to check for zeros.
220
+ `rtol ` and `atol ` are passed to `isapprox` to check for zeros.
221
221
"""
222
- function chop (p:: Poly{T} ; reltol :: Real = Base. rtoldefault (real (T)),
223
- abstol :: Real = 0 ) where {T}
222
+ function chop (p:: Poly{T} ; rtol :: Real = Base. rtoldefault (real (T)),
223
+ atol :: Real = 0 ) where {T}
224
224
c = copy (p. a)
225
225
for k= length (c): - 1 : 1
226
- if ! isapprox (c[k], zero (T); rtol= reltol , atol= abstol )
226
+ if ! isapprox (c[k], zero (T); rtol= rtol , atol= atol )
227
227
resize! (c, k)
228
228
return Poly (c, p. var)
229
229
end
@@ -396,29 +396,29 @@ rem(num::Poly, den::Poly) = divrem(num, den)[2]
396
396
== (n:: Number , p1:: Poly ) = (p1 == n)
397
397
398
398
"""
399
- isapprox{T,S}(p1::Poly{T}, p2::Poly{S}; reltol ::Real = Base.rtoldefault(T,S, 0), abstol ::Real = 0, norm::Function = vecnorm)
399
+ isapprox{T,S}(p1::Poly{T}, p2::Poly{S}; rtol ::Real = Base.rtoldefault(T,S, 0), atol ::Real = 0, norm::Function = vecnorm)
400
400
401
401
Truncate polynomials `p1` and `p2`, and compare the coefficient vectors using the
402
- given `norm` function. The tolerances `reltol ` and `abstol ` are passed to both
402
+ given `norm` function. The tolerances `rtol ` and `atol ` are passed to both
403
403
`truncate` and `isapprox`.
404
404
"""
405
405
function isapprox (p1:: Poly{T} , p2:: Poly{S} ;
406
- reltol :: Real = (@compat Base. rtoldefault (T,S, 0 )), abstol :: Real = 0 , norm:: Function = vecnorm) where {T,S}
406
+ rtol :: Real = (@compat Base. rtoldefault (T,S, 0 )), atol :: Real = 0 , norm:: Function = vecnorm) where {T,S}
407
407
p1. var == p2. var || error (" Polynomials must have same variable" )
408
- p1t = truncate (p1; reltol = reltol, abstol = abstol )
409
- p2t = truncate (p2; reltol = reltol, abstol = abstol )
410
- length (p1t) == length (p2t) && isapprox (coeffs (p1t), coeffs (p2t); rtol = reltol ,
411
- atol = abstol , norm = norm)
408
+ p1t = truncate (p1; rtol = rtol, atol = atol )
409
+ p2t = truncate (p2; rtol = rtol, atol = atol )
410
+ length (p1t) == length (p2t) && isapprox (coeffs (p1t), coeffs (p2t); rtol = rtol ,
411
+ atol = atol , norm = norm)
412
412
end
413
413
414
- function isapprox (p1:: Poly{T} , n:: S ; reltol :: Real = (@compat Base. rtoldefault (T,S, 0 )),
415
- abstol :: Real = 0 ) where {T,S<: Number }
416
- p1t = truncate (p1; reltol = reltol, abstol = abstol )
417
- degree (p1t) == 0 && isapprox (coeffs (p1), [n]; rtol = reltol , atol = abstol )
414
+ function isapprox (p1:: Poly{T} , n:: S ; rtol :: Real = (@compat Base. rtoldefault (T,S, 0 )),
415
+ atol :: Real = 0 ) where {T,S<: Number }
416
+ p1t = truncate (p1; rtol = rtol, atol = atol )
417
+ degree (p1t) == 0 && isapprox (coeffs (p1), [n]; rtol = rtol , atol = atol )
418
418
end
419
419
420
- isapprox (n:: S , p1:: Poly{T} ; reltol :: Real = (@compat Base. rtoldefault (T,S, 0 )),
421
- abstol :: Real = 0 ) where {T,S<: Number } = isapprox (p1, n; reltol = reltol, abstol = abstol )
420
+ isapprox (n:: S , p1:: Poly{T} ; rtol :: Real = (@compat Base. rtoldefault (T,S, 0 )),
421
+ atol :: Real = 0 ) where {T,S<: Number } = isapprox (p1, n; rtol = rtol, atol = atol )
422
422
423
423
hash (f:: Poly , h:: UInt ) = hash (f. var, hash (f. a, h))
424
424
isequal (p1:: Poly , p2:: Poly ) = hash (p1) == hash (p2)
0 commit comments