/* InterFace to Lisp routines, using foreign-function interface. This accesses the NTL factoring of polynomials (ZZX) routine. It should also serve as an example of how to program similar more complicated pieces than described in LispWins3.cpp . */ #include <NTL/ZZ_pX.h> #include <NTL/lzz_pX.h> #include <NTL/ZZX.h> #include <NTL/ZZXFactoring.h> #include <NTL/lzz_pXFactoring.h> #include <NTL/vec_vec_long.h> #include <NTL/vec_vec_ulong.h> #include <NTL/vec_double.h> #include <NTL/LLL.h> #include <NTL/new.h> NTL_START_IMPL //ZZX is NTL's name for polynomials in one variable (X) over // the arbitrary precision integers (ZZ). /* Here is the function we want to call... void factor(ZZ& c, vec_pair_ZZX_long& factors, const ZZX& f, long verbose=0, long bnd=0); */ //To interface with this program, see loadntl.cl. We // have to set up some buffers in lisp to hold the answers. extern "C" __declspec(dllexport) long LFactorPoly(ZZX * f, ZZX** ans, long* muls, ZZ* c ) {long bnd=0,verbose=0,size, i; vec_pair_ZZX_long * foo= new vec_pair_ZZX_long(); factor(* c, *foo, *f,verbose,bnd); //Call NTL Factoring size=(*foo).length(); // how many factors have we found? for (i=0; i<size; i++) { ans[i] = new ZZX(); * (ans[i]) = (*foo)[i].a; //the ith factor. muls[i]= (*foo)[i].b; // muls, multiplicities, is an array of longs, }; return(size); }