1. Introduction
This study investigates the properties and advantages of large-number optimization problems, defined as those involving large numbers—that is, integers with more than N digits or rational numbers whose numerators or denominators exceed N digits—in the values of the decision variables, objective functions, or constraints. It further aims, on the one hand, to develop exact-arithmetic software for their solution and, on the other, to compute partially increasing subsequences of the Collatz sequence. At the time of writing, numbers with digits could be considered large, corresponding approximatively to .
Mathematical optimization, in both its continuous and discrete forms, is a mature discipline with a wide range of theoretical foundations and applications. Foundational contributions such as those by Nemhauser and Wolsey [
1] and the comprehensive review of global optimization methods in process systems engineering by Floudas and Pardalos [
2] have provided essential methodologies that remain influential today. Recent work continues to advance both theory and practice: Werner [
3] and Werner [
4] emphasize developments in discrete optimization, while Grossmann and Biegler [
5] survey advances in mathematical programming techniques for process systems engineering. Broader algorithmic perspectives, such as those discussed in Vishnoi [
6]’s work, highlight the interface of optimization with computer science and complexity theory. Applications in emerging fields are also expanding: Qin et al. [
7] review real-time optimization in the process industries, while the edited volume of Nikeghbali et al. [
8] provides insights into cutting-edge research and methodologies on optimization, discrete mathematics, and applications to data science. Recent developments focus on bringing machine learning and classical mathematical optimization closer together. For instance, Wang et al. [
9] propose a reinforcement learning-based ranking teaching–learning optimization algorithm for parameter identification in photovoltaic models, while Schnabel and Usul [
10] investigate the embedding of neural networks into optimization models, where the network architecture itself appears as constraints in the model. These studies collectively illustrate that optimization remains both a well-established and rapidly evolving area of research with deep methodological roots and continuing impact across disciplines.
However, a search of the existing literature did not reveal any publications explicitly addressing optimization problems involving large numbers. A possible explanation may lie either in a limited perceived relevance of such problems, or in the absence of solvers capable of handling them, potentially due to the following reason: large numbers in the sense defined above are a challenge as they are beyond the limits of 32-bit or 64-bit architecture and, thus, programming languages. Many programming languages (like C, C++, Java, C#), algebraic modeling systems such as
GAMS (cf. Bussieck and Meeraus [
11] or Bussieck et al. [
12]), and commercial mixed-integer programming solvers default to 32-bit signed integers (int) ranging from the smallest number
to the largest number
(one bit is reserved for the sign, leaving 31 bits for the value). Modern systems now widely support 64-bit integers (long or int64_t) corresponding to integers up to
. In Python, integers can grow beyond any number of bits dynamically; memory is the only limit.
Numerical challenges in exact arithmetic relate to algorithmic aspects [addition and subtraction are linear in time O(
n), naive multiplication is quadratic in time O(
), a better approach by Karatsuba and Ofman [
13] O(
), and division and module operations are much slower (factor 2 to 10) than multiplication]. In addition, there are aspects of memory to be considered, for instance, rational arithmetic requires storing the numerator and denominator separately, and fractions, when added, lead to numerators and denominators growing in the number of digits.
The computational complexity of large-number optimization is expected to be worse than that of normal-number optimization as the arithmetic briefly addressed above and memory issues cause extra problems and overhead. But when is large-number optimization—or exact-arithmetic optimization—actually needed? The need for large-number optimization or exact-arithmetic optimization arises in various contexts. In 2012, the specific motivation for this study was to identify the partially increasing Collatz sequences described in
Section 2. More generally, optimization problems involving large numbers are, or could be, of value for several reasons:
Real-World Precision—Applications like cryptography and integer factorization involve large numbers and require exact computations, while quantum computing requires exact calculations or calculations beyond standard floating-point precision but does not necessarily involve large numbers. An application field that remains highly demanding despite not requiring exact solutions is orbital mechanics, also known as astrodynamics, which requires extremely precise calculations—often beyond standard floating-point precision (like 64-bit double)—due to the accumulation of numerical errors over time or sensitivity of the solution with respect to the initial conditions.
Practical Aspects and Scaling—If scaling is not possible due to the inherent structure of the optimization problem at hand, then exact arithmetic is is a good option. Note that problems related to large floating-point numbers that occur in scientific or optimization problems can often be solved by selecting the appropriate units and scaling, but when many-digit numbers are involved and exact solutions are required, this is not possible.
Algorithm Robustness—Testing optimization methods on such problems reveals weaknesses in numerical stability, rounding errors, or scalability as in the work of Jarck [
14].
Theoretical Insights—Large numbers expose hidden computational limits, pushing advancements in arbitrary-precision arithmetic and efficient algorithms.
Emerging Needs—As data grows (e.g., blockchain, AI training), handling massive integers or fractions becomes critical for accuracy in optimization tasks. Currently, the focus is more on large-scale problems, i.e., many integers, but maybe the field will also develop a taste for exact solutions.
Very Large Weights or Capacity Data in Knapsack Problems—Cryptographic knapsack problems seem to move towards consistently larger input data to resist code-breaking attacks (cf. Wang and Chen [
15] or Rizos and Draziotis [
16], respectively).
Recreational Mathematics—What is the smallest prime number with 100 digits which contains all digits 0 to 9 (each of them occurring ten times) and zero is not in the leading position? The answer is given in
Appendix A.
Solving optimization problems involving large numbers might also be considered a niche area that often intersects with computational number theory, cryptography and integer factorization, and high-precision arithmetic. Large integers are central to cryptographic algorithms like RSA, where factoring large semi-primes is a key challenge (cf. Aoki et al. [
17], where the authors focus on factoring large integers with over 100 digits). Computational number theory often involves large integers, such as primality testing or solving Diophantine equations with large integer solutions (cf. Lenstra [
18]). Several publications focus on developing specialized libraries and software tools for handling large integers and solving related optimization problems; cf. “GMP: The GNU Multiple Precision Arithmetic Library” by Granlund and the GMP Development Team [
19], a widely used library for high-precision arithmetic, and also “MPFR: A Multiple-Precision Binary Floating-Point Library with Correct Rounding” by Fousse et al. [
20], which focuses on high-precision floating-point arithmetic.
There are limits to expect in terms of the number of variables and constraints which can be handled—and there is a price to pay for exact results in terms of computational speed and the lack of real-time applications. Within the Simplex algorithm, intermediate expressions and fractions grow rapidly during row operations. Why not use existing programs and software? A few options have been explored, including Xcas, which was straightforward to install. Regarding GMP, the prerequisites (Windows is not GMP’s favored operating system) and setup intricacy did not appear appealing to us. At long last, our own software has endowed us with a greater degree of flexibility, and it has also made the experience all the more pleasurable.
The contributions and innovations by the author in this paper are as follows:
The construction of a partial subsequence of the Collatz sequence which grows for J steps.
The construction of a partial decreasing subsequence of the Collatz sequence which repeats J times the pattern of multiplying by and reaching a number which has as a divisor, i.e., it can be divided m times by 2, then being odd again.
The construction of further partial subsequences of the Collatz sequence following more general patterns repeatedly growing for J steps.
The construction of special and generic algorithms to solve large-number optimization problems although only small ones (not too many variables and constraints) coded in Python (Version 3.6.1) and Fortran:
LP-enum.py,
simplex.py,
BLP-enum.py, and
BandB.py or the Fortran equivalents, respectively. Our exact standard Simplex and Branch and Bound algorithm is suitable to solve large-number optimization problem (no limit on the number of digits). This work represents an initial step, with the expectation that it will pave the way for a comprehensive library approach addressing a broader range of problems. Fortran was chosen for the existing block structure (supporting exact integers and fractions without bit limits) in my program since the late 1980s used to compute the determinants in the work of Kallrath and Neutsch [
21], while modern Python was selected for its inherent support of arbitrary-precision integers without any bit limits and flexibility.
The construction of challenging test examples, for which I derived analytic optimal solutions, to test my algorithms and programs.
Briefly discussing the pros and cons of large-number optimization algorithms.
As far as the development of software is concerned, the following scope and thoughts about potential applications should be clear to the reader: This paper addresses optimization problems in which the dominant challenge is the size of the numbers or their number of digits, respectively, not the size of the dataset. Our algorithms and proofs target regimes where coefficients and intermediate quantities exceed standard bit limits, so that exact arithmetic and an arbitrary number of digits is required to guarantee correctness and verifiable optimality. Although this paradigm is distinct from large-scale data processing, it is relevant to models in which extremely large integers or rational numbers arise (e.g., exact mixed-integer formulations with very large coefficients; certification tasks where numerical error cannot be tolerated). Fields such as computational number theory or cryptography routinely manipulate large integers; while many of their core problems are not optimization-driven, certain verification or parameter-selection steps could, in principle, benefit from exact-arithmetic optimization. A systematic exploration of such domain-specific applications lies beyond the scope of the present foundational study and is a valuable direction for future work.
Consequently, the structure and methodology of research in this article is as follows.
Section 2 contains the problem definition related to my original motivation and the development of analytic and semi-analytic procedures to construct increasing Collatz sequences defined by given patterns. As this problem leads to large-number optimization problems, an overview of computer algebra systems, high-precision libraries and rational solver is provided in
Section 3, accompanied by the opportunities these techniques offer for the problem at hand. As they do not suffice for the given problem, in
Section 4, a brief overview and description of my implementations of algorithmic approaches to optimization involving large numbers follow. Building on these methods, in
Section 5, the reader finds the construction of several test problems, for which we have derived analytic optimal solutions for testing the programs, along with the corresponding numerical results. This is followed by the Conclusions section, which includes some suggestions for future work. The appendix has been selected as the location for material that seems necessary or useful for providing additional details, but that would have disrupted the flow of the article if it had remained in the main body. The sections in the appendix are not related.
2. Computing Partially Increasing Sequences Within the Collatz Sequence
The Collatz conjecture (cf. Lagarias [
22] or Lagarias [
23] for a recent overview), also known as the
problem, involves a recursive sequence generated by iterating a simple function: for any positive integer
n, if
n is even, divide it by 2; if
n is odd, multiply it by 3 and add 1. The Collatz sequence is the recursive sequence defined on
by
i.e., if the number is even, divide it by two, and if the number is odd, triple it and add one. An equivalent closed-form recursion not depending on conditionals is
which may be useful for proofs and numerical computations.
The Collatz conjecture named after the Darmstadt (Germany) mathematician Lothar Collatz is as follows: This sequence will always reach the number 1, regardless of which positive integer is chosen initially. Proofing the Collatz conjecture would mean to rule out the existence of cycles different from 1-4-2-1, and to rule out that .
The motivation for this paper was the question: Is it possible to find a starting number of the Collatz sequence for which the partial subsequence increases for a given number,
J, of steps, i.e., can one find a starting number
such that
, where
is the subset of odd natural numbers? In general, this pattern (up by
, down by dividing by 2), referred to as
ud, repeats
J times as
Of interest is only the smallest number
fulfilling (
2). Note that
needs to be an odd number. The sequence
contains only the odd elements of the Collatz sequence
. This idea is later generalized in
Section 2.5 to the concept of
being the header element of block
j where each block follows the same pattern.
As a generalization of (
2), although that subsequence is not increasing, one might ask whether it is possible to construct a partial sequence of the Collatz sequence with the property
At first, an integer linear programming (ILP) model is constructed in
Section 2.1. Its solution establishes the sequence
for up to
. The solutions for any
are obtained by solving the system of Diophantine equations in
Section 2.2. For easier reading, the set
is introduced.
2.1. Integer Linear Programming (ILP) Model
Condition (
2) translates algebraically into
or equivalently
If one declares the variables
as discrete variables, an MILP solver ensures through its underlying algorithms that
. Note that this does not necessarily lead to
. However, solving the minimization problem C1
does yield a solution. As
is minimal,
is as well; the minimal property propagates from
to
. As the values
grow quickly, the MILP solver
GAMS/CPLEX can only solve the problem up to
. So, as expected, with growing
J, the limits of a standard MILP solver are quickly reached when entering the regime of large-number optimization. Therefore, instead, the analytic solutions of linear Diophantine equations developed in
Section 2.2 are used. Alternatively, the suitability of the computer algebra systems and other software packages described in
Section 3 can be assessed, or a generic MILP solver can be developed; this results in
BandB.py, which is presented in
Section 4 and tested in
Section 5.
2.2. Diophantine System of Equations
Due to the numeric limitations of the MILP solvers when handling large numbers, let us now derive a closed-form analytic solution. The Diophantine Equation (
4)
can be solved analytically using Euler’s algorithm. Its solutions are
where
parameterizes all its solutions. If one wants to solve the system of Diophantine equations
one needs to ensure compatibility of all
,
, i.e.,
or
Equation (
5) is fulfilled by
The partial, odd elements of the Collatz sequence are thus
while the next even elements—resulting from the operation
—are given by
To illustrate this formula, consider the case
, leading to the following results:
Note that
can also be derived from
, but it is not an odd number any longer. For completeness, the sequence
initiated by
is listed; it obviously does not follow the pattern
ud any longer.
Note that
is given by
The starting element given by (
7) allows the following interpretation. If one wants to increase infinitely many times, i.e.,
, one has to start at infinity.
2.3. Comments on Decreasing Numbers
Let us comment on a few numbers
, referred to as
downers, for which the Collatz sequence—after a certain
step—will decrease directly to one; note that here
j is not treated as a running index (one might also name it
). At first, it is obvious that this is so for numbers
with
(type 1
downers). If
hits
, in
n steps, it reaches 1, i.e.,
. Thus, all numbers
are
downers of type 1. Examples (
): (2, 1), (4, 5), (6, 21), (8, 85).
Second (type 2
downers), if
in
steps, it reaches 1, i.e.,
. The proof is based on the observation that
can always be represented by the equation
which can be proven by complete induction. For
, the value
is obtained, initiating the induction. The induction step proceeds as follows:
Thus, all numbers
are
downers of type 2. This gives only even positive integers, i.e., they cannot be used for the
up step
.
Third, if
then downers are given by
In
steps (u-m·d-u-n·d) the result 1 is obtained, i.e.,
. This is based on the second result. From the
downer, there is one up step leading to a number which can be divided by
reaching an odd number, from which the up step gives
.
Examples for
:
Note that further pairs are given by [
].
Alternatively, this result could be expressed as follows. Each second power of two has a
downer. If
has a
downer k, the following holds:
The next power of two then does not have this property due to
which means it cannot be represented in the form
. However,
has a
downer as
with
. As
has
downer 1, the powers of two
, also have a
downer.
2.4. Modified Diophantine Systems
Unlike the downers above, consider now a slightly different situation: If one wants, after an increase,
m subsequent division by 2 and then up again (that requires the division by
to be an odd number), the Diophantine Equation (
4) needs to just be modified to
This modified Diophantine equation system (
8) has for all its components
j and for all
m the solution
, where 1 is a divisor of
. To solve the system, it needs to be evaluated for each
m individually. For
, it follows that
and the compatibility equation
with the solution
To illustrate this formula, consider the simple case
and
, leading to the results
For
, it follows that
and the compatibility equation
or
for which one cannot easily find a solution due to the appearance of the summand 2. However, the ILP approach easily produces solutions although only for small
J. From these solutions, the values
can be derived. Is it possible to prove that a solution exists for any given
? As (
11) is a linear Diophantine equation with
, one can always find a feasible pair
.
For
, it follows that
and the compatibility equation
or
for which one cannot easily find a solution due to the presence of the minuend
. However, the ILP approach easily produces solutions although only for small
J, even for
, using
GAMS/CPLEX.
2.5. More Patterns
This subsection focuses on patterns constructed from U pairs of up and down moves (operation or division by 2, respectively) followed by a few additional down moves. For example, the pattern udududd consists of up moves and down moves, while the pattern ududududddd comprises up moves and down moves.
Is it possible to find a starting number of the Collatz sequence for which the partial subsequence of numbers
increases for a given number,
J, of steps? This means that one can find a starting number,
, following the pattern
udududd, i.e.,
where
is called the header of block
. The connection between the Collatz sequence
and the partial Collatz sequence
of block headers is given by
, where
indicates the position in the pattern.
In general, this pattern (up by
, down by 2, again up by
, down by 2, and finally, up by
, and down by 4) repeats
J times as
Recursion (
14) can be formulated as the ILP minimization problem
The focus is again solely on the smallest number
that satisfies (
15). The inhomogeneous system of Diophantine equations
can also be solved analytically using Euler’s algorithm, leading to a parameterized solution by
:
To find an analytic expression for
involving only
J and
j to solve (
16), one needs to ensure the compatibility of adjacent
,
, i.e.,
Equation (
17) is again an inhomogeneous linear Diophantine equation system and cannot—as in the homogeneous case—simply be an expression like (
7):
From (
17) one can, on the one hand, obtain the recurrence relation
while, on the other hand, it has the parameterized solution
with the compatibility constraint
or
So, via this approach, detailed formulae for
and repeating the worked out formulae
J times do not bring us to a closed analytic solution; however, brute force or solving is still possible for
. Our Python implementation, for
, required 9 h 12 min 36 s to compute
, and
took 14 h 8 min 52 s with
.
To obtain a more elegant solution and a general explicit formula for the repeated patterns
udududd,
ududududd, …,
ududududdd (repeated
J times), expressions relating
Z and
N to
U and
D are derived. For example, in the pattern
ududududdd—where
and
—the computation starts with
, and
is obtained according to
leading to
The recursion formula for the starting numbers of the blocks of a pattern specified by
U and
D is
which, for
and
, gives us
The general explicit formula—proof by complete induction—for repeating
ududududdd J times is given by
For
or
, one gets a monotonically increasing sequence of block starting points
of the specified pattern
with
To compute solutions of (
20), the equation is reformulated as
or its equivalent form
with
and
. Coprimality, i.e.,
, allows the deduction of
for some integer
k derived as follows. From (
22) and (23), the variables are obtained by solving
Both numerators must be divisible by
N. Exploiting the modular arithmetic techniques described and outlined in
Appendix C.1, and using the modular inverse
satisfying
it follows that
Finally, the smallest integer
m is determined such that
satisfies
, which yields
according to (25).
So far, a computationally efficient method has been established for determining the first element
of each block. However, this method only knows how to connect the block header elements but it does not know about the inner structure of the pattern. Therefore, one must check whether the Collatz operations
up and
down are possible as these operations depend on whether the Collatz sequence elements
[
i is the index within the pattern structure] are odd or even. The process begins with
, which establishes the values of
k and
. This is performed by applying the Collatz sequence definition to
and checking whether
is odd. This is followed by computing
, checking whether
is even, computing
, and so on, until the last element—making sure that
is odd again to connect properly to the next block
. If a test for whether a number is
odd or
even fails, exit the loop and repeat the test with
. So far, if
a consistent pattern solution has always been found, leading to the conjecture that it is always possible to find a consistent solution with this approach. However, this method will not work if
, e.g., for pattern
with
,
, and thus,
. This case is solved differently as in
Appendix C.2.
The following table summarizes the results for a few patterns and
(
and
are the solutions without enforcing
while
m and
follow from enforcing it):
Note that if
or
, the sequence of block starting points is monotonically decreasing and given by
with
and
with
and
. Its equivalent form
and exploiting coprimality, i.e.,
, allows us to deduce
for some integer
k. For
and
, one obtains
and
and
.
The variables
and
are obtained from solving (
22) and (23)
where both numerators must be divisible by
N.
If the modular conditions are now exploited again, as previously conducted, there is no guarantee in this case of decreasing patterns that make itpossible to find such a path, i.e., sequence of numbers.
3. Computer Algebra Systems, Multi-Precision Libraries and Exact-Rational Solvers
The in the paper where I talk about which system I have used.
Purpose of this section is to check the suitability of computer algebra systems or other software packages for solving large-number optimization problems. To begin with, there are various commercial computer algebra systems (CAS, e.g., Mathematica, Maple) and libraries for high-precision computing—partly at no cost—available, which might be useful to solve large-number optimization problems.
The commercial computer algebra systems Mathematica and Maple both provide high-precision arithmetic or symbolic computations, respectively, and optimization functionality. While these systems are widely used and offer robust solvers, their proprietary nature and high licensing costs often limit accessibility in academic and resource-constrained contexts.
There are also some free and open-source computer algebra systems (CASs) that are used in academia and research. These systems can handle symbolic mathematics, numerical computations, and even optimization problems. And there are a few LP and MILP solvers for exact-rational arithmetic, though not necessarily designed or capable of handling large numbers. Below, without claiming completeness, is a list of such systems:
SageMath is one of the most comprehensive open-source CASs supporting symbolic and numerical computation, graph theory, combinatorics, and number theory as well as linear algebra, calculus, and optimization, e.g., linear programming and mixed-integer linear programming. It integrates many other open-source mathematical libraries (e.g., NumPy, SymPy, GAP, PARI/GP) into a single interface (URL:
https://www.sagemath.org (accessed on 20 May 2025)).
SymPy is a Python library for symbolic mathematics, e.g., algebra, calculus, and equation solving as well as support for matrices, polynomials, and discrete math. It is lightweight and easy to integrate into Python projects and with NumPy and SciPy for numerical computations (URL:
https://www.sympy.org (accessed on 20 May 2025)).
Maxima is a classic CAS with a long history in symbolic. It is based on the original Macsyma system developed at MIT. Its features include symbolic and numerical computation and numerical computations, e.g., solving equations, calculus, and linear algebra, or 2D and 3D plotting. It is mature, supports a large set of mathematical functions, and is known for its stability and robustness (URL:
https://maxima.sourceforge.io (accessed on 20 May 2025)).
PARI/GP is a specialized CAS for number theory and algebraic computations, especially, fast arithmetic with large integers, support for elliptic curves, modular forms, and algebraic number fields. A scripting language for automation is provided as well (URL:
https://pari.math.u-bordeaux.fr (accessed on 20 May 2025)).
Axiom is a general-purpose CAS with a strong focus on symbolic computation and algebraic structures, especially advanced symbolic algebra, support for abstract algebra and category theory. It is extensible via a scripting language (URL:
http://www.open-axiom.org (accessed on 1 October 2025)).
Reduce is a general-purpose CAS designed for symbolic computation, especially symbolic algebra, calculus, and equation solving and support for polynomials, matrices, and tensors. Linear programming problems can be solved by the Simplex algorithm. It is customizable via its own scripting language (URL:
https://reduce-algebra.sourceforge.io (accessed on 20 May 2025)).
Xcas/Giac is a user-friendly CAS based on the Giac library for symbolic and numerical computation with support for calculus, algebra, and geometry as well as linear programming and mixed-integer linear programming. Its syntax is compatible with Maple syntax and it is easy to use (URL:
https://xcas.univ-grenoble-alpes.fr/en.html (accessed on 4 April 2025)).
There are a few rational—and in this sense—exact LP or MILP solvers:
PySimplex by Clavero [
24] is a lightweight Python implementation of the standard Simplex algorithm for solving linear programming problems, aimed at educational use and algorithmic transparency (URL:
https://github.com/carlosclavero/PySimplex (accessed on 11 June 2025)).
SCIP by Jarck [
14] is a general purpose solver for mixed-integer linear and nonlinear programming problems. It has also an in-built exact-rational solver based on the GMP library (see below). Data and model input can be via the modeling language
ZIMPL (URL:
https://github.com/scipopt/scip/tree/exact-rational (accessed on 31 March 2025)).
SoPlex by Gleixner et al. [
25] is an open-source, high-precision linear programming solver developed at ZIB, designed for robustness and accuracy using iterative refinement and rational computations; written in C++. It uses object-oriented design principles and integrates with other C++-based tools like
SCIP, while also offering a C-style interface for broader compatibility.
It is not clear what the largest numbers these solvers support are. As PySimplex is coded in Python, it is likely that it can compute arbitrary large numbers only limited by the available memory of the computer.
Below are among the libraries relevant to large-number optimization problems:
“
GMP: The GNU Multiple Precision Arithmetic Library” by Granlund and the GMP Development Team [
19], a widely used library for high-precision arithmetic; programming language: C. URL:
https://gmplib.org (accessed on 20 May 2025). Granlund and the GMP Development Team [
19].
“
FMlib: FM Multiple-Precision Software Package” by Prof. David M. Smith reachable through
dsmith@lmu.edu. It is exact for integer and fractions. Programming language: Fortran95. URL:
https://dmsmith.lmu.build (accessed on 7 April 2025).
Several computational tools were evaluated, including
Xcas, which offered a straightforward installation process. In contrast, the GNU Multiple Precision Arithmetic Library (GMP) has less favorable prerequisites for Windows platforms, and its installation procedure is comparatively complex. In the preliminary stage of this study,
Xcas proved effective for testing small-scale examples involving large numbers but was less suitable for larger or more complex cases. Other freely available computer algebra systems appear to lack support for solving mixed-integer linear programming (MILP) problems. Consequently, we developed our own programs, described in
Section 4 (Foundations and Implementations) and
Section 5 (Examples and Testing).
4. Algorithmic Approaches to Optimization Involving Large Numbers
In this section, a brief overview of our implementations of algorithmic approaches to large-number optimization is provided. As the focus is rather on exact results and less on numerical efficiency, textbook-style implementations are sufficient, especially as we use exact-number implementations, for instance, in Python. Among the approaches implemented are vertex enumeration for small LP problems (LP-enum.py), a standard-tableau Simplex algorithm (simplex.py), an enumeration scheme for binary linear programs (BLP-Enum.py), a B&B procedure (BandB.py), and some programs tailored to the individual problems explained.
The algorithms have been coded in Fortran95 (exploiting block structures to exceed the standard integer limit), and Python (symbolic as well as exact-fraction arithmetic via SymPy). Fortran was chosen for its existing block structure derived from my program used to compute the determinants in Kallrath and Neutsch [
21], while Python was selected for its support of arbitrary-precision integers.
Testing the algorithm is challenging as there are no algebraic modeling languages available which would allow the coding of optimization problems in an elegant way. The results have been compared to the derived analytic optimal solutions, to the results obtained by GAMS/CPLEX up to the limit of numbers supported, and, in the initial phase of this project, to the results obtained by the computer algebra system Xcas. Having an enumeration scheme and a Simplex algorithm implementation is of great help to check both of these. The same is true to check the B&B implementation by the complete enumeration scheme.
4.1. Complete Vertex Enumeration
The vertex enumeration scheme has been useful in the beginning to check the Simplex algorithm described in
Section 4.2. It addresses linear programs (problem LP) in the maximization form:
where
![Mathematics 13 03190 i001 Mathematics 13 03190 i001]()
is the decision variable vector,
![Mathematics 13 03190 i002 Mathematics 13 03190 i002]()
is the constraint matrix (
m <
n),
![Mathematics 13 03190 i003 Mathematics 13 03190 i003]()
is the right-hand side vector,
![Mathematics 13 03190 i001 Mathematics 13 03190 i001]()
is the objective function coefficient vector, and
l,
![Mathematics 13 03190 i001 Mathematics 13 03190 i001]()
are lower and upper bounds of the variables.
The implemented vertex enumeration method exploits exact arithmetic. It starts with inequality constraints that are converted to equalities by adding slack variables.
The vertex enumeration algorithm enumerates all possible basis combinations of size
m from
variables (including original and slack variables). For each basis
B, the following steps are performed:
Set non-basic variables to their bounds (considering both lower and upper bounds);
Solve for basic variables;
Check feasibility for the variable bounds: and the original constraints: with ;
Compute objective value for feasible vertices.
To avoid numerical errors, exact arithmetic via SymPy is used within Python. The solver provides exact-fraction solutions with the objective function value in exact and decimal forms as well as a constraint verification with slack computation.
4.2. Simplex Algorithm
We have implemented a standard Simplex algorithm in tableau form for solving linear programs in standard form:
using the same symbols as in
Section 4.1 for problem LP. The implementation follows along the lines outlined in Kallrath [
26].
For using the concept of basic feasible solution, let
be a basis with
, and let
be non-basic indices. This leads to partition
and
from which the basic solution follows by setting
(or its lower and upper bounds) and solving
Note that the basis inverse
is implicitly generated through the tableau. For maximization problems, the optimality condition is
If satisfied, the current solution is optimal.
In pivoting, the non-basic variable
with the most positive reduced cost is selected as a candidate for entering the basis. Then, we compute the direction
and find the leaving variable via the minimum ratio test:
Subsequently, the basis is updated, and the next iteration is performed until all reduced costs are negative.
For problems with general bounds, as described in
Section 4.1 for problem LP, a transformation to standard form is applied. Specifically, for each bounded variable
, the following procedure is implemented: If the lower bound
, substitute
, and if
, add slack variable
leading to
The resulting problem has only non-negative variables.
With bounds, the ratio test becomes:
Each variable in the optimal solution is either a basic variable with its value determined by
, or a non-basic variable at lower bound if the reduced cost is the variables.
, at upper bound if the reduced cost is
, or free if the reduced cost
(for a maximization problem). Each variable in the optimal solution is either a basic variable with its value determined by
, or a non-basic variable at lower bound if reduced cost
, at upper bound if reduced cost
, or free if reduced cost
. Note that a Phase I procedure is used to find an initial feasible solution.
4.3. Complete Enumeration for Binary Linear Programming (BLP) Problems
The binary linear programming problem is formulated as
using the same symbols as in
Section 4.1, ∘ represents the constraint relations (≤, =, or ≥ for each constraint) and
is the binary decision vector.
The algorithm implements complete enumeration starting with the initialization, in which all numerical values are converted to exact fractions
and initialize the tracking variables
Within the enumeration scheme, for each binary vector
(generated via Cartesian product), feasibility for all constraints
is checked, where
is the relation for constraint
i. If feasible, the objective function value is
and the updated best solution follows as
and feasible count is incremented
The procedure terminates after evaluating all
possible solutions: If
, the problem is infeasible. Otherwise, the optimal solution
is returned; alternatively, one could also inspect other binary feasible solutions.
The algorithm coded in BLP-enum.py has time complexity and space complexity (for storing the problem). Consequently, the method is best applied only when .
4.4. Branch and Bound
Our B&B implementation follows along the lines outlined in Nemhauser and Wolsey [
1] and Kallrath [
26], and has been coded in our Python file
BandB.py; it works well for the tests in
Section 5.2 and the one described in
Appendix B.4 solved by exploring three nodes. The pseudo-code of the implementation is shown below in Algorithm 1.
Algorithm 1 Branch the variables. and Bound for Mixed-Integer Linear Programming |
- 1:
Input: Objective coefficients c, constraint matrix A, right-hand side b, integer variables x, bounds B, sense s, relations r - 2:
Output: Optimal solution , objective value - 3:
Initialize best solution , best value (min) or (max) - 4:
Initialize node queue Q with initial node from LP relaxation with bounds B - 5:
Set node counter - 6:
while Q is not empty do - 7:
Pop node n from Q with LP solution x, value z, bounds - 8:
if (min) or (max) then - 9:
Prune node n - 10:
continue - 11:
end if - 12:
if x satisfies integer constraints for all then - 13:
if (min) or (max) then - 14:
Update , - 15:
end if - 16:
continue - 17:
end if - 18:
Find integer variable with most fractional value - 19:
Compute floor , ceiling - 20:
Create left child with bound - 21:
Solve LP relaxation for to get solution , value - 22:
if is feasible then - 23:
Add to Q with priority (min) or (max) - 24:
Increment k - 25:
end if - 26:
Create right child with bound - 27:
Solve LP relaxation for to get solution , value - 28:
if is feasible then - 29:
Add to Q with priority (min) or (max) - 30:
Increment k - 31:
end if - 32:
end while - 33:
Return ,
|
Various tests of
BandB.py are now performed in
Section 5.
5. Sample Problems and Verification
In this section, a collection of test problems is presented to evaluate the correctness of the computational implementation. These problems have been specifically constructed for this study to verify that the Python programs produce accurate results. For each test problem, the analytical optimal solution has been rigorously derived and compared against the numerical solutions obtained from the programs described in
Section 4 or
Xcas. In addition to Xcas (Version: Giac/Xcas-Version 1.9.x based on builds from the period 2022–2024), we carried out tests with time-limited evaluation licenses of the commercial computer algebra systems Mathematica (Version 4.3 released on 25 August 2025) and Maple (Version 2025.1). The results obtained with these systems were identical with those of our Python implementation; only in the instance in
Section 5.2.4 did Mathematica return an alternate solution with the same objective function value. Computation times of Mathematica, Maple, and Python were for most cases below a second and are thus of comparable.
A key challenge in developing effective test cases for this study lies in the absence of an algebraic modeling language capable of handling the large numbers specifically targeted for investigation. The same seems to hold true for standard input formats, such as the MPS- or LP-format used by various commercial LP or MILP solvers. Not surprisingly, these commercial solvers are not set up for dealing with large numbers, either. Therefore, only scalar models with a limited number of variables and constraints are presented. Note that our focus is solely on large numbers and exact solutions, not on computing times or efficiency of our large-number LP or ILP solvers. Unless reported otherwise, the computing times were of the order of seconds. The experiments were run on a 64 bit machine with an Intel(R) Core(TM) i7 CPU 2.8 GHz, 16 GB RAM, and Windows 10.
This section is divided into example groups of increasing complexity, beginning with three linear programming problems. This is followed by example group 2, with five ILP problems (the last one is the original Collatz integer programming problem introduced in
Section 2). Finally, example group 3 has only one problem with a bilinear objective function and linear and quadratic constraints.
5.1. Example Group 1: Linear Programming Problems with Large Input Data
To evaluate the algorithms and implement solvers into these problems, either an analytical optimal solution is derived for each problem or the results are compared against one another for consistency. For instance, a problem is solved using Xcas, LP-enum.py, and simplex.py to verify whether consistent results are obtained across these implementations.
5.1.1. LP Example 1
Now, with
and
, the aim is to solve the following maximization problem:
subject to the constraints:
As
, for the optimal solution, one expects
, and the approximate values
and
. Our Simplex–Python code [
LP-Ex1.py] produced the exact values as fractions:
5.1.2. LP Example 2
Another test problem, utilized to evaluate the Python program
simplex.py, and incorporating a large number
N, such as
, is
subject to the constraints
This problem has the following analytic solution: The basic variables
are very close to 1 (
is a very small number approaching zero as
), the non-basic variable
at its upper bound, and the objective function value
This example turned out to be a good test case for
simplex.py, especially for the logic to handle bounds within the Simplex algorithm.
5.2. Example Group 2: Integer Linear Programming (ILP) Problems with Large Input Data
To test the ILP algorithms and implemented solvers on these problems, either an analytical optimal solution is derived for each problem or the results are compared against one another for consistency. For instance, a problem is solved using Xcas, BLP-enum.py, and BandB.py to verify whether consistent results are obtained across these implementations.
The following base case is presented, from which various variations are derived: The objective is to maximize
subject to
with
. The analytic solution is obviously
,
and
. Therefore, this base case is used as an example and starting problem from which a few more cases are derived.
5.2.1. ILP Example 1: Integer Linear Programming Problem with Large Input Data
Now, the aim is to solve the following maximization problem:
subject to the constraints:
The solution obtained by
Xcas (webversion) is
Now, instead of (
34), the inequality
is used.
Xcas provides the solution
which is wrong. The integer solution can be obtained by noting that
is a valid inequality. Now
Xcas and also
BandB.py return the correct solution
Key insight: Significant care is required when handling large numbers to ensure computational accuracy.
5.2.2. ILP Example 2: Problem with Large Objective Function Coefficients
With
and
, the goal is to maximize
subject to
and
. As
, in the optimal solution one expects
. Due to
, the maximum value
can attain is
. Thus the analytic solution is that our Python code
BandB.py returns the correct results
Also, these were obtained by BandB.py in less than a second. These values are found at root node and both inequalities are active.
5.2.3. ILP Example 3: Evolve a Problem from Small to Large Coefficients in the Constraints and Objective Function
The base problem ILP3 is to maximize
subject to
with integer variables
. This problem has three optimal solutions (1, 0, 5), (0, 1, 5) and (1, 2, 4) with
and is required to explore the following eight nodes to prove optimality—
BandB.py returns the solution within a second:
The values agree with those obtained with GAMS and GAMS/CPLEX. Note that as long all integer numbers are within the limits that GAMS/CPLEX can handle, i.e., , it is, of course, faster and more robust than BandB.py. But GAMS/CPLEX is only used herein to verify that BandB.py produces the correct results.
Variation 1 is the base problem ILP3 with a modified objective function
subject to the same constraints and, for instance,
. Ten nodes have been sufficient to proof the optimality of
with objective function
. Note that (0, 1, 5) is feasible but a zero variable has less of an effect for one of the
N’s in the objective function.
Variation 2 is the base problem ILP3 with the original objective function but modified inequalities
and, for instance,
. This time, six nodes have been sufficient to prove the optimality of
with the same objective function value
as in the base case. A value of up to
has also verified the solution with
GAMS/CPLEX. Beyond this value, the
GAMS/CPLEX solution becomes inexact.
Variation 3 is the base problem ILP3 with a modified objective function—
,
—and modified inequalities
subject to
producing—for
within a second and 12 nodes explored—the solution
and
. Note that this is identical to the analytic solution as it has the feasible region, but as
, one expects
. As for the Variation 2 problem, up to
has also verified the solution with
GAMS/CPLEX. Beyond this value, the
GAMS/CPLEX solution becomes inexact.
So, for these problems with only a few variables and constraints, BandB.py based on B&B using LP relaxation works fine and produces results within seconds.
5.2.4. ILP Example 4: Problem with Large Coefficients in Both the Objective Function and Constraints
With
the goal is to maximize
subject to
and
. To derive an analytic-closed form solution, note that (
37) can be divided by 90, leading to the inequality by
with
Now, (
38) is transformed into the equality
or
which allows us to apply a modified solution approach for solving linear Diophantine equations, i.e., (
39) is interpreted as a Diophantine equation in two integer variables
x and
y while the slack
v is treated as an integer parameter to be minimized (finding the maximum of
corresponds to finding the minimum of
v). The greatest common divisor (gcd) of
and
,
is not a divisor of
, which means that
is not a solution and that the Diophantine approach cannot directly be applied. Thus, finding the maximum of
corresponds to finding the minimum of
v. As (
39) is interpreted as a Diophantine equation in two integer variables
x and
y with a constant
, it suffices to find the largest
, which has
as a divisor:
Therefore, the minimum value of
v is 13717421, which corresponds to the minimum value
as the slack variable in the original equality
. Knowing the minimal
u, we construct two particular solutions of (
39), or the original equivalent, respectively.
The largest possible
x follows from setting
and observing
from which the optimal objective function value
follows. The largest possible
y follows from setting
and observing
leading to the non-optimal objective function value
To summarize, instead of maximizing
subject to
, the slack
u is minimized in the equation
The minimal
u occurs when
is maximized without exceeding
C. Then, a particular solution follows by setting
and maximize
x:
finding that it is optimal. The general solution for all triplets
is parameterized as
where
. Requiring that only non-negative solutions are accepted
there exist 92 optimal solutions (
to 91) with identical and minimal slack
achieved by the particular solution
, which is also the basis for a family of solutions
for
to 91.
These results were confirmed using the computer algebra system Xcas with its Maple-like input syntax close to Maple syntax, i.e.,
lpsolve(12345678901234567890*x+98765432109876543210y,
[12345678901234567890x+98765432109876543210y <= 123456789012345678901234567890],
assume=integer,maximize)
The solution of the LP relaxation (
) is returned within less than a second
with
However, if the integrality condition
is added, the Branch-and-Bound-based MILP solver in
Xcas would need about two hours to solve this problem and give the optimal solution
After modifying the integrality condition to
and adding the derived bounds
and
,
Xcas needed only minutes to come up with the result
which, however, violates (
37).
BandB.py is too simplistic to solve this case; within 24 h, it has not found an optimal solution but many integer-feasible solutions. It is interesting to see that the B&B algorithm produces feasible solutions moving from the first integer-feasible solution found
and
to
, and so on; each move requires three LP problems to be solved. This can be understood through the observation
i.e., from an integer-feasible solution one can always get to the next one by increasing
x by 8 and decreasing
y by 1. In fact, this problem is not very well suited for a B&B algorithm at all. Its is rather a problem about which combinations
produce the smallest slack in the inequality. Therefore, we programmed a complete enumeration to approach this problem starting at
and then increasing
x by 1 each time. The first optimal solution is found at node 13717418 with
and
as expected. Furthermore, Mathematica returned the solutions
and
with the correct optimal objective function value while Maple only came up with an infeasible point
and
.
5.2.5. ILP Example 5: Solving the Collatz ud Pattern Problem
Let us now apply
BandB.py to the MILP problem C1 presented in
Section 2.1:
The results for
to
obtained by
BandB.py agree with the analytic solution
and are summarized in the table below, which shows
, the number
N of nodes explored, and the CPU times
t used.
Two key observations emerge from
Table 1. First,
BandB.py based on B&B with LP relaxation is stable enough to handle this problem (for
, 11 integer variables and 10 equality constraints). Second, as
BandB.py in the current version lacks sophisticated presolving techniques as implemented, for instance, in
GAMS/CPLEX, it is too simplistic to solve this problem efficiently. The reason is that the lower bound for the objective function
moves up only very slowly. A brute-force approach enumerating all possible values of
and verifying the feasibility of all constraints would likely achieve comparable computational efficiency. Alternatively, Mathematica yielded the correct solution for
or
in less than a second;
produced the solution within 20 s.
5.3. Example 3: Bilinear Objective Function and Linear and Quadratic Constraints (MIQP)
Consider the following constrained quadratic mixed-integer optimization (MIQP) problem with very large integers (approximately 100 digits) starting with the continuous case in which the bilinear function
should be maximized subject to one linear and one quadratic inequality constraints:
The maximum occurs on the boundary of the feasible region. Consequently, two cases need to be considered:
Case 1: The maximum lies on the line
. The substitution
leads to
Taking the derivative and setting to zero,
Thus
and
This point is feasible only if
Case 2: The maximum lies on the circle
. By symmetry, the maximum occurs when
:
Thus
This point is feasible only if
Thus, the maximum value occurs at
or
At the boundary where
, both solutions coincide.
Consider now the mixed-integer case for maximizing
subject to
with
and
therefore yielding a mixed-integer quadratic programming problem.
Feasible domain integer bounds for
x follow from (42) and yield
Since
, we consider
and conduct a full enumeration on
x
i.e., for each fixed value of
x, a feasible value of
y needs to be found. For each integer
x,
y must satisfy
For each feasible integer
x, the objective function value is computed as
When
, the solution is in the linear-dominated region and follows as
which has the maximum at
or
.
When
, the solution is in the quadratic dominated region, i.e.,
with the maximum near
.
This leads to the Algorithm 2.
Algorithm 2 Optimize(N, M) |
1: xmax <– min(floor(N), floor(sqrt(M)) 2: zmax <– 0 3: for x = 0 to xmax do 4: y <– min(N-x, sqrt(M-x2)) 5: if xy > zmax then 6: (x*, y*, zmax) <– (x, y, xy) 7: return (x*, y*, zmax) |
This is illustrated for the small number example
,
:
The maximum occurs at integer
x closest to
when the linear constraint dominates, and
when the quadratic constraint dominates. Computing the optimal solution requires full enumeration of feasible
x values. This generalizes the continuous solution to the integer case.
For the example data
and
, our Python program finds the optimal solution
and
yielding the maximal objective function value
z = 249999999999999999999999999999998544665304299
1170386487993513416619233679558726642285401256891514880.0
6. Conclusions and Outlook
We have constructed partial sequences of the Collatz sequence increasing for various patterns ud, ududd, ududududdd, etc.—and repeatedly increase for any fixed natural number J. With growing J, this quickly leads to large-number optimization. Beyond the limits of for integers supported by commercial MILP solvers, Diophantine systems of equations and modular arithmetic have been used to derive analytic or semi-analytic solutions.
In addition, we have developed Python and Fortran code to solve exactly linear programming, binary linear programming, and integer linear programming problems with not too many variables or constraints, suitable to provide exact solutions for large-number optimization problems. To test the correctness of the programs, nine small specifically constructed examples [LP1-3, ILP1-5 and one mixed-integer quadratic programming problem (MIQP)] are used (analytical analytic optimal solutions have been derived). Unless otherwise reported, the computing times were on the order of seconds, and the results agreed with the expected analytical solutions. These test examples can serve as basic benchmarks or a test suite for other researchers. While the algorithms themselves have the same computational complexity and scale as their normal-number counterparts, the overhead for exact arithmetic and large numbers limits their current implementations to small and, at best, medium-sized problems. The scalability trends observed in the Collatz MILP example (
Table 1) illustrate this effect concretely, as both the number of explored nodes and the CPU time increase rapidly with growing size of the decision variables. In practice, the sensitivity to input size becomes evident even in small test cases: as the number of digits or coefficients increases, runtimes and memory usage grow sharply due to the overhead of exact arithmetic. Although the underlying algorithms maintain the same asymptotic complexity as their fixed-precision counterparts, the constant factors introduced by large-number operations dominate. This explains why the current implementations remain limited to small and medium-scale instances, while pointing to the need for future advances in algorithm engineering and data structures to address scalability.
Specialized algorithms or their development for mathematical optimization and large numbers can be justified in special situations. General algorithms or their development for large-number optimization is more difficult to justify as in many cases it can be easier to program simple algorithms in Python, C, or Fortran or to use computer algebra systems (although computer algebra systems are not specifically designed for optimization problems, Mathematica is always a valuable tool to explore). However, one can argue that generic exact large-number LP and ILP solvers allow us to explore further problems that appear interesting to us.
Python’s capabilities for handling large numbers and exact-fraction arithmetic are robust, making it well suited for solving small- and medium-sized problems involving large numbers, which correspond closely to the problem characteristics considered in this study. Unlike many programming languages that impose fixed-size integer limits, Python’s built-in ‘int’ type supports arbitrary precision, constrained only by available memory, although extremely large numbers require substantial memory. The current work (version 28 September 2025) is the beginning of large-number optimization (see the GitHub repository:
https://github.com/JosefKallrath/Large-number-optimization (accessed on 28 September 2025)), and hopefully this will lead to the creation of a library approach that covers a wider range of problems, for instance, prime programming problems. Given our exact B&B solver for large numbers at hand, the plan is to extend the B&B logic to prime numbers, i.e., instead of numbers to be integers, they are enforced to be prime numbers—this would enable us to solve also prime programming problems for large numbers. An important improvement is to simplify problem coding, ideally by employing a
GAMS-type syntax enhanced to support large numbers.