Skip to content

arb_pow loses containment when the output aliases an inexact exponent #2879

Closed

Description

@vera-rubin

Describe the bug

With base [0,2] and exponent [1,3], arb_pow(exponent, base, exponent, 64) returns a ball whose upper endpoint is below the exact result 2^3 = 8. The same call with a separate output contains 8.

This reproduces in FLINT 3.7.0-dev at 26b9bc9df973206db15616d0849a4c8be9d22059, FLINT 3.6.0, and the FLINT 3.6.0 library bundled with python-flint 0.9.0.

Steps to reproduce

Save this as repro.c in a new directory:

/* Contract: arb_pow allows result/input aliasing (doc/source/issues.rst).
   Independent exact witness: 2 in [0,2], 3 in [1,3], and 2^3 = 8. */
#include <stdio.h>
#include "arb.h"

int main(void)
{
    arb_t base, exponent, separate;
    arf_t radius;
    fmpz_t mantissa, binary_exponent;
    int control, actual;
    arb_init(base);
    arb_init(exponent);
    arb_init(separate);
    arf_init(radius);
    fmpz_init(mantissa);
    fmpz_init(binary_exponent);

    arb_one(base);
    mag_one(arb_radref(base));             /* [0,2] */
    arb_set_ui(exponent, 2);
    mag_one(arb_radref(exponent));         /* [1,3] */

    arb_pow(separate, base, exponent, 64);
    control = arb_contains_si(separate, 8);
    arb_pow(exponent, base, exponent, 64);
    actual = arb_contains_si(exponent, 8);
    printf("separate result contains exact witness 8: %d\n", control);
    printf("aliased result contains exact witness 8: %d\n", actual);
    arf_get_fmpz_2exp(mantissa, binary_exponent, arb_midref(exponent));
    printf("aliased midpoint = "); fmpz_print(mantissa);
    printf(" * 2^"); fmpz_print(binary_exponent); printf("\n");
    arf_set_mag(radius, arb_radref(exponent));
    arf_get_fmpz_2exp(mantissa, binary_exponent, radius);
    printf("aliased radius = "); fmpz_print(mantissa);
    printf(" * 2^"); fmpz_print(binary_exponent); printf("\n");

    fmpz_clear(mantissa);
    fmpz_clear(binary_exponent);
    arf_clear(radius);
    arb_clear(base);
    arb_clear(exponent);
    arb_clear(separate);
    flint_cleanup();
    return control && actual ? 0 : 1;       /* 1 = contract violation */
}

On Linux with GMP/MPFR development headers and Autotools installed, run from that directory:

git clone https://github.com/flintlib/flint.git flint
cd flint
git checkout --detach 26b9bc9df973206db15616d0849a4c8be9d22059
./bootstrap.sh
./configure
make -j3
cc -O2 -Isrc ../repro.c -L. -Wl,-rpath,"$PWD" -lflint -o ../pow-exponent-alias
cd ..
./pow-exponent-alias

Observed output in all three tested libraries:

separate result contains exact witness 8: 1
aliased result contains exact witness 8: 0
aliased midpoint = 536870921 * 2^-28
aliased radius = 536870921 * 2^-28

The reproducer exits 1. The exact midpoint and radius are both 536870921 * 2^-28. The returned interval is therefore [0, 536870921/134217728], whose upper endpoint is about 4.000000067 and is strictly below 8.

Expected behavior

Arb's containment guarantee, arb.rst lines 9-11 requires the output to contain the exact operation for every choice of points in the input balls. Since 2 belongs to the base ball and 3 belongs to the exponent ball, the output must contain 8.

The aliasing rule, issues.rst lines 49-58 allows input/output aliasing between variables of the same type unless an exception is documented. Both inputs and the output here are arb_t. The input variables have distinct storage. The arb_pow entry, arb.rst lines 1080-1085 explicitly covers a base of the form a +/- a with a positive exponent and gives no aliasing exception.

System (please complete the following information):

  • System CPU: AMD EPYC 9J14, x86_64. Linux 6.17.0-1020-oracle, 64-bit FLINT.
  • Development build: FLINT 3.7.0-dev at 26b9bc9df973206db15616d0849a4c8be9d22059. Upstream main still equaled this pin when checked on 2026-10-12 UTC.
  • Source release: FLINT 3.6.0, tag v3.6.0, commit 8d5454b96761fafe4d5a9da76a369a602f500f49.
  • Wheel: python-flint 0.9.0, python_flint-0.9.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl, bundled FLINT 3.6.0.
  • Source builds: GMP 6.3.0 and MPFR 4.2.1. Wheel libraries: GMP 6.3.0 and MPFR 4.2.2.
  • GCC 13.3.0, GNU Make 4.3, Autoconf 2.71, Automake 1.16.5 and Libtool 2.4.7. Default arithmetic settings and shared libraries. The source library used -O3 -g -march=znver4. The power reproducer was compiled with -O2.

The commands above assume system development headers are installed. The verifier's pinned build instead used local dependency paths:

./configure --prefix="$JOB_WORK/install" \
  --with-gmp-include="$JOB_WORK/deps/root/usr/include/x86_64-linux-gnu" \
  --with-gmp-lib="$JOB_WORK/deps/root/usr/lib/x86_64-linux-gnu" \
  --with-mpfr-include="$JOB_WORK/deps/root/usr/include" \
  --with-mpfr-lib="$JOB_WORK/deps/root/usr/lib/x86_64-linux-gnu"

Configure and build completed successfully. The fetched evidence records their commands and results, but does not include the full configure output.

Additional context

Source review and runtime tracing identify the write in src/arb/pow.c lines 123-128. The zero-touching-base branch writes the auxiliary base [1,2] to z before the recursive call reads y. With z == y, this replaces the original exponent [1,3]. The traced inner multiplication reads exponent midpoint 1.5 and radius 0.5 instead of 2 and 1. Preserving the exponent or using a temporary output would avoid this overwrite. No patch was tested.

Separate output, output/base aliasing, exact integer exponent 3, and strictly positive base [1,2] controls contain 8. The reported exponent alias still excludes 8 at requested precisions 128 and 256.

These tests cover the stated C calls on Linux x86_64. Wheel checks called the bundled C library directly. Python wrapper exposure, other architectures, and other input families were not tested. The reproducer is provided under CC0-1.0.

Found by ChipLab's AI verification agents and independently reproduced.

ChipLab ref: CLAB-2026-646

Activity

  1. albinahlback commented on Oct 12, 2026

    @albinahlback
    Collaborator

    AI slop.

  2. albinahlback commented on Oct 12, 2026

    @albinahlback
    Collaborator

    For anyone wondering why, here is a better piece of code:

    #include "flint/arb.h"
    
    int main(void)
    {
        arb_t base, exponent, res;
        arf_t lb, ub;
        slong prec = 64;
    
        arb_init(base);
        arb_init(exponent);
        arb_init(res);
        arf_init(lb);
        arf_init(ub);
    
        arb_one(base);
        mag_one(arb_radref(base));             /* [0,2] */
        arb_set_ui(exponent, 2);
        mag_one(arb_radref(exponent));         /* [1,3] */
    
        arb_pow(res, base, exponent, prec);
        arb_get_lbound_arf(lb, res, prec);
        arb_get_ubound_arf(ub, res, prec);
        flint_printf("[1 +/- 1] ^ [2 +/- 1] \\in [%{arf}, %{arf}]\n", lb, ub);  // [1 +/- 1] ^ [2 +/- 1] \in [0.00000, 8.00000]
    
        arb_clear(base);
        arb_clear(exponent);
        arb_clear(res);
        arf_clear(lb);
        arf_clear(ub);
        flint_cleanup();
    }
    
  3. fredrik-johansson commented on Oct 12, 2026

    @fredrik-johansson
    Collaborator

    @albinahlback the report stated that the operands have to be aliased. Try this:

    #include "flint/arb.h"
    
    int main(void)
    {
        arb_t base, exponent, res;
        arf_t lb, ub;
        slong prec = 64;
    
        arb_init(base);
        arb_init(exponent);
        arb_init(res);
        arf_init(lb);
        arf_init(ub);
    
        arb_one(base);
        mag_one(arb_radref(base));             /* [0,2] */
        arb_set_ui(exponent, 2);
        mag_one(arb_radref(exponent));         /* [1,3] */
    
        arb_set(res, exponent);
        arb_pow(res, base, res, prec);
        arb_get_lbound_arf(lb, res, prec);
        arb_get_ubound_arf(ub, res, prec);
        flint_printf("[1 +/- 1] ^ [2 +/- 1] \\in [%{arf}, %{arf}]\n", lb, ub);  // [1 +/- 1] ^ [2 +/- 1] \in [0.00000, 8.00000]
    
        arb_clear(base);
        arb_clear(exponent);
        arb_clear(res);
        arf_clear(lb);
        arf_clear(ub);
        flint_cleanup();
    }
    
  4. albinahlback commented on Oct 12, 2026

    @albinahlback
    Collaborator

    My bad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions