<p>And on the <a href="http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1459058&amp;tag=1" rel="nofollow">main paper</a> of Lehman's thesis, there is a good overview of the problem (section V B) with references.</p>

CC BY-SA 2.5
2010-09-07T07:34:45.653Z
2010-09-07T07:34:45.653Z
mgalle
<p>I would like to document some partial progress - seemingly promising so far - towards a polynomial time algorithm. <strong>UPDATE</strong>: Added some details to account for a glitch pointed out by @David (thanks!).</p>

<p>The approach is to reduce this to an instance of MIN-ONES EVEN-3 CSPs (MOEC), which happens to be a polynomial time solvable problem. The proof of the reduction is a bit fuzzy, but I am hopeful that it exists! </p>

<p>An instance of MOEC is a family of $3$-sized subsets of an universe of variables, and an integer $k$. The question is whether there is a satisfying assignment of weight at most $k$, where an assignment is a function from the universe to $\{0,1\}$, the weight of an assignment is the number of variables that it assigns one, and an assignment is satisfying if, for every subset of variables $\{x,y,z\}$, the assignment (say $f$) has the property that:</p>

<p>$f(x) + f(y) + f(z) = 0 (mod ~~2)$.</p>

<p>You could visualize this as 3-SAT with a different notion of satisfiability - pick none or pick two. I'll be a bit lax about the instance of MOEC in that I will allow for, apart from the usual $3$-subsets, implications, disjunctions of length two, and the constraint $(x = 1)$. I believe these simple additions will keep the problem polynomial time.</p>

<p>Let's say we're reducing the addition chain problem for the number $n$. The variable set for this reduction is the following:</p>

<p>For every $1 \leq i \leq n$, the variable $N_i$. I will re-write the variable $N_n$ as $N$.
For every pair $i,j$ such that $1 \leq i,j \leq k$, introduce variables $P_{ij}$ and $Q_{ij}$.  </p>

<p>Introduce the following subsets, for every $i,j,k$ such that $k = i+j$:</p>

<p>$\{P_{ij}, Q_{ij}, N_k \}$</p>

<p>and the following implications:</p>

<p>$P_{ij} \Rightarrow N_i$ and 
$P_{ij} \Rightarrow N_j$ </p>

<p>and the following constraints:</p>

<p>$(N_1 = 1), (N = 1)$.</p>

<p>Finally, we need to add constraints that ensure that at least one of the $P$-variables are picked when a "corresponding" $N$-variable (forgive the abuse of notation) is assigned one. This can be done by adding the usual OR constraint over all $P_{ij}$ such that $i + j$ sum to the $N$-variable in question. We have to, however, find a way of re-encoding this in MOEC-framework. </p>

<p>So let me outline a general way of saying, given a set of variables:</p>

<p>$(X, l_1, l_2, \ldots, l_t)$,</p>

<p>how the constraint "if an assignment is satisfying and sets $X$ to one, then exactly one of the $l_i$'s must be set to one by the assignment", can be encoded with the MOEC syntax. Note that this suffices for our requirements, we simply introduce the constraints:</p>

<p>$(N_k, \{ P_{ij} ~|~ i + j = k \})$.</p>

<p>The encoding is done as follows. Let $T_X$ be the rooted complete binary tree on $t$ leaves. Introduce a new variable $T_{di}$ for all $1 \leq d \leq \log t$ and $1 \leq i \leq {\cal L}(d)$, where ${\cal L}(d)$ denotes the number of nodes of $T_X$ at depth $d$.</p>

<p>For every node $T_{di}$, if $p$ and $q$ be its children in the tree, introduce the EVEN-3 constraint:</p>

<p>$\{T_{di},p,q\}$</p>

<p>This means that if a variable corresponding to a node is set to true, then exactly one of its children must be set to true as well. Now add the implications:</p>

<p>$(X \Rightarrow T_{11})$ and
$(d_{\log t,j}) \Rightarrow l_j$ (comma for clarity).</p>

<p>This combination of EVEN-3 constraints and implications is equivalent to constraint that we wished to encode. </p>

<p>Intuitively, what's happening is that the last two constraints trigger exactly the reactions required to build an addition chain. In particular, let us look at the $N_i$'s that are assigned one by a satisfying assignment - the claim is that they will form an addition chain for $N$: since the assignment is forced to set $N$ to one, there must be at least one $P_{ij}$ that was set to one, and the implications force $N_i$ and $N_j$ to be assigned one, and this goes all the way down (I am sure this can be formalized with induction, although I haven't worked out that level of detail yet).  Note that a satsifying assignment that is optimal in the number of ones assigned will not set $P_{ij}$ true for two pairs $(r,s)$ and $(r',s')$, for the reason that the $P$-variables come with the additional baggage of the implications, and the $Q$-variables don't (they are there to ensure EVEN-3 satisfiability - on a clause where $N_i$ is true and $P_{ij}$ is not true, we still need to pick something to satisfy that clause, and for reasons that are easy to see, this cannot be one universal variable across clauses).</p>

<p>So I believe an addition chain corresponds to a satisfying assignment and vice-versa. Let me describe one part of this somewhat formally: given an addition chain, we construct an assignment $f$ that is satisfying. To begin with, $f$ sets all $N_i$'s that feature in the chain to one, and the other $N_i$'s to zero. Further, if $k$ features in the addition chain, then for each $N_k$, let $i_k,j_k$ be the elements in the chain such that $i_k + j_k = j$. Then $f$ sets $P_{i_k j_k}$ to one (and  $Q_{i_k j_k}$  to zero), and all $(i,j)$ such that $i \neq i_k$ and $j \neq j_k$ and $i+j = k$, $f$ sets $Q_{ij}$ to one (and $P_{ij}$ to zero). For all $k$ that don't feature in the addition chain, for all $i,j$ such that $i+j = k$, set all $Q_{ij}$ and $P_{ij}$ to zero (notice that consistency follows from the fact that two numbers add up in only one way). Every clause involving a $N_i$ in the chain is satisfied because either a P-variable or Q-variable corresponding to it was set to one (and notice that exactly one of them are set to one for any pair $(i,j)$). For every other clause, everything is set to zero. That the implications hold is easy to check. </p>

<p>The part that is unclear is the following: because for every element $t$ chosen in the addition chain, the assignment incurs a weight of $t$ (because of all the $Q$-variables being set to one). So there is a possibility that a longer additional chain would correspond to a cheaper assignment, but I am quite sure this doesn't happen because of a proof along the following lines: consider an optimal addition chain and suppose there is a longer one that has a smaller-weight satisfying assignment corresponding to it. Clearly, the elements of the longer chain exclude at least one from the shorter one - let that element be $x$. I wish to say that the cost incurred with $x$ is incurred in the longer chain anyway, and the remaining compares favorably. However, I have to write this down carefully, and I might just be seeing things from post-midnight syndrome!  </p>

CC BY-SA 2.5
2010-09-04T20:12:36.430Z
If this does work, it seems that it would still be exponential time (when N is expressed in binary) because the number of variables is proportional to N^2 rather than polylog(N).
David Eppstein
CC BY-SA 2.5
2010-09-04T20:20:46.117Z
Ah yes, I should have emphasized that. I was thinking of $N$ in unary following @JeffE's remark that even that is not clear. I do plan to think about cutting down the instance size further, but at the moment am more keen on ensuring this is alright. If it is, I think there is room aplenty for improvement. Incidentally, would you find the approach promising?
Neeldhara
CC BY-SA 2.5
2010-09-04T23:11:17.183Z
I don't see how the constraints you describe force a solution to be valid. What stops you from setting P_ij=0 and Q_ij=1 for all i+j=n, and P_ij=Q_ij=0 for all other i,j?
David Eppstein
CC BY-SA 2.5
2010-09-05T04:13:56.423Z
Thanks for wading through that! And yes, you are quite right; I meant to add a constraint that said any of the $N_i$'s implies one of the relevant $P_{ij}$'s, but realized it blows up the complexity of the instance into the Hitting Set domain, and while I meant to fix it, I think I forgot about it instead. I have updated the answer with a possible fix, it's just a slightly tedious (but simple) construction.
Neeldhara
CC BY-SA 2.5
2010-09-04T19:26:06.257Z
2010-09-05T04:33:36.520Z
2010-09-05T04:33:36.520Z
Neeldhara
<p>The problem is mentioned as being open in Eric Lehman's PhD thesis "Approximation algorithms for grammar-based data compression" in 2002. From p35 of the thesis:</p>

<p>"Nevertheless, an exact solution to the addition chain problem remains strangely elusive. The M-ary method runs in time polylog(n) and gives a 1 + o(1) approximation. However, even if exponentially more time is allowed, poly(n), no exact algorithm is known." </p>

CC BY-SA 2.5
2010-09-03T18:13:36.293Z
2010-09-03T18:13:36.293Z
Andrew W.
<p>An <a href="http://wwwhomes.uni-bielefeld.de/achim/addition_chain.html">addition chain</a> is a sequence of positive integers $(x_1, x_2, \dots, x_n)$ where $x_1 = 1$ and  each index $i\ge 2$, we have $x_i = x_j + x_k$ for some indices $1\le j,k &lt; i$.  The <em>length</em> of the addition chain is $n$; the <em>target</em> of the addition chain is $x_n$.</p>

<p>What is known about the complexity of the following problem: Given an integer $N$, what is the length of the shortest addition chain whose target is $N$?  Is it NP-hard?</p>

<p><a href="http://en.wikipedia.org/wiki/Addition_chain">Wikipedia</a> points to a 1981 paper by Downey, Leong, and Sethi that proves the following related problem is NP-hard: Given a set of integers what is the minimum length of an addition chain that includes the entire set?  Several authors apparently claim that this paper proves the single-target problem is NP-hard, but it doesn't.</p>

CC BY-SA 2.5
2010-09-03T17:11:55.960Z
two questions: $N$ is given in binary form I assume, and can the $j$ and $k$ be identical (if so, then there's always a sequence of length log n via binary expansion)
Suresh Venkat
CC BY-SA 2.5
2010-09-04T02:23:24.627Z
Let's assume $N$ is given in binary, although I don't know of a poly-time algorithm even when $N$ is unary. And yes, adding to yourself is allowed — in fact, required to get off the ground. The shortest chain for 128 is (1, 2, 4, 8, 16, 32, 64, 128).
Jeffε
<reference-request><np-hardness>
Is it hard to find optimal addition chains?
Jeffε
# Is it hard to find optimal addition chains?

(Asked by: username_0 on 2010-09-03)

An [addition chain](http://wwwhomes.uni-bielefeld.de/achim/addition_chain.html) is a sequence of positive integers $(x\_1, x\_2, \dots, x\_n)$ where $x\_1 = 1$ and each index $i\ge 2$, we have $x\_i = x\_j + x\_k$ for some indices $1\le j,k < i$. The *length* of the addition chain is $n$; the *target* of the addition chain is $x\_n$.

What is known about the complexity of the following problem: Given an integer $N$, what is the length of the shortest addition chain whose target is $N$? Is it NP-hard?

[Wikipedia](http://en.wikipedia.org/wiki/Addition_chain) points to a 1981 paper by Downey, Leong, and Sethi that proves the following related problem is NP-hard: Given a set of integers what is the minimum length of an addition chain that includes the entire set? Several authors apparently claim that this paper proves the single-target problem is NP-hard, but it doesn't.

**Tags:** reference-request, np-hardness

> **Comments:**
> **username_1**: two questions: $N$ is given in binary form I assume, and can the $j$ and $k$ be identical (if so, then there's always a sequence of length log n via binary expansion)  
> **username_0**: Let's assume $N$ is given in binary, although I don't know of a poly-time algorithm even when $N$ is unary. And yes, adding to yourself is allowed — in fact, required to get off the ground. The shortest chain for 128 is (1, 2, 4, 8, 16, 32, 64, 128).  

---

## 3 answers

### Answer by username_5 on 2010-09-03. Score: 12 | Accepted answer

The problem is mentioned as being open in Eric Lehman's PhD thesis "Approximation algorithms for grammar-based data compression" in 2002. From p35 of the thesis:

"Nevertheless, an exact solution to the addition chain problem remains strangely elusive. The M-ary method runs in time polylog(n) and gives a 1 + o(1) approximation. However, even if exponentially more time is allowed, poly(n), no exact algorithm is known."


---

### Answer by username_2 on 2010-09-07. Score: 2

And on the [main paper](http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1459058&tag=1) of Lehman's thesis, there is a good overview of the problem (section V B) with references.


---

### Answer by username_3 on 2010-09-04. Score: 1

I would like to document some partial progress - seemingly promising so far - towards a polynomial time algorithm. **UPDATE**: Added some details to account for a glitch pointed out by @David (thanks!).

The approach is to reduce this to an instance of MIN-ONES EVEN-3 CSPs (MOEC), which happens to be a polynomial time solvable problem. The proof of the reduction is a bit fuzzy, but I am hopeful that it exists!

An instance of MOEC is a family of $3$-sized subsets of an universe of variables, and an integer $k$. The question is whether there is a satisfying assignment of weight at most $k$, where an assignment is a function from the universe to $\{0,1\}$, the weight of an assignment is the number of variables that it assigns one, and an assignment is satisfying if, for every subset of variables $\{x,y,z\}$, the assignment (say $f$) has the property that:

$f(x) + f(y) + f(z) = 0 (mod ~~2)$.

You could visualize this as 3-SAT with a different notion of satisfiability - pick none or pick two. I'll be a bit lax about the instance of MOEC in that I will allow for, apart from the usual $3$-subsets, implications, disjunctions of length two, and the constraint $(x = 1)$. I believe these simple additions will keep the problem polynomial time.

Let's say we're reducing the addition chain problem for the number $n$. The variable set for this reduction is the following:

For every $1 \leq i \leq n$, the variable $N\_i$. I will re-write the variable $N\_n$ as $N$.
For every pair $i,j$ such that $1 \leq i,j \leq k$, introduce variables $P\_{ij}$ and $Q\_{ij}$.

Introduce the following subsets, for every $i,j,k$ such that $k = i+j$:

$\{P\_{ij}, Q\_{ij}, N\_k \}$

and the following implications:

$P\_{ij} \Rightarrow N\_i$ and
$P\_{ij} \Rightarrow N\_j$

and the following constraints:

$(N\_1 = 1), (N = 1)$.

Finally, we need to add constraints that ensure that at least one of the $P$-variables are picked when a "corresponding" $N$-variable (forgive the abuse of notation) is assigned one. This can be done by adding the usual OR constraint over all $P\_{ij}$ such that $i + j$ sum to the $N$-variable in question. We have to, however, find a way of re-encoding this in MOEC-framework.

So let me outline a general way of saying, given a set of variables:

$(X, l\_1, l\_2, \ldots, l\_t)$,

how the constraint "if an assignment is satisfying and sets $X$ to one, then exactly one of the $l\_i$'s must be set to one by the assignment", can be encoded with the MOEC syntax. Note that this suffices for our requirements, we simply introduce the constraints:

$(N\_k, \{ P\_{ij} ~|~ i + j = k \})$.

The encoding is done as follows. Let $T\_X$ be the rooted complete binary tree on $t$ leaves. Introduce a new variable $T\_{di}$ for all $1 \leq d \leq \log t$ and $1 \leq i \leq {\cal L}(d)$, where ${\cal L}(d)$ denotes the number of nodes of $T\_X$ at depth $d$.

For every node $T\_{di}$, if $p$ and $q$ be its children in the tree, introduce the EVEN-3 constraint:

$\{T\_{di},p,q\}$

This means that if a variable corresponding to a node is set to true, then exactly one of its children must be set to true as well. Now add the implications:

$(X \Rightarrow T\_{11})$ and
$(d\_{\log t,j}) \Rightarrow l\_j$ (comma for clarity).

This combination of EVEN-3 constraints and implications is equivalent to constraint that we wished to encode.

Intuitively, what's happening is that the last two constraints trigger exactly the reactions required to build an addition chain. In particular, let us look at the $N\_i$'s that are assigned one by a satisfying assignment - the claim is that they will form an addition chain for $N$: since the assignment is forced to set $N$ to one, there must be at least one $P\_{ij}$ that was set to one, and the implications force $N\_i$ and $N\_j$ to be assigned one, and this goes all the way down (I am sure this can be formalized with induction, although I haven't worked out that level of detail yet). Note that a satsifying assignment that is optimal in the number of ones assigned will not set $P\_{ij}$ true for two pairs $(r,s)$ and $(r',s')$, for the reason that the $P$-variables come with the additional baggage of the implications, and the $Q$-variables don't (they are there to ensure EVEN-3 satisfiability - on a clause where $N\_i$ is true and $P\_{ij}$ is not true, we still need to pick something to satisfy that clause, and for reasons that are easy to see, this cannot be one universal variable across clauses).

So I believe an addition chain corresponds to a satisfying assignment and vice-versa. Let me describe one part of this somewhat formally: given an addition chain, we construct an assignment $f$ that is satisfying. To begin with, $f$ sets all $N\_i$'s that feature in the chain to one, and the other $N\_i$'s to zero. Further, if $k$ features in the addition chain, then for each $N\_k$, let $i\_k,j\_k$ be the elements in the chain such that $i\_k + j\_k = j$. Then $f$ sets $P\_{i\_k j\_k}$ to one (and $Q\_{i\_k j\_k}$ to zero), and all $(i,j)$ such that $i \neq i\_k$ and $j \neq j\_k$ and $i+j = k$, $f$ sets $Q\_{ij}$ to one (and $P\_{ij}$ to zero). For all $k$ that don't feature in the addition chain, for all $i,j$ such that $i+j = k$, set all $Q\_{ij}$ and $P\_{ij}$ to zero (notice that consistency follows from the fact that two numbers add up in only one way). Every clause involving a $N\_i$ in the chain is satisfied because either a P-variable or Q-variable corresponding to it was set to one (and notice that exactly one of them are set to one for any pair $(i,j)$). For every other clause, everything is set to zero. That the implications hold is easy to check.

The part that is unclear is the following: because for every element $t$ chosen in the addition chain, the assignment incurs a weight of $t$ (because of all the $Q$-variables being set to one). So there is a possibility that a longer additional chain would correspond to a cheaper assignment, but I am quite sure this doesn't happen because of a proof along the following lines: consider an optimal addition chain and suppose there is a longer one that has a smaller-weight satisfying assignment corresponding to it. Clearly, the elements of the longer chain exclude at least one from the shorter one - let that element be $x$. I wish to say that the cost incurred with $x$ is incurred in the longer chain anyway, and the remaining compares favorably. However, I have to write this down carefully, and I might just be seeing things from post-midnight syndrome!

> **Comments:**
> **username_4**: If this does work, it seems that it would still be exponential time (when N is expressed in binary) because the number of variables is proportional to N^2 rather than polylog(N).  
> **username_3**: Ah yes, I should have emphasized that. I was thinking of $N$ in unary following @JeffE's remark that even that is not clear. I do plan to think about cutting down the instance size further, but at the moment am more keen on ensuring this is alright. If it is, I think there is room aplenty for improvement. Incidentally, would you find the approach promising?  
> **username_4**: I don't see how the constraints you describe force a solution to be valid. What stops you from setting P_ij=0 and Q_ij=1 for all i+j=n, and P_ij=Q_ij=0 for all other i,j?  
> **username_3**: Thanks for wading through that! And yes, you are quite right; I meant to add a constraint that said any of the $N_i$'s implies one of the relevant $P_{ij}$'s, but realized it blows up the complexity of the instance into the Hitting Set domain, and while I meant to fix it, I think I forgot about it instead. I have updated the answer with a possible fix, it's just a slightly tedious (but simple) construction.  

---

