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 "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 178 of file facMul.cc.

179{
180 CanonicalForm A= F;
182
186
189
192 return A;
193}
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 940 of file facMul.cc.

941{
943 return div (F, G);
944 if (F.inCoeffDomain() && G.isUnivariate() && !G.inCoeffDomain())
945 {
946 return 0;
947 }
948 else if (F.inCoeffDomain() && G.inCoeffDomain())
949 {
950 if (b.getp() != 0)
951 {
952 if (!F.inBaseDomain() || !G.inBaseDomain())
953 {
957#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
962
964 convertCF2initFmpz (FLINTp, b.getpk());
965
967
968 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
972 #else
974 #endif
975
978
981
983
988 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
991 #else
993 #endif
994 return b (result);
995#else
996 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
998 ZZ_pE::init (NTLmipo);
1001 ZZ_pE result;
1003 return b (convertNTLZZpX2CF (rep (result), alpha));
1004#endif
1005 }
1006 return b(div (F,G));
1007 }
1008 return div (F, G);
1009 }
1010 else if (F.isUnivariate() && G.inCoeffDomain())
1011 {
1012 if (b.getp() != 0)
1013 {
1014 if (!G.inBaseDomain())
1015 {
1018#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1019 fmpz_t FLINTp;
1023 fq_t FLINTG;
1024
1025 fmpz_init (FLINTp);
1026 convertCF2initFmpz (FLINTp, b.getpk());
1027
1029
1030 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1034 #else
1036 #endif
1037
1040
1043
1045 alpha, fq_con);
1046
1051 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1054 #else
1056 #endif
1057 return b (result);
1058#else
1059 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1061 ZZ_pE::init (NTLmipo);
1064 div (NTLf, NTLf, to_ZZ_pE (NTLg));
1065 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
1066#endif
1067 }
1068 return b(div (F,G));
1069 }
1070 return div (F, G);
1071 }
1072
1073 if (getCharacteristic() == 0)
1074 {
1075
1077 if (!hasFirstAlgVar (F, alpha) && !hasFirstAlgVar (G, alpha))
1078 {
1079#ifdef HAVE_FLINT
1080 if (b.getp() != 0)
1081 {
1084 convertCF2initFmpz (FLINTpk, b.getpk());
1088 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1092 #else
1094 #endif
1096 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1100 #else
1103 #endif
1105 return result;
1106 }
1107 return divFLINTQ (F,G);
1108#else
1109 if (b.getp() != 0)
1110 {
1111 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1116 div (NTLf, NTLf, NTLg);
1117 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
1118 }
1119 return div (F, G);
1120#endif
1121 }
1122 else
1123 {
1124 if (b.getp() != 0)
1125 {
1126#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1127 fmpz_t FLINTp;
1131
1132 fmpz_init (FLINTp);
1133 convertCF2initFmpz (FLINTp, b.getpk());
1134
1136
1137 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1141 #else
1143 #endif
1144
1147
1149
1151 alpha, fq_con);
1152
1157 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1160 #else
1162 #endif
1163 return b (result);
1164#else
1165 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1167 ZZ_pE::init (NTLmipo);
1170 div (NTLf, NTLf, NTLg);
1171 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
1172#endif
1173 }
1174#ifdef HAVE_FLINT
1176 newtonDiv (F, G, Q);
1177 return Q;
1178#else
1179 return div (F,G);
1180#endif
1181 }
1182 }
1183
1184 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
1185 ASSERT (F.level() == G.level(), "expected polys of same level");
1186#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
1188 {
1190 zz_p::init (getCharacteristic());
1191 }
1192#endif
1195 if (hasFirstAlgVar (F, alpha) || hasFirstAlgVar (G, alpha))
1196 {
1197#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1200
1203
1205
1209
1211
1213
1218#else
1220 zz_pE::init (NTLMipo);
1223 div (NTLF, NTLF, NTLG);
1225#endif
1226 }
1227 else
1228 {
1229#ifdef HAVE_FLINT
1237#else
1240 div (NTLF, NTLF, NTLG);
1242#endif
1243 }
1244 return result;
1245}
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:4103
#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:178
void newtonDiv(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q)
Definition facMul.cc:384
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 3720 of file facMul.cc.

3722{
3723 CanonicalForm A= mod (F, MOD);
3724 CanonicalForm B= mod (G, MOD);
3725 Variable x= Variable (1);
3726 int degB= degree (B, x);
3727 if (degB > degree (A, x))
3728 {
3729 Q= 0;
3730 R= A;
3731 return;
3732 }
3733
3734 if (degB <= 0)
3735 {
3736 divrem (A, B, Q, R);
3737 Q= mod (Q, MOD);
3738 R= mod (R, MOD);
3739 return;
3740 }
3741 CFList splitA= split (A, degB, x);
3742
3745 Q= 0;
3747 H= i.getItem()*xToDegB;
3748 i++;
3749 H += i.getItem();
3750 while (i.hasItem())
3751 {
3752 divrem21 (H, B, bufQ, R, MOD);
3753 i++;
3754 if (i.hasItem())
3755 H= R*xToDegB + i.getItem();
3756 Q *= xToDegB;
3757 Q += bufQ;
3758 }
3759 return;
3760}
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
int degree(const CanonicalForm &f)
int i
Definition cfEzgcd.cc:132
Variable x
Definition cfModGcd.cc:4082
CanonicalForm H
Definition facAbsFact.cc:60
CanonicalForm mod(const CanonicalForm &F, const CFList &M)
reduce F modulo elements in M.
Definition facMul.cc:3076
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:3720
static CFList split(const CanonicalForm &F, const int m, const Variable &x)
Definition facMul.cc:3473
static void divrem21(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CFList &M)
Definition facMul.cc:3513
#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 3653 of file facMul.cc.

3655{
3656 CanonicalForm A= mod (F, M);
3657 CanonicalForm B= mod (G, M);
3658
3659 if (B.inCoeffDomain())
3660 {
3661 divrem (A, B, Q, R);
3662 return;
3663 }
3664 if (A.inCoeffDomain() && !B.inCoeffDomain())
3665 {
3666 Q= 0;
3667 R= A;
3668 return;
3669 }
3670
3671 if (B.level() < A.level())
3672 {
3673 divrem (A, B, Q, R);
3674 return;
3675 }
3676 if (A.level() > B.level())
3677 {
3678 R= A;
3679 Q= 0;
3680 return;
3681 }
3682 if (B.level() == 1 && B.isUnivariate())
3683 {
3684 divrem (A, B, Q, R);
3685 return;
3686 }
3687
3688 Variable x= Variable (1);
3689 int degB= degree (B, x);
3690 if (degB > degree (A, x))
3691 {
3692 Q= 0;
3693 R= A;
3694 return;
3695 }
3696
3697 CFList splitA= split (A, degB, x);
3698
3701 Q= 0;
3703 H= i.getItem()*xToDegB;
3704 i++;
3705 H += i.getItem();
3706 CFList buf;
3707 while (i.hasItem())
3708 {
3709 buf= CFList (M);
3710 divrem21 (H, B, bufQ, R, buf);
3711 i++;
3712 if (i.hasItem())
3713 H= R*xToDegB + i.getItem();
3714 Q *= xToDegB;
3715 Q += bufQ;
3716 }
3717 return;
3718}
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 3513 of file facMul.cc.

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

◆ divrem32()

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

Definition at line 3584 of file facMul.cc.

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

◆ kronSubFp()

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

Definition at line 1252 of file facMul.cc.

1253{
1254 int degAy= degree (A);
1256 result->length= d*(degAy + 1);
1257 flint_mpn_zero (result->coeffs, d*(degAy+1));
1258
1260
1261 int k;
1262 for (CFIterator i= A; i.hasTerms(); i++)
1263 {
1264 convertFacCF2nmod_poly_t (buf, i.coeff());
1265 k= i.exp()*d;
1266 flint_mpn_copyi (result->coeffs+k, buf->coeffs, nmod_poly_length(buf));
1267
1269 }
1271}
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 1275 of file facMul.cc.

1277{
1278 int degAy= degree (A);
1281 _fq_nmod_vec_zero (result->coeffs, d*(degAy + 1), fq_con);
1282
1284
1286
1287 int k;
1288
1289 for (CFIterator i= A; i.hasTerms(); i++)
1290 {
1291 if (i.coeff().inCoeffDomain())
1292 {
1293 convertFacCF2nmod_poly_t (buf2, i.coeff());
1297 }
1298 else
1300
1301 k= i.exp()*d;
1302 _fq_nmod_vec_set (result->coeffs+k, buf1->coeffs,
1304
1306 }
1307
1309}
CanonicalForm buf2
Definition facFqBivar.cc:75
CanonicalForm buf1
Definition facFqBivar.cc:75

◆ kronSubQa() [1/2]

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

Definition at line 50 of file facMul.cc.

51{
52 int degAy= degree (A);
53 fmpz_poly_init2 (result, d*(degAy + 1));
56 for (CFIterator i= A; i.hasTerms(); i++)
57 {
58 if (i.coeff().inBaseDomain())
60 else
61 for (j= i.coeff(); j.hasTerms(); j++)
63 j.coeff());
64 }
66}
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 1357 of file facMul.cc.

1358{
1359 int degAy= degree (A);
1360 fmpz_poly_init2 (result, d1*(degAy + 1));
1362
1364
1365 int k;
1366 CFIterator j;
1367 for (CFIterator i= A; i.hasTerms(); i++)
1368 {
1369 if (i.coeff().inCoeffDomain())
1370 {
1371 k= d1*i.exp();
1372 convertFacCF2Fmpz_poly_t (buf, i.coeff());
1373 _fmpz_vec_set (result->coeffs + k, buf->coeffs, buf->length);
1375 }
1376 else
1377 {
1378 for (j= i.coeff(); j.hasTerms(); j++)
1379 {
1380 k= d1*i.exp();
1381 k += d2*j.exp();
1382 convertFacCF2Fmpz_poly_t (buf, j.coeff());
1383 _fmpz_vec_set (result->coeffs + k, buf->coeffs, buf->length);
1385 }
1386 }
1387 }
1389}
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 1392 of file facMul.cc.

1394{
1395 int degAy= degree (A);
1399
1401
1402 int k, kk, j, bufRepLength;
1403 for (CFIterator i= A; i.hasTerms(); i++)
1404 {
1405 convertFacCF2nmod_poly_t (buf, i.coeff());
1406
1407 k= i.exp()*d;
1408 kk= (degAy - i.exp())*d;
1410 for (j= 0; j < bufRepLength; j++)
1411 {
1416 )
1417 );
1422 )
1423 );
1424 }
1426 }
1429}

◆ 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 1433 of file facMul.cc.

1435{
1436 int degAy= degree (A);
1439
1441 _fq_nmod_vec_zero (subA1->coeffs, d*(degAy + 2), fq_con);
1442
1444 _fq_nmod_vec_zero (subA2->coeffs, d*(degAy + 2), fq_con);
1445
1447
1449
1450 int k, kk;
1451 for (CFIterator i= A; i.hasTerms(); i++)
1452 {
1453 if (i.coeff().inCoeffDomain())
1454 {
1455 convertFacCF2nmod_poly_t (buf2, i.coeff());
1459 }
1460 else
1462
1463 k= i.exp()*d;
1464 kk= (degAy - i.exp())*d;
1465 _fq_nmod_vec_add (subA1->coeffs+k, subA1->coeffs+k, buf1->coeffs,
1467 _fq_nmod_vec_add (subA2->coeffs+kk, subA2->coeffs+kk, buf1->coeffs,
1469
1471 }
1474}

◆ kronSubReciproQ()

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

Definition at line 1478 of file facMul.cc.

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

◆ 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 3076 of file facMul.cc.

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

◆ modFLINTQ()

CanonicalForm modFLINTQ ( const CanonicalForm F,
const CanonicalForm G 
)

Definition at line 196 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 735 of file facMul.cc.

736{
738 return mod (F, G);
739 if (F.inCoeffDomain() && G.isUnivariate() && !G.inCoeffDomain())
740 {
741 if (b.getp() != 0)
742 return b(F);
743 return F;
744 }
745 else if (F.inCoeffDomain() && G.inCoeffDomain())
746 {
747 if (b.getp() != 0)
748 return b(F%G);
749 return mod (F, G);
750 }
751 else if (F.isUnivariate() && G.inCoeffDomain())
752 {
753 if (b.getp() != 0)
754 return b(F%G);
755 return mod (F,G);
756 }
757
758 if (getCharacteristic() == 0)
759 {
761 if (!hasFirstAlgVar (F, alpha) && !hasFirstAlgVar (G, alpha))
762 {
763#ifdef HAVE_FLINT
764 if (b.getp() != 0)
765 {
768 convertCF2initFmpz (FLINTpk, b.getpk());
772 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
776 #else
778 #endif
780 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
784 #else
787 #endif
789 return result;
790 }
791 return modFLINTQ (F, G);
792#else
793 if (b.getp() != 0)
794 {
795 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
800 rem (NTLf, NTLf, NTLg);
801 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
802 }
803 return mod (F, G);
804#endif
805 }
806 else
807 {
808 if (b.getp() != 0)
809 {
810#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
815
817
818 convertCF2initFmpz (FLINTp, b.getpk());
819
821 bool rat=isOn(SW_RATIONAL);
824 mipo *= cd;
825 if (!rat) Off(SW_RATIONAL);
827
828 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
832 #else
834 #endif
835
838
840
842 alpha, fq_con);
843
848 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
851 #else
853 #endif
854
855 return b(result);
856#else
857 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
859 ZZ_pE::init (NTLmipo);
862 rem (NTLf, NTLf, NTLg);
863 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
864#endif
865 }
866#ifdef HAVE_FLINT
868 newtonDivrem (F, G, Q, R);
869 return R;
870#else
871 return mod (F,G);
872#endif
873 }
874 }
875
876 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
877 ASSERT (F.level() == G.level(), "expected polys of same level");
878#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
880 {
882 zz_p::init (getCharacteristic());
883 }
884#endif
888 {
889#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
892
895
897
901
903
905
910#else
912 zz_pE::init (NTLMipo);
915 rem (NTLF, NTLF, NTLG);
917#endif
918 }
919 else
920 {
921#ifdef HAVE_FLINT
929#else
932 rem (NTLF, NTLF, NTLG);
934#endif
935 }
936 return result;
937}
bool isOn(int sw)
switches
void On(int sw)
switches
void Off(int sw)
switches
CanonicalForm cd(bCommonDen(FF))
Definition cfModGcd.cc:4089
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:350
CanonicalForm modFLINTQ(const CanonicalForm &F, const CanonicalForm &G)
Definition facMul.cc:196
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 137 of file facMul.cc.

138{
139 CanonicalForm A= F;
141
144
145 A *= denA;
146 B *= denB;
151 denA *= denB;
153 A /= denA;
156
157 return A;
158}
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 107 of file facMul.cc.

109{
110 CanonicalForm A= F;
112
115
116 A *= denA;
117 B *= denB;
118 int degAa= degree (A, alpha);
119 int degBa= degree (B, alpha);
120 int d= degAa + 1 + degBa;
121
123 kronSubQa (FLINTA, A, d);
124 kronSubQa (FLINTB, B, d);
125
127
128 denA *= denB;
129 A= reverseSubstQa (FLINTA, d, F.mvar(), alpha, denA);
130
133 return A;
134}
void kronSubQa(fmpz_poly_t result, const CanonicalForm &A, int d)
Definition facMul.cc:50
CanonicalForm reverseSubstQa(const fmpz_poly_t F, int d, const Variable &x, const Variable &alpha, const CanonicalForm &den)
Definition facMul.cc:70

◆ mulFLINTQaTrunc()

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

Definition at line 214 of file facMul.cc.

216{
217 CanonicalForm A= F;
219
222
223 A *= denA;
224 B *= denB;
225
226 int degAa= degree (A, alpha);
227 int degBa= degree (B, alpha);
228 int d= degAa + 1 + degBa;
229
231 kronSubQa (FLINTA, A, d);
232 kronSubQa (FLINTB, B, d);
233
234 int k= d*m;
236
237 denA *= denB;
238 A= reverseSubstQa (FLINTA, d, F.mvar(), alpha, denA);
241 return A;
242}

◆ mulFLINTQTrunc()

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

Definition at line 245 of file facMul.cc.

246{
247 if (F.inCoeffDomain() && G.inCoeffDomain())
248 return F*G;
249 if (F.inCoeffDomain())
250 return mod (F*G, power (G.mvar(), m));
251 if (G.inCoeffDomain())
252 return mod (F*G, power (F.mvar(), m));
255 return mulFLINTQaTrunc (F, G, alpha, m);
256
257 CanonicalForm A= F;
259
262
263 A *= denA;
264 B *= denB;
269 denA *= denB;
271 A /= denA;
274
275 return A;
276}
CanonicalForm mulFLINTQaTrunc(const CanonicalForm &F, const CanonicalForm &G, const Variable &alpha, int m)
Definition facMul.cc:214

◆ 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 3084 of file facMul.cc.

3086{
3087 if (A.isZero() || B.isZero())
3088 return 0;
3089
3090 if (MOD.length() == 1)
3091 return mulMod2 (A, B, MOD.getLast());
3092
3094 CanonicalForm F= mod (A, M);
3095 CanonicalForm G= mod (B, M);
3096 if (F.inCoeffDomain())
3097 return G*F;
3098 if (G.inCoeffDomain())
3099 return F*G;
3100
3101 int sizeF= size (F);
3102 int sizeG= size (G);
3103
3104 if (sizeF / MOD.length() < 100 || sizeG / MOD.length() < 100)
3105 {
3106 if (sizeF < sizeG)
3107 return mod (G*F, MOD);
3108 else
3109 return mod (F*G, MOD);
3110 }
3111
3112 Variable y= M.mvar();
3113 int degF= degree (F, y);
3114 int degG= degree (G, y);
3115
3116 if ((degF <= 1 && F.level() <= M.level()) &&
3117 (degG <= 1 && G.level() <= M.level()))
3118 {
3119 CFList buf= MOD;
3120 buf.removeLast();
3121 if (degF == 1 && degG == 1)
3122 {
3123 CanonicalForm F0= mod (F, y);
3124 CanonicalForm F1= div (F, y);
3125 CanonicalForm G0= mod (G, y);
3126 CanonicalForm G1= div (G, y);
3127 if (degree (M) > 2)
3128 {
3131 CanonicalForm H01= mulMod (F0 + F1, G0 + G1, buf);
3132 return H11*y*y + (H01 - H00 - H11)*y + H00;
3133 }
3134 else //here degree (M) == 2
3135 {
3136 buf.append (y);
3141 return result;
3142 }
3143 }
3144 else if (degF == 1 && degG == 0)
3145 return mulMod (div (F, y), G, buf)*y + mulMod (mod (F, y), G, buf);
3146 else if (degF == 0 && degG == 1)
3147 return mulMod (div (G, y), F, buf)*y + mulMod (mod (G, y), F, buf);
3148 else
3149 return mulMod (F, G, buf);
3150 }
3151 int m= (int) ceil (degree (M)/2.0);
3152 if (degF >= m || degG >= m)
3153 {
3155 CanonicalForm MHi= power (y, degree (M) - m);
3156 CanonicalForm F0= mod (F, MLo);
3157 CanonicalForm F1= div (F, MLo);
3158 CanonicalForm G0= mod (G, MLo);
3159 CanonicalForm G1= div (G, MLo);
3160 CFList buf= MOD;
3161 buf.removeLast();
3162 buf.append (MHi);
3166 return F0G0 + MLo*(F0G1 + F1G0);
3167 }
3168 else
3169 {
3170 m= (tmax(degF, degG)+1)/2;
3172 CanonicalForm F0= mod (F, yToM);
3173 CanonicalForm F1= div (F, yToM);
3178 CanonicalForm H01= mulMod (F0 + F1, G0 + G1, MOD);
3179 return H11*yToM*yToM + (H01 - H11 - H00)*yToM + H00;
3180 }
3181 DEBOUTLN (cerr, "fatal end in mulMod");
3182}
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:2990
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 2990 of file facMul.cc.

2992{
2993 if (A.isZero() || B.isZero())
2994 return 0;
2995
2996 ASSERT (M.isUnivariate(), "M must be univariate");
2997
2998 CanonicalForm F= mod (A, M);
2999 CanonicalForm G= mod (B, M);
3000 if (F.inCoeffDomain())
3001 return G*F;
3002 if (G.inCoeffDomain())
3003 return F*G;
3004
3005 Variable y= M.mvar();
3006 int degF= degree (F, y);
3007 int degG= degree (G, y);
3008
3009 if ((degF < 1 && degG < 1) && (F.isUnivariate() && G.isUnivariate()) &&
3010 (F.level() == G.level()))
3011 {
3013 return mod (result, M);
3014 }
3015 else if (degF <= 1 && degG <= 1)
3016 {
3018 return mod (result, M);
3019 }
3020
3021 int sizeF= size (F);
3022 int sizeG= size (G);
3023
3024 int fallBackToNaive= 50;
3026 {
3027 if (sizeF < sizeG)
3028 return mod (G*F, M);
3029 else
3030 return mod (F*G, M);
3031 }
3032
3033#ifdef HAVE_FLINT
3034 if (getCharacteristic() == 0)
3035 return mulMod2FLINTQa (F, G, M);
3036#endif
3037
3039 (((degF-degG) < 50 && degF > degG) || ((degG-degF) < 50 && degF <= degG)))
3040 return mulMod2NTLFq (F, G, M);
3041
3042 int m= (int) ceil (degree (M)/2.0);
3043 if (degF >= m || degG >= m)
3044 {
3046 CanonicalForm MHi= power (y, degree (M) - m);
3047 CanonicalForm F0= mod (F, MLo);
3048 CanonicalForm F1= div (F, MLo);
3049 CanonicalForm G0= mod (G, MLo);
3050 CanonicalForm G1= div (G, MLo);
3054 return F0G0 + MLo*(F0G1 + F1G0);
3055 }
3056 else
3057 {
3058 m= (int) ceil (tmax (degF, degG)/2.0);
3060 CanonicalForm F0= mod (F, yToM);
3061 CanonicalForm F1= div (F, yToM);
3066 CanonicalForm H01= mulMod2 (F0 + F1, G0 + G1, M);
3067 return H11*yToM*yToM + (H01 - H11 - H00)*yToM + H00;
3068 }
3069 DEBOUTLN (cerr, "fatal end in mulMod2");
3070}
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:415
CanonicalForm mulMod2NTLFq(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2930
CanonicalForm mulMod2FLINTQa(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2336

◆ mulMod2FLINTFp()

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

Definition at line 2132 of file facMul.cc.

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

◆ mulMod2FLINTFpReci()

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

Definition at line 2094 of file facMul.cc.

2096{
2097 int d1= degree (F, 1) + degree (G, 1) + 1;
2098 d1 /= 2;
2099 d1 += 1;
2100
2101 nmod_poly_t F1, F2;
2102 kronSubReciproFp (F1, F2, F, d1);
2103
2104 nmod_poly_t G1, G2;
2105 kronSubReciproFp (G1, G2, G, d1);
2106
2107 int k= d1*degree (M);
2108 nmod_poly_mullow (F1, F1, G1, (long) k);
2109
2110 int degtailF= degree (tailcoeff (F), 1);;
2111 int degtailG= degree (tailcoeff (G), 1);
2112 int taildegF= taildegree (F);
2113 int taildegG= taildegree (G);
2114
2116 + d1*(2+taildegF + taildegG);
2117 nmod_poly_mulhigh (F2, F2, G2, b);
2120
2121
2123
2128 return result;
2129}
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:1392
CanonicalForm reverseSubstReciproFp(const nmod_poly_t F, const nmod_poly_t G, int d, int k)
Definition facMul.cc:1666

◆ 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 2206 of file facMul.cc.

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

◆ 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 2164 of file facMul.cc.

2167{
2168 int d1= degree (F, 1) + degree (G, 1) + 1;
2169 d1 /= 2;
2170 d1 += 1;
2171
2173 kronSubReciproFq (F1, F2, F, d1, fq_con);
2174
2177
2178 int k= d1*degree (M);
2179 fq_nmod_poly_mullow (F1, F1, G1, (long) k, fq_con);
2180
2181 int degtailF= degree (tailcoeff (F), 1);
2182 int degtailG= degree (tailcoeff (G), 1);
2183 int taildegF= taildegree (F);
2184 int taildegG= taildegree (G);
2185
2186 int b= k + degtailF + degtailG - d1*(2+taildegF + taildegG);
2187
2192
2195
2197
2202 return result;
2203}
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:1785
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:1433

◆ mulMod2FLINTQ()

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

Definition at line 2276 of file facMul.cc.

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

◆ mulMod2FLINTQa()

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

Definition at line 2336 of file facMul.cc.

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

◆ mulMod2FLINTQReci()

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

Definition at line 2239 of file facMul.cc.

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

◆ mulMod2NTLFq()

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

Definition at line 2930 of file facMul.cc.

2932{
2934 CanonicalForm A= F;
2935 CanonicalForm B= G;
2936
2938 {
2939#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
2942
2945
2946 A= mulMod2FLINTFq (A, B, M, alpha, fq_con);
2949#else
2950 int degAx= degree (A, 1);
2951 int degAy= degree (A, 2);
2952 int degBx= degree (B, 1);
2953 int degBy= degree (B, 2);
2954 int d1= degAx + degBx + 1;
2955 int d2= tmax (degAy, degBy);
2957 {
2959 zz_p::init (getCharacteristic());
2960 }
2962 zz_pE::init (NTLMipo);
2963
2964 int degMipo= degree (getMipo (alpha));
2965 if ((d1 > 128/degMipo) && (d2 > 160/degMipo) && (degAy == degBy) &&
2966 (2*degAy > degree (M)))
2967 return mulMod2NTLFqReci (A, B, M, alpha);
2968
2971
2972 int k= d1*degree (M);
2973
2974 MulTrunc (NTLA, NTLA, NTLB, (long) k);
2975
2977#endif
2978 }
2979 else
2980 {
2981#ifdef HAVE_FLINT
2982 A= mulMod2FLINTFp (A, B, M);
2983#else
2984 A= mulMod2NTLFp (A, B, M);
2985#endif
2986 }
2987 return A;
2988}
CanonicalForm mulMod2FLINTFq(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M, const Variable &alpha, const fq_nmod_ctx_t fq_con)
Definition facMul.cc:2206
CanonicalForm mulMod2FLINTFp(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2132

◆ 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 415 of file facMul.cc.

416{
418 return F*G;
419 if (getCharacteristic() == 0)
420 {
422 if ((!F.inCoeffDomain() && !G.inCoeffDomain()) &&
424 {
425 if (b.getp() != 0)
426 {
428 bool is_rat= isOn (SW_RATIONAL);
429 if (!is_rat)
430 On (SW_RATIONAL);
431 mipo *=bCommonDen (mipo);
432 if (!is_rat)
434#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
439
441
442 convertCF2initFmpz (FLINTp, b.getpk());
443
445
446 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
450 #else
452 #endif
453
456
458
460 alpha, fq_con);
461
466 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
469 #else
471 #endif
472 return b (result);
473#endif
474#ifdef HAVE_NTL
475 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
477 ZZ_pE::init (NTLmipo);
480 mul (NTLf, NTLf, NTLg);
481
482 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
483#endif
484 }
485#ifdef HAVE_FLINT
487 return result;
488#else
489 return F*G;
490#endif
491 }
492 else if (!F.inCoeffDomain() && !G.inCoeffDomain())
493 {
494#ifdef HAVE_FLINT
495 if (b.getp() != 0)
496 {
499 convertCF2initFmpz (FLINTpk, b.getpk());
503 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
507 #else
509 #endif
511 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
515 #else
518 #endif
520 return result;
521 }
522 return mulFLINTQ (F, G);
523#endif
524#ifdef HAVE_NTL
525 if (b.getp() != 0)
526 {
527 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
532 mul (NTLf, NTLf, NTLg);
533 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
534 }
535 return F*G;
536#endif
537 }
538 if (b.getp() != 0)
539 {
540 if (!F.inBaseDomain() && !G.inBaseDomain())
541 {
543 {
544#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
548
550 convertCF2initFmpz (FLINTp, b.getpk());
551
553 bool rat=isOn(SW_RATIONAL);
556 mipo *= cd;
557 if (!rat) Off(SW_RATIONAL);
559
560 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
564 #else
566 #endif
567
569
570 if (F.inCoeffDomain() && !G.inCoeffDomain())
571 {
576
578
582 }
583 else if (!F.inCoeffDomain() && G.inCoeffDomain())
584 {
587
590
592
596 }
597 else
598 {
600
603
605
609 }
610
612 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
615 #else
617 #endif
619
620 return b (result);
621#endif
622#ifdef HAVE_NTL
623 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
625 ZZ_pE::init (NTLmipo);
626
627 if (F.inCoeffDomain() && !G.inCoeffDomain())
628 {
631 mul (NTLg, to_ZZ_pE (NTLf), NTLg);
632 return b (convertNTLZZ_pEX2CF (NTLg, G.mvar(), alpha));
633 }
634 else if (!F.inCoeffDomain() && G.inCoeffDomain())
635 {
638 mul (NTLf, NTLf, to_ZZ_pE (NTLg));
639 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
640 }
641 else
642 {
647 return b (convertNTLZZpX2CF (rep (result), alpha));
648 }
649#endif
650 }
651 }
652 return b (F*G);
653 }
654 return F*G;
655 }
656 else if (F.inCoeffDomain() || G.inCoeffDomain())
657 return F*G;
658 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
659 ASSERT (F.level() == G.level(), "expected polys of same level");
660#ifdef HAVE_NTL
661#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
663 {
665 zz_p::init (getCharacteristic());
666 }
667#endif
668#endif
672 {
673 if (!getReduce (alpha))
674 {
675 result= 0;
676 for (CFIterator i= F; i.hasTerms(); i++)
677 result += i.coeff()*G*power (F.mvar(),i.exp());
678 return result;
679 }
680#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
683
686
688
692
694
696
701 return result;
702#elif defined(AHVE_NTL)
704 zz_pE::init (NTLMipo);
707 mul (NTLF, NTLF, NTLG);
709 return result;
710#endif
711 }
712 else
713 {
714#ifdef HAVE_FLINT
722 return result;
723#endif
724#ifdef HAVE_NTL
727 mul (NTLF, NTLF, NTLG);
728 return convertNTLzzpX2CF(NTLF, F.mvar());
729#endif
730 }
731 return F*G;
732}
CanonicalForm mulFLINTQ(const CanonicalForm &F, const CanonicalForm &G)
Definition facMul.cc:137
CanonicalForm mulFLINTQa(const CanonicalForm &F, const CanonicalForm &G, const Variable &alpha)
Definition facMul.cc:107
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 384 of file facMul.cc.

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

◆ 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 3317 of file facMul.cc.

3319{
3320 ASSERT (getCharacteristic() > 0, "positive characteristic expected");
3321
3322 CanonicalForm A= mod (F, M);
3323 CanonicalForm B= mod (G, M);
3324
3325 Variable x= Variable (1);
3326 int degA= degree (A, x);
3327 int degB= degree (B, x);
3328 int m= degA - degB;
3329 if (m < 0)
3330 return 0;
3331
3332 Variable v;
3335 {
3337 divrem2 (A, B, Q, R, M);
3338 }
3339 else
3340 {
3341 if (hasFirstAlgVar (A, v) || hasFirstAlgVar (B, v))
3342 {
3345 revB= newtonInverse (revB, m + 1, M);
3346 Q= mulMod2 (R, revB, M);
3347 Q= mod (Q, power (x, m + 1));
3348 Q= reverse (Q, m);
3349 }
3350 else
3351 {
3352 Variable y= Variable (2);
3353#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
3356
3359
3361
3362
3366
3368
3370
3375#else
3376 bool zz_pEbak= zz_pE::initialized();
3377 zz_pEBak bak;
3378 if (zz_pEbak)
3379 bak.save();
3381 zz_pEX NTLA, NTLB;
3384 div (NTLA, NTLA, NTLB);
3386 if (zz_pEbak)
3387 bak.restore();
3388#endif
3389 }
3390 }
3391
3392 return Q;
3393}
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:3238
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:3653

◆ 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 350 of file facMul.cc.

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

◆ 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 3396 of file facMul.cc.

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

◆ newtonInverse() [1/2]

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

Definition at line 3262 of file facMul.cc.

3263{
3264 int l= ilog2(n);
3265
3266 CanonicalForm g= mod (F, M)[0] [0];
3267
3268 ASSERT (!g.isZero(), "expected a unit");
3269
3271
3272 if (!g.isOne())
3273 g = 1/g;
3274 Variable x= Variable (1);
3276 int exp= 0;
3277 if (n & 1)
3278 {
3279 result= g;
3280 exp= 1;
3281 }
3283
3284 for (int i= 1; i <= l; i++)
3285 {
3286 h= mulMod2 (g, mod (F, power (x, (1 << i))), M);
3287 h= mod (h, power (x, (1 << i)) - 1);
3288 h= div (h, power (x, (1 << (i - 1))));
3289 h= mod (h, M);
3290 g -= power (x, (1 << (i - 1)))*
3291 mod (mulMod2 (g, h, M), power (x, (1 << (i - 1))));
3292
3293 if (n & (1 << i))
3294 {
3295 if (exp)
3296 {
3297 h= mulMod2 (result, mod (F, power (x, exp + (1 << i))), M);
3298 h= mod (h, power (x, exp + (1 << i)) - 1);
3299 h= div (h, power (x, exp));
3300 h= mod (h, M);
3301 result -= power(x, exp)*mod (mulMod2 (g, h, M),
3302 power (x, (1 << i)));
3303 exp += (1 << i);
3304 }
3305 else
3306 {
3307 exp= (1 << i);
3308 result= g;
3309 }
3310 }
3311 }
3312
3313 return result;
3314}
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 295 of file facMul.cc.

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

◆ 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 3184 of file facMul.cc.

3185{
3186 if (L.isEmpty())
3187 return 1;
3188 int l= L.length();
3189 if (l == 1)
3190 return mod (L.getFirst(), M);
3191 else if (l == 2) {
3193 return result;
3194 }
3195 else
3196 {
3197 l /= 2;
3198 CFList tmp1, tmp2;
3199 CFListIterator i= L;
3201 for (int j= 1; j <= l; j++, i++)
3202 tmp1.append (i.getItem());
3203 tmp2= Difference (L, tmp1);
3204 buf1= prodMod (tmp1, M);
3205 buf2= prodMod (tmp2, M);
3207 return result;
3208 }
3209}
int isEmpty() const
CFList tmp1
Definition facFqBivar.cc:74
CFList tmp2
Definition facFqBivar.cc:74
CanonicalForm prodMod(const CFList &L, const CanonicalForm &M)
product of all elements in L modulo M via divide-and-conquer.
Definition facMul.cc:3184
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 3211 of file facMul.cc.

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

◆ reverse()

CanonicalForm reverse ( const CanonicalForm F,
int  d 
)

Definition at line 3238 of file facMul.cc.

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

◆ reverseSubstFp()

CanonicalForm reverseSubstFp ( const nmod_poly_t  F,
int  d 
)

Definition at line 2058 of file facMul.cc.

2059{
2060 Variable y= Variable (2);
2061 Variable x= Variable (1);
2062
2064
2067 int i= 0;
2068 int degf= nmod_poly_degree(F);
2069 int k= 0;
2070 int degfSubK, repLength, j;
2071 while (degf >= k)
2072 {
2073 degfSubK= degf - k;
2074 if (degfSubK >= d)
2075 repLength= d;
2076 else
2077 repLength= degfSubK + 1;
2078
2080 for (j= 0; j < repLength; j++)
2083
2085 i++;
2086 k= d*i;
2088 }
2089
2090 return result;
2091}

◆ reverseSubstFq()

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

Definition at line 2023 of file facMul.cc.

2025{
2026 Variable y= Variable (2);
2027 Variable x= Variable (1);
2028
2031 int i= 0;
2033 int k= 0;
2034 int degfSubK, repLength;
2035 while (degf >= k)
2036 {
2037 degfSubK= degf - k;
2038 if (degfSubK >= d)
2039 repLength= d;
2040 else
2041 repLength= degfSubK + 1;
2042
2045 _fq_nmod_vec_set (buf->coeffs, F->coeffs+k, repLength, fq_con);
2047
2049 i++;
2050 k= d*i;
2052 }
2053
2054 return result;
2055}

◆ reverseSubstQ()

CanonicalForm reverseSubstQ ( const fmpz_poly_t  F,
int  d 
)

Definition at line 1503 of file facMul.cc.

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

◆ reverseSubstQa() [1/2]

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

Definition at line 70 of file facMul.cc.

72{
74 int i= 0;
75 int degf= fmpz_poly_degree (F);
76 int k= 0;
77 int degfSubK;
78 int repLength;
82 while (degf >= k)
83 {
84 degfSubK= degf - k;
85 if (degfSubK >= d)
86 repLength= d;
87 else
89
92 _fmpz_vec_set (buf->coeffs, F->coeffs + k, repLength);
95
98 i++;
99 k= d*i;
100 }
102 result /= den;
103 return result;
104}
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 1609 of file facMul.cc.

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

◆ reverseSubstReciproFp()

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

Definition at line 1666 of file facMul.cc.

1667{
1668 Variable y= Variable (2);
1669 Variable x= Variable (1);
1670
1671 nmod_poly_t f, g;
1675 nmod_poly_set (f, F);
1676 nmod_poly_set (g, G);
1677 int degf= nmod_poly_degree(f);
1678 int degg= nmod_poly_degree(g);
1679
1680
1682
1683 if (nmod_poly_length (f) < (long) d*(k+1)) //zero padding
1684 nmod_poly_fit_length (f,(long)d*(k+1));
1685
1687 int i= 0;
1688 int lf= 0;
1689 int lg= d*k;
1690 int degfSubLf= degf;
1691 int deggSubLg= degg-lg;
1693 while (degf >= lf || lg >= 0)
1694 {
1695 if (degfSubLf >= d)
1696 repLengthBuf1= d;
1697 else if (degfSubLf < 0)
1698 repLengthBuf1= 0;
1699 else
1702
1703 for (ind= 0; ind < repLengthBuf1; ind++)
1706
1708
1709 if (deggSubLg >= d - 1)
1710 repLengthBuf2= d - 1;
1711 else if (deggSubLg < 0)
1712 repLengthBuf2= 0;
1713 else
1715
1717 for (ind= 0; ind < repLengthBuf2; ind++)
1719
1722
1724 for (ind= 0; ind < repLengthBuf1; ind++)
1726 for (ind= repLengthBuf1; ind < d; ind++)
1728 for (ind= 0; ind < repLengthBuf2; ind++)
1731
1733 i++;
1734
1735
1736 lf= i*d;
1737 degfSubLf= degf - lf;
1738
1739 lg= d*(k-i);
1740 deggSubLg= degg - lg;
1741
1742 if (lg >= 0 && deggSubLg > 0)
1743 {
1744 if (repLengthBuf2 > degfSubLf + 1)
1747 for (ind= 0; ind < tmp; ind++)
1752 )
1753 );
1754 }
1755 if (lg < 0)
1756 {
1760 break;
1761 }
1762 if (degfSubLf >= 0)
1763 {
1764 for (ind= 0; ind < repLengthBuf2; ind++)
1769 )
1770 );
1771 }
1775 }
1776
1779
1780 return result;
1781}
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 1785 of file facMul.cc.

1787{
1788 Variable y= Variable (2);
1789 Variable x= Variable (1);
1790
1794
1796
1801 if (fq_nmod_poly_length (f, fq_con) < (long) d*(k + 1)) //zero padding
1802 fq_nmod_poly_fit_length (f, (long) d*(k + 1), fq_con);
1803
1805 int i= 0;
1806 int lf= 0;
1807 int lg= d*k;
1808 int degfSubLf= degf;
1809 int deggSubLg= degg-lg;
1811 while (degf >= lf || lg >= 0)
1812 {
1813 if (degfSubLf >= d)
1814 repLengthBuf1= d;
1815 else if (degfSubLf < 0)
1816 repLengthBuf1= 0;
1817 else
1821
1822 _fq_nmod_vec_set (buf1->coeffs, f->coeffs + lf, repLengthBuf1, fq_con);
1824
1826
1827 if (deggSubLg >= d - 1)
1828 repLengthBuf2= d - 1;
1829 else if (deggSubLg < 0)
1830 repLengthBuf2= 0;
1831 else
1833
1836 _fq_nmod_vec_set (buf2->coeffs, g->coeffs + lg, repLengthBuf2, fq_con);
1837
1840
1843 _fq_nmod_vec_set (buf3->coeffs, buf1->coeffs, repLengthBuf1, fq_con);
1844 _fq_nmod_vec_set (buf3->coeffs + d, buf2->coeffs, repLengthBuf2, fq_con);
1845
1847
1849 i++;
1850
1851
1852 lf= i*d;
1853 degfSubLf= degf - lf;
1854
1855 lg= d*(k - i);
1856 deggSubLg= degg - lg;
1857
1858 if (lg >= 0 && deggSubLg > 0)
1859 {
1860 if (repLengthBuf2 > degfSubLf + 1)
1863 _fq_nmod_vec_sub (g->coeffs + lg, g->coeffs + lg, buf1-> coeffs,
1864 tmp, fq_con);
1865 }
1866 if (lg < 0)
1867 {
1871 break;
1872 }
1873 if (degfSubLf >= 0)
1874 _fq_nmod_vec_sub (f->coeffs + lf, f->coeffs + lf, buf2->coeffs,
1879 }
1880
1883
1884 return result;
1885}
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 1889 of file facMul.cc.

1890{
1891 Variable y= Variable (2);
1892 Variable x= Variable (1);
1893
1894 fmpz_poly_t f, g;
1895 fmpz_poly_init (f);
1896 fmpz_poly_init (g);
1897 fmpz_poly_set (f, F);
1898 fmpz_poly_set (g, G);
1899 int degf= fmpz_poly_degree(f);
1900 int degg= fmpz_poly_degree(g);
1901
1903
1904 if (fmpz_poly_length (f) < (long) d*(k+1)) //zero padding
1905 fmpz_poly_fit_length (f,(long)d*(k+1));
1906
1908 int i= 0;
1909 int lf= 0;
1910 int lg= d*k;
1911 int degfSubLf= degf;
1912 int deggSubLg= degg-lg;
1914 fmpz_t tmp1, tmp2;
1915 while (degf >= lf || lg >= 0)
1916 {
1917 if (degfSubLf >= d)
1918 repLengthBuf1= d;
1919 else if (degfSubLf < 0)
1920 repLengthBuf1= 0;
1921 else
1923
1925
1926 for (ind= 0; ind < repLengthBuf1; ind++)
1927 {
1930 }
1932
1934
1935 if (deggSubLg >= d - 1)
1936 repLengthBuf2= d - 1;
1937 else if (deggSubLg < 0)
1938 repLengthBuf2= 0;
1939 else
1941
1943
1944 for (ind= 0; ind < repLengthBuf2; ind++)
1945 {
1948 }
1949
1952
1954 for (ind= 0; ind < repLengthBuf1; ind++)
1955 {
1958 }
1959 for (ind= repLengthBuf1; ind < d; ind++)
1961 for (ind= 0; ind < repLengthBuf2; ind++)
1962 {
1965 }
1967
1969 i++;
1970
1971
1972 lf= i*d;
1973 degfSubLf= degf - lf;
1974
1975 lg= d*(k-i);
1976 deggSubLg= degg - lg;
1977
1978 if (lg >= 0 && deggSubLg > 0)
1979 {
1980 if (repLengthBuf2 > degfSubLf + 1)
1983 for (ind= 0; ind < tmp; ind++)
1984 {
1987 fmpz_sub (tmp1, tmp1, tmp2);
1989 }
1990 }
1991 if (lg < 0)
1992 {
1996 break;
1997 }
1998 if (degfSubLf >= 0)
1999 {
2000 for (ind= 0; ind < repLengthBuf2; ind++)
2001 {
2004 fmpz_sub (tmp1, tmp1, tmp2);
2006 }
2007 }
2011 }
2012
2015 fmpz_clear (tmp1);
2016 fmpz_clear (tmp2);
2017
2018 return result;
2019}

◆ split()

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

Definition at line 3473 of file facMul.cc.

3474{
3475 CanonicalForm A= F;
3476 CanonicalForm buf= 0;
3477 bool swap= false;
3478 if (degree (A, x) <= 0)
3479 return CFList(A);
3480 else if (x.level() != A.level())
3481 {
3482 swap= true;
3483 A= swapvar (A, x, A.mvar());
3484 }
3485
3486 int j= (int) floor ((double) degree (A)/ m);
3487 CFList result;
3488 CFIterator i= A;
3489 for (; j >= 0; j--)
3490 {
3491 while (i.hasTerms() && i.exp() - j*m >= 0)
3492 {
3493 if (swap)
3494 buf += i.coeff()*power (A.mvar(), i.exp() - j*m);
3495 else
3496 buf += i.coeff()*power (x, i.exp() - j*m);
3497 i++;
3498 }
3499 if (swap)
3500 result.append (swapvar (buf, x, F.mvar()));
3501 else
3502 result.append (buf);
3503 buf= 0;
3504 }
3505 return result;
3506}
#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 3763 of file facMul.cc.

3764{
3765 if (B.isZero())
3766 return true;
3767 if (A.isZero())
3768 return false;
3770 return fdivides (A, B);
3771 int p= getCharacteristic();
3772 if (A.inCoeffDomain() || B.inCoeffDomain())
3773 {
3774 if (A.inCoeffDomain())
3775 return true;
3776 else
3777 return false;
3778 }
3779 if (p > 0)
3780 {
3781#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
3782 if (fac_NTL_char != p)
3783 {
3784 fac_NTL_char= p;
3785 zz_p::init (p);
3786 }
3787#endif
3790 {
3791#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
3794
3797
3799
3808 return result;
3809#else
3811 zz_pE::init (NTLMipo);
3814 return divide (NTLB, NTLA);
3815#endif
3816 }
3817#ifdef HAVE_FLINT
3825 return result;
3826#else
3829 return divide (NTLB, NTLA);
3830#endif
3831 }
3832#ifdef HAVE_FLINT
3834 bool isRat= isOn (SW_RATIONAL);
3835 if (!isRat)
3836 On (SW_RATIONAL);
3837 if (!hasFirstAlgVar (A, alpha) && !hasFirstAlgVar (B, alpha))
3838 {
3846 if (!isRat)
3847 Off (SW_RATIONAL);
3848 return result;
3849 }
3850 CanonicalForm Q, R;
3851 newtonDivrem (B, A, Q, R);
3852 if (!isRat)
3853 Off (SW_RATIONAL);
3854 return R.isZero();
3855#else
3856 bool isRat= isOn (SW_RATIONAL);
3857 if (!isRat)
3858 On (SW_RATIONAL);
3859 bool result= fdivides (A, B);
3860 if (!isRat)
3861 Off (SW_RATIONAL);
3862 return result; //maybe NTL?
3863#endif
3864}
int p
Definition cfModGcd.cc:4078
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 278 of file facMul.cc.

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