From cb067b41e7ca7b0e2548ae98ac46a9ab11f6e520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Mon, 25 Mar 2024 10:34:11 +0100 Subject: [PATCH 1/4] Reenable workflows --- .github/workflows/CI.yml | 24 +++++++++--------------- .github/workflows/push_CI.yml | 6 +----- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4475ea0adc..d29aefc91e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -8,7 +8,7 @@ on: - flint-* env: - GLOBAL_MULTIPLIER: 0.1 + GLOBAL_MULTIPLIER: 1 concurrency: # group by workflow and ref; the last slightly strange component ensures that for pull @@ -265,8 +265,6 @@ jobs: env: FLINT_TEST_MULTIPLIER: "2" - if: false # temporary disabled - steps: - name: "Rescale multiplier" run: | @@ -393,15 +391,7 @@ jobs: CC: "gcc" FLINT_TEST_MULTIPLIER: "0.5" - if: false # temporary disabled - steps: - - name: "Rescale multiplier" - run: | - FLINT_TEST_MULTIPLIER=$(echo "${FLINT_TEST_MULTIPLIER} * ${GLOBAL_MULTIPLIER}" | bc) - echo "FLINT_TEST_MULTIPLIER=${FLINT_TEST_MULTIPLIER}" - echo "FLINT_TEST_MULTIPLIER=${FLINT_TEST_MULTIPLIER}" >> $GITHUB_ENV - - uses: actions/checkout@v4 - name: "Setup MinGW" @@ -409,7 +399,13 @@ jobs: with: msystem: mingw64 update: true - install: mingw-w64-x86_64-gcc mingw-w64-x86_64-autotools + install: bc mingw-w64-x86_64-gcc mingw-w64-x86_64-autotools + + - name: "Rescale multiplier" + run: | + FLINT_TEST_MULTIPLIER=$(echo "${FLINT_TEST_MULTIPLIER} * ${GLOBAL_MULTIPLIER}" | bc) + echo "FLINT_TEST_MULTIPLIER=${FLINT_TEST_MULTIPLIER}" + echo "FLINT_TEST_MULTIPLIER=${FLINT_TEST_MULTIPLIER}" >> $GITHUB_ENV - name: "Setup" run: | @@ -449,7 +445,7 @@ jobs: runs-on: windows-latest env: FLINT_TEST_MULTIPLIER: 1 - TIMEOUT: 450 + TIMEOUT: 150 steps: - name: "Rescale multiplier (powershell)" @@ -589,8 +585,6 @@ jobs: LOCAL: ${{ github.workspace }}/local CC: "gcc" - if: false # temporarily disabled - steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/push_CI.yml b/.github/workflows/push_CI.yml index 317ba1c961..188d6b9c04 100644 --- a/.github/workflows/push_CI.yml +++ b/.github/workflows/push_CI.yml @@ -24,14 +24,12 @@ jobs: env: FLINT_TEST_MULTIPLIER: "0.5" - if: false # temporarily disabled - steps: - uses: actions/checkout@v4 - name: "Run tests on FreeBSD" uses: cross-platform-actions/action@v0.22.0 - timeout-minutes: 30 + timeout-minutes: 15 continue-on-error: true with: operating_system: freebsd @@ -108,8 +106,6 @@ jobs: runs-on: windows-latest - if: false # temporarily disabled - defaults: run: shell: C:\cygwin64\bin\bash.exe --login -o igncr '{0}' From 6c2aac957ce0149fe2a8db5f6e63e934a09243e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Mon, 25 Mar 2024 13:46:34 +0100 Subject: [PATCH 2/4] Implement n_factor_evaluate --- doc/source/ulong_extras.rst | 6 ++ src/ulong_extras.h | 2 + src/ulong_extras/factor_misc.c | 29 ++++++++++ src/ulong_extras/test/main.c | 2 + src/ulong_extras/test/t-factor.c | 11 ++-- src/ulong_extras/test/t-factor_evaluate.c | 68 +++++++++++++++++++++++ 6 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 src/ulong_extras/factor_misc.c create mode 100644 src/ulong_extras/test/t-factor_evaluate.c diff --git a/doc/source/ulong_extras.rst b/doc/source/ulong_extras.rst index b5169a1923..5b7200360e 100644 --- a/doc/source/ulong_extras.rst +++ b/doc/source/ulong_extras.rst @@ -1075,6 +1075,12 @@ Factorisation Initializes factors. +.. function:: ulong n_factor_evaluate(const n_factor_t * factors) + + Returns the evaluation of ``factors``, + i.e. `p_{1}^{e_{1}} \cdots p_{n}^{e_{n}}` assuming that it fits in a limb. + In case the evaluation does not fit in a limb, it returns `0`. + .. function:: int n_remove(ulong * n, ulong p) Removes the highest possible power of `p` from `n`, replacing diff --git a/src/ulong_extras.h b/src/ulong_extras.h index 8bcabb9263..a79831be4e 100644 --- a/src/ulong_extras.h +++ b/src/ulong_extras.h @@ -357,6 +357,8 @@ ulong n_nextprime(ulong n, int FLINT_UNUSED(proved)); ULONG_EXTRAS_INLINE void n_factor_init(n_factor_t * factors) { factors->num = UWORD(0); } +ulong n_factor_evaluate(const n_factor_t * fac); + void n_factor(n_factor_t * factors, ulong n, int proved); void n_factor_insert(n_factor_t * factors, ulong p, ulong exp); diff --git a/src/ulong_extras/factor_misc.c b/src/ulong_extras/factor_misc.c new file mode 100644 index 0000000000..41cf2f0840 --- /dev/null +++ b/src/ulong_extras/factor_misc.c @@ -0,0 +1,29 @@ +/* + Copyright (C) 2024 Albin Ahlbäck + + This file is part of FLINT. + + FLINT 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 3 of the License, or + (at your option) any later version. See . +*/ + +#include "ulong_extras.h" + +ulong n_factor_evaluate(const n_factor_t * fac) +{ + ulong ret = 1; + slong ix; + + for (ix = 0; ix < fac->num; ix++) + { + ulong t0, t1; + t0 = _n_pow_check(fac->p[ix], fac->exp[ix]); + umul_ppmm(t1, ret, ret, t0); + if (t1 != 0) + return 0; + } + + return ret; +} diff --git a/src/ulong_extras/test/main.c b/src/ulong_extras/test/main.c index e2b719dc0c..f63e74e9c1 100644 --- a/src/ulong_extras/test/main.c +++ b/src/ulong_extras/test/main.c @@ -31,6 +31,7 @@ #include "t-divrem2_preinv.c" #include "t-euler_phi.c" #include "t-factor.c" +#include "t-factor_evaluate.c" #include "t-factor_ecm.c" #include "t-factorial_fast_mod2_preinv.c" #include "t-factorial_mod2_preinv.c" @@ -128,6 +129,7 @@ test_struct tests[] = TEST_FUNCTION(n_divrem2_preinv), TEST_FUNCTION(n_euler_phi), TEST_FUNCTION(n_factor), + TEST_FUNCTION(n_factor_evaluate), TEST_FUNCTION(n_factor_ecm), TEST_FUNCTION(n_factorial_fast_mod2_preinv), TEST_FUNCTION(n_factorial_mod2_preinv), diff --git a/src/ulong_extras/test/t-factor.c b/src/ulong_extras/test/t-factor.c index bbc0c76175..bd4092ee18 100644 --- a/src/ulong_extras/test/t-factor.c +++ b/src/ulong_extras/test/t-factor.c @@ -14,9 +14,10 @@ TEST_FUNCTION_START(n_factor, state) { - int i, j, result; + int result; + slong ix; - for (i = 0; i < 1000 * flint_test_multiplier(); i++) + for (ix = 0; ix < 1000 * flint_test_multiplier(); ix++) { mp_limb_t n1, n2; n_factor_t factors; @@ -39,11 +40,7 @@ TEST_FUNCTION_START(n_factor, state) n_factor(&factors, n1, 0); - n2 = UWORD(1); - for (j = 0; j < factors.num; j++) - { - n2 *= n_pow(factors.p[j], factors.exp[j]); - } + n2 = n_factor_evaluate(&factors); result = (n1 == n2); if (!result) diff --git a/src/ulong_extras/test/t-factor_evaluate.c b/src/ulong_extras/test/t-factor_evaluate.c new file mode 100644 index 0000000000..781997b4e1 --- /dev/null +++ b/src/ulong_extras/test/t-factor_evaluate.c @@ -0,0 +1,68 @@ +/* + Copyright (C) 2024 Albin Ahlbäck + + This file is part of FLINT. + + FLINT 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 3 of the License, or + (at your option) any later version. See . +*/ + +#include "test_helpers.h" +#include "ulong_extras.h" + +TEST_FUNCTION_START(n_factor_evaluate, state) +{ + int result; + slong iter; + + for (iter = 0; iter < 10000 * flint_test_multiplier(); iter++) + { + ulong eval, fac_eval; + n_factor_t factors; + int type; + + n_factor_init(&factors); + + type = n_randint(state, 2); + + if (type == 0) + { + /* Test random limb */ + eval = n_randtest_not_zero(state); + n_factor(&factors, eval, 0); + } + else + { + /* Test factorization whose evaluation cannot fit in a limb */ + ulong top; + + eval = 1; + + do + { + ulong prime = n_randtest_prime(state, 0); + umul_ppmm(top, eval, eval, prime); + n_factor_insert(&factors, prime, 1); + } while (top == UWORD(0)); + + /* And maybe add extra exponents */ + if (n_randint(state, 2)) + factors.exp[n_randint(state, factors.num)] += 1 + n_randint(state, 10); + + eval = 0; /* n_factor_evaluate should return 0 */ + } + + fac_eval = n_factor_evaluate(&factors); + + result = (eval == fac_eval); + if (!result) + TEST_FUNCTION_FAIL( + "eval = %wu\n" + "fac_eval = %wu\n", + eval, fac_eval); + } + + TEST_FUNCTION_END(state); +} From f8ad664a41845b80d6245b3eda542120c4276f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Mon, 25 Mar 2024 13:46:54 +0100 Subject: [PATCH 3/4] Fix warning in test --- src/ulong_extras/test/t-factor_power235.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ulong_extras/test/t-factor_power235.c b/src/ulong_extras/test/t-factor_power235.c index f5eeb42ba4..80627509ea 100644 --- a/src/ulong_extras/test/t-factor_power235.c +++ b/src/ulong_extras/test/t-factor_power235.c @@ -21,7 +21,8 @@ TEST_FUNCTION_START(n_factor_power235, state) for (ix = 0; ix < 3000 * flint_test_multiplier(); ix++) { ulong factor, exp, n1, n2, n1pow; - int bits, type; + int bits; + ulong type; type = n_randint(state, 4); From 8e0780be02e5d3cbea484e2b86500971c7b530e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Mon, 25 Mar 2024 14:08:14 +0100 Subject: [PATCH 4/4] Revert change in n_factor_t struct --- src/limb_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/limb_types.h b/src/limb_types.h index 70ccf2987b..05d52238ad 100644 --- a/src/limb_types.h +++ b/src/limb_types.h @@ -22,7 +22,7 @@ extern "C" { typedef struct { - slong num; + int num; int exp[FLINT_MAX_FACTORS_IN_LIMB]; ulong p[FLINT_MAX_FACTORS_IN_LIMB]; }