Exemplo n.º 1
0
RCP<const UnivariatePolynomial> mul_uni_poly(RCP<const UnivariatePolynomial> a,
                                             RCP<const UnivariatePolynomial> b)
{
    map_int_Expr dict;
    RCP<const Symbol> var = symbol("");
    if (a->get_var()->get_name() == "") {
        var = b->get_var();
    } else if (b->get_var()->get_name() == "") {
        var = a->get_var();
    } else if (!(a->get_var()->__eq__(*b->get_var()))) {
        throw std::runtime_error("Error: variables must agree.");
    } else {
        var = a->get_var();
    }

    if (a->get_var() != b->get_var())
        throw std::runtime_error("Error: variables must agree.");
    if (a->get_dict().empty() and b->get_dict().empty())
        return univariate_polynomial(var, {{0, 0}});

    for (const auto &i1 : a->get_dict())
        for (const auto &i2 : b->get_dict())
            dict[i1.first + i2.first] += i1.second * i2.second;
    return univariate_polynomial(var, std::move(dict));
}
Exemplo n.º 2
0
RCP<const UnivariatePolynomial> neg_uni_poly(const UnivariatePolynomial &a)
{
    map_int_Expr dict;
    for (const auto &it : a.get_dict())
        dict[it.first] = -1 * it.second;
    return univariate_polynomial(a.get_var(), std::move(dict));
}
Exemplo n.º 3
0
RCP<const UnivariatePolynomial> neg_uni_poly(const UnivariatePolynomial &a) {
    map_uint_mpz dict;
    for (const auto &it : a.dict_)
        dict[it.first] = -1 * it.second;

    RCP<const UnivariatePolynomial> c = univariate_polynomial(a.var_, (--(dict.end()))->first, std::move(dict));
    return c;
}
Exemplo n.º 4
0
RCP<const UnivariatePolynomial> sub_uni_poly(const UnivariatePolynomial &a,
                                             const UnivariatePolynomial &b)
{
    map_int_Expr dict;
    RCP<const Symbol> var = symbol("");
    if (a.get_var()->get_name() == "") {
        var = b.get_var();
    } else if (b.get_var()->get_name() == "") {
        var = a.get_var();
    } else if (!(a.get_var()->__eq__(*b.get_var()))) {
        throw std::runtime_error("Error: variables must agree.");
    } else {
        var = a.get_var();
    }
    for (const auto &it : a.get_dict())
        dict[it.first] = it.second;
    for (const auto &it : b.get_dict())
        dict[it.first] -= it.second;
    return univariate_polynomial(var, std::move(dict));
}