本文整理汇总了C++中vec_ZZ::length方法的典型用法代码示例。如果您正苦于以下问题:C++ vec_ZZ::length方法的具体用法?C++ vec_ZZ::length怎么用?C++ vec_ZZ::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec_ZZ
的用法示例。
在下文中一共展示了vec_ZZ::length方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RowTransform
static void RowTransform(vec_ZZ& A, vec_ZZ& B, const ZZ& MU1)
// x = x - y*MU
{
NTL_ZZRegister(T);
NTL_ZZRegister(MU);
long k;
long n = A.length();
long i;
MU = MU1;
if (MU == 1) {
for (i = 1; i <= n; i++)
sub(A(i), A(i), B(i));
return;
}
if (MU == -1) {
for (i = 1; i <= n; i++)
add(A(i), A(i), B(i));
return;
}
if (MU == 0) return;
if (NumTwos(MU) >= NTL_ZZ_NBITS)
k = MakeOdd(MU);
else
k = 0;
if (MU.WideSinglePrecision()) {
long mu1;
conv(mu1, MU);
if (k > 0) {
for (i = 1; i <= n; i++) {
mul(T, B(i), mu1);
LeftShift(T, T, k);
sub(A(i), A(i), T);
}
}
else {
for (i = 1; i <= n; i++) {
MulSubFrom(A(i), B(i), mu1);
}
}
}
else {
for (i = 1; i <= n; i++) {
mul(T, B(i), MU);
if (k > 0) LeftShift(T, T, k);
sub(A(i), A(i), T);
}
}
}
示例2: solve
void solve(ZZ& d_out, vec_ZZ& x_out,
const mat_ZZ& A, const vec_ZZ& b,
long deterministic)
{
long n = A.NumRows();
if (A.NumCols() != n)
Error("solve: nonsquare matrix");
if (b.length() != n)
Error("solve: dimension mismatch");
if (n == 0) {
set(d_out);
x_out.SetLength(0);
return;
}
zz_pBak zbak;
zbak.save();
ZZ_pBak Zbak;
Zbak.save();
vec_ZZ x(INIT_SIZE, n);
ZZ d, d1;
ZZ d_prod, x_prod;
set(d_prod);
set(x_prod);
long d_instable = 1;
long x_instable = 1;
long check = 0;
long gp_cnt = 0;
vec_ZZ y, b1;
long i;
long bound = 2+DetBound(A);
for (i = 0; ; i++) {
if ((check || IsZero(d)) && !d_instable) {
if (NumBits(d_prod) > bound) {
break;
}
else if (!deterministic &&
bound > 1000 && NumBits(d_prod) < 0.25*bound) {
ZZ P;
long plen = 90 + NumBits(max(bound, NumBits(d)));
GenPrime(P, plen, 90 + 2*NumBits(gp_cnt++));
ZZ_p::init(P);
mat_ZZ_p AA;
conv(AA, A);
ZZ_p dd;
determinant(dd, AA);
if (CRT(d, d_prod, rep(dd), P))
d_instable = 1;
else
break;
}
}
zz_p::FFTInit(i);
long p = zz_p::modulus();
mat_zz_p AA;
conv(AA, A);
if (!check) {
vec_zz_p bb, xx;
conv(bb, b);
zz_p dd;
solve(dd, xx, AA, bb);
d_instable = CRT(d, d_prod, rep(dd), p);
if (!IsZero(dd)) {
mul(xx, xx, dd);
x_instable = CRT(x, x_prod, xx);
}
else
x_instable = 1;
if (!d_instable && !x_instable) {
mul(y, x, A);
mul(b1, b, d);
if (y == b1) {
d1 = d;
check = 1;
//.........这里部分代码省略.........
示例3: solve1
void solve1(ZZ& d_out, vec_ZZ& x_out, const mat_ZZ& A, const vec_ZZ& b)
{
long n = A.NumRows();
if (A.NumCols() != n)
LogicError("solve1: nonsquare matrix");
if (b.length() != n)
LogicError("solve1: dimension mismatch");
if (n == 0) {
set(d_out);
x_out.SetLength(0);
return;
}
ZZ num_bound, den_bound;
hadamard(num_bound, den_bound, A, b);
if (den_bound == 0) {
clear(d_out);
return;
}
zz_pBak zbak;
zbak.save();
long i;
long j;
ZZ prod;
prod = 1;
mat_zz_p B;
for (i = 0; ; i++) {
zz_p::FFTInit(i);
mat_zz_p AA, BB;
zz_p dd;
conv(AA, A);
inv(dd, BB, AA);
if (dd != 0) {
transpose(B, BB);
break;
}
mul(prod, prod, zz_p::modulus());
if (prod > den_bound) {
d_out = 0;
return;
}
}
long max_A_len = MaxBits(A);
long use_double_mul1 = 0;
long use_double_mul2 = 0;
long double_limit = 0;
if (max_A_len + NTL_SP_NBITS + NumBits(n) <= NTL_DOUBLE_PRECISION-1)
use_double_mul1 = 1;
if (!use_double_mul1 && max_A_len+NTL_SP_NBITS+2 <= NTL_DOUBLE_PRECISION-1) {
use_double_mul2 = 1;
double_limit = (1L << (NTL_DOUBLE_PRECISION-1-max_A_len-NTL_SP_NBITS));
}
long use_long_mul1 = 0;
long use_long_mul2 = 0;
long long_limit = 0;
if (max_A_len + NTL_SP_NBITS + NumBits(n) <= NTL_BITS_PER_LONG-1)
use_long_mul1 = 1;
if (!use_long_mul1 && max_A_len+NTL_SP_NBITS+2 <= NTL_BITS_PER_LONG-1) {
use_long_mul2 = 1;
long_limit = (1L << (NTL_BITS_PER_LONG-1-max_A_len-NTL_SP_NBITS));
}
if (use_double_mul1 && use_long_mul1)
use_long_mul1 = 0;
else if (use_double_mul1 && use_long_mul2)
use_long_mul2 = 0;
else if (use_double_mul2 && use_long_mul1)
use_double_mul2 = 0;
else if (use_double_mul2 && use_long_mul2) {
if (long_limit > double_limit)
use_double_mul2 = 0;
else
use_long_mul2 = 0;
}
//.........这里部分代码省略.........
示例4: solve1
void solve1(ZZ& d_out, vec_ZZ& x_out, const mat_ZZ& A, const vec_ZZ& b)
{
long n = A.NumRows();
if (A.NumCols() != n)
Error("solve1: nonsquare matrix");
if (b.length() != n)
Error("solve1: dimension mismatch");
if (n == 0) {
set(d_out);
x_out.SetLength(0);
return;
}
ZZ num_bound, den_bound;
hadamard(num_bound, den_bound, A, b);
if (den_bound == 0) {
clear(d_out);
return;
}
zz_pBak zbak;
zbak.save();
long i;
long j;
ZZ prod;
prod = 1;
mat_zz_p B;
for (i = 0; ; i++) {
zz_p::FFTInit(i);
mat_zz_p AA, BB;
zz_p dd;
conv(AA, A);
inv(dd, BB, AA);
if (dd != 0) {
transpose(B, BB);
break;
}
mul(prod, prod, zz_p::modulus());
if (prod > den_bound) {
d_out = 0;
return;
}
}
long max_A_len = MaxBits(A);
long use_double_mul1 = 0;
long use_double_mul2 = 0;
long double_limit = 0;
if (max_A_len + NTL_SP_NBITS + NumBits(n) <= NTL_DOUBLE_PRECISION-1)
use_double_mul1 = 1;
if (!use_double_mul1 && max_A_len+NTL_SP_NBITS+2 <= NTL_DOUBLE_PRECISION-1) {
use_double_mul2 = 1;
double_limit = (1L << (NTL_DOUBLE_PRECISION-1-max_A_len-NTL_SP_NBITS));
}
long use_long_mul1 = 0;
long use_long_mul2 = 0;
long long_limit = 0;
if (max_A_len + NTL_SP_NBITS + NumBits(n) <= NTL_BITS_PER_LONG-1)
use_long_mul1 = 1;
if (!use_long_mul1 && max_A_len+NTL_SP_NBITS+2 <= NTL_BITS_PER_LONG-1) {
use_long_mul2 = 1;
long_limit = (1L << (NTL_BITS_PER_LONG-1-max_A_len-NTL_SP_NBITS));
}
if (use_double_mul1 && use_long_mul1)
use_long_mul1 = 0;
else if (use_double_mul1 && use_long_mul2)
use_long_mul2 = 0;
else if (use_double_mul2 && use_long_mul1)
use_double_mul2 = 0;
else if (use_double_mul2 && use_long_mul2) {
if (long_limit > double_limit)
use_double_mul2 = 0;
else
use_long_mul2 = 0;
}
//.........这里部分代码省略.........
示例5: LatticeSolve
long LatticeSolve(vec_ZZ& x, const mat_ZZ& A, const vec_ZZ& y, long reduce)
{
long n = A.NumRows();
long m = A.NumCols();
if (y.length() != m)
Error("LatticeSolve: dimension mismatch");
if (reduce < 0 || reduce > 2)
Error("LatticeSolve: bad reduce parameter");
if (IsZero(y)) {
x.SetLength(n);
clear(x);
return 1;
}
mat_ZZ A1, U1;
ZZ det2;
long im_rank, ker_rank;
A1 = A;
im_rank = image(det2, A1, U1);
ker_rank = n - im_rank;
mat_ZZ A2, U2;
long new_rank;
long i;
A2.SetDims(im_rank + 1, m);
for (i = 1; i <= im_rank; i++)
A2(i) = A1(ker_rank + i);
A2(im_rank + 1) = y;
new_rank = image(det2, A2, U2);
if (new_rank != im_rank ||
(U2(1)(im_rank+1) != 1 && U2(1)(im_rank+1) != -1))
return 0;
vec_ZZ x1;
x1.SetLength(im_rank);
for (i = 1; i <= im_rank; i++)
x1(i) = U2(1)(i);
if (U2(1)(im_rank+1) == 1)
negate(x1, x1);
vec_ZZ x2, tmp;
x2.SetLength(n);
clear(x2);
tmp.SetLength(n);
for (i = 1; i <= im_rank; i++) {
mul(tmp, U1(ker_rank+i), x1(i));
add(x2, x2, tmp);
}
if (reduce == 0) {
x = x2;
return 1;
}
else if (reduce == 1) {
U1.SetDims(ker_rank+1, n);
U1(ker_rank+1) = x2;
image(det2, U1);
x = U1(ker_rank + 1);
return 1;
}
else if (reduce == 2) {
U1.SetDims(ker_rank, n);
LLL(det2, U1);
U1.SetDims(ker_rank+1, n);
U1(ker_rank+1) = x2;
image(det2, U1);
x = U1(ker_rank + 1);
return 1;
}
return 0;
}