header file cleanup (de-inlining, etc)

This commit is contained in:
fredrik 2019-01-18 15:34:54 +01:00
parent 2488af9b1d
commit 242fa2e4c0
16 changed files with 389 additions and 248 deletions

100
acb.h
View file

@ -40,7 +40,6 @@ typedef const acb_struct * acb_srcptr;
#define acb_realref(x) (&(x)->real)
#define acb_imagref(x) (&(x)->imag)
ACB_INLINE void
acb_init(acb_t x)
{
@ -329,74 +328,9 @@ void acb_get_mag(mag_t z, const acb_t x);
void acb_get_mag_lower(mag_t z, const acb_t x);
ACB_INLINE void
acb_get_abs_ubound_arf(arf_t u, const acb_t z, slong prec)
{
if (arb_is_zero(acb_imagref(z)))
{
arb_get_abs_ubound_arf(u, acb_realref(z), prec);
}
else if (arb_is_zero(acb_realref(z)))
{
arb_get_abs_ubound_arf(u, acb_imagref(z), prec);
}
else
{
arf_t v;
arf_init(v);
arb_get_abs_ubound_arf(u, acb_realref(z), prec);
arb_get_abs_ubound_arf(v, acb_imagref(z), prec);
arf_mul(u, u, u, prec, ARF_RND_UP);
arf_mul(v, v, v, prec, ARF_RND_UP);
arf_add(u, u, v, prec, ARF_RND_UP);
arf_sqrt(u, u, prec, ARF_RND_UP);
arf_clear(v);
}
}
ACB_INLINE void
acb_get_abs_lbound_arf(arf_t u, const acb_t z, slong prec)
{
if (arb_is_zero(acb_imagref(z)))
{
arb_get_abs_lbound_arf(u, acb_realref(z), prec);
}
else if (arb_is_zero(acb_realref(z)))
{
arb_get_abs_lbound_arf(u, acb_imagref(z), prec);
}
else
{
arf_t v;
arf_init(v);
arb_get_abs_lbound_arf(u, acb_realref(z), prec);
arb_get_abs_lbound_arf(v, acb_imagref(z), prec);
arf_mul(u, u, u, prec, ARF_RND_DOWN);
arf_mul(v, v, v, prec, ARF_RND_DOWN);
arf_add(u, u, v, prec, ARF_RND_DOWN);
arf_sqrt(u, u, prec, ARF_RND_DOWN);
arf_clear(v);
}
}
ACB_INLINE void
acb_get_rad_ubound_arf(arf_t u, const acb_t z, slong prec)
{
/* fixme: this bound is very sloppy */
if (mag_cmp(arb_radref(acb_realref(z)), arb_radref(acb_imagref(z))) >= 0)
arf_set_mag(u, arb_radref(acb_realref(z)));
else
arf_set_mag(u, arb_radref(acb_imagref(z)));
arf_mul_2exp_si(u, u, 1);
}
void acb_get_abs_ubound_arf(arf_t u, const acb_t z, slong prec);
void acb_get_abs_lbound_arf(arf_t u, const acb_t z, slong prec);
void acb_get_rad_ubound_arf(arf_t u, const acb_t z, slong prec);
ACB_INLINE void
acb_union(acb_t res, const acb_t x, const acb_t y, slong prec)
@ -854,15 +788,6 @@ acb_sqr(acb_t res, const acb_t val, slong prec)
acb_mul(res, val, val, prec);
}
/*
TBD
void acb_invroot_newton(acb_t r, const acb_t a, ulong m, const acb_t r0, slong startprec, slong prec);
void acb_root_exp(acb_t r, const acb_t a, slong m, slong index, slong prec);
void acb_root_newton(acb_t r, const acb_t a, slong m, slong index, slong prec);
void acb_root(acb_t r, const acb_t a, slong m, slong index, slong prec);
*/
ACB_INLINE int
acb_is_finite(const acb_t x)
{
@ -1087,7 +1012,6 @@ acb_rel_accuracy_bits(const acb_t x)
return -acb_rel_error_bits(x);
}
ACB_INLINE slong
acb_bits(const acb_t x)
{
@ -1123,23 +1047,7 @@ _acb_vec_bits(acb_srcptr vec, slong len)
return _arb_vec_bits((arb_srcptr) vec, 2 * len);
}
ACB_INLINE void
_acb_vec_set_powers(acb_ptr xs, const acb_t x, slong len, slong prec)
{
slong i;
for (i = 0; i < len; i++)
{
if (i == 0)
acb_one(xs + i);
else if (i == 1)
acb_set_round(xs + i, x, prec);
else if (i % 2 == 0)
acb_mul(xs + i, xs + i / 2, xs + i / 2, prec);
else
acb_mul(xs + i, xs + i - 1, x, prec);
}
}
void _acb_vec_set_powers(acb_ptr xs, const acb_t x, slong len, slong prec);
ACB_INLINE void
_acb_vec_add_error_arf_vec(acb_ptr res, arf_srcptr err, slong len)

40
acb/get_abs_lbound_arf.c Normal file
View file

@ -0,0 +1,40 @@
/*
Copyright (C) 2014 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.h"
void
acb_get_abs_lbound_arf(arf_t u, const acb_t z, slong prec)
{
if (arb_is_zero(acb_imagref(z)))
{
arb_get_abs_lbound_arf(u, acb_realref(z), prec);
}
else if (arb_is_zero(acb_realref(z)))
{
arb_get_abs_lbound_arf(u, acb_imagref(z), prec);
}
else
{
arf_t v;
arf_init(v);
arb_get_abs_lbound_arf(u, acb_realref(z), prec);
arb_get_abs_lbound_arf(v, acb_imagref(z), prec);
arf_mul(u, u, u, prec, ARF_RND_DOWN);
arf_mul(v, v, v, prec, ARF_RND_DOWN);
arf_add(u, u, v, prec, ARF_RND_DOWN);
arf_sqrt(u, u, prec, ARF_RND_DOWN);
arf_clear(v);
}
}

40
acb/get_abs_ubound_arf.c Normal file
View file

@ -0,0 +1,40 @@
/*
Copyright (C) 2014 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.h"
void
acb_get_abs_ubound_arf(arf_t u, const acb_t z, slong prec)
{
if (arb_is_zero(acb_imagref(z)))
{
arb_get_abs_ubound_arf(u, acb_realref(z), prec);
}
else if (arb_is_zero(acb_realref(z)))
{
arb_get_abs_ubound_arf(u, acb_imagref(z), prec);
}
else
{
arf_t v;
arf_init(v);
arb_get_abs_ubound_arf(u, acb_realref(z), prec);
arb_get_abs_ubound_arf(v, acb_imagref(z), prec);
arf_mul(u, u, u, prec, ARF_RND_UP);
arf_mul(v, v, v, prec, ARF_RND_UP);
arf_add(u, u, v, prec, ARF_RND_UP);
arf_sqrt(u, u, prec, ARF_RND_UP);
arf_clear(v);
}
}

25
acb/get_rad_ubound_arf.c Normal file
View file

@ -0,0 +1,25 @@
/*
Copyright (C) 2014 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.h"
void
acb_get_rad_ubound_arf(arf_t u, const acb_t z, slong prec)
{
/* fixme: this bound is very sloppy */
if (mag_cmp(arb_radref(acb_realref(z)), arb_radref(acb_imagref(z))) >= 0)
arf_set_mag(u, arb_radref(acb_realref(z)));
else
arf_set_mag(u, arb_radref(acb_imagref(z)));
arf_mul_2exp_si(u, u, 1);
}

30
acb/vec_set_powers.c Normal file
View file

@ -0,0 +1,30 @@
/*
Copyright (C) 2014 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.h"
void
_acb_vec_set_powers(acb_ptr xs, const acb_t x, slong len, slong prec)
{
slong i;
for (i = 0; i < len; i++)
{
if (i == 0)
acb_one(xs + i);
else if (i == 1)
acb_set_round(xs + i, x, prec);
else if (i % 2 == 0)
acb_mul(xs + i, xs + i / 2, xs + i / 2, prec);
else
acb_mul(xs + i, xs + i - 1, x, prec);
}
}

95
arb.h
View file

@ -291,57 +291,10 @@ arb_get_rad_arb(arb_t z, const arb_t x)
mag_zero(arb_radref(z));
}
ARB_INLINE void
arb_get_abs_ubound_arf(arf_t u, const arb_t x, slong prec)
{
arf_t t;
arf_init_set_mag_shallow(t, arb_radref(x));
if (arf_sgn(arb_midref(x)) < 0)
arf_sub(u, arb_midref(x), t, prec, ARF_RND_UP);
else
arf_add(u, arb_midref(x), t, prec, ARF_RND_UP);
arf_abs(u, u);
}
ARB_INLINE void
arb_get_abs_lbound_arf(arf_t u, const arb_t x, slong prec)
{
arf_t t;
arf_init_set_mag_shallow(t, arb_radref(x));
if (arf_sgn(arb_midref(x)) > 0)
{
arf_sub(u, arb_midref(x), t, prec, ARF_RND_DOWN);
}
else
{
arf_add(u, arb_midref(x), t, prec, ARF_RND_DOWN);
arf_neg(u, u);
}
if (arf_sgn(u) < 0)
arf_zero(u);
}
ARB_INLINE void
arb_get_ubound_arf(arf_t u, const arb_t x, long prec)
{
arf_t t;
arf_init_set_mag_shallow(t, arb_radref(x));
arf_add(u, arb_midref(x), t, prec, ARF_RND_CEIL);
}
ARB_INLINE void
arb_get_lbound_arf(arf_t u, const arb_t x, long prec)
{
arf_t t;
arf_init_set_mag_shallow(t, arb_radref(x));
arf_sub(u, arb_midref(x), t, prec, ARF_RND_FLOOR);
}
void arb_get_abs_ubound_arf(arf_t u, const arb_t x, slong prec);
void arb_get_abs_lbound_arf(arf_t u, const arb_t x, slong prec);
void arb_get_ubound_arf(arf_t u, const arb_t x, long prec);
void arb_get_lbound_arf(arf_t u, const arb_t x, long prec);
void arb_nonnegative_part(arb_t res, const arb_t x);
@ -800,27 +753,7 @@ _arb_vec_scalar_addmul(arb_ptr res, arb_srcptr vec,
arb_addmul(res + i, vec + i, c, prec);
}
ARB_INLINE void
_arb_vec_get_mag(mag_t bound, arb_srcptr vec, slong len)
{
if (len < 1)
{
mag_zero(bound);
}
else
{
mag_t t;
slong i;
arb_get_mag(bound, vec);
mag_init(t);
for (i = 1; i < len; i++)
{
arb_get_mag(t, vec + i);
mag_max(bound, bound, t);
}
mag_clear(t);
}
}
void _arb_vec_get_mag(mag_t bound, arb_srcptr vec, slong len);
ARB_INLINE slong
_arb_vec_bits(arb_srcptr x, slong len)
@ -837,23 +770,7 @@ _arb_vec_bits(arb_srcptr x, slong len)
return b;
}
ARB_INLINE void
_arb_vec_set_powers(arb_ptr xs, const arb_t x, slong len, slong prec)
{
slong i;
for (i = 0; i < len; i++)
{
if (i == 0)
arb_one(xs + i);
else if (i == 1)
arb_set_round(xs + i, x, prec);
else if (i % 2 == 0)
arb_mul(xs + i, xs + i / 2, xs + i / 2, prec);
else
arb_mul(xs + i, xs + i - 1, x, prec);
}
}
void _arb_vec_set_powers(arb_ptr xs, const arb_t x, slong len, slong prec);
ARB_INLINE void
_arb_vec_add_error_arf_vec(arb_ptr res, arf_srcptr err, slong len)

32
arb/get_abs_lbound_arf.c Normal file
View file

@ -0,0 +1,32 @@
/*
Copyright (C) 2014 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.h"
void
arb_get_abs_lbound_arf(arf_t u, const arb_t x, slong prec)
{
arf_t t;
arf_init_set_mag_shallow(t, arb_radref(x));
if (arf_sgn(arb_midref(x)) > 0)
{
arf_sub(u, arb_midref(x), t, prec, ARF_RND_DOWN);
}
else
{
arf_add(u, arb_midref(x), t, prec, ARF_RND_DOWN);
arf_neg(u, u);
}
if (arf_sgn(u) < 0)
arf_zero(u);
}

26
arb/get_abs_ubound_arf.c Normal file
View file

@ -0,0 +1,26 @@
/*
Copyright (C) 2014 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.h"
void
arb_get_abs_ubound_arf(arf_t u, const arb_t x, slong prec)
{
arf_t t;
arf_init_set_mag_shallow(t, arb_radref(x));
if (arf_sgn(arb_midref(x)) < 0)
arf_sub(u, arb_midref(x), t, prec, ARF_RND_UP);
else
arf_add(u, arb_midref(x), t, prec, ARF_RND_UP);
arf_abs(u, u);
}

21
arb/get_lbound_arf.c Normal file
View file

@ -0,0 +1,21 @@
/*
Copyright (C) 2014 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.h"
void
arb_get_lbound_arf(arf_t u, const arb_t x, long prec)
{
arf_t t;
arf_init_set_mag_shallow(t, arb_radref(x));
arf_sub(u, arb_midref(x), t, prec, ARF_RND_FLOOR);
}

21
arb/get_ubound_arf.c Normal file
View file

@ -0,0 +1,21 @@
/*
Copyright (C) 2014 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.h"
void
arb_get_ubound_arf(arf_t u, const arb_t x, long prec)
{
arf_t t;
arf_init_set_mag_shallow(t, arb_radref(x));
arf_add(u, arb_midref(x), t, prec, ARF_RND_CEIL);
}

34
arb/vec_get_mag.c Normal file
View file

@ -0,0 +1,34 @@
/*
Copyright (C) 2014 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.h"
void
_arb_vec_get_mag(mag_t bound, arb_srcptr vec, slong len)
{
if (len < 1)
{
mag_zero(bound);
}
else
{
mag_t t;
slong i;
arb_get_mag(bound, vec);
mag_init(t);
for (i = 1; i < len; i++)
{
arb_get_mag(t, vec + i);
mag_max(bound, bound, t);
}
mag_clear(t);
}
}

30
arb/vec_set_powers.c Normal file
View file

@ -0,0 +1,30 @@
/*
Copyright (C) 2014 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.h"
void
_arb_vec_set_powers(arb_ptr xs, const arb_t x, slong len, slong prec)
{
slong i;
for (i = 0; i < len; i++)
{
if (i == 0)
arb_one(xs + i);
else if (i == 1)
arb_set_round(xs + i, x, prec);
else if (i % 2 == 0)
arb_mul(xs + i, xs + i / 2, xs + i / 2, prec);
else
arb_mul(xs + i, xs + i - 1, x, prec);
}
}

46
fmpr.h
View file

@ -400,52 +400,10 @@ slong _fmpr_add_mpn(fmpr_t z,
mp_srcptr yman, mp_size_t yn, int ysign, const fmpz_t yexp,
slong shift, slong prec, fmpr_rnd_t rnd);
static __inline__ slong
_fmpr_add_1x1(fmpr_t z,
slong _fmpr_add_1x1(fmpr_t z,
mp_limb_t x, int xsign, const fmpz_t xexp,
mp_limb_t y, int ysign, const fmpz_t yexp,
slong shift, slong prec, slong rnd)
{
mp_limb_t hi, lo, t, u;
int sign = ysign;
t = x;
u = y;
(void) yexp; /* unused */
lo = u << shift;
hi = (shift == 0) ? 0 : (u >> (FLINT_BITS - shift));
if (xsign == ysign)
{
add_ssaaaa(hi, lo, hi, lo, 0, t);
}
else
{
if (hi == 0)
{
if (lo >= t)
{
lo = lo - t;
}
else
{
lo = t - lo;
sign = !sign;
}
}
else
{
sub_ddmmss(hi, lo, hi, lo, 0, t);
}
}
if (hi == 0)
return fmpr_set_round_ui_2exp_fmpz(z, lo, xexp, sign, prec, rnd);
else
return fmpr_set_round_uiui_2exp_fmpz(z, hi, lo, xexp, sign, prec, rnd);
}
slong shift, slong prec, slong rnd);
slong fmpr_add_naive(fmpr_t z, const fmpr_t x, const fmpr_t y, slong prec, fmpr_rnd_t rnd);

View file

@ -11,6 +11,53 @@
#include "fmpr.h"
slong
_fmpr_add_1x1(fmpr_t z,
mp_limb_t x, int xsign, const fmpz_t xexp,
mp_limb_t y, int ysign, const fmpz_t yexp,
slong shift, slong prec, slong rnd)
{
mp_limb_t hi, lo, t, u;
int sign = ysign;
t = x;
u = y;
(void) yexp; /* unused */
lo = u << shift;
hi = (shift == 0) ? 0 : (u >> (FLINT_BITS - shift));
if (xsign == ysign)
{
add_ssaaaa(hi, lo, hi, lo, 0, t);
}
else
{
if (hi == 0)
{
if (lo >= t)
{
lo = lo - t;
}
else
{
lo = t - lo;
sign = !sign;
}
}
else
{
sub_ddmmss(hi, lo, hi, lo, 0, t);
}
}
if (hi == 0)
return fmpr_set_round_ui_2exp_fmpz(z, lo, xexp, sign, prec, rnd);
else
return fmpr_set_round_uiui_2exp_fmpz(z, hi, lo, xexp, sign, prec, rnd);
}
static slong
_fmpr_add_special(fmpr_t z, const fmpr_t x, const fmpr_t y, slong prec, fmpr_rnd_t rnd)
{

23
mag.h
View file

@ -321,19 +321,7 @@ mag_inv_lower(mag_t res, const mag_t x)
void mag_mul_2exp_si(mag_t z, const mag_t x, slong y);
MAG_INLINE void
mag_mul_2exp_fmpz(mag_t z, const mag_t x, const fmpz_t y)
{
if (mag_is_special(x))
{
mag_set(z, x);
}
else
{
_fmpz_add2_fast(MAG_EXPREF(z), MAG_EXPREF(x), y, 0);
MAG_MAN(z) = MAG_MAN(x);
}
}
void mag_mul_2exp_fmpz(mag_t z, const mag_t x, const fmpz_t y);
void mag_sub(mag_t z, const mag_t x, const mag_t y);
@ -680,20 +668,18 @@ MAG_INLINE void
mag_mul_ui(mag_t z, const mag_t x, ulong y)
{
mag_t t;
mag_init(t);
mag_init(t); /* no need to clear */
mag_set_ui(t, y);
mag_mul(z, x, t);
mag_clear(t);
}
MAG_INLINE void
mag_mul_ui_lower(mag_t z, const mag_t x, ulong y)
{
mag_t t;
mag_init(t);
mag_init(t); /* no need to clear */
mag_set_ui_lower(t, y);
mag_mul_lower(z, x, t);
mag_clear(t);
}
MAG_INLINE void
@ -720,10 +706,9 @@ MAG_INLINE void
mag_div_ui(mag_t z, const mag_t x, ulong y)
{
mag_t t;
mag_init(t);
mag_init(t); /* no need to clear */
mag_set_ui_lower(t, y);
mag_div(z, x, t);
mag_clear(t);
}
MAG_INLINE void

27
mag/mul_2exp_fmpz.c Normal file
View file

@ -0,0 +1,27 @@
/*
Copyright (C) 2014 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 "mag.h"
void
mag_mul_2exp_fmpz(mag_t z, const mag_t x, const fmpz_t y)
{
if (mag_is_special(x))
{
mag_set(z, x);
}
else
{
_fmpz_add2_fast(MAG_EXPREF(z), MAG_EXPREF(x), y, 0);
MAG_MAN(z) = MAG_MAN(x);
}
}