tifa-factor 0.4.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tifa_factor-0.4.6/.gitignore +27 -0
- tifa_factor-0.4.6/CMakeLists.txt +418 -0
- tifa_factor-0.4.6/PKG-INFO +118 -0
- tifa_factor-0.4.6/README.md +479 -0
- tifa_factor-0.4.6/bench/CMakeLists.txt +21 -0
- tifa_factor-0.4.6/bench/ab.sh +47 -0
- tifa_factor-0.4.6/bench/bench_utils.h +108 -0
- tifa_factor-0.4.6/bench/factor_bench.c +162 -0
- tifa_factor-0.4.6/bench/siqs_bench.c +184 -0
- tifa_factor-0.4.6/bench/siqs_check.c +124 -0
- tifa_factor-0.4.6/cmake/FindGMP.cmake +81 -0
- tifa_factor-0.4.6/cmake/TifaConfig.cmake.in +18 -0
- tifa_factor-0.4.6/cmake/tifa.pc.in +12 -0
- tifa_factor-0.4.6/cmake/tifa_config.h.in +212 -0
- tifa_factor-0.4.6/doxygen.conf.in +396 -0
- tifa_factor-0.4.6/lib/CMakeLists.txt +153 -0
- tifa_factor-0.4.6/lib/algo/include/cfrac.h +178 -0
- tifa_factor-0.4.6/lib/algo/include/cofactor.h +154 -0
- tifa_factor-0.4.6/lib/algo/include/ecm.h +175 -0
- tifa_factor-0.4.6/lib/algo/include/fermat.h +146 -0
- tifa_factor-0.4.6/lib/algo/include/p_minus_1.h +138 -0
- tifa_factor-0.4.6/lib/algo/include/p_plus_1.h +148 -0
- tifa_factor-0.4.6/lib/algo/include/rho.h +169 -0
- tifa_factor-0.4.6/lib/algo/include/siqs.h +178 -0
- tifa_factor-0.4.6/lib/algo/include/squfof.h +161 -0
- tifa_factor-0.4.6/lib/algo/include/tdiv.h +95 -0
- tifa_factor-0.4.6/lib/algo/include/tifa_factor.h +157 -0
- tifa_factor-0.4.6/lib/algo/include/tuning.h +296 -0
- tifa_factor-0.4.6/lib/algo/include/tuning_baked.h +41 -0
- tifa_factor-0.4.6/lib/algo/src/cfrac.c +1064 -0
- tifa_factor-0.4.6/lib/algo/src/cofactor.c +421 -0
- tifa_factor-0.4.6/lib/algo/src/ecm.c +1384 -0
- tifa_factor-0.4.6/lib/algo/src/fermat.c +994 -0
- tifa_factor-0.4.6/lib/algo/src/p_minus_1.c +647 -0
- tifa_factor-0.4.6/lib/algo/src/p_plus_1.c +806 -0
- tifa_factor-0.4.6/lib/algo/src/rho.c +517 -0
- tifa_factor-0.4.6/lib/algo/src/siqs.c +1784 -0
- tifa_factor-0.4.6/lib/algo/src/squfof.c +1333 -0
- tifa_factor-0.4.6/lib/algo/src/tdiv.c +219 -0
- tifa_factor-0.4.6/lib/algo/src/tifa_factor.c +433 -0
- tifa_factor-0.4.6/lib/algo/src/tuning.c +471 -0
- tifa_factor-0.4.6/lib/algo/src/tuning_baked.c +29 -0
- tifa_factor-0.4.6/lib/data/include/first_primes.h +73 -0
- tifa_factor-0.4.6/lib/data/include/z2z8_curves.h +62 -0
- tifa_factor-0.4.6/lib/data/scripts/genprimes.py +214 -0
- tifa_factor-0.4.6/lib/data/src/first_primes.c +65579 -0
- tifa_factor-0.4.6/lib/data/src/z2z8_curves.c +56 -0
- tifa_factor-0.4.6/lib/mainpage.h +105 -0
- tifa_factor-0.4.6/lib/tifa.h +67 -0
- tifa_factor-0.4.6/lib/tifa_internals.h +112 -0
- tifa_factor-0.4.6/lib/utils/include/approx.h +240 -0
- tifa_factor-0.4.6/lib/utils/include/array.h +1357 -0
- tifa_factor-0.4.6/lib/utils/include/bernsteinisms.h +300 -0
- tifa_factor-0.4.6/lib/utils/include/bitstring_t.h +112 -0
- tifa_factor-0.4.6/lib/utils/include/buckets.h +116 -0
- tifa_factor-0.4.6/lib/utils/include/ecm_schedule.h +104 -0
- tifa_factor-0.4.6/lib/utils/include/exit_codes.h +162 -0
- tifa_factor-0.4.6/lib/utils/include/factor_u64.h +98 -0
- tifa_factor-0.4.6/lib/utils/include/factoring_machine.h +262 -0
- tifa_factor-0.4.6/lib/utils/include/funcs.h +770 -0
- tifa_factor-0.4.6/lib/utils/include/gauss_elim.h +97 -0
- tifa_factor-0.4.6/lib/utils/include/gmp_utils.h +133 -0
- tifa_factor-0.4.6/lib/utils/include/hashtable.h +219 -0
- tifa_factor-0.4.6/lib/utils/include/lindep.h +308 -0
- tifa_factor-0.4.6/lib/utils/include/linked_list.h +255 -0
- tifa_factor-0.4.6/lib/utils/include/lp_table.h +147 -0
- tifa_factor-0.4.6/lib/utils/include/macros.h +617 -0
- tifa_factor-0.4.6/lib/utils/include/matrix.h +443 -0
- tifa_factor-0.4.6/lib/utils/include/messages.h +433 -0
- tifa_factor-0.4.6/lib/utils/include/methods.h +115 -0
- tifa_factor-0.4.6/lib/utils/include/mont_ecm.h +154 -0
- tifa_factor-0.4.6/lib/utils/include/print_error.h +113 -0
- tifa_factor-0.4.6/lib/utils/include/res_tdiv.h +69 -0
- tifa_factor-0.4.6/lib/utils/include/siqs_poly.h +263 -0
- tifa_factor-0.4.6/lib/utils/include/siqs_sieve.h +348 -0
- tifa_factor-0.4.6/lib/utils/include/smooth_filter.h +310 -0
- tifa_factor-0.4.6/lib/utils/include/sqrt_cont_frac.h +201 -0
- tifa_factor-0.4.6/lib/utils/include/stopwatch.h +142 -0
- tifa_factor-0.4.6/lib/utils/include/tifa_alloc.h +88 -0
- tifa_factor-0.4.6/lib/utils/include/timer.h +168 -0
- tifa_factor-0.4.6/lib/utils/include/x_array_list.h +261 -0
- tifa_factor-0.4.6/lib/utils/include/x_tree.h +205 -0
- tifa_factor-0.4.6/lib/utils/src/approx.c +492 -0
- tifa_factor-0.4.6/lib/utils/src/array.c +917 -0
- tifa_factor-0.4.6/lib/utils/src/bernsteinisms.c +1455 -0
- tifa_factor-0.4.6/lib/utils/src/ecm_schedule.c +181 -0
- tifa_factor-0.4.6/lib/utils/src/factor_u64.c +1100 -0
- tifa_factor-0.4.6/lib/utils/src/factoring_machine.c +668 -0
- tifa_factor-0.4.6/lib/utils/src/funcs.c +1363 -0
- tifa_factor-0.4.6/lib/utils/src/gauss_elim.c +616 -0
- tifa_factor-0.4.6/lib/utils/src/gmp_utils.c +94 -0
- tifa_factor-0.4.6/lib/utils/src/hashtable.c +156 -0
- tifa_factor-0.4.6/lib/utils/src/lindep.c +801 -0
- tifa_factor-0.4.6/lib/utils/src/linked_list.c +357 -0
- tifa_factor-0.4.6/lib/utils/src/lp_table.c +157 -0
- tifa_factor-0.4.6/lib/utils/src/matrix.c +247 -0
- tifa_factor-0.4.6/lib/utils/src/mont_ecm.c +717 -0
- tifa_factor-0.4.6/lib/utils/src/mont_ecm_impl.h +451 -0
- tifa_factor-0.4.6/lib/utils/src/mont_pm1_impl.h +276 -0
- tifa_factor-0.4.6/lib/utils/src/res_tdiv.c +905 -0
- tifa_factor-0.4.6/lib/utils/src/siqs_poly.c +662 -0
- tifa_factor-0.4.6/lib/utils/src/siqs_sieve.c +1343 -0
- tifa_factor-0.4.6/lib/utils/src/smooth_filter.c +245 -0
- tifa_factor-0.4.6/lib/utils/src/sqrt_cont_frac.c +457 -0
- tifa_factor-0.4.6/lib/utils/src/stopwatch.c +86 -0
- tifa_factor-0.4.6/lib/utils/src/x_array_list.c +121 -0
- tifa_factor-0.4.6/lib/utils/src/x_tree.c +948 -0
- tifa_factor-0.4.6/pyproject.toml +66 -0
- tifa_factor-0.4.6/python/CMakeLists.txt +19 -0
- tifa_factor-0.4.6/python/README.md +100 -0
- tifa_factor-0.4.6/python/_tifa.c +181 -0
- tifa_factor-0.4.6/python/tests/test_factor.py +146 -0
- tifa_factor-0.4.6/python/tifa/__init__.py +105 -0
- tifa_factor-0.4.6/python/tifa/_tifa.pyi +3 -0
- tifa_factor-0.4.6/python/tifa/py.typed +0 -0
- tifa_factor-0.4.6/readme/authors.txt +4 -0
- tifa_factor-0.4.6/readme/copying.txt +23 -0
- tifa_factor-0.4.6/readme/gpl_v3.txt +658 -0
- tifa_factor-0.4.6/readme/issues.txt +13 -0
- tifa_factor-0.4.6/readme/license_v2.1.txt +501 -0
- tifa_factor-0.4.6/readme/license_v3.txt +166 -0
- tifa_factor-0.4.6/readme/news.md +1718 -0
- tifa_factor-0.4.6/readme/readme.txt +439 -0
- tifa_factor-0.4.6/readme/tifacube.png +0 -0
- tifa_factor-0.4.6/readme/todo.txt +78 -0
- tifa_factor-0.4.6/tests/CMakeLists.txt +98 -0
- tifa_factor-0.4.6/tests/check_exit.cmake +14 -0
- tifa_factor-0.4.6/tests/fixtures/bad.tuning +3 -0
- tifa_factor-0.4.6/tests/fixtures/duplicate.tuning +4 -0
- tifa_factor-0.4.6/tests/fixtures/long_line.tuning +4 -0
- tifa_factor-0.4.6/tests/fixtures/negative.tuning +3 -0
- tifa_factor-0.4.6/tests/fixtures/overflow.tuning +3 -0
- tifa_factor-0.4.6/tests/fixtures/p_minus_1.tuning +7 -0
- tifa_factor-0.4.6/tests/test_algorithms.c +466 -0
- tifa_factor-0.4.6/tests/test_cofactor.c +244 -0
- tifa_factor-0.4.6/tests/test_containers.c +123 -0
- tifa_factor-0.4.6/tests/test_factor_u64.c +174 -0
- tifa_factor-0.4.6/tests/test_funcs.c +150 -0
- tifa_factor-0.4.6/tests/test_inputs.c +316 -0
- tifa_factor-0.4.6/tests/test_matrix.c +224 -0
- tifa_factor-0.4.6/tests/test_mont_ecm.c +351 -0
- tifa_factor-0.4.6/tests/test_mont_pm1.c +241 -0
- tifa_factor-0.4.6/tests/test_siqs.c +142 -0
- tifa_factor-0.4.6/tests/test_threads.c +279 -0
- tifa_factor-0.4.6/tests/test_tifa_factor.c +289 -0
- tifa_factor-0.4.6/tests/test_tuning.c +218 -0
- tifa_factor-0.4.6/tests/tifa_test.h +99 -0
- tifa_factor-0.4.6/tools/CMakeLists.txt +50 -0
- tifa_factor-0.4.6/tools/include/common_funcs.h +114 -0
- tifa_factor-0.4.6/tools/include/factoring_program.h +173 -0
- tifa_factor-0.4.6/tools/include/tool_utils.h +98 -0
- tifa_factor-0.4.6/tools/src/cfrac_program.c +251 -0
- tifa_factor-0.4.6/tools/src/common_funcs.c +70 -0
- tifa_factor-0.4.6/tools/src/ecm_program.c +218 -0
- tifa_factor-0.4.6/tools/src/factoring_program.c +368 -0
- tifa_factor-0.4.6/tools/src/fermat_program.c +167 -0
- tifa_factor-0.4.6/tools/src/p_minus_1_program.c +212 -0
- tifa_factor-0.4.6/tools/src/p_plus_1_program.c +212 -0
- tifa_factor-0.4.6/tools/src/rho_program.c +229 -0
- tifa_factor-0.4.6/tools/src/siqs_program.c +245 -0
- tifa_factor-0.4.6/tools/src/squfof_program.c +170 -0
- tifa_factor-0.4.6/tools/src/tdiv_program.c +174 -0
- tifa_factor-0.4.6/tools/src/tifa_factor_program.c +169 -0
- tifa_factor-0.4.6/tools/src/tool_utils.c +84 -0
- tifa_factor-0.4.6/tools/tune/CMakeLists.txt +49 -0
- tifa_factor-0.4.6/tools/tune/tune.c +1017 -0
- tifa_factor-0.4.6/tools/tune/tune_algos.c +365 -0
- tifa_factor-0.4.6/tools/tune/tune_algos.h +98 -0
- tifa_factor-0.4.6/tools/tune/tune_grid.c +120 -0
- tifa_factor-0.4.6/tools/tune/tune_grid.h +103 -0
- tifa_factor-0.4.6/tools/tune/tune_numgen.c +99 -0
- tifa_factor-0.4.6/tools/tune/tune_numgen.h +59 -0
- tifa_factor-0.4.6/tools/z2z8/search.c +112 -0
- tifa_factor-0.4.6/tools/z2z8/table.py +85 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# CMake out-of-source build directories (build/, build-asan/, ...)
|
|
2
|
+
/build*/
|
|
3
|
+
|
|
4
|
+
# CPack working directory and source packages
|
|
5
|
+
/_CPack_Packages/
|
|
6
|
+
/tifa-*.tar.gz
|
|
7
|
+
/tifa-*.tgz
|
|
8
|
+
|
|
9
|
+
# Generated config header (produced into the build dir, but guard against
|
|
10
|
+
# an in-source generation too)
|
|
11
|
+
/tifa_config.h
|
|
12
|
+
|
|
13
|
+
# Legacy SCons artifacts
|
|
14
|
+
/.sconf_temp/
|
|
15
|
+
.sconsign.dblite
|
|
16
|
+
|
|
17
|
+
# Editor / OS cruft
|
|
18
|
+
*.o
|
|
19
|
+
*.a
|
|
20
|
+
*.so
|
|
21
|
+
*.dylib
|
|
22
|
+
.DS_Store
|
|
23
|
+
|
|
24
|
+
# Python package builds
|
|
25
|
+
/dist/
|
|
26
|
+
__pycache__/
|
|
27
|
+
*.egg-info/
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
#------------------------------------------------------------------------------
|
|
2
|
+
# TIFA - Tools for Integer FActorization
|
|
3
|
+
#
|
|
4
|
+
# CMake build system (replaces the historical SCons build).
|
|
5
|
+
#------------------------------------------------------------------------------
|
|
6
|
+
cmake_minimum_required(VERSION 3.20)
|
|
7
|
+
|
|
8
|
+
project(Tifa
|
|
9
|
+
VERSION 0.4.6
|
|
10
|
+
DESCRIPTION "TIFA - Tools for Integer FActorization"
|
|
11
|
+
LANGUAGES C
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
|
15
|
+
|
|
16
|
+
include(GNUInstallDirs)
|
|
17
|
+
include(CheckTypeSize)
|
|
18
|
+
include(CMakePackageConfigHelpers)
|
|
19
|
+
|
|
20
|
+
#------------------------------------------------------------------------------
|
|
21
|
+
# Build type / language standard
|
|
22
|
+
#------------------------------------------------------------------------------
|
|
23
|
+
# Default to an optimized build, matching the historical SCons "-O3" default.
|
|
24
|
+
# Note: we deliberately keep the Release flags free of -DNDEBUG for parity with
|
|
25
|
+
# the old build (which never defined NDEBUG).
|
|
26
|
+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
27
|
+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
|
28
|
+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
|
|
29
|
+
STRINGS Debug Release RelWithDebInfo MinSizeRel)
|
|
30
|
+
endif()
|
|
31
|
+
if(CMAKE_C_FLAGS_RELEASE STREQUAL "-O3 -DNDEBUG")
|
|
32
|
+
# CMake's own default, not a user's choice.
|
|
33
|
+
set(CMAKE_C_FLAGS_RELEASE "-O3" CACHE STRING
|
|
34
|
+
"Flags used by the C compiler during RELEASE builds." FORCE)
|
|
35
|
+
endif()
|
|
36
|
+
|
|
37
|
+
set(CMAKE_C_STANDARD 99)
|
|
38
|
+
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
39
|
+
set(CMAKE_C_EXTENSIONS OFF)
|
|
40
|
+
|
|
41
|
+
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
|
|
42
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
43
|
+
endif()
|
|
44
|
+
|
|
45
|
+
# Install headers into a dedicated tifa/ subfolder (the sources include their
|
|
46
|
+
# headers by bare basename, so consumers add <prefix>/include/tifa to -I).
|
|
47
|
+
set(TIFA_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/tifa")
|
|
48
|
+
|
|
49
|
+
#------------------------------------------------------------------------------
|
|
50
|
+
# Options (successors of BuildOptions.py)
|
|
51
|
+
#------------------------------------------------------------------------------
|
|
52
|
+
option(TIFA_USE_GMP_INTERNAL_FUNCS "Use some of GMP's internal functions (needs gmp-impl.h)" OFF)
|
|
53
|
+
option(TIFA_USE_CALLOC_MEMSET "Use calloc/memset for zero-init of integer arrays" ON)
|
|
54
|
+
option(TIFA_PRINT_ERROR "Print critical error messages on stderr" ON)
|
|
55
|
+
option(TIFA_ALLOW_VERBOSE "Master switch enabling per-algorithm verbose output" OFF)
|
|
56
|
+
option(TIFA_ALLOW_TIMING "Master switch enabling per-algorithm timing messages" OFF)
|
|
57
|
+
option(TIFA_ALLOW_EXTRA_TIMING "Enable extra (potentially costly) timing measurements" OFF)
|
|
58
|
+
|
|
59
|
+
set(TIFA_ALGOS CFRAC ECM FERMAT SIQS SQUFOF RHO TDIV PM1 PP1)
|
|
60
|
+
foreach(_a IN LISTS TIFA_ALGOS)
|
|
61
|
+
string(TOLOWER "${_a}" _al)
|
|
62
|
+
option(TIFA_VERBOSE_${_a} "Verbose output for the ${_al} function (needs TIFA_ALLOW_VERBOSE)" ON)
|
|
63
|
+
option(TIFA_TIMING_${_a} "Timing messages for the ${_al} function (needs TIFA_ALLOW_TIMING)" ON)
|
|
64
|
+
endforeach()
|
|
65
|
+
|
|
66
|
+
set(TIFA_BITSTRING_T "uint64_t" CACHE STRING "Native C type used to represent a string of bits")
|
|
67
|
+
|
|
68
|
+
# Directory the library searches at runtime for machine-tuned parameter files
|
|
69
|
+
# (<dir>/<algo>.tuning, produced by the tifa-tune tool). Consulted only as a
|
|
70
|
+
# last resort, after tifa_tuning_set_dir() and the TIFA_TUNING_DIR environment
|
|
71
|
+
# variable; a missing directory simply means the compiled-in defaults are used.
|
|
72
|
+
set(TIFA_TUNING_DIR "${CMAKE_INSTALL_FULL_DATADIR}/tifa/tuning" CACHE PATH
|
|
73
|
+
"Directory searched at runtime for machine-tuned parameter files")
|
|
74
|
+
|
|
75
|
+
set(GMP_INCDIR "" CACHE PATH "Directory containing gmp.h (optional hint for FindGMP)")
|
|
76
|
+
set(GMP_LIBDIR "" CACHE PATH "Directory containing the GMP library (optional hint)")
|
|
77
|
+
set(GMP_INTERNAL_INCDIR "" CACHE PATH "Directory containing gmp-impl.h (used only with TIFA_USE_GMP_INTERNAL_FUNCS)")
|
|
78
|
+
|
|
79
|
+
# Documentation options
|
|
80
|
+
option(TIFA_GENERATE_DOXYGEN_DOC "Provide a 'doc' target that runs Doxygen" ON)
|
|
81
|
+
option(TIFA_GENERATE_DOXYGEN_HTML "Doxygen: generate HTML output" ON)
|
|
82
|
+
option(TIFA_GENERATE_DOXYGEN_PDF "Doxygen: generate PDF (LaTeX) output" ON)
|
|
83
|
+
option(TIFA_GENERATE_DOXYGEN_XML "Doxygen: generate XML output" OFF)
|
|
84
|
+
option(TIFA_GENERATE_DOXYGEN_RTF "Doxygen: generate RTF output" OFF)
|
|
85
|
+
set(TIFA_DOXYGEN_PAPER_TYPE "a4wide" CACHE STRING "Doxygen PDF paper type")
|
|
86
|
+
set_property(CACHE TIFA_DOXYGEN_PAPER_TYPE PROPERTY
|
|
87
|
+
STRINGS a4 a4wide letter legal executive)
|
|
88
|
+
|
|
89
|
+
option(TIFA_BUILD_TESTS "Build the test suite (CTest)" ON)
|
|
90
|
+
option(TIFA_BUILD_BENCH "Build the benchmark programs of bench/ (not installed)" OFF)
|
|
91
|
+
option(TIFA_BUILD_PYTHON "Build the Python extension module of python/ (pip builds it)" OFF)
|
|
92
|
+
option(TIFA_WERROR "Treat compiler warnings as errors (used in CI)" OFF)
|
|
93
|
+
|
|
94
|
+
# Compile the baked tuning tables (lib/algo/src/tuning_baked.c) into the library
|
|
95
|
+
# as a fallback used when no runtime tuning file is found. OFF keeps builds
|
|
96
|
+
# hermetic and behavior identical to the untuned defaults.
|
|
97
|
+
option(TIFA_USE_BAKED_TUNING "Compile in the baked parameter-tuning tables" OFF)
|
|
98
|
+
# Provide a 'regen-tuning' target that runs tifa-tune to regenerate the baked
|
|
99
|
+
# tables in the source tree (a full tuning pass; can be lengthy).
|
|
100
|
+
option(TIFA_REGEN_TUNING "Add a 'regen-tuning' target that rebuilds baked tables" OFF)
|
|
101
|
+
|
|
102
|
+
#------------------------------------------------------------------------------
|
|
103
|
+
# Dependencies
|
|
104
|
+
#------------------------------------------------------------------------------
|
|
105
|
+
find_package(GMP 6.0 REQUIRED) # mpz_limbs_read and mpz_limbs_write
|
|
106
|
+
find_package(Threads REQUIRED) # the tuning cache is shared between threads
|
|
107
|
+
find_library(TIFA_M_LIBRARY m) # libm; may be absent (folded into libc) on some platforms
|
|
108
|
+
|
|
109
|
+
#------------------------------------------------------------------------------
|
|
110
|
+
# Feature detection (compile-only; cross-compilation safe, no run-probes)
|
|
111
|
+
#------------------------------------------------------------------------------
|
|
112
|
+
set(CMAKE_EXTRA_INCLUDE_FILES stdint.h stdlib.h)
|
|
113
|
+
check_type_size("${TIFA_BITSTRING_T}" TIFA_CFG_SIZEOF_BITSTRING_T LANGUAGE C)
|
|
114
|
+
check_type_size("unsigned long int" TIFA_CFG_SIZEOF_ULONG_T LANGUAGE C)
|
|
115
|
+
check_type_size("long int" TIFA_SIZEOF_LONG LANGUAGE C)
|
|
116
|
+
unset(CMAKE_EXTRA_INCLUDE_FILES)
|
|
117
|
+
|
|
118
|
+
if(NOT TIFA_CFG_SIZEOF_BITSTRING_T)
|
|
119
|
+
message(FATAL_ERROR
|
|
120
|
+
"Could not determine sizeof(${TIFA_BITSTRING_T}). "
|
|
121
|
+
"Set -DTIFA_BITSTRING_T=<a valid C integer type>.")
|
|
122
|
+
endif()
|
|
123
|
+
|
|
124
|
+
# Precomputed integer square roots of LONG_MAX / ULONG_MAX (used in runtime
|
|
125
|
+
# comparisons). Only 32- and 64-bit longs are supported; extend if needed.
|
|
126
|
+
if(TIFA_SIZEOF_LONG EQUAL 8)
|
|
127
|
+
set(TIFA_CFG_SQRT_LONG_MAX "3037000499L")
|
|
128
|
+
elseif(TIFA_SIZEOF_LONG EQUAL 4)
|
|
129
|
+
set(TIFA_CFG_SQRT_LONG_MAX "46340L")
|
|
130
|
+
else()
|
|
131
|
+
message(FATAL_ERROR "Unsupported sizeof(long int) = ${TIFA_SIZEOF_LONG}")
|
|
132
|
+
endif()
|
|
133
|
+
if(TIFA_CFG_SIZEOF_ULONG_T EQUAL 8)
|
|
134
|
+
set(TIFA_CFG_SQRT_ULONG_MAX "4294967295UL")
|
|
135
|
+
elseif(TIFA_CFG_SIZEOF_ULONG_T EQUAL 4)
|
|
136
|
+
set(TIFA_CFG_SQRT_ULONG_MAX "65535UL")
|
|
137
|
+
else()
|
|
138
|
+
message(FATAL_ERROR "Unsupported sizeof(unsigned long int) = ${TIFA_CFG_SIZEOF_ULONG_T}")
|
|
139
|
+
endif()
|
|
140
|
+
|
|
141
|
+
#------------------------------------------------------------------------------
|
|
142
|
+
# Assemble the substitution values for tifa_config.h
|
|
143
|
+
#------------------------------------------------------------------------------
|
|
144
|
+
# Helper: map the option named by flag_var to the literal 1 or 0.
|
|
145
|
+
function(tifa_bool01 out_var flag_var)
|
|
146
|
+
if(${flag_var})
|
|
147
|
+
set(${out_var} 1 PARENT_SCOPE)
|
|
148
|
+
else()
|
|
149
|
+
set(${out_var} 0 PARENT_SCOPE)
|
|
150
|
+
endif()
|
|
151
|
+
endfunction()
|
|
152
|
+
|
|
153
|
+
set(TIFA_CFG_SHORTNAME "TIFA")
|
|
154
|
+
set(TIFA_CFG_FULLNAME "TIFA - Tools for Integer FActorization")
|
|
155
|
+
set(TIFA_CFG_TARNAME "tifa")
|
|
156
|
+
set(TIFA_CFG_STRING "TIFA v${PROJECT_VERSION}")
|
|
157
|
+
set(TIFA_CFG_BUGREPORT "milanje at gmail dot com")
|
|
158
|
+
|
|
159
|
+
set(TIFA_CFG_VERSION "${PROJECT_VERSION}")
|
|
160
|
+
set(TIFA_CFG_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
|
|
161
|
+
set(TIFA_CFG_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
|
|
162
|
+
set(TIFA_CFG_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
|
|
163
|
+
|
|
164
|
+
math(EXPR _tifa_wordsize_bits "${TIFA_CFG_SIZEOF_ULONG_T} * 8")
|
|
165
|
+
set(TIFA_CFG_COMPILED_ON_OS "${CMAKE_HOST_SYSTEM_NAME}")
|
|
166
|
+
set(TIFA_CFG_COMPILED_ON_RELEASE "${CMAKE_HOST_SYSTEM_VERSION}")
|
|
167
|
+
set(TIFA_CFG_COMPILED_ON_MACHINE "${CMAKE_HOST_SYSTEM_PROCESSOR}")
|
|
168
|
+
set(TIFA_CFG_COMPILED_ON
|
|
169
|
+
"${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_VERSION}-${CMAKE_HOST_SYSTEM_PROCESSOR}-${_tifa_wordsize_bits}bit")
|
|
170
|
+
|
|
171
|
+
tifa_bool01(TIFA_CFG_USE_CALLOC_MEMSET TIFA_USE_CALLOC_MEMSET)
|
|
172
|
+
tifa_bool01(TIFA_CFG_USE_GMP_INTERNAL_FUNCS TIFA_USE_GMP_INTERNAL_FUNCS)
|
|
173
|
+
tifa_bool01(TIFA_CFG_PRINT_ERROR TIFA_PRINT_ERROR)
|
|
174
|
+
tifa_bool01(TIFA_CFG_USE_BAKED_TUNING TIFA_USE_BAKED_TUNING)
|
|
175
|
+
|
|
176
|
+
set(TIFA_CFG_BITSTRING_T "${TIFA_BITSTRING_T}")
|
|
177
|
+
set(TIFA_CFG_TUNING_DIR "${TIFA_TUNING_DIR}")
|
|
178
|
+
|
|
179
|
+
# Per-algorithm verbose/timing, gated by the master switches.
|
|
180
|
+
foreach(_a IN LISTS TIFA_ALGOS)
|
|
181
|
+
if(TIFA_ALLOW_VERBOSE AND TIFA_VERBOSE_${_a})
|
|
182
|
+
set(TIFA_CFG_VERBOSE_${_a} 1)
|
|
183
|
+
else()
|
|
184
|
+
set(TIFA_CFG_VERBOSE_${_a} 0)
|
|
185
|
+
endif()
|
|
186
|
+
if(TIFA_ALLOW_TIMING AND TIFA_TIMING_${_a})
|
|
187
|
+
set(TIFA_CFG_TIMING_${_a} 1)
|
|
188
|
+
else()
|
|
189
|
+
set(TIFA_CFG_TIMING_${_a} 0)
|
|
190
|
+
endif()
|
|
191
|
+
endforeach()
|
|
192
|
+
if(TIFA_ALLOW_TIMING AND TIFA_ALLOW_EXTRA_TIMING)
|
|
193
|
+
set(TIFA_CFG_ALLOW_EXTRA_TIMING 1)
|
|
194
|
+
else()
|
|
195
|
+
set(TIFA_CFG_ALLOW_EXTRA_TIMING 0)
|
|
196
|
+
endif()
|
|
197
|
+
|
|
198
|
+
configure_file(
|
|
199
|
+
"${PROJECT_SOURCE_DIR}/cmake/tifa_config.h.in"
|
|
200
|
+
"${PROJECT_BINARY_DIR}/tifa_config.h"
|
|
201
|
+
@ONLY
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
#------------------------------------------------------------------------------
|
|
205
|
+
# Warning flags for TIFA's own compilation. Applied here (after all configure-
|
|
206
|
+
# time feature checks) so they affect only the targets built below, never the
|
|
207
|
+
# check_type_size()/find_package() probes, and are not exported to consumers.
|
|
208
|
+
#------------------------------------------------------------------------------
|
|
209
|
+
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
|
210
|
+
add_compile_options(-Wall -Wextra)
|
|
211
|
+
if(TIFA_WERROR)
|
|
212
|
+
add_compile_options(-Werror)
|
|
213
|
+
endif()
|
|
214
|
+
endif()
|
|
215
|
+
|
|
216
|
+
#------------------------------------------------------------------------------
|
|
217
|
+
# Build the library and the tools
|
|
218
|
+
#------------------------------------------------------------------------------
|
|
219
|
+
add_subdirectory(lib)
|
|
220
|
+
add_subdirectory(tools)
|
|
221
|
+
|
|
222
|
+
#------------------------------------------------------------------------------
|
|
223
|
+
# Tests (CTest)
|
|
224
|
+
#------------------------------------------------------------------------------
|
|
225
|
+
if(TIFA_BUILD_TESTS)
|
|
226
|
+
enable_testing()
|
|
227
|
+
add_subdirectory(tests)
|
|
228
|
+
endif()
|
|
229
|
+
|
|
230
|
+
#------------------------------------------------------------------------------
|
|
231
|
+
# Benchmarks (after the tests, which they add siqs-check to)
|
|
232
|
+
#------------------------------------------------------------------------------
|
|
233
|
+
if(TIFA_BUILD_BENCH)
|
|
234
|
+
add_subdirectory(bench)
|
|
235
|
+
endif()
|
|
236
|
+
|
|
237
|
+
if(TIFA_BUILD_PYTHON)
|
|
238
|
+
add_subdirectory(python)
|
|
239
|
+
endif()
|
|
240
|
+
|
|
241
|
+
#------------------------------------------------------------------------------
|
|
242
|
+
# Installation & packaging
|
|
243
|
+
#------------------------------------------------------------------------------
|
|
244
|
+
install(TARGETS tifa_static tifa_shared
|
|
245
|
+
EXPORT TifaTargets
|
|
246
|
+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
247
|
+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
248
|
+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
|
249
|
+
INCLUDES DESTINATION "${TIFA_INSTALL_INCLUDEDIR}"
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
install(EXPORT TifaTargets
|
|
253
|
+
FILE TifaTargets.cmake
|
|
254
|
+
NAMESPACE Tifa::
|
|
255
|
+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Tifa"
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
configure_package_config_file(
|
|
259
|
+
"${PROJECT_SOURCE_DIR}/cmake/TifaConfig.cmake.in"
|
|
260
|
+
"${PROJECT_BINARY_DIR}/TifaConfig.cmake"
|
|
261
|
+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Tifa"
|
|
262
|
+
)
|
|
263
|
+
# As for the soname (lib/CMakeLists.txt): below 1.0, minor versions differ.
|
|
264
|
+
if(PROJECT_VERSION_MAJOR EQUAL 0)
|
|
265
|
+
set(TIFA_PACKAGE_COMPATIBILITY SameMinorVersion)
|
|
266
|
+
else()
|
|
267
|
+
set(TIFA_PACKAGE_COMPATIBILITY SameMajorVersion)
|
|
268
|
+
endif()
|
|
269
|
+
write_basic_package_version_file(
|
|
270
|
+
"${PROJECT_BINARY_DIR}/TifaConfigVersion.cmake"
|
|
271
|
+
VERSION "${PROJECT_VERSION}"
|
|
272
|
+
COMPATIBILITY ${TIFA_PACKAGE_COMPATIBILITY}
|
|
273
|
+
)
|
|
274
|
+
install(FILES
|
|
275
|
+
"${PROJECT_BINARY_DIR}/TifaConfig.cmake"
|
|
276
|
+
"${PROJECT_BINARY_DIR}/TifaConfigVersion.cmake"
|
|
277
|
+
"${PROJECT_SOURCE_DIR}/cmake/FindGMP.cmake"
|
|
278
|
+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Tifa"
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
# pkg-config. TIFA's API is made of GMP types, so GMP is a public dependency:
|
|
282
|
+
# programs using TIFA call GMP themselves. Prefer delegating to GMP's own
|
|
283
|
+
# gmp.pc when one was found at configure time; otherwise embed the discovered
|
|
284
|
+
# GMP paths so the .pc is self-contained.
|
|
285
|
+
if(PC_GMP_FOUND)
|
|
286
|
+
set(TIFA_PC_REQUIRES "gmp")
|
|
287
|
+
set(TIFA_PC_LIBS_EXTRA "")
|
|
288
|
+
set(TIFA_PC_CFLAGS_EXTRA "")
|
|
289
|
+
else()
|
|
290
|
+
set(TIFA_PC_REQUIRES "")
|
|
291
|
+
get_filename_component(_tifa_gmp_libdir "${GMP_LIBRARY}" DIRECTORY)
|
|
292
|
+
set(TIFA_PC_LIBS_EXTRA " -L${_tifa_gmp_libdir} -lgmp")
|
|
293
|
+
set(TIFA_PC_CFLAGS_EXTRA " -I${GMP_INCLUDE_DIR}")
|
|
294
|
+
endif()
|
|
295
|
+
set(TIFA_PC_LIBS_PRIVATE "-lm ${CMAKE_THREAD_LIBS_INIT}")
|
|
296
|
+
# Relative to the .pc file, so that `cmake --install --prefix` keeps it right.
|
|
297
|
+
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
|
|
298
|
+
set(TIFA_PC_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
|
299
|
+
else()
|
|
300
|
+
file(RELATIVE_PATH _tifa_pc_up "/_/${CMAKE_INSTALL_LIBDIR}/pkgconfig" "/_")
|
|
301
|
+
string(REGEX REPLACE "/$" "" _tifa_pc_up "${_tifa_pc_up}")
|
|
302
|
+
set(TIFA_PC_PREFIX "\${pcfiledir}/${_tifa_pc_up}")
|
|
303
|
+
endif()
|
|
304
|
+
# The dylib's install name is @rpath-relative.
|
|
305
|
+
if(APPLE)
|
|
306
|
+
set(TIFA_PC_RPATH " -Wl,-rpath,\${libdir}")
|
|
307
|
+
else()
|
|
308
|
+
set(TIFA_PC_RPATH "")
|
|
309
|
+
endif()
|
|
310
|
+
configure_file(
|
|
311
|
+
"${PROJECT_SOURCE_DIR}/cmake/tifa.pc.in"
|
|
312
|
+
"${PROJECT_BINARY_DIR}/tifa.pc"
|
|
313
|
+
@ONLY
|
|
314
|
+
)
|
|
315
|
+
install(FILES "${PROJECT_BINARY_DIR}/tifa.pc"
|
|
316
|
+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
|
317
|
+
|
|
318
|
+
#------------------------------------------------------------------------------
|
|
319
|
+
# Documentation (Doxygen) - replaces the old os.system() based doc builder
|
|
320
|
+
#------------------------------------------------------------------------------
|
|
321
|
+
if(TIFA_GENERATE_DOXYGEN_DOC)
|
|
322
|
+
find_package(Doxygen)
|
|
323
|
+
if(DOXYGEN_FOUND)
|
|
324
|
+
set(_doc_dir "${PROJECT_BINARY_DIR}/doc")
|
|
325
|
+
file(MAKE_DIRECTORY "${_doc_dir}")
|
|
326
|
+
|
|
327
|
+
macro(_tifa_yesno out flag)
|
|
328
|
+
if(${flag})
|
|
329
|
+
set(${out} "YES")
|
|
330
|
+
else()
|
|
331
|
+
set(${out} "NO")
|
|
332
|
+
endif()
|
|
333
|
+
endmacro()
|
|
334
|
+
_tifa_yesno(_doxy_html TIFA_GENERATE_DOXYGEN_HTML)
|
|
335
|
+
_tifa_yesno(_doxy_latex TIFA_GENERATE_DOXYGEN_PDF)
|
|
336
|
+
_tifa_yesno(_doxy_xml TIFA_GENERATE_DOXYGEN_XML)
|
|
337
|
+
_tifa_yesno(_doxy_rtf TIFA_GENERATE_DOXYGEN_RTF)
|
|
338
|
+
|
|
339
|
+
# The historical Doxyfile template uses %TOKEN% placeholders; substitute
|
|
340
|
+
# them at configure time (all values are known now).
|
|
341
|
+
file(READ "${PROJECT_SOURCE_DIR}/doxygen.conf.in" _doxy)
|
|
342
|
+
string(REPLACE "%PROJECT%" "${TIFA_CFG_SHORTNAME}" _doxy "${_doxy}")
|
|
343
|
+
string(REPLACE "%VERSION%" "${PROJECT_VERSION}" _doxy "${_doxy}")
|
|
344
|
+
string(REPLACE "%DOCDIR%" "${_doc_dir}" _doxy "${_doxy}")
|
|
345
|
+
string(REPLACE "%TOPSRCDIR%" "${PROJECT_SOURCE_DIR}" _doxy "${_doxy}")
|
|
346
|
+
string(REPLACE "%PAPER_TYPE%" "${TIFA_DOXYGEN_PAPER_TYPE}" _doxy "${_doxy}")
|
|
347
|
+
string(REPLACE "%GENERATE_HTML%" "${_doxy_html}" _doxy "${_doxy}")
|
|
348
|
+
string(REPLACE "%GENERATE_LATEX%" "${_doxy_latex}" _doxy "${_doxy}")
|
|
349
|
+
string(REPLACE "%GENERATE_XML%" "${_doxy_xml}" _doxy "${_doxy}")
|
|
350
|
+
string(REPLACE "%GENERATE_RTF%" "${_doxy_rtf}" _doxy "${_doxy}")
|
|
351
|
+
file(WRITE "${_doc_dir}/doxygen.conf" "${_doxy}")
|
|
352
|
+
|
|
353
|
+
add_custom_target(doc
|
|
354
|
+
COMMAND "${DOXYGEN_EXECUTABLE}" "${_doc_dir}/doxygen.conf"
|
|
355
|
+
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
|
|
356
|
+
COMMENT "Generating API documentation with Doxygen"
|
|
357
|
+
VERBATIM
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
if(TIFA_GENERATE_DOXYGEN_PDF)
|
|
361
|
+
find_package(LATEX COMPONENTS PDFLATEX QUIET)
|
|
362
|
+
if(LATEX_FOUND)
|
|
363
|
+
# Doxygen emits a LaTeX Makefile; build the PDF best-effort.
|
|
364
|
+
add_custom_command(TARGET doc POST_BUILD
|
|
365
|
+
COMMAND sh -c "if [ -d '${_doc_dir}/latex' ]; then make -C '${_doc_dir}/latex' || echo 'TIFA: PDF build failed (non-fatal).'; fi"
|
|
366
|
+
VERBATIM
|
|
367
|
+
)
|
|
368
|
+
else()
|
|
369
|
+
message(STATUS "TIFA: LaTeX not found; the 'doc' target will not build a PDF.")
|
|
370
|
+
endif()
|
|
371
|
+
endif()
|
|
372
|
+
else()
|
|
373
|
+
message(STATUS "TIFA: Doxygen not found; the 'doc' target is unavailable.")
|
|
374
|
+
endif()
|
|
375
|
+
endif()
|
|
376
|
+
|
|
377
|
+
#------------------------------------------------------------------------------
|
|
378
|
+
# Source packaging (replaces the broken SCons 'dist' target)
|
|
379
|
+
# cpack --config CPackSourceConfig.cmake (or: cmake --build . --target package_source)
|
|
380
|
+
#------------------------------------------------------------------------------
|
|
381
|
+
set(CPACK_SOURCE_GENERATOR "TGZ")
|
|
382
|
+
set(CPACK_SOURCE_PACKAGE_FILE_NAME "tifa-${PROJECT_VERSION}")
|
|
383
|
+
set(CPACK_VERBATIM_VARIABLES YES)
|
|
384
|
+
# Matched against absolute paths: anchor the build directories to the source
|
|
385
|
+
# tree, which may itself sit under a /build... directory (CI checkouts).
|
|
386
|
+
string(REGEX REPLACE "([][+.*()^$?|\\\\])" "\\\\\\1" _tifa_src_re
|
|
387
|
+
"${PROJECT_SOURCE_DIR}")
|
|
388
|
+
set(CPACK_SOURCE_IGNORE_FILES
|
|
389
|
+
"/\\.git$"
|
|
390
|
+
"/\\.git/"
|
|
391
|
+
"^${_tifa_src_re}/build[^/]*/"
|
|
392
|
+
"/\\.claude/"
|
|
393
|
+
"\\.DS_Store$"
|
|
394
|
+
"/\\.sconf_temp/"
|
|
395
|
+
"\\.sconsign"
|
|
396
|
+
"\\.sconsign\\.dblite"
|
|
397
|
+
"\\.o$"
|
|
398
|
+
"\\.a$"
|
|
399
|
+
"\\.so$"
|
|
400
|
+
"\\.dylib$"
|
|
401
|
+
"\\.tgz$"
|
|
402
|
+
"\\.tar\\.gz$"
|
|
403
|
+
"/tifa_config\\.h$"
|
|
404
|
+
)
|
|
405
|
+
include(CPack)
|
|
406
|
+
|
|
407
|
+
#------------------------------------------------------------------------------
|
|
408
|
+
# Configuration summary
|
|
409
|
+
#------------------------------------------------------------------------------
|
|
410
|
+
message(STATUS "")
|
|
411
|
+
message(STATUS "TIFA ${PROJECT_VERSION} configured:")
|
|
412
|
+
message(STATUS " Build type : ${CMAKE_BUILD_TYPE}")
|
|
413
|
+
message(STATUS " BITSTRING_T : ${TIFA_BITSTRING_T} (sizeof=${TIFA_CFG_SIZEOF_BITSTRING_T})")
|
|
414
|
+
message(STATUS " GMP include dir : ${GMP_INCLUDE_DIRS}")
|
|
415
|
+
message(STATUS " GMP library : ${GMP_LIBRARIES}")
|
|
416
|
+
message(STATUS " libm : ${TIFA_M_LIBRARY}")
|
|
417
|
+
message(STATUS " Install prefix : ${CMAKE_INSTALL_PREFIX}")
|
|
418
|
+
message(STATUS "")
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tifa-factor
|
|
3
|
+
Version: 0.4.6
|
|
4
|
+
Summary: Fast factorization of integers of up to about 220 bits, with the TIFA library
|
|
5
|
+
Author: Jerome Milan
|
|
6
|
+
License-Expression: LGPL-2.1-or-later
|
|
7
|
+
License-File: readme/license_v2.1.txt
|
|
8
|
+
License-File: readme/license_v3.txt
|
|
9
|
+
Classifier: Programming Language :: C
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Project-URL: Homepage, https://github.com/milanje/tifa
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest; extra == "test"
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# tifa
|
|
20
|
+
|
|
21
|
+
Fast factorization of integers of up to about 220 bits (66 digits), with
|
|
22
|
+
the [TIFA](https://github.com/milanje/tifa) C library: its quadratic sieve,
|
|
23
|
+
elliptic curves and smaller methods, chosen by the size of the number.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
>>> import tifa
|
|
27
|
+
>>> tifa.factor(360)
|
|
28
|
+
{2: 3, 3: 2, 5: 1}
|
|
29
|
+
>>> tifa.factor(2**64 + 1)
|
|
30
|
+
{274177: 1, 67280421310721: 1}
|
|
31
|
+
>>> tifa.factor(1)
|
|
32
|
+
{}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`factor(n)` returns the prime factorization of a positive integer as
|
|
36
|
+
`{prime: exponent}`, primes in increasing order, like SymPy's `factorint`.
|
|
37
|
+
`n` can be an `int` or any integer type with `__index__` (NumPy's, gmpy2's).
|
|
38
|
+
|
|
39
|
+
## Speed
|
|
40
|
+
|
|
41
|
+
One thread, balanced semiprimes (the hardest numbers of a size), on an AMD
|
|
42
|
+
EPYC 9V45:
|
|
43
|
+
|
|
44
|
+
| bits | 100 | 140 | 180 | 220 |
|
|
45
|
+
|---|---:|---:|---:|---:|
|
|
46
|
+
| `tifa.factor` | 0.7 ms | 9.6 ms | 0.18 s | 3.0 s |
|
|
47
|
+
| PARI/GP 2.15 `factorint` | 1.9 ms | 39 ms | 0.55 s | 9.0 s |
|
|
48
|
+
|
|
49
|
+
Numbers with small factors take much less. From 180 to 220 bits the time
|
|
50
|
+
doubles about every 10 bits, and keeps growing beyond.
|
|
51
|
+
|
|
52
|
+
## Hints
|
|
53
|
+
|
|
54
|
+
When something is known of `n`, a hint saves time:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
tifa.factor(n, hint="balanced") # two primes of about the same size
|
|
58
|
+
tifa.factor(n, hint="unbalanced") # a prime factor under a third of its size
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
A hint never changes the result, but a wrong one can cost much more time
|
|
62
|
+
than none.
|
|
63
|
+
|
|
64
|
+
## Threads
|
|
65
|
+
|
|
66
|
+
`factor` releases the GIL, so that threads factor in parallel:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
70
|
+
|
|
71
|
+
with ThreadPoolExecutor() as pool:
|
|
72
|
+
results = list(pool.map(tifa.factor, numbers))
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Errors
|
|
76
|
+
|
|
77
|
+
`TypeError` if `n` is not an integer, `ValueError` if it is not positive
|
|
78
|
+
or the hint is unknown. In the rare event that `n` can not be factored
|
|
79
|
+
completely, `tifa.FactorizationError` is raised, its `factors` attribute
|
|
80
|
+
holding what was found (factors that multiply to `n`, some of them not
|
|
81
|
+
prime).
|
|
82
|
+
|
|
83
|
+
## Installing
|
|
84
|
+
|
|
85
|
+
From PyPI:
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
pip install tifa-factor
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Wheels exist for Linux (x86-64 and arm64, glibc and musl) and macOS (arm64
|
|
92
|
+
and x86-64, 11.0 and later), for Python 3.10 and later; GMP comes in them.
|
|
93
|
+
Elsewhere, pip builds the package from source.
|
|
94
|
+
|
|
95
|
+
From a checkout of [TIFA](https://github.com/milanje/tifa), at the top of
|
|
96
|
+
the tree:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
pip install ".[test]" # or "pip install ." without pytest
|
|
100
|
+
python -m pytest # the tests
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
A build from source needs a C compiler, CMake 3.26 or later (pip fetches it
|
|
104
|
+
if the system's is older) and GMP with its headers (`libgmp-dev` on
|
|
105
|
+
Debian and Ubuntu, `gmp-devel` on Fedora, `brew install gmp` on macOS). A
|
|
106
|
+
GMP installed elsewhere than in the usual places is found through
|
|
107
|
+
`GMP_ROOT`, the directory holding its `include` and `lib`:
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
GMP_ROOT=/opt/gmp pip install .
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Licence
|
|
114
|
+
|
|
115
|
+
LGPL 2.1 or later, as TIFA. The wheels contain GMP 6.3.0
|
|
116
|
+
([gmplib.org](https://gmplib.org)), under the LGPL 3 (readme/license_v3.txt),
|
|
117
|
+
linked statically: `pip install --no-binary tifa-factor tifa-factor` builds
|
|
118
|
+
the package against the GMP of the system instead.
|