mirror of
https://github.com/vale981/arb
synced 2025-03-04 17:01:40 -05:00
add polynomial add_series and sub_series methods
This commit is contained in:
parent
b60365962c
commit
b6be51978f
12 changed files with 488 additions and 0 deletions
|
@ -236,6 +236,12 @@ void _acb_poly_sub(acb_ptr res, acb_srcptr poly1, slong len1,
|
|||
void acb_poly_sub(acb_poly_t res, const acb_poly_t poly1,
|
||||
const acb_poly_t poly2, slong prec);
|
||||
|
||||
void acb_poly_add_series(acb_poly_t res, const acb_poly_t poly1,
|
||||
const acb_poly_t poly2, slong len, slong prec);
|
||||
|
||||
void acb_poly_sub_series(acb_poly_t res, const acb_poly_t poly1,
|
||||
const acb_poly_t poly2, slong len, slong prec);
|
||||
|
||||
ACB_POLY_INLINE void
|
||||
acb_poly_neg(acb_poly_t res, const acb_poly_t poly)
|
||||
{
|
||||
|
|
32
acb_poly/add_series.c
Normal file
32
acb_poly/add_series.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Copyright (C) 2016 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "acb_poly.h"
|
||||
|
||||
void
|
||||
acb_poly_add_series(acb_poly_t res, const acb_poly_t poly1,
|
||||
const acb_poly_t poly2, slong len, slong prec)
|
||||
{
|
||||
slong len1, len2;
|
||||
|
||||
len1 = poly1->length;
|
||||
len2 = poly2->length;
|
||||
|
||||
len1 = FLINT_MIN(len1, len);
|
||||
len2 = FLINT_MIN(len2, len);
|
||||
len = FLINT_MAX(len1, len2);
|
||||
|
||||
acb_poly_fit_length(res, len);
|
||||
_acb_poly_add(res->coeffs, poly1->coeffs, len1, poly2->coeffs, len2, prec);
|
||||
_acb_poly_set_length(res, len);
|
||||
_acb_poly_normalise(res);
|
||||
}
|
||||
|
32
acb_poly/sub_series.c
Normal file
32
acb_poly/sub_series.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Copyright (C) 2016 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "acb_poly.h"
|
||||
|
||||
void
|
||||
acb_poly_sub_series(acb_poly_t res, const acb_poly_t poly1,
|
||||
const acb_poly_t poly2, slong len, slong prec)
|
||||
{
|
||||
slong len1, len2;
|
||||
|
||||
len1 = poly1->length;
|
||||
len2 = poly2->length;
|
||||
|
||||
len1 = FLINT_MIN(len1, len);
|
||||
len2 = FLINT_MIN(len2, len);
|
||||
len = FLINT_MAX(len1, len2);
|
||||
|
||||
acb_poly_fit_length(res, len);
|
||||
_acb_poly_sub(res->coeffs, poly1->coeffs, len1, poly2->coeffs, len2, prec);
|
||||
_acb_poly_set_length(res, len);
|
||||
_acb_poly_normalise(res);
|
||||
}
|
||||
|
83
acb_poly/test/t-add_series.c
Normal file
83
acb_poly/test/t-add_series.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "acb_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
slong iter;
|
||||
flint_rand_t state;
|
||||
|
||||
flint_printf("add_series....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
|
||||
{
|
||||
acb_poly_t a, b, c, d;
|
||||
slong len, prec;
|
||||
|
||||
acb_poly_init(a);
|
||||
acb_poly_init(b);
|
||||
acb_poly_init(c);
|
||||
acb_poly_init(d);
|
||||
|
||||
acb_poly_randtest(a, state, 1 + n_randint(state, 10), 100, 10);
|
||||
acb_poly_randtest(b, state, 1 + n_randint(state, 10), 100, 10);
|
||||
acb_poly_randtest(c, state, 1 + n_randint(state, 10), 100, 10);
|
||||
acb_poly_randtest(d, state, 1 + n_randint(state, 10), 100, 10);
|
||||
prec = 2 + n_randint(state, 100);
|
||||
len = n_randint(state, 10);
|
||||
|
||||
acb_poly_add_series(c, a, b, len, prec);
|
||||
acb_poly_add(d, a, b, prec);
|
||||
acb_poly_truncate(d, len);
|
||||
|
||||
if (!acb_poly_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL\n\n");
|
||||
flint_printf("a = "); acb_poly_printd(a, 15); flint_printf("\n\n");
|
||||
flint_printf("b = "); acb_poly_printd(b, 15); flint_printf("\n\n");
|
||||
flint_printf("c = "); acb_poly_printd(c, 15); flint_printf("\n\n");
|
||||
flint_printf("c = "); acb_poly_printd(c, 15); flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
acb_poly_set(d, a);
|
||||
acb_poly_add_series(d, d, b, len, prec);
|
||||
if (!acb_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing 1)\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
acb_poly_set(d, b);
|
||||
acb_poly_add_series(d, a, d, len, prec);
|
||||
if (!acb_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing 2)\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
acb_poly_clear(a);
|
||||
acb_poly_clear(b);
|
||||
acb_poly_clear(c);
|
||||
acb_poly_clear(d);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
83
acb_poly/test/t-sub_series.c
Normal file
83
acb_poly/test/t-sub_series.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "acb_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
slong iter;
|
||||
flint_rand_t state;
|
||||
|
||||
flint_printf("sub_series....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
|
||||
{
|
||||
acb_poly_t a, b, c, d;
|
||||
slong len, prec;
|
||||
|
||||
acb_poly_init(a);
|
||||
acb_poly_init(b);
|
||||
acb_poly_init(c);
|
||||
acb_poly_init(d);
|
||||
|
||||
acb_poly_randtest(a, state, 1 + n_randint(state, 10), 100, 10);
|
||||
acb_poly_randtest(b, state, 1 + n_randint(state, 10), 100, 10);
|
||||
acb_poly_randtest(c, state, 1 + n_randint(state, 10), 100, 10);
|
||||
acb_poly_randtest(d, state, 1 + n_randint(state, 10), 100, 10);
|
||||
prec = 2 + n_randint(state, 100);
|
||||
len = n_randint(state, 10);
|
||||
|
||||
acb_poly_sub_series(c, a, b, len, prec);
|
||||
acb_poly_sub(d, a, b, prec);
|
||||
acb_poly_truncate(d, len);
|
||||
|
||||
if (!acb_poly_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL\n\n");
|
||||
flint_printf("a = "); acb_poly_printd(a, 15); flint_printf("\n\n");
|
||||
flint_printf("b = "); acb_poly_printd(b, 15); flint_printf("\n\n");
|
||||
flint_printf("c = "); acb_poly_printd(c, 15); flint_printf("\n\n");
|
||||
flint_printf("c = "); acb_poly_printd(c, 15); flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
acb_poly_set(d, a);
|
||||
acb_poly_sub_series(d, d, b, len, prec);
|
||||
if (!acb_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing 1)\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
acb_poly_set(d, b);
|
||||
acb_poly_sub_series(d, a, d, len, prec);
|
||||
if (!acb_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing 2)\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
acb_poly_clear(a);
|
||||
acb_poly_clear(b);
|
||||
acb_poly_clear(c);
|
||||
acb_poly_clear(d);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -214,6 +214,12 @@ void _arb_poly_sub(arb_ptr res, arb_srcptr poly1, slong len1,
|
|||
void arb_poly_sub(arb_poly_t res, const arb_poly_t poly1,
|
||||
const arb_poly_t poly2, slong prec);
|
||||
|
||||
void arb_poly_add_series(arb_poly_t res, const arb_poly_t poly1,
|
||||
const arb_poly_t poly2, slong len, slong prec);
|
||||
|
||||
void arb_poly_sub_series(arb_poly_t res, const arb_poly_t poly1,
|
||||
const arb_poly_t poly2, slong len, slong prec);
|
||||
|
||||
ARB_POLY_INLINE void
|
||||
arb_poly_neg(arb_poly_t res, const arb_poly_t poly)
|
||||
{
|
||||
|
|
32
arb_poly/add_series.c
Normal file
32
arb_poly/add_series.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Copyright (C) 2016 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "arb_poly.h"
|
||||
|
||||
void
|
||||
arb_poly_add_series(arb_poly_t res, const arb_poly_t poly1,
|
||||
const arb_poly_t poly2, slong len, slong prec)
|
||||
{
|
||||
slong len1, len2;
|
||||
|
||||
len1 = poly1->length;
|
||||
len2 = poly2->length;
|
||||
|
||||
len1 = FLINT_MIN(len1, len);
|
||||
len2 = FLINT_MIN(len2, len);
|
||||
len = FLINT_MAX(len1, len2);
|
||||
|
||||
arb_poly_fit_length(res, len);
|
||||
_arb_poly_add(res->coeffs, poly1->coeffs, len1, poly2->coeffs, len2, prec);
|
||||
_arb_poly_set_length(res, len);
|
||||
_arb_poly_normalise(res);
|
||||
}
|
||||
|
32
arb_poly/sub_series.c
Normal file
32
arb_poly/sub_series.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Copyright (C) 2016 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "arb_poly.h"
|
||||
|
||||
void
|
||||
arb_poly_sub_series(arb_poly_t res, const arb_poly_t poly1,
|
||||
const arb_poly_t poly2, slong len, slong prec)
|
||||
{
|
||||
slong len1, len2;
|
||||
|
||||
len1 = poly1->length;
|
||||
len2 = poly2->length;
|
||||
|
||||
len1 = FLINT_MIN(len1, len);
|
||||
len2 = FLINT_MIN(len2, len);
|
||||
len = FLINT_MAX(len1, len2);
|
||||
|
||||
arb_poly_fit_length(res, len);
|
||||
_arb_poly_sub(res->coeffs, poly1->coeffs, len1, poly2->coeffs, len2, prec);
|
||||
_arb_poly_set_length(res, len);
|
||||
_arb_poly_normalise(res);
|
||||
}
|
||||
|
83
arb_poly/test/t-add_series.c
Normal file
83
arb_poly/test/t-add_series.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "arb_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
slong iter;
|
||||
flint_rand_t state;
|
||||
|
||||
flint_printf("add_series....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
|
||||
{
|
||||
arb_poly_t a, b, c, d;
|
||||
slong len, prec;
|
||||
|
||||
arb_poly_init(a);
|
||||
arb_poly_init(b);
|
||||
arb_poly_init(c);
|
||||
arb_poly_init(d);
|
||||
|
||||
arb_poly_randtest(a, state, 1 + n_randint(state, 10), 100, 10);
|
||||
arb_poly_randtest(b, state, 1 + n_randint(state, 10), 100, 10);
|
||||
arb_poly_randtest(c, state, 1 + n_randint(state, 10), 100, 10);
|
||||
arb_poly_randtest(d, state, 1 + n_randint(state, 10), 100, 10);
|
||||
prec = 2 + n_randint(state, 100);
|
||||
len = n_randint(state, 10);
|
||||
|
||||
arb_poly_add_series(c, a, b, len, prec);
|
||||
arb_poly_add(d, a, b, prec);
|
||||
arb_poly_truncate(d, len);
|
||||
|
||||
if (!arb_poly_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL\n\n");
|
||||
flint_printf("a = "); arb_poly_printd(a, 15); flint_printf("\n\n");
|
||||
flint_printf("b = "); arb_poly_printd(b, 15); flint_printf("\n\n");
|
||||
flint_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");
|
||||
flint_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_poly_set(d, a);
|
||||
arb_poly_add_series(d, d, b, len, prec);
|
||||
if (!arb_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing 1)\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_poly_set(d, b);
|
||||
arb_poly_add_series(d, a, d, len, prec);
|
||||
if (!arb_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing 2)\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_poly_clear(a);
|
||||
arb_poly_clear(b);
|
||||
arb_poly_clear(c);
|
||||
arb_poly_clear(d);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
83
arb_poly/test/t-sub_series.c
Normal file
83
arb_poly/test/t-sub_series.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Copyright (C) 2012 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "arb_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
slong iter;
|
||||
flint_rand_t state;
|
||||
|
||||
flint_printf("sub_series....");
|
||||
fflush(stdout);
|
||||
|
||||
flint_randinit(state);
|
||||
|
||||
for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
|
||||
{
|
||||
arb_poly_t a, b, c, d;
|
||||
slong len, prec;
|
||||
|
||||
arb_poly_init(a);
|
||||
arb_poly_init(b);
|
||||
arb_poly_init(c);
|
||||
arb_poly_init(d);
|
||||
|
||||
arb_poly_randtest(a, state, 1 + n_randint(state, 10), 100, 10);
|
||||
arb_poly_randtest(b, state, 1 + n_randint(state, 10), 100, 10);
|
||||
arb_poly_randtest(c, state, 1 + n_randint(state, 10), 100, 10);
|
||||
arb_poly_randtest(d, state, 1 + n_randint(state, 10), 100, 10);
|
||||
prec = 2 + n_randint(state, 100);
|
||||
len = n_randint(state, 10);
|
||||
|
||||
arb_poly_sub_series(c, a, b, len, prec);
|
||||
arb_poly_sub(d, a, b, prec);
|
||||
arb_poly_truncate(d, len);
|
||||
|
||||
if (!arb_poly_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL\n\n");
|
||||
flint_printf("a = "); arb_poly_printd(a, 15); flint_printf("\n\n");
|
||||
flint_printf("b = "); arb_poly_printd(b, 15); flint_printf("\n\n");
|
||||
flint_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");
|
||||
flint_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_poly_set(d, a);
|
||||
arb_poly_sub_series(d, d, b, len, prec);
|
||||
if (!arb_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing 1)\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_poly_set(d, b);
|
||||
arb_poly_sub_series(d, a, d, len, prec);
|
||||
if (!arb_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing 2)\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
arb_poly_clear(a);
|
||||
arb_poly_clear(b);
|
||||
arb_poly_clear(c);
|
||||
arb_poly_clear(d);
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
flint_cleanup();
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -253,6 +253,14 @@ Arithmetic
|
|||
|
||||
Sets *C* to the difference of *A* and *B*.
|
||||
|
||||
.. function:: void acb_poly_add_series(acb_poly_t C, const acb_poly_t A, const acb_poly_t B, slong len, slong prec)
|
||||
|
||||
Sets *C* to the sum of *A* and *B*, truncated to length *len*.
|
||||
|
||||
.. function:: void acb_poly_sub_series(acb_poly_t C, const acb_poly_t A, const acb_poly_t B, slong len, slong prec)
|
||||
|
||||
Sets *C* to the difference of *A* and *B*, truncated to length *len*.
|
||||
|
||||
.. function:: void acb_poly_neg(acb_poly_t C, const acb_poly_t A)
|
||||
|
||||
Sets *C* to the negation of *A*.
|
||||
|
|
|
@ -234,6 +234,14 @@ Arithmetic
|
|||
|
||||
Sets *C* to the difference of *A* and *B*.
|
||||
|
||||
.. function:: void arb_poly_add_series(arb_poly_t C, const arb_poly_t A, const arb_poly_t B, slong len, slong prec)
|
||||
|
||||
Sets *C* to the sum of *A* and *B*, truncated to length *len*.
|
||||
|
||||
.. function:: void arb_poly_sub_series(arb_poly_t C, const arb_poly_t A, const arb_poly_t B, slong len, slong prec)
|
||||
|
||||
Sets *C* to the difference of *A* and *B*, truncated to length *len*.
|
||||
|
||||
.. function:: void arb_poly_neg(arb_poly_t C, const arb_poly_t A)
|
||||
|
||||
Sets *C* to the negation of *A*.
|
||||
|
|
Loading…
Add table
Reference in a new issue