Karim Belabas on Sun, 22 Feb 2026 22:12:04 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Question on factorint matrix modification


* hermann@stamm-wilbrandt.de [2026-02-22 22:03]:
> A recursive function g(n) will call g(n/q) for each prime divisor q of n.
> 
> It can do so with: F=factorint(n)[,1];foreach(F,q,g(n/q))
> But that way each invocation of g() has to factorint its argument and those
> numbers are big.
> 
> I want to factor top n once and pass factorization matrix additionally.
> Just found one way to compute the reduced factorization matrix:
> 
> ? F=factorint(2^3*7*19^2);
> ? print(F)
> [2, 3; 7, 1; 19, 2]
> ? dec(f,i)=if(f[1]==i,[i,f[2]-1]~,f);
> ? for(i=1,#F~,M=Mat([g|f<-F~;g<-[dec(f,F~[1,i])],f[1]!=F~[1,i]||f[2]>1])~;print(M))
> [2, 2; 7, 1; 19, 2]
> [2, 3; 19, 2]
> [2, 3; 7, 1; 19, 1]
> ?
> 
> That does what I want and I am happy to have found it.
> But it looks a bit complex to me for the task.
> Is there a simpler GP way to determine the factorization matrix of n/q from
> F?
> Is there a way without matrix comprehension?

? removep(F, i) = matreduce(matconcat([F, [F[i,1],-1]]~))
? for (i = 1, #F~, print(removep(F, i)))
[2, 2; 7, 1; 19, 2]
[2, 3; 19, 2]
[2, 3; 7, 1; 19, 1]

matreduce is quite flexible, and more general of course.

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/