rem
stringlengths
0
83.5k
add
stringlengths
0
223k
context
stringlengths
10
471k
meta
stringlengths
120
236
{ GEN p1; /* Given g in Z[x], g' its derivative, p a prime, [w0,h0] in Z[x] s.t. * h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), return * [w1,h1] satisfying the same condition mod p^2, [w1,h1] = [w0,h0] (mod p)
{/* Given g,w0,h0 in Z[x], s.t. h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), find * [w1,h1] satisfying the same conditions mod p^2, [w1,h1] = [w0,h0] (mod p)
embedding_of_potential_subfields(GEN nf,GEN g,GEN DATA,GEN rootsA,GEN delta){ GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind, maxp; ulong av; T = (GEN)nf[1]; ind = (GEN)nf[4]; p = (GEN)DATA[2]; maxp = mulii((GEN)DATA[7],ind); gp = derivpol(g); av = avma; w0 = interpolation_polynomial(rootsA, delta, (GEN)DATA[4],p); w0_Q = retrieve_ratpol(ind,w0,p); /* h0 = 1/g'(w0) mod (T,p) */ h0 = FpXQ_inv(FpX_FpXQ_compo(gp,w0, T,p), T,p); for(;;) { GEN p1; /* Given g in Z[x], g' its derivative, p a prime, [w0,h0] in Z[x] s.t. * h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), return * [w1,h1] satisfying the same condition mod p^2, [w1,h1] = [w0,h0] (mod p) * (cf. Dixon: J. Austral. Math. Soc., Series A, vol.49, 1990, p.445) */ if (DEBUGLEVEL>2) fprintferr("w = %Z\nh = %Z\n",w0,h0); p = sqri(p); /* w1 = w0 - h0 g(w0) mod (T,p) */ p1 = gmul(gneg(h0), FpX_FpXQ_compo(g,w0, T,p)); w1 = gadd(w0, FpX_res(p1, T,p)); w1_Q = retrieve_ratpol(ind,w1,p); if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) && gcmp0(poleval(g, gmodulcp(w1_Q,T)))) break; if (DEBUGLEVEL>2) { fprintferr("Old Q-polynomial: %Z\n",w0_Q); fprintferr("New Q-polynomial: %Z\n",w1_Q); } if (cmpii(p, maxp) > 0) { if (DEBUGLEVEL) fprintferr("coeff too big for embedding\n"); return NULL; } p1 = gmul(gneg(h0), FpX_FpXQ_compo(gp,w1, T,p)); p1 = gadd(gdeux, FpX_res(p1, T,p)); h0 = FpX_res(gmul(h0, p1), T,p); w0 = w1; w0_Q = w1_Q; { GEN *gptr[4]; gptr[0]=&w0; gptr[1]=&h0; gptr[2]=&w0_Q; gptr[3]=&p; gerepilemany(av,gptr,4); } } return poleval(w1_Q, gadd(polx[0],stoi(TR)));}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/59af7aa1a95aeb4e670f3d2cf01cd1e105edb8c4/subfield.c/buggy/src/modules/subfield.c
if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) &&
if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp) > 0) &&
embedding_of_potential_subfields(GEN nf,GEN g,GEN DATA,GEN rootsA,GEN delta){ GEN w0_Q,w0,w1,h0,gp,w1_Q,T,p,ind, maxp; ulong av; T = (GEN)nf[1]; ind = (GEN)nf[4]; p = (GEN)DATA[2]; maxp = mulii((GEN)DATA[7],ind); gp = derivpol(g); av = avma; w0 = interpolation_polynomial(rootsA, delta, (GEN)DATA[4],p); w0_Q = retrieve_ratpol(ind,w0,p); /* h0 = 1/g'(w0) mod (T,p) */ h0 = FpXQ_inv(FpX_FpXQ_compo(gp,w0, T,p), T,p); for(;;) { GEN p1; /* Given g in Z[x], g' its derivative, p a prime, [w0,h0] in Z[x] s.t. * h0.g'(w0) = 1 and g(w0) = 0 mod (T,p), return * [w1,h1] satisfying the same condition mod p^2, [w1,h1] = [w0,h0] (mod p) * (cf. Dixon: J. Austral. Math. Soc., Series A, vol.49, 1990, p.445) */ if (DEBUGLEVEL>2) fprintferr("w = %Z\nh = %Z\n",w0,h0); p = sqri(p); /* w1 = w0 - h0 g(w0) mod (T,p) */ p1 = gmul(gneg(h0), FpX_FpXQ_compo(g,w0, T,p)); w1 = gadd(w0, FpX_res(p1, T,p)); w1_Q = retrieve_ratpol(ind,w1,p); if ((gegal(w1_Q, w0_Q) || cmpii(p,maxp)) && gcmp0(poleval(g, gmodulcp(w1_Q,T)))) break; if (DEBUGLEVEL>2) { fprintferr("Old Q-polynomial: %Z\n",w0_Q); fprintferr("New Q-polynomial: %Z\n",w1_Q); } if (cmpii(p, maxp) > 0) { if (DEBUGLEVEL) fprintferr("coeff too big for embedding\n"); return NULL; } p1 = gmul(gneg(h0), FpX_FpXQ_compo(gp,w1, T,p)); p1 = gadd(gdeux, FpX_res(p1, T,p)); h0 = FpX_res(gmul(h0, p1), T,p); w0 = w1; w0_Q = w1_Q; { GEN *gptr[4]; gptr[0]=&w0; gptr[1]=&h0; gptr[2]=&w0_Q; gptr[3]=&p; gerepilemany(av,gptr,4); } } return poleval(w1_Q, gadd(polx[0],stoi(TR)));}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/59af7aa1a95aeb4e670f3d2cf01cd1e105edb8c4/subfield.c/buggy/src/modules/subfield.c
struct sockaddr_in *sin,sa;
struct sockaddr_in *sin;
bootpc_call(call,reply,procp) struct bootp_packet *call; struct bootp_packet *reply; /* output */ struct proc *procp;{ struct socket *so; struct sockaddr_in *sin,sa; struct mbuf *m, *nam; struct uio auio; struct iovec aio; int error, rcvflg, timo, secs, len; u_int tport; /* Free at end if not null. */ nam = NULL; /* * Create socket and set its recieve timeout. */ if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp))) goto out; m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) { error = ENOBUFS; goto out; } else { struct timeval *tv; tv = mtod(m, struct timeval *); m->m_len = sizeof(*tv); tv->tv_sec = 1; tv->tv_usec = 0; if ((error = sosetopt(so, SOL_SOCKET, SO_RCVTIMEO, m))) goto out; } /* * Enable broadcast. */ { int *on; m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) { error = ENOBUFS; goto out; } on = mtod(m, int *); m->m_len = sizeof(*on); *on = 1; if ((error = sosetopt(so, SOL_SOCKET, SO_BROADCAST, m))) goto out; } /* * Bind the local endpoint to a bootp client port. */ m = m_getclr(M_WAIT, MT_SONAME); sin = mtod(m, struct sockaddr_in *); sin->sin_len = m->m_len = sizeof(*sin); sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; sin->sin_port = htons(IPPORT_BOOTPC); error = sobind(so, m); m_freem(m); if (error) { printf("bind failed\n"); goto out; } /* * Setup socket address for the server. */ nam = m_get(M_WAIT, MT_SONAME); if (nam == NULL) { error = ENOBUFS; goto out; } sin = mtod(nam, struct sockaddr_in *); sin-> sin_len = sizeof(*sin); sin-> sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_BROADCAST; sin->sin_port = htons(IPPORT_BOOTPS); nam->m_len = sizeof(*sin); /* * Send it, repeatedly, until a reply is received, * but delay each re-send by an increasing amount. * If the delay hits the maximum, start complaining. */ timo = 0; for (;;) { /* Send BOOTP request (or re-send). */ aio.iov_base = (caddr_t) call; aio.iov_len = sizeof(*call); auio.uio_iov = &aio; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_WRITE; auio.uio_offset = 0; auio.uio_resid = sizeof(*call); auio.uio_procp = procp; error = sosend(so, nam, &auio, NULL, NULL, 0); if (error) { printf("bootpc_call: sosend: %d\n", error); goto out; } /* Determine new timeout. */ if (timo < MAX_RESEND_DELAY) timo++; else printf("BOOTP timeout for server 0x%x\n", (int)ntohl(sin->sin_addr.s_addr)); /* * Wait for up to timo seconds for a reply. * The socket receive timeout was set to 1 second. */ secs = timo; while (secs > 0) { aio.iov_base = (caddr_t) reply; aio.iov_len = sizeof(*reply); auio.uio_iov = &aio; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_READ; auio.uio_offset = 0; auio.uio_resid = sizeof(*reply); auio.uio_procp = procp; rcvflg = 0; error = soreceive(so, NULL, &auio, NULL, NULL, &rcvflg); if (error == EWOULDBLOCK) { secs--; call->secs=htons(ntohs(call->secs)+1); continue; } if (error) goto out; len = sizeof(*reply) - auio.uio_resid; /* Do we have the required number of bytes ? */ if (len < BOOTP_MIN_LEN) continue; /* Is it the right reply? */ if (reply->op != 2) continue; if (reply->xid != call->xid) continue; if (reply->hlen != call->hlen) continue; if (bcmp(reply->chaddr,call->chaddr,call->hlen)) continue; goto gotreply; /* break two levels */ } /* while secs */ } /* forever send/receive */ error = ETIMEDOUT; goto out; gotreply: out: if (nam) m_freem(nam); soclose(so); return error;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ff0f694d466fb114c185bf464811658f97d012f1/bootp_subr.c/clean/c/src/exec/libnetworking/nfs/bootp_subr.c
u_int tport;
bootpc_call(call,reply,procp) struct bootp_packet *call; struct bootp_packet *reply; /* output */ struct proc *procp;{ struct socket *so; struct sockaddr_in *sin,sa; struct mbuf *m, *nam; struct uio auio; struct iovec aio; int error, rcvflg, timo, secs, len; u_int tport; /* Free at end if not null. */ nam = NULL; /* * Create socket and set its recieve timeout. */ if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp))) goto out; m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) { error = ENOBUFS; goto out; } else { struct timeval *tv; tv = mtod(m, struct timeval *); m->m_len = sizeof(*tv); tv->tv_sec = 1; tv->tv_usec = 0; if ((error = sosetopt(so, SOL_SOCKET, SO_RCVTIMEO, m))) goto out; } /* * Enable broadcast. */ { int *on; m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) { error = ENOBUFS; goto out; } on = mtod(m, int *); m->m_len = sizeof(*on); *on = 1; if ((error = sosetopt(so, SOL_SOCKET, SO_BROADCAST, m))) goto out; } /* * Bind the local endpoint to a bootp client port. */ m = m_getclr(M_WAIT, MT_SONAME); sin = mtod(m, struct sockaddr_in *); sin->sin_len = m->m_len = sizeof(*sin); sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; sin->sin_port = htons(IPPORT_BOOTPC); error = sobind(so, m); m_freem(m); if (error) { printf("bind failed\n"); goto out; } /* * Setup socket address for the server. */ nam = m_get(M_WAIT, MT_SONAME); if (nam == NULL) { error = ENOBUFS; goto out; } sin = mtod(nam, struct sockaddr_in *); sin-> sin_len = sizeof(*sin); sin-> sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_BROADCAST; sin->sin_port = htons(IPPORT_BOOTPS); nam->m_len = sizeof(*sin); /* * Send it, repeatedly, until a reply is received, * but delay each re-send by an increasing amount. * If the delay hits the maximum, start complaining. */ timo = 0; for (;;) { /* Send BOOTP request (or re-send). */ aio.iov_base = (caddr_t) call; aio.iov_len = sizeof(*call); auio.uio_iov = &aio; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_WRITE; auio.uio_offset = 0; auio.uio_resid = sizeof(*call); auio.uio_procp = procp; error = sosend(so, nam, &auio, NULL, NULL, 0); if (error) { printf("bootpc_call: sosend: %d\n", error); goto out; } /* Determine new timeout. */ if (timo < MAX_RESEND_DELAY) timo++; else printf("BOOTP timeout for server 0x%x\n", (int)ntohl(sin->sin_addr.s_addr)); /* * Wait for up to timo seconds for a reply. * The socket receive timeout was set to 1 second. */ secs = timo; while (secs > 0) { aio.iov_base = (caddr_t) reply; aio.iov_len = sizeof(*reply); auio.uio_iov = &aio; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_READ; auio.uio_offset = 0; auio.uio_resid = sizeof(*reply); auio.uio_procp = procp; rcvflg = 0; error = soreceive(so, NULL, &auio, NULL, NULL, &rcvflg); if (error == EWOULDBLOCK) { secs--; call->secs=htons(ntohs(call->secs)+1); continue; } if (error) goto out; len = sizeof(*reply) - auio.uio_resid; /* Do we have the required number of bytes ? */ if (len < BOOTP_MIN_LEN) continue; /* Is it the right reply? */ if (reply->op != 2) continue; if (reply->xid != call->xid) continue; if (reply->hlen != call->hlen) continue; if (bcmp(reply->chaddr,call->chaddr,call->hlen)) continue; goto gotreply; /* break two levels */ } /* while secs */ } /* forever send/receive */ error = ETIMEDOUT; goto out; gotreply: out: if (nam) m_freem(nam); soclose(so); return error;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ff0f694d466fb114c185bf464811658f97d012f1/bootp_subr.c/clean/c/src/exec/libnetworking/nfs/bootp_subr.c
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string)
rtems_monitor_command_usage( rtems_monitor_command_entry_t *table, char *command_string )
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/32e2554f105163017052572a1830f3caa19ba625/mon-command.c/buggy/cpukit/libmisc/monitor/mon-command.c
rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2];
rtems_monitor_command_entry_t *command = table; int max_cmd_len = 0;
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/32e2554f105163017052572a1830f3caa19ba625/mon-command.c/buggy/cpukit/libmisc/monitor/mon-command.c
/* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; }
/* if first entry in table is a usage, then print it out */ if (command_string && (*command_string != '\0')) { char *argv[2]; argv[0] = command_string; argv[1] = 0; command = rtems_monitor_command_lookup (table, 1, argv); if (command) rtems_monitor_show_help (command, strlen (command_string));
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/32e2554f105163017052572a1830f3caa19ba625/mon-command.c/buggy/cpukit/libmisc/monitor/mon-command.c
{ help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); }
printf ("Unrecognised command; try just 'help'\n"); return; } /* * Find the largest command size. */ while (command) { int len = strlen (command->command);
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/32e2554f105163017052572a1830f3caa19ba625/mon-command.c/buggy/cpukit/libmisc/monitor/mon-command.c
if (help) printf("%s\n", help->usage);
if (len > max_cmd_len) max_cmd_len = len; command = command->next; } max_cmd_len++; command = table; /* * Now some nice formatting for the help. */ while (command) { rtems_monitor_show_help (command, max_cmd_len); command = command->next; }
rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, char *command_string){ rtems_monitor_command_entry_t *help = 0; char *help_command_argv[2]; /* if first entry in table is a usage, then print it out */ if (command_string == 0) { if (STREQ(table->command, "--usage--") && table->usage) help = table; } else { help_command_argv[0] = command_string; help_command_argv[1] = 0; help = rtems_monitor_command_lookup(table, 1, help_command_argv); } if (help) printf("%s\n", help->usage);}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/32e2554f105163017052572a1830f3caa19ba625/mon-command.c/buggy/cpukit/libmisc/monitor/mon-command.c
unsigned32 length = 0;
uint32_t length = 0;
rtems_monitor_config_dump( rtems_monitor_config_t *monitor_config, boolean verbose){ unsigned32 length = 0; length = 0; length += printf("WORKSPACE"); length += rtems_monitor_pad(DATACOL, length); length += printf("start: %p; size: 0x%x\n", monitor_config->work_space_start, monitor_config->work_space_size); length = 0; length += printf("TIME"); length += rtems_monitor_pad(DATACOL, length); length += printf("usec/tick: %d; tick/timeslice: %d; tick/sec: %d\n", monitor_config->microseconds_per_tick, monitor_config->ticks_per_timeslice, 1000000 / monitor_config->microseconds_per_tick); length = 0; length += printf("MAXIMUMS"); length += rtems_monitor_pad(DATACOL, length); length += printf("tasks: %d; timers: %d; sems: %d; que's: %d; ext's: %d\n", monitor_config->maximum_tasks, monitor_config->maximum_timers, monitor_config->maximum_semaphores, monitor_config->maximum_message_queues, monitor_config->maximum_extensions); length = 0; length += rtems_monitor_pad(CONTCOL, length); length += printf("partitions: %d; regions: %d; ports: %d; periods: %d\n", monitor_config->maximum_partitions, monitor_config->maximum_regions, monitor_config->maximum_ports, monitor_config->maximum_periods);}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3e08d4ee6242f1a0ea4afe9dc0a20800632184fe/mon-config.c/clean/cpukit/libmisc/monitor/mon-config.c
n = negi(n); y = cgetg(3,t_VEC); y[2] = lnegi((GEN)z[2]); y[1] = z[1]; z = y;
z = negsell(z); n = negi(n);
powsell(GEN e, GEN z, GEN n, GEN p){ GEN y; long s=signe(n),i,j; ulong m; if (!s || !z) return NULL; if (s < 0) { n = negi(n); y = cgetg(3,t_VEC); y[2] = lnegi((GEN)z[2]); y[1] = z[1]; z = y; } if (is_pm1(n)) return z; y = NULL; for (i=lgefint(n)-1; i>2; i--) for (m=n[i],j=0; j<BITS_IN_LONG; j++,m>>=1) { if (m&1) y = addsell(e,y,z,p); z = addsell(e,z,z,p); } for (m=n[2]; m>1; m>>=1) { if (m&1) y = addsell(e,y,z,p); z = addsell(e,z,z,p); } return addsell(e,y,z,p);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/f85c7b0c1ca7393252f54eb29f56f6b4d77a1c77/elliptic.c/clean/src/modules/elliptic.c
for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */
for (m = 2; m < (ulong)gse+k; m++) /* omit Y coords of [2^gse*210]Q */
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/9749d3e46caef3f61b412b608c8ac51b8f010460/ifactor1.c/clean/src/basemath/ifactor1.c
for (m = 5; m <= gse; m++)
for (m = 5; m <= (ulong)gse; m++)
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/9749d3e46caef3f61b412b608c8ac51b8f010460/ifactor1.c/clean/src/basemath/ifactor1.c
for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */
for (j = 0; (ulong)j < m2-64; j+=64) /* executed 0 times when m == 5 */
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/9749d3e46caef3f61b412b608c8ac51b8f010460/ifactor1.c/clean/src/basemath/ifactor1.c
(m<gse ? XB2 + m2 + j : NULL))
(m<(ulong)gse ? XB2 + m2 + j : NULL))
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/9749d3e46caef3f61b412b608c8ac51b8f010460/ifactor1.c/clean/src/basemath/ifactor1.c
(m<gse ? XB2 + m2 + j : NULL))
(m<(ulong)gse ? XB2 + m2 + j : NULL))
ellfacteur(GEN n, int insist){ static ulong TB1[] = { /* table revised, cf. below 1998Aug15 --GN */ 142,172,208,252,305,370,450,545,661,801,972,1180,1430, 1735,2100,2550,3090,3745,4540,5505,6675,8090,9810,11900, 14420,17490,21200,25700,31160,37780UL,45810UL,55550UL,67350UL, 81660UL,99010UL,120050UL,145550UL,176475UL,213970UL,259430UL, 314550UL,381380UL,462415UL,560660UL,679780UL,824220UL,999340UL, 1211670UL,1469110UL,1781250UL,2159700UL,2618600UL,3175000UL, 3849600UL,4667500UL,5659200UL,6861600UL,8319500UL,10087100UL, 12230300UL,14828900UL,17979600UL,21799700UL,26431500UL, 32047300UL,38856400UL, /* 110 times that still fits into 32bits */#ifdef LONG_IS_64BIT 47112200UL,57122100UL,69258800UL,83974200UL,101816200UL, 123449000UL,149678200UL,181480300UL,220039400UL,266791100UL, 323476100UL,392204900UL,475536500UL,576573500UL,699077800UL, 847610500UL,1027701900UL,1246057200UL,1510806400UL,1831806700UL, 2221009800UL,2692906700UL,3265067200UL,3958794400UL,4799917500UL, /* the only reason to stop here is that I got bored (and that users * will get bored watching their 64bit machines churning on such large * numbers for month after month). Someone can extend this table when * the hardware has gotten 100 times faster than now --GN */#endif }; static ulong TB1_for_stage[] = { /* table revised 1998Aug11 --GN. The idea is to start a little below * the optimal B1 for finding factors which would just have been missed * by pollardbrent(), and escalate gradually, changing curves suf- * ficiently frequently to give good coverage of the small factor * ranges. The table entries grow a bit faster than what Paul says * would be optimal, but having a single table instead of a 2D array * keeps the code simple */ 500,520,560,620,700,800,900,1000,1150,1300,1450,1600,1800,2000, 2200,2450,2700,2950,3250,3600,4000,4400,4850,5300,5800,6400, 7100,7850,8700,9600,10600,11700,12900,14200,15700,17300, 19000,21000,23200,25500,28000,31000,34500UL,38500UL,43000UL, 48000UL,53800UL,60400UL,67750UL,76000UL,85300UL,95700UL, 107400UL,120500UL,135400UL,152000UL,170800UL,191800UL,215400UL, 241800UL,271400UL,304500UL,341500UL,383100UL,429700UL,481900UL, 540400UL,606000UL,679500UL,761800UL,854100UL,957500UL,1073500UL, }; long nbc,nbc2,dsn,dsnmax,rep,spc,gse,gss,rcn,rcn0,bstp,bstp0; long a,i,j,k, av,av1,avtmp, size = expi(n) + 1, tf = lgefint(n); ulong B1,B2,B2_p,B2_rt,m,p,p0,p2,dp; GEN w,w0,x,*X,*XT,*XD,*XG,*YG,*XH,*XB,*XB2,*Xh,*Yh,*Xb, res = cgeti(tf); int rflag, use_clones = 0; byteptr d, d0; av = avma; /* taking res into account */ N = n; /* make n known to auxiliary functions */ /* determine where we'll start, how long we'll persist, and how many * curves we'll use in parallel */ if (insist) { dsnmax = (size >> 2) - 10; if (dsnmax < 0) dsnmax = 0;#ifdef LONG_IS_64BIT else if (dsnmax > 90) dsnmax = 90;#else else if (dsnmax > 65) dsnmax = 65;#endif dsn = (size >> 3) - 5; if (dsn < 0) dsn = 0; else if (dsn > 47) dsn = 47; /* pick up the torch where non-insistent stage would have given up */ nbc = dsn + (dsn >> 2) + 9; /* 8 or more curves in parallel */ nbc &= ~3; /* nbc is always a multiple of 4 */ if (nbc > nbcmax) nbc = nbcmax; a = 1 + (nbcmax<<7); /* seed for choice of curves */ rep = 0; /* gcc -Wall */ } else { dsn = (size - 140) >> 3; if (dsn > 12) dsn = 12; dsnmax = 72; if (dsn < 0) /* < 140 bits: decline the task */ {#ifdef __EMX__ /* MPQS's disk access under DOS/EMX would be abysmally slow, so... */ dsn = 0; rep = 20; nbc = 8;#else if (DEBUGLEVEL >= 4) { fprintferr("ECM: number too small to justify this stage\n"); flusherr(); } avma = av; return NULL;#endif } else { rep = (size <= 248 ? (size <= 176 ? (size - 124) >> 4 : (size - 148) >> 3) : (size - 224) >> 1); nbc = ((size >> 3) << 2) - 80; if (nbc < 8) nbc = 8; else if (nbc > nbcmax) nbc = nbcmax;#ifdef __EMX__ rep += 20;#endif } /* it may be convenient to use disjoint sets of curves for the non-insist * and insist phases; moreover, repeated non-insistent calls acting on * factors of the same original number should try to use fresh curves. * The following achieves this */ a = 1 + (nbcmax<<3)*(size & 0xf); } if (dsn > dsnmax) dsn = dsnmax; if (DEBUGLEVEL >= 4) { (void) timer2(); /* clear timer */ fprintferr("ECM: working on %ld curves at a time; initializing", nbc); if (!insist) { if (rep == 1) fprintferr(" for one round"); else fprintferr(" for up to %ld rounds", rep); } fprintferr("...\n"); } /* The auxiliary routines above need < (3*nbc+240)*tf words on the PARI * stack, in addition to the spc*(tf+1) words occupied by our main table. * If stack space is already tight, try the heap, using newbloc() and * killbloc() */ nbc2 = nbc << 1; spc = (13 + 48) * nbc2 + bstpmax * 4; if ((long)((GEN)avma - (GEN)bot) < spc + 385 + (spc + 3*nbc + 240)*tf) { if (DEBUGLEVEL >= 5) { fprintferr("ECM: stack tight, using clone space on the heap\n"); } use_clones = 1; x = newbloc(spc + 385); } else x = new_chunk(spc + 385); X = 1 + (GEN*)x; /* B1 phase: current point */ XAUX = X + nbc2; /* scratchpad for ellmult() */ XT = XAUX + nbc2; /* ditto, will later hold [3*210]Q */ XD = XT + nbc2; /* room for various multiples */ XB = XD + 20*nbc; /* start of baby steps table */ XB2 = XB + 2 * bstpmax; /* middle of baby steps table */ XH = XB2 + 2 * bstpmax; /* end of bstps table, start of helix */ Xh = XH + 96*nbc; /* little helix, X coords */ Yh = XH + 192; /* ditto, Y coords */ /* XG will be set later, inside the main loop, since it depends on B2 */ { long tw = evallg(tf) | evaltyp(t_INT); if (use_clones) w = newbloc(spc*tf); else w = new_chunk(spc*tf); w0 = w; /* remember this for later... */ for (i = spc; i--; ) { *w = tw; X[i] = w; w += tf; /* hack for: w = cgeti(tf) */ } /* Xh range of 384 pointers not set; these will later duplicate the * pointers in the XH range, 4 curves at a time. Some of the cells * reserved here for the XB range will never be used, instead, we'll * warp the pointers to connect to (read-only) GENs in the X/XD range; * it would be complicated to skip them here to conserve merely a few * KBy of stack or heap space. --GN */ } /* *** ECM MAIN LOOP *** */ for(;;) { d = diffptr; rcn = NPRC; /* multipliers begin at the beginning */ /* pick curves */ for (i = nbc2; i--; ) affsi(a++, X[i]); /* pick bounds */ B1 = insist ? TB1[dsn] : TB1_for_stage[dsn]; B2 = 110*B1; B2_rt = (ulong)(sqrt((double)B2)); /* pick giant step exponent and size. * With 32 baby steps, a giant step corresponds to 32*420 = 13440, appro- * priate for the smallest B2s. With 1024, a giant step will be 430080; * this will be appropriate for B1 >~ 42000, where 512 baby steps would * imply roughly the same number of E.C. additions. */ gse = (B1 < 656 ? (B1 < 200 ? 5 : 6) : (B1 < 10500 ? (B1 < 2625 ? 7 : 8) : (B1 < 42000 ? 9 : 10) ) ); gss = 1UL << gse; XG = XT + gse*nbc2; /* will later hold [2^(gse+1)*210]Q */ YG = XG + nbc; if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms\nECM: dsn = %2ld,\tB1 = %4lu,", timer2(), dsn, B1); fprintferr("\tB2 = %6lu,\tgss = %4ld*420\n", B2, gss); flusherr(); } p = *d++; /* ---B1 PHASE--- */ /* treat p=2 separately */ B2_p = B2 >> 1; for (m=1; m<=B2_p; m<<=1) { if ((rflag = elldouble(nbc, X, X)) > 1) goto fin; else if (rflag) break; } /* p=3,...,nextprime(B1) */ while (p < B1 && p <= B2_rt) { p = snextpr(p, &d, &rcn, NULL, miller_k1); B2_p = B2/p; /* beware integer overflow on 32-bit CPUs */ for (m=1; m<=B2_p; m*=p) { if ((rflag = ellmult(nbc, p, X, X)) > 1) goto fin; else if (rflag) break; } } /* primes p larger than sqrt(B2) can appear only to the 1st power */ while (p < B1) { p = snextpr(p, &d, &rcn, NULL, miller_k1); if (ellmult(nbc, p, X, X) > 1) goto fin; /* p^2 > B2: no loop */ } if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, B1 phase done, ", timer2()); fprintferr("p = %lu, setting up for B2\n", p); } /* ---B2 PHASE--- */ /* compute [2]Q,...,[10]Q, which we need to build the helix */ if (elldouble(nbc, X, XD) > 1) goto fin; /* [2]Q */ if (elldouble(nbc, XD, XD + nbc2) > 1) goto fin; /* [4]Q */ if (elladd(nbc, XD, XD + nbc2, XD + (nbc<<2)) > 1) goto fin; /* [6]Q */ if (elladd2(nbc, XD, XD + (nbc<<2), XT + (nbc<<3), XD + nbc2, XD + (nbc<<2), XD + (nbc<<3)) > 1) goto fin; /* [8]Q and [10]Q */ if (DEBUGLEVEL >= 7) fprintferr("\t(got [2]Q...[10]Q)\n"); /* get next prime (still using the foolproof test) */ p = snextpr(p, &d, &rcn, NULL, miller_k1); /* make sure we have the residue class number (mod 210) */ if (rcn == NPRC) { rcn = prc210_no[(p % 210) >> 1]; if (rcn == NPRC) { fprintferr("ECM: %lu should have been prime but isn\'t\n", p); err(bugparier, "ellfacteur"); } } /* compute [p]Q and put it into its place in the helix */ if (ellmult(nbc, p, X, XH + rcn*nbc2) > 1) goto fin; if (DEBUGLEVEL >= 7) fprintferr("\t(got [p]Q, p = %lu = %lu mod 210)\n", p, (ulong)(prc210_rp[rcn])); /* save current p, d, and rcn; we'll need them more than once below */ p0 = p; d0 = d; rcn0 = rcn; /* remember where the helix wraps */ bstp0 = 0; /* p is at baby-step offset 0 from itself */ /* fill up the helix, stepping forward through the prime residue classes * mod 210 until we're back at the r'class of p0. Keep updating p so * that we can print meaningful diagnostics if a factor shows up; but * don't bother checking which of these p's are in fact prime */ for (i = 47; i; i--) /* 47 iterations */ { p += (dp = (ulong)prc210_d1[rcn]); if (rcn == 47) { /* wrap mod 210 */ if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH) > 1) goto fin; rcn = 0; continue; } if (elladd(nbc, XT + dp*nbc, XH + rcn*nbc2, XH + rcn*nbc2 + nbc2) > 1) goto fin; rcn++; } if (DEBUGLEVEL >= 7) fprintferr("\t(got initial helix)\n"); /* compute [210]Q etc, which will be needed for the baby step table */ if (ellmult(nbc, 3, XD + (nbc<<3), X) > 1) goto fin; if (ellmult(nbc, 7, X, X) > 1) goto fin; /* [210]Q */ /* this was the last call to ellmult() in the main loop body; may now * overwrite XAUX and slots XD and following */ if (elldouble(nbc, X, XAUX) > 1) goto fin; /* [420]Q */ if (elladd(nbc, X, XAUX, XT) > 1) goto fin; /* [630]Q */ if (elladd(nbc, X, XT, XD) > 1) goto fin; /* [840]Q */ for (i=1; i <= gse; i++) /* gse successive doublings */ { if (elldouble(nbc, XT + i*nbc2, XD + i*nbc2) > 1) goto fin; } /* (the last iteration has initialized XG to [210*2^(gse+1)]Q) */ if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms, entering B2 phase, p = %lu\n", timer2(), p); } /* inner loop over small sets of 4 curves at a time */ for (i = nbc - 4; i >= 0; i -= 4) { if (DEBUGLEVEL >= 6) fprintferr("ECM: finishing curves %ld...%ld\n", i, i+3); /* copy relevant pointers from XH to Xh. Recall memory layout in XH * is: nbc X coordinates followed by nbc Y coordinates for residue * class 1 mod 210, then the same for r.c. 11 mod 210, etc. Memory * layout for Xh is: four X coords for 1 mod 210, four for 11 mod 210, * etc, four for 209 mod 210, and then the corresponding Y coordinates * in the same order. This will allow us to do a giant step on Xh * using just three calls to elladd0() each acting on 64 points in * parallel */ for (j = 48; j--; ) { k = nbc2*j + i; m = j << 2; /* X coordinates */ Xh[m] = XH[k]; Xh[m+1] = XH[k+1]; Xh[m+2] = XH[k+2]; Xh[m+3] = XH[k+3]; k += nbc; /* Y coordinates */ Yh[m] = XH[k]; Yh[m+1] = XH[k+1]; Yh[m+2] = XH[k+2]; Yh[m+3] = XH[k+3]; } /* build baby step table of X coords of multiples of [210]Q. XB[4*j] * will point at X coords on four curves from [(j+1)*210]Q. Until * we're done, we need some Y coords as well, which we keep in the * second half of the table, overwriting them at the end when gse==10. * Those multiples which we already have (by 1,2,3,4,8,16,...,2^gse) * are entered simply by copying the pointers, ignoring the small * number of slots in w that were initially reserved for them. * Here are the initial entries... */ for (Xb=XB,k=2,j=i; k--; Xb=XB2,j+=nbc) /* do first X, then Y coords */ { Xb[0] = X[j]; Xb[1] = X[j+1]; /* [210]Q */ Xb[2] = X[j+2]; Xb[3] = X[j+3]; Xb[4] = XAUX[j]; Xb[5] = XAUX[j+1]; /* [420]Q */ Xb[6] = XAUX[j+2]; Xb[7] = XAUX[j+3]; Xb[8] = XT[j]; Xb[9] = XT[j+1]; /* [630]Q */ Xb[10] = XT[j+2]; Xb[11] = XT[j+3]; Xb += 4; /* this points at [420]Q */ /* ... entries at powers of 2 times 210 .... */ for (m = 2; m < gse+k; m++) /* omit Y coords of [2^gse*210]Q */ { long m2 = m*nbc2 + j; Xb += (2UL<<m); /* points now at [2^m*210]Q */ Xb[0] = XAUX[m2]; Xb[1] = XAUX[m2+1]; Xb[2] = XAUX[m2+2]; Xb[3] = XAUX[m2+3]; } } if (DEBUGLEVEL >= 7) fprintferr("\t(extracted precomputed helix / baby step entries)\n"); /* ... glue in between, up to 16*210 ... */ if (elladd0(12, 4, /* 12 pts + (4 pts replicated thrice) */ XB + 12, XB2 + 12, XB, XB2, XB + 16, XB2 + 16) > 1) goto fin; /* 4 + {1,2,3} = {5,6,7} */ if (elladd0(28, 4, /* 28 pts + (4 pts replicated 7fold) */ XB + 28, XB2 + 28, XB, XB2, XB + 32, XB2 + 32) > 1) goto fin; /* 8 + {1,...,7} = {9,...,15} */ /* ... and the remainder of the lot */ for (m = 5; m <= gse; m++) { /* fill in from 2^(m-1)+1 to 2^m-1 in chunks of 64 and 60 points */ ulong m2 = 2UL << m; /* will point at 2^(m-1)+1 */ for (j = 0; j < m2-64; j+=64) /* executed 0 times when m == 5 */ { if (elladd0(64, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; } /* j == m2-64 here, 60 points left */ if (elladd0(60, 4, XB + m2 - 4, XB2 + m2 - 4, XB + j, XB2 + j, XB + m2 + j, (m<gse ? XB2 + m2 + j : NULL)) > 1) goto fin; /* (when m==gse, drop Y coords of result, and when both equal 1024, * overwrite Y coords of second argument with X coords of result) */ } if (DEBUGLEVEL >= 7) fprintferr("\t(baby step table complete)\n"); /* initialize a few other things */ bstp = bstp0; p = p0; d = d0; rcn = rcn0; gl = gun; av1 = avma; /* scratchspace for prod (x_i-x_j) */ avtmp = (long)new_chunk(8 * lgefint(n)); /* the correct entry in XB to use depends on bstp and on where we are * on the helix. As we skip from prime to prime, bstp will be incre- * mented by snextpr() each time we wrap around through residue class * number 0 (1 mod 210), but the baby step should not be taken until * rcn>=rcn0 (i.e. until we pass again the residue class of p0). * The correct signed multiplier is thus k = bstp - (rcn < rcn0), * and the offset from XB is four times (|k| - 1). When k==0, we may * ignore the current prime (if it had led to a factorization, this * would have been noted during the last giant step, or -- when we * first get here -- whilst initializing the helix). When k > gss, * we must do a giant step and bump bstp back by -2*gss. * The gcd of the product of X coord differences against N is taken just * before we do a giant step. */ /* loop over probable primes p0 < p <= nextprime(B2), * inserting giant steps as necessary */ while (p < B2) { /* save current p for diagnostics */ p2 = p; /* get next probable prime */ p = snextpr(p, &d, &rcn, &bstp, miller_k2); /* work out the corresponding baby-step multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); /* check whether it's giant-step time */ if (k > gss) { /* take gcd */ gl = mppgcd(gl, n); if (!is_pm1(gl) && !egalii(gl, n)) { p = p2; goto fin; } gl = gun; avma = av1; while (k > gss) /* hm, just how large are those prime gaps? */ { /* giant step */ if (DEBUGLEVEL >= 7) fprintferr("\t(giant step at p = %lu)\n", p); if (elladd0(64, 4, XG + i, YG + i, Xh, Yh, Xh, Yh) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 64, Yh + 64, Xh + 64, Yh + 64) > 1) goto fin; if (elladd0(64, 4, XG + i, YG + i, Xh + 128, Yh + 128, Xh + 128, Yh + 128) > 1) goto fin; bstp -= (gss << 1); /* recompute multiplier */ k = bstp - (rcn < rcn0 ? 1 : 0); } } if (!k) continue; /* point of interest is already in Xh */ if (k < 0) k = -k; m = ((ulong)k - 1) << 2; /* accumulate product of differences of X coordinates */ j = rcn<<2; avma = avtmp; /* go to garbage zone */ gl = modii(mulii(gl, subii(XB[m], Xh[j])), n); gl = modii(mulii(gl, subii(XB[m+1], Xh[j+1])), n); gl = modii(mulii(gl, subii(XB[m+2], Xh[j+2])), n); gl = mulii(gl, subii(XB[m+3], Xh[j+3])); avma = av1; gl = modii(gl, n); } /* loop over p */ avma = av1; } /* for i (loop over sets of 4 curves) */ /* continuation part of main loop */ if (dsn < dsnmax) { dsn += insist ? 1 : 2; if (dsn > dsnmax) dsn = dsnmax; } if (!insist && !--rep) { if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tellfacteur giving up.\n", timer2()); flusherr(); } avma = av; if (use_clones) { gunclone(w0); gunclone(x); } return NULL; } } /* *** END OF ECM MAIN LOOP *** */fin: affii(gl, res); if (DEBUGLEVEL >= 4) { fprintferr("ECM: time = %6ld ms,\tp <= %6lu,\n\tfound factor = %Z\n", timer2(), p, res); flusherr(); } avma=av; if (use_clones) { gunclone(w0); gunclone(x); } return res;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/9749d3e46caef3f61b412b608c8ac51b8f010460/ifactor1.c/clean/src/basemath/ifactor1.c
#if 0 printf( "write %d in %d: %*s\n", to_copy, block, to_copy, src ); #endif
MEMFILE_STATIC int IMFS_memfile_write( IMFS_jnode_t *the_jnode, off_t start, const unsigned char *source, unsigned int length){ block_p *block_ptr; unsigned int block; int status; unsigned int my_length; unsigned int to_copy = 0; unsigned int last_byte; unsigned int start_offset; int copied; const unsigned char *src; src = source; /* * Perform internal consistency checks */ assert( the_jnode ); if ( !the_jnode ) set_errno_and_return_minus_one( EIO ); assert( the_jnode->type == IMFS_MEMORY_FILE ); if ( the_jnode->type != IMFS_MEMORY_FILE ) set_errno_and_return_minus_one( EIO ); /* * Error check arguments */ assert( source ); if ( !source ) set_errno_and_return_minus_one( EINVAL ); /* * If there is nothing to write, then quick exit. */ my_length = length; if ( !my_length ) set_errno_and_return_minus_one( EINVAL ); /* * If the last byte we are supposed to write is past the end of this * in memory file, then extend the length. */ last_byte = start + length; if ( last_byte > the_jnode->info.file.size ) { status = IMFS_memfile_extend( the_jnode, last_byte ); if ( status ) set_errno_and_return_minus_one( ENOSPC ); } copied = 0; /* * Three phases to the write: * + possibly the last part of one block * + all of zero of more blocks * + possibly the first part of one block */ /* * Phase 1: possibly the last part of one block */ start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK; block = start / IMFS_MEMFILE_BYTES_PER_BLOCK; if ( start_offset ) { to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK - start_offset; if ( to_copy > my_length ) to_copy = my_length; block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); assert( block_ptr ); if ( !block_ptr ) return copied; memcpy( &(*block_ptr)[ start_offset ], src, to_copy ); src += to_copy; block++; my_length -= to_copy; copied += to_copy; } /* * Phase 2: all of zero of more blocks */ to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK; while ( my_length >= IMFS_MEMFILE_BYTES_PER_BLOCK ) { block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); assert( block_ptr ); if ( !block_ptr ) return copied; memcpy( &(*block_ptr)[ 0 ], src, to_copy ); src += to_copy; block++; my_length -= to_copy; copied += to_copy; } /* * Phase 3: possibly the first part of one block */ assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK ); to_copy = my_length; if ( my_length ) { block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); assert( block_ptr ); if ( !block_ptr ) return copied; memcpy( &(*block_ptr)[ 0 ], src, my_length ); my_length = 0; copied += to_copy; } IMFS_atime_mtime_update( the_jnode ); return copied;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/b10f6e12e00caba93e56976cdef7b6326bc3af3e/memfile.c/buggy/c/src/exec/libfs/src/imfs/memfile.c
clr_exisr(mask);
/*clr_exisr(mask); too early to ack*/
ictrl_isr(rtems_vector_number vector,CPU_Interrupt_frame *cpu_frame){ unsigned32 istat, mask, global_vec; int exvec; rtems_isr_entry handler; istat = get_exisr() & get_exier() & PPC_EXI_MASK; /* FIXME: this may be speeded up using cntlzw instruction */ for (exvec = 0;exvec < PPC_IRQ_EXT_MAX;exvec++) { mask = VEC_TO_EXMSK(exvec); if (0 != (istat & mask)) { clr_exisr(mask); handler = ictrl_vector_table[exvec]; if (handler) { istat &= ~mask; global_vec = exvec + PPC_IRQ_EXT_BASE; (handler)(global_vec); } } } if (istat != 0) { /* anything left? then we have a spurious interrupt */ ictrl_spurious_handler(istat,cpu_frame); }}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/307685b3a6c9510462c313394be58b698cb6ce9c/ictrl.c/clean/c/src/lib/libcpu/powerpc/ppc403/ictrl/ictrl.c
clr_exisr(mask);/* now we can ack*/
ictrl_isr(rtems_vector_number vector,CPU_Interrupt_frame *cpu_frame){ unsigned32 istat, mask, global_vec; int exvec; rtems_isr_entry handler; istat = get_exisr() & get_exier() & PPC_EXI_MASK; /* FIXME: this may be speeded up using cntlzw instruction */ for (exvec = 0;exvec < PPC_IRQ_EXT_MAX;exvec++) { mask = VEC_TO_EXMSK(exvec); if (0 != (istat & mask)) { clr_exisr(mask); handler = ictrl_vector_table[exvec]; if (handler) { istat &= ~mask; global_vec = exvec + PPC_IRQ_EXT_BASE; (handler)(global_vec); } } } if (istat != 0) { /* anything left? then we have a spurious interrupt */ ictrl_spurious_handler(istat,cpu_frame); }}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/307685b3a6c9510462c313394be58b698cb6ce9c/ictrl.c/clean/c/src/lib/libcpu/powerpc/ppc403/ictrl/ictrl.c
case '!': case '#': analyseur++; skiptruc(); return;
case '!': case '#': analyseur++; skipfacteur(); return;
skiptruc(void){ long i,m,n; char *old; switch(*analyseur) { case '"': skipstring(); return; case '!': case '#': analyseur++; skiptruc(); return; case '&': case '\'': analyseur++; check_var_name(); skipentry(); return; } if (isalpha((int)*analyseur)) { skipidentifier(); return; } if (isdigit((int)*analyseur) || *analyseur== '.') { skipconstante(); return; } switch(*analyseur++) { case '(': skipexpr(); match(')'); return; case '[': old = analyseur-1; if (*analyseur == ';' && analyseur[1] == ']') /* [;] */ { analyseur+=2; return; } n = 0; if (*analyseur != ']') { do { n++; skipexpr(); old=analyseur; } while (*analyseur++ == ','); analyseur--; } switch (*analyseur) { case ']': analyseur++; return; case ';': analyseur++; for (m=2; ; m++) { for (i=1; i<n; i++) { skipexpr(); match(','); } skipexpr(); if (*analyseur == ']') break; match(';'); } analyseur++; return; default: err(talker2,"; or ] expected",old,mark.start); } case '%': if (*analyseur == '`') { while (*++analyseur == '`') /*empty*/; return; } number(&n); return; } err(caracer1,analyseur-1,mark.start);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/286c8b02b52436ccee0ef5124040dc1b6b649636/anal.c/clean/src/language/anal.c
rtems_unsigned8 umr1, umr2;
uint8_t umr1, umr2;
mcfuart_set_attributes(mcfuart *uart, const struct termios *t){ int level; speed_t baud; rtems_unsigned8 umr1, umr2; baud = cfgetospeed(t); umr1 = 0; umr2 = MCF5206E_UMR2_CM_NORMAL; /* Set flow control */ if ((t->c_cflag & CRTSCTS) != 0) { umr1 |= MCF5206E_UMR1_RXRTS; umr2 |= MCF5206E_UMR2_TXCTS; } /* Set character size */ switch (t->c_cflag & CSIZE) { case CS5: umr1 |= MCF5206E_UMR1_BC_5; break; case CS6: umr1 |= MCF5206E_UMR1_BC_6; break; case CS7: umr1 |= MCF5206E_UMR1_BC_7; break; case CS8: umr1 |= MCF5206E_UMR1_BC_8; break; } /* Set number of stop bits */ if ((t->c_cflag & CSTOPB) != 0) { if ((t->c_cflag & CSIZE) == CS5) { umr2 |= MCF5206E_UMR2_SB5_2; } else { umr2 |= MCF5206E_UMR2_SB_2; } } else { if ((t->c_cflag & CSIZE) == CS5) { umr2 |= MCF5206E_UMR2_SB5_1; } else { umr2 |= MCF5206E_UMR2_SB_1; } } /* Set parity mode */ if ((t->c_cflag & PARENB) != 0) { if ((t->c_cflag & PARODD) != 0) { umr1 |= MCF5206E_UMR1_PM_ODD; } else { umr1 |= MCF5206E_UMR1_PM_EVEN; } } else { umr1 |= MCF5206E_UMR1_PM_NO_PARITY; } rtems_interrupt_disable(level); *MCF5206E_UCR(MBAR,uart->chn) = MCF5206E_UCR_TC_DISABLE | MCF5206E_UCR_RC_DISABLE; mcfuart_set_baudrate(uart, baud); *MCF5206E_UCR(MBAR,uart->chn) = MCF5206E_UCR_MISC_RESET_MR; *MCF5206E_UMR(MBAR,uart->chn) = umr1; *MCF5206E_UMR(MBAR,uart->chn) = umr2; if ((t->c_cflag & CREAD) != 0) { *MCF5206E_UCR(MBAR,uart->chn) = MCF5206E_UCR_TC_ENABLE | MCF5206E_UCR_RC_ENABLE; } else { *MCF5206E_UCR(MBAR,uart->chn) = MCF5206E_UCR_TC_ENABLE; } rtems_interrupt_enable(level); return RTEMS_SUCCESSFUL;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/8bc4430b7be84f0bfa8913693775166ae420fc41/mcfuart.c/clean/c/src/lib/libcpu/m68k/mcf5206/console/mcfuart.c
int pk,i,j,LE=0;
int pk,pk2,i,j,LE=0;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d824424e0a4051e3b938353b1b01e0b528104092/aprcl.c/clean/src/modules/aprcl.c
GEN tabt,taba,m,E=gzero,p1;
GEN tabt,taba,m,E=gzero,p1,a=gzero,a2=gzero;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d824424e0a4051e3b938353b1b01e0b528104092/aprcl.c/clean/src/modules/aprcl.c
tabcyc[pk] = cyclo(pk,0);
ishack = isinstep5 && ((pk>=lg((GEN)tabcyc)) || ((!signe(tabcyc[pk])))); pk2 = pkfalse; tabcyc[pk2] = cyclo(pk,0);
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d824424e0a4051e3b938353b1b01e0b528104092/aprcl.c/clean/src/modules/aprcl.c
for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1);
for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk2]); tabeta[pk2] = lmul(gmodulcp(gun,N),p1);
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d824424e0a4051e3b938353b1b01e0b528104092/aprcl.c/clean/src/modules/aprcl.c
tabE[pk] = (long)E;
tabE[pk2] = (long)E;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d824424e0a4051e3b938353b1b01e0b528104092/aprcl.c/clean/src/modules/aprcl.c
tabTH[pk] = (long)p1;
tabTH[pk2] = (long)p1;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d824424e0a4051e3b938353b1b01e0b528104092/aprcl.c/clean/src/modules/aprcl.c
setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;
setlg(taba, e); tabaall[pk2] = taba; setlg(tabt, e); tabtall[pk2] = tabt;
filltabs(GEN N, int p, int k, ulong ltab){ const ulong mask = (1<<kglob)-1; int pk,i,j,LE=0; ulong s,e; GEN tabt,taba,m,E=gzero,p1; pk = u_pow(p,k); tabcyc[pk] = cyclo(pk,0); p1 = cgetg(pk+1,t_VEC); for (i=1; i<=pk; i++) p1[i] = lmod(gpowgs(polx[0],i-1), tabcyc[pk]); tabeta[pk] = lmul(gmodulcp(gun,N),p1); if (p > 2) { LE = pk - pk/p + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if (i%p) E[++j] = i; } else if (k >= 3) { LE = (pk>>2) + 1; E = cgetg(LE,t_VECSMALL); for (i=1,j=0; i<pk; i++) if ((i%8)==1 || (i%8)==3) E[++j] = i; } if (p>2 || k>=3) { tabE[pk] = (long)E; p1 = cgetg(LE,t_VEC); for (i=1; i<LE; i++) { GEN p2 = cgetg(3,t_VECSMALL); p2[1] = p2[2] = E[i]; p1[i] = (long)p2; } tabTH[pk] = (long)p1; } tabt = cgetg(ltab+1,t_VECSMALL); taba = cgetg(ltab+1,t_VECSMALL); m = divis(N,pk); for (e=1; e<=ltab && signe(m); e++) { s = vali(m); m = shifti(m,-s); tabt[e] = e==1? s: s+kglob; taba[e] = signe(m)? ((modBIL(m) & mask)+1)>>1: 0; m = shifti(m, -kglob); } if (e > ltab) err(bugparier,"filltabs"); setlg(taba, e); tabaall[pk] = taba; setlg(tabt, e); tabtall[pk] = tabt;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/d824424e0a4051e3b938353b1b01e0b528104092/aprcl.c/clean/src/modules/aprcl.c
if (DEBUGLEVEL>5) fprintferr("initial parameters p=%Z,\n f=%Z\n",p,f);
if (DEBUGLEVEL>5) fprintferr("initial parameters p=%Z,\n f=%Z\n",p,f);
dedek(GEN f, long mf, GEN p,GEN g){ GEN k,h; long dk; h = FpX_div(f,g,p); k = gdivexact(gadd(f, gneg_i(gmul(g,h))), p); k = FpX_gcd(k, FpX_gcd(g,h, p), p); dk = degpol(k); if (DEBUGLEVEL>2) { fprintferr(" dedek: gcd has degree %ld\n", dk); if (DEBUGLEVEL>5) fprintferr("initial parameters p=%Z,\n f=%Z\n",p,f); } if (2*dk >= mf-1) return FpX_div(f,k,p); return dk? (GEN)NULL: f;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/b53c2a08405189f6a07ca394dfaa0e9f4c997cf7/base2.c/clean/src/basemath/base2.c
GEN x0 = x+2, z; z = (GEN)x0[0];
GEN x0 = x+2, z = (GEN)x0[0];
spec_FpXQ_pow(GEN x, GEN p, GEN S){ long i, dx = degpol(x); pari_sp av = avma, lim = stack_lim(av, 1); GEN x0 = x+2, z; z = (GEN)x0[0]; if (dx < 0) err(talker, "zero polynomial in FpXQ_pow. %Z not prime", p); for (i = 1; i <= dx; i++) { GEN d, c = (GEN)x0[i]; /* assume coeffs in [0, p-1] */ if (!signe(c)) continue; d = (GEN)S[i]; if (!gcmp1(c)) d = gmul(c,d); z = gadd(z, d); if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"spec_FpXQ_pow"); z = gerepileupto(av, z); } } z = FpX_red(z, p); return gerepileupto(av, z);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c
z = FpX_red(z, p); return gerepileupto(av, z);
return gerepileupto(av, FpX_red(z, p));
spec_FpXQ_pow(GEN x, GEN p, GEN S){ long i, dx = degpol(x); pari_sp av = avma, lim = stack_lim(av, 1); GEN x0 = x+2, z; z = (GEN)x0[0]; if (dx < 0) err(talker, "zero polynomial in FpXQ_pow. %Z not prime", p); for (i = 1; i <= dx; i++) { GEN d, c = (GEN)x0[i]; /* assume coeffs in [0, p-1] */ if (!signe(c)) continue; d = (GEN)S[i]; if (!gcmp1(c)) d = gmul(c,d); z = gadd(z, d); if (low_stack(lim, stack_lim(av,1))) { if(DEBUGMEM>1) err(warnmem,"spec_FpXQ_pow"); z = gerepileupto(av, z); } } z = FpX_red(z, p); return gerepileupto(av, z);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0653bf4e80ffba66b9dad8b9b9bf38de88f14841/polarit1.c/clean/src/basemath/polarit1.c
long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m;
long iscol, i, j, k, li, bco, aco = lg(a)-1; ulong piv, invpiv, m; const int OK_ulong = u_OK_ULONG(p);
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
piv = 0; /* gcc -Wall */
piv = invpiv = 0; /* -Wall */
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv)
if (OK_ulong) /* u_Fp_gauss_get_col wants 0 <= a[i,j] < p for all i,j */ for (k = 1; k < i; k++) coeff(a,k,i) %= p; for (k = i; k <= li; k++)
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL;
piv = ( coeff(a,k,i) %= p ); if (piv) break;
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
piv = coeff(a,i,i);
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m)
m = ( coeff(a,k,i) %= p ); if (!m) continue; m = p - mulssmod(m, invpiv, p); /* - 1/piv mod p */ if (m == 1)
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); }
for (j=i+1; j<=aco; j++) _u_Fp_add((ulong*)a[j],k,i, p); for (j=1; j<=bco; j++) _u_Fp_add((ulong*)b[j],k,i, p); } else if (OK_ulong) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((ulong*)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((ulong*)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((ulong*)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((ulong*)b[j],k,i,m, p);
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p);
if (OK_ulong) for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col_OK(a,(GEN)b[j], invpiv, aco, p); else for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j], invpiv, aco, p);
u_FpM_gauss_sp(GEN a, GEN b, ulong p){ long iscol,i,j,k,li,bco, aco = lg(a)-1; ulong piv, m; GEN u; if (!aco) return cgetg(1,t_MAT); li = lg(a[1])-1; bco = lg(b)-1; iscol = (typ(b)!=t_MAT); if (iscol) b = col_to_mat(b); piv = 0; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ piv = coeff(a,i,i) % p; coeff(a,i,i) = piv; k = i; if (!piv) { for (k++; k <= li; k++) { coeff(a,k,i) %= p; if (coeff(a,k,i)) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = coeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { m = coeff(a,k,i) % p; coeff(a,k,i) = 0; if (m) { m = mulssmod(m, u_invmod(piv,p), p); m = p - m; if (u_OK_ULONG(p)) { for (j=i+1; j<=aco; j++) _u_Fp_addmul_OK((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul_OK((GEN)b[j],k,i,m, p); } else { for (j=i+1; j<=aco; j++) _u_Fp_addmul((GEN)a[j],k,i,m, p); for (j=1; j<=bco; j++) _u_Fp_addmul((GEN)b[j],k,i,m, p); } } } } u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)u_Fp_gauss_get_col(a,(GEN)b[j],piv,aco,p); return iscol? (GEN)u[1]: u;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
if (maxprime() < a) err(primer1);
if (maxprime() < (ulong)a) err(primer1);
sinitp(long a, long c, byteptr *ptr){ byteptr p = *ptr; if (a <= 0) a = 2; if (maxprime() < a) err(primer1); while (a > c) c += *p++; *ptr = p; return c;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/9749d3e46caef3f61b412b608c8ac51b8f010460/sumiter.c/clean/src/language/sumiter.c
GEN piv,m,u;
GEN piv, invpiv, m, u;
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
piv = NULL; /* gcc -Wall */
piv = invpiv = NULL; /* -Wall */
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv))
for (k = i; k <= li; k++)
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL;
piv = FpX_res(gcoeff(a,k,i), T,p); coeff(a,k,i) = (long)piv; if (signe(piv)) break;
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p);
m = gneg( FpXQ_mul(m, invpiv, T,p) );
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b;
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
gerepilemany(av,gptr,2);
gerepileall(av, 2, &a,&b);
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p);
for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a, (GEN)b[j], invpiv, aco, T, p);
FqM_gauss(GEN a, GEN b, GEN T, GEN p){ pari_sp av,lim; long i,j,k,li,bco, aco = lg(a)-1; int iscol; GEN piv,m,u; if (!T) return FpM_gauss(a,b,p); if (typ(a)!=t_MAT) err(mattype1,"gauss"); if (b && typ(b)!=t_COL && typ(b)!=t_MAT) err(typeer,"gauss"); if (!aco) { if (b && lg(b)!=1) err(consister,"gauss"); if (DEBUGLEVEL) err(warner,"in Gauss lg(a)=1 lg(b)=%ld", b?1:-1); return cgetg(1,t_MAT); } li = lg(a[1])-1; if (li != aco && (li < aco || b)) err(mattype1,"gauss"); b = check_b(b,li,&iscol); av = avma; lim = stack_lim(av,1); a = dummycopy(a); bco = lg(b)-1; piv = NULL; /* gcc -Wall */ for (i=1; i<=aco; i++) { /* k is the line where we find the pivot */ coeff(a,i,i) = (long)FpX_res(gcoeff(a,i,i), T,p); piv = gcoeff(a,i,i); k = i; if (!signe(piv)) { for (k++; k <= li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); if (signe(coeff(a,k,i))) break; } if (k>li) return NULL; } /* if (k!=i), exchange the lines s.t. k = i */ if (k != i) { for (j=i; j<=aco; j++) swap(coeff(a,i,j), coeff(a,k,j)); for (j=1; j<=bco; j++) swap(coeff(b,i,j), coeff(b,k,j)); piv = gcoeff(a,i,i); } if (i == aco) break; for (k=i+1; k<=li; k++) { coeff(a,k,i) = (long)FpX_res(gcoeff(a,k,i), T,p); m = gcoeff(a,k,i); coeff(a,k,i) = zero; if (signe(m)) { m = FpXQ_mul(m, FpXQ_inv(piv,T,p),T,p); m = resii(negi(m), p); for (j=i+1; j<=aco; j++) _Fq_addmul((GEN)a[j],k,i,m, T,p); for (j=1; j<=bco; j++) _Fq_addmul((GEN)b[j],k,i,m, T,p); } } if (low_stack(lim, stack_lim(av,1))) { GEN *gptr[2]; gptr[0]=&a; gptr[1]=&b; if(DEBUGMEM>1) err(warnmem,"FpM_gauss. i=%ld",i); gerepilemany(av,gptr,2); } } if(DEBUGLEVEL>4) fprintferr("Solving the triangular system\n"); u = cgetg(bco+1,t_MAT); for (j=1; j<=bco; j++) u[j] = (long)Fq_gauss_get_col(a,(GEN)b[j],piv,aco,T,p); return gerepilecopy(av, iscol? (GEN)u[1]: u);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/0413a80bd91a41fc053e0149a3c6bf7d1e6f290c/alglin1.c/buggy/src/basemath/alglin1.c
if (!T) return FpM_ker_i(x,p,deplin);
FqM_ker_i(GEN x, GEN T, GEN p, long deplin){ gpmem_t av0,av,lim,tetpil; GEN y,c,d,piv,mun; long i,j,k,r,t,n,m; if (typ(x)!=t_MAT) err(typeer,"FpM_ker"); n=lg(x)-1; if (!n) return cgetg(1,t_MAT); m=lg(x[1])-1; r=0; av0 = avma; x=dummycopy(x); mun=negi(gun); c=new_chunk(m+1); for (k=1; k<=m; k++) c[k]=0; d=new_chunk(n+1); av=avma; lim=stack_lim(av,1); for (k=1; k<=n; k++) { for (j=1; j<=m; j++) if (!c[j]) { coeff(x,j,k) = (long) Fq_res(gcoeff(x,j,k), T, p); if (signe(coeff(x,j,k))) break; } if (j>m) { if (deplin) { c = cgetg(n+1, t_COL); for (i=1; i<k; i++) c[i] = (long)Fq_res(gcoeff(x,d[i],k), T, p); c[k] = un; for (i=k+1; i<=n; i++) c[i] = zero; return gerepileupto(av0, c); } r++; d[k]=0; for(j=1; j<k; j++) if (d[j]) coeff(x,d[j],k) = lclone(gcoeff(x,d[j],k)); } else { c[j]=k; d[k]=j; piv = Fq_neg_inv(gcoeff(x,j,k), T, p); coeff(x,j,k) = (long)mun; for (i=k+1; i<=n; i++) coeff(x,j,i) = (long) Fq_mul(piv,gcoeff(x,j,i), T, p); for (t=1; t<=m; t++) if (t!=j) { piv = Fq_res(gcoeff(x,t,k), T, p); if (signe(piv)) { coeff(x,t,k)=zero; for (i=k+1; i<=n; i++) coeff(x,t,i) = (long)Fq_add(gcoeff(x,t,i),Fq_mul(piv,gcoeff(x,j,i), T, p), T, p); if (low_stack(lim, stack_lim(av,1))) Fq_gerepile_gauss_ker(x,T,p,k,t,av); } } } } if (deplin) { avma = av0; return NULL; } tetpil=avma; y=cgetg(r+1,t_MAT); for (j=k=1; j<=r; j++,k++) { GEN c = cgetg(n+1,t_COL); y[j]=(long)c; while (d[k]) k++; for (i=1; i<k; i++) if (d[i]) { GEN p1=gcoeff(x,d[i],k); c[i] = (long) Fq_res(p1, T, p); gunclone(p1); } else c[i] = zero; c[k]=un; for (i=k+1; i<=n; i++) c[i]=zero; } return gerepile(av0,tetpil,y);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/40e574294e7e78bc748e3af5f0b3a447ab2c9e5f/alglin1.c/buggy/src/basemath/alglin1.c
sqrtu2_1(ulong *a) { double beta = sqrt((double)a[0]); /* 0.707... ~ 1/sqrt(2) */ return (ulong)(beta * ((1UL << BITS_IN_HALFULONG) * 0.707106781186547524)); }
sqrtu2_1(ulong *a) { return dblmantissa( sqrt(2. * a[0]) ); }
sqrtu2_1(ulong *a){ double beta = sqrt((double)a[0]); /* 0.707... ~ 1/sqrt(2) */ return (ulong)(beta * ((1UL << BITS_IN_HALFULONG) * 0.707106781186547524));}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/bb644736021b50546346a114cbaa5c805227bc3f/mp.c/buggy/src/kernel/none/mp.c
if (! (F->in_comment | F->in_string)) { while (isspace((int)*s)) s++; /* Skip space */ if (*s == LBRACE) { s++; F->more_input = 2; F->wait_for_brace = 1; } }
filtre0(filtre_t *F){ const int downcase = F->downcase; char c, *s = F->s, *t; if (!F->t) F->t = gpmalloc(strlen(s)+1); t = F->t; if (F->more_input == 1) F->more_input = 0; if (! (F->in_comment | F->in_string)) { while (isspace((int)*s)) s++; /* Skip space */ if (*s == LBRACE) { s++; F->more_input = 2; F->wait_for_brace = 1; } } while ((c = *s++)) { if (F->in_string) { *t++ = c; /* copy verbatim */ switch(c) { case '\\': /* in strings, \ is the escape character */ if (*s) *t++ = *s++; break; case '"': F->in_string = 0; } continue; } if (F->in_comment) { /* look for comment's end */ if (F->in_comment == MULTI_LINE_COMMENT) { while (c != '*' || *s != '/') { if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } c = *s++; } s++; } else while (c != '\n' && *s) c = *s++; F->in_comment = 0; continue; } /* weed out comments and spaces */ if (c=='\\' && *s=='\\') { F->in_comment = ONE_LINE_COMMENT; continue; } if (isspace((int)c)) continue; *t++ = downcase? tolower((int)c): c; switch(c) { case '/': if (*s == '*') { t--; F->in_comment = MULTI_LINE_COMMENT; } break; case '\\': if (!*s) { if (t[-2] == '?') break; /* '?\' */ t--; if (!F->more_input) F->more_input = 1; goto END; } if (*s == '\r') s++; /* DOS */ if (*s == '\n') { if (t[-2] == '?') break; /* '?\' */ t--; s++; if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } } /* skip \<CR> */ break; case ':': if (!compatible && isalpha((int)*s)) { t--; s++; while (is_keyword_char(*s)) { s++; } } break; case '"': F->in_string = 1; } } if (t != F->t) /* non empty input */ { c = t[-1]; /* = last input char */ if (c == '=') F->more_input = 2; else if (! F->wait_for_brace) F->more_input = 0; else if (c == RBRACE) { F->more_input = 0; t--; } }END: F->end = t; *t = 0; return F->t;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/f7d452c12ec91042db2a51f8cac89be08be1fcaa/es.c/clean/src/language/es.c
break; case LBRACE: t--; if (F->wait_for_brace) err(impl,"embedded braces (in parser)"); F->more_input = 2; F->wait_for_brace = 1; break;
filtre0(filtre_t *F){ const int downcase = F->downcase; char c, *s = F->s, *t; if (!F->t) F->t = gpmalloc(strlen(s)+1); t = F->t; if (F->more_input == 1) F->more_input = 0; if (! (F->in_comment | F->in_string)) { while (isspace((int)*s)) s++; /* Skip space */ if (*s == LBRACE) { s++; F->more_input = 2; F->wait_for_brace = 1; } } while ((c = *s++)) { if (F->in_string) { *t++ = c; /* copy verbatim */ switch(c) { case '\\': /* in strings, \ is the escape character */ if (*s) *t++ = *s++; break; case '"': F->in_string = 0; } continue; } if (F->in_comment) { /* look for comment's end */ if (F->in_comment == MULTI_LINE_COMMENT) { while (c != '*' || *s != '/') { if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } c = *s++; } s++; } else while (c != '\n' && *s) c = *s++; F->in_comment = 0; continue; } /* weed out comments and spaces */ if (c=='\\' && *s=='\\') { F->in_comment = ONE_LINE_COMMENT; continue; } if (isspace((int)c)) continue; *t++ = downcase? tolower((int)c): c; switch(c) { case '/': if (*s == '*') { t--; F->in_comment = MULTI_LINE_COMMENT; } break; case '\\': if (!*s) { if (t[-2] == '?') break; /* '?\' */ t--; if (!F->more_input) F->more_input = 1; goto END; } if (*s == '\r') s++; /* DOS */ if (*s == '\n') { if (t[-2] == '?') break; /* '?\' */ t--; s++; if (!*s) { if (!F->more_input) F->more_input = 1; goto END; } } /* skip \<CR> */ break; case ':': if (!compatible && isalpha((int)*s)) { t--; s++; while (is_keyword_char(*s)) { s++; } } break; case '"': F->in_string = 1; } } if (t != F->t) /* non empty input */ { c = t[-1]; /* = last input char */ if (c == '=') F->more_input = 2; else if (! F->wait_for_brace) F->more_input = 0; else if (c == RBRACE) { F->more_input = 0; t--; } }END: F->end = t; *t = 0; return F->t;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/f7d452c12ec91042db2a51f8cac89be08be1fcaa/es.c/clean/src/language/es.c
while (lx-- && x[lx]==0);
while (lx-- && x[lx]==0) /* empty */;
smallpolrev(GEN x){ long i,j, lx = lg(x); GEN y; while (lx-- && x[lx]==0); i = lx+2; y = cgetg(i,t_POL); y[1] = evallgef(i) | evalsigne(1); for (j=2; j<i; j++) y[j] = lstoi(x[j-1]); return y;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8ac2292b2e02fd23dcdd96371571717ef1011e3f/aprcl.c/clean/src/modules/aprcl.c
the_object = _Objects_Get( information, id, &ignored_location ); if (!the_object)
the_object = _Objects_Get( information, id, &ignored_location ); if ( !the_object )
Objects_Name_or_id_lookup_errors _Objects_Id_to_name ( Objects_Id id, Objects_Name *name){ uint32_t the_api; uint32_t the_class; Objects_Information *information; Objects_Control *the_object = (Objects_Control *) 0; Objects_Locations ignored_location; if ( !name ) return OBJECTS_INVALID_NAME; the_api = _Objects_Get_API( id ); if ( the_api && the_api > OBJECTS_APIS_LAST ) return OBJECTS_INVALID_ID; the_class = _Objects_Get_class( id ); information = _Objects_Information_table[ the_api ][ the_class ]; if ( !information ) return OBJECTS_INVALID_ID; if ( information->is_string ) return OBJECTS_INVALID_ID; the_object = _Objects_Get( information, id, &ignored_location ); if (!the_object) return OBJECTS_INVALID_ID; *name = the_object->name; _Thread_Enable_dispatch(); return OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/5670775cec817710cb65ab076864fd28f75bbb9d/objectidtoname.c/clean/cpukit/score/src/objectidtoname.c
Objects_Name the_name,
unsigned32 the_name, /* XXX -- wrong for variable */
boolean _Objects_MP_Open ( Objects_Information *information, Objects_Name the_name, Objects_Id the_id, boolean is_fatal_error){ Objects_MP_Control *the_global_object; the_global_object = _Objects_MP_Allocate_global_object(); if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { if ( is_fatal_error == FALSE ) return FALSE; rtems_fatal_error_occurred( RTEMS_TOO_MANY ); } the_global_object->Object.id = the_id; the_global_object->name = the_name; _Chain_Prepend( &information->global_table[ rtems_get_node( the_id ) ], &the_global_object->Object.Node ); return TRUE;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3235ad9a2cd717df901853ad5220a4aaffae84a9/objectmp.c/clean/cpukit/score/src/objectmp.c
Objects_MP_Control *the_global_object;
Objects_MP_Control *the_global_object;
boolean _Objects_MP_Open ( Objects_Information *information, Objects_Name the_name, Objects_Id the_id, boolean is_fatal_error){ Objects_MP_Control *the_global_object; the_global_object = _Objects_MP_Allocate_global_object(); if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { if ( is_fatal_error == FALSE ) return FALSE; rtems_fatal_error_occurred( RTEMS_TOO_MANY ); } the_global_object->Object.id = the_id; the_global_object->name = the_name; _Chain_Prepend( &information->global_table[ rtems_get_node( the_id ) ], &the_global_object->Object.Node ); return TRUE;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3235ad9a2cd717df901853ad5220a4aaffae84a9/objectmp.c/clean/cpukit/score/src/objectmp.c
unsigned32 real_trap; unsigned32 source;
uint32_t real_trap; uint32_t source;
rtems_isr_entry set_vector( /* returns old vector */ rtems_isr_entry handler, /* isr routine */ rtems_vector_number vector, /* vector number */ int type /* RTEMS or RAW intr */){ rtems_isr_entry previous_isr; unsigned32 real_trap; unsigned32 source; if ( type ) rtems_interrupt_catch( handler, vector, &previous_isr ); else _CPU_ISR_install_raw_handler( vector, handler, (void *)&previous_isr ); real_trap = SPARC_REAL_TRAP_NUMBER( vector ); if ( ERC32_Is_MEC_Trap( real_trap ) ) { source = ERC32_TRAP_SOURCE( real_trap ); ERC32_Clear_interrupt( source ); ERC32_Unmask_interrupt( source ); } return previous_isr;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/1be1e913564b73bf50ce1aa58c003e564ddae83a/setvec.c/buggy/c/src/lib/libbsp/sparc/erc32/startup/setvec.c
triv121PgTblLdMinSize(unsigned long size)
triv121PgTblLdMinSize (unsigned long size)
triv121PgTblLdMinSize(unsigned long size){unsigned long i; /* round 'size' up to the next page boundary */ size += (1<<LD_PG_SIZE)-1; size &= ~((1<<LD_PG_SIZE)-1); /* divide by number of PTEs and multiply * by the size of a PTE. */ size >>= LD_PG_SIZE - LD_PTE_SIZE; /* find the next power of 2 >= size */ for (i=0; i<LD_PHYS_SIZE; i++) { if ((1<<i) >= size) break; } /* pop up to the allowed minimum, if necessary */ if (i<LD_MIN_PT_SIZE) i=LD_MIN_PT_SIZE; return i;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/1b1b43ccc1a6d654199ddb6329366d2e44bdaea3/pte121.c/clean/c/src/lib/libcpu/powerpc/mpc6xx/mmu/pte121.c
unsigned long i; /* round 'size' up to the next page boundary */ size += (1<<LD_PG_SIZE)-1; size &= ~((1<<LD_PG_SIZE)-1); /* divide by number of PTEs and multiply * by the size of a PTE. */ size >>= LD_PG_SIZE - LD_PTE_SIZE; /* find the next power of 2 >= size */ for (i=0; i<LD_PHYS_SIZE; i++) { if ((1<<i) >= size) break; } /* pop up to the allowed minimum, if necessary */ if (i<LD_MIN_PT_SIZE) i=LD_MIN_PT_SIZE; return i;
unsigned long i; /* round 'size' up to the next page boundary */ size += (1 << LD_PG_SIZE) - 1; size &= ~((1 << LD_PG_SIZE) - 1); /* divide by number of PTEs and multiply * by the size of a PTE. */ size >>= LD_PG_SIZE - LD_PTE_SIZE; /* find the next power of 2 >= size */ for (i = 0; i < LD_PHYS_SIZE; i++) { if ((1 << i) >= size) break; } /* pop up to the allowed minimum, if necessary */ if (i < LD_MIN_PT_SIZE) i = LD_MIN_PT_SIZE; return i;
triv121PgTblLdMinSize(unsigned long size){unsigned long i; /* round 'size' up to the next page boundary */ size += (1<<LD_PG_SIZE)-1; size &= ~((1<<LD_PG_SIZE)-1); /* divide by number of PTEs and multiply * by the size of a PTE. */ size >>= LD_PG_SIZE - LD_PTE_SIZE; /* find the next power of 2 >= size */ for (i=0; i<LD_PHYS_SIZE; i++) { if ((1<<i) >= size) break; } /* pop up to the allowed minimum, if necessary */ if (i<LD_MIN_PT_SIZE) i=LD_MIN_PT_SIZE; return i;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/1b1b43ccc1a6d654199ddb6329366d2e44bdaea3/pte121.c/clean/c/src/lib/libcpu/powerpc/mpc6xx/mmu/pte121.c
unsigned32 regno, unsigned32 value
uint32_t regno, uint32_t value
void dmv177_sonic_write_register( void *base, unsigned32 regno, unsigned32 value){ volatile unsigned32 *p = base;#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Write 0x%04x to %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif p[regno] = value;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/dmvsonic.c/clean/c/src/lib/libbsp/powerpc/dmv177/sonic/dmvsonic.c
volatile unsigned32 *p = base;
volatile uint32_t *p = base;
void dmv177_sonic_write_register( void *base, unsigned32 regno, unsigned32 value){ volatile unsigned32 *p = base;#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Write 0x%04x to %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif p[regno] = value;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/dmvsonic.c/clean/c/src/lib/libbsp/powerpc/dmv177/sonic/dmvsonic.c
volatile unsigned16 *card_resource_reg; unsigned16 v;
volatile uint16_t *card_resource_reg; uint16_t v;
boolean dmv177_icm7170_probe(int minor){ volatile unsigned16 *card_resource_reg; unsigned16 v; card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG; v = *card_resource_reg & DMV170_RTC_INST_MASK; if ( v == DMV170_RTC_INSTALLED ) return TRUE; return FALSE;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/todcfg.c/clean/c/src/lib/libbsp/powerpc/dmv177/tod/todcfg.c
card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG;
card_resource_reg = (volatile uint16_t*) DMV170_CARD_RESORCE_REG;
boolean dmv177_icm7170_probe(int minor){ volatile unsigned16 *card_resource_reg; unsigned16 v; card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG; v = *card_resource_reg & DMV170_RTC_INST_MASK; if ( v == DMV170_RTC_INSTALLED ) return TRUE; return FALSE;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/todcfg.c/clean/c/src/lib/libbsp/powerpc/dmv177/tod/todcfg.c
if (use_readline) return 1; else
if (use_readline) return 1; else
get_preproc_value(char *s){ if (!strncmp(s,"EMACS",5)) return under_emacs || under_texmacs; if (!strncmp(s,"READL",5)) {#ifdef READLINE if (use_readline) return 1; else#endif return 0; } return -1;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/2c6aab0280a0585f9de1347c6a47eea8bbaed76d/gp.c/clean/src/gp/gp.c
return 0;
return 0;
get_preproc_value(char *s){ if (!strncmp(s,"EMACS",5)) return under_emacs || under_texmacs; if (!strncmp(s,"READL",5)) {#ifdef READLINE if (use_readline) return 1; else#endif return 0; } return -1;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/2c6aab0280a0585f9de1347c6a47eea8bbaed76d/gp.c/clean/src/gp/gp.c
if (DEBUGLEVEL) msgtimer("LLL basis");
initalgall0(GEN x, long flag, long prec){ const gpmem_t av=avma; GEN lead = NULL,nf,ro,bas,mat,rev,dK,dx,index,res; long n,i,r1,r2,ru,PRECREG; if (DEBUGLEVEL) (void)timer2(); if (typ(x)==t_POL) { n=degpol(x); if (n<=0) err(constpoler,"initalgall0"); check_pol_int(x,"initalg"); if (gisirreducible(x) == gzero) err(redpoler,"nfinit"); if (!gcmp1((GEN)x[n+2])) { x = pol_to_monic(x,&lead); if (!(flag & nf_SMALL)) { if (!(flag & nf_REDUCE)) err(warner,"non-monic polynomial. Result of the form [nf,c]"); flag = flag | nf_REDUCE | nf_ORIG; } } bas = allbase4(x,0,&dK,NULL); if (DEBUGLEVEL) msgtimer("round4"); dx = ZX_disc(x); r1 = sturm(x); } else { i = lg(x); if (typ(x) == t_VEC && i==3 && typ(x[1])==t_POL) { /* polynomial + integer basis */ bas=(GEN)x[2]; x=(GEN)x[1]; n=degpol(x); if (typ(bas) == t_MAT) { mat = bas; bas = mat_to_vecpol(mat,varn(x)); } else mat = vecpol_to_mat(bas,n); dx = ZX_disc(x); r1 = sturm(x); dK = gmul(dx, gsqr(det2(mat))); } else { nf=checknf(x); bas=(GEN)nf[7]; x=(GEN)nf[1]; n=degpol(x); dK=(GEN)nf[3]; dx=mulii(dK, sqri((GEN)nf[4])); r1 = nf_get_r1(nf); } bas[1]=lpolun[varn(x)]; /* it may be gun => SEGV later */ } r2=(n-r1)>>1; ru=r1+r2; PRECREG = prec + (expi(dK)>>(TWOPOTBITS_IN_LONG+1)) + (long)((sqrt((double)n)+3) / sizeof(long) * 4); rev = NULL; if (flag & nf_REDUCE) { nfinit_reduce(flag, &x, &dx, &rev, &bas, prec); if (DEBUGLEVEL) msgtimer("polred"); } if (!carrecomplet(divii(dx,dK),&index)) err(bugparier,"nfinit (incorrect discriminant)"); ro=get_roots(x,r1,PRECREG); if (DEBUGLEVEL) msgtimer("roots"); bas = gmul(bas, LLL_nfbasis(x,ro,bas,prec)); nf=cgetg(10,t_VEC); nf[1]=(long)x; nf[2]=lgetg(3,t_VEC); mael(nf,2,1)=lstoi(r1); mael(nf,2,2)=lstoi(r2); nf[3]=(long)dK; nf[4]=(long)index; nf[6]=(long)ro; nf[7]=(long)bas; get_nf_matrices(nf, flag & nf_SMALL); if (flag & nf_ORIG) { if (!rev) err(talker,"bad flag in initalgall0"); res = cgetg(3,t_VEC); res[1]=(long)nf; nf = res; res[2]=lead? ldiv(rev,lead): (long)rev; } return gerepilecopy(av, nf);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/f621d4fc3f50352e76eace4dafe933fbb39491dc/base1.c/buggy/src/basemath/base1.c
unsigned32 dmv177_sonic_read_register(
uint32_t dmv177_sonic_read_register(
unsigned32 dmv177_sonic_read_register( void *base, unsigned32 regno){ volatile unsigned32 *p = base; unsigned32 value; value = p[regno];#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Read 0x%04x from %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif return value;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/dmvsonic.c/clean/c/src/lib/libbsp/powerpc/dmv177/sonic/dmvsonic.c
unsigned32 regno
uint32_t regno
unsigned32 dmv177_sonic_read_register( void *base, unsigned32 regno){ volatile unsigned32 *p = base; unsigned32 value; value = p[regno];#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Read 0x%04x from %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif return value;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/dmvsonic.c/clean/c/src/lib/libbsp/powerpc/dmv177/sonic/dmvsonic.c
volatile unsigned32 *p = base; unsigned32 value;
volatile uint32_t *p = base; uint32_t value;
unsigned32 dmv177_sonic_read_register( void *base, unsigned32 regno){ volatile unsigned32 *p = base; unsigned32 value; value = p[regno];#if (SONIC_DEBUG & SONIC_DEBUG_PRINT_REGISTERS) printf( "%p Read 0x%04x from %s (0x%02x)\n", &p[regno], value, SONIC_Reg_name[regno], regno ); fflush( stdout );#endif return value;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/dmvsonic.c/clean/c/src/lib/libbsp/powerpc/dmv177/sonic/dmvsonic.c
volatile unsigned16 *card_resource_reg; unsigned16 v;
volatile uint16_t *card_resource_reg; uint16_t v;
boolean dmv177_mc68681_probe(int minor){ volatile unsigned16 *card_resource_reg; unsigned16 v; card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG; v = *card_resource_reg & DMV170_DUART_INST_MASK; if ( v == DMV170_DUART_INSTALLED ) return TRUE; return FALSE;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/conscfg.c/clean/c/src/lib/libbsp/powerpc/dmv177/console/conscfg.c
card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG;
card_resource_reg = (volatile uint16_t*) DMV170_CARD_RESORCE_REG;
boolean dmv177_mc68681_probe(int minor){ volatile unsigned16 *card_resource_reg; unsigned16 v; card_resource_reg = (volatile unsigned16 *) DMV170_CARD_RESORCE_REG; v = *card_resource_reg & DMV170_DUART_INST_MASK; if ( v == DMV170_DUART_INSTALLED ) return TRUE; return FALSE;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/ed9e44994265d3dccca845c7aade2f634184c339/conscfg.c/clean/c/src/lib/libbsp/powerpc/dmv177/console/conscfg.c
#if 0 printf( "write %d in %d: %*s\n", to_copy, block, to_copy, src ); #endif
MEMFILE_STATIC int IMFS_memfile_write( IMFS_jnode_t *the_jnode, off_t start, const unsigned char *source, unsigned int length){ block_p *block_ptr; unsigned int block; int status; unsigned int my_length; unsigned int to_copy = 0; unsigned int last_byte; unsigned int start_offset; int copied; const unsigned char *src; src = source; /* * Perform internal consistency checks */ assert( the_jnode ); if ( !the_jnode ) set_errno_and_return_minus_one( EIO ); assert( the_jnode->type == IMFS_MEMORY_FILE ); if ( the_jnode->type != IMFS_MEMORY_FILE ) set_errno_and_return_minus_one( EIO ); /* * Error check arguments */ assert( source ); if ( !source ) set_errno_and_return_minus_one( EINVAL ); /* * If there is nothing to write, then quick exit. */ my_length = length; if ( !my_length ) set_errno_and_return_minus_one( EINVAL ); /* * If the last byte we are supposed to write is past the end of this * in memory file, then extend the length. */ last_byte = start + length; if ( last_byte > the_jnode->info.file.size ) { status = IMFS_memfile_extend( the_jnode, last_byte ); if ( status ) set_errno_and_return_minus_one( ENOSPC ); } copied = 0; /* * Three phases to the write: * + possibly the last part of one block * + all of zero of more blocks * + possibly the first part of one block */ /* * Phase 1: possibly the last part of one block */ start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK; block = start / IMFS_MEMFILE_BYTES_PER_BLOCK; if ( start_offset ) { to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK - start_offset; if ( to_copy > my_length ) to_copy = my_length; block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); assert( block_ptr ); if ( !block_ptr ) return copied; memcpy( &(*block_ptr)[ start_offset ], src, to_copy ); src += to_copy; block++; my_length -= to_copy; copied += to_copy; } /* * Phase 2: all of zero of more blocks */ to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK; while ( my_length >= IMFS_MEMFILE_BYTES_PER_BLOCK ) { block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); assert( block_ptr ); if ( !block_ptr ) return copied; memcpy( &(*block_ptr)[ 0 ], src, to_copy ); src += to_copy; block++; my_length -= to_copy; copied += to_copy; } /* * Phase 3: possibly the first part of one block */ assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK ); to_copy = my_length; if ( my_length ) { block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); assert( block_ptr ); if ( !block_ptr ) return copied; memcpy( &(*block_ptr)[ 0 ], src, my_length ); my_length = 0; copied += to_copy; } IMFS_atime_mtime_update( the_jnode ); return copied;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/b10f6e12e00caba93e56976cdef7b6326bc3af3e/memfile.c/buggy/cpukit/libfs/src/imfs/memfile.c
char token[ NAME_MAX + 1 ];
char token[ IMFS_NAME_MAX + 1 ];
int IMFS_evaluate_for_make( const char *path, /* IN */ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ const char **name /* OUT */){ int i = 0; int len; IMFS_token_types type; char token[ NAME_MAX + 1 ]; rtems_filesystem_location_info_t newloc; IMFS_jnode_t *node; int done = 0; int result; /* * This was filled in by the caller and is valid in the * mount table. */ node = pathloc->node_access; /* * Evaluate all tokens until we are done or an error occurs. */ while( !done ) { type = IMFS_get_token( &path[i], token, &len ); i += len; if ( !pathloc->node_access ) set_errno_and_return_minus_one( ENOENT ); /* * I cannot move out of this directory without execute permission. */ if ( type != IMFS_NO_MORE_PATH ) if ( node->type == IMFS_DIRECTORY ) if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) ) set_errno_and_return_minus_one( EACCES ); node = pathloc->node_access; switch( type ) { case IMFS_UP_DIR: /* * Am I at the root of this mounted filesystem? */ if (pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access){ /* * Am I at the root of all filesystems? */ if ( pathloc->node_access == rtems_filesystem_root.node_access ) { break; } else { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; return (*pathloc->ops->evalformake)( &path[i-len], pathloc, name ); } } else { if ( !node->Parent ) set_errno_and_return_minus_one( ENOENT ); node = node->Parent; } pathloc->node_access = node; break; case IMFS_NAME: if ( node->type == IMFS_HARD_LINK ) { result = IMFS_evaluate_link( pathloc, 0 ); if ( result == -1 ) return -1; } else if ( node->type == IMFS_SYM_LINK ) { result = IMFS_evaluate_link( pathloc, 0 ); if ( result == -1 ) return -1; } node = pathloc->node_access; if ( !node ) set_errno_and_return_minus_one( ENOTDIR ); /* * Only a directory can be decended into. */ if ( node->type != IMFS_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); /* * If we are at a node that is a mount point. Set loc to the * new fs root node and let them finish evaluating the path. */ if ( node->info.directory.mt_fs != NULL ) { newloc = node->info.directory.mt_fs->mt_fs_root; *pathloc = newloc; return (*pathloc->ops->evalformake)( &path[i-len], pathloc, name ); } /* * Otherwise find the token name in the present location. */ node = IMFS_find_match_in_dir( node, token ); /* * If there is no node we have found the name of the node we * wish to create. */ if ( ! node ) done = TRUE; else pathloc->node_access = node; break; case IMFS_NO_MORE_PATH: set_errno_and_return_minus_one( EEXIST ); break; case IMFS_INVALID_TOKEN: set_errno_and_return_minus_one( ENAMETOOLONG ); break; case IMFS_CURRENT_DIR: break; } } *name = &path[ i - len ]; /* * We have evaluated the path as far as we can. * Verify there is not any invalid stuff at the end of the name. */ for( ; path[i] != '\0'; i++) { if ( !IMFS_is_separator( path[ i ] ) ) set_errno_and_return_minus_one( ENOENT ); } /* * Verify we can execute and write to this directory. */ result = IMFS_Set_handlers( pathloc ); /* * The returned node must be a directory */ node = pathloc->node_access; if ( node->type != IMFS_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); /* * We must have Write and execute permission on the returned node. */ if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_WX ) ) set_errno_and_return_minus_one( EACCES ); return result;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3cf8394af5f646642df593c8de833441e186af64/imfs_eval.c/buggy/cpukit/libfs/src/imfs/imfs_eval.c
char token[ NAME_MAX + 1 ];
char token[ IMFS_NAME_MAX + 1 ];
int IMFS_eval_path( const char *pathname, /* IN */ int flags, /* IN */ rtems_filesystem_location_info_t *pathloc /* IN/OUT */){ int i = 0; int len; IMFS_token_types type = IMFS_CURRENT_DIR; char token[ NAME_MAX + 1 ]; rtems_filesystem_location_info_t newloc; IMFS_jnode_t *node; int result; if ( !rtems_libio_is_valid_perms( flags ) ) { assert( 0 ); set_errno_and_return_minus_one( EIO ); } /* * This was filled in by the caller and is valid in the * mount table. */ node = pathloc->node_access; /* * Evaluate all tokens until we are done or an error occurs. */ while( (type != IMFS_NO_MORE_PATH) && (type != IMFS_INVALID_TOKEN) ) { type = IMFS_get_token( &pathname[i], token, &len ); i += len; if ( !pathloc->node_access ) set_errno_and_return_minus_one( ENOENT ); /* * I cannot move out of this directory without execute permission. */ if ( type != IMFS_NO_MORE_PATH ) if ( node->type == IMFS_DIRECTORY ) if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) ) set_errno_and_return_minus_one( EACCES ); node = pathloc->node_access; switch( type ) { case IMFS_UP_DIR: /* * Am I at the root of this mounted filesystem? */ if (pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access) { /* * Am I at the root of all filesystems? */ if ( pathloc->node_access == rtems_filesystem_root.node_access ) { break; /* Throw out the .. in this case */ } else { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; return (*pathloc->ops->evalpath)(&(pathname[i-len]),flags,pathloc); } } else { if ( !node->Parent ) set_errno_and_return_minus_one( ENOENT ); node = node->Parent; pathloc->node_access = node; } pathloc->node_access = node; break; case IMFS_NAME: /* * If we are at a link follow it. */ if ( node->type == IMFS_HARD_LINK ) { IMFS_evaluate_hard_link( pathloc, 0 ); node = pathloc->node_access; if ( !node ) set_errno_and_return_minus_one( ENOTDIR ); } else if ( node->type == IMFS_SYM_LINK ) { result = IMFS_evaluate_sym_link( pathloc, 0 ); node = pathloc->node_access; if ( result == -1 ) return -1; } /* * Only a directory can be decended into. */ if ( node->type != IMFS_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); /* * If we are at a node that is a mount point. Set loc to the * new fs root node and let them finish evaluating the path. */ if ( node->info.directory.mt_fs != NULL ) { newloc = node->info.directory.mt_fs->mt_fs_root; *pathloc = newloc; return (*pathloc->ops->evalpath)( &pathname[i-len], flags, pathloc ); } /* * Otherwise find the token name in the present location. */ node = IMFS_find_match_in_dir( node, token ); if ( !node ) set_errno_and_return_minus_one( ENOENT ); /* * Set the node access to the point we have found. */ pathloc->node_access = node; break; case IMFS_NO_MORE_PATH: case IMFS_CURRENT_DIR: break; case IMFS_INVALID_TOKEN: set_errno_and_return_minus_one( ENAMETOOLONG ); break; } } /* * Only return root node if this is the base file system. */ if ((pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access) && (pathloc->node_access != rtems_filesystem_root.node_access) ) { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; } result = IMFS_Set_handlers( pathloc ); /* * Verify we have the correct permissions for this node. */ if ( !IMFS_evaluate_permission( pathloc, flags ) ) set_errno_and_return_minus_one( EACCES ); return result;}
10355 /local/tlutelli/issta_data/temp/c/2005_temp/2005/10355/3cf8394af5f646642df593c8de833441e186af64/imfs_eval.c/buggy/cpukit/libfs/src/imfs/imfs_eval.c
GEN ishiftr_spec(GEN x, long lx, long n) { /*This is a kludge since x is not an integer*/
ishiftr_spec(GEN x, long lx, long n) { /*This is a kludge since x is not an integer*/
GEN ishiftr_spec(GEN x, long lx, long n){ /*This is a kludge since x is not an integer*/ return shifti_spec(x, lx, n);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/2edc82b0d172402925241429eca01a236af8dd01/mp.c/buggy/src/kernel/none/mp.c
if (gcmp0(FpC_Fp_mul(gel(vecMsup,i), X, ell))) return 0;
if (gcmp0(FpM_FpC_mul(gel(vecMsup,i),X, ell))) return 0;
ok_congruence(GEN X, GEN ell, long lW, GEN vecMsup){ long i, l; if (gcmp0(X)) return 0; l = lg(X); for (i=lW; i<l; i++) if (gcmp0(gel(X,i))) return 0; l = lg(vecMsup); for (i=1; i<l; i++) if (gcmp0(FpC_Fp_mul(gel(vecMsup,i), X, ell))) return 0; return 1;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/57f0bcc0cb57aaea5971178f69ac0f3cee279153/kummer.c/buggy/src/modules/kummer.c
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q)
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN modpr,GEN q)
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/6da8e45a4f668a23a107c980a7b0f1544ce9ae74/base3.c/clean/src/basemath/base3.c
GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1];
GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)modpr[1];
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/6da8e45a4f668a23a107c980a7b0f1544ce9ae74/base3.c/clean/src/basemath/base3.c
x = lift_intern(nfreducemodpr(nf,x,prhall));
x = lift_intern(nfreducemodpr(nf,x,modpr));
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/6da8e45a4f668a23a107c980a7b0f1544ce9ae74/base3.c/clean/src/basemath/base3.c
g0inv = lift_intern(element_invmodpr(nf,g0,prhall));
g0inv = lift_intern(element_invmodpr(nf,g0,modpr));
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/6da8e45a4f668a23a107c980a7b0f1544ce9ae74/base3.c/clean/src/basemath/base3.c
giant=lift_intern(element_divmodpr(nf,x,p1,prhall));
giant=lift_intern(element_divmodpr(nf,x,p1,modpr));
nfshanks(GEN nf,GEN x,GEN g0,GEN pr,GEN prhall,GEN q){ gpmem_t av=avma,av1,lim; long lbaby,i,k, f = itos((GEN)pr[4]); GEN p1,smalltable,giant,perm,v,g0inv,prh = (GEN)prhall[1]; GEN multab, p = (GEN)pr[1]; x = lift_intern(nfreducemodpr(nf,x,prhall)); p1 = q? q: addsi(-1, gpowgs(p,f)); p1 = racine(p1); if (cmpis(p1,LGBITS) >= 0) err(talker,"module too large in nfshanks"); lbaby=itos(p1)+1; smalltable=cgetg(lbaby+1,t_VEC); g0inv = lift_intern(element_invmodpr(nf,g0,prhall)); p1 = x; multab = eltmul_get_table(nf, g0inv); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); for (i=1;;i++) { if (isnfscalar(p1) && gcmp1((GEN)p1[1])) { avma=av; return stoi(i-1); } smalltable[i]=(long)p1; if (i==lbaby) break; p1 = mul_matvec_mod_pr(multab,p1,prh); } giant=lift_intern(element_divmodpr(nf,x,p1,prhall)); p1=cgetg(lbaby+1,t_VEC); perm = gen_sort(smalltable, cmp_IND | cmp_C, cmp_vecint); for (i=1; i<=lbaby; i++) p1[i]=smalltable[perm[i]]; smalltable=p1; p1=giant; multab = eltmul_get_table(nf, giant); for (i=lg(multab)-1; i; i--) multab[i]=(long)FpV_red((GEN)multab[i], p); av1 = avma; lim=stack_lim(av1,2); for (k=1;;k++) { i=tablesearch(smalltable,p1,cmp_vecint); if (i) { v=addis(mulss(lbaby-1,k),perm[i]); return gerepileuptoint(av,addsi(-1,v)); } p1 = mul_matvec_mod_pr(multab,p1,prh); if (low_stack(lim, stack_lim(av1,2))) { if(DEBUGMEM>1) err(warnmem,"nfshanks"); p1 = gerepileupto(av1, p1); } }}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/6da8e45a4f668a23a107c980a7b0f1544ce9ae74/base3.c/clean/src/basemath/base3.c
GEN pr, C0, C, dk, bad, polbase, pk, init_fa;
GEN pr, C0, C, dk, bad, polbase, pk, init_fa = NULL;
nfsqff(GEN nf, GEN pol, long fl){ long i, m, n, nbf, ct, maxf, dpol = degpol(pol); ulong pp; pari_sp av = avma; GEN pr, C0, C, dk, bad, polbase, pk, init_fa; GEN N2, rep, p, polmod, polred, lt, nfpol; byteptr pt = diffptr; double bestind = 1.; nfcmbf_t T; nflift_t L; pari_timer ti, ti_tot; if (DEBUGLEVEL>2) { TIMERstart(&ti); TIMERstart(&ti_tot); } nfpol = (GEN)nf[1]; n = degpol(nfpol); polbase = unifpol(nf,pol,0); if (typ(polbase) != t_POL) err(typeer, "nfsqff"); polmod = unifpol(nf,pol,1); /* heuristic */ if (dpol*3 < n) { GEN z, t; if (DEBUGLEVEL>2) fprintferr("Using Trager's method\n"); z = (GEN)polfnf(polmod, nfpol)[1]; if (fl) { long l = lg(z); for (i = 1; i < l; i++) { t = (GEN)z[i]; if (degpol(t) > 1) break; z[i] = lneg(gdiv((GEN)t[3], (GEN)t[2])); } setlg(z, i); } return gerepilecopy(av, z); } pol = simplify_i(lift(polmod)); lt = (GEN)leading_term(polbase)[1]; /* t_INT */ if (gcmp1(lt)) lt = NULL; dk = absi((GEN)nf[3]); bad = mulii(dk,(GEN)nf[4]); if (lt) bad = mulii(bad, lt); polred = pr = NULL; /* gcc -Wall */ nbf = 0; pp = 0; L.Tp = NULL; /* FIXME: slow factorization of large polynomials over large Fq */ maxf = (n >= 15)? 6: 1; for (ct = 5;;) { GEN aT, apr, ap, modpr, red; long anbf; double ind; pari_timer ti_pr; GEN list, r = NULL; pari_sp av2 = avma; if (DEBUGLEVEL>3) TIMERstart(&ti_pr); for (;;) { NEXT_PRIME_VIADIFF_CHECK(pp, pt); if (! umodiu(bad,pp)) continue; ap = utoi(pp); list = (GEN)factmod0(nfpol, ap)[1]; if (maxf == 1) { /* deg.1 factors are best */ r = (GEN)list[1]; if (degpol(r) == 1) break; } else { /* otherwise, pick factor of largish degree */ long i, dr; for (i = lg(list)-1; i > 0; i--) { r = (GEN)list[i]; dr = degpol(r); if (dr <= maxf) break; } if (i > 0) break; } avma = av2; } apr = apply_kummer(nf,r,gun,ap); modpr = zk_to_ff_init(nf,&apr,&aT,&ap); red = modprX(polbase, nf, modpr); if (!aT) { /* degree 1 */ red = u_Fp_FpX(red, pp); if (!u_FpX_is_squarefree(red, pp)) continue; anbf = fl? u_FpX_nbroots(red, pp): u_FpX_nbfact(red, pp); } else { GEN q; if (!FqX_is_squarefree(red,aT,ap)) continue; q = gpowgs(ap, degpol(aT)); anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap); } if (fl == 2 && anbf < dpol) return cgetg(1,t_VEC); if (anbf <= 1) { if (!fl) /* irreducible */ return gerepilecopy(av, _vec(QXQ_normalize(polmod, nfpol))); if (!anbf) return cgetg(1,t_VEC); /* no root */ } ind = ((double)anbf) / itos((GEN)apr[4]); if (!nbf || ind <= bestind) { bestind = ind; nbf = anbf; pr = apr; L.Tp = aT; } if (DEBUGLEVEL>3) fprintferr("%3ld %s at prime\n %Z\nTime: %ld\n", nbf, fl?"roots": "factors", apr, TIMER(&ti_pr)); if (--ct <= 0) break; } if (DEBUGLEVEL>2) { msgTIMER(&ti, "choice of a prime ideal"); fprintferr("Prime ideal chosen: %Z\n", pr); } p = (GEN)pr[1]; L.tozk = (GEN)nf[8]; L.topow= Q_remove_denom((GEN)nf[7], &L.topowden); T.ZC = L2_bound(nf, L.tozk, &(T.dn)); T.Br = nf_root_bounds(pol, nf); if (lt) T.Br = gmul(T.Br, lt); if (fl) C0 = normlp(T.Br, 2, n); else C0 = nf_factor_bound(nf, polbase); /* bound for T_2(Q_i), Q | P */ C = mulrr(T.ZC, C0); /* bound for |Q_i|^2 in Z^n on chosen Z-basis */ T.bound = C; N2 = mulsr(dpol*dpol, normlp(T.Br, 4, n)); /* bound for T_2(lt * S_2) */ T.BS_2 = mulrr(T.ZC, N2); /* bound for |S_2|^2 on chosen Z-basis */ if (DEBUGLEVEL>2) { msgTIMER(&ti, "bound computation"); fprintferr(" 1) T_2 bound for %s: %Z\n", fl?"root":"factor", C0); fprintferr(" 2) Conversion from T_2 --> | |^2 bound : %Z\n", T.ZC); fprintferr(" 3) Final bound: %Z\n", C); } if (L.Tp && degpol(L.Tp) == 1) L.Tp = NULL; bestlift_init(0, nf, pr, C, &L); T.pr = pr; T.L = &L; init_proj(&L, nfpol, p); pk = L.pk; polred = polbase; if (lt) polred = gmul(mpinvmod(lt,pk), polred); polred = ZqX(polred, pk, L.Tpk, L.ZqProj); /* polred is monic */ if (fl) { /* roots only */ long Cltx_r[] = { evaltyp(t_POL)|_evallg(4), 0,0,0 }; GEN C2ltpol, C = L.topowden; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); if (L.Tpk) { int cof = (dpol > nbf); /* non trivial cofactor ? */ rep = FqX_split_roots(init_fa, L.Tp, p, cof? polred: NULL); rep = hensel_lift_fact(polred, rep, L.Tpk, p, pk, L.k); if (cof) setlg(rep, lg(rep)-1); /* remove cofactor */ rep = roots_from_deg1(rep); } else rep = rootpadicfast(polred, p, L.k); Cltx_r[1] = evalsigne(1) | evalvarn(varn(pol)) | evallgef(4); Cltx_r[3] = Clt? (long)Clt: un; C2ltpol = C2lt? gmul(C2lt, pol): pol; for (m=1,i=1; i<lg(rep); i++) { GEN q, r = (GEN)rep[i]; r = nf_bestlift_to_pol(r, NULL, &L); Cltx_r[2] = lneg(r); /* check P(r) == 0 */ q = RXQX_divrem(C2ltpol, Cltx_r, nfpol, ONLY_DIVIDES); /* integral */ if (q) { C2ltpol = C2lt? gmul(Clt,q): q; if (Clt) r = gdiv(r, Clt); rep[m++] = (long)r; } else if (fl == 2) return cgetg(1, t_VEC); } rep[0] = evaltyp(t_VEC) | evallg(m); return gerepilecopy(av, rep); } if (L.Tp) rep = FqX_split_all(init_fa, L.Tp, p); else { long d; rep = cgetg(dpol + 1, t_VEC); rep[1] = (long)polred; d = FpX_split_berlekamp((GEN*)(rep + 1), p); setlg(rep, d + 1); } T.fact = rep; T.polbase = polbase; T.pol = pol; T.nf = nf; T.hint = 1; /* useless */ rep = nf_combine_factors(&T, polred, p, L.k, dpol-1); if (DEBUGLEVEL>2) fprintferr("Total Time: %ld\n===========\n", TIMER(&ti)); return gerepileupto(av, rep);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/ad0d1bcf58030be7a5b95bb7a98336799512ea9c/nffactor.c/clean/src/modules/nffactor.c
GEN list, r = NULL;
GEN list, r = NULL, fa = NULL;
nfsqff(GEN nf, GEN pol, long fl){ long i, m, n, nbf, ct, maxf, dpol = degpol(pol); ulong pp; pari_sp av = avma; GEN pr, C0, C, dk, bad, polbase, pk, init_fa; GEN N2, rep, p, polmod, polred, lt, nfpol; byteptr pt = diffptr; double bestind = 1.; nfcmbf_t T; nflift_t L; pari_timer ti, ti_tot; if (DEBUGLEVEL>2) { TIMERstart(&ti); TIMERstart(&ti_tot); } nfpol = (GEN)nf[1]; n = degpol(nfpol); polbase = unifpol(nf,pol,0); if (typ(polbase) != t_POL) err(typeer, "nfsqff"); polmod = unifpol(nf,pol,1); /* heuristic */ if (dpol*3 < n) { GEN z, t; if (DEBUGLEVEL>2) fprintferr("Using Trager's method\n"); z = (GEN)polfnf(polmod, nfpol)[1]; if (fl) { long l = lg(z); for (i = 1; i < l; i++) { t = (GEN)z[i]; if (degpol(t) > 1) break; z[i] = lneg(gdiv((GEN)t[3], (GEN)t[2])); } setlg(z, i); } return gerepilecopy(av, z); } pol = simplify_i(lift(polmod)); lt = (GEN)leading_term(polbase)[1]; /* t_INT */ if (gcmp1(lt)) lt = NULL; dk = absi((GEN)nf[3]); bad = mulii(dk,(GEN)nf[4]); if (lt) bad = mulii(bad, lt); polred = pr = NULL; /* gcc -Wall */ nbf = 0; pp = 0; L.Tp = NULL; /* FIXME: slow factorization of large polynomials over large Fq */ maxf = (n >= 15)? 6: 1; for (ct = 5;;) { GEN aT, apr, ap, modpr, red; long anbf; double ind; pari_timer ti_pr; GEN list, r = NULL; pari_sp av2 = avma; if (DEBUGLEVEL>3) TIMERstart(&ti_pr); for (;;) { NEXT_PRIME_VIADIFF_CHECK(pp, pt); if (! umodiu(bad,pp)) continue; ap = utoi(pp); list = (GEN)factmod0(nfpol, ap)[1]; if (maxf == 1) { /* deg.1 factors are best */ r = (GEN)list[1]; if (degpol(r) == 1) break; } else { /* otherwise, pick factor of largish degree */ long i, dr; for (i = lg(list)-1; i > 0; i--) { r = (GEN)list[i]; dr = degpol(r); if (dr <= maxf) break; } if (i > 0) break; } avma = av2; } apr = apply_kummer(nf,r,gun,ap); modpr = zk_to_ff_init(nf,&apr,&aT,&ap); red = modprX(polbase, nf, modpr); if (!aT) { /* degree 1 */ red = u_Fp_FpX(red, pp); if (!u_FpX_is_squarefree(red, pp)) continue; anbf = fl? u_FpX_nbroots(red, pp): u_FpX_nbfact(red, pp); } else { GEN q; if (!FqX_is_squarefree(red,aT,ap)) continue; q = gpowgs(ap, degpol(aT)); anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap); } if (fl == 2 && anbf < dpol) return cgetg(1,t_VEC); if (anbf <= 1) { if (!fl) /* irreducible */ return gerepilecopy(av, _vec(QXQ_normalize(polmod, nfpol))); if (!anbf) return cgetg(1,t_VEC); /* no root */ } ind = ((double)anbf) / itos((GEN)apr[4]); if (!nbf || ind <= bestind) { bestind = ind; nbf = anbf; pr = apr; L.Tp = aT; } if (DEBUGLEVEL>3) fprintferr("%3ld %s at prime\n %Z\nTime: %ld\n", nbf, fl?"roots": "factors", apr, TIMER(&ti_pr)); if (--ct <= 0) break; } if (DEBUGLEVEL>2) { msgTIMER(&ti, "choice of a prime ideal"); fprintferr("Prime ideal chosen: %Z\n", pr); } p = (GEN)pr[1]; L.tozk = (GEN)nf[8]; L.topow= Q_remove_denom((GEN)nf[7], &L.topowden); T.ZC = L2_bound(nf, L.tozk, &(T.dn)); T.Br = nf_root_bounds(pol, nf); if (lt) T.Br = gmul(T.Br, lt); if (fl) C0 = normlp(T.Br, 2, n); else C0 = nf_factor_bound(nf, polbase); /* bound for T_2(Q_i), Q | P */ C = mulrr(T.ZC, C0); /* bound for |Q_i|^2 in Z^n on chosen Z-basis */ T.bound = C; N2 = mulsr(dpol*dpol, normlp(T.Br, 4, n)); /* bound for T_2(lt * S_2) */ T.BS_2 = mulrr(T.ZC, N2); /* bound for |S_2|^2 on chosen Z-basis */ if (DEBUGLEVEL>2) { msgTIMER(&ti, "bound computation"); fprintferr(" 1) T_2 bound for %s: %Z\n", fl?"root":"factor", C0); fprintferr(" 2) Conversion from T_2 --> | |^2 bound : %Z\n", T.ZC); fprintferr(" 3) Final bound: %Z\n", C); } if (L.Tp && degpol(L.Tp) == 1) L.Tp = NULL; bestlift_init(0, nf, pr, C, &L); T.pr = pr; T.L = &L; init_proj(&L, nfpol, p); pk = L.pk; polred = polbase; if (lt) polred = gmul(mpinvmod(lt,pk), polred); polred = ZqX(polred, pk, L.Tpk, L.ZqProj); /* polred is monic */ if (fl) { /* roots only */ long Cltx_r[] = { evaltyp(t_POL)|_evallg(4), 0,0,0 }; GEN C2ltpol, C = L.topowden; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); if (L.Tpk) { int cof = (dpol > nbf); /* non trivial cofactor ? */ rep = FqX_split_roots(init_fa, L.Tp, p, cof? polred: NULL); rep = hensel_lift_fact(polred, rep, L.Tpk, p, pk, L.k); if (cof) setlg(rep, lg(rep)-1); /* remove cofactor */ rep = roots_from_deg1(rep); } else rep = rootpadicfast(polred, p, L.k); Cltx_r[1] = evalsigne(1) | evalvarn(varn(pol)) | evallgef(4); Cltx_r[3] = Clt? (long)Clt: un; C2ltpol = C2lt? gmul(C2lt, pol): pol; for (m=1,i=1; i<lg(rep); i++) { GEN q, r = (GEN)rep[i]; r = nf_bestlift_to_pol(r, NULL, &L); Cltx_r[2] = lneg(r); /* check P(r) == 0 */ q = RXQX_divrem(C2ltpol, Cltx_r, nfpol, ONLY_DIVIDES); /* integral */ if (q) { C2ltpol = C2lt? gmul(Clt,q): q; if (Clt) r = gdiv(r, Clt); rep[m++] = (long)r; } else if (fl == 2) return cgetg(1, t_VEC); } rep[0] = evaltyp(t_VEC) | evallg(m); return gerepilecopy(av, rep); } if (L.Tp) rep = FqX_split_all(init_fa, L.Tp, p); else { long d; rep = cgetg(dpol + 1, t_VEC); rep[1] = (long)polred; d = FpX_split_berlekamp((GEN*)(rep + 1), p); setlg(rep, d + 1); } T.fact = rep; T.polbase = polbase; T.pol = pol; T.nf = nf; T.hint = 1; /* useless */ rep = nf_combine_factors(&T, polred, p, L.k, dpol-1); if (DEBUGLEVEL>2) fprintferr("Total Time: %ld\n===========\n", TIMER(&ti)); return gerepileupto(av, rep);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/ad0d1bcf58030be7a5b95bb7a98336799512ea9c/nffactor.c/clean/src/modules/nffactor.c
anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap);
anbf = fl? FqX_split_deg1(&fa, red, q, aT, ap) : FqX_split_by_degree(&fa, red, q, aT, ap);
nfsqff(GEN nf, GEN pol, long fl){ long i, m, n, nbf, ct, maxf, dpol = degpol(pol); ulong pp; pari_sp av = avma; GEN pr, C0, C, dk, bad, polbase, pk, init_fa; GEN N2, rep, p, polmod, polred, lt, nfpol; byteptr pt = diffptr; double bestind = 1.; nfcmbf_t T; nflift_t L; pari_timer ti, ti_tot; if (DEBUGLEVEL>2) { TIMERstart(&ti); TIMERstart(&ti_tot); } nfpol = (GEN)nf[1]; n = degpol(nfpol); polbase = unifpol(nf,pol,0); if (typ(polbase) != t_POL) err(typeer, "nfsqff"); polmod = unifpol(nf,pol,1); /* heuristic */ if (dpol*3 < n) { GEN z, t; if (DEBUGLEVEL>2) fprintferr("Using Trager's method\n"); z = (GEN)polfnf(polmod, nfpol)[1]; if (fl) { long l = lg(z); for (i = 1; i < l; i++) { t = (GEN)z[i]; if (degpol(t) > 1) break; z[i] = lneg(gdiv((GEN)t[3], (GEN)t[2])); } setlg(z, i); } return gerepilecopy(av, z); } pol = simplify_i(lift(polmod)); lt = (GEN)leading_term(polbase)[1]; /* t_INT */ if (gcmp1(lt)) lt = NULL; dk = absi((GEN)nf[3]); bad = mulii(dk,(GEN)nf[4]); if (lt) bad = mulii(bad, lt); polred = pr = NULL; /* gcc -Wall */ nbf = 0; pp = 0; L.Tp = NULL; /* FIXME: slow factorization of large polynomials over large Fq */ maxf = (n >= 15)? 6: 1; for (ct = 5;;) { GEN aT, apr, ap, modpr, red; long anbf; double ind; pari_timer ti_pr; GEN list, r = NULL; pari_sp av2 = avma; if (DEBUGLEVEL>3) TIMERstart(&ti_pr); for (;;) { NEXT_PRIME_VIADIFF_CHECK(pp, pt); if (! umodiu(bad,pp)) continue; ap = utoi(pp); list = (GEN)factmod0(nfpol, ap)[1]; if (maxf == 1) { /* deg.1 factors are best */ r = (GEN)list[1]; if (degpol(r) == 1) break; } else { /* otherwise, pick factor of largish degree */ long i, dr; for (i = lg(list)-1; i > 0; i--) { r = (GEN)list[i]; dr = degpol(r); if (dr <= maxf) break; } if (i > 0) break; } avma = av2; } apr = apply_kummer(nf,r,gun,ap); modpr = zk_to_ff_init(nf,&apr,&aT,&ap); red = modprX(polbase, nf, modpr); if (!aT) { /* degree 1 */ red = u_Fp_FpX(red, pp); if (!u_FpX_is_squarefree(red, pp)) continue; anbf = fl? u_FpX_nbroots(red, pp): u_FpX_nbfact(red, pp); } else { GEN q; if (!FqX_is_squarefree(red,aT,ap)) continue; q = gpowgs(ap, degpol(aT)); anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap); } if (fl == 2 && anbf < dpol) return cgetg(1,t_VEC); if (anbf <= 1) { if (!fl) /* irreducible */ return gerepilecopy(av, _vec(QXQ_normalize(polmod, nfpol))); if (!anbf) return cgetg(1,t_VEC); /* no root */ } ind = ((double)anbf) / itos((GEN)apr[4]); if (!nbf || ind <= bestind) { bestind = ind; nbf = anbf; pr = apr; L.Tp = aT; } if (DEBUGLEVEL>3) fprintferr("%3ld %s at prime\n %Z\nTime: %ld\n", nbf, fl?"roots": "factors", apr, TIMER(&ti_pr)); if (--ct <= 0) break; } if (DEBUGLEVEL>2) { msgTIMER(&ti, "choice of a prime ideal"); fprintferr("Prime ideal chosen: %Z\n", pr); } p = (GEN)pr[1]; L.tozk = (GEN)nf[8]; L.topow= Q_remove_denom((GEN)nf[7], &L.topowden); T.ZC = L2_bound(nf, L.tozk, &(T.dn)); T.Br = nf_root_bounds(pol, nf); if (lt) T.Br = gmul(T.Br, lt); if (fl) C0 = normlp(T.Br, 2, n); else C0 = nf_factor_bound(nf, polbase); /* bound for T_2(Q_i), Q | P */ C = mulrr(T.ZC, C0); /* bound for |Q_i|^2 in Z^n on chosen Z-basis */ T.bound = C; N2 = mulsr(dpol*dpol, normlp(T.Br, 4, n)); /* bound for T_2(lt * S_2) */ T.BS_2 = mulrr(T.ZC, N2); /* bound for |S_2|^2 on chosen Z-basis */ if (DEBUGLEVEL>2) { msgTIMER(&ti, "bound computation"); fprintferr(" 1) T_2 bound for %s: %Z\n", fl?"root":"factor", C0); fprintferr(" 2) Conversion from T_2 --> | |^2 bound : %Z\n", T.ZC); fprintferr(" 3) Final bound: %Z\n", C); } if (L.Tp && degpol(L.Tp) == 1) L.Tp = NULL; bestlift_init(0, nf, pr, C, &L); T.pr = pr; T.L = &L; init_proj(&L, nfpol, p); pk = L.pk; polred = polbase; if (lt) polred = gmul(mpinvmod(lt,pk), polred); polred = ZqX(polred, pk, L.Tpk, L.ZqProj); /* polred is monic */ if (fl) { /* roots only */ long Cltx_r[] = { evaltyp(t_POL)|_evallg(4), 0,0,0 }; GEN C2ltpol, C = L.topowden; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); if (L.Tpk) { int cof = (dpol > nbf); /* non trivial cofactor ? */ rep = FqX_split_roots(init_fa, L.Tp, p, cof? polred: NULL); rep = hensel_lift_fact(polred, rep, L.Tpk, p, pk, L.k); if (cof) setlg(rep, lg(rep)-1); /* remove cofactor */ rep = roots_from_deg1(rep); } else rep = rootpadicfast(polred, p, L.k); Cltx_r[1] = evalsigne(1) | evalvarn(varn(pol)) | evallgef(4); Cltx_r[3] = Clt? (long)Clt: un; C2ltpol = C2lt? gmul(C2lt, pol): pol; for (m=1,i=1; i<lg(rep); i++) { GEN q, r = (GEN)rep[i]; r = nf_bestlift_to_pol(r, NULL, &L); Cltx_r[2] = lneg(r); /* check P(r) == 0 */ q = RXQX_divrem(C2ltpol, Cltx_r, nfpol, ONLY_DIVIDES); /* integral */ if (q) { C2ltpol = C2lt? gmul(Clt,q): q; if (Clt) r = gdiv(r, Clt); rep[m++] = (long)r; } else if (fl == 2) return cgetg(1, t_VEC); } rep[0] = evaltyp(t_VEC) | evallg(m); return gerepilecopy(av, rep); } if (L.Tp) rep = FqX_split_all(init_fa, L.Tp, p); else { long d; rep = cgetg(dpol + 1, t_VEC); rep[1] = (long)polred; d = FpX_split_berlekamp((GEN*)(rep + 1), p); setlg(rep, d + 1); } T.fact = rep; T.polbase = polbase; T.pol = pol; T.nf = nf; T.hint = 1; /* useless */ rep = nf_combine_factors(&T, polred, p, L.k, dpol-1); if (DEBUGLEVEL>2) fprintferr("Total Time: %ld\n===========\n", TIMER(&ti)); return gerepileupto(av, rep);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/ad0d1bcf58030be7a5b95bb7a98336799512ea9c/nffactor.c/clean/src/modules/nffactor.c
L.Tp = aT;
L.Tp = aT; init_fa = fa;
nfsqff(GEN nf, GEN pol, long fl){ long i, m, n, nbf, ct, maxf, dpol = degpol(pol); ulong pp; pari_sp av = avma; GEN pr, C0, C, dk, bad, polbase, pk, init_fa; GEN N2, rep, p, polmod, polred, lt, nfpol; byteptr pt = diffptr; double bestind = 1.; nfcmbf_t T; nflift_t L; pari_timer ti, ti_tot; if (DEBUGLEVEL>2) { TIMERstart(&ti); TIMERstart(&ti_tot); } nfpol = (GEN)nf[1]; n = degpol(nfpol); polbase = unifpol(nf,pol,0); if (typ(polbase) != t_POL) err(typeer, "nfsqff"); polmod = unifpol(nf,pol,1); /* heuristic */ if (dpol*3 < n) { GEN z, t; if (DEBUGLEVEL>2) fprintferr("Using Trager's method\n"); z = (GEN)polfnf(polmod, nfpol)[1]; if (fl) { long l = lg(z); for (i = 1; i < l; i++) { t = (GEN)z[i]; if (degpol(t) > 1) break; z[i] = lneg(gdiv((GEN)t[3], (GEN)t[2])); } setlg(z, i); } return gerepilecopy(av, z); } pol = simplify_i(lift(polmod)); lt = (GEN)leading_term(polbase)[1]; /* t_INT */ if (gcmp1(lt)) lt = NULL; dk = absi((GEN)nf[3]); bad = mulii(dk,(GEN)nf[4]); if (lt) bad = mulii(bad, lt); polred = pr = NULL; /* gcc -Wall */ nbf = 0; pp = 0; L.Tp = NULL; /* FIXME: slow factorization of large polynomials over large Fq */ maxf = (n >= 15)? 6: 1; for (ct = 5;;) { GEN aT, apr, ap, modpr, red; long anbf; double ind; pari_timer ti_pr; GEN list, r = NULL; pari_sp av2 = avma; if (DEBUGLEVEL>3) TIMERstart(&ti_pr); for (;;) { NEXT_PRIME_VIADIFF_CHECK(pp, pt); if (! umodiu(bad,pp)) continue; ap = utoi(pp); list = (GEN)factmod0(nfpol, ap)[1]; if (maxf == 1) { /* deg.1 factors are best */ r = (GEN)list[1]; if (degpol(r) == 1) break; } else { /* otherwise, pick factor of largish degree */ long i, dr; for (i = lg(list)-1; i > 0; i--) { r = (GEN)list[i]; dr = degpol(r); if (dr <= maxf) break; } if (i > 0) break; } avma = av2; } apr = apply_kummer(nf,r,gun,ap); modpr = zk_to_ff_init(nf,&apr,&aT,&ap); red = modprX(polbase, nf, modpr); if (!aT) { /* degree 1 */ red = u_Fp_FpX(red, pp); if (!u_FpX_is_squarefree(red, pp)) continue; anbf = fl? u_FpX_nbroots(red, pp): u_FpX_nbfact(red, pp); } else { GEN q; if (!FqX_is_squarefree(red,aT,ap)) continue; q = gpowgs(ap, degpol(aT)); anbf = fl? FqX_split_deg1(&init_fa, red, q, aT, ap) : FqX_split_by_degree(&init_fa, red, q, aT, ap); } if (fl == 2 && anbf < dpol) return cgetg(1,t_VEC); if (anbf <= 1) { if (!fl) /* irreducible */ return gerepilecopy(av, _vec(QXQ_normalize(polmod, nfpol))); if (!anbf) return cgetg(1,t_VEC); /* no root */ } ind = ((double)anbf) / itos((GEN)apr[4]); if (!nbf || ind <= bestind) { bestind = ind; nbf = anbf; pr = apr; L.Tp = aT; } if (DEBUGLEVEL>3) fprintferr("%3ld %s at prime\n %Z\nTime: %ld\n", nbf, fl?"roots": "factors", apr, TIMER(&ti_pr)); if (--ct <= 0) break; } if (DEBUGLEVEL>2) { msgTIMER(&ti, "choice of a prime ideal"); fprintferr("Prime ideal chosen: %Z\n", pr); } p = (GEN)pr[1]; L.tozk = (GEN)nf[8]; L.topow= Q_remove_denom((GEN)nf[7], &L.topowden); T.ZC = L2_bound(nf, L.tozk, &(T.dn)); T.Br = nf_root_bounds(pol, nf); if (lt) T.Br = gmul(T.Br, lt); if (fl) C0 = normlp(T.Br, 2, n); else C0 = nf_factor_bound(nf, polbase); /* bound for T_2(Q_i), Q | P */ C = mulrr(T.ZC, C0); /* bound for |Q_i|^2 in Z^n on chosen Z-basis */ T.bound = C; N2 = mulsr(dpol*dpol, normlp(T.Br, 4, n)); /* bound for T_2(lt * S_2) */ T.BS_2 = mulrr(T.ZC, N2); /* bound for |S_2|^2 on chosen Z-basis */ if (DEBUGLEVEL>2) { msgTIMER(&ti, "bound computation"); fprintferr(" 1) T_2 bound for %s: %Z\n", fl?"root":"factor", C0); fprintferr(" 2) Conversion from T_2 --> | |^2 bound : %Z\n", T.ZC); fprintferr(" 3) Final bound: %Z\n", C); } if (L.Tp && degpol(L.Tp) == 1) L.Tp = NULL; bestlift_init(0, nf, pr, C, &L); T.pr = pr; T.L = &L; init_proj(&L, nfpol, p); pk = L.pk; polred = polbase; if (lt) polred = gmul(mpinvmod(lt,pk), polred); polred = ZqX(polred, pk, L.Tpk, L.ZqProj); /* polred is monic */ if (fl) { /* roots only */ long Cltx_r[] = { evaltyp(t_POL)|_evallg(4), 0,0,0 }; GEN C2ltpol, C = L.topowden; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); if (L.Tpk) { int cof = (dpol > nbf); /* non trivial cofactor ? */ rep = FqX_split_roots(init_fa, L.Tp, p, cof? polred: NULL); rep = hensel_lift_fact(polred, rep, L.Tpk, p, pk, L.k); if (cof) setlg(rep, lg(rep)-1); /* remove cofactor */ rep = roots_from_deg1(rep); } else rep = rootpadicfast(polred, p, L.k); Cltx_r[1] = evalsigne(1) | evalvarn(varn(pol)) | evallgef(4); Cltx_r[3] = Clt? (long)Clt: un; C2ltpol = C2lt? gmul(C2lt, pol): pol; for (m=1,i=1; i<lg(rep); i++) { GEN q, r = (GEN)rep[i]; r = nf_bestlift_to_pol(r, NULL, &L); Cltx_r[2] = lneg(r); /* check P(r) == 0 */ q = RXQX_divrem(C2ltpol, Cltx_r, nfpol, ONLY_DIVIDES); /* integral */ if (q) { C2ltpol = C2lt? gmul(Clt,q): q; if (Clt) r = gdiv(r, Clt); rep[m++] = (long)r; } else if (fl == 2) return cgetg(1, t_VEC); } rep[0] = evaltyp(t_VEC) | evallg(m); return gerepilecopy(av, rep); } if (L.Tp) rep = FqX_split_all(init_fa, L.Tp, p); else { long d; rep = cgetg(dpol + 1, t_VEC); rep[1] = (long)polred; d = FpX_split_berlekamp((GEN*)(rep + 1), p); setlg(rep, d + 1); } T.fact = rep; T.polbase = polbase; T.pol = pol; T.nf = nf; T.hint = 1; /* useless */ rep = nf_combine_factors(&T, polred, p, L.k, dpol-1); if (DEBUGLEVEL>2) fprintferr("Total Time: %ld\n===========\n", TIMER(&ti)); return gerepileupto(av, rep);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/ad0d1bcf58030be7a5b95bb7a98336799512ea9c/nffactor.c/clean/src/modules/nffactor.c
res[2] = (long)_vec(T->fact);
res[2] = (long)T->fact;
nfcmbf(nfcmbf_t *T, GEN p, long a, long maxK, long klim){ long Sbound; GEN pol = T->pol, nf = T->nf, famod = T->fact, dn = T->dn; GEN bound = T->bound; GEN nfpol = (GEN)nf[1]; long K = 1, cnt = 1, i,j,k, curdeg, lfamod = lg(famod)-1, dnf = degpol(nfpol); GEN res = cgetg(3, t_VEC); pari_sp av0 = avma; GEN pk = gpowgs(p,a), pks2 = shifti(pk,-1); GEN trace1 = cgetg(lfamod+1, t_MAT); GEN trace2 = cgetg(lfamod+1, t_MAT); GEN ind = cgetg(lfamod+1, t_VECSMALL); GEN degpol = cgetg(lfamod+1, t_VECSMALL); GEN degsofar = cgetg(lfamod+1, t_VECSMALL); GEN listmod = cgetg(lfamod+1, t_COL); GEN fa = cgetg(lfamod+1, t_COL); GEN q = ceil_safe(mpsqrt(T->BS_2)); GEN lc = absi(leading_term(pol)), lt = is_pm1(lc)? NULL: lc; GEN C2ltpol, C = T->L->topowden, Tpk = T->L->Tpk; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); const double Bhigh = get_Bhigh(lfamod, dnf); trace_data _T1, _T2, *T1, *T2; pari_timer ti; TIMERstart(&ti); if (maxK < 0) maxK = lfamod-1; C2ltpol = C2lt? gmul(C2lt,pol): pol; { GEN t1,t2, ltdn, lt2dn; ltdn = mul_content(lt, dn); lt2dn= mul_content(ltdn, lt); for (i=1; i <= lfamod; i++) { GEN P = (GEN)famod[i]; long d = degpol(P); degpol[i] = d; P += 2; t1 = (GEN)P[d-1];/* = - S_1 */ t2 = gsqr(t1); if (d > 1) t2 = gsub(t2, gmul2n((GEN)P[d-2], 1)); t2 = Tpk? FpX_rem(t2, Tpk, pk): modii(t2, pk); /* = S_2 Newton sum */ if (lt) { t1 = FpX_red(gmul(ltdn, t1), pk); t2 = FpX_red(gmul(lt2dn,t2), pk); } trace1[i] = (long)nf_bestlift(t1, NULL, T->L); trace2[i] = (long)nf_bestlift(t2, NULL, T->L); } T1 = init_trace(&_T1, trace1, T->L, q); T2 = init_trace(&_T2, trace2, T->L, q); } degsofar[0] = 0; /* sentinel */ /* ind runs through strictly increasing sequences of length K, * 1 <= ind[i] <= lfamod */nextK: if (K > maxK || 2*K > lfamod) goto END; if (DEBUGLEVEL > 3) fprintferr("\n### K = %d, %Z combinations\n", K,binome(stoi(lfamod), K)); setlg(ind, K+1); ind[1] = 1; Sbound = ((K+1)>>1); i = 1; curdeg = degpol[ind[1]]; for(;;) { /* try all combinations of K factors */ for (j = i; j < K; j++) { degsofar[j] = curdeg; ind[j+1] = ind[j]+1; curdeg += degpol[ind[j+1]]; } if (curdeg <= klim && curdeg % T->hint == 0) /* trial divide */ { GEN t, y, q, list; pari_sp av; av = avma; /* d - 1 test */ if (T1) { t = get_trace(ind, T1); if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh) { if (DEBUGLEVEL>6) fprintferr("."); avma = av; goto NEXT; } } /* d - 2 test */ if (T2) { t = get_trace(ind, T2); if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh) { if (DEBUGLEVEL>3) fprintferr("|"); avma = av; goto NEXT; } } avma = av; y = lt; /* full computation */ for (i=1; i<=K; i++) { GEN q = (GEN)famod[ind[i]]; if (y) q = gmul(y, q); y = FqX_centermod(q, Tpk, pk, pks2); } y = nf_pol_lift(y, bound, T); if (!y) { if (DEBUGLEVEL>3) fprintferr("@"); avma = av; goto NEXT; } /* try out the new combination: y is the candidate factor */ q = RXQX_divrem(C2ltpol, y, nfpol, ONLY_DIVIDES); if (!q) { if (DEBUGLEVEL>3) fprintferr("*"); avma = av; goto NEXT; } /* found a factor */ list = cgetg(K+1, t_VEC); listmod[cnt] = (long)list; for (i=1; i<=K; i++) list[i] = famod[ind[i]]; y = Q_primpart(y); fa[cnt++] = (long)QXQ_normalize(y, nfpol); /* fix up pol */ pol = q; for (i=j=k=1; i <= lfamod; i++) { /* remove used factors */ if (j <= K && i == ind[j]) j++; else { famod[k] = famod[i]; update_trace(T1, k, i); update_trace(T2, k, i); degpol[k] = degpol[i]; k++; } } lfamod -= K; if (lfamod < 2*K) goto END; i = 1; curdeg = degpol[ind[1]]; if (C2lt) pol = Q_primpart(pol); if (lt) lt = absi(leading_term(pol)); Clt = mul_content(C, lt); C2lt = mul_content(C,Clt); C2ltpol = C2lt? gmul(C2lt,pol): pol; if (DEBUGLEVEL > 2) { fprintferr("\n"); msgTIMER(&ti, "to find factor %Z",y); fprintferr("remaining modular factor(s): %ld\n", lfamod); } continue; }NEXT: for (i = K+1;;) { if (--i == 0) { K++; goto nextK; } if (++ind[i] <= lfamod - K + i) { curdeg = degsofar[i-1] + degpol[ind[i]]; if (curdeg <= klim) break; } } }END: if (degpol(pol) > 0) { /* leftover factor */ if (signe(leading_term(pol)) < 0) pol = gneg_i(pol); if (C2lt && lfamod < 2*K) pol = QXQ_normalize(Q_primpart(pol), nfpol); setlg(famod, lfamod+1); listmod[cnt] = (long)dummycopy(famod); fa[cnt++] = (long)pol; } if (DEBUGLEVEL>6) fprintferr("\n"); if (cnt == 2) { avma = av0; res[1] = (long)_vec(T->pol); res[2] = (long)_vec(T->fact); } else { setlg(listmod, cnt); setlg(fa, cnt); res[1] = (long)fa; res[2] = (long)listmod; gerepilecopy(av0, res); } return res;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fbffc11008a0932ab8699e70f9e65b2911a26ac/nffactor.c/clean/src/modules/nffactor.c
gerepilecopy(av0, res);
res = gerepilecopy(av0, res);
nfcmbf(nfcmbf_t *T, GEN p, long a, long maxK, long klim){ long Sbound; GEN pol = T->pol, nf = T->nf, famod = T->fact, dn = T->dn; GEN bound = T->bound; GEN nfpol = (GEN)nf[1]; long K = 1, cnt = 1, i,j,k, curdeg, lfamod = lg(famod)-1, dnf = degpol(nfpol); GEN res = cgetg(3, t_VEC); pari_sp av0 = avma; GEN pk = gpowgs(p,a), pks2 = shifti(pk,-1); GEN trace1 = cgetg(lfamod+1, t_MAT); GEN trace2 = cgetg(lfamod+1, t_MAT); GEN ind = cgetg(lfamod+1, t_VECSMALL); GEN degpol = cgetg(lfamod+1, t_VECSMALL); GEN degsofar = cgetg(lfamod+1, t_VECSMALL); GEN listmod = cgetg(lfamod+1, t_COL); GEN fa = cgetg(lfamod+1, t_COL); GEN q = ceil_safe(mpsqrt(T->BS_2)); GEN lc = absi(leading_term(pol)), lt = is_pm1(lc)? NULL: lc; GEN C2ltpol, C = T->L->topowden, Tpk = T->L->Tpk; GEN Clt = mul_content(C, lt); GEN C2lt = mul_content(C,Clt); const double Bhigh = get_Bhigh(lfamod, dnf); trace_data _T1, _T2, *T1, *T2; pari_timer ti; TIMERstart(&ti); if (maxK < 0) maxK = lfamod-1; C2ltpol = C2lt? gmul(C2lt,pol): pol; { GEN t1,t2, ltdn, lt2dn; ltdn = mul_content(lt, dn); lt2dn= mul_content(ltdn, lt); for (i=1; i <= lfamod; i++) { GEN P = (GEN)famod[i]; long d = degpol(P); degpol[i] = d; P += 2; t1 = (GEN)P[d-1];/* = - S_1 */ t2 = gsqr(t1); if (d > 1) t2 = gsub(t2, gmul2n((GEN)P[d-2], 1)); t2 = Tpk? FpX_rem(t2, Tpk, pk): modii(t2, pk); /* = S_2 Newton sum */ if (lt) { t1 = FpX_red(gmul(ltdn, t1), pk); t2 = FpX_red(gmul(lt2dn,t2), pk); } trace1[i] = (long)nf_bestlift(t1, NULL, T->L); trace2[i] = (long)nf_bestlift(t2, NULL, T->L); } T1 = init_trace(&_T1, trace1, T->L, q); T2 = init_trace(&_T2, trace2, T->L, q); } degsofar[0] = 0; /* sentinel */ /* ind runs through strictly increasing sequences of length K, * 1 <= ind[i] <= lfamod */nextK: if (K > maxK || 2*K > lfamod) goto END; if (DEBUGLEVEL > 3) fprintferr("\n### K = %d, %Z combinations\n", K,binome(stoi(lfamod), K)); setlg(ind, K+1); ind[1] = 1; Sbound = ((K+1)>>1); i = 1; curdeg = degpol[ind[1]]; for(;;) { /* try all combinations of K factors */ for (j = i; j < K; j++) { degsofar[j] = curdeg; ind[j+1] = ind[j]+1; curdeg += degpol[ind[j+1]]; } if (curdeg <= klim && curdeg % T->hint == 0) /* trial divide */ { GEN t, y, q, list; pari_sp av; av = avma; /* d - 1 test */ if (T1) { t = get_trace(ind, T1); if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh) { if (DEBUGLEVEL>6) fprintferr("."); avma = av; goto NEXT; } } /* d - 2 test */ if (T2) { t = get_trace(ind, T2); if (rtodbl(QuickNormL2(t,DEFAULTPREC)) > Bhigh) { if (DEBUGLEVEL>3) fprintferr("|"); avma = av; goto NEXT; } } avma = av; y = lt; /* full computation */ for (i=1; i<=K; i++) { GEN q = (GEN)famod[ind[i]]; if (y) q = gmul(y, q); y = FqX_centermod(q, Tpk, pk, pks2); } y = nf_pol_lift(y, bound, T); if (!y) { if (DEBUGLEVEL>3) fprintferr("@"); avma = av; goto NEXT; } /* try out the new combination: y is the candidate factor */ q = RXQX_divrem(C2ltpol, y, nfpol, ONLY_DIVIDES); if (!q) { if (DEBUGLEVEL>3) fprintferr("*"); avma = av; goto NEXT; } /* found a factor */ list = cgetg(K+1, t_VEC); listmod[cnt] = (long)list; for (i=1; i<=K; i++) list[i] = famod[ind[i]]; y = Q_primpart(y); fa[cnt++] = (long)QXQ_normalize(y, nfpol); /* fix up pol */ pol = q; for (i=j=k=1; i <= lfamod; i++) { /* remove used factors */ if (j <= K && i == ind[j]) j++; else { famod[k] = famod[i]; update_trace(T1, k, i); update_trace(T2, k, i); degpol[k] = degpol[i]; k++; } } lfamod -= K; if (lfamod < 2*K) goto END; i = 1; curdeg = degpol[ind[1]]; if (C2lt) pol = Q_primpart(pol); if (lt) lt = absi(leading_term(pol)); Clt = mul_content(C, lt); C2lt = mul_content(C,Clt); C2ltpol = C2lt? gmul(C2lt,pol): pol; if (DEBUGLEVEL > 2) { fprintferr("\n"); msgTIMER(&ti, "to find factor %Z",y); fprintferr("remaining modular factor(s): %ld\n", lfamod); } continue; }NEXT: for (i = K+1;;) { if (--i == 0) { K++; goto nextK; } if (++ind[i] <= lfamod - K + i) { curdeg = degsofar[i-1] + degpol[ind[i]]; if (curdeg <= klim) break; } } }END: if (degpol(pol) > 0) { /* leftover factor */ if (signe(leading_term(pol)) < 0) pol = gneg_i(pol); if (C2lt && lfamod < 2*K) pol = QXQ_normalize(Q_primpart(pol), nfpol); setlg(famod, lfamod+1); listmod[cnt] = (long)dummycopy(famod); fa[cnt++] = (long)pol; } if (DEBUGLEVEL>6) fprintferr("\n"); if (cnt == 2) { avma = av0; res[1] = (long)_vec(T->pol); res[2] = (long)_vec(T->fact); } else { setlg(listmod, cnt); setlg(fa, cnt); res[1] = (long)fa; res[2] = (long)listmod; gerepilecopy(av0, res); } return res;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/8fbffc11008a0932ab8699e70f9e65b2911a26ac/nffactor.c/clean/src/modules/nffactor.c
GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5;
GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst, Z; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 10;
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/55fb284243ce815fb6c5694ba2b52d1b1920793f/bibli1.c/clean/src/basemath/bibli1.c
if (!B) B = N;
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/55fb284243ce815fb6c5694ba2b52d1b1920793f/bibli1.c/clean/src/basemath/bibli1.c
fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0));
fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(Z));
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/55fb284243ce815fb6c5694ba2b52d1b1920793f/bibli1.c/clean/src/basemath/bibli1.c
fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0)));
fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, Z)));
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/55fb284243ce815fb6c5694ba2b52d1b1920793f/bibli1.c/clean/src/basemath/bibli1.c
if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */
if (cmpii(nsp, mulsi(bnd, Z)) < 0) break; /* SUCCESS */
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/55fb284243ce815fb6c5694ba2b52d1b1920793f/bibli1.c/clean/src/basemath/bibli1.c
bnd = itos(divii(nsp, N0)) + 1;
bnd = itos(divii(nsp, Z)) + 1;
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/55fb284243ce815fb6c5694ba2b52d1b1920793f/bibli1.c/clean/src/basemath/bibli1.c
if (i < bnd) R[2] = (long)addii((GEN)R[2], N0);
if (i < bnd) R[2] = (long)addii((GEN)R[2], Z);
zncoppersmith(GEN P0, GEN N, GEN X, GEN B){ GEN Q, R, N0, M, sh, short_pol, *Xpowers, z, r, sol, nsp, P, tst; int delta, ltop = avma, i, j, row, d, l, dim, t, bnd = 5; if (typ(P0) != t_POL || typ(N) != t_INT) err(typeer, "Coppersmith"); if (typ(X) != t_INT) X = gfloor(X); if (!B) B = N; if (typ(B) != t_INT) B = gfloor(B); P = dummycopy(P0); d = degpol(P); if (!gcmp1((GEN)P[d+2])) { P[d+2] = (long)bezout((GEN)P[d+2], N, &z, &r); for (j = 0; j < d; j++) P[j+2] = lmodii(mulii((GEN)P[j+2], z), N); } if (DEBUGLEVEL >= 2) fprintferr("Modified P: %Z\n", P); choose_params(P, N, X, B, &delta, &t); if (DEBUGLEVEL >= 2) fprintferr("Init: trying delta = %d, t = %d\n", delta, t); for(;;) { dim = d * delta + t; /* TODO: In case of failure do not recompute the full vector */ Xpowers = (GEN*)new_chunk(dim + 1); Xpowers[0] = gun; for (j = 1; j <= dim; j++) Xpowers[j] = gmul(Xpowers[j-1], X); /* TODO: in case of failure, use the part of the matrix already computed */ M = cgetg(dim + 1, t_MAT); for (j = 1; j <= dim; j++) M[j] = (long)zerocol(dim); /* Rows of M correspond to the polynomials * N^delta, N^delta Xi, ... N^delta (Xi)^d-1, * N^(delta-1)P(Xi), N^(delta-1)XiP(Xi), ... N^(delta-1)P(Xi)(Xi)^d-1, * ... * P(Xi)^delta, XiP(Xi)^delta, ..., P(Xi)^delta(Xi)^t-1 */ for (j = 1; j <= d; j++) coeff(M, j, j) = (long)Xpowers[j-1]; for ( ; j <= dim; j++) coeff(M, j, j) = un; /* P-part */ row = d + 1; Q = P; for (i = 1; i < delta; i++) { for (j = 0; j < d; j++,row++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); Q = RgX_mul(Q, P); } for (j = 0; j < t; row++, j++) for (l = j + 1; l <= row; l++) coeff(M, l, row) = lmulii(Xpowers[l-1], (GEN)Q[l-j+1]); /* N-part */ row = dim - t; N0 = N; while (row >= 1) { for (j = 0; j < d; j++,row--) for (l = 1; l <= row; l++) coeff(M, l, row) = lmulii(gmael(M, row, l), N0); if (row >= 1) N0 = mulii(N0, N); } if (DEBUGLEVEL >= 2) { if (DEBUGLEVEL >= 6) fprintferr("Matrix to be reduced:\n%Z\n", M); fprintferr("Entering LLL\nbitsize bound: %ld\n", expi(N0)); fprintferr("expected shvector bitsize: %ld\n", expi(dethnf_i(M))/dim); } sh = lllint_fp_ip(M, 4); short_pol = (GEN)sh[1]; nsp = gzero; for (j = 1; j <= dim; j++) nsp = addii(nsp, absi((GEN)short_pol[j])); if (DEBUGLEVEL >= 2) { fprintferr("Candidate: %Z\n", short_pol); fprintferr("bitsize Norm: %ld\n", expi(nsp)); fprintferr("bitsize bound: %ld\n", expi(mulsi(bnd, N0))); } if (cmpii(nsp, mulsi(bnd, N0)) < 0) break; /* SUCCESS */ /* Failed with the precomputed or supplied value */ t++; if (t == d) { delta++; t = 1; } if (DEBUGLEVEL >= 2) fprintferr("Increasing dim, delta = %d t = %d\n", delta, t); } bnd = itos(divii(nsp, N0)) + 1; while (!signe(short_pol[dim])) dim--; R = cgetg(dim + 2, t_POL); R[1] = P[1]; for (j = 1; j <= dim; j++) R[j+1] = (long)diviiexact((GEN)short_pol[j], Xpowers[j-1]); R[2] = (long)subii((GEN)R[2], mulsi(bnd - 1, N0)); sol = cgetg(1, t_VEC); for (i = -bnd + 1; i < bnd; i++) { r = nfrootsQ(R); if (DEBUGLEVEL >= 2) fprintferr("Roots: %Z\n", r); for (j = 1; j < lg(r); j++) { z = (GEN)r[j]; tst = gcdii(FpX_eval(P, z, N), N); if (cmpii(tst, B) >= 0) /* We have found a factor of N >= B */ { for (l = 1; l < lg(sol) && !egalii(z, (GEN)sol[l]); l++) /*empty*/; if (l == lg(sol)) sol = concatsp(sol, z); } } if (i < bnd) R[2] = (long)addii((GEN)R[2], N0); } return gerepilecopy(ltop, sol);}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/55fb284243ce815fb6c5694ba2b52d1b1920793f/bibli1.c/clean/src/basemath/bibli1.c
return gerepileupto(av, gcopy(y));
return gerepilecopy(av, y);
zidealstarinitall(GEN nf, GEN ideal,long add_gen){ long av = avma,i,j,k,nba,nbp,R1,nbgen,cp; GEN p1,y,h,cyc,U,u1,fa,fa2,ep,x,arch,list,sarch,gen; nf = checknf(nf); R1=itos(gmael(nf,2,1)); if (typ(ideal)==t_VEC && lg(ideal)==3) { arch=(GEN)ideal[2]; ideal = (GEN)ideal[1]; i = typ(arch); if (!is_vec_t(i) || lg(arch) != R1+1) err(talker,"incorrect archimedean component in zidealstarinit"); for (nba=0,i=1; i<=R1; i++) if (signe(arch[i])) nba++; } else { arch=cgetg(R1+1,t_VEC); for (nba=0,i=1; i<=R1; i++) arch[i]=zero; } x = idealhermite(nf,ideal); if (!gcmp1(denom(x))) err(talker,"zidealstarinit needs an integral ideal: %Z",x); p1=cgetg(3,t_VEC); ideal=p1; p1[1]=(long)x; p1[2]=(long)arch; fa=idealfactor(nf,x); list=(GEN)fa[1]; ep=(GEN)fa[2]; nbp=lg(list)-1; fa2=cgetg(nbp+2,t_VEC); gen = cgetg(1,t_VEC); p1 = (nbp==1)? (GEN)NULL: x; for (i=1; i<=nbp; i++) { GEN L = zprimestar(nf,(GEN)list[i],(GEN)ep[i],p1,arch); fa2[i] = (long)L; for (j=1; j<lg(L); j++) gen = concatsp(gen,gmael(L,j,3)); } sarch = zarchstar(nf,x,arch,nba); fa2[i]=(long)sarch; gen = concatsp(gen,(GEN)sarch[2]); nbgen = lg(gen)-1; h=cgetg(nbgen+1,t_MAT); cp=0; for (i=1; i<=nbp; i++) { list = (GEN)fa2[i]; for (j=1; j<lg(list); j++) { GEN a, L = (GEN)list[j], e = (GEN)L[1], g = (GEN)L[3]; for (k=1; k<lg(g); k++) { a = element_powmodidele(nf,(GEN)g[k],(GEN)e[k],ideal,sarch); h[++cp] = lneg(zinternallog(nf,a,fa2,nbgen,arch,fa,i)); coeff(h,cp,cp) = e[k]; } } } for (j=1; j<=nba; j++) { h[++cp]=(long)zerocol(nbgen); coeff(h,cp,cp)=deux; } if (cp!=nbgen) err(talker,"bug in zidealstarinit"); h = hnfall_i(h,NULL,0); cyc = smithrel(h, &U, add_gen? &u1: NULL); p1 = cgetg(add_gen? 4: 3, t_VEC); p1[1] = (long)detcyc(cyc); p1[2] = (long)cyc; y = cgetg(6,t_VEC); y[1] = (long)ideal; y[2] = (long)p1; y[3] = (long)fa; y[4] = (long)fa2; y[5] = (long)U; if (add_gen) p1[3] = (long)compute_gen(nf,u1,gen, y); return gerepileupto(av, gcopy(y));}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/7168973a923818508c45aa17d871c53e9225fad1/base3.c/buggy/src/basemath/base3.c
if (*xl != ~uzero) {
if ((ulong)*xl != ~uzero) {
incdec(GEN x, long incdec){ long *xf = x + 2, *xl; long len = lgefint(x); const ulong uzero = 0; xl = x + len; if (incdec == 1) { while (--xl >= xf) { if (*xl != ~uzero) { (*xl)++; return 0; } *xl = 0; } return 1; } else { while (--xl >= xf) { if (*xl != 0) { (*xl)--; return 0; } *xl = (long)~uzero; } return 0; }}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/9749d3e46caef3f61b412b608c8ac51b8f010460/arith2.c/clean/src/basemath/arith2.c
if (gcmp0(x)) return ggamma(a,prec);
incgam(GEN a, GEN x, long prec){ GEN p1,z = cgetr(prec); long av = avma; if (typ(x)!=t_REAL) { gaffect(x,z); x=z; } if (gcmp(subrs(x,1),a) > 0 || gsigne(greal(a)) <= 0) p1 = incgam2(a,x,prec); else p1 = gsub(ggamma(a,prec), incgam3(a,x,prec)); affrr(p1,z); avma = av; return z;}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/88886e5d9c3a9681343a9c35e7d0ffe1e3588045/trans3.c/buggy/src/basemath/trans3.c
q = gpowgs(p, pp+xp);
q = gpowgs(p, pp+2*xp);
gzetap(GEN s){ long pp, j, k, N, f, c, xp, l; pari_sp av = avma; GEN p, q, vz, is, cff, vtz, val, va, cft, bn; if (valp(s) < 0) err(talker, "argument must be a p-adic integer"); p = (GEN)s[2]; xp = 3; /* the extra precision; FIXME: quite arbitrary */ pp = precp(s); is = gtrunc(s); /* make s an integer */ N = itos(mulis(p, pp))+2*xp; /* FIXME: crude estimation */ q = gpowgs(p, pp+xp); /* initialize the roots of unity for the computation of the Teichmuller character (also the values of f and c) */ if (cmpis(p, 2) == 0) { vz = NULL; f = 4; c = 3; } else { GEN x = polx[0]; GEN p1 = gsubgs(powgi(x, subis(p, 1)), 1); vz = cgetg(itos(p), t_VEC); for (j = 1; cmpsi(j, p) < 0; j++) vz[j] = (long)gsubgs(x, j); p1 = hensel_lift_fact(p1, vz, NULL, p, q, pp+xp); /* p1 = polhensellift(p1, vz, p, pp+xp); */ for (j = 1; cmpsi(j, p) < 0; j++) vz[j] = (long)gadd(gneg(polcoeff0((GEN) p1[j], 0, 0)), zeropadic(p, pp+xp)); f = itos(p); c = 2; } /* compute the first N coefficients of the Malher expansion of phi^(-1)_s skipping the first one (which is zero) */ cff = cgetg(N+1, t_VEC); bn = new_chunk(N+2); /* bn[i] = binom(k, i), i <= k */ l = lg(q); for (k = 0; k <= N; k++) { GEN t = cgeti(l); affsi(1, t); bn[k] = (long)t; } for (k = 1; k <= N; k++) { pari_sp av2 = avma; GEN p1, A = phi_ms(vz, p, -1, is, gaddsg(k, zeropadic(p, pp+xp))); A = gtrunc(A); p1 = gzero; for (j = k - 1; j > 0; j--) { GEN b = addii((GEN)bn[j], (GEN)bn[j-1]); if (cmpii(b, q) >= 0) b = subii(b, q); affii(b, (GEN)bn[j]); /* = binom(k, j+1) */ } for (j = 1; j < k; j++) p1 = addii(p1, mulii((GEN)bn[j], (GEN)cff[j])); cff[k] = (long)gerepileuptoint(av2, modii(subii(A, p1), q)); } /* compute the coefficients of the power series corresponding to the twisted partial zeta function Z_f(a, c, s) for a in va */ /* The line below looks a bit stupid but it is to keep the possibility of later adding p-adic Dirichlet L-functions */ va = perm_identity(f - 1); vtz = twistpartialpowser(p, q, N, f, c, va); /* sum over all a's the coefficients of the twisted partial zeta functions and integrate */ val = gzero; for (k = 1; k <= N; k++) { GEN p1 = gzero; for (j = 1; j < f; j++) p1 = gadd(p1, gcoeff(vtz, k, j)); val = gadd(val, gmul(p1, (GEN)cff[k])); } /* finally we multiply by the corrective factor */ cft = gsubgs(gmulsg(c, phi_ms(vz, p, -1, is, gaddsg(c, zeropadic(p, pp+xp)))), 1); val = gdiv(val, cft); /* adjust the precision and return */ return gerepileupto(av, gadd(val, zeropadic(p, pp)));}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/81282841645f6a41162c6b7c228e3e863d4a6c31/trans3.c/buggy/src/basemath/trans3.c
/* p1 = polhensellift(p1, vz, p, pp+xp); */
gzetap(GEN s){ long pp, j, k, N, f, c, xp, l; pari_sp av = avma; GEN p, q, vz, is, cff, vtz, val, va, cft, bn; if (valp(s) < 0) err(talker, "argument must be a p-adic integer"); p = (GEN)s[2]; xp = 3; /* the extra precision; FIXME: quite arbitrary */ pp = precp(s); is = gtrunc(s); /* make s an integer */ N = itos(mulis(p, pp))+2*xp; /* FIXME: crude estimation */ q = gpowgs(p, pp+xp); /* initialize the roots of unity for the computation of the Teichmuller character (also the values of f and c) */ if (cmpis(p, 2) == 0) { vz = NULL; f = 4; c = 3; } else { GEN x = polx[0]; GEN p1 = gsubgs(powgi(x, subis(p, 1)), 1); vz = cgetg(itos(p), t_VEC); for (j = 1; cmpsi(j, p) < 0; j++) vz[j] = (long)gsubgs(x, j); p1 = hensel_lift_fact(p1, vz, NULL, p, q, pp+xp); /* p1 = polhensellift(p1, vz, p, pp+xp); */ for (j = 1; cmpsi(j, p) < 0; j++) vz[j] = (long)gadd(gneg(polcoeff0((GEN) p1[j], 0, 0)), zeropadic(p, pp+xp)); f = itos(p); c = 2; } /* compute the first N coefficients of the Malher expansion of phi^(-1)_s skipping the first one (which is zero) */ cff = cgetg(N+1, t_VEC); bn = new_chunk(N+2); /* bn[i] = binom(k, i), i <= k */ l = lg(q); for (k = 0; k <= N; k++) { GEN t = cgeti(l); affsi(1, t); bn[k] = (long)t; } for (k = 1; k <= N; k++) { pari_sp av2 = avma; GEN p1, A = phi_ms(vz, p, -1, is, gaddsg(k, zeropadic(p, pp+xp))); A = gtrunc(A); p1 = gzero; for (j = k - 1; j > 0; j--) { GEN b = addii((GEN)bn[j], (GEN)bn[j-1]); if (cmpii(b, q) >= 0) b = subii(b, q); affii(b, (GEN)bn[j]); /* = binom(k, j+1) */ } for (j = 1; j < k; j++) p1 = addii(p1, mulii((GEN)bn[j], (GEN)cff[j])); cff[k] = (long)gerepileuptoint(av2, modii(subii(A, p1), q)); } /* compute the coefficients of the power series corresponding to the twisted partial zeta function Z_f(a, c, s) for a in va */ /* The line below looks a bit stupid but it is to keep the possibility of later adding p-adic Dirichlet L-functions */ va = perm_identity(f - 1); vtz = twistpartialpowser(p, q, N, f, c, va); /* sum over all a's the coefficients of the twisted partial zeta functions and integrate */ val = gzero; for (k = 1; k <= N; k++) { GEN p1 = gzero; for (j = 1; j < f; j++) p1 = gadd(p1, gcoeff(vtz, k, j)); val = gadd(val, gmul(p1, (GEN)cff[k])); } /* finally we multiply by the corrective factor */ cft = gsubgs(gmulsg(c, phi_ms(vz, p, -1, is, gaddsg(c, zeropadic(p, pp+xp)))), 1); val = gdiv(val, cft); /* adjust the precision and return */ return gerepileupto(av, gadd(val, zeropadic(p, pp)));}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/81282841645f6a41162c6b7c228e3e863d4a6c31/trans3.c/buggy/src/basemath/trans3.c
vz[j] = (long)gadd(gneg(polcoeff0((GEN) p1[j], 0, 0)), zeropadic(p, pp+xp));
vz[j] = (long)gmodulcp(gneg(polcoeff0((GEN) p1[j], 0, 0)), q);
gzetap(GEN s){ long pp, j, k, N, f, c, xp, l; pari_sp av = avma; GEN p, q, vz, is, cff, vtz, val, va, cft, bn; if (valp(s) < 0) err(talker, "argument must be a p-adic integer"); p = (GEN)s[2]; xp = 3; /* the extra precision; FIXME: quite arbitrary */ pp = precp(s); is = gtrunc(s); /* make s an integer */ N = itos(mulis(p, pp))+2*xp; /* FIXME: crude estimation */ q = gpowgs(p, pp+xp); /* initialize the roots of unity for the computation of the Teichmuller character (also the values of f and c) */ if (cmpis(p, 2) == 0) { vz = NULL; f = 4; c = 3; } else { GEN x = polx[0]; GEN p1 = gsubgs(powgi(x, subis(p, 1)), 1); vz = cgetg(itos(p), t_VEC); for (j = 1; cmpsi(j, p) < 0; j++) vz[j] = (long)gsubgs(x, j); p1 = hensel_lift_fact(p1, vz, NULL, p, q, pp+xp); /* p1 = polhensellift(p1, vz, p, pp+xp); */ for (j = 1; cmpsi(j, p) < 0; j++) vz[j] = (long)gadd(gneg(polcoeff0((GEN) p1[j], 0, 0)), zeropadic(p, pp+xp)); f = itos(p); c = 2; } /* compute the first N coefficients of the Malher expansion of phi^(-1)_s skipping the first one (which is zero) */ cff = cgetg(N+1, t_VEC); bn = new_chunk(N+2); /* bn[i] = binom(k, i), i <= k */ l = lg(q); for (k = 0; k <= N; k++) { GEN t = cgeti(l); affsi(1, t); bn[k] = (long)t; } for (k = 1; k <= N; k++) { pari_sp av2 = avma; GEN p1, A = phi_ms(vz, p, -1, is, gaddsg(k, zeropadic(p, pp+xp))); A = gtrunc(A); p1 = gzero; for (j = k - 1; j > 0; j--) { GEN b = addii((GEN)bn[j], (GEN)bn[j-1]); if (cmpii(b, q) >= 0) b = subii(b, q); affii(b, (GEN)bn[j]); /* = binom(k, j+1) */ } for (j = 1; j < k; j++) p1 = addii(p1, mulii((GEN)bn[j], (GEN)cff[j])); cff[k] = (long)gerepileuptoint(av2, modii(subii(A, p1), q)); } /* compute the coefficients of the power series corresponding to the twisted partial zeta function Z_f(a, c, s) for a in va */ /* The line below looks a bit stupid but it is to keep the possibility of later adding p-adic Dirichlet L-functions */ va = perm_identity(f - 1); vtz = twistpartialpowser(p, q, N, f, c, va); /* sum over all a's the coefficients of the twisted partial zeta functions and integrate */ val = gzero; for (k = 1; k <= N; k++) { GEN p1 = gzero; for (j = 1; j < f; j++) p1 = gadd(p1, gcoeff(vtz, k, j)); val = gadd(val, gmul(p1, (GEN)cff[k])); } /* finally we multiply by the corrective factor */ cft = gsubgs(gmulsg(c, phi_ms(vz, p, -1, is, gaddsg(c, zeropadic(p, pp+xp)))), 1); val = gdiv(val, cft); /* adjust the precision and return */ return gerepileupto(av, gadd(val, zeropadic(p, pp)));}
2195 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2195/81282841645f6a41162c6b7c228e3e863d4a6c31/trans3.c/buggy/src/basemath/trans3.c