⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vec_lzz_pe.cpp

📁 数值算法库for Windows
💻 CPP
字号:

#include <NTL/vec_lzz_pE.h>

#include <NTL/new.h>

NTL_START_IMPL

NTL_vector_impl(zz_pE,vec_zz_pE)

NTL_io_vector_impl(zz_pE,vec_zz_pE)

NTL_eq_vector_impl(zz_pE,vec_zz_pE)


void InnerProduct(zz_pE& x, const vec_zz_pE& a, const vec_zz_pE& b)
{
   long n = min(a.length(), b.length());
   long i;
   zz_pX accum, t;

   clear(accum);
   for (i = 0; i < n; i++) {
      mul(t, rep(a[i]), rep(b[i]));
      add(accum, accum, t);
   }

   conv(x, accum);
}

void InnerProduct(zz_pE& x, const vec_zz_pE& a, const vec_zz_pE& b,
                  long offset)
{
   long n = min(a.length(), b.length()+offset);
   long i;
   zz_pX accum, t;

   clear(accum);
   for (i = offset; i < n; i++) {
      mul(t, rep(a[i]), rep(b[i-offset]));
      add(accum, accum, t);
   }

   conv(x, accum);
}

void mul(vec_zz_pE& x, const vec_zz_pE& a, const zz_pE& b_in)
{
   zz_pE b = b_in;
   long n = a.length();
   x.SetLength(n);
   long i;
   for (i = 0; i < n; i++)
      mul(x[i], a[i], b);
}

void mul(vec_zz_pE& x, const vec_zz_pE& a, const zz_p& b_in)
{
   NTL_zz_pRegister(b);
   b = b_in;
   long n = a.length();
   x.SetLength(n);
   long i;
   for (i = 0; i < n; i++)
      mul(x[i], a[i], b);
}

void mul(vec_zz_pE& x, const vec_zz_pE& a, long b_in)
{
   NTL_zz_pRegister(b);
   b = b_in;
   long n = a.length();
   x.SetLength(n);
   long i;
   for (i = 0; i < n; i++)
      mul(x[i], a[i], b);
}


void add(vec_zz_pE& x, const vec_zz_pE& a, const vec_zz_pE& b)
{
   long n = a.length();
   if (b.length() != n) Error("vector add: dimension mismatch");

   x.SetLength(n);
   long i;
   for (i = 0; i < n; i++)
      add(x[i], a[i], b[i]);
}

void sub(vec_zz_pE& x, const vec_zz_pE& a, const vec_zz_pE& b)
{
   long n = a.length();
   if (b.length() != n) Error("vector sub: dimension mismatch");

   x.SetLength(n);
   long i;
   for (i = 0; i < n; i++)
      sub(x[i], a[i], b[i]);
}

void negate(vec_zz_pE& x, const vec_zz_pE& a)
{
   long n = a.length();

   x.SetLength(n);
   long i;
   for (i = 0; i < n; i++)
      negate(x[i], a[i]);
}


void clear(vec_zz_pE& x)
{
   long n = x.length();
   long i;
   for (i = 0; i < n; i++)
      clear(x[i]);
}



long IsZero(const vec_zz_pE& a)
{
   long n = a.length();
   long i;

   for (i = 0; i < n; i++)
      if (!IsZero(a[i]))
         return 0;

   return 1;
}

vec_zz_pE operator+(const vec_zz_pE& a, const vec_zz_pE& b)
{
   vec_zz_pE res;
   add(res, a, b);
   NTL_OPT_RETURN(vec_zz_pE, res);
}

vec_zz_pE operator-(const vec_zz_pE& a, const vec_zz_pE& b)
{
   vec_zz_pE res;
   sub(res, a, b);
   NTL_OPT_RETURN(vec_zz_pE, res);
}


vec_zz_pE operator-(const vec_zz_pE& a)
{
   vec_zz_pE res;
   negate(res, a);
   NTL_OPT_RETURN(vec_zz_pE, res);
}


zz_pE operator*(const vec_zz_pE& a, const vec_zz_pE& b)
{
   zz_pE res;
   InnerProduct(res, a, b);
   return res;
}

void VectorCopy(vec_zz_pE& x, const vec_zz_pE& a, long n)
{
   if (n < 0) Error("VectorCopy: negative length");
   if (n >= (1L << (NTL_BITS_PER_LONG-4))) Error("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]);
}



NTL_END_IMPL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -