| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| /*============================================================================= | ||
| This file is part of ARB. | ||
| ARB is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| ARB is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ARB; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| =============================================================================*/ | ||
| /****************************************************************************** | ||
| Copyright (C) 2012 Fredrik Johansson | ||
| ******************************************************************************/ | ||
|
|
||
| #include "arb.h" | ||
|
|
||
| int main() | ||
| { | ||
| long iter; | ||
| flint_rand_t state; | ||
|
|
||
| printf("mul...."); | ||
| fflush(stdout); | ||
|
|
||
| flint_randinit(state); | ||
|
|
||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b, c; | ||
| fmpq_t x, y, z; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
| arb_init(c, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
| fmpq_init(z); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
| arb_randtest(c, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
|
|
||
| arb_mul(c, a, b); | ||
| fmpq_mul(z, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(c, z)) | ||
| { | ||
| printf("FAIL: containment\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| printf("c = "); arb_debug(c); printf("\n\n"); | ||
| printf("z = "); fmpq_print(z); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
| arb_clear(c); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| fmpq_clear(z); | ||
| } | ||
|
|
||
| /* aliasing of c and a */ | ||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b; | ||
| fmpq_t x, y, z; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
| fmpq_init(z); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
|
|
||
| arb_mul(a, a, b); | ||
| fmpq_mul(z, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(a, z)) | ||
| { | ||
| printf("FAIL: aliasing (c, a)\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| printf("z = "); fmpq_print(z); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| fmpq_clear(z); | ||
| } | ||
|
|
||
| /* aliasing of c and b */ | ||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b; | ||
| fmpq_t x, y, z; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
| fmpq_init(z); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
|
|
||
| arb_mul(b, a, b); | ||
| fmpq_mul(z, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(b, z)) | ||
| { | ||
| printf("FAIL: aliasing (c, b)\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| printf("z = "); fmpq_print(z); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| fmpq_clear(z); | ||
| } | ||
|
|
||
| flint_randclear(state); | ||
| _fmpz_cleanup(); | ||
| printf("PASS\n"); | ||
| return EXIT_SUCCESS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /*============================================================================= | ||
| This file is part of ARB. | ||
| ARB is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| ARB is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ARB; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| =============================================================================*/ | ||
| /****************************************************************************** | ||
| Copyright (C) 2012 Fredrik Johansson | ||
| ******************************************************************************/ | ||
|
|
||
| #include "arb.h" | ||
|
|
||
| int main() | ||
| { | ||
| long iter; | ||
| flint_rand_t state; | ||
|
|
||
| printf("set_fmpq...."); | ||
| fflush(stdout); | ||
|
|
||
| flint_randinit(state); | ||
|
|
||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a; | ||
| fmpq_t x; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| fmpq_init(x); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| fmpq_randtest(x, state, 1 + n_randint(state, 200)); | ||
| arb_set_fmpq(a, x); | ||
|
|
||
| if (!arb_contains_fmpq(a, x)) | ||
| { | ||
| printf("FAIL\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| fmpq_clear(x); | ||
| } | ||
|
|
||
| flint_randclear(state); | ||
| _fmpz_cleanup(); | ||
| printf("PASS\n"); | ||
| return EXIT_SUCCESS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /*============================================================================= | ||
| This file is part of ARB. | ||
| ARB is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| ARB is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ARB; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| =============================================================================*/ | ||
| /****************************************************************************** | ||
| Copyright (C) 2012 Fredrik Johansson | ||
| ******************************************************************************/ | ||
|
|
||
| #include "arb.h" | ||
|
|
||
| int main() | ||
| { | ||
| long iter; | ||
| flint_rand_t state; | ||
|
|
||
| printf("sqrt_fmpz...."); | ||
| fflush(stdout); | ||
|
|
||
| flint_randinit(state); | ||
|
|
||
| /* check (sqrt(n))^2 contains n */ | ||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b; | ||
| fmpz_t n; | ||
|
|
||
| arb_init(a, 1 + n_randint(state, 500)); | ||
| arb_init(b, 1 + n_randint(state, 500)); | ||
|
|
||
| fmpz_init(n); | ||
| fmpz_randtest_unsigned(n, state, 1 + n_randint(state, 500)); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
|
|
||
| arb_sqrt_fmpz(a, n); | ||
| arb_mul(b, a, a); | ||
|
|
||
| if (!arb_contains_fmpz(b, n)) | ||
| { | ||
| printf("FAIL: containment\n\n"); | ||
| printf("n = "); fmpz_print(n); printf("\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
| fmpz_clear(n); | ||
| } | ||
|
|
||
| flint_randclear(state); | ||
| _fmpz_cleanup(); | ||
| printf("PASS\n"); | ||
| return EXIT_SUCCESS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /*============================================================================= | ||
| This file is part of ARB. | ||
| ARB is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| ARB is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ARB; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| =============================================================================*/ | ||
| /****************************************************************************** | ||
| Copyright (C) 2012 Fredrik Johansson | ||
| ******************************************************************************/ | ||
|
|
||
| #include "arb.h" | ||
|
|
||
| int main() | ||
| { | ||
| long iter; | ||
| flint_rand_t state; | ||
|
|
||
| printf("sqrt_ui...."); | ||
| fflush(stdout); | ||
|
|
||
| flint_randinit(state); | ||
|
|
||
| /* check (sqrt(a))^2 contains a */ | ||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b; | ||
| ulong n; | ||
|
|
||
| arb_init(a, 1 + n_randint(state, 500)); | ||
| arb_init(b, 1 + n_randint(state, 500)); | ||
|
|
||
| n = n_randtest(state); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
|
|
||
| arb_sqrt_ui(a, n); | ||
| arb_mul(b, a, a); | ||
|
|
||
| if (!arb_contains_ui(b, n)) | ||
| { | ||
| printf("FAIL: containment\n\n"); | ||
| printf("n = %lu\n\n", n); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
| } | ||
|
|
||
| flint_randclear(state); | ||
| _fmpz_cleanup(); | ||
| printf("PASS\n"); | ||
| return EXIT_SUCCESS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| /*============================================================================= | ||
| This file is part of ARB. | ||
| ARB is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| ARB is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ARB; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| =============================================================================*/ | ||
| /****************************************************************************** | ||
| Copyright (C) 2012 Fredrik Johansson | ||
| ******************************************************************************/ | ||
|
|
||
| #include "arb.h" | ||
|
|
||
| int main() | ||
| { | ||
| long iter; | ||
| flint_rand_t state; | ||
|
|
||
| printf("sub...."); | ||
| fflush(stdout); | ||
|
|
||
| flint_randinit(state); | ||
|
|
||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b, c; | ||
| fmpq_t x, y, z; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
| arb_init(c, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
| fmpq_init(z); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
| arb_randtest(c, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
|
|
||
| arb_sub(c, a, b); | ||
| fmpq_sub(z, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(c, z)) | ||
| { | ||
| printf("FAIL: containment\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| printf("c = "); arb_debug(c); printf("\n\n"); | ||
| printf("z = "); fmpq_print(z); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
| arb_clear(c); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| fmpq_clear(z); | ||
| } | ||
|
|
||
| /* aliasing of c and a */ | ||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b; | ||
| fmpq_t x, y, z; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
| fmpq_init(z); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
|
|
||
| arb_sub(a, a, b); | ||
| fmpq_sub(z, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(a, z)) | ||
| { | ||
| printf("FAIL: aliasing (c, a)\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| printf("z = "); fmpq_print(z); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| fmpq_clear(z); | ||
| } | ||
|
|
||
| /* aliasing of c and b */ | ||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b; | ||
| fmpq_t x, y, z; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
| fmpq_init(z); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
|
|
||
| arb_sub(b, a, b); | ||
| fmpq_sub(z, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(b, z)) | ||
| { | ||
| printf("FAIL: aliasing (c, b)\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| printf("z = "); fmpq_print(z); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| fmpq_clear(z); | ||
| } | ||
|
|
||
| flint_randclear(state); | ||
| _fmpz_cleanup(); | ||
| printf("PASS\n"); | ||
| return EXIT_SUCCESS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| /*============================================================================= | ||
| This file is part of ARB. | ||
| ARB is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| ARB is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ARB; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| =============================================================================*/ | ||
| /****************************************************************************** | ||
| Copyright (C) 2012 Fredrik Johansson | ||
| ******************************************************************************/ | ||
|
|
||
| #include "arb.h" | ||
|
|
||
| int main() | ||
| { | ||
| long iter; | ||
| flint_rand_t state; | ||
|
|
||
| printf("submul...."); | ||
| fflush(stdout); | ||
|
|
||
| flint_randinit(state); | ||
|
|
||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b, c; | ||
| fmpq_t x, y, z; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
| arb_init(c, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
| fmpq_init(z); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
| arb_randtest(c, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
| arb_get_rand_fmpq(z, state, c); | ||
|
|
||
| arb_submul(c, a, b); | ||
| fmpq_submul(z, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(c, z)) | ||
| { | ||
| printf("FAIL: containment\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| printf("c = "); arb_debug(c); printf("\n\n"); | ||
| printf("z = "); fmpq_print(z); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
| arb_clear(c); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| fmpq_clear(z); | ||
| } | ||
|
|
||
| /* aliasing of c and a */ | ||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b; | ||
| fmpq_t x, y; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
|
|
||
| arb_submul(a, a, b); | ||
| fmpq_submul(x, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(a, x)) | ||
| { | ||
| printf("FAIL: aliasing (c, a)\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| } | ||
|
|
||
| /* aliasing of c and b */ | ||
| for (iter = 0; iter < 10000; iter++) | ||
| { | ||
| arb_t a, b; | ||
| fmpq_t x, y; | ||
|
|
||
| arb_init(a, n_randint(state, 200)); | ||
| arb_init(b, n_randint(state, 200)); | ||
|
|
||
| fmpq_init(x); | ||
| fmpq_init(y); | ||
|
|
||
| arb_randtest(a, state, 10); | ||
| arb_randtest(b, state, 10); | ||
|
|
||
| arb_get_rand_fmpq(x, state, a); | ||
| arb_get_rand_fmpq(y, state, b); | ||
|
|
||
| arb_submul(b, a, b); | ||
| fmpq_submul(y, x, y); | ||
|
|
||
| if (!arb_contains_fmpq(b, y)) | ||
| { | ||
| printf("FAIL: aliasing (c, b)\n\n"); | ||
| printf("a = "); arb_debug(a); printf("\n\n"); | ||
| printf("x = "); fmpq_print(x); printf("\n\n"); | ||
| printf("b = "); arb_debug(b); printf("\n\n"); | ||
| printf("y = "); fmpq_print(y); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(a); | ||
| arb_clear(b); | ||
|
|
||
| fmpq_clear(x); | ||
| fmpq_clear(y); | ||
| } | ||
|
|
||
| flint_randclear(state); | ||
| _fmpz_cleanup(); | ||
| printf("PASS\n"); | ||
| return EXIT_SUCCESS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /*============================================================================= | ||
| This file is part of ARB. | ||
| ARB is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| ARB is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ARB; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| =============================================================================*/ | ||
| /****************************************************************************** | ||
| Copyright (C) 2012 Fredrik Johansson | ||
| ******************************************************************************/ | ||
|
|
||
| #include "arb.h" | ||
|
|
||
| int main() | ||
| { | ||
| long iter; | ||
| flint_rand_t state; | ||
|
|
||
| printf("zeta_ui_bsplit...."); | ||
| fflush(stdout); | ||
|
|
||
| flint_randinit(state); | ||
|
|
||
| for (iter = 0; iter < 1000; iter++) | ||
| { | ||
| arb_t r; | ||
| ulong n; | ||
| mpfr_t s; | ||
| long effective_prec; | ||
|
|
||
| arb_init(r, 1 + n_randint(state, 1 << n_randint(state, 14))); | ||
| mpfr_init2(s, arb_prec(r) + 100); | ||
| arb_randtest(r, state, 10); | ||
|
|
||
| do { n = n_randint(state, 1 << n_randint(state, 10)); } while (n == 1); | ||
|
|
||
| arb_zeta_ui_bsplit(r, n); | ||
| mpfr_zeta_ui(s, n, MPFR_RNDN); | ||
|
|
||
| if (!arb_contains_mpfr(r, s)) | ||
| { | ||
| printf("FAIL: containment\n\n"); | ||
| printf("n = %lu\n\n", n); | ||
| printf("r = "); arb_debug(r); printf("\n\n"); | ||
| printf("s = "); mpfr_printf("%.275Rf\n", s); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| effective_prec = fmpz_bits(arb_midref(r)) - fmpz_bits(arb_radref(r)); | ||
|
|
||
| if (!fmpz_is_zero(arb_radref(r)) && effective_prec < arb_prec(r) - 4) | ||
| { | ||
| printf("FAIL: poor accuracy\n\n"); | ||
| printf("r = "); arb_debug(r); printf("\n\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| arb_clear(r); | ||
| mpfr_clear(s); | ||
| } | ||
|
|
||
| flint_randclear(state); | ||
| _fmpz_cleanup(); | ||
| mpfr_free_cache(); | ||
| printf("PASS\n"); | ||
| return EXIT_SUCCESS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| /*============================================================================= | ||
| This file is part of ARB. | ||
| ARB is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
| ARB is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with ARB; if not, write to the Free Software | ||
| Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| =============================================================================*/ | ||
| /****************************************************************************** | ||
| Copyright (C) 2012 Fredrik Johansson | ||
| ******************************************************************************/ | ||
|
|
||
| #include "arb.h" | ||
|
|
||
| /* With parameter n, the error is bounded by 3/(3+sqrt(8))^n */ | ||
| #define ERROR_A 1.5849625007211561815 /* log2(3) */ | ||
| #define ERROR_B 2.5431066063272239453 /* log2(3+sqrt(8)) */ | ||
|
|
||
| typedef struct | ||
| { | ||
| arb_t A; | ||
| arb_t B; | ||
| arb_t C; | ||
| arb_t D; | ||
| arb_t E; | ||
| arb_t Q1; | ||
| arb_t Q2; | ||
| arb_t Q3; | ||
| } | ||
| zeta_bsplit_state; | ||
|
|
||
| typedef zeta_bsplit_state zeta_bsplit_t[1]; | ||
|
|
||
| static __inline__ void | ||
| zeta_bsplit_init(zeta_bsplit_t S, long prec) | ||
| { | ||
| arb_init(S->A, prec); | ||
| arb_init(S->B, prec); | ||
| arb_init(S->C, prec); | ||
| arb_init(S->D, prec); | ||
| arb_init(S->E, prec); | ||
| arb_init(S->Q1, prec); | ||
| arb_init(S->Q2, prec); | ||
| arb_init(S->Q3, prec); | ||
| } | ||
|
|
||
| static __inline__ void | ||
| zeta_bsplit_clear(zeta_bsplit_t S) | ||
| { | ||
| arb_clear(S->A); | ||
| arb_clear(S->B); | ||
| arb_clear(S->C); | ||
| arb_clear(S->D); | ||
| arb_clear(S->E); | ||
| arb_clear(S->Q1); | ||
| arb_clear(S->Q2); | ||
| arb_clear(S->Q3); | ||
| } | ||
|
|
||
|
|
||
| static __inline__ void | ||
| zeta_coeff_k(zeta_bsplit_t S, long k, long n, long s) | ||
| { | ||
| if (k + 1 < 0) | ||
| { | ||
| arb_set_si(S->D, 1); | ||
| arb_set_si(S->Q1, 1); | ||
| } | ||
| else if (k + 1 > n) | ||
| { | ||
| arb_zero(S->D); | ||
| arb_set_si(S->Q1, 1); | ||
| } | ||
| else | ||
| { | ||
| arb_set_si(S->D, 2 * (n + (k + 1) - 1)); | ||
| arb_mul_si(S->D, S->D, n + 1 - (k + 1)); | ||
| arb_set_si(S->Q1, k + 1); | ||
| arb_mul_si(S->Q1, S->Q1, 2*(k + 1) - 1); | ||
| } | ||
|
|
||
| if (k - 1 < 0) | ||
| { | ||
| arb_zero(S->E); | ||
| arb_set_si(S->Q2, 1); | ||
| } | ||
| else if (k - 1 >= n) | ||
| { | ||
| arb_set_si(S->E, 1); | ||
| arb_set_si(S->Q2, 1); | ||
| } | ||
| else | ||
| { | ||
| arb_set_si(S->E, ((k - 1) % 2) ? -1 : 1); | ||
| arb_set_si(S->Q2, k); | ||
| fmpz_pow_ui(arb_midref(S->Q2), arb_midref(S->Q2), s); /* XXX */ | ||
| } | ||
|
|
||
| arb_mul(S->Q3, S->Q1, S->Q2); | ||
| arb_mul(S->A, S->E, S->Q1); | ||
| arb_zero(S->B); | ||
| arb_set(S->C, S->Q1); | ||
| } | ||
|
|
||
| static void | ||
| zeta_bsplit(zeta_bsplit_t L, long a, long b, | ||
| long n, long s, int cont, long bits) | ||
| { | ||
| if (a + 1 == b) | ||
| { | ||
| zeta_coeff_k(L, a, n, s); | ||
| } | ||
| else | ||
| { | ||
| zeta_bsplit_t R; | ||
|
|
||
| long m = (a + b) / 2; | ||
|
|
||
| zeta_bsplit(L, m, b, n, s, 1, bits); | ||
|
|
||
| zeta_bsplit_init(R, bits); | ||
| zeta_bsplit(R, a, m, n, s, 1, bits); | ||
|
|
||
| arb_mul(L->E, L->E, R->Q2); | ||
| arb_addmul(L->E, R->E, L->Q2); | ||
|
|
||
| arb_mul(L->B, L->B, R->D); | ||
| arb_addmul(L->B, L->A, R->C); | ||
|
|
||
| arb_mul(L->B, L->B, R->Q2); | ||
| arb_addmul(L->B, R->B, L->Q3); | ||
|
|
||
| if (cont) | ||
| { | ||
| arb_mul(L->A, L->A, R->Q3); | ||
| arb_addmul(L->A, R->A, L->Q3); | ||
| } | ||
|
|
||
| arb_mul(L->C, L->C, R->D); | ||
| arb_addmul(L->C, R->C, L->Q1); | ||
| arb_mul(L->Q2, L->Q2, R->Q2); | ||
|
|
||
| if (cont) | ||
| { | ||
| arb_mul(L->D, L->D, R->D); | ||
| arb_mul(L->Q1, L->Q1, R->Q1); | ||
| arb_mul(L->Q3, L->Q3, R->Q3); | ||
| } | ||
|
|
||
| zeta_bsplit_clear(R); | ||
| } | ||
| } | ||
|
|
||
| void | ||
| arb_zeta_ui_bsplit(arb_t x, ulong s) | ||
| { | ||
| zeta_bsplit_t sum; | ||
| long prec, wp, n; | ||
| long i; | ||
|
|
||
| /* zeta(0) = -1/2 */ | ||
| if (s == 0) | ||
| { | ||
| fmpz_set_si(arb_midref(x), -1); | ||
| fmpz_set_si(arb_expref(x), -1); | ||
| fmpz_zero(arb_radref(x)); | ||
| return; | ||
| } | ||
|
|
||
| if (s == 1) | ||
| { | ||
| printf("arb_zeta_ui_bsplit: zeta(1)"); | ||
| abort(); | ||
| } | ||
|
|
||
| prec = arb_prec(x); | ||
|
|
||
| /* for s > p, zeta(s) - 1 < 2^(-p) */ | ||
| if (s != 2 && s > prec) | ||
| { | ||
| fmpz_one(arb_midref(x)); | ||
| fmpz_mul_2exp(arb_midref(x), arb_midref(x), prec); | ||
| fmpz_set_si(arb_expref(x), -prec); | ||
| fmpz_one(arb_radref(x)); | ||
| return; | ||
| } | ||
|
|
||
| n = prec / ERROR_B + 2; | ||
| wp = prec + 30; | ||
|
|
||
| zeta_bsplit_init(sum, wp); | ||
| zeta_bsplit(sum, 0, n + 1, n, s, 0, wp); | ||
|
|
||
| arb_mul(sum->E, sum->E, sum->C); | ||
| arb_sub(sum->E, sum->E, sum->B); | ||
| arb_mul(sum->Q2, sum->Q2, sum->C); | ||
| arb_div(sum->C, sum->E, sum->Q2); | ||
|
|
||
| /* D = 1/(1 - 2^(1-s)) */ | ||
| fmpz_zero(arb_midref(sum->D)); | ||
| for (i = wp; i >= 0; i -= (s - 1)) | ||
| fmpz_setbit(arb_midref(sum->D), i); | ||
| fmpz_set_si(arb_expref(sum->D), -wp); | ||
| fmpz_set_ui(arb_radref(sum->D), 1UL); | ||
|
|
||
| arb_mul(x, sum->C, sum->D); | ||
|
|
||
| /* The error is bounded by 3/(3+sqrt(8))^n */ | ||
| arb_add_error_2exp(x, (long) (ERROR_A - ERROR_B * n + 1)); | ||
|
|
||
| zeta_bsplit_clear(sum); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| #!/bin/sh | ||
|
|
||
| # (C) 2007, Robert Bradshaw, William Hart, William Stein, Michael Abshoff | ||
| # (C) 2011, William Hart | ||
|
|
||
| PREFIX="/usr/local" | ||
| MPIR_DIR="/usr/local" | ||
| MPFR_DIR="/usr/local" | ||
| FLINT_DIR="/home/fredrik/src/flint2/flint2" | ||
| SHARED=1 | ||
| STATIC=1 | ||
|
|
||
| usage() | ||
| { | ||
| echo "Usage: ./configure <options> <args>" | ||
| echo " where <options> may be" | ||
| echo " -h display usage information" | ||
| echo " where <args> may be:" | ||
| echo " --with-mpir=<path> Specify location of MPIR" | ||
| echo " --with-mpfr=<path> Specify location of MPFR" | ||
| echo " --prefix=<path> Specify path to installation location" | ||
| echo " --disable-shared Do not build a shared library" | ||
| echo " --disable-static Do not build a static library" | ||
| echo " CC=<name> Use the C compiler with the given name" | ||
| echo " AR=<name> Use the AR library builder with the given name" | ||
| echo " CFLAGS=<flags> Pass the given flags to the compiler" | ||
| } | ||
|
|
||
| until [ -z "$1" ]; do | ||
| case $1 in | ||
| "-h") usage | ||
| exit 0 | ||
| ;; | ||
| "--with-mpir="*) | ||
| MPIR_DIR=`expr substr $1 13 length $1` | ||
| ;; | ||
| "--with-mpfr="*) | ||
| MPFR_DIR=`expr substr $1 13 length $1` | ||
| ;; | ||
| "--prefix="*) | ||
| PREFIX=`expr substr $1 10 length $1` | ||
| ;; | ||
| "--disable-shared") | ||
| SHARED=0 | ||
| ;; | ||
| "--disable-static") | ||
| STATIC=0 | ||
| ;; | ||
| "AR="*) | ||
| AR=`expr substr $1 4 length $1` | ||
| ;; | ||
| "CC="*) | ||
| CC=`expr substr $1 4 length $1` | ||
| ;; | ||
| "CFLAGS="*) | ||
| CFLAGS=`expr substr $1 8 length $1` | ||
| ;; | ||
| *) usage | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| shift | ||
| done | ||
|
|
||
| if [ -d "${MPIR_DIR}/lib" ]; then | ||
| MPIR_LIB_DIR="${MPIR_DIR}/lib" | ||
| MPIR_INCLUDE_DIR="${MPIR_DIR}/include" | ||
| elif [ -d "${MPIR_DIR}/.libs" ]; then | ||
| MPIR_LIB_DIR="${MPIR_DIR}/.libs" | ||
| MPIR_INCLUDE_DIR="${MPIR_DIR}" | ||
| else | ||
| echo "Invalid MPIR directory" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -d "${MPFR_DIR}/lib" ]; then | ||
| MPFR_LIB_DIR="${MPFR_DIR}/lib" | ||
| MPFR_INCLUDE_DIR="${MPFR_DIR}/include" | ||
| elif [ -d "${MPFR_DIR}/.libs" ]; then | ||
| MPFR_LIB_DIR="${MPFR_DIR}/.libs" | ||
| MPFR_INCLUDE_DIR="${MPFR_DIR}" | ||
| else | ||
| echo "Invalid MPFR directory" | ||
| exit 1 | ||
| fi | ||
|
|
||
| FLINT_LIB_DIR="${FLINT_DIR}" | ||
| FLINT_INCLUDE_DIR="${FLINT_DIR}" | ||
|
|
||
| if [ "`uname`" = "Linux" -a "`uname -m`" = "x86_64" ]; then | ||
| ARB_TUNE="-funroll-loops " | ||
| elif [ "`uname`" = "Darwin" -a "`uname -m`" = "Power Macintosh" ]; then | ||
| ARB_TUNE=" -funroll-loops " | ||
| elif [ "`uname -p`" = "powerpc" ]; then | ||
| ARB_TUNE="-m64 -mcpu=970 -mtune=970 -mpowerpc64 -falign-loops=16 -falign-functions=16 -falign-labels=16 -falign-jumps=16" | ||
| elif [ "`uname -m`" = "ia64" ]; then | ||
| # -funroll-loops crashes the build on itanium under GCC-4.2.1, as reported by | ||
| # Kate Minola. | ||
| ARB_TUNE=" " | ||
| else | ||
| ARB_TUNE="-funroll-loops " | ||
| fi | ||
|
|
||
| if [ "`uname`" = "Darwin" ]; then | ||
| ARB_LIB="libarb.dylib" | ||
| else | ||
| ARB_LIB="libarb.so" | ||
| fi | ||
|
|
||
| if [ -z "$CFLAGS" ]; then | ||
| CFLAGS="-O2 -g -ansi -pedantic -Wall" | ||
| fi | ||
|
|
||
| if [ -z "$CC" ]; then | ||
| CC=gcc | ||
| fi | ||
|
|
||
| CFLAGS="$CFLAGS $ARB_TUNE" | ||
|
|
||
| echo "# This file is autogenerated by ./configure -- do not edit!" > Makefile | ||
| echo "" >> Makefile | ||
| if [ "$STATIC" = "1" ]; then | ||
| echo "ARB_STATIC=1" >> Makefile | ||
| fi | ||
| if [ "$SHARED" = "1" ]; then | ||
| echo "ARB_SHARED=1" >> Makefile | ||
| fi | ||
| echo "ARB_MPIR_LIB_DIR=$MPIR_LIB_DIR" >> Makefile | ||
| echo "ARB_MPIR_INCLUDE_DIR=$MPIR_INCLUDE_DIR" >> Makefile | ||
| echo "ARB_MPFR_LIB_DIR=$MPFR_LIB_DIR" >> Makefile | ||
| echo "ARB_MPFR_INCLUDE_DIR=$MPFR_INCLUDE_DIR" >> Makefile | ||
| echo "ARB_FLINT_LIB_DIR=$FLINT_LIB_DIR" >> Makefile | ||
| echo "ARB_FLINT_INCLUDE_DIR=$FLINT_INCLUDE_DIR" >> Makefile | ||
| echo "" >> Makefile | ||
| echo "ARB_LIB=$ARB_LIB" >> Makefile | ||
| echo "CC=$CC" >> Makefile | ||
| echo "CFLAGS=$CFLAGS" >> Makefile | ||
| echo "PREFIX=$PREFIX" >> Makefile | ||
| echo "" >> Makefile | ||
|
|
||
| cat Makefile.in >> Makefile | ||
|
|