un-fmprbify arb_union and remove fmprb_union

This commit is contained in:
Fredrik Johansson 2016-02-25 17:08:53 +01:00
parent 7cebb85b15
commit 793fa9abeb
5 changed files with 29 additions and 174 deletions

View file

@ -28,21 +28,39 @@
void
arb_union(arb_t z, const arb_t x, const arb_t y, slong prec)
{
fmprb_t t, u, v;
arf_t left, right, t, xr, yr;
fmprb_init(t);
fmprb_init(u);
fmprb_init(v);
if (arf_is_nan(arb_midref(x)) || arf_is_nan(arb_midref(y)))
{
arb_indeterminate(z);
return;
}
arb_get_fmprb(t, x);
arb_get_fmprb(u, y);
if (mag_is_inf(arb_radref(x)) || mag_is_inf(arb_radref(y)))
{
arb_zero_pm_inf(z);
return;
}
fmprb_union(v, t, u, prec);
arf_init(left);
arf_init(right);
arf_init(t);
arb_set_fmprb(z, v);
arf_init_set_mag_shallow(xr, arb_radref(x));
arf_init_set_mag_shallow(yr, arb_radref(y));
fmprb_clear(t);
fmprb_clear(u);
fmprb_clear(v);
arf_sub(left, arb_midref(x), xr, prec, ARF_RND_FLOOR);
arf_sub(t, arb_midref(y), yr, prec, ARF_RND_FLOOR);
arf_min(left, left, t);
arf_add(right, arb_midref(x), xr, prec, ARF_RND_CEIL);
arf_add(t, arb_midref(y), yr, prec, ARF_RND_CEIL);
arf_max(right, right, t);
arb_set_interval_arf(z, left, right, prec);
arf_clear(left);
arf_clear(right);
arf_clear(t);
}

View file

@ -197,10 +197,6 @@ Radius and interval operations
Adds the supremum of *err*, which is assumed to be nonnegative, to the
radius of *x*.
.. function:: void fmprb_union(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec)
Sets *z* to a ball containing both *x* and *y*.
.. function:: void fmprb_get_abs_ubound_fmpr(fmpr_t u, const fmprb_t x, slong prec)
Sets *u* to the upper bound of the absolute value of *x*,

View file

@ -462,8 +462,6 @@ int fmprb_get_unique_fmpz(fmpz_t z, const fmprb_t x);
void fmprb_set_interval_fmpr(fmprb_t x, const fmpr_t a, const fmpr_t b, slong prec);
void fmprb_union(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec);
static __inline__ slong
fmprb_bits(const fmprb_t x)
{

View file

@ -1,94 +0,0 @@
/*=============================================================================
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 "fmprb.h"
int main()
{
slong iter;
flint_rand_t state;
flint_printf("union....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 100000; iter++)
{
fmprb_t x, y, z;
slong prec;
int alias;
fmprb_init(x);
fmprb_init(y);
fmprb_init(z);
fmprb_randtest_special(x, state, 200, 10);
fmprb_randtest_special(y, state, 200, 10);
fmprb_randtest_special(z, state, 200, 10);
prec = 2 + n_randint(state, 200);
fmprb_union(z, x, y, prec);
if (!fmprb_contains(z, x) || !fmprb_contains(z, y))
{
flint_printf("FAIL:\n\n");
flint_printf("x = "); fmprb_print(x); flint_printf("\n\n");
flint_printf("y = "); fmprb_print(y); flint_printf("\n\n");
flint_printf("z = "); fmprb_print(z); flint_printf("\n\n");
abort();
}
if (n_randint(state, 2))
{
fmprb_union(x, x, y, prec);
alias = fmprb_equal(x, z);
}
else
{
fmprb_union(y, x, y, prec);
alias = fmprb_equal(y, z);
}
if (!alias)
{
flint_printf("FAIL (aliasing):\n\n");
flint_printf("x = "); fmprb_print(x); flint_printf("\n\n");
flint_printf("y = "); fmprb_print(y); flint_printf("\n\n");
flint_printf("z = "); fmprb_print(z); flint_printf("\n\n");
abort();
}
fmprb_clear(x);
fmprb_clear(y);
fmprb_clear(z);
}
flint_randclear(state);
flint_cleanup();
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View file

@ -1,63 +0,0 @@
/*=============================================================================
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) 2013 Fredrik Johansson
******************************************************************************/
#include "fmprb.h"
void
fmprb_union(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec)
{
fmpr_t left, right, t;
if (fmpr_is_nan(fmprb_midref(x)) || fmpr_is_nan(fmprb_midref(y)))
{
fmprb_indeterminate(z);
return;
}
if (fmpr_is_pos_inf(fmprb_radref(x)) || fmpr_is_pos_inf(fmprb_radref(y)))
{
fmprb_zero_pm_inf(z);
return;
}
fmpr_init(left);
fmpr_init(right);
fmpr_init(t);
fmpr_sub(left, fmprb_midref(x), fmprb_radref(x), prec, FMPR_RND_FLOOR);
fmpr_sub(t, fmprb_midref(y), fmprb_radref(y), prec, FMPR_RND_FLOOR);
fmpr_min(left, left, t);
fmpr_add(right, fmprb_midref(x), fmprb_radref(x), prec, FMPR_RND_CEIL);
fmpr_add(t, fmprb_midref(y), fmprb_radref(y), prec, FMPR_RND_CEIL);
fmpr_max(right, right, t);
fmprb_set_interval_fmpr(z, left, right, prec);
fmpr_clear(left);
fmpr_clear(right);
fmpr_clear(t);
}