/usr/share/singular/LIB/ringgb.lib is in singular-data 4.0.3+ds-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | /////////////////////////////////////////////////////////////////////////////
version="version ringgb.lib 4.0.0.0 Jun_2013 "; // $Id: 4ddabf56c4914ebf04eacb3a180c200e78759fee $
category="Miscellaneous";
info="
LIBRARY: ringgb.lib Functions for coefficient rings
AUTHOR: Oliver Wienand, email: wienand@mathematik.uni-kl.de
KEYWORDS: vanishing polynomial; zeroreduce; polynomial functions; library, ringgb.lib; ringgb.lib, functions for coefficient rings
PROCEDURES:
findZeroPoly(f); finds a vanishing polynomial for reducing f
zeroReduce(f); normal form of f concerning the ideal of vanishing polynomials
testZero(poly f); tests f defines the constant zero function
noElements(def r); the number of elements of the coefficient ring, if of type (integer, ...)
";
LIB "general.lib";
///////////////////////////////////////////////////////////////////////////////
proc findZeroPoly (poly f)
"USAGE: findZeroPoly(f); f - a polynomial
RETURN: zero polynomial with the same leading term as f if exists, otherwise 0
EXAMPLE: example findZeroPoly; shows an example
"
{
list data = getZeroCoef(f);
if (data[1] == 0)
{
return(0);
}
number q = leadcoef(f) / data[1];
if (q == 0)
{
return(0);
}
poly g = getZeroPolyRaw(data[2]);
g = leadmonom(f) / leadmonom(g) * g;
return(q * data[1] * g);
//return(system("findZeroPoly", f));
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (integer, 65536), (y,x), dp;
poly f = 1024*x^8*y^2+11264*x^8*y+28672*x^8+45056*x^7*y^2+36864*x^7*y+16384*x^7+40960*x^6*y^2+57344*x^6*y+32768*x^6+30720*x^5*y^2+10240*x^5*y+8192*x^5+35840*x^4*y^2+1024*x^4*y+20480*x^4+30720*x^3*y^2+10240*x^3*y+8192*x^3+4096*x^2*y^2+45056*x^2*y+49152*x^2+40960*x*y^2+57344*x*y+32768*x;
findZeroPoly(f);
}
proc zeroReduce(poly f, list #)
"USAGE: zeroReduce(f, [i = 0]); f - a polynomial, i - noise level (if != 0 prints all steps)
RETURN: reduced normal form of f modulo zero polynomials
EXAMPLE: example zeroReduce; shows an example
"
{
int i = 0;
if (size(#) > 0)
{
i = #[1];
}
poly h = f;
poly n = 0;
poly g = findZeroPoly(h);
if (i <> 0) {
printf("reducing polyfct : %s", h);
}
while ( h <> 0 ) {
while ( g <> 0 ) {
h = h - g;
if (i <> 0) {
printf(" reduce with: %s", g);
printf(" to: %s", h);
}
g = findZeroPoly(h);
}
n = lead(h) + n;
if (i <> 0) {
printf("head irreducible : %s", lead(h));
printf("irreducible start : %s", n);
printf("remains to check : %s", h - lead(h));
}
h = h - lead(h);
g = findZeroPoly(h);
}
return(n);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (integer, 65536), (y,x), dp;
poly f = 1024*x^8*y^2+11264*x^8*y+28672*x^8+45056*x^7*y^2+36864*x^7*y+16384*x^7+40960*x^6*y^2+57344*x^6*y+32768*x^6+30720*x^5*y^2+10240*x^5*y+8192*x^5+35840*x^4*y^2+1024*x^4*y+20480*x^4+30720*x^3*y^2+10240*x^3*y+8192*x^3+4096*x^2*y^2+45056*x^2*y+49152*x^2+40960*x*y^2+57344*x*y+32768*x;
zeroReduce(f);
kill r;
ring r = (integer, 2, 32), (x,y,z), dp;
// Polynomial 1:
poly p1 = 3795162112*x^3+587202566*x^2*y+2936012853*x*y*z+2281701376*x+548767119*y^3+16777216*y^2+268435456*y*z+1107296256*y+4244635648*z^3+4244635648*z^2+16777216*z;
// Polynomial 2:
poly p2 = 1647678464*x^3+587202566*x^2*y+2936012853*x*y*z+134217728*x+548767119*y^3+16777216*y^2+268435456*y*z+1107296256*y+2097152000*z^3+2097152000*z^2+16777216*z;
zeroReduce(p1-p2);
}
proc testZero(poly f)
"USAGE: testZero(f); f - a polynomial
RETURN: returns 1 if f is zero as a function and otherwise a counterexample as a list [f(x_1, ..., x_n), x_1, ..., x_n]
EXAMPLE: example testZero; shows an example
"
{
poly g;
int j;
bigint i = 0;
bigint modul = noElements(basering);
printf("Teste %s Belegungen ...", modul^nvars(basering));
for (; i < modul^nvars(basering); i = i + 1)
{
if ((i + 1) % modul^(nvars(basering)/2) == 0)
{
printf("bisher: %s", i);
}
g = f;
for (j = 1; j <= nvars(basering); j++)
{
g = subst(g, var(j), number((i / modul^(j-1)) % modul));
}
if (g != 0)
{
list counter = g;
for (j = 1; j <= nvars(basering); j++)
{
counter = insert(counter, (i / modul^(j-1)) % modul);
}
return(counter);
}
}
return(1);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (integer, 12), (y,x), dp;
poly f = 1024*x^8*y^2+11264*x^8*y+28672*x^8+45056*x^7*y^2+36864*x^7*y+16384*x^7+40960*x^6*y^2+57344*x^6*y+32768*x^6+30720*x^5*y^2+10240*x^5*y+8192*x^5+35840*x^4*y^2+1024*x^4*y+20480*x^4+30720*x^3*y^2+10240*x^3*y+8192*x^3+4096*x^2*y^2+45056*x^2*y+49152*x^2+40960*x*y^2+57344*x*y+32768*x;
zeroReduce(f);
testZero(f);
poly g = findZeroPoly(x2y3);
g;
testZero(g);
}
proc noElements(def r)
"USAGE: noElements(r); r - a ring with a finite coefficient ring of type integer
RETURN: returns the number of elements of the coefficient ring of r
EXAMPLE: example noElements; shows an example
"
{
list l = ringlist(basering);
return(l[1][2][1]^l[1][2][2]);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (integer, 233,6), (y,x), dp;
noElements(r);
}
static proc getZeroCoef(poly f)
{
if (f == 0)
{
return(0, leadexp(f))
}
list data = sort(leadexp(f));
intvec exp = data[1];
intvec index = data[2];
intvec nec = 0:size(exp);
int i = 1;
int j = 2;
bigint g;
bigint G = 1;
bigint modul = noElements(basering);
bigint B = modul;
for (; exp[i] < 2; i++) {if (i == size(exp)) break;}
for (; i <= size(exp); i++)
{
g = gcd(B, G);
G = G * g;
B = B / g;
if (g != 1)
{
nec[index[i]] = j - 1;
}
if (B == 1)
{
return(B, nec);
}
for (; j <= exp[i]; j++)
{
g = gcd(B, bigint(j));
G = G * g;
B = B / g;
if (g != 1)
{
nec[index[i]] = j;
}
if (B == 1)
{
return(B, nec);
}
}
}
if (B == modul)
{
nec = 0;
return(0, nec);
}
return(B, nec);
}
static proc getZeroPolyRaw(intvec fexp)
{
list data = sort(fexp);
intvec exp = data[1];
intvec index = data[2];
int j = 0;
poly res = 1;
poly tillnow = 1;
int i = 1;
for (; exp[i] < 2; i++) {if (i == size(exp)) break;}
for (; i <= size(exp); i++)
{
for (; j < exp[i]; j++)
{
tillnow = tillnow * (var(1) - j);
}
res = res * subst(tillnow, var(1), var(index[i]));
}
return(res);
}
static proc getZeroPoly(poly f)
{
list data = getZeroCoef(f);
poly g = getZeroPolyRaw(data[2]);
g = leadmonom(f) / leadmonom(g) * g;
return(data[1] * g);
}
static proc findZeroPolyWrap (poly f)
"USAGE: findZeroPolyWrap(f); f - a polynomial
RETURN: zero polynomial with the same leading term as f if exists, otherwise 0
NOTE: just a wrapper, work only in Z/2^n with n < int_machine_size - 1
EXAMPLE: example findZeroPoly; shows an example
"
{
return(system("findZeroPoly", f));
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (integer, 2, 16), (y,x), dp;
poly f = 1024*x^8*y^2+11264*x^8*y+28672*x^8+45056*x^7*y^2+36864*x^7*y+16384*x^7+40960*x^6*y^2+57344*x^6*y+32768*x^6+30720*x^5*y^2+10240*x^5*y+8192*x^5+35840*x^4*y^2+1024*x^4*y+20480*x^4+30720*x^3*y^2+10240*x^3*y+8192*x^3+4096*x^2*y^2+45056*x^2*y+49152*x^2+40960*x*y^2+57344*x*y+32768*x;
findZeroPoly(f);
}
///////////////////////////////////////////////////////////////////////////////
/*
Examples:
// POLYNOMIAL EXAMPLES (Singular ready)
// ===================
//
// For each of the examples below, there are three equivalent polynomials. 'm' indicates the bit-widths of the
// input/output variables. For some of the polynomials, I have attached the RTL as well.
//
//
// 1) VOLTERRA MODELS:
//
// A) CUBIC FILTER: (m = 32, 3 Vars)
LIB "ringgb.lib";
ring r = (integer, 2, 32), (x,y,z), dp;
poly p1 = 3795162112*x^3+587202566*x^2*y+2936012853*x*y*z+2281701376*x+548767119*y^3+16777216*y^2+268435456*y*z \
+1107296256*y+4244635648*z^3+4244635648*z^2+16777216*z;
poly p2 = 1647678464*x^3+587202566*x^2*y+2936012853*x*y*z+134217728*x+548767119*y^3+16777216*y^2+268435456*y*z \
+1107296256*y+2097152000*z^3+2097152000*z^2+16777216*z;
poly p3 = 1647678464*x^3+587202566*x^2*y+2936012853*x*y*z+134217728*x+548767119*y^3+16777216*y^2+268435456*y*z \
+1107296256*y+2097152000*z^3+2097152000*z^2+16777216*z;
zeroReduce(p1-p2);
zeroReduce(p1-p3);
zeroReduce(p2-p3);
// B) DEGREE-4 FILTER: (m=16 , 3 Vars)
LIB "ringgb.lib";
ring r = (integer, 2, 16), (x,y,z), dp;
poly p1 = 16384*x^4+y^4+57344*z^4+64767*x*y^3+16127*y^2*z^2+8965*x^3*z+19275*x^2*y*z+51903*x*y*z+32768*x^2*y \
+40960*z^2+32768*x*y^2+49152*x^2+4869*y;
poly p2 = 8965*x^3*z+19275*x^2*y*z+31999*x*y^3+51903*x*y*z+32768*x*y+y^4+32768*y^3+16127*y^2*z^2+32768*y^2 \
+4869*y+57344*z^4+40960*z^2;
poly p3 = 8965*x^3*z+19275*x^2*y*z+31999*x*y^3+51903*x*y*z+32768*x*y+y^4+16127*y^2*z^2+4869*y+16384*z^3+16384*z;
zeroReduce(p1-p2);
zeroReduce(p1-p3);
zeroReduce(p2-p3);
// 2) Savitzsky Golay filter(m=16,5 Vars)
LIB "ringgb.lib";
ring r = (integer, 2, 16), (v,w,x,y,z), dp;
poly p1 = 25000*v^2*y+37322*v^2+22142*v*w*z+50356*w^3+58627*w^2+17797*w+17797*x^3+62500*x^2*z+41667*x \
+22142*y^3+23870*y^2+59464*y+41667*z+58627;
poly p2 = 25000*v^2*y+4554*v^2+22142*v*w*z+32768*v+17588*w^3+25859*w^2+17797*w+17797*x^3+29732*x^2*z+32768*x^2 \
+32768*x*z+8899*x+22142*y^3+23870*y^2+59464*y+41667*z+58627;
poly p3 = 25000*v^2*y+4554*v^2+22142*v*w*z+32768*v+17588*w^3+25859*w^2+17797*w+17797*x^3+29732*x^2*z+32768*x*z \
+41667*x+22142*y^3+23870*y^2+59464*y+41667*z+58627;
zeroReduce(p1-p2);
zeroReduce(p1-p3);
zeroReduce(p2-p3);
// 3) Anti-alias filter:(m=16, 1 Var)
LIB "ringgb.lib";
ring r = (integer, 2, 16), c, dp;
poly p1 = 156*c^6+62724*c^5+17968*c^4+18661*c^3+43593*c^2+40224*c+13281;
poly p2 = 156*c^6+5380*c^5+1584*c^4+43237*c^3+27209*c^2+40224*c+13281;
poly p3 = 156*c^6+5380*c^5+1584*c^4+10469*c^3+27209*c^2+7456*c+13281;
zeroReduce(p1-p2);
zeroReduce(p1-p3);
zeroReduce(p2-p3);
// 4) PSK:(m=16, 2 Var)
LIB "ringgb.lib";
ring r = (integer, 2, 16), (x,y), dp;
poly p1 = 4166*x^4+16666*x^3*y+25000*x^2*y^2+15536*x^2+16666*x*y^4+31072*x*y+4166*y^4+15536*y^2+34464;
poly p2 = 4166*x^4+16666*x^3*y+8616*x^2*y^2+16384*x^2*y+15536*x^2+282*x*y^4+47456*x*y+53318*y^4+31920*y^2+34464;
poly p3 = 4166*x^4+16666*x^3*y+8616*x^2*y^2+16384*x^2*y+15536*x^2+282*x*y^4+47456*x*y+4166*y^4+15536*y^2+34464;
zeroReduce(p1-p2);
zeroReduce(p1-p3);
zeroReduce(p2-p3);
// Ref: A. Peymandoust G. De Micheli, �Application of Symbolic Computer Algebra in High-Level Data-Flow
// Synthesis,� IEEE Transactions on CAD/ICAS, Vol. 22, No. 9, September 2003, pp.1154-1165.
*/
|