Skip to content

Commit 919e804

Browse files
committed
removed unused code from intfactorization
1 parent 15de0f6 commit 919e804

5 files changed

Lines changed: 57 additions & 286 deletions

File tree

src/CommutativeRings.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export GaloisField
1212

1313
export Hom, Ideal
1414

15-
export isunit, deg, content, primpart, isnegative, isproper
15+
export isunit, deg, content, primpart, content_primpart, isnegative, isproper
1616
export LC, LM, LT, lcunit, multideg, modulus, value
1717
export isdiv, pdivrem, divremv, pgcd, pgcdx, resultant, discriminant
1818
export basetype, basetypes, depth, iszerodiv

src/intfactorization.jl

Lines changed: 0 additions & 273 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
11

2-
function factor_must_try_all_factors_of_e(p::P) where P<:UnivariatePolynomial{<:ZZ}
3-
q, e = tominexp(p)
4-
res = factor_minexp(q)
5-
if e == 1
6-
res
7-
else
8-
x = monom(P)
9-
[first(res[i])(x^e) => last(res[i]) for i = 1:length(res)]
10-
end
11-
end
12-
13-
"""
14-
content_primpart(p::UnivariatePolynomial{<:QQ})
15-
16-
Convert a polynomial over `QQ` to a (rational) content and a polynomial over `ZZ`
17-
"""
18-
function content_primpart(p::P) where {T,X,P<:UnivariatePolynomial{QQ{T},X}}
19-
c = content(p)
20-
Z = ZZ{T}
21-
pp = Z[X](Z.(numerator.((p / c).coeff)), p.first)
22-
c, pp
23-
end
24-
252
function isirreducible(p::P; p0 = 3) where P<:UnivariatePolynomial{<:ZZ}
263
(iszero(p) || isunit(p)) && return false
274
deg(p) <= 1 && return true
@@ -118,17 +95,6 @@ function GCD(u, v)
11895
isone(t) ? (t, u, v) : (t, u / t, v / t)
11996
end
12097

121-
function zassenhaus_unused_tomonic_etc(u)
122-
un = LC(u)
123-
v = tomonic(u)
124-
vv = zassenhaus_monic(v)
125-
if isone(un)
126-
vv
127-
else
128-
primpart.(frommonic.(vv, un))
129-
end
130-
end
131-
13298
function zassenhaus(u; p0)
13399
zassenhaus2(u, Val(false); p0)
134100
end
@@ -302,23 +268,6 @@ function lift!(fac, i)
302268
fac, p
303269
end
304270

305-
"""
306-
factormod(u::Polynomial[; p0])
307-
308-
The procedure may be repeated with increased `p`.
309-
If the vector is empty, `p` was one of those rare "unlucky" primes, which are not useful for this polynomial.
310-
"""
311-
function factormod(u::P; p0 = 3) where P<:UnivariatePolynomial{<:ZZ}
312-
fl = leftfactor(u)
313-
fr = rightfactor(u)
314-
u = rightop!(leftop!(copy(u), ÷, fl), ÷, fr)
315-
res = zassenhaus(u; p0)
316-
for (u, vv) in res
317-
rightop!(leftop!(u, *, fl), *, fr)
318-
end
319-
res
320-
end
321-
322271
"""
323272
combinefactors(u, v::Vector{<:UnivariatePolynomial{ZZ/p}}, a::Vector{<:UnivariatePolynomial{ZZ/q}})
324273
@@ -516,23 +465,6 @@ function stripzeros(p::P) where P<:UnivariatePolynomial
516465
P(p.coeff, 0), p.first
517466
end
518467

519-
"""
520-
reverse(p::UnivariatePolynomial)
521-
522-
Revert the order of coefficients. decrease degree if `p(0) == 0`.
523-
"""
524-
Base.reverse(p::P) where P<:UnivariatePolynomial = reverse!(copy(p))
525-
function Base.reverse!(p::P) where P<:UnivariatePolynomial
526-
c = p.coeff
527-
n = length(c)
528-
reverse!(c)
529-
while n > 0 && iszero(c[n])
530-
n -= 1
531-
end
532-
resize!(c, n)
533-
p
534-
end
535-
536468
"""
537469
pprod(v::Vector, n::{Integer,BitVector})
538470
@@ -664,95 +596,6 @@ function divides_maybe(v::UnivariatePolynomial, u::UnivariatePolynomial)
664596
end
665597
end
666598

667-
function partsums(s::Vector{<:Integer})
668-
m = length(s)
669-
n = Base.sum(s) ÷ 2 + 1
670-
if n > 64
671-
a = falses(n)
672-
a[1] = true
673-
else
674-
a = UInt64(1)
675-
end
676-
pa = partsums!(a, s)
677-
pv = zeros(Int, n)
678-
pv[1] = 1
679-
pv = partsums!(pv, s)
680-
if m > 64
681-
ps = fill(BitVector[], n)
682-
ps[1] = [falses(m)]
683-
else
684-
ps = fill(UInt64[], n)
685-
ps[1] = [0]
686-
end
687-
ps = partsums!(ps, s)
688-
pa, pv, ps
689-
end
690-
691-
function partsums!(a::BitVector, s::Vector)
692-
for d in s
693-
map!(|, a, a, a >> d)
694-
end
695-
a
696-
end
697-
function partsums!(a::Integer, s::Vector)
698-
for d in s
699-
a |= a << d
700-
end
701-
a
702-
end
703-
704-
function partsums!(a::Vector{<:Integer}, s::Vector)
705-
n = length(a)
706-
for d in s
707-
for k = n-d:-1:1
708-
ak = a[k]
709-
if ak > 0
710-
a[k+d] += ak
711-
end
712-
end
713-
end
714-
a
715-
end
716-
717-
function partsums!(a::Vector{<:Vector{BitVector}}, s::Vector)
718-
n = length(a)
719-
for (i, d) in enumerate(s)
720-
for k = n-d:-1:1
721-
ak = a[k]
722-
if length(ak) > 0
723-
bk = map(copy, ak)
724-
for x in bk
725-
x[i] = true
726-
end
727-
if length(a[k+d]) > 0
728-
append!(a[k+d], bk)
729-
else
730-
a[k+d] = bk
731-
end
732-
end
733-
end
734-
end
735-
a
736-
end
737-
function partsums!(a::Vector{<:Vector{<:Integer}}, s::Vector)
738-
n = length(a)
739-
for (i, d) in enumerate(s)
740-
for k = n-d:-1:1
741-
ak = a[k]
742-
if length(ak) > 0
743-
bk = copy(ak)
744-
bk .|= 1 << (i - 1)
745-
if length(a[k+d]) > 0
746-
append!(a[k+d], bk)
747-
else
748-
a[k+d] = bk
749-
end
750-
end
751-
end
752-
end
753-
a
754-
end
755-
756599
"""
757600
enumx(n::Integer, bits)::Integer
758601
@@ -794,109 +637,6 @@ function enumx(n::Integer, bits::Int)
794637
a
795638
end
796639

797-
# From here experimental to simplify cases with: 1. p(x) = q(x^e) 2. p(x) = q(f*x)
798-
#=
799-
function tomonic(u::P) where P<:UnivariatePolynomial
800-
un = LC(u)
801-
isone(un) && return u
802-
c = coeff(u)
803-
n = deg(u)
804-
c[n+1] = one(un)
805-
s = un
806-
for i = n:-1:1
807-
c[i] *= s
808-
s *= un
809-
end
810-
P(c)
811-
end
812-
813-
function frommonic(u::P, un) where P<:UnivariatePolynomial
814-
isone(un) && return u
815-
c = coeff(u)
816-
n = deg(u)
817-
s = un
818-
for i = 2:n+1
819-
c[i] *= s
820-
s *= un
821-
end
822-
P(c)
823-
end
824-
825-
function common_exp(u::UnivariatePolynomial)
826-
gcd(filter(i -> !iszero(u[i]), 0:deg(u)))
827-
end
828-
829-
function tominexp(u::P) where P<:UnivariatePolynomial
830-
e = common_exp(u)
831-
e == 1 && return u, e
832-
n = deg(u) ÷ e
833-
c = [u[i*e] for i = 0:n]
834-
P(c), e
835-
end
836-
837-
# x -> k * x
838-
function leftop!(u::UnivariatePolynomial{R}, op, v) where R
839-
c = u.coeff
840-
p = R(v)^u.first
841-
for i = 1:size(c, 1)
842-
c[i] = op(c[i], p)
843-
p *= v
844-
end
845-
u
846-
end
847-
function rightop!(u::UnivariatePolynomial{R}, op, v) where R
848-
c = u.coeff
849-
p = R(v)
850-
for i = length(c)-1:-1:1
851-
c[i] = op(c[i], p)
852-
p *= v
853-
end
854-
u
855-
end
856-
857-
"""
858-
leftfactor(u)
859-
860-
Find greatest integer `g` such that `g^k` divides `u[k]` for all `k = 1:deg(u)`
861-
"""
862-
leftfactor(u) = polyfactor(u, true)
863-
864-
"""
865-
rightfactor(u)
866-
867-
Find greatest integer `g` such that `g^k` divides `u[deg(u)-k]` for all `k = 1:deg(u)`
868-
"""
869-
rightfactor(u) = polyfactor(u, false)
870-
871-
function polyfactor(u::UnivariatePolynomial{ZZ{T}}, left::Bool) where T<:Integer
872-
c = u.coeff
873-
n = deg(u)
874-
g = Vector{T}(undef, n)
875-
gk = zero(T)
876-
cc(k) = left ? c[k+1] : c[n-k+1]
877-
878-
for k = n:-1:1
879-
gk = gcd(gk, value(cc(k)))
880-
g[k] = gk
881-
isone(gk) && return gk
882-
end
883-
for a in factors(gk)
884-
a = gk ÷ a
885-
b = a
886-
isone(b) && break
887-
ok = true
888-
for k = 2:n
889-
b *= a
890-
if !iszero(rem(g[k], b))
891-
ok = false
892-
break
893-
end
894-
end
895-
ok && return a
896-
end
897-
one(gk)
898-
end
899-
=#
900640
"""
901641
allgcdx(v)
902642
@@ -925,19 +665,6 @@ function allgcdx(v::AbstractVector{T}) where T
925665
w
926666
end
927667

928-
function check_mutual_coprime(v)
929-
n = length(v)
930-
for i = 1:n
931-
for k = i+1:n
932-
g = gcd(v[i], v[k])
933-
if !isone(g)
934-
println("not coprime: v[i], v[k], $g = gcd($(v[i]), $(v[k]))")
935-
end
936-
end
937-
end
938-
nothing
939-
end
940-
941668
"""
942669
bezout_sum(u, a)
943670

src/univarpolynom.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,28 @@ end
470470
primpart(p::Polynomial)
471471
472472
The primitive part of the polynomial `p`, equals [`p / content(p)`](@ref).
473+
If the basetype is `QQ`, returned polynomial has basetype `ZZ`.
473474
"""
474475
primpart(p::Polynomial) = p / content(p)
475476
function primpart(p::UnivariatePolynomial{Q,X}) where {Q<:Union{QQ,Frac},X}
476477
Z = basetype(Q)
477-
(Z[X])(Z.(numerator.((p / content(p)).coeff)))
478+
(Z[X])(Z.(numerator.((p / content(p)).coeff)), p.first)
479+
end
480+
481+
"""
482+
content_primpart(p::UnivariatePolynomial{<:QQ})
483+
484+
Return content and primpart of a polynomial.
485+
"""
486+
function content_primpart(p::Polynomial)
487+
c = content(p)
488+
c, p / c
489+
end
490+
function content_primpart(p::P) where {T,X,P<:UnivariatePolynomial{QQ{T},X}}
491+
c = content(p)
492+
Z = ZZ{T}
493+
pp = Z[X](Z.(numerator.((p / c).coeff)), p.first)
494+
c, pp
478495
end
479496

480497
function inv(p::T) where T<:Polynomial

0 commit comments

Comments
 (0)