Question: split a polynomial based on leading integer coefficients

I could not find a command that splits a polynomial in parts based on leading integer coefficients, so I wrote a procedure. It works well, but I still wonder if there is no simpler way of doing this?
My aim is to investigate whether there is some way of factoring this and other polynomials.
 

kind regards,
Harry Garst
 

``

restart; with(ListTools); with(LinearAlgebra)

p := 2*x^3*y+2*x^3*z+4*x^2*y^2+24*x^2*y*z+4*x^2*z^2+2*x*y^3+24*x*y^2*z+24*x*y*z^2+2*x*z^3+2*y^3*z+4*y^2*z^2+2*y*z^3-40*x^2*y-40*x^2*z-40*x*y^2-40*x*z^2-40*y^2*z-40*y*z^2+108*x*y+108*x*z+108*y*z-9*x-9*y-9*z+36

2*x^3*y+2*x^3*z+4*x^2*y^2+24*x^2*y*z+4*x^2*z^2+2*x*y^3+24*x*y^2*z+24*x*y*z^2+2*x*z^3+2*y^3*z+4*y^2*z^2+2*y*z^3-40*x^2*y-40*x^2*z-40*x*y^2-40*x*z^2-40*y^2*z-40*y*z^2+108*x*y+108*x*z+108*y*z-9*x-9*y-9*z+36

(1)

p1 := 2*x^3*y+2*x^3*z+2*x*y^3+2*x*z^3+2*y^3*z+2*y*z^3

2*x^3*y+2*x^3*z+2*x*y^3+2*x*z^3+2*y^3*z+2*y*z^3

(2)

p2 := 24*x^2*y*z+24*x*y^2*z+24*x*y*z^2

24*x^2*y*z+24*x*y^2*z+24*x*y*z^2

(3)

p3 := 4*x^2*y^2+4*x^2*z^2+4*y^2*z^2

4*x^2*y^2+4*x^2*z^2+4*y^2*z^2

(4)

p4 := -40*x^2*y-40*x^2*z-40*x*y^2-40*x*z^2-40*y^2*z-40*y*z^2

-40*x^2*y-40*x^2*z-40*x*y^2-40*x*z^2-40*y^2*z-40*y*z^2

(5)

p5 := 108*x*y+108*x*z+108*y*z

108*x*y+108*x*z+108*y*z

(6)

p6 := -9*x-9*y-9*z

-9*x-9*y-9*z

(7)

p7 := 36

36

(8)

simplify(p-p1-p2-p3-p4-p5-p6-p7)

0

(9)

Knip := proc (p) local g, h, i, j, N, X, Q; g := sort(ListTools:-MakeUnique([seq(lcoeff([op(p)][j]), j = 1 .. nops([op(p)]))])); h := 0; N := Matrix(nops([op(p)]), 1); X := Matrix(nops([op(g)]), 1); Q := convert([op(p)], Matrix); for j in g do h := h+1; N[h, 1] := convert([seq(ifelse(has(lcoeff([op(p)][i]), j), 1, 0), i = 1 .. nops([op(p)]))], Matrix); X[h, 1] := LinearAlgebra:-Trace(Q.N[h, 1]^%T) end do; return X end proc

proc (p) local g, h, i, j, N, X, Q; g := sort(ListTools:-MakeUnique([seq(lcoeff([op(p)][j]), j = 1 .. nops([op(p)]))])); h := 0; N := Matrix(nops([op(p)]), 1); X := Matrix(nops([op(g)]), 1); Q := convert([op(p)], Matrix); for j in g do h := h+1; N[h, 1] := convert([seq(ifelse(has(lcoeff([op(p)][i]), j), 1, 0), i = 1 .. nops([op(p)]))], Matrix); X[h, 1] := LinearAlgebra:-Trace(Typesetting:-delayDotProduct(Q, N[h, 1]^%T)) end do; return X end proc

(10)

Knip(p)

Matrix(%id = 18446747088530918086)

(11)

simplify(p-Trace(Matrix(1, 7, 1).Knip(p)))

0

(12)

``


 

Download knip.mw

 

Please Wait...