本文整理汇总了C++中vec_ZZ类的典型用法代码示例。如果您正苦于以下问题:C++ vec_ZZ类的具体用法?C++ vec_ZZ怎么用?C++ vec_ZZ使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vec_ZZ类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intVecCRT
bool intVecCRT(vec_ZZ& vp, const ZZ& p, const zzvec& vq, long q)
{
long pInv = InvMod(rem(p,q), q); // p^{-1} mod q
long n = min(vp.length(),vq.length());
long q_over_2 = q/2;
ZZ tmp;
long vqi;
mulmod_precon_t pqInv = PrepMulModPrecon(pInv, q);
for (long i=0; i<n; i++) {
conv(vqi, vq[i]); // convert to single precision
long vq_minus_vp_mod_q = SubMod(vqi, rem(vp[i],q), q);
long delta_times_pInv = MulModPrecon(vq_minus_vp_mod_q, pInv, q, pqInv);
if (delta_times_pInv > q_over_2) delta_times_pInv -= q;
mul(tmp, delta_times_pInv, p); // tmp = [(vq_i-vp_i)*p^{-1}]_q * p
vp[i] += tmp;
}
// other entries (if any) are 0 mod q
for (long i=vq.length(); i<vp.length(); i++) {
long minus_vp_mod_q = NegateMod(rem(vp[i],q), q);
long delta_times_pInv = MulModPrecon(minus_vp_mod_q, pInv, q, pqInv);
if (delta_times_pInv > q_over_2) delta_times_pInv -= q;
mul(tmp, delta_times_pInv, p); // tmp = [(vq_i-vp_i)*p^{-1}]_q * p
vp[i] += tmp;
}
return (vp.length()==vq.length());
}
示例2: mul
void mul(vec_ZZ& x, const vec_ZZ& a, long b)
{
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
mul(x[i], a[i], b);
}
示例3: negate
void negate(vec_ZZ& x, const vec_ZZ& a)
{
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
negate(x[i], a[i]);
}
示例4: sub
void sub(vec_ZZ& x, const vec_ZZ& a, const vec_ZZ& b)
{
long n = a.length();
if (b.length() != n) LogicError("vector sub: dimension mismatch");
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
sub(x[i], a[i], b[i]);
}
示例5: MulSubFrom
static void MulSubFrom(vec_ZZ& c, const vec_ZZ& c2, long x)
// c = c - x*c2
{
long n = c.length();
if (c2.length() != n) Error("MulSubFrom: length mismatch");
long i;
for (i = 1; i <= n; i++)
MulSubFrom(c(i), c2(i), x);
}
示例6: conv
void conv(vec_zz_p& x, const vec_ZZ& a)
{
long i, n;
n = a.length();
x.SetLength(n);
zz_p* xp = x.elts();
const ZZ* ap = a.elts();
for (i = 0; i < n; i++)
conv(xp[i], ap[i]);
}
示例7: conv
NTL_START_IMPL
// NOTE: the signature for this is in lzz_p.h
void conv(vec_zz_p& x, const vec_ZZ& a)
{
long i, n;
n = a.length();
x.SetLength(n);
VectorConv(n, x.elts(), a.elts());
}
示例8: SubDiv
static
void SubDiv(vec_ZZ& e, const vec_ZZ& t, long p)
{
long n = e.length();
if (t.length() != n) Error("SubDiv: dimension mismatch");
ZZ s;
long i;
for (i = 0; i < n; i++) {
sub(s, e[i], t[i]);
div(e[i], s, p);
}
}
示例9: MulSubDiv
static void MulSubDiv(vec_ZZ& c, const vec_ZZ& c1, const vec_ZZ& c2,
const ZZ& x, const ZZ& y, const ZZ& z)
// c = (x*c1 + y*c2)/z
{
long n = c1.length();
if (c2.length() != n) Error("MulSubDiv: length mismatch");
c.SetLength(n);
long i;
for (i = 1; i <= n; i++)
MulSubDiv(c(i), c1(i), c2(i), x, y, z);
}
示例10: clear
void clear(vec_ZZ& x)
{
long n = x.length();
long i;
for (i = 0; i < n; i++)
clear(x[i]);
}
示例11: CRT
long CRT(vec_ZZ& gg, ZZ& a, const vec_zz_p& G)
{
long n = gg.length();
if (G.length() != n) Error("CRT: vector length mismatch");
long p = zz_p::modulus();
ZZ new_a;
mul(new_a, a, p);
long a_inv;
a_inv = rem(a, p);
a_inv = InvMod(a_inv, p);
long p1;
p1 = p >> 1;
ZZ a1;
RightShift(a1, a, 1);
long p_odd = (p & 1);
long modified = 0;
long h;
ZZ g;
long i;
for (i = 0; i < n; i++) {
if (!CRTInRange(gg[i], a)) {
modified = 1;
rem(g, gg[i], a);
if (g > a1) sub(g, g, a);
}
else
g = gg[i];
h = rem(g, p);
h = SubMod(rep(G[i]), h, p);
h = MulMod(h, a_inv, p);
if (h > p1)
h = h - p;
if (h != 0) {
modified = 1;
if (!p_odd && g > 0 && (h == p1))
MulSubFrom(g, a, h);
else
MulAddTo(g, a, h);
}
gg[i] = g;
}
a = new_a;
return modified;
}
示例12: VectorCopy
void VectorCopy(vec_ZZ& x, const vec_ZZ& a, long n)
{
if (n < 0) LogicError("VectorCopy: negative length");
if (NTL_OVERFLOW(n, 1, 0)) ResourceError("overflow in VectorCopy");
long m = min(n, a.length());
x.SetLength(n);
long i;
for (i = 0; i < m; i++)
x[i] = a[i];
for (i = m; i < n; i++)
clear(x[i]);
}
示例13: InnerProduct
NTL_START_IMPL
void InnerProduct(ZZ& xx, const vec_ZZ& a, const vec_ZZ& b)
{
ZZ t1, x;
long n = min(a.length(), b.length());
long i;
clear(x);
for (i = 1; i <= n; i++) {
mul(t1, a(i), b(i));
add(x, x, t1);
}
xx = x;
}
示例14: ExactDiv
static
void ExactDiv(vec_ZZ& x, const ZZ& d)
{
long n = x.length();
long i;
for (i = 0; i < n; i++)
if (!divide(x[i], x[i], d))
Error("inexact division");
}
示例15: IsZero
long IsZero(const vec_ZZ& a)
{
long n = a.length();
long i;
for (i = 0; i < n; i++)
if (!IsZero(a[i]))
return 0;
return 1;
}