My Project
Loading...
Searching...
No Matches
Functions
facMul.cc File Reference

This file implements functions for fast multiplication and division with remainder. More...

#include "debug.h"
#include "config.h"
#include <math.h>
#include "canonicalform.h"
#include "facMul.h"
#include "cf_util.h"
#include "cf_iter.h"
#include "cf_algorithm.h"
#include "templates/ftmpl_functions.h"
#include <NTL/lzz_pEX.h>
#include "NTLconvert.h"
#include "FLINTconvert.h"
#include "flint/fq_nmod_vec.h"

Go to the source code of this file.

Functions

void kronSubQa (fmpz_poly_t result, const CanonicalForm &A, int d)
 
CanonicalForm reverseSubstQa (const fmpz_poly_t F, int d, const Variable &x, const Variable &alpha, const CanonicalForm &den)
 
CanonicalForm mulFLINTQa (const CanonicalForm &F, const CanonicalForm &G, const Variable &alpha)
 
CanonicalForm mulFLINTQ (const CanonicalForm &F, const CanonicalForm &G)
 
CanonicalForm divFLINTQ (const CanonicalForm &F, const CanonicalForm &G)
 
CanonicalForm modFLINTQ (const CanonicalForm &F, const CanonicalForm &G)
 
CanonicalForm mulFLINTQaTrunc (const CanonicalForm &F, const CanonicalForm &G, const Variable &alpha, int m)
 
CanonicalForm mulFLINTQTrunc (const CanonicalForm &F, const CanonicalForm &G, int m)
 
CanonicalForm uniReverse (const CanonicalForm &F, int d, const Variable &x)
 
CanonicalForm newtonInverse (const CanonicalForm &F, const int n, const Variable &x)
 
void newtonDivrem (const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R)
 division with remainder of univariate polynomials over Q and Q(a) using Newton inversion, satisfying F=G*Q+R, deg(R) < deg(G)
 
void newtonDiv (const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q)
 
CanonicalForm mulNTL (const CanonicalForm &F, const CanonicalForm &G, const modpk &b)
 multiplication of univariate polys using FLINT/NTL over F_p, F_q, Z/p^k, Z/p^k[t]/(f), Z, Q, Q(a), if we are in GF factory's default multiplication is used. If b!= 0 and getCharacteristic() == 0 the input will be considered as elements over Z/p^k or Z/p^k[t]/(f).
 
CanonicalForm modNTL (const CanonicalForm &F, const CanonicalForm &G, const modpk &b)
 mod of univariate polys using FLINT/NTL over F_p, F_q, Z/p^k, Z/p^k[t]/(f), Z, Q, Q(a), if we are in GF factory's default multiplication is used. If b!= 0 and getCharacteristic() == 0 the input will be considered as elements over Z/p^k or Z/p^k[t]/(f); in this case invertiblity of Lc(G) is not checked
 
CanonicalForm divNTL (const CanonicalForm &F, const CanonicalForm &G, const modpk &b)
 division of univariate polys using FLINT/NTL over F_p, F_q, Z/p^k, Z/p^k[t]/(f), Z, Q, Q(a), if we are in GF factory's default multiplication is used. If b!= 0 and getCharacteristic() == 0 the input will be considered as elements over Z/p^k or Z/p^k[t]/(f); in this case invertiblity of Lc(G) is not checked
 
void kronSubFp (nmod_poly_t result, const CanonicalForm &A, int d)
 
void kronSubFq (fq_nmod_poly_t result, const CanonicalForm &A, int d, const fq_nmod_ctx_t fq_con)
 
void kronSubQa (fmpz_poly_t result, const CanonicalForm &A, int d1, int d2)
 
void kronSubReciproFp (nmod_poly_t subA1, nmod_poly_t subA2, const CanonicalForm &A, int d)
 
void kronSubReciproFq (fq_nmod_poly_t subA1, fq_nmod_poly_t subA2, const CanonicalForm &A, int d, const fq_nmod_ctx_t fq_con)
 
void kronSubReciproQ (fmpz_poly_t subA1, fmpz_poly_t subA2, const CanonicalForm &A, int d)
 
CanonicalForm reverseSubstQ (const fmpz_poly_t F, int d)
 
CanonicalForm reverseSubstQa (const fmpz_poly_t F, int d1, int d2, const Variable &alpha, const fmpq_poly_t mipo)
 
CanonicalForm reverseSubstReciproFp (const nmod_poly_t F, const nmod_poly_t G, int d, int k)
 
CanonicalForm reverseSubstReciproFq (const fq_nmod_poly_t F, const fq_nmod_poly_t G, int d, int k, const Variable &alpha, const fq_nmod_ctx_t fq_con)
 
CanonicalForm reverseSubstReciproQ (const fmpz_poly_t F, const fmpz_poly_t G, int d, int k)
 
CanonicalForm reverseSubstFq (const fq_nmod_poly_t F, int d, const Variable &alpha, const fq_nmod_ctx_t fq_con)
 
CanonicalForm reverseSubstFp (const nmod_poly_t F, int d)
 
CanonicalForm mulMod2FLINTFpReci (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
 
CanonicalForm mulMod2FLINTFp (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
 
CanonicalForm mulMod2FLINTFqReci (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M, const Variable &alpha, const fq_nmod_ctx_t fq_con)
 
CanonicalForm mulMod2FLINTFq (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M, const Variable &alpha, const fq_nmod_ctx_t fq_con)
 
CanonicalForm mulMod2FLINTQReci (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
 
CanonicalForm mulMod2FLINTQ (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
 
CanonicalForm mulMod2FLINTQa (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
 
CanonicalForm mulMod2NTLFq (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
 
CanonicalForm mulMod2 (const CanonicalForm &A, const CanonicalForm &B, const CanonicalForm &M)
 Karatsuba style modular multiplication for bivariate polynomials.
 
CanonicalForm mod (const CanonicalForm &F, const CFList &M)
 reduce F modulo elements in M.
 
CanonicalForm mulMod (const CanonicalForm &A, const CanonicalForm &B, const CFList &MOD)
 Karatsuba style modular multiplication for multivariate polynomials.
 
CanonicalForm prodMod (const CFList &L, const CanonicalForm &M)
 product of all elements in L modulo M via divide-and-conquer.
 
CanonicalForm prodMod (const CFList &L, const CFList &M)
 product of all elements in L modulo M via divide-and-conquer.
 
CanonicalForm reverse (const CanonicalForm &F, int d)
 
CanonicalForm newtonInverse (const CanonicalForm &F, const int n, const CanonicalForm &M)
 
CanonicalForm newtonDiv (const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
 division of F by G wrt Variable (1) modulo M using Newton inversion
 
void newtonDivrem (const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CanonicalForm &M)
 division with remainder of F by G wrt Variable (1) modulo M using Newton inversion
 
static CFList split (const CanonicalForm &F, const int m, const Variable &x)
 
static void divrem32 (const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CFList &M)
 
static void divrem21 (const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CFList &M)
 
void divrem2 (const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CanonicalForm &M)
 division with remainder of F by G wrt Variable (1) modulo M. Uses an algorithm based on Burnikel, Ziegler "Fast recursive division".
 
void divrem (const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CFList &MOD)
 division with remainder of F by G wrt Variable (1) modulo MOD. Uses an algorithm based on Burnikel, Ziegler "Fast recursive division".
 
bool uniFdivides (const CanonicalForm &A, const CanonicalForm &B)
 divisibility test for univariate polys
 

Detailed Description

This file implements functions for fast multiplication and division with remainder.

Nomenclature rules: kronSub* -> plain Kronecker substitution reverseSubst* -> reverse Kronecker substitution kronSubRecipro* -> reciprocal Kronecker substitution as described in D. Harvey "Faster polynomial multiplication via multipoint Kronecker substitution"

Author
Martin Lee

Definition in file facMul.cc.

Function Documentation

◆ divFLINTQ()

CanonicalForm divFLINTQ ( const CanonicalForm F,
const CanonicalForm G 
)

Definition at line 179 of file facMul.cc.

180{
181 CanonicalForm A= F;
183
187
190
193 return A;
194}
CanonicalForm convertFmpq_poly_t2FacCF(const fmpq_poly_t p, const Variable &x)
conversion of a FLINT poly over Q to CanonicalForm
void convertFacCF2Fmpq_poly_t(fmpq_poly_t result, const CanonicalForm &f)
conversion of a factory univariate polynomials over Q to fmpq_poly_t
factory's main class
Variable mvar() const
mvar() returns the main variable of CO or Variable() if CO is in a base domain.
b *CanonicalForm B
Definition facBivar.cc:52
STATIC_VAR TreeM * G
Definition janet.cc:31
#define A
Definition sirandom.c:24

◆ divNTL()

CanonicalForm divNTL ( const CanonicalForm F,
const CanonicalForm G,
const modpk b = modpk() 
)

division of univariate polys using FLINT/NTL over F_p, F_q, Z/p^k, Z/p^k[t]/(f), Z, Q, Q(a), if we are in GF factory's default multiplication is used. If b!= 0 and getCharacteristic() == 0 the input will be considered as elements over Z/p^k or Z/p^k[t]/(f); in this case invertiblity of Lc(G) is not checked

Returns
divNTL returns F/G
Parameters
[in]Fa univariate poly
[in]Ga univariate poly
[in]bcoeff bound

Definition at line 941 of file facMul.cc.

942{
944 return div (F, G);
945 if (F.inCoeffDomain() && G.isUnivariate() && !G.inCoeffDomain())
946 {
947 return 0;
948 }
949 else if (F.inCoeffDomain() && G.inCoeffDomain())
950 {
951 if (b.getp() != 0)
952 {
953 if (!F.inBaseDomain() || !G.inBaseDomain())
954 {
958#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
963
965 convertCF2initFmpz (FLINTp, b.getpk());
966
968
969 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
973 #else
975 #endif
976
979
982
984
989 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
992 #else
994 #endif
995 return b (result);
996#else
997 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
999 ZZ_pE::init (NTLmipo);
1002 ZZ_pE result;
1004 return b (convertNTLZZpX2CF (rep (result), alpha));
1005#endif
1006 }
1007 return b(div (F,G));
1008 }
1009 return div (F, G);
1010 }
1011 else if (F.isUnivariate() && G.inCoeffDomain())
1012 {
1013 if (b.getp() != 0)
1014 {
1015 if (!G.inBaseDomain())
1016 {
1019#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1020 fmpz_t FLINTp;
1024 fq_t FLINTG;
1025
1026 fmpz_init (FLINTp);
1027 convertCF2initFmpz (FLINTp, b.getpk());
1028
1030
1031 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1035 #else
1037 #endif
1038
1041
1044
1046 alpha, fq_con);
1047
1052 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1055 #else
1057 #endif
1058 return b (result);
1059#else
1060 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1062 ZZ_pE::init (NTLmipo);
1065 div (NTLf, NTLf, to_ZZ_pE (NTLg));
1066 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
1067#endif
1068 }
1069 return b(div (F,G));
1070 }
1071 return div (F, G);
1072 }
1073
1074 if (getCharacteristic() == 0)
1075 {
1076
1078 if (!hasFirstAlgVar (F, alpha) && !hasFirstAlgVar (G, alpha))
1079 {
1080#ifdef HAVE_FLINT
1081 if (b.getp() != 0)
1082 {
1085 convertCF2initFmpz (FLINTpk, b.getpk());
1089 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1093 #else
1095 #endif
1097 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1101 #else
1104 #endif
1106 return result;
1107 }
1108 return divFLINTQ (F,G);
1109#else
1110 if (b.getp() != 0)
1111 {
1112 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1117 div (NTLf, NTLf, NTLg);
1118 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
1119 }
1120 return div (F, G);
1121#endif
1122 }
1123 else
1124 {
1125 if (b.getp() != 0)
1126 {
1127#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1128 fmpz_t FLINTp;
1132
1133 fmpz_init (FLINTp);
1134 convertCF2initFmpz (FLINTp, b.getpk());
1135
1137
1138 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1142 #else
1144 #endif
1145
1148
1150
1152 alpha, fq_con);
1153
1158 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1161 #else
1163 #endif
1164 return b (result);
1165#else
1166 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1168 ZZ_pE::init (NTLmipo);
1171 div (NTLf, NTLf, NTLg);
1172 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
1173#endif
1174 }
1175#ifdef HAVE_FLINT
1177 newtonDiv (F, G, Q);
1178 return Q;
1179#else
1180 return div (F,G);
1181#endif
1182 }
1183 }
1184
1185 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
1186 ASSERT (F.level() == G.level(), "expected polys of same level");
1187#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
1189 {
1191 zz_p::init (getCharacteristic());
1192 }
1193#endif
1196 if (hasFirstAlgVar (F, alpha) || hasFirstAlgVar (G, alpha))
1197 {
1198#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1201
1204
1206
1210
1212
1214
1219#else
1221 zz_pE::init (NTLMipo);
1224 div (NTLF, NTLF, NTLG);
1226#endif
1227 }
1228 else
1229 {
1230#ifdef HAVE_FLINT
1238#else
1241 div (NTLF, NTLF, NTLG);
1243#endif
1244 }
1245 return result;
1246}
CanonicalForm convertFq_poly_t2FacCF(const fq_poly_t p, const Variable &x, const Variable &alpha, const fq_ctx_t ctx)
conversion of a FLINT poly over Fq (for non-word size p) to a CanonicalForm with alg....
void convertFacCF2Fq_t(fq_t result, const CanonicalForm &f, const fq_ctx_t ctx)
conversion of a factory element of F_q (for non-word size p) to a FLINT fq_t
CanonicalForm convertFq_nmod_poly_t2FacCF(const fq_nmod_poly_t p, const Variable &x, const Variable &alpha, const fq_nmod_ctx_t ctx)
conversion of a FLINT poly over Fq to a CanonicalForm with alg. variable alpha and polynomial variabl...
CanonicalForm convertFq_t2FacCF(const fq_t poly, const Variable &alpha)
conversion of a FLINT element of F_q with non-word size p to a CanonicalForm with alg....
CanonicalForm convertFmpz_mod_poly_t2FacCF(const fmpz_mod_poly_t poly, const Variable &x, const modpk &b)
conversion of a FLINT poly over Z/p (for non word size p) to a CanonicalForm over Z
CanonicalForm convertnmod_poly_t2FacCF(const nmod_poly_t poly, const Variable &x)
conversion of a FLINT poly over Z/p to CanonicalForm
void convertFacCF2Fmpz_mod_poly_t(fmpz_mod_poly_t result, const CanonicalForm &f, const fmpz_t p)
conversion of a factory univariate poly over Z to a FLINT poly over Z/p (for non word size p)
void convertFacCF2Fq_nmod_poly_t(fq_nmod_poly_t result, const CanonicalForm &f, const fq_nmod_ctx_t ctx)
conversion of a factory univariate poly over F_q to a FLINT fq_nmod_poly_t
void convertCF2initFmpz(fmpz_t result, const CanonicalForm &f)
conversion of a factory integer to fmpz_t(init.)
void convertFacCF2Fq_poly_t(fq_poly_t result, const CanonicalForm &f, const fq_ctx_t ctx)
conversion of a factory univariate poly over F_q (for non-word size p) to a FLINT fq_poly_t
ZZX convertFacCF2NTLZZX(const CanonicalForm &f)
zz_pEX convertFacCF2NTLzz_pEX(const CanonicalForm &f, const zz_pX &mipo)
CanonicalForm convertNTLzz_pEX2CF(const zz_pEX &f, const Variable &x, const Variable &alpha)
ZZ_pEX convertFacCF2NTLZZ_pEX(const CanonicalForm &f, const ZZ_pX &mipo)
CanonicalForm in Z_p(a)[X] to NTL ZZ_pEX.
CanonicalForm convertNTLzzpX2CF(const zz_pX &poly, const Variable &x)
CanonicalForm convertNTLZZpX2CF(const ZZ_pX &poly, const Variable &x)
NAME: convertNTLZZpX2CF.
CanonicalForm convertNTLZZX2CF(const ZZX &polynom, const Variable &x)
CanonicalForm convertNTLZZ_pEX2CF(const ZZ_pEX &f, const Variable &x, const Variable &alpha)
zz_pX convertFacCF2NTLzzpX(const CanonicalForm &f)
ZZ_pX convertFacCF2NTLZZpX(const CanonicalForm &f)
NAME: convertFacCF2NTLZZpX.
Definition NTLconvert.cc:64
VAR long fac_NTL_char
Definition NTLconvert.cc:46
ZZ convertFacCF2NTLZZ(const CanonicalForm &f)
NAME: convertFacCF2NTLZZX.
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm div(const CanonicalForm &, const CanonicalForm &)
bool hasFirstAlgVar(const CanonicalForm &f, Variable &a)
check if poly f contains an algebraic variable a
Definition cf_ops.cc:679
int FACTORY_PUBLIC getCharacteristic()
Definition cf_char.cc:70
CanonicalForm b
Definition cfModGcd.cc:4111
#define ASSERT(expression, message)
Definition cf_assert.h:99
#define GaloisFieldDomain
Definition cf_defs.h:18
static int gettype()
Definition cf_factory.h:28
bool inCoeffDomain() const
int level() const
level() returns the level of CO.
bool inBaseDomain() const
bool isUnivariate() const
factory's class for variables
Definition factory.h:127
Variable alpha
return result
fq_nmod_ctx_t fq_con
Definition facHensel.cc:99
fq_nmod_ctx_clear(fq_con)
nmod_poly_init(FLINTmipo, getCharacteristic())
fq_nmod_ctx_init_modulus(fq_con, FLINTmipo, "Z")
convertFacCF2nmod_poly_t(FLINTmipo, M)
nmod_poly_clear(FLINTmipo)
fq_nmod_poly_clear(prod, fq_con)
CanonicalForm divFLINTQ(const CanonicalForm &F, const CanonicalForm &G)
Definition facMul.cc:179
void newtonDiv(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q)
Definition facMul.cc:385
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
Definition variable.cc:207
#define Q
Definition sirandom.c:26

◆ divrem()

void divrem ( const CanonicalForm F,
const CanonicalForm G,
CanonicalForm Q,
CanonicalForm R,
const CFList MOD 
)

division with remainder of F by G wrt Variable (1) modulo MOD. Uses an algorithm based on Burnikel, Ziegler "Fast recursive division".

See also
divrem2()
Parameters
[in]Fmultivariate, compressed polynomial
[in]Gmultivariate, compressed polynomial
[in,out]Qdividend
[in,out]Rremainder, degree (R, 1) < degree (G, 1)
[in]MODonly contains powers of Variables of level higher than 1

Definition at line 3721 of file facMul.cc.

3723{
3724 CanonicalForm A= mod (F, MOD);
3725 CanonicalForm B= mod (G, MOD);
3726 Variable x= Variable (1);
3727 int degB= degree (B, x);
3728 if (degB > degree (A, x))
3729 {
3730 Q= 0;
3731 R= A;
3732 return;
3733 }
3734
3735 if (degB <= 0)
3736 {
3737 divrem (A, B, Q, R);
3738 Q= mod (Q, MOD);
3739 R= mod (R, MOD);
3740 return;
3741 }
3742 CFList splitA= split (A, degB, x);
3743
3746 Q= 0;
3748 H= i.getItem()*xToDegB;
3749 i++;
3750 H += i.getItem();
3751 while (i.hasItem())
3752 {
3753 divrem21 (H, B, bufQ, R, MOD);
3754 i++;
3755 if (i.hasItem())
3756 H= R*xToDegB + i.getItem();
3757 Q *= xToDegB;
3758 Q += bufQ;
3759 }
3760 return;
3761}
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
int degree(const CanonicalForm &f)
int i
Definition cfEzgcd.cc:132
Variable x
Definition cfModGcd.cc:4090
CanonicalForm H
Definition facAbsFact.cc:60
CanonicalForm mod(const CanonicalForm &F, const CFList &M)
reduce F modulo elements in M.
Definition facMul.cc:3077
void divrem(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CFList &MOD)
division with remainder of F by G wrt Variable (1) modulo MOD. Uses an algorithm based on Burnikel,...
Definition facMul.cc:3721
static CFList split(const CanonicalForm &F, const int m, const Variable &x)
Definition facMul.cc:3474
static void divrem21(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CFList &M)
Definition facMul.cc:3514
#define R
Definition sirandom.c:27

◆ divrem2()

void divrem2 ( const CanonicalForm F,
const CanonicalForm G,
CanonicalForm Q,
CanonicalForm R,
const CanonicalForm M 
)

division with remainder of F by G wrt Variable (1) modulo M. Uses an algorithm based on Burnikel, Ziegler "Fast recursive division".

Returns
Q returns the dividend, R returns the remainder.
See also
divrem()
Parameters
[in]Fbivariate, compressed polynomial
[in]Gbivariate, compressed polynomial
[in,out]Qdividend
[in,out]Rremainder, degree (R, 1) < degree (G, 1)
[in]Mpower of Variable (2)

Definition at line 3654 of file facMul.cc.

3656{
3657 CanonicalForm A= mod (F, M);
3658 CanonicalForm B= mod (G, M);
3659
3660 if (B.inCoeffDomain())
3661 {
3662 divrem (A, B, Q, R);
3663 return;
3664 }
3665 if (A.inCoeffDomain() && !B.inCoeffDomain())
3666 {
3667 Q= 0;
3668 R= A;
3669 return;
3670 }
3671
3672 if (B.level() < A.level())
3673 {
3674 divrem (A, B, Q, R);
3675 return;
3676 }
3677 if (A.level() > B.level())
3678 {
3679 R= A;
3680 Q= 0;
3681 return;
3682 }
3683 if (B.level() == 1 && B.isUnivariate())
3684 {
3685 divrem (A, B, Q, R);
3686 return;
3687 }
3688
3689 Variable x= Variable (1);
3690 int degB= degree (B, x);
3691 if (degB > degree (A, x))
3692 {
3693 Q= 0;
3694 R= A;
3695 return;
3696 }
3697
3698 CFList splitA= split (A, degB, x);
3699
3702 Q= 0;
3704 H= i.getItem()*xToDegB;
3705 i++;
3706 H += i.getItem();
3707 CFList buf;
3708 while (i.hasItem())
3709 {
3710 buf= CFList (M);
3711 divrem21 (H, B, bufQ, R, buf);
3712 i++;
3713 if (i.hasItem())
3714 H= R*xToDegB + i.getItem();
3715 Q *= xToDegB;
3716 Q += bufQ;
3717 }
3718 return;
3719}
List< CanonicalForm > CFList
int status int void * buf
Definition si_signals.h:59
#define M
Definition sirandom.c:25

◆ divrem21()

static void divrem21 ( const CanonicalForm F,
const CanonicalForm G,
CanonicalForm Q,
CanonicalForm R,
const CFList M 
)
inlinestatic

Definition at line 3514 of file facMul.cc.

3516{
3517 CanonicalForm A= mod (F, M);
3518 CanonicalForm B= mod (G, M);
3519 Variable x= Variable (1);
3520 int degB= degree (B, x);
3521 int degA= degree (A, x);
3522 if (degA < degB)
3523 {
3524 Q= 0;
3525 R= A;
3526 return;
3527 }
3528 if (degB < 1)
3529 {
3530 divrem (A, B, Q, R);
3531 Q= mod (Q, M);
3532 R= mod (R, M);
3533 return;
3534 }
3535 int m= (int) ceil ((double) (degB + 1)/2.0) + 1;
3536 ASSERT (4*m >= degA, "expected degree (F, 1) < 2*degree (G, 1)");
3537 CFList splitA= split (A, m, x);
3538 if (splitA.length() == 3)
3539 splitA.insert (0);
3540 if (splitA.length() == 2)
3541 {
3542 splitA.insert (0);
3543 splitA.insert (0);
3544 }
3545 if (splitA.length() == 1)
3546 {
3547 splitA.insert (0);
3548 splitA.insert (0);
3549 splitA.insert (0);
3550 }
3551
3553
3555 CanonicalForm H= i.getItem();
3556 i++;
3557 H *= xToM;
3558 H += i.getItem();
3559 i++;
3560 H *= xToM;
3561 H += i.getItem();
3562 i++;
3563
3564 divrem32 (H, B, Q, R, M);
3565
3566 CFList splitR= split (R, m, x);
3567 if (splitR.length() == 1)
3568 splitR.insert (0);
3569
3570 H= splitR.getFirst();
3571 H *= xToM;
3572 H += splitR.getLast();
3573 H *= xToM;
3574 H += i.getItem();
3575
3577 divrem32 (H, B, bufQ, R, M);
3578
3579 Q *= xToM;
3580 Q += bufQ;
3581 return;
3582}
int m
Definition cfEzgcd.cc:128
T getFirst() const
int length() const
T getLast() const
void insert(const T &)
static void divrem32(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CFList &M)
Definition facMul.cc:3585

◆ divrem32()

static void divrem32 ( const CanonicalForm F,
const CanonicalForm G,
CanonicalForm Q,
CanonicalForm R,
const CFList M 
)
inlinestatic

Definition at line 3585 of file facMul.cc.

3587{
3588 CanonicalForm A= mod (F, M);
3589 CanonicalForm B= mod (G, M);
3590 Variable x= Variable (1);
3591 int degB= degree (B, x);
3592 int degA= degree (A, x);
3593 if (degA < degB)
3594 {
3595 Q= 0;
3596 R= A;
3597 return;
3598 }
3599 if (degB < 1)
3600 {
3601 divrem (A, B, Q, R);
3602 Q= mod (Q, M);
3603 R= mod (R, M);
3604 return;
3605 }
3606 int m= (int) ceil ((double) (degB + 1)/ 2.0);
3607 ASSERT (3*m > degA, "expected degree (F, 1) < 3*degree (G, 1)");
3608 CFList splitA= split (A, m, x);
3609 CFList splitB= split (B, m, x);
3610
3611 if (splitA.length() == 2)
3612 {
3613 splitA.insert (0);
3614 }
3615 if (splitA.length() == 1)
3616 {
3617 splitA.insert (0);
3618 splitA.insert (0);
3619 }
3621
3624 i++;
3625
3626 if (degree (splitA.getFirst(), x) < degree (splitB.getFirst(), x))
3627 {
3628 H= splitA.getFirst()*xToM + i.getItem();
3629 divrem21 (H, splitB.getFirst(), Q, R, M);
3630 }
3631 else
3632 {
3633 R= splitA.getFirst()*xToM + i.getItem() + splitB.getFirst() -
3635 Q= xToM - 1;
3636 }
3637
3638 H= mulMod (Q, splitB.getLast(), M);
3639
3640 R= R*xToM + splitA.getLast() - H;
3641
3642 while (degree (R, x) >= degB)
3643 {
3644 xToM= power (x, degree (R, x) - degB);
3645 Q += LC (R, x)*xToM;
3646 R -= mulMod (LC (R, x), B, M)*xToM;
3647 Q= mod (Q, M);
3648 R= mod (R, M);
3649 }
3650
3651 return;
3652}
CanonicalForm LC(const CanonicalForm &f)
CanonicalForm mulMod(const CanonicalForm &A, const CanonicalForm &B, const CFList &MOD)
Karatsuba style modular multiplication for multivariate polynomials.
Definition facMul.cc:3085

◆ kronSubFp()

void kronSubFp ( nmod_poly_t  result,
const CanonicalForm A,
int  d 
)

Definition at line 1253 of file facMul.cc.

1254{
1255 int degAy= degree (A);
1257 result->length= d*(degAy + 1);
1258 flint_mpn_zero (result->coeffs, d*(degAy+1));
1259
1261
1262 int k;
1263 for (CFIterator i= A; i.hasTerms(); i++)
1264 {
1265 convertFacCF2nmod_poly_t (buf, i.coeff());
1266 k= i.exp()*d;
1267 flint_mpn_copyi (result->coeffs+k, buf->coeffs, nmod_poly_length(buf));
1268
1270 }
1272}
int k
Definition cfEzgcd.cc:99
class to iterate through CanonicalForm's
Definition cf_iter.h:44

◆ kronSubFq()

void kronSubFq ( fq_nmod_poly_t  result,
const CanonicalForm A,
int  d,
const fq_nmod_ctx_t  fq_con 
)

Definition at line 1276 of file facMul.cc.

1278{
1279 int degAy= degree (A);
1282 _fq_nmod_vec_zero (result->coeffs, d*(degAy + 1), fq_con);
1283
1285
1287
1288 int k;
1289
1290 for (CFIterator i= A; i.hasTerms(); i++)
1291 {
1292 if (i.coeff().inCoeffDomain())
1293 {
1294 convertFacCF2nmod_poly_t (buf2, i.coeff());
1298 }
1299 else
1301
1302 k= i.exp()*d;
1303 _fq_nmod_vec_set (result->coeffs+k, buf1->coeffs,
1305
1307 }
1308
1310}
CanonicalForm buf2
Definition facFqBivar.cc:76
CanonicalForm buf1
Definition facFqBivar.cc:76

◆ kronSubQa() [1/2]

void kronSubQa ( fmpz_poly_t  result,
const CanonicalForm A,
int  d 
)

Definition at line 51 of file facMul.cc.

52{
53 int degAy= degree (A);
54 fmpz_poly_init2 (result, d*(degAy + 1));
57 for (CFIterator i= A; i.hasTerms(); i++)
58 {
59 if (i.coeff().inBaseDomain())
61 else
62 for (j= i.coeff(); j.hasTerms(); j++)
64 j.coeff());
65 }
67}
int j
Definition facHensel.cc:110

◆ kronSubQa() [2/2]

void kronSubQa ( fmpz_poly_t  result,
const CanonicalForm A,
int  d1,
int  d2 
)

Definition at line 1358 of file facMul.cc.

1359{
1360 int degAy= degree (A);
1361 fmpz_poly_init2 (result, d1*(degAy + 1));
1363
1365
1366 int k;
1367 CFIterator j;
1368 for (CFIterator i= A; i.hasTerms(); i++)
1369 {
1370 if (i.coeff().inCoeffDomain())
1371 {
1372 k= d1*i.exp();
1373 convertFacCF2Fmpz_poly_t (buf, i.coeff());
1374 _fmpz_vec_set (result->coeffs + k, buf->coeffs, buf->length);
1376 }
1377 else
1378 {
1379 for (j= i.coeff(); j.hasTerms(); j++)
1380 {
1381 k= d1*i.exp();
1382 k += d2*j.exp();
1383 convertFacCF2Fmpz_poly_t (buf, j.coeff());
1384 _fmpz_vec_set (result->coeffs + k, buf->coeffs, buf->length);
1386 }
1387 }
1388 }
1390}
void convertFacCF2Fmpz_poly_t(fmpz_poly_t result, const CanonicalForm &f)
conversion of a factory univariate polynomial over Z to a fmpz_poly_t

◆ kronSubReciproFp()

void kronSubReciproFp ( nmod_poly_t  subA1,
nmod_poly_t  subA2,
const CanonicalForm A,
int  d 
)

Definition at line 1393 of file facMul.cc.

1395{
1396 int degAy= degree (A);
1400
1402
1403 int k, kk, j, bufRepLength;
1404 for (CFIterator i= A; i.hasTerms(); i++)
1405 {
1406 convertFacCF2nmod_poly_t (buf, i.coeff());
1407
1408 k= i.exp()*d;
1409 kk= (degAy - i.exp())*d;
1411 for (j= 0; j < bufRepLength; j++)
1412 {
1417 )
1418 );
1423 )
1424 );
1425 }
1427 }
1430}

◆ kronSubReciproFq()

void kronSubReciproFq ( fq_nmod_poly_t  subA1,
fq_nmod_poly_t  subA2,
const CanonicalForm A,
int  d,
const fq_nmod_ctx_t  fq_con 
)

Definition at line 1434 of file facMul.cc.

1436{
1437 int degAy= degree (A);
1440
1442 _fq_nmod_vec_zero (subA1->coeffs, d*(degAy + 2), fq_con);
1443
1445 _fq_nmod_vec_zero (subA2->coeffs, d*(degAy + 2), fq_con);
1446
1448
1450
1451 int k, kk;
1452 for (CFIterator i= A; i.hasTerms(); i++)
1453 {
1454 if (i.coeff().inCoeffDomain())
1455 {
1456 convertFacCF2nmod_poly_t (buf2, i.coeff());
1460 }
1461 else
1463
1464 k= i.exp()*d;
1465 kk= (degAy - i.exp())*d;
1466 _fq_nmod_vec_add (subA1->coeffs+k, subA1->coeffs+k, buf1->coeffs,
1468 _fq_nmod_vec_add (subA2->coeffs+kk, subA2->coeffs+kk, buf1->coeffs,
1470
1472 }
1475}

◆ kronSubReciproQ()

void kronSubReciproQ ( fmpz_poly_t  subA1,
fmpz_poly_t  subA2,
const CanonicalForm A,
int  d 
)

Definition at line 1479 of file facMul.cc.

1481{
1482 int degAy= degree (A);
1483 fmpz_poly_init2 (subA1, d*(degAy + 2));
1484 fmpz_poly_init2 (subA2, d*(degAy + 2));
1485
1487
1488 int k, kk;
1489 for (CFIterator i= A; i.hasTerms(); i++)
1490 {
1491 convertFacCF2Fmpz_poly_t (buf, i.coeff());
1492
1493 k= i.exp()*d;
1494 kk= (degAy - i.exp())*d;
1495 _fmpz_vec_add (subA1->coeffs+k, subA1->coeffs + k, buf->coeffs, buf->length);
1496 _fmpz_vec_add (subA2->coeffs+kk, subA2->coeffs + kk, buf->coeffs, buf->length);
1498 }
1499
1502}

◆ mod()

CanonicalForm mod ( const CanonicalForm F,
const CFList M 
)

reduce F modulo elements in M.

Returns
mod returns F modulo M
Parameters
[in]Fcompressed polynomial
[in]Mlist containing only univariate polynomials

Definition at line 3077 of file facMul.cc.

3078{
3079 CanonicalForm A= F;
3080 for (CFListIterator i= M; i.hasItem(); i++)
3081 A= mod (A, i.getItem());
3082 return A;
3083}

◆ modFLINTQ()

CanonicalForm modFLINTQ ( const CanonicalForm F,
const CanonicalForm G 
)

Definition at line 197 of file facMul.cc.

◆ modNTL()

CanonicalForm modNTL ( const CanonicalForm F,
const CanonicalForm G,
const modpk b = modpk() 
)

mod of univariate polys using FLINT/NTL over F_p, F_q, Z/p^k, Z/p^k[t]/(f), Z, Q, Q(a), if we are in GF factory's default multiplication is used. If b!= 0 and getCharacteristic() == 0 the input will be considered as elements over Z/p^k or Z/p^k[t]/(f); in this case invertiblity of Lc(G) is not checked

Returns
modNTL returns F mod G
Parameters
[in]Fa univariate poly
[in]Ga univariate poly
[in]bcoeff bound

Definition at line 736 of file facMul.cc.

737{
739 return mod (F, G);
740 if (F.inCoeffDomain() && G.isUnivariate() && !G.inCoeffDomain())
741 {
742 if (b.getp() != 0)
743 return b(F);
744 return F;
745 }
746 else if (F.inCoeffDomain() && G.inCoeffDomain())
747 {
748 if (b.getp() != 0)
749 return b(F%G);
750 return mod (F, G);
751 }
752 else if (F.isUnivariate() && G.inCoeffDomain())
753 {
754 if (b.getp() != 0)
755 return b(F%G);
756 return mod (F,G);
757 }
758
759 if (getCharacteristic() == 0)
760 {
762 if (!hasFirstAlgVar (F, alpha) && !hasFirstAlgVar (G, alpha))
763 {
764#ifdef HAVE_FLINT
765 if (b.getp() != 0)
766 {
769 convertCF2initFmpz (FLINTpk, b.getpk());
773 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
777 #else
779 #endif
781 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
785 #else
788 #endif
790 return result;
791 }
792 return modFLINTQ (F, G);
793#else
794 if (b.getp() != 0)
795 {
796 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
801 rem (NTLf, NTLf, NTLg);
802 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
803 }
804 return mod (F, G);
805#endif
806 }
807 else
808 {
809 if (b.getp() != 0)
810 {
811#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
816
818
819 convertCF2initFmpz (FLINTp, b.getpk());
820
822 bool rat=isOn(SW_RATIONAL);
825 mipo *= cd;
826 if (!rat) Off(SW_RATIONAL);
828
829 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
833 #else
835 #endif
836
839
841
843 alpha, fq_con);
844
849 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
852 #else
854 #endif
855
856 return b(result);
857#else
858 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
860 ZZ_pE::init (NTLmipo);
863 rem (NTLf, NTLf, NTLg);
864 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
865#endif
866 }
867#ifdef HAVE_FLINT
869 newtonDivrem (F, G, Q, R);
870 return R;
871#else
872 return mod (F,G);
873#endif
874 }
875 }
876
877 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
878 ASSERT (F.level() == G.level(), "expected polys of same level");
879#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
881 {
883 zz_p::init (getCharacteristic());
884 }
885#endif
889 {
890#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
893
896
898
902
904
906
911#else
913 zz_pE::init (NTLMipo);
916 rem (NTLF, NTLF, NTLG);
918#endif
919 }
920 else
921 {
922#ifdef HAVE_FLINT
930#else
933 rem (NTLF, NTLF, NTLG);
935#endif
936 }
937 return result;
938}
bool isOn(int sw)
switches
void On(int sw)
switches
void Off(int sw)
switches
CanonicalForm cd(bCommonDen(FF))
Definition cfModGcd.cc:4097
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
static const int SW_RATIONAL
set to 1 for computations over Q
Definition cf_defs.h:31
CanonicalForm mipo
Definition facAlgExt.cc:57
void newtonDivrem(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R)
division with remainder of univariate polynomials over Q and Q(a) using Newton inversion,...
Definition facMul.cc:351
CanonicalForm modFLINTQ(const CanonicalForm &F, const CanonicalForm &G)
Definition facMul.cc:197
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition minpoly.cc:572

◆ mulFLINTQ()

CanonicalForm mulFLINTQ ( const CanonicalForm F,
const CanonicalForm G 
)

Definition at line 138 of file facMul.cc.

139{
140 CanonicalForm A= F;
142
145
146 A *= denA;
147 B *= denB;
152 denA *= denB;
154 A /= denA;
157
158 return A;
159}
CanonicalForm convertFmpz_poly_t2FacCF(const fmpz_poly_t poly, const Variable &x)
conversion of a FLINT poly over Z to CanonicalForm

◆ mulFLINTQa()

CanonicalForm mulFLINTQa ( const CanonicalForm F,
const CanonicalForm G,
const Variable alpha 
)

Definition at line 108 of file facMul.cc.

110{
111 CanonicalForm A= F;
113
116
117 A *= denA;
118 B *= denB;
119 int degAa= degree (A, alpha);
120 int degBa= degree (B, alpha);
121 int d= degAa + 1 + degBa;
122
124 kronSubQa (FLINTA, A, d);
125 kronSubQa (FLINTB, B, d);
126
128
129 denA *= denB;
130 A= reverseSubstQa (FLINTA, d, F.mvar(), alpha, denA);
131
134 return A;
135}
void kronSubQa(fmpz_poly_t result, const CanonicalForm &A, int d)
Definition facMul.cc:51
CanonicalForm reverseSubstQa(const fmpz_poly_t F, int d, const Variable &x, const Variable &alpha, const CanonicalForm &den)
Definition facMul.cc:71

◆ mulFLINTQaTrunc()

CanonicalForm mulFLINTQaTrunc ( const CanonicalForm F,
const CanonicalForm G,
const Variable alpha,
int  m 
)

Definition at line 215 of file facMul.cc.

217{
218 CanonicalForm A= F;
220
223
224 A *= denA;
225 B *= denB;
226
227 int degAa= degree (A, alpha);
228 int degBa= degree (B, alpha);
229 int d= degAa + 1 + degBa;
230
232 kronSubQa (FLINTA, A, d);
233 kronSubQa (FLINTB, B, d);
234
235 int k= d*m;
237
238 denA *= denB;
239 A= reverseSubstQa (FLINTA, d, F.mvar(), alpha, denA);
242 return A;
243}

◆ mulFLINTQTrunc()

CanonicalForm mulFLINTQTrunc ( const CanonicalForm F,
const CanonicalForm G,
int  m 
)

Definition at line 246 of file facMul.cc.

247{
248 if (F.inCoeffDomain() && G.inCoeffDomain())
249 return F*G;
250 if (F.inCoeffDomain())
251 return mod (F*G, power (G.mvar(), m));
252 if (G.inCoeffDomain())
253 return mod (F*G, power (F.mvar(), m));
256 return mulFLINTQaTrunc (F, G, alpha, m);
257
258 CanonicalForm A= F;
260
263
264 A *= denA;
265 B *= denB;
270 denA *= denB;
272 A /= denA;
275
276 return A;
277}
CanonicalForm mulFLINTQaTrunc(const CanonicalForm &F, const CanonicalForm &G, const Variable &alpha, int m)
Definition facMul.cc:215

◆ mulMod()

CanonicalForm mulMod ( const CanonicalForm A,
const CanonicalForm B,
const CFList MOD 
)

Karatsuba style modular multiplication for multivariate polynomials.

Returns
mulMod2 returns A * B mod MOD.
Parameters
[in]Amultivariate, compressed polynomial
[in]Bmultivariate, compressed polynomial
[in]MODonly contains powers of Variables of level higher than 1

Definition at line 3085 of file facMul.cc.

3087{
3088 if (A.isZero() || B.isZero())
3089 return 0;
3090
3091 if (MOD.length() == 1)
3092 return mulMod2 (A, B, MOD.getLast());
3093
3095 CanonicalForm F= mod (A, M);
3096 CanonicalForm G= mod (B, M);
3097 if (F.inCoeffDomain())
3098 return G*F;
3099 if (G.inCoeffDomain())
3100 return F*G;
3101
3102 int sizeF= size (F);
3103 int sizeG= size (G);
3104
3105 if (sizeF / MOD.length() < 100 || sizeG / MOD.length() < 100)
3106 {
3107 if (sizeF < sizeG)
3108 return mod (G*F, MOD);
3109 else
3110 return mod (F*G, MOD);
3111 }
3112
3113 Variable y= M.mvar();
3114 int degF= degree (F, y);
3115 int degG= degree (G, y);
3116
3117 if ((degF <= 1 && F.level() <= M.level()) &&
3118 (degG <= 1 && G.level() <= M.level()))
3119 {
3120 CFList buf= MOD;
3121 buf.removeLast();
3122 if (degF == 1 && degG == 1)
3123 {
3124 CanonicalForm F0= mod (F, y);
3125 CanonicalForm F1= div (F, y);
3126 CanonicalForm G0= mod (G, y);
3127 CanonicalForm G1= div (G, y);
3128 if (degree (M) > 2)
3129 {
3132 CanonicalForm H01= mulMod (F0 + F1, G0 + G1, buf);
3133 return H11*y*y + (H01 - H00 - H11)*y + H00;
3134 }
3135 else //here degree (M) == 2
3136 {
3137 buf.append (y);
3142 return result;
3143 }
3144 }
3145 else if (degF == 1 && degG == 0)
3146 return mulMod (div (F, y), G, buf)*y + mulMod (mod (F, y), G, buf);
3147 else if (degF == 0 && degG == 1)
3148 return mulMod (div (G, y), F, buf)*y + mulMod (mod (G, y), F, buf);
3149 else
3150 return mulMod (F, G, buf);
3151 }
3152 int m= (int) ceil (degree (M)/2.0);
3153 if (degF >= m || degG >= m)
3154 {
3156 CanonicalForm MHi= power (y, degree (M) - m);
3157 CanonicalForm F0= mod (F, MLo);
3158 CanonicalForm F1= div (F, MLo);
3159 CanonicalForm G0= mod (G, MLo);
3160 CanonicalForm G1= div (G, MLo);
3161 CFList buf= MOD;
3162 buf.removeLast();
3163 buf.append (MHi);
3167 return F0G0 + MLo*(F0G1 + F1G0);
3168 }
3169 else
3170 {
3171 m= (tmax(degF, degG)+1)/2;
3173 CanonicalForm F0= mod (F, yToM);
3174 CanonicalForm F1= div (F, yToM);
3179 CanonicalForm H01= mulMod (F0 + F1, G0 + G1, MOD);
3180 return H11*yToM*yToM + (H01 - H11 - H00)*yToM + H00;
3181 }
3182 DEBOUTLN (cerr, "fatal end in mulMod");
3183}
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
CF_NO_INLINE bool isZero() const
void append(const T &)
void removeLast()
#define DEBOUTLN(stream, objects)
Definition debug.h:49
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53
CanonicalForm mulMod2(const CanonicalForm &A, const CanonicalForm &B, const CanonicalForm &M)
Karatsuba style modular multiplication for bivariate polynomials.
Definition facMul.cc:2991
template CanonicalForm tmax(const CanonicalForm &, const CanonicalForm &)

◆ mulMod2()

Karatsuba style modular multiplication for bivariate polynomials.

Returns
mulMod2 returns A * B mod M.
Parameters
[in]Abivariate, compressed polynomial
[in]Bbivariate, compressed polynomial
[in]Mpower of Variable (2)

Definition at line 2991 of file facMul.cc.

2993{
2994 if (A.isZero() || B.isZero())
2995 return 0;
2996
2997 ASSERT (M.isUnivariate(), "M must be univariate");
2998
2999 CanonicalForm F= mod (A, M);
3000 CanonicalForm G= mod (B, M);
3001 if (F.inCoeffDomain())
3002 return G*F;
3003 if (G.inCoeffDomain())
3004 return F*G;
3005
3006 Variable y= M.mvar();
3007 int degF= degree (F, y);
3008 int degG= degree (G, y);
3009
3010 if ((degF < 1 && degG < 1) && (F.isUnivariate() && G.isUnivariate()) &&
3011 (F.level() == G.level()))
3012 {
3014 return mod (result, M);
3015 }
3016 else if (degF <= 1 && degG <= 1)
3017 {
3019 return mod (result, M);
3020 }
3021
3022 int sizeF= size (F);
3023 int sizeG= size (G);
3024
3025 int fallBackToNaive= 50;
3027 {
3028 if (sizeF < sizeG)
3029 return mod (G*F, M);
3030 else
3031 return mod (F*G, M);
3032 }
3033
3034#ifdef HAVE_FLINT
3035 if (getCharacteristic() == 0)
3036 return mulMod2FLINTQa (F, G, M);
3037#endif
3038
3040 (((degF-degG) < 50 && degF > degG) || ((degG-degF) < 50 && degF <= degG)))
3041 return mulMod2NTLFq (F, G, M);
3042
3043 int m= (int) ceil (degree (M)/2.0);
3044 if (degF >= m || degG >= m)
3045 {
3047 CanonicalForm MHi= power (y, degree (M) - m);
3048 CanonicalForm F0= mod (F, MLo);
3049 CanonicalForm F1= div (F, MLo);
3050 CanonicalForm G0= mod (G, MLo);
3051 CanonicalForm G1= div (G, MLo);
3055 return F0G0 + MLo*(F0G1 + F1G0);
3056 }
3057 else
3058 {
3059 m= (int) ceil (tmax (degF, degG)/2.0);
3061 CanonicalForm F0= mod (F, yToM);
3062 CanonicalForm F1= div (F, yToM);
3067 CanonicalForm H01= mulMod2 (F0 + F1, G0 + G1, M);
3068 return H11*yToM*yToM + (H01 - H11 - H00)*yToM + H00;
3069 }
3070 DEBOUTLN (cerr, "fatal end in mulMod2");
3071}
CanonicalForm mulNTL(const CanonicalForm &F, const CanonicalForm &G, const modpk &b)
multiplication of univariate polys using FLINT/NTL over F_p, F_q, Z/p^k, Z/p^k[t]/(f),...
Definition facMul.cc:416
CanonicalForm mulMod2NTLFq(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2931
CanonicalForm mulMod2FLINTQa(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2337

◆ mulMod2FLINTFp()

CanonicalForm mulMod2FLINTFp ( const CanonicalForm F,
const CanonicalForm G,
const CanonicalForm M 
)

Definition at line 2133 of file facMul.cc.

2135{
2136 CanonicalForm A= F;
2137 CanonicalForm B= G;
2138
2139 int degAx= degree (A, 1);
2140 int degAy= degree (A, 2);
2141 int degBx= degree (B, 1);
2142 int degBy= degree (B, 2);
2143 int d1= degAx + 1 + degBx;
2144 int d2= tmax (degAy, degBy);
2145
2146 if (d1 > 128 && d2 > 160 && (degAy == degBy) && (2*degAy > degree (M)))
2147 return mulMod2FLINTFpReci (A, B, M);
2148
2150 kronSubFp (FLINTA, A, d1);
2151 kronSubFp (FLINTB, B, d1);
2152
2153 int k= d1*degree (M);
2155
2157
2160 return A;
2161}
CanonicalForm reverseSubstFp(const nmod_poly_t F, int d)
Definition facMul.cc:2059
CanonicalForm mulMod2FLINTFpReci(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2095
void kronSubFp(nmod_poly_t result, const CanonicalForm &A, int d)
Definition facMul.cc:1253

◆ mulMod2FLINTFpReci()

CanonicalForm mulMod2FLINTFpReci ( const CanonicalForm F,
const CanonicalForm G,
const CanonicalForm M 
)

Definition at line 2095 of file facMul.cc.

2097{
2098 int d1= degree (F, 1) + degree (G, 1) + 1;
2099 d1 /= 2;
2100 d1 += 1;
2101
2102 nmod_poly_t F1, F2;
2103 kronSubReciproFp (F1, F2, F, d1);
2104
2105 nmod_poly_t G1, G2;
2106 kronSubReciproFp (G1, G2, G, d1);
2107
2108 int k= d1*degree (M);
2109 nmod_poly_mullow (F1, F1, G1, (long) k);
2110
2111 int degtailF= degree (tailcoeff (F), 1);;
2112 int degtailG= degree (tailcoeff (G), 1);
2113 int taildegF= taildegree (F);
2114 int taildegG= taildegree (G);
2115
2117 + d1*(2+taildegF + taildegG);
2118 nmod_poly_mulhigh (F2, F2, G2, b);
2121
2122
2124
2129 return result;
2130}
CanonicalForm tailcoeff(const CanonicalForm &f)
int taildegree(const CanonicalForm &f)
void kronSubReciproFp(nmod_poly_t subA1, nmod_poly_t subA2, const CanonicalForm &A, int d)
Definition facMul.cc:1393
CanonicalForm reverseSubstReciproFp(const nmod_poly_t F, const nmod_poly_t G, int d, int k)
Definition facMul.cc:1667

◆ mulMod2FLINTFq()

CanonicalForm mulMod2FLINTFq ( const CanonicalForm F,
const CanonicalForm G,
const CanonicalForm M,
const Variable alpha,
const fq_nmod_ctx_t  fq_con 
)

Definition at line 2207 of file facMul.cc.

2210{
2211 CanonicalForm A= F;
2212 CanonicalForm B= G;
2213
2214 int degAx= degree (A, 1);
2215 int degAy= degree (A, 2);
2216 int degBx= degree (B, 1);
2217 int degBy= degree (B, 2);
2218 int d1= degAx + 1 + degBx;
2219 int d2= tmax (degAy, degBy);
2220
2221 if (d1 > 128 && d2 > 160 && (degAy == degBy) && (2*degAy > degree (M)))
2222 return mulMod2FLINTFqReci (A, B, M, alpha, fq_con);
2223
2225 kronSubFq (FLINTA, A, d1, fq_con);
2226 kronSubFq (FLINTB, B, d1, fq_con);
2227
2228 int k= d1*degree (M);
2230
2232
2235 return A;
2236}
void kronSubFq(fq_nmod_poly_t result, const CanonicalForm &A, int d, const fq_nmod_ctx_t fq_con)
Definition facMul.cc:1276
CanonicalForm mulMod2FLINTFqReci(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M, const Variable &alpha, const fq_nmod_ctx_t fq_con)
Definition facMul.cc:2165
CanonicalForm reverseSubstFq(const fq_nmod_poly_t F, int d, const Variable &alpha, const fq_nmod_ctx_t fq_con)
Definition facMul.cc:2024

◆ mulMod2FLINTFqReci()

CanonicalForm mulMod2FLINTFqReci ( const CanonicalForm F,
const CanonicalForm G,
const CanonicalForm M,
const Variable alpha,
const fq_nmod_ctx_t  fq_con 
)

Definition at line 2165 of file facMul.cc.

2168{
2169 int d1= degree (F, 1) + degree (G, 1) + 1;
2170 d1 /= 2;
2171 d1 += 1;
2172
2174 kronSubReciproFq (F1, F2, F, d1, fq_con);
2175
2178
2179 int k= d1*degree (M);
2180 fq_nmod_poly_mullow (F1, F1, G1, (long) k, fq_con);
2181
2182 int degtailF= degree (tailcoeff (F), 1);
2183 int degtailG= degree (tailcoeff (G), 1);
2184 int taildegF= taildegree (F);
2185 int taildegG= taildegree (G);
2186
2187 int b= k + degtailF + degtailG - d1*(2+taildegF + taildegG);
2188
2193
2196
2198
2203 return result;
2204}
CanonicalForm reverseSubstReciproFq(const fq_nmod_poly_t F, const fq_nmod_poly_t G, int d, int k, const Variable &alpha, const fq_nmod_ctx_t fq_con)
Definition facMul.cc:1786
void kronSubReciproFq(fq_nmod_poly_t subA1, fq_nmod_poly_t subA2, const CanonicalForm &A, int d, const fq_nmod_ctx_t fq_con)
Definition facMul.cc:1434

◆ mulMod2FLINTQ()

CanonicalForm mulMod2FLINTQ ( const CanonicalForm F,
const CanonicalForm G,
const CanonicalForm M 
)

Definition at line 2277 of file facMul.cc.

2279{
2280 CanonicalForm A= F;
2281 CanonicalForm B= G;
2282
2283 int degAx= degree (A, 1);
2284 int degBx= degree (B, 1);
2285 int d1= degAx + 1 + degBx;
2286
2289 A *= f;
2290 B *= g;
2291
2293 kronSubQa (FLINTA, A, d1);
2294 kronSubQa (FLINTB, B, d1);
2295 int k= d1*degree (M);
2296
2301 return A/(f*g);
2302}
g
Definition cfModGcd.cc:4098
FILE * f
Definition checklibs.c:9
CanonicalForm reverseSubstQ(const fmpz_poly_t F, int d)
Definition facMul.cc:1504

◆ mulMod2FLINTQa()

CanonicalForm mulMod2FLINTQa ( const CanonicalForm F,
const CanonicalForm G,
const CanonicalForm M 
)

Definition at line 2337 of file facMul.cc.

2339{
2340 Variable a;
2341 if (!hasFirstAlgVar (F,a) && !hasFirstAlgVar (G, a))
2342 return mulMod2FLINTQ (F, G, M);
2343 CanonicalForm A= F, B= G;
2344
2345 int degFx= degree (F, 1);
2346 int degFa= degree (F, a);
2347 int degGx= degree (G, 1);
2348 int degGa= degree (G, a);
2349
2350 int d2= degFa+degGa+1;
2351 int d1= degFx + 1 + degGx;
2352 d1 *= d2;
2353
2356 A *= f;
2357 B *= g;
2358
2360 kronSubQa (FLINTF, A, d1, d2);
2361 kronSubQa (FLINTG, B, d1, d2);
2362
2364
2367 A= reverseSubstQa (FLINTF, d1, d2, a, mipo);
2370 return A/(f*g);
2371}
CanonicalForm mulMod2FLINTQ(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2277

◆ mulMod2FLINTQReci()

CanonicalForm mulMod2FLINTQReci ( const CanonicalForm F,
const CanonicalForm G,
const CanonicalForm M 
)

Definition at line 2240 of file facMul.cc.

2242{
2243 int d1= degree (F, 1) + degree (G, 1) + 1;
2244 d1 /= 2;
2245 d1 += 1;
2246
2247 fmpz_poly_t F1, F2;
2248 kronSubReciproQ (F1, F2, F, d1);
2249
2250 fmpz_poly_t G1, G2;
2251 kronSubReciproQ (G1, G2, G, d1);
2252
2253 int k= d1*degree (M);
2254 fmpz_poly_mullow (F1, F1, G1, (long) k);
2255
2256 int degtailF= degree (tailcoeff (F), 1);;
2257 int degtailG= degree (tailcoeff (G), 1);
2258 int taildegF= taildegree (F);
2259 int taildegG= taildegree (G);
2260
2262 + d1*(2+taildegF + taildegG);
2266
2268
2273 return result;
2274}
void kronSubReciproQ(fmpz_poly_t subA1, fmpz_poly_t subA2, const CanonicalForm &A, int d)
Definition facMul.cc:1479
CanonicalForm reverseSubstReciproQ(const fmpz_poly_t F, const fmpz_poly_t G, int d, int k)
Definition facMul.cc:1890

◆ mulMod2NTLFq()

CanonicalForm mulMod2NTLFq ( const CanonicalForm F,
const CanonicalForm G,
const CanonicalForm M 
)

Definition at line 2931 of file facMul.cc.

2933{
2935 CanonicalForm A= F;
2936 CanonicalForm B= G;
2937
2939 {
2940#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
2943
2946
2947 A= mulMod2FLINTFq (A, B, M, alpha, fq_con);
2950#else
2951 int degAx= degree (A, 1);
2952 int degAy= degree (A, 2);
2953 int degBx= degree (B, 1);
2954 int degBy= degree (B, 2);
2955 int d1= degAx + degBx + 1;
2956 int d2= tmax (degAy, degBy);
2958 {
2960 zz_p::init (getCharacteristic());
2961 }
2963 zz_pE::init (NTLMipo);
2964
2965 int degMipo= degree (getMipo (alpha));
2966 if ((d1 > 128/degMipo) && (d2 > 160/degMipo) && (degAy == degBy) &&
2967 (2*degAy > degree (M)))
2968 return mulMod2NTLFqReci (A, B, M, alpha);
2969
2972
2973 int k= d1*degree (M);
2974
2975 MulTrunc (NTLA, NTLA, NTLB, (long) k);
2976
2978#endif
2979 }
2980 else
2981 {
2982#ifdef HAVE_FLINT
2983 A= mulMod2FLINTFp (A, B, M);
2984#else
2985 A= mulMod2NTLFp (A, B, M);
2986#endif
2987 }
2988 return A;
2989}
CanonicalForm mulMod2FLINTFq(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M, const Variable &alpha, const fq_nmod_ctx_t fq_con)
Definition facMul.cc:2207
CanonicalForm mulMod2FLINTFp(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2133

◆ mulNTL()

CanonicalForm mulNTL ( const CanonicalForm F,
const CanonicalForm G,
const modpk b = modpk() 
)

multiplication of univariate polys using FLINT/NTL over F_p, F_q, Z/p^k, Z/p^k[t]/(f), Z, Q, Q(a), if we are in GF factory's default multiplication is used. If b!= 0 and getCharacteristic() == 0 the input will be considered as elements over Z/p^k or Z/p^k[t]/(f).

Returns
mulNTL returns F*G
Parameters
[in]Fa univariate poly
[in]Ga univariate poly
[in]bcoeff bound

Definition at line 416 of file facMul.cc.

417{
419 return F*G;
420 if (getCharacteristic() == 0)
421 {
423 if ((!F.inCoeffDomain() && !G.inCoeffDomain()) &&
425 {
426 if (b.getp() != 0)
427 {
429 bool is_rat= isOn (SW_RATIONAL);
430 if (!is_rat)
431 On (SW_RATIONAL);
432 mipo *=bCommonDen (mipo);
433 if (!is_rat)
435#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
440
442
443 convertCF2initFmpz (FLINTp, b.getpk());
444
446
447 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
451 #else
453 #endif
454
457
459
461 alpha, fq_con);
462
467 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
470 #else
472 #endif
473 return b (result);
474#endif
475#ifdef HAVE_NTL
476 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
478 ZZ_pE::init (NTLmipo);
481 mul (NTLf, NTLf, NTLg);
482
483 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
484#endif
485 }
486#ifdef HAVE_FLINT
488 return result;
489#else
490 return F*G;
491#endif
492 }
493 else if (!F.inCoeffDomain() && !G.inCoeffDomain())
494 {
495#ifdef HAVE_FLINT
496 if (b.getp() != 0)
497 {
500 convertCF2initFmpz (FLINTpk, b.getpk());
504 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
508 #else
510 #endif
512 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
516 #else
519 #endif
521 return result;
522 }
523 return mulFLINTQ (F, G);
524#endif
525#ifdef HAVE_NTL
526 if (b.getp() != 0)
527 {
528 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
533 mul (NTLf, NTLf, NTLg);
534 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
535 }
536 return F*G;
537#endif
538 }
539 if (b.getp() != 0)
540 {
541 if (!F.inBaseDomain() && !G.inBaseDomain())
542 {
544 {
545#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
549
551 convertCF2initFmpz (FLINTp, b.getpk());
552
554 bool rat=isOn(SW_RATIONAL);
557 mipo *= cd;
558 if (!rat) Off(SW_RATIONAL);
560
561 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
565 #else
567 #endif
568
570
571 if (F.inCoeffDomain() && !G.inCoeffDomain())
572 {
577
579
583 }
584 else if (!F.inCoeffDomain() && G.inCoeffDomain())
585 {
588
591
593
597 }
598 else
599 {
601
604
606
610 }
611
613 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
616 #else
618 #endif
620
621 return b (result);
622#endif
623#ifdef HAVE_NTL
624 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
626 ZZ_pE::init (NTLmipo);
627
628 if (F.inCoeffDomain() && !G.inCoeffDomain())
629 {
632 mul (NTLg, to_ZZ_pE (NTLf), NTLg);
633 return b (convertNTLZZ_pEX2CF (NTLg, G.mvar(), alpha));
634 }
635 else if (!F.inCoeffDomain() && G.inCoeffDomain())
636 {
639 mul (NTLf, NTLf, to_ZZ_pE (NTLg));
640 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
641 }
642 else
643 {
648 return b (convertNTLZZpX2CF (rep (result), alpha));
649 }
650#endif
651 }
652 }
653 return b (F*G);
654 }
655 return F*G;
656 }
657 else if (F.inCoeffDomain() || G.inCoeffDomain())
658 return F*G;
659 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
660 ASSERT (F.level() == G.level(), "expected polys of same level");
661#ifdef HAVE_NTL
662#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
664 {
666 zz_p::init (getCharacteristic());
667 }
668#endif
669#endif
673 {
674 if (!getReduce (alpha))
675 {
676 result= 0;
677 for (CFIterator i= F; i.hasTerms(); i++)
678 result += i.coeff()*G*power (F.mvar(),i.exp());
679 return result;
680 }
681#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
684
687
689
693
695
697
702 return result;
703#elif defined(AHVE_NTL)
705 zz_pE::init (NTLMipo);
708 mul (NTLF, NTLF, NTLG);
710 return result;
711#endif
712 }
713 else
714 {
715#ifdef HAVE_FLINT
723 return result;
724#endif
725#ifdef HAVE_NTL
728 mul (NTLF, NTLF, NTLG);
729 return convertNTLzzpX2CF(NTLF, F.mvar());
730#endif
731 }
732 return F*G;
733}
CanonicalForm mulFLINTQ(const CanonicalForm &F, const CanonicalForm &G)
Definition facMul.cc:138
CanonicalForm mulFLINTQa(const CanonicalForm &F, const CanonicalForm &G, const Variable &alpha)
Definition facMul.cc:108
bool getReduce(const Variable &alpha)
Definition variable.cc:232

◆ newtonDiv() [1/2]

void newtonDiv ( const CanonicalForm F,
const CanonicalForm G,
CanonicalForm Q 
)

Definition at line 385 of file facMul.cc.

386{
387 ASSERT (F.level() == G.level(), "F and G have different level");
388 CanonicalForm A= F;
390 Variable x= A.mvar();
391 int degA= degree (A);
392 int degB= degree (B);
393 int m= degA - degB;
394
395 if (m < 0)
396 {
397 Q= 0;
398 return;
399 }
400
401 if (degB <= 1)
402 Q= div (A, B);
403 else
404 {
407 revB= newtonInverse (revB, m + 1, x);
408 Q= mulFLINTQTrunc (R, revB, m + 1);
409 Q= uniReverse (Q, m, x);
410 }
411}
CanonicalForm uniReverse(const CanonicalForm &F, int d, const Variable &x)
Definition facMul.cc:279
CanonicalForm mulFLINTQTrunc(const CanonicalForm &F, const CanonicalForm &G, int m)
Definition facMul.cc:246
CanonicalForm newtonInverse(const CanonicalForm &F, const int n, const Variable &x)
Definition facMul.cc:296

◆ newtonDiv() [2/2]

division of F by G wrt Variable (1) modulo M using Newton inversion

Returns
newtonDiv returns the dividend
See also
divrem2(), newtonDivrem()
Parameters
[in]Fbivariate, compressed polynomial
[in]Gbivariate, compressed polynomial which is monic in Variable (1)
[in]Mpower of Variable (2)

Definition at line 3318 of file facMul.cc.

3320{
3321 ASSERT (getCharacteristic() > 0, "positive characteristic expected");
3322
3323 CanonicalForm A= mod (F, M);
3324 CanonicalForm B= mod (G, M);
3325
3326 Variable x= Variable (1);
3327 int degA= degree (A, x);
3328 int degB= degree (B, x);
3329 int m= degA - degB;
3330 if (m < 0)
3331 return 0;
3332
3333 Variable v;
3336 {
3338 divrem2 (A, B, Q, R, M);
3339 }
3340 else
3341 {
3342 if (hasFirstAlgVar (A, v) || hasFirstAlgVar (B, v))
3343 {
3346 revB= newtonInverse (revB, m + 1, M);
3347 Q= mulMod2 (R, revB, M);
3348 Q= mod (Q, power (x, m + 1));
3349 Q= reverse (Q, m);
3350 }
3351 else
3352 {
3353 Variable y= Variable (2);
3354#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
3357
3360
3362
3363
3367
3369
3371
3376#else
3377 bool zz_pEbak= zz_pE::initialized();
3378 zz_pEBak bak;
3379 if (zz_pEbak)
3380 bak.save();
3382 zz_pEX NTLA, NTLB;
3385 div (NTLA, NTLA, NTLB);
3387 if (zz_pEbak)
3388 bak.restore();
3389#endif
3390 }
3391 }
3392
3393 return Q;
3394}
CanonicalForm FACTORY_PUBLIC swapvar(const CanonicalForm &, const Variable &, const Variable &)
swapvar() - swap variables x1 and x2 in f.
Definition cf_ops.cc:168
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
CanonicalForm reverse(const CanonicalForm &F, int d)
Definition facMul.cc:3239
void divrem2(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CanonicalForm &M)
division with remainder of F by G wrt Variable (1) modulo M. Uses an algorithm based on Burnikel,...
Definition facMul.cc:3654

◆ newtonDivrem() [1/2]

void newtonDivrem ( const CanonicalForm F,
const CanonicalForm G,
CanonicalForm Q,
CanonicalForm R 
)

division with remainder of univariate polynomials over Q and Q(a) using Newton inversion, satisfying F=G*Q+R, deg(R) < deg(G)

Parameters
[in]Funivariate poly
[in]Gunivariate poly
[in,out]Qquotient
[in,out]Rremainder

Definition at line 351 of file facMul.cc.

353{
354 ASSERT (F.level() == G.level(), "F and G have different level");
355 CanonicalForm A= F;
357 Variable x= A.mvar();
358 int degA= degree (A);
359 int degB= degree (B);
360 int m= degA - degB;
361
362 if (m < 0)
363 {
364 R= A;
365 Q= 0;
366 return;
367 }
368
369 if (degB <= 1)
370 divrem (A, B, Q, R);
371 else
372 {
373 R= uniReverse (A, degA, x);
374
376 revB= newtonInverse (revB, m + 1, x);
377 Q= mulFLINTQTrunc (R, revB, m + 1);
378 Q= uniReverse (Q, m, x);
379
380 R= A - mulNTL (Q, B);
381 }
382}

◆ newtonDivrem() [2/2]

void newtonDivrem ( const CanonicalForm F,
const CanonicalForm G,
CanonicalForm Q,
CanonicalForm R,
const CanonicalForm M 
)

division with remainder of F by G wrt Variable (1) modulo M using Newton inversion

Returns
Q returns the dividend, R returns the remainder.
See also
divrem2(), newtonDiv()
Parameters
[in]Fbivariate, compressed polynomial
[in]Gbivariate, compressed polynomial which is monic in Variable (1)
[in,out]Qdividend
[in,out]Rremainder, degree (R, 1) < degree (G, 1)
[in]Mpower of Variable (2)

Definition at line 3397 of file facMul.cc.

3399{
3400 CanonicalForm A= mod (F, M);
3401 CanonicalForm B= mod (G, M);
3402 Variable x= Variable (1);
3403 int degA= degree (A, x);
3404 int degB= degree (B, x);
3405 int m= degA - degB;
3406
3407 if (m < 0)
3408 {
3409 R= A;
3410 Q= 0;
3411 return;
3412 }
3413
3414 Variable v;
3415 if (degB <= 1 || CFFactory::gettype() == GaloisFieldDomain)
3416 {
3417 divrem2 (A, B, Q, R, M);
3418 }
3419 else
3420 {
3421 if (hasFirstAlgVar (A, v) || hasFirstAlgVar (B, v))
3422 {
3423 R= reverse (A, degA);
3424
3426 revB= newtonInverse (revB, m + 1, M);
3427 Q= mulMod2 (R, revB, M);
3428
3429 Q= mod (Q, power (x, m + 1));
3430 Q= reverse (Q, m);
3431
3432 R= A - mulMod2 (Q, B, M);
3433 }
3434 else
3435 {
3436 Variable y= Variable (2);
3437#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
3440
3443
3445
3449
3451
3454
3459#else
3461 zz_pEX NTLA, NTLB;
3464 zz_pEX NTLQ, NTLR;
3465 DivRem (NTLQ, NTLR, NTLA, NTLB);
3468#endif
3469 }
3470 }
3471}

◆ newtonInverse() [1/2]

CanonicalForm newtonInverse ( const CanonicalForm F,
const int  n,
const CanonicalForm M 
)

Definition at line 3263 of file facMul.cc.

3264{
3265 int l= ilog2(n);
3266
3267 CanonicalForm g= mod (F, M)[0] [0];
3268
3269 ASSERT (!g.isZero(), "expected a unit");
3270
3272
3273 if (!g.isOne())
3274 g = 1/g;
3275 Variable x= Variable (1);
3277 int exp= 0;
3278 if (n & 1)
3279 {
3280 result= g;
3281 exp= 1;
3282 }
3284
3285 for (int i= 1; i <= l; i++)
3286 {
3287 h= mulMod2 (g, mod (F, power (x, (1 << i))), M);
3288 h= mod (h, power (x, (1 << i)) - 1);
3289 h= div (h, power (x, (1 << (i - 1))));
3290 h= mod (h, M);
3291 g -= power (x, (1 << (i - 1)))*
3292 mod (mulMod2 (g, h, M), power (x, (1 << (i - 1))));
3293
3294 if (n & (1 << i))
3295 {
3296 if (exp)
3297 {
3298 h= mulMod2 (result, mod (F, power (x, exp + (1 << i))), M);
3299 h= mod (h, power (x, exp + (1 << i)) - 1);
3300 h= div (h, power (x, exp));
3301 h= mod (h, M);
3302 result -= power(x, exp)*mod (mulMod2 (g, h, M),
3303 power (x, (1 << i)));
3304 exp += (1 << i);
3305 }
3306 else
3307 {
3308 exp= (1 << i);
3309 result= g;
3310 }
3311 }
3312 }
3313
3314 return result;
3315}
int ilog2(const CanonicalForm &a)
int l
Definition cfEzgcd.cc:100
STATIC_VAR Poly * h
Definition janet.cc:971
gmp_float exp(const gmp_float &a)

◆ newtonInverse() [2/2]

CanonicalForm newtonInverse ( const CanonicalForm F,
const int  n,
const Variable x 
)

Definition at line 296 of file facMul.cc.

297{
298 int l= ilog2(n);
299
301 if (F.inCoeffDomain())
302 g= F;
303 else
304 g= F [0];
305
306 if (!F.inCoeffDomain())
307 ASSERT (F.mvar() == x, "main variable of F and x differ");
308 ASSERT (!g.isZero(), "expected a unit");
309
310 if (!g.isOne())
311 g = 1/g;
313 int exp= 0;
314 if (n & 1)
315 {
316 result= g;
317 exp= 1;
318 }
320
321 for (int i= 1; i <= l; i++)
322 {
323 h= mulNTL (g, mod (F, power (x, (1 << i))));
324 h= mod (h, power (x, (1 << i)) - 1);
325 h= div (h, power (x, (1 << (i - 1))));
326 g -= power (x, (1 << (i - 1)))*
327 mulFLINTQTrunc (g, h, 1 << (i-1));
328
329 if (n & (1 << i))
330 {
331 if (exp)
332 {
333 h= mulNTL (result, mod (F, power (x, exp + (1 << i))));
334 h= mod (h, power (x, exp + (1 << i)) - 1);
335 h= div (h, power (x, exp));
336 result -= power(x, exp)*mulFLINTQTrunc (g, h, 1 << i);
337 exp += (1 << i);
338 }
339 else
340 {
341 exp= (1 << i);
342 result= g;
343 }
344 }
345 }
346
347 return result;
348}

◆ prodMod() [1/2]

CanonicalForm prodMod ( const CFList L,
const CanonicalForm M 
)

product of all elements in L modulo M via divide-and-conquer.

Returns
prodMod returns product of all elements in L modulo M.
Parameters
[in]Lcontains only bivariate, compressed polynomials
[in]Mpower of Variable (2)

Definition at line 3185 of file facMul.cc.

3186{
3187 if (L.isEmpty())
3188 return 1;
3189 int l= L.length();
3190 if (l == 1)
3191 return mod (L.getFirst(), M);
3192 else if (l == 2) {
3194 return result;
3195 }
3196 else
3197 {
3198 l /= 2;
3199 CFList tmp1, tmp2;
3200 CFListIterator i= L;
3202 for (int j= 1; j <= l; j++, i++)
3203 tmp1.append (i.getItem());
3204 tmp2= Difference (L, tmp1);
3205 buf1= prodMod (tmp1, M);
3206 buf2= prodMod (tmp2, M);
3208 return result;
3209 }
3210}
int isEmpty() const
CFList tmp1
Definition facFqBivar.cc:75
CFList tmp2
Definition facFqBivar.cc:75
CanonicalForm prodMod(const CFList &L, const CanonicalForm &M)
product of all elements in L modulo M via divide-and-conquer.
Definition facMul.cc:3185
template List< Variable > Difference(const List< Variable > &, const List< Variable > &)

◆ prodMod() [2/2]

CanonicalForm prodMod ( const CFList L,
const CFList M 
)

product of all elements in L modulo M via divide-and-conquer.

Returns
prodMod returns product of all elements in L modulo M.
Parameters
[in]Lcontains multivariate, compressed polynomials
[in]Mcontains only powers of Variables

Definition at line 3212 of file facMul.cc.

3213{
3214 if (L.isEmpty())
3215 return 1;
3216 else if (L.length() == 1)
3217 return L.getFirst();
3218 else if (L.length() == 2)
3219 return mulMod (L.getFirst(), L.getLast(), M);
3220 else
3221 {
3222 int l= L.length()/2;
3223 CFListIterator i= L;
3224 CFList tmp1, tmp2;
3226 for (int j= 1; j <= l; j++, i++)
3227 tmp1.append (i.getItem());
3228 tmp2= Difference (L, tmp1);
3229 buf1= prodMod (tmp1, M);
3230 buf2= prodMod (tmp2, M);
3231 return mulMod (buf1, buf2, M);
3232 }
3233}

◆ reverse()

CanonicalForm reverse ( const CanonicalForm F,
int  d 
)

Definition at line 3239 of file facMul.cc.

3240{
3241 if (d == 0)
3242 return F;
3243 CanonicalForm A= F;
3244 Variable y= Variable (2);
3245 Variable x= Variable (1);
3246 if (degree (A, x) > 0)
3247 {
3248 A= swapvar (A, x, y);
3250 CFIterator i= A;
3251 while (d - i.exp() < 0)
3252 i++;
3253
3254 for (; i.hasTerms() && (d - i.exp() >= 0); i++)
3255 result += swapvar (i.coeff(),x,y)*power (x, d - i.exp());
3256 return result;
3257 }
3258 else
3259 return A*power (x, d);
3260}

◆ reverseSubstFp()

CanonicalForm reverseSubstFp ( const nmod_poly_t  F,
int  d 
)

Definition at line 2059 of file facMul.cc.

2060{
2061 Variable y= Variable (2);
2062 Variable x= Variable (1);
2063
2065
2068 int i= 0;
2069 int degf= nmod_poly_degree(F);
2070 int k= 0;
2071 int degfSubK, repLength, j;
2072 while (degf >= k)
2073 {
2074 degfSubK= degf - k;
2075 if (degfSubK >= d)
2076 repLength= d;
2077 else
2078 repLength= degfSubK + 1;
2079
2081 for (j= 0; j < repLength; j++)
2084
2086 i++;
2087 k= d*i;
2089 }
2090
2091 return result;
2092}

◆ reverseSubstFq()

CanonicalForm reverseSubstFq ( const fq_nmod_poly_t  F,
int  d,
const Variable alpha,
const fq_nmod_ctx_t  fq_con 
)

Definition at line 2024 of file facMul.cc.

2026{
2027 Variable y= Variable (2);
2028 Variable x= Variable (1);
2029
2032 int i= 0;
2034 int k= 0;
2035 int degfSubK, repLength;
2036 while (degf >= k)
2037 {
2038 degfSubK= degf - k;
2039 if (degfSubK >= d)
2040 repLength= d;
2041 else
2042 repLength= degfSubK + 1;
2043
2046 _fq_nmod_vec_set (buf->coeffs, F->coeffs+k, repLength, fq_con);
2048
2050 i++;
2051 k= d*i;
2053 }
2054
2055 return result;
2056}

◆ reverseSubstQ()

CanonicalForm reverseSubstQ ( const fmpz_poly_t  F,
int  d 
)

Definition at line 1504 of file facMul.cc.

1505{
1506 Variable y= Variable (2);
1507 Variable x= Variable (1);
1508
1511 int i= 0;
1512 int degf= fmpz_poly_degree(F);
1513 int k= 0;
1514 int degfSubK, repLength;
1515 while (degf >= k)
1516 {
1517 degfSubK= degf - k;
1518 if (degfSubK >= d)
1519 repLength= d;
1520 else
1521 repLength= degfSubK + 1;
1522
1525 _fmpz_vec_set (buf->coeffs, F->coeffs+k, repLength);
1527
1529 i++;
1530 k= d*i;
1532 }
1533
1534 return result;
1535}

◆ reverseSubstQa() [1/2]

CanonicalForm reverseSubstQa ( const fmpz_poly_t  F,
int  d,
const Variable x,
const Variable alpha,
const CanonicalForm den 
)

Definition at line 71 of file facMul.cc.

73{
75 int i= 0;
76 int degf= fmpz_poly_degree (F);
77 int k= 0;
78 int degfSubK;
79 int repLength;
83 while (degf >= k)
84 {
85 degfSubK= degf - k;
86 if (degfSubK >= d)
87 repLength= d;
88 else
90
93 _fmpz_vec_set (buf->coeffs, F->coeffs + k, repLength);
96
99 i++;
100 k= d*i;
101 }
103 result /= den;
104 return result;
105}
CanonicalForm den(const CanonicalForm &f)

◆ reverseSubstQa() [2/2]

CanonicalForm reverseSubstQa ( const fmpz_poly_t  F,
int  d1,
int  d2,
const Variable alpha,
const fmpq_poly_t  mipo 
)

Definition at line 1610 of file facMul.cc.

1612{
1613 Variable y= Variable (2);
1614 Variable x= Variable (1);
1615
1618 int i= 0;
1619 int degf= fmpz_poly_degree(F);
1620 int k= 0;
1621 int degfSubK;
1622 int repLength;
1623 while (degf >= k)
1624 {
1625 degfSubK= degf - k;
1626 if (degfSubK >= d1)
1627 repLength= d1;
1628 else
1629 repLength= degfSubK + 1;
1630
1631 int j= 0;
1632 result2= 0;
1633 while (j*d2 < repLength)
1634 {
1637 _fmpz_vec_set (buf->coeffs, F->coeffs + k + j*d2, d2);
1641 j++;
1643 }
1644 if (repLength - j*d2 != 0 && j*d2 - repLength < d2)
1645 {
1646 j--;
1647 repLength -= j*d2;
1650 j++;
1651 _fmpz_vec_set (buf->coeffs, F->coeffs + k + j*d2, repLength);
1656 }
1657
1658 result += result2*power (y, i);
1659 i++;
1660 k= d1*i;
1661 }
1662
1663 return result;
1664}

◆ reverseSubstReciproFp()

CanonicalForm reverseSubstReciproFp ( const nmod_poly_t  F,
const nmod_poly_t  G,
int  d,
int  k 
)

Definition at line 1667 of file facMul.cc.

1668{
1669 Variable y= Variable (2);
1670 Variable x= Variable (1);
1671
1672 nmod_poly_t f, g;
1676 nmod_poly_set (f, F);
1677 nmod_poly_set (g, G);
1678 int degf= nmod_poly_degree(f);
1679 int degg= nmod_poly_degree(g);
1680
1681
1683
1684 if (nmod_poly_length (f) < (long) d*(k+1)) //zero padding
1685 nmod_poly_fit_length (f,(long)d*(k+1));
1686
1688 int i= 0;
1689 int lf= 0;
1690 int lg= d*k;
1691 int degfSubLf= degf;
1692 int deggSubLg= degg-lg;
1694 while (degf >= lf || lg >= 0)
1695 {
1696 if (degfSubLf >= d)
1697 repLengthBuf1= d;
1698 else if (degfSubLf < 0)
1699 repLengthBuf1= 0;
1700 else
1703
1704 for (ind= 0; ind < repLengthBuf1; ind++)
1707
1709
1710 if (deggSubLg >= d - 1)
1711 repLengthBuf2= d - 1;
1712 else if (deggSubLg < 0)
1713 repLengthBuf2= 0;
1714 else
1716
1718 for (ind= 0; ind < repLengthBuf2; ind++)
1720
1723
1725 for (ind= 0; ind < repLengthBuf1; ind++)
1727 for (ind= repLengthBuf1; ind < d; ind++)
1729 for (ind= 0; ind < repLengthBuf2; ind++)
1732
1734 i++;
1735
1736
1737 lf= i*d;
1738 degfSubLf= degf - lf;
1739
1740 lg= d*(k-i);
1741 deggSubLg= degg - lg;
1742
1743 if (lg >= 0 && deggSubLg > 0)
1744 {
1745 if (repLengthBuf2 > degfSubLf + 1)
1748 for (ind= 0; ind < tmp; ind++)
1753 )
1754 );
1755 }
1756 if (lg < 0)
1757 {
1761 break;
1762 }
1763 if (degfSubLf >= 0)
1764 {
1765 for (ind= 0; ind < repLengthBuf2; ind++)
1770 )
1771 );
1772 }
1776 }
1777
1780
1781 return result;
1782}
int degg
Definition facAlgExt.cc:64
template CanonicalForm tmin(const CanonicalForm &, const CanonicalForm &)

◆ reverseSubstReciproFq()

CanonicalForm reverseSubstReciproFq ( const fq_nmod_poly_t  F,
const fq_nmod_poly_t  G,
int  d,
int  k,
const Variable alpha,
const fq_nmod_ctx_t  fq_con 
)

Definition at line 1786 of file facMul.cc.

1788{
1789 Variable y= Variable (2);
1790 Variable x= Variable (1);
1791
1795
1797
1802 if (fq_nmod_poly_length (f, fq_con) < (long) d*(k + 1)) //zero padding
1803 fq_nmod_poly_fit_length (f, (long) d*(k + 1), fq_con);
1804
1806 int i= 0;
1807 int lf= 0;
1808 int lg= d*k;
1809 int degfSubLf= degf;
1810 int deggSubLg= degg-lg;
1812 while (degf >= lf || lg >= 0)
1813 {
1814 if (degfSubLf >= d)
1815 repLengthBuf1= d;
1816 else if (degfSubLf < 0)
1817 repLengthBuf1= 0;
1818 else
1822
1823 _fq_nmod_vec_set (buf1->coeffs, f->coeffs + lf, repLengthBuf1, fq_con);
1825
1827
1828 if (deggSubLg >= d - 1)
1829 repLengthBuf2= d - 1;
1830 else if (deggSubLg < 0)
1831 repLengthBuf2= 0;
1832 else
1834
1837 _fq_nmod_vec_set (buf2->coeffs, g->coeffs + lg, repLengthBuf2, fq_con);
1838
1841
1844 _fq_nmod_vec_set (buf3->coeffs, buf1->coeffs, repLengthBuf1, fq_con);
1845 _fq_nmod_vec_set (buf3->coeffs + d, buf2->coeffs, repLengthBuf2, fq_con);
1846
1848
1850 i++;
1851
1852
1853 lf= i*d;
1854 degfSubLf= degf - lf;
1855
1856 lg= d*(k - i);
1857 deggSubLg= degg - lg;
1858
1859 if (lg >= 0 && deggSubLg > 0)
1860 {
1861 if (repLengthBuf2 > degfSubLf + 1)
1864 _fq_nmod_vec_sub (g->coeffs + lg, g->coeffs + lg, buf1-> coeffs,
1865 tmp, fq_con);
1866 }
1867 if (lg < 0)
1868 {
1872 break;
1873 }
1874 if (degfSubLf >= 0)
1875 _fq_nmod_vec_sub (f->coeffs + lf, f->coeffs + lf, buf2->coeffs,
1880 }
1881
1884
1885 return result;
1886}
fq_nmod_poly_init(prod, fq_con)
The main handler for Singular numbers which are suitable for Singular polynomials.

◆ reverseSubstReciproQ()

CanonicalForm reverseSubstReciproQ ( const fmpz_poly_t  F,
const fmpz_poly_t  G,
int  d,
int  k 
)

Definition at line 1890 of file facMul.cc.

1891{
1892 Variable y= Variable (2);
1893 Variable x= Variable (1);
1894
1895 fmpz_poly_t f, g;
1896 fmpz_poly_init (f);
1897 fmpz_poly_init (g);
1898 fmpz_poly_set (f, F);
1899 fmpz_poly_set (g, G);
1900 int degf= fmpz_poly_degree(f);
1901 int degg= fmpz_poly_degree(g);
1902
1904
1905 if (fmpz_poly_length (f) < (long) d*(k+1)) //zero padding
1906 fmpz_poly_fit_length (f,(long)d*(k+1));
1907
1909 int i= 0;
1910 int lf= 0;
1911 int lg= d*k;
1912 int degfSubLf= degf;
1913 int deggSubLg= degg-lg;
1915 fmpz_t tmp1, tmp2;
1916 while (degf >= lf || lg >= 0)
1917 {
1918 if (degfSubLf >= d)
1919 repLengthBuf1= d;
1920 else if (degfSubLf < 0)
1921 repLengthBuf1= 0;
1922 else
1924
1926
1927 for (ind= 0; ind < repLengthBuf1; ind++)
1928 {
1931 }
1933
1935
1936 if (deggSubLg >= d - 1)
1937 repLengthBuf2= d - 1;
1938 else if (deggSubLg < 0)
1939 repLengthBuf2= 0;
1940 else
1942
1944
1945 for (ind= 0; ind < repLengthBuf2; ind++)
1946 {
1949 }
1950
1953
1955 for (ind= 0; ind < repLengthBuf1; ind++)
1956 {
1959 }
1960 for (ind= repLengthBuf1; ind < d; ind++)
1962 for (ind= 0; ind < repLengthBuf2; ind++)
1963 {
1966 }
1968
1970 i++;
1971
1972
1973 lf= i*d;
1974 degfSubLf= degf - lf;
1975
1976 lg= d*(k-i);
1977 deggSubLg= degg - lg;
1978
1979 if (lg >= 0 && deggSubLg > 0)
1980 {
1981 if (repLengthBuf2 > degfSubLf + 1)
1984 for (ind= 0; ind < tmp; ind++)
1985 {
1988 fmpz_sub (tmp1, tmp1, tmp2);
1990 }
1991 }
1992 if (lg < 0)
1993 {
1997 break;
1998 }
1999 if (degfSubLf >= 0)
2000 {
2001 for (ind= 0; ind < repLengthBuf2; ind++)
2002 {
2005 fmpz_sub (tmp1, tmp1, tmp2);
2007 }
2008 }
2012 }
2013
2016 fmpz_clear (tmp1);
2017 fmpz_clear (tmp2);
2018
2019 return result;
2020}

◆ split()

static CFList split ( const CanonicalForm F,
const int  m,
const Variable x 
)
inlinestatic

Definition at line 3474 of file facMul.cc.

3475{
3476 CanonicalForm A= F;
3477 CanonicalForm buf= 0;
3478 bool swap= false;
3479 if (degree (A, x) <= 0)
3480 return CFList(A);
3481 else if (x.level() != A.level())
3482 {
3483 swap= true;
3484 A= swapvar (A, x, A.mvar());
3485 }
3486
3487 int j= (int) floor ((double) degree (A)/ m);
3488 CFList result;
3489 CFIterator i= A;
3490 for (; j >= 0; j--)
3491 {
3492 while (i.hasTerms() && i.exp() - j*m >= 0)
3493 {
3494 if (swap)
3495 buf += i.coeff()*power (A.mvar(), i.exp() - j*m);
3496 else
3497 buf += i.coeff()*power (x, i.exp() - j*m);
3498 i++;
3499 }
3500 if (swap)
3501 result.append (swapvar (buf, x, F.mvar()));
3502 else
3503 result.append (buf);
3504 buf= 0;
3505 }
3506 return result;
3507}
#define swap(_i, _j)
int level() const
Definition factory.h:143

◆ uniFdivides()

bool uniFdivides ( const CanonicalForm A,
const CanonicalForm B 
)

divisibility test for univariate polys

Returns
uniFdivides returns true if A divides B
Parameters
[in]Aunivariate poly
[in]Bunivariate poly

Definition at line 3764 of file facMul.cc.

3765{
3766 if (B.isZero())
3767 return true;
3768 if (A.isZero())
3769 return false;
3771 return fdivides (A, B);
3772 int p= getCharacteristic();
3773 if (A.inCoeffDomain() || B.inCoeffDomain())
3774 {
3775 if (A.inCoeffDomain())
3776 return true;
3777 else
3778 return false;
3779 }
3780 if (p > 0)
3781 {
3782#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
3783 if (fac_NTL_char != p)
3784 {
3785 fac_NTL_char= p;
3786 zz_p::init (p);
3787 }
3788#endif
3791 {
3792#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
3795
3798
3800
3809 return result;
3810#else
3812 zz_pE::init (NTLMipo);
3815 return divide (NTLB, NTLA);
3816#endif
3817 }
3818#ifdef HAVE_FLINT
3826 return result;
3827#else
3830 return divide (NTLB, NTLA);
3831#endif
3832 }
3833#ifdef HAVE_FLINT
3835 bool isRat= isOn (SW_RATIONAL);
3836 if (!isRat)
3837 On (SW_RATIONAL);
3838 if (!hasFirstAlgVar (A, alpha) && !hasFirstAlgVar (B, alpha))
3839 {
3847 if (!isRat)
3848 Off (SW_RATIONAL);
3849 return result;
3850 }
3851 CanonicalForm Q, R;
3852 newtonDivrem (B, A, Q, R);
3853 if (!isRat)
3854 Off (SW_RATIONAL);
3855 return R.isZero();
3856#else
3857 bool isRat= isOn (SW_RATIONAL);
3858 if (!isRat)
3859 On (SW_RATIONAL);
3860 bool result= fdivides (A, B);
3861 if (!isRat)
3862 Off (SW_RATIONAL);
3863 return result; //maybe NTL?
3864#endif
3865}
int p
Definition cfModGcd.cc:4086
bool fdivides(const CanonicalForm &f, const CanonicalForm &g)
bool fdivides ( const CanonicalForm & f, const CanonicalForm & g )
CanonicalForm divide(const CanonicalForm &ff, const CanonicalForm &f, const CFList &as)

◆ uniReverse()

CanonicalForm uniReverse ( const CanonicalForm F,
int  d,
const Variable x 
)

Definition at line 279 of file facMul.cc.

280{
281 if (d == 0)
282 return F;
283 if (F.inCoeffDomain())
284 return F*power (x,d);
286 CFIterator i= F;
287 while (d - i.exp() < 0)
288 i++;
289
290 for (; i.hasTerms() && (d - i.exp() >= 0); i++)
291 result += i.coeff()*power (x, d - i.exp());
292 return result;
293}