本文整理汇总了C++中ring_elem类的典型用法代码示例。如果您正苦于以下问题:C++ ring_elem类的具体用法?C++ ring_elem怎么用?C++ ring_elem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ring_elem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Lovasz
bool LLLoperations::Lovasz(MutableMatrix *lambda,
int k,
ring_elem alphaTop,
ring_elem alphaBottom)
{
// Test:alphaBottom * (D#(k-2) * D#k + lambda#(k,k-1)^2) <
// alphaTop * D#(k-1)^2
ring_elem D2,D1,D,L;
mpz_t a,b;
lambda->get_entry(k-1,k-1,D1);
lambda->get_entry(k,k,D);
bool Lnotzero = lambda->get_entry(k-1,k,L);
if (k == 1)
mpz_init_set(a,D.get_mpz());
else
{
mpz_init(a);
lambda->get_entry(k-2,k-2,D2);
mpz_mul(a,D2.get_mpz(),D.get_mpz());
}
mpz_init(b);
if (Lnotzero)
{
mpz_mul(b,L.get_mpz(),L.get_mpz());
mpz_add(a,a,b);
}
mpz_mul(a,a,alphaBottom.get_mpz()); // This is the LHS.
mpz_mul(b,D1.get_mpz(),D1.get_mpz());
mpz_mul(b,alphaTop.get_mpz(),b); // RHS
int cmp = mpz_cmp(a,b);
mpz_clear(a);
mpz_clear(b);
return (cmp < 0);
}
开发者ID:ChristineJost,项目名称:M2,代码行数:35,代码来源:LLL.cpp
示例2: syzygy
void RingZZ::syzygy(const ring_elem a, const ring_elem b,
ring_elem &x, ring_elem &y) const
{
// First check the special cases a = 0, b = 1, -1. Other cases: use gcd.
if (RingZZ::is_zero(a))
{
x = RingZZ::from_int(1);
y = RingZZ::from_int(0);
return;
}
mpz_ptr bb = b.get_mpz();
if (mpz_cmp_ui(bb,1) == 0)
{
x = RingZZ::from_int(1);
y = RingZZ::negate(a);
return;
}
if (mask_mpz_cmp_si(bb,-1) == 0)
{
x = RingZZ::from_int(1);
y = RingZZ::copy(a);
return;
}
ring_elem g = RingZZ::gcd(a,b);
y = RingZZ::divide(a,g);
x = RingZZ::divide(b,g);
RingZZ::remove(g);
if (mpz_sgn(x.get_mpz()) > 0)
RingZZ::internal_negate_to(y);
else
RingZZ::internal_negate_to(x);
}
开发者ID:mikestillman,项目名称:practice1,代码行数:32,代码来源:ZZ.cpp
示例3: is_equal
bool RingZZ::is_equal(const ring_elem f, const ring_elem g) const
{
mpz_ptr a = f.get_mpz();
mpz_ptr b = g.get_mpz();
return mpz_cmp(a, b) == 0;
}
开发者ID:mikestillman,项目名称:practice1,代码行数:7,代码来源:ZZ.cpp
示例4: compare_elems
int GF::compare_elems(const ring_elem f, const ring_elem g) const
{
int cmp = f.get_int() - g.get_int();
if (cmp < 0) return -1;
if (cmp == 0) return 0;
return 1;
}
开发者ID:ChristineJost,项目名称:M2,代码行数:7,代码来源:GF.cpp
示例5: new_elem
ring_elem RingZZ::remainderAndQuotient(const ring_elem f, const ring_elem g,
ring_elem ") const
{
mpz_ptr q = new_elem();
mpz_ptr r = new_elem();
int gsign = mpz_sgn(g.get_mpz());
mpz_t gg, ghalf;
mpz_init(gg);
mpz_init(ghalf);
mpz_abs(gg,g.get_mpz());
mpz_fdiv_qr(q, r, f.get_mpz(), gg);
mpz_tdiv_q_2exp(ghalf, gg, 1);
if (mpz_cmp(r,ghalf) > 0) // r > ghalf
{
mpz_sub(r,r,gg);
mpz_add_ui(q,q,1);
}
if (gsign < 0)
mpz_neg(q,q);
mpz_clear(gg);
mpz_clear(ghalf);
quot = ring_elem(q);
return ring_elem(r);
}
开发者ID:mikestillman,项目名称:practice1,代码行数:25,代码来源:ZZ.cpp
示例6: fraction
ring_elem QQ::fraction(ring_elem top, ring_elem bottom) const
{
gmp_QQ result = QQ::new_elem();
mpz_set(mpq_numref(result),top.get_mpz());
mpz_set(mpq_denref(result),bottom.get_mpz());
mpq_canonicalize(result);
return MPQ_RINGELEM(result);
}
开发者ID:ChristineJost,项目名称:M2,代码行数:8,代码来源:QQ.cpp
示例7: compare_elems
int RingZZ::compare_elems(const ring_elem f, const ring_elem g) const
{
mpz_ptr a = f.get_mpz();
mpz_ptr b = g.get_mpz();
int cmp = mpz_cmp(a,b);
if (cmp > 0) return 1;
if (cmp == 0) return 0;
return -1;
}
开发者ID:mikestillman,项目名称:practice1,代码行数:9,代码来源:ZZ.cpp
示例8: elem_text_out
void RingZZ::elem_text_out(buffer &o,
const ring_elem ap,
bool p_one,
bool p_plus,
bool p_parens) const
{
mpz_ptr a = ap.get_mpz();
#warning "possible overflow in large int situations"
char s[1000];
char *str;
bool is_neg = (mask_mpz_cmp_si(a, 0) == -1);
bool is_one = (mask_mpz_cmp_si(a, 1) == 0 || mask_mpz_cmp_si(a, -1) == 0);
int size = static_cast<int>(mpz_sizeinbase(a, 10)) + 2;
char *allocstr = (size > 1000 ? newarray_atomic(char,size) : s);
if (!is_neg && p_plus) o << '+';
if (is_one)
{
if (is_neg) o << '-';
if (p_one) o << '1';
}
else
{
str = mpz_get_str(allocstr, 10, a);
o << str;
}
if (size > 1000) deletearray(allocstr);
}
开发者ID:mikestillman,项目名称:practice1,代码行数:32,代码来源:ZZ.cpp
示例9: mpz_gcd
void RingZZ::lower_content(ring_elem &c, ring_elem g) const
// c is a content elem, g is in ring
{
if (is_zero(c))
{
c = g;
return;
}
gmp_ZZ result = RingZZ::new_elem();
mpz_srcptr a = c.get_mpz();
mpz_srcptr b = g.get_mpz();
mpz_gcd(result, a, b);
if(mpz_sgn(a) == -1)
mpz_neg(result, result);
c = ring_elem(result);
}
开发者ID:DanGrayson,项目名称:M2,代码行数:16,代码来源:ZZ.cpp
示例10: mpz_gcd
void RingZZ::lower_content(ring_elem &c, ring_elem g) const
// c is a content elem, g is in ring
{
// if f is 0, do f=sign(g), else f=sign(f)
// return whether f is zero
if (is_zero(c))
{
c = g;
return;
}
gmp_ZZ result = RingZZ::new_elem();
mpz_ptr a = c.get_mpz();
mpz_ptr b = g.get_mpz();
mpz_gcd(result,a,b);
c = ring_elem(result);
}
开发者ID:mikestillman,项目名称:practice1,代码行数:16,代码来源:ZZ.cpp
示例11: mpz_sgn
bool RingZZ::lower_associate_divisor(ring_elem &f, const ring_elem g) const
{
// This sets f to either 0, 1 or -1.
// if f is 0, do f=sign(g), else f=sign(f)
// return whether f is zero
gmp_ZZ result = RingZZ::new_elem();
mpz_ptr a = f.get_mpz();
mpz_ptr b = g.get_mpz();
int sa = mpz_sgn(a);
int sb = mpz_sgn(b);
int s = (sa == 0 ? sb : sa);
mpz_set_si(result,s);
f = ring_elem(result);
return !RingZZ::is_zero(f);
}
开发者ID:mikestillman,项目名称:practice1,代码行数:16,代码来源:ZZ.cpp
示例12: preferred_associate
ring_elem RingZZ::preferred_associate(ring_elem f) const
{
mpz_ptr a = f.get_mpz();
if (mpz_sgn(a) >= 0)
return from_int(1);
return from_int(-1);
}
开发者ID:mikestillman,项目名称:practice1,代码行数:7,代码来源:ZZ.cpp
示例13: checkThreshold
bool LLLoperations::checkThreshold(ring_elem num, ring_elem den)
{
// Makes sure that 1/4 < num/den <= 1
// Assumed: num, den are elements of ZZ.
mpz_ptr a = num.get_mpz();
mpz_ptr b = den.get_mpz();
if (mpz_sgn(a) < 0) return false;
if (mpz_sgn(b) < 0) return false;
if (mpz_cmp(a,b) > 0) return false; // return false if a>b.
mpz_t c;
mpz_init(c);
mpz_mul_2exp(c,a,2); // c = 4*a
int cmp = mpz_cmp(b,c);
mpz_clear(c);
if (cmp >= 0) return false;
return true;
}
开发者ID:ChristineJost,项目名称:M2,代码行数:17,代码来源:LLL.cpp
示例14: promote
bool QQ::promote(const Ring *Rf, const ring_elem f, ring_elem &result) const
{
// Rf = ZZ ---> QQ
if (Rf->is_ZZ())
{
result = QQ::from_int(f.get_mpz());
return true;
}
return false;
}
开发者ID:ChristineJost,项目名称:M2,代码行数:10,代码来源:QQ.cpp
示例15: promote
bool Z_mod::promote(const Ring *Rf, const ring_elem f, ring_elem &result) const
{
// Rf = Z ---> Z/p
if (Rf == globalZZ)
{
result = from_int(f.get_mpz());
return true;
}
return false;
}
开发者ID:AlessandroOneto,项目名称:M2,代码行数:10,代码来源:ZZp.cpp
示例16: promote
bool promote(const Ring *Rf, const ring_elem f, ElementType& result) const {
printf("ARingQQGMP::calling promote\n");
// Rf = ZZ ---> QQ
if (Rf->is_ZZ())
{
set_from_mpz(result, f.get_mpz());
return true;
}
return false;
}
开发者ID:pzinn,项目名称:M2,代码行数:10,代码来源:aring-qq-gmp.hpp
示例17: elem_text_out
void GF::elem_text_out(buffer &o,
const ring_elem a,
bool p_one,
bool p_plus,
bool p_parens) const
{
if (a.get_int() == _ZERO)
{
o << "0";
return;
}
ring_elem h = _originalR->power(_primitive_element->get_value(), a.int_val);
_originalR->elem_text_out(o, h, p_one, p_plus, p_parens);
_originalR->remove(h);
}
开发者ID:ChristineJost,项目名称:M2,代码行数:15,代码来源:GF.cpp
示例18: fprintf
bool ConcreteRing<RingType>::promote(const Ring *R,
const ring_elem fR,
ring_elem &resultS) const
{
const Ring *S = this;
fprintf(stderr, "calling promote\n");
typedef RingPromoter RP;
if (R == globalZZ)
{
resultS = S->from_int(fR.get_mpz());
return true;
}
if (R == S)
{
resultS = copy(fR);
return true;
}
switch (R->ringID()) {
case M2::ring_ZZp:
switch (S->ringID()) {
case M2::ring_ZZp: return false;
case M2::ring_GF: return RP::promoter<ARingZZp,ARingGF>(R,S,fR,resultS);
case M2::ring_FFPACK: return RP::promoter<ARingZZp,ARingZZpFFPACK>(R,S,fR,resultS);
default: return false;
}
break;
case M2::ring_GF:
switch (S->ringID()) {
case M2::ring_ZZp: return RP::promoter<ARingGF,ARingZZp>(R,S,fR,resultS);
case M2::ring_GF: return RP::promoter<ARingGF,ARingGF>(R,S,fR,resultS);
case M2::ring_FFPACK: return RP::promoter<ARingGF,ARingZZpFFPACK>(R,S,fR,resultS);
default: return false;
}
case M2::ring_FFPACK:
switch (S->ringID()) {
case M2::ring_ZZp: return RP::promoter<ARingZZpFFPACK,ARingZZp>(R,S,fR,resultS);
case M2::ring_GF: return RP::promoter<ARingZZpFFPACK,ARingGF>(R,S,fR,resultS);
case M2::ring_FFPACK: return RP::promoter<ARingZZpFFPACK,ARingZZpFFPACK>(R,S,fR,resultS);
default: return false;
}
default:
break;
};
return false;
}
开发者ID:ChristineJost,项目名称:M2,代码行数:45,代码来源:aring-glue.cpp
示例19: is_equal
bool GF::is_equal(const ring_elem f, const ring_elem g) const
{
return f.get_int() == g.get_int();
}
开发者ID:ChristineJost,项目名称:M2,代码行数:4,代码来源:GF.cpp
示例20: is_zero
bool GF::is_zero(const ring_elem f) const
{
return (f.get_int() == _ZERO);
}
开发者ID:ChristineJost,项目名称:M2,代码行数:4,代码来源:GF.cpp
注:本文中的ring_elem类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论