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

181{
182 CanonicalForm A= F;
184
188
191
194 return A;
195}
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 942 of file facMul.cc.

943{
945 return div (F, G);
946 if (F.inCoeffDomain() && G.isUnivariate() && !G.inCoeffDomain())
947 {
948 return 0;
949 }
950 else if (F.inCoeffDomain() && G.inCoeffDomain())
951 {
952 if (b.getp() != 0)
953 {
954 if (!F.inBaseDomain() || !G.inBaseDomain())
955 {
959#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
964
966 convertCF2initFmpz (FLINTp, b.getpk());
967
969
970 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
974 #else
976 #endif
977
980
983
985
990 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
993 #else
995 #endif
996 return b (result);
997#else
998 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1000 ZZ_pE::init (NTLmipo);
1003 ZZ_pE result;
1005 return b (convertNTLZZpX2CF (rep (result), alpha));
1006#endif
1007 }
1008 return b(div (F,G));
1009 }
1010 return div (F, G);
1011 }
1012 else if (F.isUnivariate() && G.inCoeffDomain())
1013 {
1014 if (b.getp() != 0)
1015 {
1016 if (!G.inBaseDomain())
1017 {
1020#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1021 fmpz_t FLINTp;
1025 fq_t FLINTG;
1026
1027 fmpz_init (FLINTp);
1028 convertCF2initFmpz (FLINTp, b.getpk());
1029
1031
1032 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1036 #else
1038 #endif
1039
1042
1045
1047 alpha, fq_con);
1048
1053 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1056 #else
1058 #endif
1059 return b (result);
1060#else
1061 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1063 ZZ_pE::init (NTLmipo);
1066 div (NTLf, NTLf, to_ZZ_pE (NTLg));
1067 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
1068#endif
1069 }
1070 return b(div (F,G));
1071 }
1072 return div (F, G);
1073 }
1074
1075 if (getCharacteristic() == 0)
1076 {
1077
1079 if (!hasFirstAlgVar (F, alpha) && !hasFirstAlgVar (G, alpha))
1080 {
1081#ifdef HAVE_FLINT
1082 if (b.getp() != 0)
1083 {
1086 convertCF2initFmpz (FLINTpk, b.getpk());
1090 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1094 #else
1096 #endif
1098 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1102 #else
1105 #endif
1107 return result;
1108 }
1109 return divFLINTQ (F,G);
1110#else
1111 if (b.getp() != 0)
1112 {
1113 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1118 div (NTLf, NTLf, NTLg);
1119 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
1120 }
1121 return div (F, G);
1122#endif
1123 }
1124 else
1125 {
1126 if (b.getp() != 0)
1127 {
1128#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1129 fmpz_t FLINTp;
1133
1134 fmpz_init (FLINTp);
1135 convertCF2initFmpz (FLINTp, b.getpk());
1136
1138
1139 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1143 #else
1145 #endif
1146
1149
1151
1153 alpha, fq_con);
1154
1159 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
1162 #else
1164 #endif
1165 return b (result);
1166#else
1167 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
1169 ZZ_pE::init (NTLmipo);
1172 div (NTLf, NTLf, NTLg);
1173 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
1174#endif
1175 }
1176#ifdef HAVE_FLINT
1178 newtonDiv (F, G, Q);
1179 return Q;
1180#else
1181 return div (F,G);
1182#endif
1183 }
1184 }
1185
1186 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
1187 ASSERT (F.level() == G.level(), "expected polys of same level");
1188#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
1190 {
1192 zz_p::init (getCharacteristic());
1193 }
1194#endif
1197 if (hasFirstAlgVar (F, alpha) || hasFirstAlgVar (G, alpha))
1198 {
1199#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
1202
1205
1207
1211
1213
1215
1220#else
1222 zz_pE::init (NTLMipo);
1225 div (NTLF, NTLF, NTLG);
1227#endif
1228 }
1229 else
1230 {
1231#ifdef HAVE_FLINT
1239#else
1242 div (NTLF, NTLF, NTLG);
1244#endif
1245 }
1246 return result;
1247}
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:180
void newtonDiv(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q)
Definition facMul.cc:386
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 3722 of file facMul.cc.

3724{
3725 CanonicalForm A= mod (F, MOD);
3726 CanonicalForm B= mod (G, MOD);
3727 Variable x= Variable (1);
3728 int degB= degree (B, x);
3729 if (degB > degree (A, x))
3730 {
3731 Q= 0;
3732 R= A;
3733 return;
3734 }
3735
3736 if (degB <= 0)
3737 {
3738 divrem (A, B, Q, R);
3739 Q= mod (Q, MOD);
3740 R= mod (R, MOD);
3741 return;
3742 }
3743 CFList splitA= split (A, degB, x);
3744
3747 Q= 0;
3749 H= i.getItem()*xToDegB;
3750 i++;
3751 H += i.getItem();
3752 while (i.hasItem())
3753 {
3754 divrem21 (H, B, bufQ, R, MOD);
3755 i++;
3756 if (i.hasItem())
3757 H= R*xToDegB + i.getItem();
3758 Q *= xToDegB;
3759 Q += bufQ;
3760 }
3761 return;
3762}
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:3078
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:3722
static CFList split(const CanonicalForm &F, const int m, const Variable &x)
Definition facMul.cc:3475
static void divrem21(const CanonicalForm &F, const CanonicalForm &G, CanonicalForm &Q, CanonicalForm &R, const CFList &M)
Definition facMul.cc:3515
#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 3655 of file facMul.cc.

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

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

◆ divrem32()

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

Definition at line 3586 of file facMul.cc.

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

◆ kronSubFp()

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

Definition at line 1254 of file facMul.cc.

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

1279{
1280 int degAy= degree (A);
1283 _fq_nmod_vec_zero (result->coeffs, d*(degAy + 1), fq_con);
1284
1286
1288
1289 int k;
1290
1291 for (CFIterator i= A; i.hasTerms(); i++)
1292 {
1293 if (i.coeff().inCoeffDomain())
1294 {
1295 convertFacCF2nmod_poly_t (buf2, i.coeff());
1299 }
1300 else
1302
1303 k= i.exp()*d;
1304 _fq_nmod_vec_set (result->coeffs+k, buf1->coeffs,
1306
1308 }
1309
1311}
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 52 of file facMul.cc.

53{
54 int degAy= degree (A);
55 fmpz_poly_init2 (result, d*(degAy + 1));
58 for (CFIterator i= A; i.hasTerms(); i++)
59 {
60 if (i.coeff().inBaseDomain())
62 else
63 for (j= i.coeff(); j.hasTerms(); j++)
65 j.coeff());
66 }
68}
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 1359 of file facMul.cc.

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

1396{
1397 int degAy= degree (A);
1401
1403
1404 int k, kk, j, bufRepLength;
1405 for (CFIterator i= A; i.hasTerms(); i++)
1406 {
1407 convertFacCF2nmod_poly_t (buf, i.coeff());
1408
1409 k= i.exp()*d;
1410 kk= (degAy - i.exp())*d;
1412 for (j= 0; j < bufRepLength; j++)
1413 {
1418 )
1419 );
1424 )
1425 );
1426 }
1428 }
1431}

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

1437{
1438 int degAy= degree (A);
1441
1443 _fq_nmod_vec_zero (subA1->coeffs, d*(degAy + 2), fq_con);
1444
1446 _fq_nmod_vec_zero (subA2->coeffs, d*(degAy + 2), fq_con);
1447
1449
1451
1452 int k, kk;
1453 for (CFIterator i= A; i.hasTerms(); i++)
1454 {
1455 if (i.coeff().inCoeffDomain())
1456 {
1457 convertFacCF2nmod_poly_t (buf2, i.coeff());
1461 }
1462 else
1464
1465 k= i.exp()*d;
1466 kk= (degAy - i.exp())*d;
1467 _fq_nmod_vec_add (subA1->coeffs+k, subA1->coeffs+k, buf1->coeffs,
1469 _fq_nmod_vec_add (subA2->coeffs+kk, subA2->coeffs+kk, buf1->coeffs,
1471
1473 }
1476}

◆ kronSubReciproQ()

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

Definition at line 1480 of file facMul.cc.

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

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

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

◆ modFLINTQ()

CanonicalForm modFLINTQ ( const CanonicalForm F,
const CanonicalForm G 
)

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

738{
740 return mod (F, G);
741 if (F.inCoeffDomain() && G.isUnivariate() && !G.inCoeffDomain())
742 {
743 if (b.getp() != 0)
744 return b(F);
745 return F;
746 }
747 else if (F.inCoeffDomain() && G.inCoeffDomain())
748 {
749 if (b.getp() != 0)
750 return b(F%G);
751 return mod (F, G);
752 }
753 else if (F.isUnivariate() && G.inCoeffDomain())
754 {
755 if (b.getp() != 0)
756 return b(F%G);
757 return mod (F,G);
758 }
759
760 if (getCharacteristic() == 0)
761 {
763 if (!hasFirstAlgVar (F, alpha) && !hasFirstAlgVar (G, alpha))
764 {
765#ifdef HAVE_FLINT
766 if (b.getp() != 0)
767 {
770 convertCF2initFmpz (FLINTpk, b.getpk());
774 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
778 #else
780 #endif
782 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
786 #else
789 #endif
791 return result;
792 }
793 return modFLINTQ (F, G);
794#else
795 if (b.getp() != 0)
796 {
797 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
802 rem (NTLf, NTLf, NTLg);
803 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
804 }
805 return mod (F, G);
806#endif
807 }
808 else
809 {
810 if (b.getp() != 0)
811 {
812#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
817
819
820 convertCF2initFmpz (FLINTp, b.getpk());
821
823 bool rat=isOn(SW_RATIONAL);
826 mipo *= cd;
827 if (!rat) Off(SW_RATIONAL);
829
830 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
834 #else
836 #endif
837
840
842
844 alpha, fq_con);
845
850 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
853 #else
855 #endif
856
857 return b(result);
858#else
859 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
861 ZZ_pE::init (NTLmipo);
864 rem (NTLf, NTLf, NTLg);
865 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
866#endif
867 }
868#ifdef HAVE_FLINT
870 newtonDivrem (F, G, Q, R);
871 return R;
872#else
873 return mod (F,G);
874#endif
875 }
876 }
877
878 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
879 ASSERT (F.level() == G.level(), "expected polys of same level");
880#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
882 {
884 zz_p::init (getCharacteristic());
885 }
886#endif
890 {
891#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
894
897
899
903
905
907
912#else
914 zz_pE::init (NTLMipo);
917 rem (NTLF, NTLF, NTLG);
919#endif
920 }
921 else
922 {
923#ifdef HAVE_FLINT
931#else
934 rem (NTLF, NTLF, NTLG);
936#endif
937 }
938 return result;
939}
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:352
CanonicalForm modFLINTQ(const CanonicalForm &F, const CanonicalForm &G)
Definition facMul.cc:198
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 139 of file facMul.cc.

140{
141 CanonicalForm A= F;
143
146
147 A *= denA;
148 B *= denB;
153 denA *= denB;
155 A /= denA;
158
159 return A;
160}
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 109 of file facMul.cc.

111{
112 CanonicalForm A= F;
114
117
118 A *= denA;
119 B *= denB;
120 int degAa= degree (A, alpha);
121 int degBa= degree (B, alpha);
122 int d= degAa + 1 + degBa;
123
125 kronSubQa (FLINTA, A, d);
126 kronSubQa (FLINTB, B, d);
127
129
130 denA *= denB;
131 A= reverseSubstQa (FLINTA, d, F.mvar(), alpha, denA);
132
135 return A;
136}
void kronSubQa(fmpz_poly_t result, const CanonicalForm &A, int d)
Definition facMul.cc:52
CanonicalForm reverseSubstQa(const fmpz_poly_t F, int d, const Variable &x, const Variable &alpha, const CanonicalForm &den)
Definition facMul.cc:72

◆ mulFLINTQaTrunc()

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

Definition at line 216 of file facMul.cc.

218{
219 CanonicalForm A= F;
221
224
225 A *= denA;
226 B *= denB;
227
228 int degAa= degree (A, alpha);
229 int degBa= degree (B, alpha);
230 int d= degAa + 1 + degBa;
231
233 kronSubQa (FLINTA, A, d);
234 kronSubQa (FLINTB, B, d);
235
236 int k= d*m;
238
239 denA *= denB;
240 A= reverseSubstQa (FLINTA, d, F.mvar(), alpha, denA);
243 return A;
244}

◆ mulFLINTQTrunc()

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

Definition at line 247 of file facMul.cc.

248{
249 if (F.inCoeffDomain() && G.inCoeffDomain())
250 return F*G;
251 if (F.inCoeffDomain())
252 return mod (F*G, power (G.mvar(), m));
253 if (G.inCoeffDomain())
254 return mod (F*G, power (F.mvar(), m));
257 return mulFLINTQaTrunc (F, G, alpha, m);
258
259 CanonicalForm A= F;
261
264
265 A *= denA;
266 B *= denB;
271 denA *= denB;
273 A /= denA;
276
277 return A;
278}
CanonicalForm mulFLINTQaTrunc(const CanonicalForm &F, const CanonicalForm &G, const Variable &alpha, int m)
Definition facMul.cc:216

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

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

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

◆ mulMod2FLINTFp()

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

Definition at line 2134 of file facMul.cc.

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

◆ mulMod2FLINTFpReci()

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

Definition at line 2096 of file facMul.cc.

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

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

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

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

2169{
2170 int d1= degree (F, 1) + degree (G, 1) + 1;
2171 d1 /= 2;
2172 d1 += 1;
2173
2175 kronSubReciproFq (F1, F2, F, d1, fq_con);
2176
2179
2180 int k= d1*degree (M);
2181 fq_nmod_poly_mullow (F1, F1, G1, (long) k, fq_con);
2182
2183 int degtailF= degree (tailcoeff (F), 1);
2184 int degtailG= degree (tailcoeff (G), 1);
2185 int taildegF= taildegree (F);
2186 int taildegG= taildegree (G);
2187
2188 int b= k + degtailF + degtailG - d1*(2+taildegF + taildegG);
2189
2194
2197
2199
2204 return result;
2205}
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:1787
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:1435

◆ mulMod2FLINTQ()

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

Definition at line 2278 of file facMul.cc.

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

◆ mulMod2FLINTQa()

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

Definition at line 2338 of file facMul.cc.

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

◆ mulMod2FLINTQReci()

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

Definition at line 2241 of file facMul.cc.

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

◆ mulMod2NTLFq()

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

Definition at line 2932 of file facMul.cc.

2934{
2936 CanonicalForm A= F;
2937 CanonicalForm B= G;
2938
2940 {
2941#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
2944
2947
2948 A= mulMod2FLINTFq (A, B, M, alpha, fq_con);
2951#else
2952 int degAx= degree (A, 1);
2953 int degAy= degree (A, 2);
2954 int degBx= degree (B, 1);
2955 int degBy= degree (B, 2);
2956 int d1= degAx + degBx + 1;
2957 int d2= tmax (degAy, degBy);
2959 {
2961 zz_p::init (getCharacteristic());
2962 }
2964 zz_pE::init (NTLMipo);
2965
2966 int degMipo= degree (getMipo (alpha));
2967 if ((d1 > 128/degMipo) && (d2 > 160/degMipo) && (degAy == degBy) &&
2968 (2*degAy > degree (M)))
2969 return mulMod2NTLFqReci (A, B, M, alpha);
2970
2973
2974 int k= d1*degree (M);
2975
2976 MulTrunc (NTLA, NTLA, NTLB, (long) k);
2977
2979#endif
2980 }
2981 else
2982 {
2983#ifdef HAVE_FLINT
2984 A= mulMod2FLINTFp (A, B, M);
2985#else
2986 A= mulMod2NTLFp (A, B, M);
2987#endif
2988 }
2989 return A;
2990}
CanonicalForm mulMod2FLINTFq(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M, const Variable &alpha, const fq_nmod_ctx_t fq_con)
Definition facMul.cc:2208
CanonicalForm mulMod2FLINTFp(const CanonicalForm &F, const CanonicalForm &G, const CanonicalForm &M)
Definition facMul.cc:2134

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

418{
420 return F*G;
421 if (getCharacteristic() == 0)
422 {
424 if ((!F.inCoeffDomain() && !G.inCoeffDomain()) &&
426 {
427 if (b.getp() != 0)
428 {
430 bool is_rat= isOn (SW_RATIONAL);
431 if (!is_rat)
432 On (SW_RATIONAL);
433 mipo *=bCommonDen (mipo);
434 if (!is_rat)
436#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
441
443
444 convertCF2initFmpz (FLINTp, b.getpk());
445
447
448 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
452 #else
454 #endif
455
458
460
462 alpha, fq_con);
463
468 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
471 #else
473 #endif
474 return b (result);
475#endif
476#ifdef HAVE_NTL
477 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
479 ZZ_pE::init (NTLmipo);
482 mul (NTLf, NTLf, NTLg);
483
484 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
485#endif
486 }
487#ifdef HAVE_FLINT
489 return result;
490#else
491 return F*G;
492#endif
493 }
494 else if (!F.inCoeffDomain() && !G.inCoeffDomain())
495 {
496#ifdef HAVE_FLINT
497 if (b.getp() != 0)
498 {
501 convertCF2initFmpz (FLINTpk, b.getpk());
505 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
509 #else
511 #endif
513 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
517 #else
520 #endif
522 return result;
523 }
524 return mulFLINTQ (F, G);
525#endif
526#ifdef HAVE_NTL
527 if (b.getp() != 0)
528 {
529 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
534 mul (NTLf, NTLf, NTLg);
535 return b (convertNTLZZX2CF (to_ZZX (NTLf), F.mvar()));
536 }
537 return F*G;
538#endif
539 }
540 if (b.getp() != 0)
541 {
542 if (!F.inBaseDomain() && !G.inBaseDomain())
543 {
545 {
546#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
550
552 convertCF2initFmpz (FLINTp, b.getpk());
553
555 bool rat=isOn(SW_RATIONAL);
558 mipo *= cd;
559 if (!rat) Off(SW_RATIONAL);
561
562 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
566 #else
568 #endif
569
571
572 if (F.inCoeffDomain() && !G.inCoeffDomain())
573 {
578
580
584 }
585 else if (!F.inCoeffDomain() && G.inCoeffDomain())
586 {
589
592
594
598 }
599 else
600 {
602
605
607
611 }
612
614 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
617 #else
619 #endif
621
622 return b (result);
623#endif
624#ifdef HAVE_NTL
625 ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
627 ZZ_pE::init (NTLmipo);
628
629 if (F.inCoeffDomain() && !G.inCoeffDomain())
630 {
633 mul (NTLg, to_ZZ_pE (NTLf), NTLg);
634 return b (convertNTLZZ_pEX2CF (NTLg, G.mvar(), alpha));
635 }
636 else if (!F.inCoeffDomain() && G.inCoeffDomain())
637 {
640 mul (NTLf, NTLf, to_ZZ_pE (NTLg));
641 return b (convertNTLZZ_pEX2CF (NTLf, F.mvar(), alpha));
642 }
643 else
644 {
649 return b (convertNTLZZpX2CF (rep (result), alpha));
650 }
651#endif
652 }
653 }
654 return b (F*G);
655 }
656 return F*G;
657 }
658 else if (F.inCoeffDomain() || G.inCoeffDomain())
659 return F*G;
660 ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
661 ASSERT (F.level() == G.level(), "expected polys of same level");
662#ifdef HAVE_NTL
663#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
665 {
667 zz_p::init (getCharacteristic());
668 }
669#endif
670#endif
674 {
675 if (!getReduce (alpha))
676 {
677 result= 0;
678 for (CFIterator i= F; i.hasTerms(); i++)
679 result += i.coeff()*G*power (F.mvar(),i.exp());
680 return result;
681 }
682#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
685
688
690
694
696
698
703 return result;
704#elif defined(AHVE_NTL)
706 zz_pE::init (NTLMipo);
709 mul (NTLF, NTLF, NTLG);
711 return result;
712#endif
713 }
714 else
715 {
716#ifdef HAVE_FLINT
724 return result;
725#endif
726#ifdef HAVE_NTL
729 mul (NTLF, NTLF, NTLG);
730 return convertNTLzzpX2CF(NTLF, F.mvar());
731#endif
732 }
733 return F*G;
734}
CanonicalForm mulFLINTQ(const CanonicalForm &F, const CanonicalForm &G)
Definition facMul.cc:139
CanonicalForm mulFLINTQa(const CanonicalForm &F, const CanonicalForm &G, const Variable &alpha)
Definition facMul.cc:109
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 386 of file facMul.cc.

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

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

3321{
3322 ASSERT (getCharacteristic() > 0, "positive characteristic expected");
3323
3324 CanonicalForm A= mod (F, M);
3325 CanonicalForm B= mod (G, M);
3326
3327 Variable x= Variable (1);
3328 int degA= degree (A, x);
3329 int degB= degree (B, x);
3330 int m= degA - degB;
3331 if (m < 0)
3332 return 0;
3333
3334 Variable v;
3337 {
3339 divrem2 (A, B, Q, R, M);
3340 }
3341 else
3342 {
3343 if (hasFirstAlgVar (A, v) || hasFirstAlgVar (B, v))
3344 {
3347 revB= newtonInverse (revB, m + 1, M);
3348 Q= mulMod2 (R, revB, M);
3349 Q= mod (Q, power (x, m + 1));
3350 Q= reverse (Q, m);
3351 }
3352 else
3353 {
3354 Variable y= Variable (2);
3355#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
3358
3361
3363
3364
3368
3370
3372
3377#else
3378 bool zz_pEbak= zz_pE::initialized();
3379 zz_pEBak bak;
3380 if (zz_pEbak)
3381 bak.save();
3383 zz_pEX NTLA, NTLB;
3386 div (NTLA, NTLA, NTLB);
3388 if (zz_pEbak)
3389 bak.restore();
3390#endif
3391 }
3392 }
3393
3394 return Q;
3395}
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:3240
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:3655

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

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

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

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

◆ newtonInverse() [1/2]

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

Definition at line 3264 of file facMul.cc.

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

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

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

3187{
3188 if (L.isEmpty())
3189 return 1;
3190 int l= L.length();
3191 if (l == 1)
3192 return mod (L.getFirst(), M);
3193 else if (l == 2) {
3195 return result;
3196 }
3197 else
3198 {
3199 l /= 2;
3200 CFList tmp1, tmp2;
3201 CFListIterator i= L;
3203 for (int j= 1; j <= l; j++, i++)
3204 tmp1.append (i.getItem());
3205 tmp2= Difference (L, tmp1);
3206 buf1= prodMod (tmp1, M);
3207 buf2= prodMod (tmp2, M);
3209 return result;
3210 }
3211}
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:3186
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 3213 of file facMul.cc.

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

◆ reverse()

CanonicalForm reverse ( const CanonicalForm F,
int  d 
)

Definition at line 3240 of file facMul.cc.

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

◆ reverseSubstFp()

CanonicalForm reverseSubstFp ( const nmod_poly_t  F,
int  d 
)

Definition at line 2060 of file facMul.cc.

2061{
2062 Variable y= Variable (2);
2063 Variable x= Variable (1);
2064
2066
2069 int i= 0;
2070 int degf= nmod_poly_degree(F);
2071 int k= 0;
2072 int degfSubK, repLength, j;
2073 while (degf >= k)
2074 {
2075 degfSubK= degf - k;
2076 if (degfSubK >= d)
2077 repLength= d;
2078 else
2079 repLength= degfSubK + 1;
2080
2082 for (j= 0; j < repLength; j++)
2085
2087 i++;
2088 k= d*i;
2090 }
2091
2092 return result;
2093}

◆ reverseSubstFq()

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

Definition at line 2025 of file facMul.cc.

2027{
2028 Variable y= Variable (2);
2029 Variable x= Variable (1);
2030
2033 int i= 0;
2035 int k= 0;
2036 int degfSubK, repLength;
2037 while (degf >= k)
2038 {
2039 degfSubK= degf - k;
2040 if (degfSubK >= d)
2041 repLength= d;
2042 else
2043 repLength= degfSubK + 1;
2044
2047 _fq_nmod_vec_set (buf->coeffs, F->coeffs+k, repLength, fq_con);
2049
2051 i++;
2052 k= d*i;
2054 }
2055
2056 return result;
2057}

◆ reverseSubstQ()

CanonicalForm reverseSubstQ ( const fmpz_poly_t  F,
int  d 
)

Definition at line 1505 of file facMul.cc.

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

◆ reverseSubstQa() [1/2]

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

Definition at line 72 of file facMul.cc.

74{
76 int i= 0;
77 int degf= fmpz_poly_degree (F);
78 int k= 0;
79 int degfSubK;
80 int repLength;
84 while (degf >= k)
85 {
86 degfSubK= degf - k;
87 if (degfSubK >= d)
88 repLength= d;
89 else
91
94 _fmpz_vec_set (buf->coeffs, F->coeffs + k, repLength);
97
100 i++;
101 k= d*i;
102 }
104 result /= den;
105 return result;
106}
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 1611 of file facMul.cc.

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

◆ reverseSubstReciproFp()

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

Definition at line 1668 of file facMul.cc.

1669{
1670 Variable y= Variable (2);
1671 Variable x= Variable (1);
1672
1673 nmod_poly_t f, g;
1677 nmod_poly_set (f, F);
1678 nmod_poly_set (g, G);
1679 int degf= nmod_poly_degree(f);
1680 int degg= nmod_poly_degree(g);
1681
1682
1684
1685 if (nmod_poly_length (f) < (long) d*(k+1)) //zero padding
1686 nmod_poly_fit_length (f,(long)d*(k+1));
1687
1689 int i= 0;
1690 int lf= 0;
1691 int lg= d*k;
1692 int degfSubLf= degf;
1693 int deggSubLg= degg-lg;
1695 while (degf >= lf || lg >= 0)
1696 {
1697 if (degfSubLf >= d)
1698 repLengthBuf1= d;
1699 else if (degfSubLf < 0)
1700 repLengthBuf1= 0;
1701 else
1704
1705 for (ind= 0; ind < repLengthBuf1; ind++)
1708
1710
1711 if (deggSubLg >= d - 1)
1712 repLengthBuf2= d - 1;
1713 else if (deggSubLg < 0)
1714 repLengthBuf2= 0;
1715 else
1717
1719 for (ind= 0; ind < repLengthBuf2; ind++)
1721
1724
1726 for (ind= 0; ind < repLengthBuf1; ind++)
1728 for (ind= repLengthBuf1; ind < d; ind++)
1730 for (ind= 0; ind < repLengthBuf2; ind++)
1733
1735 i++;
1736
1737
1738 lf= i*d;
1739 degfSubLf= degf - lf;
1740
1741 lg= d*(k-i);
1742 deggSubLg= degg - lg;
1743
1744 if (lg >= 0 && deggSubLg > 0)
1745 {
1746 if (repLengthBuf2 > degfSubLf + 1)
1749 for (ind= 0; ind < tmp; ind++)
1754 )
1755 );
1756 }
1757 if (lg < 0)
1758 {
1762 break;
1763 }
1764 if (degfSubLf >= 0)
1765 {
1766 for (ind= 0; ind < repLengthBuf2; ind++)
1771 )
1772 );
1773 }
1777 }
1778
1781
1782 return result;
1783}
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 1787 of file facMul.cc.

1789{
1790 Variable y= Variable (2);
1791 Variable x= Variable (1);
1792
1796
1798
1803 if (fq_nmod_poly_length (f, fq_con) < (long) d*(k + 1)) //zero padding
1804 fq_nmod_poly_fit_length (f, (long) d*(k + 1), fq_con);
1805
1807 int i= 0;
1808 int lf= 0;
1809 int lg= d*k;
1810 int degfSubLf= degf;
1811 int deggSubLg= degg-lg;
1813 while (degf >= lf || lg >= 0)
1814 {
1815 if (degfSubLf >= d)
1816 repLengthBuf1= d;
1817 else if (degfSubLf < 0)
1818 repLengthBuf1= 0;
1819 else
1823
1824 _fq_nmod_vec_set (buf1->coeffs, f->coeffs + lf, repLengthBuf1, fq_con);
1826
1828
1829 if (deggSubLg >= d - 1)
1830 repLengthBuf2= d - 1;
1831 else if (deggSubLg < 0)
1832 repLengthBuf2= 0;
1833 else
1835
1838 _fq_nmod_vec_set (buf2->coeffs, g->coeffs + lg, repLengthBuf2, fq_con);
1839
1842
1845 _fq_nmod_vec_set (buf3->coeffs, buf1->coeffs, repLengthBuf1, fq_con);
1846 _fq_nmod_vec_set (buf3->coeffs + d, buf2->coeffs, repLengthBuf2, fq_con);
1847
1849
1851 i++;
1852
1853
1854 lf= i*d;
1855 degfSubLf= degf - lf;
1856
1857 lg= d*(k - i);
1858 deggSubLg= degg - lg;
1859
1860 if (lg >= 0 && deggSubLg > 0)
1861 {
1862 if (repLengthBuf2 > degfSubLf + 1)
1865 _fq_nmod_vec_sub (g->coeffs + lg, g->coeffs + lg, buf1-> coeffs,
1866 tmp, fq_con);
1867 }
1868 if (lg < 0)
1869 {
1873 break;
1874 }
1875 if (degfSubLf >= 0)
1876 _fq_nmod_vec_sub (f->coeffs + lf, f->coeffs + lf, buf2->coeffs,
1881 }
1882
1885
1886 return result;
1887}
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 1891 of file facMul.cc.

1892{
1893 Variable y= Variable (2);
1894 Variable x= Variable (1);
1895
1896 fmpz_poly_t f, g;
1897 fmpz_poly_init (f);
1898 fmpz_poly_init (g);
1899 fmpz_poly_set (f, F);
1900 fmpz_poly_set (g, G);
1901 int degf= fmpz_poly_degree(f);
1902 int degg= fmpz_poly_degree(g);
1903
1905
1906 if (fmpz_poly_length (f) < (long) d*(k+1)) //zero padding
1907 fmpz_poly_fit_length (f,(long)d*(k+1));
1908
1910 int i= 0;
1911 int lf= 0;
1912 int lg= d*k;
1913 int degfSubLf= degf;
1914 int deggSubLg= degg-lg;
1916 fmpz_t tmp1, tmp2;
1917 while (degf >= lf || lg >= 0)
1918 {
1919 if (degfSubLf >= d)
1920 repLengthBuf1= d;
1921 else if (degfSubLf < 0)
1922 repLengthBuf1= 0;
1923 else
1925
1927
1928 for (ind= 0; ind < repLengthBuf1; ind++)
1929 {
1932 }
1934
1936
1937 if (deggSubLg >= d - 1)
1938 repLengthBuf2= d - 1;
1939 else if (deggSubLg < 0)
1940 repLengthBuf2= 0;
1941 else
1943
1945
1946 for (ind= 0; ind < repLengthBuf2; ind++)
1947 {
1950 }
1951
1954
1956 for (ind= 0; ind < repLengthBuf1; ind++)
1957 {
1960 }
1961 for (ind= repLengthBuf1; ind < d; ind++)
1963 for (ind= 0; ind < repLengthBuf2; ind++)
1964 {
1967 }
1969
1971 i++;
1972
1973
1974 lf= i*d;
1975 degfSubLf= degf - lf;
1976
1977 lg= d*(k-i);
1978 deggSubLg= degg - lg;
1979
1980 if (lg >= 0 && deggSubLg > 0)
1981 {
1982 if (repLengthBuf2 > degfSubLf + 1)
1985 for (ind= 0; ind < tmp; ind++)
1986 {
1989 fmpz_sub (tmp1, tmp1, tmp2);
1991 }
1992 }
1993 if (lg < 0)
1994 {
1998 break;
1999 }
2000 if (degfSubLf >= 0)
2001 {
2002 for (ind= 0; ind < repLengthBuf2; ind++)
2003 {
2006 fmpz_sub (tmp1, tmp1, tmp2);
2008 }
2009 }
2013 }
2014
2017 fmpz_clear (tmp1);
2018 fmpz_clear (tmp2);
2019
2020 return result;
2021}

◆ split()

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

Definition at line 3475 of file facMul.cc.

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

3766{
3767 if (B.isZero())
3768 return true;
3769 if (A.isZero())
3770 return false;
3772 return fdivides (A, B);
3773 int p= getCharacteristic();
3774 if (A.inCoeffDomain() || B.inCoeffDomain())
3775 {
3776 if (A.inCoeffDomain())
3777 return true;
3778 else
3779 return false;
3780 }
3781 if (p > 0)
3782 {
3783#if (!defined(HAVE_FLINT) || __FLINT_RELEASE < 20400)
3784 if (fac_NTL_char != p)
3785 {
3786 fac_NTL_char= p;
3787 zz_p::init (p);
3788 }
3789#endif
3792 {
3793#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
3796
3799
3801
3810 return result;
3811#else
3813 zz_pE::init (NTLMipo);
3816 return divide (NTLB, NTLA);
3817#endif
3818 }
3819#ifdef HAVE_FLINT
3827 return result;
3828#else
3831 return divide (NTLB, NTLA);
3832#endif
3833 }
3834#ifdef HAVE_FLINT
3836 bool isRat= isOn (SW_RATIONAL);
3837 if (!isRat)
3838 On (SW_RATIONAL);
3839 if (!hasFirstAlgVar (A, alpha) && !hasFirstAlgVar (B, alpha))
3840 {
3848 if (!isRat)
3849 Off (SW_RATIONAL);
3850 return result;
3851 }
3852 CanonicalForm Q, R;
3853 newtonDivrem (B, A, Q, R);
3854 if (!isRat)
3855 Off (SW_RATIONAL);
3856 return R.isZero();
3857#else
3858 bool isRat= isOn (SW_RATIONAL);
3859 if (!isRat)
3860 On (SW_RATIONAL);
3861 bool result= fdivides (A, B);
3862 if (!isRat)
3863 Off (SW_RATIONAL);
3864 return result; //maybe NTL?
3865#endif
3866}
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 280 of file facMul.cc.

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