flintlib / arb

Arb has been merged into FLINT -- use https://github.com/flintlib/flint/ instead
http://arblib.org/
GNU Lesser General Public License v2.1
457 stars 137 forks source link

Would you want to have an arb_abs_slow() function? #441

Closed postmath closed 1 year ago

postmath commented 1 year ago

The documentation for arb_abs states that "[n]o attempt is made to improve the interval represented by x if it contains zero". That is of course the right design for the "default" implementation of the abs function. But would it make sense to have an alternative that does do this? Something like this:

arb_abs_slow(arb_t y, const arb_t x, slong prec) {
  if(arb_is_finite(x) && arb_contains_zero(x)) {
    arb_get_abs_ubound_arf(arb_midref(y), x, prec);
    /* Now t :=arb_midref(y) is the upper bound of the interval x; we need to set arb_midref(y) and arb_radref(y) to (approximations of) t/2.  */
    arf_mul_2exp_si(arb_midref(y), arb_midref(y), -1);
    arf_get_mag(arb_radref(y), arb_midref(y));
    /* Note the above is inexact (rounding up), so need to update arb_midref(y) to match again */
    arf_set_mag(arb_midref(y), arb_radref(y));
  }
  else {
    arf_abs(arb_midref(y), arb_midref(x));
    mag_set(arb_radref(y), arb_radref(x));
  }
}

If you like this idea, I'll write it up a bit more nicely, test & document it, and create a pull request. Otherwise we'll implement it in our wrapper library.

postmath commented 1 year ago

Maybe we should use MAG_BITS instead of prec for this, since the second half uses MAG_BITS anyway.

fredrik-johansson commented 1 year ago

Yes, that would be useful to have. I think there are a few places in the library where this ought to replace arb_abs, too.

postmath commented 1 year ago

On it. Would you like to suggest a better name than arb_abs_slow, or shall I use that?

fredrik-johansson commented 1 year ago

Maybe arb_nonnegative_abs to match arb_nonnegative_part?

The prec argument looks redundant.

postmath commented 1 year ago

Okay, I'll use that. Yes, I only used prec before I realized the precision would be dropped to MAG_BITS anyway.

Erik

On Tue, Nov 8, 2022, 17:23 Fredrik Johansson @.***> wrote:

Maybe arb_nonnegative_abs to match arb_nonnegative_part?

The prec argument looks redundant.

— Reply to this email directly, view it on GitHub https://github.com/fredrik-johansson/arb/issues/441#issuecomment-1307912104, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDYH3X2O3STRAVV2NVXHPDWHLHE3ANCNFSM6AAAAAAR2XDEZA . You are receiving this because you authored the thread.Message ID: @.***>

postmath commented 1 year ago

Thinking about the name a bit more, arb_abs_nonnegative feels more natural to me than arb_nonnegative_abs. I'll go ahead with what you suggested originally, but let me know if you're okay with that name and I'll modify it.