@@ -14,19 +14,37 @@ function ngcd(p::P, q::Q, args...;kwargs...) where {T, S, P<:StandardBasisPolyno
14
14
15
15
p′,q′ = promote (p,q)
16
16
u,v,w,Θ,κ = NGCD. ngcd (coeffs (p′), coeffs (q′), args... ; kwargs... )
17
+
17
18
PP = ⟒ (typeof (p′))
18
19
(u= PP (u, p. var), v= PP (v, p. var), w = PP (w, p. var), Θ= Θ, κ= κ)
20
+
19
21
end
20
22
21
23
"""
22
24
ngcd′(p,q)
23
25
24
26
When degree(p) ≫ degree(q), this uses a early call to `divrem`.
25
27
"""
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
+
27
38
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
30
48
end
31
49
32
50
@@ -111,10 +129,10 @@ Note: Based on work by Andreas Varga
111
129
function ngcd (ps:: Vector{T} ,
112
130
qs:: Vector{T} ;
113
131
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 ,
118
136
verbose= false
119
137
) where {T <: AbstractFloat }
120
138
0 commit comments