Ejemplo n.º 1
0
void
_fmpq_poly_compose(fmpz * res, fmpz_t den, const fmpz * poly1, const fmpz_t den1, 
                   long len1, const fmpz * poly2, const fmpz_t den2, long len2)
{
    if (*den2 == 1L)
    {
        _fmpz_poly_compose(res, poly1, len1, poly2, len2);
        fmpz_set(den, den1);
        _fmpq_poly_canonicalise(res, den, (len1 - 1L) * (len2 - 1L) + 1L);
    }
    else
    {
        fmpz_t one;
        fmpz * v = _fmpz_vec_init(len1);
        fmpz_init(one);
        fmpz_one(one);
        
        _fmpq_poly_rescale(v, den, poly1, den1, len1, one, den2);
        _fmpz_poly_compose(res, v, len1, poly2, len2);
        _fmpq_poly_canonicalise(res, den, (len1 - 1L) * (len2 - 1L) + 1L);
        
        fmpz_clear(one);
        _fmpz_vec_clear(v, len1);
    }
}
Ejemplo n.º 2
0
void
fmpz_poly_compose(fmpz_poly_t res, 
                  const fmpz_poly_t poly1, const fmpz_poly_t poly2)
{
    const slong len1 = poly1->length;
    const slong len2 = poly2->length;
    slong lenr;
    
    if (len1 == 0)
    {
        fmpz_poly_zero(res);
        return;
    }
    if (len1 == 1 || len2 == 0)
    {
        fmpz_poly_set_fmpz(res, poly1->coeffs);
        return;
    }
    
    lenr = (len1 - 1) * (len2 - 1) + 1;
    
    if (res != poly1 && res != poly2)
    {
        fmpz_poly_fit_length(res, lenr);
        _fmpz_poly_compose(res->coeffs, poly1->coeffs, len1, 
                                        poly2->coeffs, len2);
        _fmpz_poly_set_length(res, lenr);
        _fmpz_poly_normalise(res);
    }
    else
    {
        fmpz_poly_t t;
        fmpz_poly_init2(t, lenr);
        _fmpz_poly_compose(t->coeffs, poly1->coeffs, len1,
                                      poly2->coeffs, len2);
        _fmpz_poly_set_length(t, lenr);
        _fmpz_poly_normalise(t);
        fmpz_poly_swap(res, t);
        fmpz_poly_clear(t);
    }
}