static uint64_t embed_fraction(struct solver_Algebra *a, uint64_t numerator, uint64_t denominator) {
  assert(is_smallint(numerator));
  assert(is_smallint(denominator));

  if(denominator == LITERAL_ZERO) {
    return pack_undefined();
  }

  uint64_t div, rem;
  integer_divide_remainder(a, numerator, denominator, &div, &rem);
  if(rem == LITERAL_ZERO) {
    return div;
  }

  uint64_t g = integer_greatest_common_denominator(a, numerator, denominator);

  uint64_t values[2];
  if(integer_is_negative(denominator)) {
    values[0] = integer_divide(a, numerator, g);
    values[1] = integer_divide(a, denominator, g);
  } else {
    values[0] = integer_divide(a, integer_negate(numerator), g);
    values[1] = integer_divide(a, integer_negate(denominator), g);
  }

  uint32_t index = embed_values(a, 2, values);
  return pack_fraction(index);
}

uint64_t solver_Algebra_fraction(struct solver_Algebra *a, uint64_t numerator, uint64_t denominator) {
  return embed_fraction(a, numerator, denominator);
}