[GiNaC-list] feature request

Marko Riedel riedelmo at mathematik.uni-stuttgart.de
Wed Feb 22 23:16:44 CET 2023


Thank you for these useful comments. I just wanted to mention, there is 
a considerable improvement in creating the set of divisors from the 
factorization of an integer, see below. No more raising primes to some 
power.

Regards,

Marko

lst divisors(numeric n)
{
   if (n==1) return {1};

   lst pfact = factorizeposint(n), ent;

   numeric tau(1);

   lst::const_iterator it;
   for(it = pfact.begin(); it != pfact.end(); ++it){
     ent = ex_to<lst>(*it);
     tau *= numeric(1)+ex_to<numeric>(ent.op(1));
   }

   exvector res {};
   res.resize(tau.to_int(), numeric(1));

   int sofar = 1; int pos;
   for(it = pfact.begin(); it != pfact.end(); ++it){
     pos = sofar;
     ent = ex_to<lst>(*it);
     numeric p = ex_to<numeric>(ent.op(0));
     numeric v = ex_to<numeric>(ent.op(1));
     for(numeric vv(1); vv <= v; vv++){
       for(int q = 0; q < sofar; q++){
         res[pos] = res[pos-sofar]*p; pos++;
       }
     }
     sofar = pos;
   }

   lst result = {};
   for(pos=0; pos<sofar; pos++)
     result.append(res[pos]);

   return result;
}


Am 22.02.23 um 10:26 schrieb Vladimir V. Kisil:
> 	Dear Marko,
> 
> 	GiNaC is a library build on top of other libraries: numeric CLN
>    which is development of GNU GMP. Factorisation of integer is not in
>    the proper domain of GiNaC itself, it is rather a GMP task.
> 
>    Did you checked what is written here:
> 
> https://gmplib.org/manual/Demonstration-Programs#index-Factorization-demo
> 
>    Best wishes,
>    Vladimir


More information about the GiNaC-list mailing list