예제 #1
0
/*
 * Given p and q as above
 * - p and q must be normalized and have integer coefficients
 * - compute the GCD of all coefficients in p and q that are not
 *   in the common part.
 * - the result is returned in factor.
 * - if p = q, then the result is 0
 */
void monarray_pair_non_common_gcd(monomial_t *p, monomial_t *q, rational_t *factor) {
  int32_t x, y;

  q_clear(factor);
  x = p->var;
  y = q->var;
  for (;;) {
    if (x == y) {
      if (x == max_idx) break;
      if (q_neq(&p->coeff, &q->coeff)) {
        // a.x and b.x not in the common part
        aux_gcd(factor, &p->coeff);
        aux_gcd(factor, &q->coeff);
      }
      p ++;
      x = p->var;
      q ++;
      y = q->var;
    } else if (x < y) {
      aux_gcd(factor, &p->coeff);
      p ++;
      x = p->var;
    } else {
      aux_gcd(factor, &q->coeff);
      q ++;
      y = q->var;
    }
  }
}
예제 #2
0
/*
 * Comparison between two monomial_arrays.
 * - p1 and p2 must be normalized.
 */
bool equal_monarrays(monomial_t *p1, monomial_t *p2) {
  int32_t v1, v2;

  v1 = p1->var;
  v2 = p2->var;
  while (v1 == v2) {
    if (v1 == max_idx) return true;
    if (q_neq(&p1->coeff, &p2->coeff)) return false;

    p1++;
    v1 = p1->var;
    p2++;
    v2 = p2->var;
  }

  return false;
}
예제 #3
0
/*
 * Check whether b1 and b2 are equal
 * - both must be normalized and use the same ptbl
 */
bool arith_buffer_equal(arith_buffer_t *b1, arith_buffer_t *b2) {
  mlist_t *p1, *p2;

  assert(b1->ptbl == b2->ptbl);

  if (b1->nterms != b2->nterms) return false;

  p1 = b1->list;
  p2 = b2->list;

  while (p1->prod == p2->prod) {
    if (p1->prod == end_pp) return true;
    if (q_neq(&p1->coeff, &p2->coeff)) return false;
    p1 = p1->next;
    p2 = p2->next;
  }

  return false;
}
예제 #4
0
/*
 * Check where P(b, v) is equal to p
 * - both b and p must be normalized.
 */
bool arith_buffer_equal_poly(arith_buffer_t *b, int32_t *v, polynomial_t *p) {
  mlist_t *q;
  monomial_t *mono;
  int32_t x1, x2;

  if (b->nterms == p->nterms) {
    q = b->list;
    mono = p->mono;
    x1 = *v;
    x2 = mono->var;
    while (x1 == x2) {
      if (x1 == max_idx) return true;
      if (q_neq(&q->coeff, &mono->coeff)) return false;

      mono ++;
      v ++;
      q = q->next;
      x1 = *v;
      x2 = mono->var;
    }
  }

  return false;
}