Project

General

Profile

Feature #1488

Updated by Anna Maria Bigatti over 1 year ago

The function @interreduce@ is implemented in CoCoA-5, and CoCoA-L, while the implementation (@NotBuiltin.cpkg5@) from @NotBuiltin.cpkg5@ can be translated into C++ in a straightforward way. Below you can find such an implementation which I am already using for more than a year. It is well-tested for lists of polynomials. (As I did not know where to put it best, I just added it to @src/CoCoA-5/BuiltInFunctions-CoCoALib.C@.)

<pre><code class="cpp">
DECLARE_STD_BUILTIN_FUNCTION(ir, 1) { //InterReduce-function added by Danner May'19
intrusive_ptr<RightValue> w = runtimeEnv->evalArgAs<LIST>(ARG(0));
vector<RingElem> v = runtimeEnv->evalRVAsListOfRingElem(w, ARG(0));

//ensure v is not an empty list
if (v.empty()) {
return Value::from(v);
}
//delete possible zeros in v
v.erase(std::remove(v.begin(), v.end(), v[0]-v[0]),v.end()); //v[0]-v[0]=0 in the correct ring.

vector<RingElem> ans;
RingElem rem;
int count=0;
bool newLPPfound=true;
while(newLPPfound){
ans=vector<RingElem>();
if(VerbosityLevel()>=90){printf("interreduced: round n.%i\n", ++count);}
newLPPfound=false;
sort(v.begin(), v.end(), [](RingElem elem1, RingElem elem2) {return LPP(elem1)<LPP(elem2);} );
for(vector<RingElem>::const_iterator it=v.begin(); it!=v.end(); ++it){
CheckForInterrupt("interreduction");
rem=NR(*it,ans);
if(!IsZero(rem)) {
ans.push_back(rem);
if(!newLPPfound && LPP(rem)!=LPP(*it)){
newLPPfound=true;
}
}
}
v=ans;
}
//result is stored in ans
return Value::from(ans);
}
END_STD_BUILTIN_FUNCTION
</code></pre>

It would be nice to officially get it in CoCoA-Lib ;)

Back