@@ -397,7 +397,7 @@ _polynomial(ts, state, ::MA.IsNotMutable) = polynomial(ts, state)
397
397
_polynomial (ts, state, :: MA.IsMutable ) = polynomial! (ts, state)
398
398
399
399
"""
400
- primitive_univariate_gcd!(p::APL, q::APL, algo::AbstractUnivariateGCDAlgorithm)
400
+ primitive_univariate_gcd!(p::APL, q::APL, algo::AbstractUnivariateGCDAlgorithm, buffer=nothing )
401
401
402
402
Returns the `gcd` of primitive polynomials `p` and `q` using algorithm `algo`
403
403
which is a subtype of [`AbstractUnivariateGCDAlgorithm`](@ref).
@@ -419,11 +419,19 @@ end
419
419
420
420
# If `p` and `q` do not have the same type then the local variables `p` and `q`
421
421
# won't be type stable so we create `u` and `v`.
422
- function primitive_univariate_gcd! (p:: APL , q:: APL , algo:: GeneralizedEuclideanAlgorithm )
422
+ function primitive_univariate_gcd! (
423
+ p:: APL ,
424
+ q:: APL ,
425
+ algo:: GeneralizedEuclideanAlgorithm ,
426
+ buffer= nothing ,
427
+ )
423
428
if maxdegree (p) < maxdegree (q)
424
- return primitive_univariate_gcd! (q, p, algo)
429
+ return primitive_univariate_gcd! (q, p, algo, buffer )
425
430
end
426
431
R = MA. promote_operation (gcd, typeof (p), typeof (q))
432
+ if isnothing (buffer)
433
+ buffer = MA. buffer_for (rem_or_pseudo_rem, R, R, typeof (algo))
434
+ end
427
435
u = convert (R, p)
428
436
v = convert (R, q)
429
437
while true
@@ -436,7 +444,7 @@ function primitive_univariate_gcd!(p::APL, q::APL, algo::GeneralizedEuclideanAlg
436
444
end
437
445
438
446
d_before = degree (leadingmonomial (u))
439
- r = MA. operate !! (rem_or_pseudo_rem, u, v, algo)
447
+ r = MA. buffered_operate !! (buffer, rem_or_pseudo_rem, u, v, algo)
440
448
d_after = degree (leadingmonomial (r))
441
449
if d_after == d_before
442
450
not_divided_error (u, v)
@@ -485,7 +493,7 @@ function primitive_univariate_gcdx(u0::APL, v0::APL, algo::GeneralizedEuclideanA
485
493
end
486
494
487
495
488
- function primitive_univariate_gcd! (p:: APL , q:: APL , :: SubresultantAlgorithm )
496
+ function primitive_univariate_gcd! (p:: APL , q:: APL , :: SubresultantAlgorithm , buffer = nothing )
489
497
error (" Not implemented yet" )
490
498
end
491
499
@@ -512,13 +520,28 @@ If the coefficients are not `AbstractFloat`, this
512
520
*Art of computer programming, volume 2: Seminumerical algorithms.*
513
521
Addison-Wesley Professional. Third edition.
514
522
"""
515
- function univariate_gcd (p1:: APL{S} , p2:: APL{T} , algo:: AbstractUnivariateGCDAlgorithm , m1:: MA.MutableTrait , m2:: MA.MutableTrait ) where {S,T}
516
- return univariate_gcd (_field_absorb (algebraic_structure (S), algebraic_structure (T)), p1, p2, algo, m1, m2)
517
- end
518
- function univariate_gcd (:: UFD , p1:: APL , p2:: APL , algo:: AbstractUnivariateGCDAlgorithm , m1:: MA.MutableTrait , m2:: MA.MutableTrait )
523
+ function univariate_gcd (
524
+ p1:: APL{S} ,
525
+ p2:: APL{T} ,
526
+ algo:: AbstractUnivariateGCDAlgorithm ,
527
+ m1:: MA.MutableTrait ,
528
+ m2:: MA.MutableTrait ,
529
+ buffer= nothing
530
+ ) where {S,T}
531
+ return univariate_gcd (_field_absorb (algebraic_structure (S), algebraic_structure (T)), p1, p2, algo, m1, m2, buffer)
532
+ end
533
+ function univariate_gcd (
534
+ :: UFD ,
535
+ p1:: APL ,
536
+ p2:: APL ,
537
+ algo:: AbstractUnivariateGCDAlgorithm ,
538
+ m1:: MA.MutableTrait ,
539
+ m2:: MA.MutableTrait ,
540
+ buffer= nothing ,
541
+ )
519
542
f1, g1 = primitive_part_content (p1, algo, m1)
520
543
f2, g2 = primitive_part_content (p2, algo, m2)
521
- pp = primitive_univariate_gcd! (f1, f2, algo)
544
+ pp = primitive_univariate_gcd! (f1, f2, algo, buffer )
522
545
gg = _gcd (g1, g2, algo, MA. IsMutable (), MA. IsMutable ())# ::MA.promote_operation(gcd, typeof(g1), typeof(g2))
523
546
# Multiply each coefficient by the gcd of the contents.
524
547
if ! isone (gg)
@@ -527,8 +550,8 @@ function univariate_gcd(::UFD, p1::APL, p2::APL, algo::AbstractUnivariateGCDAlgo
527
550
return pp
528
551
end
529
552
530
- function univariate_gcd (:: Field , p1:: APL , p2:: APL , algo:: AbstractUnivariateGCDAlgorithm , m1:: MA.MutableTrait , m2:: MA.MutableTrait )
531
- return primitive_univariate_gcd! (_copy (p1, m1), _copy (p2, m2), algo)
553
+ function univariate_gcd (:: Field , p1:: APL , p2:: APL , algo:: AbstractUnivariateGCDAlgorithm , m1:: MA.MutableTrait , m2:: MA.MutableTrait , buffer = nothing )
554
+ return primitive_univariate_gcd! (_copy (p1, m1), _copy (p2, m2), algo, buffer )
532
555
end
533
556
534
557
function univariate_gcdx (p1:: APL{S} , p2:: APL{T} , algo:: AbstractUnivariateGCDAlgorithm ) where {S,T}
0 commit comments