[GiNaC-devel] Polynomial arithmetics (Was: please pull from ...)

bernard.parisse bernard.parisse at wanadoo.fr
Mon Sep 22 22:34:00 CEST 2008


Alexei Sheplyakov wrote:

> Hello,
>
> On Mon, Sep 22, 2008 at 07:34:22PM +0200, Bernard Parisse wrote:
>
>  
>
>> Did you consider the option of writing GiNaC::ex to giac::gen 
>> converters and use giac factorization and gcd code instead?
>>   
>
>
> I've tried to re-use gcd and factorization code from giac. But sanitazing
> that code was very boring, and I've gave up. I guess I'll re-use (some)
> ideas instead.
>
>  
>
You never contacted me about using giac. Anyway, I don't see why you 
would have to "sanitaze" any code from giac : when I'm using a library, 
like GMP or NTL or whatever, I don't look at the coding style, I look at 
the performances and if I can easily call the functions. Using giac 
factor and gcd code is easy (using symbolic representation, it's a 
little bit more difficult if you work with polynomials).*

// -*- compile-command: "g++ -g essai.cc -lgmp -lgiac" -*-
#include "giac/giac.h"
using namespace std;
using namespace giac;

int main(int ARGC, char *ARGV[]){   
 signal(SIGINT,giac::ctrl_c_signal_handler);
 giac::child_id=1;
 context ct;
 gen x("x",&ct);
 gen g(pow(x,4)-1);
 gen gf=factor(g,false,&ct);
 gen gg=gcd(g,pow(x,4)+2*pow(x,2)+1);
 cerr << "Factorization:" << gf << " GCD:" << gg << endl;
}

Building a converter from ex to gen should not be hard (perhaps 1 or 2 
weeks of work, I might even consider to do it myself to be able to use 
some ginac functions someday).

>> I guess it would save you a lot of time and headaches
>>   
>
>
> At the expense of another headaches (such as messy error handling),
> unfortunately.
>
>  
>
What's wrong with giac error handling?
Anyway, if you believe you will have less headaches to get good 
performance for gcd and factorization (like Lewis gcd benchmarks), I 
will certainly not loose time to convince you otherwise, I already lost 
too much time trying to convince sage developpers. I just find it stupid 
that people prefer to redevelop something already working and C++-usable.

>> (I have worked and extensive amount of time on these functions, I 
>> know what I'm speaking of)
>>   
>
>
> I'm aware of that.
>
>  
>
>> without much loss of performance since the initial and final 
>> conversions do
>> not take much time with respect to these algorithms.
>>   
>
>
> That's not quite true. First of all, the conversion (at least) doubles
> the memory footprint. Secondly, GMP is quite slow when operating on small
> (i.e. native) integers (because it always allocates them on heap).
>
>  
>
If you had some look at giac, then you have perhaps observed that 
giac::gen use hardware integers for smalls integers (_INT_), GMP is used 
for int largers than 231 (_ZINT). Moreover most modular computations are 
done with int, not gen nor GMP.




More information about the GiNaC-devel mailing list