flint::fmpqxx URatPSeriesFlint::convert(const rational_class &x) { flint::fmpqxx r; flint::fmpzxx i1; fmpz_set_mpz(i1._data().inner, get_mpz_t(get_num(x))); flint::fmpzxx i2; fmpz_set_mpz(i2._data().inner, get_mpz_t(get_den(x))); r.num() = i1; r.den() = i2; return r; }
// Factorization int factor(const Ptr<RCP<const Integer>> &f, const Integer &n, double B1) { int ret_val = 0; integer_class _n, _f; _n = n.as_integer_class(); #ifdef HAVE_SYMENGINE_ECM if (mp_perfect_power_p(_n)) { unsigned long int i = 1; integer_class m, rem; rem = 1; // Any non zero number m = 2; // set `m` to 2**i, i = 1 at the begining // calculate log2n, this can be improved for (; m < _n; ++i) m = m * 2; // eventually `rem` = 0 zero as `n` is a perfect power. `f_t` will // be set to a factor of `n` when that happens while (i > 1 and rem != 0) { mp_rootrem(_f, rem, _n, i); --i; } ret_val = 1; } else { if (mp_probab_prime_p(_n, 25) > 0) { // most probably, n is a prime ret_val = 0; _f = _n; } else { for (int i = 0; i < 10 and not ret_val; ++i) ret_val = ecm_factor(get_mpz_t(_f), get_mpz_t(_n), B1, nullptr); mp_demote(_f); if (not ret_val) throw SymEngineException( "ECM failed to factor the given number"); } } #else // B1 is discarded if gmp-ecm is not installed ret_val = _factor_trial_division_sieve(_f, _n); #endif // HAVE_SYMENGINE_ECM *f = integer(std::move(_f)); return ret_val; }
vec_integer_class UIntPolyFlint::multieval(const vec_integer_class &v) const { const unsigned int n = v.size(); fmpz *fvp = _fmpz_vec_init(n); for (unsigned int i = 0; i < n; ++i) fmpz_set_mpz(fvp + i, get_mpz_t(v[i])); poly_.eval_vec(fvp, fvp, n); vec_integer_class res(n); for (unsigned int i = 0; i < n; ++i) res[i] = to_integer_class(fvp + i); _fmpz_vec_clear(fvp, n); return res; }
RCP<const UIntPolyFlint> UIntPolyFlint::from_dict(const RCP<const Symbol> &var, map_uint_mpz &&d) { // benchmark this against dict->str->fmpz_polyxx if (d.empty()) return UIntPolyFlint::from_dict(var, {{}}); fp_t f; for (auto const &p : d) { fz_t r(get_mpz_t(p.second)); f.set_coeff(p.first, r); } return make_rcp<const UIntPolyFlint>(var, std::move(f)); }
RCP<const UIntPolyFlint> UIntPolyFlint::from_vec(const RCP<const Symbol> &var, const vec_integer_class &v) { // benchmark this against vec->str->fmpz_polyxx unsigned int deg = v.size() - 1; while (v[deg] == integer_class(0)) deg--; fp_t f(deg + 1); for (unsigned int i = 0; i <= deg; i++) { if (v[i] != integer_class(0)) { fz_t r(get_mpz_t(v[i])); f.set_coeff(i, r); } } return make_rcp<const UIntPolyFlint>(var, std::move(f)); }
fqp_t URatPSeriesFlint::convert(const integer_class &x) { return fqp_t(get_mpz_t(x)); }
flint::fmpzxx URatPSeriesFlint::convert(const Integer &x) { flint::fmpzxx r; fmpz_set_mpz(r._data().inner, get_mpz_t(x.as_mpz())); return r; }
integer_class UIntPolyFlint::eval(const integer_class &x) const { fz_t r(get_mpz_t(x)); return to_integer_class(poly_.eval(r)); }