Skip to content

Commit fc49775

Browse files
hannes14mohamed-barakat
authored andcommitted
fix: conversion of transext to/from factory
1 parent c3238c9 commit fc49775

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

libpolys/coeffs/coeffs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ struct n_Procs_s
202202
number nNULL; /* the 0 as constant */
203203
int char_flag;
204204
int ref;
205+
/// how many variables of factort are already used by this coeff
206+
int factoryVarOffset;
205207
n_coeffType type;
206208
//-------------------------------------------
207209

libpolys/polys/clapconv.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ static void conv_RecPP ( const CanonicalForm & f, int * exp, sBucket_pt result,
6363
{
6464
poly term = p_Init(r);
6565
pNext( term ) = NULL;
66+
int varoffset=r->cf->factoryVarOffset;
6667
for ( int i = 1; i <= r->N; i++ )
67-
p_SetExp( term, i, exp[i], r);
68+
p_SetExp( term, i-varoffset, exp[i], r);
6869
pGetCoeff( term )=r->cf->convFactoryNSingN(f, r->cf);
6970
p_Setm( term, r );
7071
if ( n_IsZero(pGetCoeff(term), r->cf) )
@@ -91,10 +92,11 @@ CanonicalForm convSingPFactoryP( poly p, const ring r )
9192
term=r->cf->convSingNFactoryN(pGetCoeff( p ),setChar, r->cf);
9293
if (errorreported) break;
9394
setChar=FALSE;
95+
int varoffset=r->cf->factoryVarOffset;
9496
for ( int i = n; i >0; i-- )
9597
{
9698
if ( (e = p_GetExp( p, i, r)) != 0 )
97-
term *= power( Variable( i ), e );
99+
term *= power( Variable( i+varoffset ), e );
98100
}
99101
result += term;
100102
pIter( p );

libpolys/polys/ext_fields/transext.cc

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
#ifdef HAVE_FACTORY
5252
#include <polys/clapsing.h>
53+
#include <polys/clapconv.h>
54+
#include <factory/factory.h>
5355
#endif
5456

5557
#include "ext_fields/transext.h"
@@ -89,7 +91,7 @@ static const n_coeffType ID = n_transExt;
8991

9092

9193

92-
extern omBin fractionObjectBin = omGetSpecBin(sizeof(fractionObject));
94+
omBin fractionObjectBin = omGetSpecBin(sizeof(fractionObject));
9395

9496
/// forward declarations
9597
BOOLEAN ntGreaterZero(number a, const coeffs cf);
@@ -304,8 +306,8 @@ number ntInit(int i, const coeffs cf)
304306
{
305307
fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
306308
NUM(result) = p_ISet(i, ntRing);
307-
DEN(result) = NULL;
308-
COM(result) = 0;
309+
//DEN(result) = NULL; // done by omAlloc0Bin
310+
//COM(result) = 0; // done by omAlloc0Bin
309311
return (number)result;
310312
}
311313
}
@@ -1198,6 +1200,26 @@ void ntKillChar(coeffs cf)
11981200
if ((--cf->extRing->ref) == 0)
11991201
rDelete(cf->extRing);
12001202
}
1203+
#ifdef HAVE_FACTORY
1204+
number ntConvFactoryNSingN( const CanonicalForm n, const coeffs cf)
1205+
{
1206+
if (n.isZero()) return NULL;
1207+
poly p=convFactoryPSingP(n,ntRing);
1208+
fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
1209+
NUM(result) = p;
1210+
//DEN(result) = NULL; // done by omAlloc0Bin
1211+
//COM(result) = 0; // done by omAlloc0Bin
1212+
return (number)result;
1213+
}
1214+
CanonicalForm ntConvSingNFactoryN( number n, BOOLEAN setChar, const coeffs cf )
1215+
{
1216+
ntTest(n);
1217+
if (IS0(n)) return CanonicalForm(0);
1218+
1219+
fraction f = (fraction)n;
1220+
return convSingPFactoryP(NUM(f),ntRing);
1221+
}
1222+
#endif
12011223

12021224
BOOLEAN ntInitChar(coeffs cf, void * infoStruct)
12031225
{
@@ -1215,6 +1237,7 @@ BOOLEAN ntInitChar(coeffs cf, void * infoStruct)
12151237

12161238
cf->extRing = e->r;
12171239
cf->extRing->ref ++; // increase the ref.counter for the ground poly. ring!
1240+
cf->factoryVarOffset = cf->extRing->cf->factoryVarOffset+rVar(cf->extRing);
12181241

12191242
/* propagate characteristic up so that it becomes
12201243
directly accessible in cf: */
@@ -1260,6 +1283,9 @@ BOOLEAN ntInitChar(coeffs cf, void * infoStruct)
12601283
PrintS("// Warning: The 'factory' module is not available.\n");
12611284
PrintS("// Hence gcd's cannot be cancelled in any\n");
12621285
PrintS("// computed fraction!\n");
1286+
#else
1287+
cf->convFactoryNSingN =ntConvFactoryNSingN;
1288+
cf->convSingNFactoryN =ntConvSingNFactoryN;
12631289
#endif
12641290

12651291
return FALSE;

0 commit comments

Comments
 (0)