@@ -14,19 +14,37 @@ function ngcd(p::P, q::Q, args...;kwargs...) where {T, S, P<:StandardBasisPolyno
1414
1515 p′,q′ = promote (p,q)
1616 u,v,w,Θ,κ = NGCD. ngcd (coeffs (p′), coeffs (q′), args... ; kwargs... )
17+
1718 PP = ⟒ (typeof (p′))
1819 (u= PP (u, p. var), v= PP (v, p. var), w = PP (w, p. var), Θ= Θ, κ= κ)
20+
1921end
2022
2123"""
2224 ngcd′(p,q)
2325
2426When degree(p) ≫ degree(q), this uses a early call to `divrem`.
2527"""
26- function ngcd′ (p:: P , q:: P ; kwargs... ) where {P <: StandardBasisPolynomial }
28+ function ngcd′ (p:: P , q:: P ;
29+ atol = eps (real (float (T))),
30+ # rtol=eps(real(float(T))),
31+ rtol = Base. rtoldefault (real (float (T))), # relax this
32+ satol= atol,
33+ srtol= rtol,
34+ kwargs...
35+ ) where {T, P <: StandardBasisPolynomial{T} }
36+
37+
2738 a, b = divrem (p,q)
28- u,v,w,Θ, κ = ngcd (q, b; kwargs... )
29- ngcd (p, q, degree (u))
39+
40+ # check if a=u (p,q) ≈ (aq,q)
41+ if isapprox (p, a* q, atol= atol, rtol= rtol)
42+ return a
43+ else
44+ u,v,w,Θ, κ = ngcd (q, b; atol= 100 atol, rtol= 100 rtol, kwargs... )
45+ u
46+ # ngcd(p, q, degree(u))
47+ end
3048end
3149
3250
@@ -111,10 +129,10 @@ Note: Based on work by Andreas Varga
111129function ngcd (ps:: Vector{T} ,
112130 qs:: Vector{T} ;
113131 scale:: Bool = true ,
114- atol= ( length (ps) + length (qs)) * eps (real (T)),
115- rtol= eps ( real (T)), # Base.rtoldefault (real(T)),
116- satol= atol,
117- srtol= eps ( real (T)) ,
132+ atol = eps (real (T)),
133+ rtol = eps (real (T)),
134+ satol = atol,
135+ srtol = rtol ,
118136 verbose= false
119137 ) where {T <: AbstractFloat }
120138
0 commit comments