I am interested in approximating positive integers with numbers in the form $N=2^a3^b$ where $a,b\in\mathbb{Z}$. For example, let's say that we want to approximate $143=11\times13$. We have,
$$2^a3^b\approx11\times13\Rightarrow a\log(2)+b\log(3)=\log(11)+\log(13)$$
$$a\log(2)+b\log(3)-\log(11)-\log(13)=0$$
The $\log p_1,\dots,\log p_t$ is linearly independent over $\mathbb{Q}$ (see), so obviously we cannot determine $a,b$ to have the above equation. I'm wondering if it is possible to optimize $a$ and $b$ to minimize the absolute error between $2^a3^b$ and $143$. Furthermore, I would be glad to solve this optimization problem in general case. In general, the problem can be stated in the form related to linear combination of the logarithm functions:
$$a \log (2) + b \log (3) + n_1\log(p_1)+n_2\log(p_2)+\cdots + n_k \log (p_k) = 0 $$
where the integers $n_1,\ldots,n_k$ and the prime numbers $p_1,\ldots,p_k$ are given and we want to optimize the integers $a$ and $b$.
I used a python script for $2^a\times 3^b\approx 143$ and the result was not so good. I looped over $a,b\in\{-10^6,\ldots,10^6\}$ and after about $35$ minutes of running, I got only two results for $|2^a3^b-143|<0.1$:
\begin{array}{|c|c|c|}
\hline
a & b & \text{Error} \\
\hline
825 & -516 & 0.05170246118419186 \\
-229 & 149 & 0.04546204418605271 \\
\hline
\end{array}
The python script:
from numba import njit, prange
@njit(parallel=True)
def fn():
for a in prange(-1000000, 1000001):
i_a = 2.0a
for b in prange(-1000000, 1000001):
i_b = i_a * 3.0b
v = i_b - 143.0
if abs(v) <= 1e-01:
print(
"a=",
a,
", b=",
b,
", error=",
abs(v),
)
fn()
0orinfbeing assigned toi_ain your code. – Daniel Mathias Oct 13 '24 at 13:59