本文整理汇总了C++中LeadCoeff函数的典型用法代码示例。如果您正苦于以下问题:C++ LeadCoeff函数的具体用法?C++ LeadCoeff怎么用?C++ LeadCoeff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LeadCoeff函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: MakeMonic
void MakeMonic(zz_pX& x)
{
if (IsZero(x))
return;
if (IsOne(LeadCoeff(x)))
return;
zz_p t;
inv(t, LeadCoeff(x));
mul(x, x, t);
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:13,代码来源:lzz_pX1.c
示例2: CanZass
void CanZass(vec_pair_ZZ_pEX_long& factors, const ZZ_pEX& f, long verbose)
{
if (!IsOne(LeadCoeff(f)))
LogicError("CanZass: bad args");
double t;
vec_pair_ZZ_pEX_long sfd;
vec_ZZ_pEX x;
if (verbose) { cerr << "square-free decomposition..."; t = GetTime(); }
SquareFreeDecomp(sfd, f);
if (verbose) cerr << (GetTime()-t) << "\n";
factors.SetLength(0);
long i, j;
for (i = 0; i < sfd.length(); i++) {
if (verbose) {
cerr << "factoring multiplicity " << sfd[i].b
<< ", deg = " << deg(sfd[i].a) << "\n";
}
SFCanZass(x, sfd[i].a, verbose);
for (j = 0; j < x.length(); j++)
append(factors, cons(x[j], sfd[i].b));
}
}
开发者ID:Brainloop-Security,项目名称:secret-sharing,代码行数:30,代码来源:ZZ_pEXFactoring.cpp
示例3: FindRoot
void FindRoot(GF2E& root, const GF2EX& ff)
// finds a root of ff.
// assumes that ff is monic and splits into distinct linear factors
{
GF2EXModulus F;
GF2EX h, h1, f;
GF2E r;
f = ff;
if (!IsOne(LeadCoeff(f)))
Error("FindRoot: bad args");
if (deg(f) == 0)
Error("FindRoot: bad args");
while (deg(f) > 1) {
build(F, f);
random(r);
clear(h);
SetCoeff(h, 1, r);
TraceMap(h, h, F);
GCD(h, h, f);
if (deg(h) > 0 && deg(h) < deg(f)) {
if (deg(h) > deg(f)/2)
div(f, f, h);
else
f = h;
}
}
root = ConstTerm(f);
}
开发者ID:shayne-fletcher,项目名称:cppf,代码行数:35,代码来源:GF2EXFactoring.cpp
示例4: SquareFreeDecomp
NTL_START_IMPL
void SquareFreeDecomp(vec_pair_ZZ_pX_long& u, const ZZ_pX& ff)
{
ZZ_pX f = ff;
if (!IsOne(LeadCoeff(f)))
Error("SquareFreeDecomp: bad args");
ZZ_pX r, t, v, tmp1;
long m, j, finished, done;
u.SetLength(0);
if (deg(f) == 0)
return;
m = 1;
finished = 0;
do {
j = 1;
diff(tmp1, f);
GCD(r, f, tmp1);
div(t, f, r);
if (deg(t) > 0) {
done = 0;
do {
GCD(v, r, t);
div(tmp1, t, v);
if (deg(tmp1) > 0) append(u, cons(tmp1, j*m));
if (deg(v) > 0) {
div(r, r, v);
t = v;
j++;
}
else
done = 1;
} while (!done);
if (deg(r) == 0) finished = 1;
}
if (!finished) {
/* r is a p-th power */
long p, k, d;
conv(p, ZZ_p::modulus());
d = deg(r)/p;
f.rep.SetLength(d+1);
for (k = 0; k <= d; k++)
f.rep[k] = r.rep[k*p];
m = m*p;
}
} while (!finished);
}
开发者ID:JamesHirschorn,项目名称:QFCL,代码行数:59,代码来源:ZZ_pXFactoring.cpp
示例5: XGCD
void XGCD(zz_pX& d, zz_pX& s, zz_pX& t, const zz_pX& a, const zz_pX& b)
{
zz_p w;
if (IsZero(a) && IsZero(b)) {
clear(d);
set(s);
clear(t);
return;
}
zz_pX U, V, Q;
U = a;
V = b;
long flag = 0;
if (deg(U) == deg(V)) {
DivRem(Q, U, U, V);
swap(U, V);
flag = 1;
}
else if (deg(U) < deg(V)) {
swap(U, V);
flag = 2;
}
zz_pXMatrix M;
XHalfGCD(M, U, V, deg(U)+1);
d = U;
if (flag == 0) {
s = M(0,0);
t = M(0,1);
}
else if (flag == 1) {
s = M(0,1);
mul(t, Q, M(0,1));
sub(t, M(0,0), t);
}
else { /* flag == 2 */
s = M(0,1);
t = M(0,0);
}
// normalize
inv(w, LeadCoeff(d));
mul(d, d, w);
mul(s, s, w);
mul(t, t, w);
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:55,代码来源:lzz_pX1.c
示例6: FindRoots
void FindRoots(vec_GF2E& x, const GF2EX& ff)
{
GF2EX f = ff;
if (!IsOne(LeadCoeff(f)))
Error("FindRoots: bad args");
x.SetMaxLength(deg(f));
x.SetLength(0);
RecFindRoots(x, f);
}
开发者ID:shayne-fletcher,项目名称:cppf,代码行数:11,代码来源:GF2EXFactoring.cpp
示例7: FindRoots
void FindRoots(vec_ZZ_pE& x, const ZZ_pEX& ff)
{
ZZ_pEX f = ff;
if (!IsOne(LeadCoeff(f)))
LogicError("FindRoots: bad args");
x.SetMaxLength(deg(f));
x.SetLength(0);
RecFindRoots(x, f);
}
开发者ID:Brainloop-Security,项目名称:secret-sharing,代码行数:11,代码来源:ZZ_pEXFactoring.cpp
示例8: SquareFreeDecomp
void SquareFreeDecomp(vec_pair_GF2EX_long& u, const GF2EX& ff)
{
GF2EX f = ff;
if (!IsOne(LeadCoeff(f)))
Error("SquareFreeDecomp: bad args");
GF2EX r, t, v, tmp1;
long m, j, finished, done;
u.SetLength(0);
if (deg(f) == 0)
return;
m = 1;
finished = 0;
do {
j = 1;
diff(tmp1, f);
GCD(r, f, tmp1);
div(t, f, r);
if (deg(t) > 0) {
done = 0;
do {
GCD(v, r, t);
div(tmp1, t, v);
if (deg(tmp1) > 0) append(u, cons(tmp1, j*m));
if (deg(v) > 0) {
div(r, r, v);
t = v;
j++;
}
else
done = 1;
} while (!done);
if (deg(r) == 0) finished = 1;
}
if (!finished) {
/* r is a square */
long k, d;
d = deg(r)/2;
f.rep.SetLength(d+1);
for (k = 0; k <= d; k++)
IterSqr(f.rep[k], r.rep[k*2], GF2E::degree()-1);
m = m*2;
}
} while (!finished);
}
开发者ID:shayne-fletcher,项目名称:cppf,代码行数:53,代码来源:GF2EXFactoring.cpp
示例9: ModComp
void ModComp(ZZX& res, const ZZX& g, const ZZX& h, const ZZX& f)
{
assert(LeadCoeff(f) == 1);
ZZX hh = h % f;
ZZX r = to_ZZX(0);
for (long i = deg(g); i >= 0; i--)
r = (r*hh + coeff(g, i)) % f;
res = r;
}
开发者ID:deepinit-arek,项目名称:HElib,代码行数:12,代码来源:NumbTh.cpp
示例10: NormMod
void NormMod(zz_p& x, const zz_pX& a, const zz_pX& f)
{
if (deg(f) <= 0 || deg(a) >= deg(f))
Error("norm: bad args");
if (IsZero(a)) {
clear(x);
return;
}
zz_p t;
resultant(t, f, a);
if (!IsOne(LeadCoeff(f))) {
zz_p t1;
power(t1, LeadCoeff(f), deg(a));
inv(t1, t1);
mul(t, t, t1);
}
x = t;
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:21,代码来源:lzz_pX1.c
示例11: PlainResultant
void PlainResultant(ZZ_p& rres, const ZZ_pX& a, const ZZ_pX& b)
{
ZZ_p res;
if (IsZero(a) || IsZero(b))
clear(res);
else if (deg(a) == 0 && deg(b) == 0)
set(res);
else {
long d0, d1, d2;
ZZ_p lc;
set(res);
long n = max(deg(a),deg(b)) + 1;
ZZ_pX u(INIT_SIZE, n), v(INIT_SIZE, n);
ZZVec tmp(n, ZZ_p::ExtendedModulusSize());
u = a;
v = b;
for (;;) {
d0 = deg(u);
d1 = deg(v);
lc = LeadCoeff(v);
PlainRem(u, u, v, tmp);
swap(u, v);
d2 = deg(v);
if (d2 >= 0) {
power(lc, lc, d0-d2);
mul(res, res, lc);
if (d0 & d1 & 1) negate(res, res);
}
else {
if (d1 == 0) {
power(lc, lc, d0);
mul(res, res, lc);
}
else
clear(res);
break;
}
}
}
rres = res;
}
开发者ID:Brainloop-Security,项目名称:secret-sharing,代码行数:49,代码来源:ZZ_pX1.cpp
示例12: to_ulong
unsigned long to_ulong(const zz_pX& x)
{
unsigned long u;
int i;
static zz_p c;
c = LeadCoeff(x);
static long p;
p = c.modulus();
for (u = 0, i = deg(x); i >= 0; i--) {
GetCoeff(c, x,i);
u = u * p + rep(c);
}
return u;
}
开发者ID:Alwnikrotikz,项目名称:purplesage,代码行数:16,代码来源:helper.cpp
示例13: ResHalfGCD
void ResHalfGCD(zz_pX& U, zz_pX& V, vec_zz_p& cvec, vec_long& dvec)
{
long d_red = (deg(U)+1)/2;
if (IsZero(V) || deg(V) <= deg(U) - d_red) {
return;
}
long du = deg(U);
long d1 = (d_red + 1)/2;
if (d1 < 1) d1 = 1;
if (d1 >= d_red) d1 = d_red - 1;
zz_pXMatrix M1;
ResHalfGCD(M1, U, V, d1, cvec, dvec);
mul(U, V, M1);
long d2 = deg(V) - du + d_red;
if (IsZero(V) || d2 <= 0) {
return;
}
M1(0,0).kill();
M1(0,1).kill();
M1(1,0).kill();
M1(1,1).kill();
zz_pX Q;
append(cvec, LeadCoeff(V));
append(dvec, dvec[dvec.length()-1]-deg(U)+deg(V));
DivRem(Q, U, U, V);
swap(U, V);
ResHalfGCD(M1, U, V, d2, cvec, dvec);
mul(U, V, M1);
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:43,代码来源:lzz_pX1.c
示例14: EDF
void EDF(vec_ZZ_pEX& factors, const ZZ_pEX& ff, const ZZ_pEX& bb,
long d, long verbose)
{
ZZ_pEX f = ff;
ZZ_pEX b = bb;
if (!IsOne(LeadCoeff(f)))
LogicError("EDF: bad args");
long n = deg(f);
long r = n/d;
if (r == 0) {
factors.SetLength(0);
return;
}
if (r == 1) {
factors.SetLength(1);
factors[0] = f;
return;
}
if (d == 1) {
RootEDF(factors, f, verbose);
return;
}
double t;
if (verbose) {
cerr << "computing EDF(" << d << "," << r << ")...";
t = GetTime();
}
factors.SetLength(0);
RecEDF(factors, f, b, d, verbose);
if (verbose) cerr << (GetTime()-t) << "\n";
}
开发者ID:Brainloop-Security,项目名称:secret-sharing,代码行数:42,代码来源:ZZ_pEXFactoring.cpp
示例15: GCDMinPolySeq
void GCDMinPolySeq(zz_pX& h, const vec_zz_p& x, long m)
{
long i;
zz_pX a, b;
zz_pXMatrix M;
zz_p t;
a.rep.SetLength(2*m);
for (i = 0; i < 2*m; i++) a.rep[i] = x[2*m-1-i];
a.normalize();
SetCoeff(b, 2*m);
HalfGCD(M, b, a, m+1);
/* make monic */
inv(t, LeadCoeff(M(1,1)));
mul(h, M(1,1), t);
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:20,代码来源:lzz_pX1.c
示例16: FindRoot
void FindRoot(ZZ_pE& root, const ZZ_pEX& ff)
// finds a root of ff.
// assumes that ff is monic and splits into distinct linear factors
{
ZZ_pEXModulus F;
ZZ_pEX h, h1, f;
ZZ_pEX r;
f = ff;
if (!IsOne(LeadCoeff(f)))
LogicError("FindRoot: bad args");
if (deg(f) == 0)
LogicError("FindRoot: bad args");
while (deg(f) > 1) {
build(F, f);
random(r, deg(F));
if (IsOdd(ZZ_pE::cardinality())) {
PowerMod(h, r, RightShift(ZZ_pE::cardinality(), 1), F);
sub(h, h, 1);
}
else {
AbsTraceMap(h, r, F);
}
GCD(h, h, f);
if (deg(h) > 0 && deg(h) < deg(f)) {
if (deg(h) > deg(f)/2)
div(f, f, h);
else
f = h;
}
}
negate(root, ConstTerm(f));
}
开发者ID:Brainloop-Security,项目名称:secret-sharing,代码行数:39,代码来源:ZZ_pEXFactoring.cpp
示例17: FindRoot
void FindRoot(ZZ_p& root, const ZZ_pX& ff)
// finds a root of ff.
// assumes that ff is monic and splits into distinct linear factors
{
ZZ_pXModulus F;
ZZ_pX h, h1, f;
ZZ_p r;
ZZ p1;
f = ff;
if (!IsOne(LeadCoeff(f)))
Error("FindRoot: bad args");
if (deg(f) == 0)
Error("FindRoot: bad args");
RightShift(p1, ZZ_p::modulus(), 1);
h1 = 1;
while (deg(f) > 1) {
build(F, f);
random(r);
PowerXPlusAMod(h, r, p1, F);
sub(h, h, h1);
GCD(h, h, f);
if (deg(h) > 0 && deg(h) < deg(f)) {
if (deg(h) > deg(f)/2)
div(f, f, h);
else
f = h;
}
}
negate(root, ConstTerm(f));
}
开发者ID:JamesHirschorn,项目名称:QFCL,代码行数:37,代码来源:ZZ_pXFactoring.cpp
示例18: ResIterHalfGCD
void ResIterHalfGCD(ZZ_pXMatrix& M_out, ZZ_pX& U, ZZ_pX& V, long d_red,
vec_ZZ_p& cvec, vec_long& dvec)
{
M_out(0,0).SetMaxLength(d_red);
M_out(0,1).SetMaxLength(d_red);
M_out(1,0).SetMaxLength(d_red);
M_out(1,1).SetMaxLength(d_red);
set(M_out(0,0)); clear(M_out(0,1));
clear(M_out(1,0)); set(M_out(1,1));
long goal = deg(U) - d_red;
if (deg(V) <= goal)
return;
ZZVec tmp(deg(U)+1, ZZ_p::ExtendedModulusSize());
ZZ_pX Q, t(INIT_SIZE, d_red);
while (deg(V) > goal) {
append(cvec, LeadCoeff(V));
append(dvec, dvec[dvec.length()-1]-deg(U)+deg(V));
PlainDivRem(Q, U, U, V, tmp);
swap(U, V);
mul(t, Q, M_out(1,0));
sub(t, M_out(0,0), t);
M_out(0,0) = M_out(1,0);
M_out(1,0) = t;
mul(t, Q, M_out(1,1));
sub(t, M_out(0,1), t);
M_out(0,1) = M_out(1,1);
M_out(1,1) = t;
}
}
开发者ID:Brainloop-Security,项目名称:secret-sharing,代码行数:37,代码来源:ZZ_pX1.cpp
示例19: deg
void divisor::update() {
bool_t OK = TRUE;
// Check curve's validity
OK = OK && s_hcurve.is_valid_curve();
/* Check if [u, v] belongs to Jacobian of genus 2 curve
It is so if
(1) u is monic
(2) deg(v) < deg(u) <= genus = 2
(3) u | v^2 + v*h - f
*/
OK = OK && IsOne( LeadCoeff(upoly) ); // (1)
OK = OK && ( deg(upoly) <= genus ) && ( deg(vpoly) < deg(upoly) ); // (2)
OK = OK && IsZero(( vpoly*(vpoly + s_hcurve.get_h())
- s_hcurve.get_f() ) % upoly ); // (3)
// Set is_valid flag
is_valid = OK;
}
开发者ID:syncom,项目名称:libg2hec,代码行数:24,代码来源:divisor.C
示例20: SFBerlekamp
void SFBerlekamp(vec_ZZ_pX& factors, const ZZ_pX& ff, long verbose)
{
ZZ_pX f = ff;
if (!IsOne(LeadCoeff(f)))
Error("SFBerlekamp: bad args");
if (deg(f) == 0) {
factors.SetLength(0);
return;
}
if (deg(f) == 1) {
factors.SetLength(1);
factors[0] = f;
return;
}
double t;
const ZZ& p = ZZ_p::modulus();
long n = deg(f);
ZZ_pXModulus F;
build(F, f);
ZZ_pX g, h;
if (verbose) { cerr << "computing X^p..."; t = GetTime(); }
PowerXMod(g, p, F);
if (verbose) { cerr << (GetTime()-t) << "\n"; }
vec_long D;
long r;
vec_ZZVec M;
if (verbose) { cerr << "building matrix..."; t = GetTime(); }
BuildMatrix(M, n, g, F, verbose);
if (verbose) { cerr << (GetTime()-t) << "\n"; }
if (verbose) { cerr << "diagonalizing..."; t = GetTime(); }
NullSpace(r, D, M, verbose);
if (verbose) { cerr << (GetTime()-t) << "\n"; }
if (verbose) cerr << "number of factors = " << r << "\n";
if (r == 1) {
factors.SetLength(1);
factors[0] = f;
return;
}
if (verbose) { cerr << "factor extraction..."; t = GetTime(); }
vec_ZZ_p roots;
RandomBasisElt(g, D, M);
MinPolyMod(h, g, F, r);
if (deg(h) == r) M.kill();
FindRoots(roots, h);
FindFactors(factors, f, g, roots);
ZZ_pX g1;
vec_ZZ_pX S, S1;
long i;
while (factors.length() < r) {
if (verbose) cerr << "+";
RandomBasisElt(g, D, M);
S.kill();
for (i = 0; i < factors.length(); i++) {
const ZZ_pX& f = factors[i];
if (deg(f) == 1) {
append(S, f);
continue;
}
build(F, f);
rem(g1, g, F);
if (deg(g1) <= 0) {
append(S, f);
continue;
}
MinPolyMod(h, g1, F, min(deg(f), r-factors.length()+1));
FindRoots(roots, h);
S1.kill();
FindFactors(S1, f, g1, roots);
append(S, S1);
}
swap(factors, S);
}
if (verbose) { cerr << (GetTime()-t) << "\n"; }
if (verbose) {
cerr << "degrees:";
long i;
//.........这里部分代码省略.........
开发者ID:JamesHirschorn,项目名称:QFCL,代码行数:101,代码来源:ZZ_pXFactoring.cpp
注:本文中的LeadCoeff函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论