10

How can I create a given postitive integer $N$ by multi by $2$ and divide by $3$ (integer part) ?

(Write a computer program is allowed) For example: $$100 = 2*2*2*2*2*2*2*2*2*2*2/3/3/3/3*2*2$$

(The numbers of $2, 3$ need to be minimum)

($/3$ mean $\text{div}\ 3$, eg: $2/3 = 0, 4/3 = 1...$)

Is solving equation

$$\left \lfloor{\frac {2^a}{3^b} }\right \rfloor *2^c = N$$ help ?


If it help then, how to solve $$\left \lfloor{\frac {2^a}{3^b} }\right \rfloor *2^c = N$$

such that $a > c, a+b+c$ is minimum.

  • Is it possible to use brackets? – Constructor Jan 02 '14 at 09:39
  • @Constructor No – user118662 Jan 02 '14 at 09:47
  • Note that:

    $$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
  • 1
    First write $100$ as a product of prime numbers: $100 = 5522$. Then it's easy to find the simpler results: $5 = 2222/3$ and $2=2$. Giving: $100 = 2222/3 2222/3 2 * 2$ , which is more dense than the example in the question. Have no idea if the numbers of $2,3$ are a minimum with this approach. – Han de Bruijn Jan 04 '14 at 12:41
  • 1
    Note that the reverse question has sense as well: write $100$ as a multiplication of $3$'s and an integer division of $2$'s: $100 = 3333/2/2/2/2 3333/2/2/2/2 33/2/2 33/2/2$. Done again with the prime factors in: $100 = 5522$. – Han de Bruijn Jan 04 '14 at 12:47
  • @HandeBruijn I believe your decompositions are for a different question than the one asked. It seems the stated question only lets you divide by three in one single block, not separating them optimally like you do in your example. This is specially relevant since I've seen you're the one that has put the bounty. As the question is stated, I believe the algorithm of Ross Millikan checking for all possible $c$ is more than enough. – AnilCh Jan 08 '21 at 15:04
  • We need $23$ steps to create the number $27>$! Starting with $1$ the operations are $222232>222222>332323>22323$, where a $2$ means $\cdot2$ and a $3$ means $/3$. – Christian Blatter Jan 08 '21 at 16:19
  • 1
    @ACheca. No. It's safe to suppose that most users think different about it. See e.g. the comment by Christian Blatter (which is of course entirely correct). If one wants to do the same according to your scheme, then we may have, for example: $27 = 2^{46}/3^{26}$. Resulting in $45+26=71$ operations instead of the $27$ by Christian Blatter. Since the question is not quite explicit concerning this issue, it's up to me to decide that the BOUNTY is for a minimum number of operations, regardless of any "blocking". – Han de Bruijn Jan 09 '21 at 15:50
  • The condition is a > c or a=b? – yugikaiba Jan 10 '21 at 00:08
  • This is integer programming you will need a computer and it will take probably exponential time since it's at least NP-hard.

    $$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:25
  • You will need to check if there is an integer d for each N that you input and $\forall$ b $\in$ N – yugikaiba Jan 10 '21 at 00:27
  • If you don't give importance to the condition $a>c$ then I have found my way. But if that condition is important then it will not work.
    If $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
  • 2
    I think it's wise to restrict attention to odd numbers only, because all even numbers are constructed trivially by multiplying the former with a power of two. Then we only have to answer the first half of the question and get rid of the rather uninteresting $2^c$ and $c$. Furthermore, I think it can safely be assumed that solving an equation $\left \lfloor 2^a/3^b \right \rfloor 2^c = N$ does indeed not help: see my comment about $27 = 2^{46}/3^{26}$, in comparison with the far more dense $27 = 2^4/32^7/3/32/32/322/3*2/3$. – Han de Bruijn Jan 10 '21 at 16:32
  • 1
    Is it obvious that any number may be written this way? And then, that the shortest decomposition is not necessarily unique? For instance, 27 has decompositions 22222322222222333222333 and 22223222222233232322323, both of length 23 which is minimal, if I am correct. – Matthieu Latapy Jan 12 '21 at 12:53
  • 1
    @MatthieuLatapy - well, my algorithm is a restricted brute force, and for every number it did find multi-, sometimes multi-multi-decompositions, and even for the same $\rho$ (number of divisions of 3) and $\lambda$ (number of all operations) it found multiple solutions, too many to document them here. $a=25$ with $\rho=12$ (12 divisions by 3) and $\lambda=36$ ($36$ operations overall), it found about $256$ variants. – Gottfried Helms Jan 12 '21 at 16:28
  • 1
    @MatthieuLatapy see my comment under Gottfried Helms answer for an argument why every number has indeed a decomposition. There are infinite, actually. – AnilCh Jan 13 '21 at 07:28
  • @MatthieuLatapy. Yes, $27$ has many decompositions with an optimal length of $23$, to be precise: $716$ of them. – Han de Bruijn Jan 13 '21 at 15:38
  • 1
    It's impossible for me to judge which of the answers - given after rise of the bounty - is the best. I hope that all active participants have enjoyed commenting and answering the question, like I did. Instead of tossing a coin, I decided to award the 100+ to the person with most short of reputation. – Han de Bruijn Jan 13 '21 at 16:10
  • Haha, thank you Han! I am not sure it is fair, but I do appreciate the 100 points :) Anyway, exploring this topic with you all was very interesting, and may be continued! – Matthieu Latapy Jan 13 '21 at 16:24
  • It was a nice challenge and I'm still on it. There is something in it for me worth to exercise: building a route towards proof, (at the moment for the "strictly-decreasing" method), and to re-activate my programming skills of earlier years to recursive solutions. Maybe I can make my proof as well as the recursive solution available soon. The problem of assigning a bounty to which answer is sometimes NP-complex, as well as the mathematical problem itself, so ... ;-) – Gottfried Helms Jan 14 '21 at 09:25
  • I posted an extended version of this question on MathOverflow, with the hope to get more insight: https://mathoverflow.net/questions/383675/integer-decompositions-into-products-by-2-and-integer-division-by-3 – Matthieu Latapy Feb 11 '21 at 02:54

6 Answers6

2

I hope I did not miss it somewhere in the many wonderful comments and partial answers above, but did you try a brute-force forward approach?

For instance, the following python lines:

from collections import deque

Q = deque([(2,"2")]) seen = {} consecutive=-1

def eval(s): # to check results i=0 resu=1 while i<len(s): if s[i]=='2': resu *= 2 else: resu /= 3 i+=1 return(resu)

while True: (x,s) = Q.popleft() if x not in seen: seen[x] = s Q.append((x*2,s+"2")) Q.append((int(x/3),s+"3")) while x==consecutive+1 and x in seen: assert(x==eval(seen[x])) print x,seen[x] consecutive+=1 seen[x]="" # to save space x += 1

enumerate all possible solutions in increasing length order, and output them in increasing value order, if I am correct.

It reaches 1434 in seconds on my laptop, and then get stuck (because of memory limitations, I think, and because 1435 has a significantly longer decomposition). It goes above 2400 in minutes on my server with more memory, then gets stuck for a while, then goes above 4400, then gets stuck.

BTW, it finds a decompositions, but there may be several decompositions of same, minimal length.

Once this minimal length is known for a given number $N$, another brute-force approach consists in sampling random decompositions of this length and check if they are decompositions of $N$. For instance, after establishing with Gottfried (see comments) that the shortest decompositions of 4535 have length 77, I sampled 20 billions decompositions (in a few minutes) and obtained the following decompositions of 4535:

22222322223323222232222232323322223222232222222223222233322233233223333222233
22222322232232322232232222323232222322232232222223232233222233222233222333233
22223222322232322232232222322232232232322232222222333223322233232223322322233

They were obtained only once each, suggesting that there are many more solutions, and is consistent with the fact that we are far from sampling all $2^{77} > 10^{23}$ possible decompositions.

This is a terrible waste of computational resources, of course!

  • 1
    My just posted answer has a program which implements a brute force approach, however restricted up to a highest number of /3steps (my parameter rho) . For the full brute force the flags in docsolutions() must be set to zero. – Gottfried Helms Jan 12 '21 at 12:10
  • 1
    The collatz-transformation should give an upper limit for the trajectory-length (or: number of *2and \3) I get for $a=1435$ the value $\rho=26$ in my notation and $\lambda=78$ Having $\rho=26$ my algorithm has really to chew... To work one time to $\rho=16$ alone needs a couple of seconds, and the searchspace grows exponentially with linearly increasing $\rho$, so ... I'm waiting on the result of my program... ;-) – Gottfried Helms Jan 12 '21 at 12:39
  • 1
    Ok, 260 seconds for searching with $\rho=16..26$ ... The first found trajectory is [1435, 4305, 12915, 38745, 116235, 174353, 130765, 49037, 18389, 431, 1293, 485, 91, 273, 205, 77, 29, 11, 17, 13, 5, 1] with $\rho=21$ and $\lambda=65$ and vector of exponents $A=[0, 0, 0, 0, 1, 2, 3, 3, 7, 0, 3, 4, 0, 2, 3, 3, 3, 1, 2, 3, 4]$ and vector of residues $R=[0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]$ (see my second posting) – Gottfried Helms Jan 12 '21 at 12:43
  • Do you find any decomposition of 4535? It must be of length at least 76, whereas all numbers lower than it have a decomposition of length no longer than 71, according to my code. – Matthieu Latapy Jan 12 '21 at 13:51
  • 1
    Hmm, currently my program is busy rigidly full searching alternative decompositions of 1435 ... – Gottfried Helms Jan 12 '21 at 14:10
  • 4535 has decomposition 22222322222333222232222222333232222222222222222222333333333322232222333222233 (length 77, probably the shortest one) ; thank you Alexis! – Matthieu Latapy Jan 12 '21 at 14:38
  • 1
    Matthieu - confirmed! I used the "strictly-decreasing" -method mentioned in my first answer (in "update1"). Unfortunately I saw that "strictly decreasing" does not always give the optimal length (thus my (restricted) brute-force attempt in my 2nd answer - but this is extremely timeconsuming with this initial number and thus practically worthless for numbers with $\rho>20$) – Gottfried Helms Jan 12 '21 at 20:07
  • 2
    Great! That's a crazy, addictive problem! Thanks Han for driving our attention to it :) – Matthieu Latapy Jan 12 '21 at 20:14
  • 1
    The number $4535$ is beyond my current resources, while the numbers $4530 \cdots 4534 , 4536 \cdots 4538$ all have an optimal $25$ operations. – Han de Bruijn Jan 13 '21 at 15:51
  • 1
    Matthieu - while my confirmation confirms $ #(4535)=77$ I was not correct in that the sequences of $2$,$3$ are equal. It is difficult to follow that sequences and compare correctly. But we can see the differences more easily when we look only at the convergents at ends of pairs $222...2;;333...3 $. Your and my decompositions compared give the trajectory $$ your: [1, 10, 11, 58, 274, 182, 1615, 4306, 2551, 4535] \ mine: [1, 5, 11, 29, 77, 91, 511, 1211, 1435, 2551, 4535] $$. The second trajectory (mine) shows the "strictly decreasing" property (when read from left). How did you found yours? – Gottfried Helms Jan 14 '21 at 12:19
  • Gottfried, I used the greedy approach described in my "answer": just generating sequences of increasing length. It just happens to be the first one it finds. Does this help? – Matthieu Latapy Jan 14 '21 at 12:40
  • 1
    Matthieu - ah, yes. I thought about that "increasing-length" algo, but simply did not yet attempt to program it. I'd be curious, whether "increasing-length" and "strictly-decreasing" could give examples with different lengthes (different decompositions (or trajectories) are at least now known, of course). While my (nearly) brute force algo could not manage the full course from $4535 \to 1$ I checked the optimality of three consecutive partial-trajectories $4535 \to 575 \to 77 \to 1$: all partial-trajectories at least are optimal. – Gottfried Helms Jan 14 '21 at 15:02
  • 1
    @GottfriedHelms, Han, I added another brute-force approach to my answer above, based on random sampling, and able to find more decompositions of 4535. – Matthieu Latapy Jan 15 '21 at 11:42
  • Matthieu - I thought of reducing the search space for the brute-force. One argument is of course, that the number $e_2$ (counting the *2 operations) must be balanced by the number $e_3$ (counting the /3 operations) combined with the $\log_3()$ of the target number, so we need not to look at decompositions like 1*2*2*2*...*2 and for the same reason not at /3/3/3.../3. Well, this reduces a stringlength of $77$ (giving $2^{77}$ decompositions to test) not yet to nicely small numbers, but considerations of this type might be extended to more and more sophisticated rules. – Gottfried Helms Jan 15 '21 at 12:40
1

What I'm trying is this.

We go the inverse way; starting on value $w_0=N$ and then $w_1=w_0/2^{\nu_2(w_0) }$.

After that, possibly one of $\{3w_1,3w_1+1,3w_1+2\}$ is a perfect power of $2$. If it is, we've solved the problem.

If not, possibly one of $ 3^2 \cdot w_1 +\{0,1,2,3,4,5,6,7,8\}$ is a perfect power of $2$ . If yes, then we've solved the problem.

If not, possibly one of $ 3^3 \cdot w_1 +\{0,1,\ldots,3^3-1\}$ is a perfect power of $2$.

We can proceed the obvious way.

  • For $N=w_0=100$ I got $2^{A_1}=4$ so $A_1=2$ and $w_1=25$
    Then in the interval $25\cdot 3 \to 75+\{0,1,2\}$ there is no perfect power of $2$
    Then in the interval $25 \cdot 3^2 \to 225+\{0,1,...,8\}$ there is no perfect power of $2$
    Then in the interval $25 \cdot 3^3 \to 675+\{0,1,...,26\}$ there is no perfect power of $2$

    Then in the interval $25 \cdot 3^4 \to 2025+\{0,1,...,80\}$ there is a perfect power of $2$ (namely $2^{11}$and we have the solution (which was already given by the OP):

    $ \qquad \qquad 1 \cdot 2^{11} \backslash 3 \backslash 3\backslash 3\backslash 3 \cdot 2^2 = N (= 100)$
    where "$\backslash$" means integer division and we proceed from left to right without compacting the integer-divisions.

However, I didn't attempt yet to find out, whether this is an optimal solution in any way...


For instance, using $w_1=25$ gives $4$ steps of multiplication by $3$ (inlcusive the residue correction) but it we use $w_1=w_0=100$ then I needed $57$ multiplications by $3$ (inclusive the residue corrections). So there are clearly optimality criteria to define/satisfy.


update1
I found it interesting, that a simple restriction is then equivalent with the Collatz-transformation. If we throw away the requirement that in the listed example we do not increase the exponent at 3 until a perfect power of 2 occurs in the interval $25*3^k + \{0,1,2,...,3^k-1\}$ but instead at a occuring even number (at odd residue) we remove the even factor and then proceed taking that value for iteration, we simply have the $(3a+1)/2^A$-transformation, and we could use the orbit of that transformation as upper limit for the optimal length, giving a basic normalization of the representation of a number.

As a perhaps more interesting option I looked at another restriction:
In the example check the intervals using $N=25$ again:
$$ 25\cdot 3 \to w_{1,k}=75+\{1\}_k \\ 25 \cdot 3^2 \to w_{2,k}=225+\{1,3,...,7\}_k \\ 25 \cdot 3^3 \to w_{3,k}=675+\{1,3,...,25\}_k \\ \vdots \\ 25 \cdot 3^e \to w_{e,k}=25 \cdot 3^e +\{1,3,...,3^e-2\}_k $$ Test the even numbers $w_{e,k}=2^j \cdot r_k$ (= remove the even prime factor $2^j$) along increasing $e$ and $k$ until first time $r_{k}<25$. And iterate, until we arrive at $r_k=1$.
This gives a trajectory of strictly decreasing intermediate values, being another candidate for the normalization. Unfortunately this way needs sometimes even more steps of the basic operation than using the $3a+1$-rule, so again this method does not always produce an optimal (shortest) representation of some $N$. However, it seems an interesting question to prove, that such a rule is always applicable at all, leading towards $1$.

To get a better overview in the possibilities of finding an optimal representation the following picture :
picture

Here we may start at the left column, with some power of 2, and walk right for the $ /3$ steps, until $2$ or $1$ occurs. If we assume, that this process covers all natural numbers, it might be the best strategy for getting a shortest trajectory for any number $N$. If we count the steps down and then steps right towards some number $N$ as length of the trajectory, it seems that lengthes towards some duplicates (for some small $N$ visible in the more rightpart and colored orange) are always longer. To help intuition I placed duplicate indicator lines for the values $N=8$ and $N=42$ in the picture.

For the question of whether all numbers are covered by this scheme I brute force sorted all occuring intermediate values smaller than $1000$ and using the first $120$ rows of the table I got the following list of occuring numbers $N$ (the smaller part of them occur multiple times):

    0    1    2    3    4    5    6    7    8    9
   10   11   12   13   14   15   16   17   18   19
   20   21   22   23   24   25   26   27   28   29
   30   31   32   33   34   35   36   37   38   39
   40   41   42   43   44   45   46   47   48   49
   50   51   52   53   54   55   56   57   58   59
   60   61   62   63   64   65   66   67   68   69
   70   71   72   73   74   75   76   77   78   79
   80   81   83   84   85   86   87   88   89   90
   92   93   94   95   97   98   99  100  101  102
  103  105  106  107  109  110  112  113  115  116
  118  119  121  122  124  126  127  128  129  131
  132  133  134  136  138  140  141  142  143  145
  147  149  151  153  155  157  159  161  163  166
  168  170  172  174  177  179  181  184  186  189
  191  194  196  199  201  202  204  207  210  212

But I think it is not too difficult to prove that the infinite table indeed covers all natural numbers.


Looking at the solutions in @HandeBruijns's answer, for instance $N=11$, he has a much better/shorter representation. Applying the principle of my scheme to them, for instance for $N=11$ I can make this route:
picture2
and it indicates, that likely we need the look to the right of the table far more than possible in the image of that small segment of the first table.

  • 1
    Actually, due to rule 4 and rule 9 in my answer, all of the representations presented there are provable the best possible. It takes quite some computer resources to find them, though. I've managed to make a contiguous sequence up to 90 now - it's on my website - but I had minutes to wait for an outcome! BTW, unfortunately, I can give you no more than one upvote (+1). – Han de Bruijn Jan 11 '21 at 19:28
  • @HandeBruijn - "there are provable the best possible": ah, this is interesting. I didn't yet stepped in for some proofs like that (because meaningful programming for finding heuristics takes all energy so far), but had such workouts in mind. I'll take a look at your website; thanks for your comment! – Gottfried Helms Jan 11 '21 at 19:49
  • @HandeBruijn: Just to compare: my routine checks for odd $N$ from $1$ up to $15$ divisions by $3$ (plus the according powers of 2), thus making (restricted) brute force. For odd $N=3..199$ I needed $680$ secs in Pari/GP. Allowing at most $8$ divisions by $3$ it needed $3$ secs (but missing convergences to $1$ for some initial $N$). Allowing $12$ divisions it needed $65$ secs, and found converging solutions for all odd $N$. Don't know whether my procedure is of interest for you? – Gottfried Helms Jan 11 '21 at 20:20
  • The last improvement of my (restricted) brute-force-routine assumes, that for any odd $N$ the first found solution cannot be improved by further testing (why not??). This assumption has no other base than heuristics on small numbers so far. With this implementation I test odd $N=3..399$ in 16 secs, finding that at most $15$ divisions by $3$ occur at $N=255$ , which has also the maximal length (=$46$) . At $N=383$ I get $14$ divisions by $3$ and $31$ multiplications by $2$ making a length of $44$ in your notation. – Gottfried Helms Jan 11 '21 at 21:11
  • 1
    For the question of whether or not the table covers all natural numbers, if I'm not misreading what you're writing, you can prove it with https://math.stackexchange.com/questions/1485372/how-to-show-density-of-2a-3b . However, if you interpret the question as being able to write $3$ and $2$ wherever you like, they're not optimal. – AnilCh Jan 12 '21 at 08:53
  • @ACheca. Wow! An application with music. That may be related to this question as well. The subject becomes more interesting every day. – Han de Bruijn Jan 12 '21 at 10:50
  • @ACheca thanks for pointing this related question; but I do not get how it proves that any integer may be written as a sequence of products by 2 and integer divisions by 3. I am not sure for the question pointed by Han either. May you please elaborate? – Matthieu Latapy Jan 13 '21 at 07:44
  • @MatthieuLatapy If I'm not wrong, you can use the linked question in the answer ( https://math.stackexchange.com/questions/843763/for-x-in-mathbb-r-setminus-mathbb-q-the-set-nx-lfloor-nx-rfloor-n-in-ma ) with $\alpha = \ln(2)/ \ln(3)$ to prove $n\alpha -m$ is dense in $[0,1)$. You multiply by $\ln(3)$ to obtain $2^a/3^b$ with $a,b \geq 0$ is dense in positive reals. That means that for any interval $[k, k+1)$ there are particular $a,b$ to obtain a decomposition that falls there. Take floor and you obtain $k$. Floor at the end is the same than at each division of $3$ when they're together. – AnilCh Jan 13 '21 at 09:59
1

Lessons were learnt from numerical experiments. The basic rules with my last attempt are:

  1. It's easier to work the other way around: define sequences of operations in order of terseness and see what numbers come out, rather than define a number and find out what its optimal sequence is.
  2. Optimal even numbers always end with (*2) . All odd numbers end with (/3) .
  3. Even numbers can always be constructed from previous ones by multiplying the latter with 2 .
  4. All patterns are generated in order, namely with binary counting and iterpreting bits as:
    0 → (*2) , 1 → (/3) .
  5. Interpretation of the binary coding shall end at the leftmost bit up, hence with (/3) as the last operation.
  6. The above rules ( 4 , 5 ) result in even numbers as well; discard them and use rule ( 3 ) instead.
  7. Our method is brute force in every respect; it's greedy with respect to memory as well as computing time.
  8. An enormous amount of duplicates will be found, most of them being 0 . Get rid of them as soon as possible.
  9. Quite fortunately, the first pattern found with odd numbers is always the best. Keep it and discard the rest.
  10. Finding a contiguous sequence of numbers with their optimal patterns has become a matter of sorting now.
  11. Given a maximal number of operations, (large) gaps in the contiguous sequence of numbers are expected to occur soon.
  12. The last attempt (22 bits) was interrupted by the first gap (at 51) in the contiguous sequence of numbers.
Notes. If rule (6) is not taken into account, then sub-optimal results like the one below will be encountered:
2*2*2*2/3*2/3*2*2*2/3 = 8    instead of   2*2*2 = 8
Accompanying program sources and outputs are found at: MSE publications / references 2021.
Most operations are not commutative nor associative. Concerning rule (6) the following is noticed: $$ 2^{\mbox{ even}}/3 = \mbox{odd} \qquad ; \qquad 2^{\mbox{ odd}}/3 = \mbox{even} = 2^{\mbox{ even}}/3\times 2 $$ Output of my last attempt:
  1 = 2*2/3 (#2)
  2 = 2 (#0)
  3 = 2*2*2*2/3*2/3 (#6)
  4 = 2*2 (#1)
  5 = 2*2*2*2/3 (#4)
  6 = 2*2*2*2/3*2/3*2 (#7)
  7 = 2*2*2*2*2*2/3/3 (#7)
  8 = 2*2*2 (#2)
  9 = 2*2*2*2*2*2/3/3*2*2/3 (#10)
 10 = 2*2*2*2/3*2 (#5)
 11 = 2*2*2*2/3*2*2*2/3*2*2/3*2/3 (#13)
 12 = 2*2*2*2/3*2/3*2*2 (#8)
 13 = 2*2*2*2/3*2*2*2/3 (#8)
 14 = 2*2*2*2*2*2/3/3*2 (#8)
 15 = 2*2*2*2/3*2*2*2*2*2/3*2/3*2/3*2/3 (#16)
 16 = 2*2*2*2 (#3)
 17 = 2*2*2*2/3*2*2*2/3*2*2/3 (#11)
 18 = 2*2*2*2*2*2/3/3*2*2/3*2 (#11)
 19 = 2*2*2*2/3*2*2*2/3*2*2/3*2/3*2*2*2/3*2/3 (#19)
 20 = 2*2*2*2/3*2*2 (#6)
 21 = 2*2*2*2*2*2/3 (#6)
 22 = 2*2*2*2/3*2*2*2/3*2*2/3*2/3*2 (#14)
 23 = 2*2*2*2/3*2*2*2*2*2/3*2/3*2/3 (#14)
 24 = 2*2*2*2/3*2/3*2*2*2 (#9)
 25 = 2*2*2*2*2*2*2*2/3*2*2/3*2/3/3 (#14)
 26 = 2*2*2*2/3*2*2*2/3*2 (#9)
 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)
 28 = 2*2*2*2*2*2/3/3*2*2 (#9)
 29 = 2*2*2*2/3*2*2*2/3*2*2/3*2/3*2*2*2/3 (#17)
 30 = 2*2*2*2/3*2*2*2*2*2/3*2/3*2/3*2/3*2 (#17)
 31 = 2*2*2*2/3*2*2*2*2*2*2*2/3/3*2/3*2/3 (#17)
 32 = 2*2*2*2*2 (#4)
 33 = 2*2*2*2*2*2*2*2/3*2*2/3*2/3/3*2*2/3 (#17)
 34 = 2*2*2*2/3*2*2*2/3*2*2/3*2 (#12)
 35 = 2*2*2*2/3*2*2*2*2*2/3*2/3 (#12)
 36 = 2*2*2*2*2*2/3/3*2*2/3*2*2 (#12)
 37 = 2*2*2*2*2*2/3/3*2*2*2*2/3 (#12)
 38 = 2*2*2*2/3*2*2*2/3*2*2/3*2/3*2*2*2/3*2/3*2 (#20)
 39 = 2*2*2*2/3*2*2*2/3*2*2/3*2/3*2*2*2*2*2/3/3 (#20)
 40 = 2*2*2*2/3*2*2*2 (#7)
 41 = 2*2*2*2/3*2*2*2*2*2*2*2/3/3*2/3*2/3*2*2/3 (#20)
 42 = 2*2*2*2*2*2/3*2 (#7)
 43 = 2*2*2*2*2*2/3/3*2*2*2*2/3*2*2/3*2*2/3*2/3 (#20)
 44 = 2*2*2*2/3*2*2*2/3*2*2/3*2/3*2*2 (#15)
 45 = 2*2*2*2/3*2*2*2/3*2*2/3*2*2*2/3 (#15)
 46 = 2*2*2*2/3*2*2*2*2*2/3*2/3*2/3*2 (#15)
 47 = 2*2*2*2/3*2*2*2*2*2*2*2/3/3*2/3 (#15)
 48 = 2*2*2*2/3*2/3*2*2*2*2 (#10)
 49 = 2*2*2*2*2*2/3/3*2*2*2*2/3*2*2/3 (#15)
 50 = 2*2*2*2*2*2*2*2/3*2*2/3*2/3/3*2 (#15)

Especially take notice of the number $27$, which has been mentioned by Christian Blatter in a comment.

Han de Bruijn
  • 17,070
  • Have you noticed the nice patterns that appear when you plot the length of the (shortest) decomposition of $x$ as a function of $x$ (try log scale for $x$)? Also check the number of integers having a (shortest) decomposition of length $l$ as a function of $l$. – Matthieu Latapy Jan 10 '21 at 00:58
  • @MatthieuLatapy. No, I didn't. But you are free to formulate your findings as another answer - for better understanding by anyone (and maybe become a bounty winner :-). – Han de Bruijn Jan 10 '21 at 14:09
  • I do not claim that my own answer is original or better than the other ones. But anyway the (full) bounty winner is expected improve on it. – Han de Bruijn Jan 10 '21 at 20:15
1

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:

  1. the ininital value $a_{k-1}$ is assumed to be odd (let's implement the routine for the even numbers later) and
  2. 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

1

I am not sure if it is optimum, but it shouldn't be too bad to
Find the highest power of $2$ that divides $N$. Let this be $c$
Let $M=N/2^c$
Start with $a=b=0$
If $\lfloor \frac {2^a}{3^b}\rfloor \lt M: a=a+1$
If $\lfloor \frac {2^a}{3^b}\rfloor \gt M: b=b+1$
Else return $a,b,c$
Loop to first If

Maybe you want to loop over $0$ to this $c$ for the final exponent and try all the possibilities.

After a few dozen tries, I always found the best answer with $c$ as large as possible, but have not proven it to be the best.

Ross Millikan
  • 374,822
  • 1
    It's important to note that the integer (!) divisions and multiplications are not commutative: the order in which the operations $*$ and $/$ take place is crucial. But, as far as I can see, your answer doesn't take this into account. – Han de Bruijn Jan 06 '14 at 14:26
  • 1
    @HandeBruijn: I think it does. I take out all the factors of $2$ that I need, and add them back at the end, then approximate the odd part of $N$ with the floor until I get there. For example, for $N=13$, it finds $a=18,b=9$, giving the inside of the floor as $13.31829$ For $51$, it takes a while to get to $a=58,b=33$ – Ross Millikan Jan 06 '14 at 15:13
  • 1
    @HandeBruijn Note that taking one floor at the end is the same as doing an integer divide by each of the $3$'s – Ross Millikan Jan 06 '14 at 15:38
0

While the 2nd answer of mine provides a (restricted) brute force method this method cannot be used when the length of the decomposition is over 30 or so: the computation time grows exponentially with the length. (If we use for the available digits for the residues modulo 3 only the residues $\{0,1\}$ we have a $2^\text{length}$ instead of a $3^\text{length}$-problem, but we see, that the method shall come to its limit soon.)

Here I've applied my "strictly decreasing" algorithm on some example numbers $a_0$ taken from Eric Roosendaal's Collatz-pages. I think that are well "complicated" numbers: record holders for glide-, delay- and path- records; and the "strictly decreasing" algo can handle numbers with dozens (or likely hundreds) of digits. The trajectory-length of the "strictly decreasing" algo is in all cases drastically shorter than the original Collatz-trajectory. On one hand there are examples where the "strictly decreasing" decompositions are not optimal, but they might be the best systematic approach available when decomposition length becomes large and memory and/or computation time becomes galactic when full combinatorical brute force is no more applicable. (This reminds me, btw., of the problem of "perfect rulers" and "optimal rulers", I think in Wikipedia is an entry)

I give the table not in mathjax because I'd like to have colors etc, and that's not my expertise... So here is a jpeg of the table, and below the raw data.

picture


Roosendaal : 
here: idx= index in E.R.'s webpage
idx   a0                  collatz  collatz   collatz    stric dec       optimal??
                           N (3^N)  S (2^S)  length(N+S)# of tokens         
      page: Glide-records                                         
32    180352746940718527    714       1189      1903        241       
20            1200991791    326        547       873        113       
10                626331    189        319       508         84        
      page: Delay-records                                         
100   14022512981985        590        979      1569        199       
96     3743559068799        583        966      1549        179       
66        1341234558        370        617       987        134       
30             26623        113        194       307         77        
      page: Pathrecords                                           
93  274133054632352106267   672       1133      1805        280       
88    1980976057694848447   547        928      1475        216       
      page: (other)                                               
30           903             41         75       116         54

Eric Roosendaal: http://www.ericr.nl/wondrous/ Glide-records: http://www.ericr.nl/wondrous/glidrecs.html Delay-records: http://www.ericr.nl/wondrous/delrecs.html Pathrecords: http://www.ericr.nl/wondrous/pathrecs.html

The Pari/GP-code is the following (only little reworked for readable, I'll improve this later)

\\ Pari/GP
\\ from some a0 find between a1=a0*3^e3 ... a1+(3^e3 -1) a number a2 divisible by
\\    2^e2 such that a3=a2/2^e2 < a0 . If for e3=1 there is no such number,
\\ increase e3 until success or e3>maxe3. 
\\ Return a short list of first solutions with increasing e3
\\
\\ user routine "mcc( [vectorv,vectorv,...,vectorv])" returns concatenation
\\  to rectangular matrix and "VE()" extracts leading rows&columns of matrix
\\
{findstepdown(a0,maxe3=4)=my(aa,ae,a1,p3,a2,m2,r1,A,res_a,res_A,res_e3,res_r,il);
      res_a=res_e3=res_A=res_r=vectorv(maxe3);il=0; \\ res_ulting value-vectors
      for(e3=1,maxe3,
          p3=3^e3;[aa=p3*a0,ae=aa+p3-1,p3-1,m2=2^ceil(ld3*e3)];
          [r1= (-aa % m2),p3-1] ; \\ >p3-1
          if(r1>=p3,next());      \\ residue must be in interval a1..a1+3^e3-1
          A=valuation(aa +r1,2);a1=(aa+r1)>>A;
          il++;
          res_e3[il]=e3;res_a[il]=a1;res_A[il]=A;res_r[il]=r1; 
               \\ fill list of result vectors 
       ); return(VE(mcc([res_e3,res_a,res_A,res_r]),il,4));
   }

\ calls "findstepdown()" repeatedly until a1 approaches 1 {strictlydecreasing(a0,maxstepdown=8)=my(lambda,st,st1,st2,res,res1,e3,e2,a1,r1); lambda=0; st=Str("");a1=a0;print1(a0,":"); for(k=1,40, res= findstepdown(a1,maxstepdown); res1=res[1,]; \ use always first stepdown-result! e3=res1[1];a1=res1[2];e2=res1[3];r1=res1[4];lambda+=(e2+e3); print1([a1,lambda]); st1=st2=""; for(k=1,e2,st1=Str(st1,"*2")); for(k=1,e3,st2=Str(st2,"/3")); st=Str(st1,st2,st); if(a1==1,break()) ); print(""); print(a0,"=",Str(1,st," (#"lambda")")); }

\ apply this a0=4535 strictlydecreasing(a0) \ prints a decomposition of a0

Exemplary results: decompositions of two not too large values $a_0$:
These are also a challenge for competing methods to find better/optimal decompositions.

legend: -------------------------------------------------------------
  a_0 :[consecutive a_k, cumulative partial length] [...,...] ... 
626331:[528467, 8][297263, 14][3919, 28][3307, 36][2791, 44][785, 51][589, 54][221, 58][83, 62][47, 68][5, 79][1, 84]
  a_0 = decomposition-string beginning at 1 growing towards a_0:
626331=1*2*2*2*2/3*2*2*2*2*2*2*2*2/3/3/3*2*2*2*2/3/3*2*2*2/3*2*2*2/3*2*2/3*2*2*2*2*2/3/3*2*2*2*2*2/3/3/3*2*2*2*2*2/3/3/3*2*2*2*2*2*2*2*2*2*2*2/3/3/3*2*2*2*2/3/3*2*2*2*2*2/3/3/3 (#84)

26623:[14215, 19][1999, 27][1687, 35][949, 41][89, 47][67, 50][19, 57][11, 63][5, 72][1, 77] 26623=12222/3222222/3/3/32222/3/322222/3/322/322222/32222/3/322222/3/3/3222222/3/322222222222*2/3/3/3/3/3/3/3 (#77)