I've got now an algorithm which reproduces perfectly the lengthes for (only odd so far) $N $ from $1$ to $49$ as given by @HandeBruijn in his answer.
Real efficiency occurs, if the heuristics from small cases $N$ extend to larger values as well, that - when a solution with small set of small parameters is found - , no better solutions (in terms of length) shall occur.
I'll give my Pari/GP code below.
To understand the rationale I'll refer to my first answer, reducing the notation to a smaller vectorial notation.
1) For instance in 3 = 2*2*2*2/3*2/3 (#6)
I read from right and count, after each /3
term, the *2
terms and simply store that in a vector, arriving at
$ 3 = T(1; [1,4])$ meaning that beginning at $a_0=1$ we have a term of $2^4$ and then one of $2^1$, separated by $/3$-terms, giving:
$$ T([1,4])=3 \qquad \to \qquad 1 \cdot 2^4 /3 \cdot 2^1 /3 = 3 \tag 1$$
Here, to save notation, I omit the leading "$(1;$"-argument in the $T()$-notation assuming it to be the default in the following.
Note that the length in my expression is the sum of the exponents at $2$ (call it $S$) plus the number of divisions by $3$ (call in $N$) which means $\lambda(3)=(1+4) + 2=7$ while Han de Bruijn gives here one less as (#6)
, let's call it $\beta$ with $\beta(x)=\lambda(x)-1$.
Another example, 27 = 2*2*2*2/3*2*2*2*2*2*2*2/3/3*2/3*2/3*2*2/3*2/3 (#22)
.
My notation looks like
$$ T([1,2,1,1,0,7,4])=27 \qquad \to \qquad 1 \cdot 2^4 /3 \cdot 2^7 /3 \cdot 2^0 /3 \cdots = 27 \tag 2
$$
2) But an even more parsimony notation occurs as possible, when we think in reverse: we deconstruct $a_0=3$ by inverting the $/3$ and the $ \cdot 2^A$ operations.
The reverse of $y = x /3 $ is here underdetermined, we have $x_k = y \cdot 3 + \{0,1,2\}_k$ , that means $3$ solutions. We can then write the example of $a_0=3$ by
$$ U(3;[1,1])=1 \qquad \to \qquad {{3 \cdot 3 +1 \over 2^1} \cdot 3+1\over 2^4}=1
\tag 3$$
The vector $[1,1]$ is here the vector of residues $\pmod 3$ , let's call it $R$ and write $R=[1,1]$ and the $k$'th residue as $r_k = R[k]$
Note that we introduce here two remarkable restrictions:
- the ininital value $a_{k-1}$ is assumed to be odd (let's implement the routine for the even numbers later) and
- the exponent $A_k$ at $2$ is that value that $ a_{k}={a_{k-1} \cdot 3+ r_k \over 2^{A_k}}$ is odd (that simply means $A_k= \nu_2(a_{k-1} \cdot 3+ r_k)$ where $\nu_2()$ is the 2-adic valuation).
It is noteworthy that if all $r_k=1$ we have simply the Collatz-transformation in the "syracuse"-style. But we do not wat to restrict ourselves to $r_k=1$ only but allow $r_k \in \{0,1,2\}$ as well.
Let's see, how this looks for $a_0=25$ . The coding in the OP's notation is 25 = 2*2*2*2*2*2*2*2/3*2*2/3*2/3/3
Constructing first the $A$-vector notation we get $A=[0,1,2,8]$ and $T(1;A)=25$ . So we have $4$ integer divisions by $3$, which means in reverse, $4$ multiplications by $3$ each with residue $r_k$ to be determined. First, from $A_1=0$ follows, that $r_1 \in \{0,2\}$ because the numerator in $ {a_{k-1} \cdot 3+ r_k \over 2^0}$ must be odd and since $a_{k-1}$ is odd by definition $r_k \in \{0,2\}$ must be even. In reverse, for all $A_k \gt 0$ we need to have $r_k=1$ and have thus one step of the Collatz/Syracuse-transformation. For $a_0=25$ it comes out that $A=[0,1,2,8]$ and $R=[0,1,1,1]$ so $U(25;R)=1$ is a solution with $\lambda(25)=15$.
Let us as well introduce the notation of $\rho=4$ for the length of the $R$ (resp. $A$)-vector.
Caution: that found solution is likely in most cases not unique, as we can simply see when we look at the big table in my other answer: the same value $a$ occurs repeatedly in the table thus the coding of any $a$ into a $T()$ or a $U()$-transformations is not unique.
3) This makes a search-routine meaningful.
We take $a_0=25$ as initial value.
We begin with $\rho=1$ and test $U(a_0;R)\overset?=1 $ with $R=[0]$,$R=[1]$,$R=[2]$. We get no solutions.
$\rho=2$ and test with $R=R_{2,j}=[[0,0],[0,1],[0,2],[1,0],[1,1],...[2,1],[2,2]]_j$ . Again, no solutions. Next:
$\rho=3$ and test with $R=R_{3,j}=[[0,0,0],[0,0,1],...[2,2,1],[2,2,2]]_j$ . Again, no solutions.
And so on. With $\rho=4$ we get solution(s) and can proceed to arbitrary $\rho$.
Time consumption is exponentially growing, so up to $\rho=10$ is easy for modern computer (say, $2$ secs) but up to $\rho=16$ needs already a lot of seconds.
However, heuristics suggest two strong reductions of the searchspace.
- it seems, there are solutions containg $r_k=2$ only if there are solutions $r_k \in \{0,1\}$ with same $\rho$ and $\lambda$ already, so actually we need only test $R$ containing $r_k \in \{0,1\}$
- it seems, after a short solution with a certain $\rho$ and $\lambda_1$ has been found, no shorter solution with $\lambda_k \lt \lambda_1$ occurs.
Example:
$\rho=4$, $\lambda=15$:
25 15 4 \\ a0, lambda, rho
a1vec=[25, 75, 113, 85, 1]
R=[0, 1, 1, 1]
A=[0, 1, 2, 8]
25 15 4
a1vec=[25, 75, 113, 341, 1]
R=[0, 1, 2, 1] \\ r_3=2 occur at the same rho & lambda
A=[0, 1, 0, 10]
25 15 4
a1vec=[25, 75, 227, 341, 1]
R=[0, 2, 1, 1] \\ r_2=2 occur at the same rho & lambda
A=[0, 0, 1, 10]
$\rho=7$, $\lambda=23$: (non optimal solution : $\lambda \gt 15$)
25 23 7
a1vec=[25, 19, 29, 11, 17, 13, 5, 1]
R=[1, 1, 1, 1, 1, 1, 1]
A=[2, 1, 3, 1, 2, 3, 4]
25 23 7
a1vec=[25, 19, 29, 11, 17, 53, 5, 1]
R=[1, 1, 1, 1, 2, 1, 1]
A=[2, 1, 3, 1, 0, 5, 4]
... (some more solutions with same rho, lambda)
$\rho=9$, $\lambda=28$: (non optimal solution : $\lambda \gt 15$)
25 28 9
a1vec=[25, 19, 57, 43, 65, 49, 37, 7, 21, 1]
R=[1, 0, 1, 1, 1, 1, 1, 0, 1]
A=[2, 0, 2, 1, 2, 2, 4, 0, 6]
25 28 9
a1vec=[25, 19, 57, 43, 65, 49, 37, 113, 85, 1]
R=[1, 0, 1, 1, 1, 1, 2, 1, 1]
A=[2, 0, 2, 1, 2, 2, 0, 2, 8]
... (a lot more solutions with same rho, lambda)
$\rho=10$, $\lambda=31$: (non optimal solution : $\lambda \gt 15$)
remarkable: all $r_k \in \{1,2\}$, no $r_k=0$ !
25 31 10
a1vec=[25, 19, 29, 11, 17, 13, 5, 17, 13, 5, 1]
R=[1, 1, 1, 1, 1, 1, 2, 1, 1, 1]
A=[2, 1, 3, 1, 2, 3, 0, 2, 3, 4]
... (some more solutions with same rho, lambda)
$\rho=12$, $\lambda=36$: (non optimal solution : $\lambda \gt 15$)
25 36 12
a1vec=[25, 19, 57, 43, 65, 49, 37, 7, 11, 17, 13, 5, 1]
R=[1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
A=[2, 0, 2, 1, 2, 2, 4, 1, 1, 2, 3, 4]
25 36 12
a1vec=[25, 19, 57, 43, 65, 49, 37, 7, 11, 17, 53, 5, 1]
R=[1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1]
A=[2, 0, 2, 1, 2, 2, 4, 1, 1, 0, 5, 4]
... (a lot more solutions with same rho, lambda)
While the first heuristic is already surprising, the latter heuristic is really astonishing and should either be improved or be dealt with attempts of proving or disproving.
4) In my code I use that heuristics, and jump out from the two innermost loops once a solution is found. This code-line, however, can simply be commented-out if the heuristics should be improved.
\\ flgs: 1 - use residues 0,1 only
\\ 2 - print only running minimal lambda
\\ 4 - find only first solution
\\ 8 - print only short docu
{docsolutions(a0,maxrho=12,flgs=1+4)=my(lambda,rho,minlambda, minlambdarho,Rvectors,a1,a1vec,S,A,Avec,r,rrng);
if( bittest(flgs,0), rrng=[0,1], rrng=[0,2]);
minlambda=999;
for(rho=1,maxrho,
Rvectors=vector(rho,j,rrng);
minlambdarho=999;
forvec(R=Rvectors,
a1vec=vector(rho+1);a1vec[1]=a0;
Avec=vector(rho);
S=0;
a1=a0;
for(j=1,rho,
r=R[j];
a1=3*a1+r;
A=valuation(a1,2);
a1>>=A;
Avec[j]=A;
S+=A;
a1vec[1+j]=a1;
if(a1==1,break())
);
if(a1<>1,next()); \\ test did not converge to 1
if(a1vec[1+rho]==0,next()); \\ test has converged to solution with
\\ smaller rho
lambda=S+rho;
if(bittest(flgs,1),if(lambda>=minlambdarho,next()));
minlambdarho=lambda;
print(a0," ",lambda," ",rho); \\ for compatibility with HdB lambda-1
if(!bittest(flgs,3),
print(" a1vec=",a1vec);
print(" R=",R);
print(" A=",Avec);
);
if(bittest(flgs,2),break(2)); \\ assuming the first solution is the best
\\ don't test any further
);\\ end forvec(R=...
); \\ end for(rho=...
}
Perform tests:
docsolutions(25,10,1+2) \\ runs short test up to rho=10
Some more protocol, with appended time-consumption in milliseconds:
gettime();docsolutions(25,10,2+8);gettime()
\ a0 lambda rho ++ note:lambda is length+1 from Han de Bruijn-doku
25 15 4
25 23 7
25 28 9
25 31 10
%9 = 6536
gettime();docsolutions(25,10,1+2+8);gettime()
\ a0 lambda rho
25 15 4
25 23 7
25 28 9
%10 = 125
gettime();docsolutions(25,10,1+4+8);gettime()
\ a0 lambda rho
25 15 4
%11 = 0
a0=1093
gettime();docsolutions(a0,10,2+8);gettime()
\ a0 lambda rho
1093 31 8
1093 36 10
%13 = 6661
gettime();docsolutions(a0,10,1+2+8);gettime()
\ a0 lambda rho
1093 31 8
1093 36 10
%14 = 125
gettime();docsolutions(a0,10,1+4+8);gettime()
\ a0 lambda rho
1093 31 8
%15 = 31
\ use higher rho / greater length for composition
gettime();docsolutions(a0,12,1+2+8);gettime()
\ a0 lambda rho
1093 31 8
1093 36 10
%16 = 671
gettime();docsolutions(a0,14,1+2+8);gettime()
\ a0 lambda rho
1093 31 8
1093 36 10
1093 44 13
%17 = 3276
gettime();docsolutions(a0,16,1+2+8);gettime()
\ a0 lambda rho
1093 31 8
1093 36 10
1093 44 13
1093 49 15
%18 = 15117
The check for $a=\{3,5,7,...,499\}$ as the following
gettime(); forstep(a0=3,499,2,docsolutions(a0,16,1+4+8)); Str(gettime(),"msecs")
\\a0 l rho a0 l rho a0 l rho a0 l rho a0 l rho
3 7 2 5 5 1 7 8 2 9 11 3
11 14 4 13 9 2 15 17 5 17 12 3 19 20 6
21 7 1 23 15 4 25 15 4 27 23 7 29 18 5
31 18 5 33 18 5 35 13 3 37 13 3 39 21 6
41 21 6
....
481 40 12 483 22 5 485 35 10 487 35 10 489 40 12
491 40 12 493 22 5 495 40 12 497 22 5 499 40 12
"27799 msecs"
needed 28 secs
$$c = \frac{log(N/floor(2^a/3^b))}{log(2)}$$
P/S: Like @Ross Millikan, I am not sure if it is optimum too
– Xeing Jan 02 '14 at 16:18$$3^bN \le 2^a2^c<3^b(N+1)$$
$$3^bN \le 2^d<3^b(N+1)$$
$$log(N 3^b)/log(2) \le d < log((N + 1) 3^b)/log(2)$$
– yugikaiba Jan 10 '21 at 00:25If $N=2^c$ then it just take $a=2,b=1$ so that $[{2^a\over 3^b}]=1$. – Sam Jan 10 '21 at 00:45