3

We are given a natural number $x\in\mathbb{N}^+$, and $x-1$ adders. An adder in our case would be a component with two inputs $x_1,x_2$ and a single output $y$ such that $y=x_1+x_2$. Our goal is to design a system that has $x$ as its single input, and $x^2$ as its single output. No constants are available to use. Define $n:\mathbb{N}^+\to\mathbb{N}$ such that $\forall x\in\mathbb{N}^+$, $n(x)$ is the minimum amount of adders needed in order to implement such system that calculates $x^2$. What is $n(x)$ precisely?

For example: In order to calculate $7^2$ efficiently:

  1. First step: we only have $7$, so we must do $7+7=14$. (1 adder)
  2. Second step: Now we also have $14$, so we can calculate $7+14=21$ and $14+14=28$ (2 adders; 3 overall)
  3. Final step: Now we have $21$ and $28$, so we can calculate $21+28=49$ (1 adder; 4 overall) and we're done.

It needs to be proven now that $7^2$ can't be calculated using $3$ adders or less (pretty intuitive), and then it can be concluded that $n(7)=4$.


It is clear that $n(x)\leq x-1$. I was able to show that $n(x)$ is not increasing (for instance - $n(7)=4$ while $n(8)=3$), but I think I did manage to find a tighter upper bound - which is $n(x)\leq2\lfloor\log_2(x)\rfloor$. I'm having trouble with finding the exact expression for $n(x)$.

This was my way of thinking. For every $m\in\mathbb{N}^+$, define the group of natural numbers $A_m$ s.t.:

$$A_m\triangleq \{x\in\mathbb{N}^+|\lceil\log_2(x)\rceil=m\}$$

So for example, $A_3=\{5,6,7,8\}$. It is clear that $x_m\equiv2^m-1\in A_m$. This demands proof, but I tend to believe that out of all the integers of $A_m$, $x_m$ requires the greatest amount of adders. Pay attention that:

$$x_m^2=x_m(2^{m-1}+2^{m-1}-1)=2^{m-1}x_m+\sum_{k=0}^{m-2}2^kx_m$$

You can efficiently calculate $2^{m-1}x_m$ using $m-1$ adders. When you do that, you have the input $2^kx_m$ available, for every $k\in[1,m-1]_\mathbb{N}$. So $\sum_{k=0}^{m-2}2^kx_m$ can be calculated with $m-2$ adders. Then, a final adder is needed in order to calculate $x_m^2$. So overall:

$$n(2^m-1)=2m-2$$

Given that $x_m^2$ cannot be calculated using $2m-3$ adders or less. Pay attention that for $m=3$, we get $n(7)=4$, as before.


I tried to do the same thing with different patterns, but I didn't manage to conclude the general form. Some help would be appreciated :)

Note: This question can be rephrased in a clearer way. Suppose you initially have a set $S=\{1\}$, each time you can pick up two (can be duplicate) numbers in $S$ and put the sum of those two numbers in $S$. What is the least number of steps, or $|S|$, that is needed such that $n\in S$? (The question is not the same, but the answers are (I believe) the same, since all my equations can simply be divided by $x_m$). (Thank you @JetfiRex for this)

JetfiRex
  • 2,451
Amit Zach
  • 1,626
  • 1
  • 7
  • 17
  • I do have a thought: instead try to add $n$ to $n^2$, why not add $1$ to $n$ (assume you need to use the adders to make $n$, not use $n$ directly from the input)? – JetfiRex Feb 14 '22 at 17:58
  • @JetfiRex I believe the questions are equivalent, yeah. This does simplify things a bit. – Amit Zach Feb 14 '22 at 18:01
  • I would not use adders to say, but I will try to rephrase your question in a clearer way: Suppose you have $S={1}$ initially, each time you can pick up two (can be duplicate) numbers in $S$ and put the sum of two numbers in $S$. In order to make $n$ in $S$, what is the least number of steps, or $|S|$, can you achieve? Is that equivalent to your question? – JetfiRex Feb 14 '22 at 18:03
  • @JetfiRex I believe so, yes – Amit Zach Feb 14 '22 at 18:05
  • The upper bound is the number of digits of $n$ (in binary) plus the number of $1$s in the binary representation in $n$ (minus $1$ for $|S|$, minus $2$ for steps). I believe it is the exact number too. – JetfiRex Feb 14 '22 at 18:14
  • Please refer to this https://en.wikipedia.org/wiki/Addition_chain and http://oeis.org/A265690 It seems that there is no closed form for it... – JetfiRex Feb 15 '22 at 05:08

1 Answers1

0

Not really an answer, but you can refer to wiki page and oeis to find the thing you need...

Also, this is the result by running the python code below:

import time
sets = {(1,)}
prev_union = {1}
union_11 = set()
ans = {1:0}
for i in range(1,11):
    if i<10:
        print("numbers that need",i,"adders to go")
        aux=set()
        union=set()
        for s in sets:
            for first in range(i):
                for second in range(first+1):
                    s1 = set(s)|{s[first]+s[second]}
                    if len(s1)==i+1:
                        aux.add(tuple(sorted(s1)))
                        union|=s1
        print(union-prev_union)
        prev_union=union
        sets=aux
    elif i==10:
        print("numbers that need",i,"adders to go")
        aux=set()
        union=set()
        for s in sets:
            for first in range(i):
                for second in range(first+1):
                    new = s[first]+s[second]
                    s1 = set(s)|{new}
                    if len(s1)==i+1:
                        aux.add(tuple(sorted(s1)))
                        union|=s1
                        union_11|=set(new+third for third in s1)
        print(union-prev_union)
        print("numbers that need 11 adders to go")
        print(union_11-union)

The result is here: (covers at least 1 to 378)

numbers that need 1 adders to go
{2}
numbers that need 2 adders to go
{3, 4}
numbers that need 3 adders to go
{8, 5, 6}
numbers that need 4 adders to go
{7, 9, 10, 12, 16}
numbers that need 5 adders to go
{32, 11, 13, 14, 15, 17, 18, 20, 24}
numbers that need 6 adders to go
{64, 33, 34, 36, 40, 48, 19, 21, 22, 23, 25, 26, 27, 28, 30}
numbers that need 7 adders to go
{128, 29, 31, 35, 37, 38, 39, 41, 42, 43, 44, 45, 46, 49, 50, 51, 52, 54, 56, 60, 65, 66, 68, 72, 80, 96}
numbers that need 8 adders to go
{256, 129, 130, 132, 136, 144, 160, 47, 53, 55, 57, 58, 59, 61, 62, 63, 192, 67, 69, 70, 73, 74, 75, 76, 77, 78, 81, 82, 83, 84, 85, 86, 88, 90, 92, 97, 98, 99, 100, 102, 104, 108, 112, 120}
numbers that need 9 adders to go
{512, 71, 79, 87, 89, 91, 93, 94, 95, 101, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 131, 133, 134, 135, 137, 138, 140, 145, 146, 147, 148, 149, 150, 152, 153, 154, 156, 161, 162, 163, 164, 165, 166, 168, 170, 172, 176, 180, 184, 193, 194, 195, 196, 198, 200, 204, 208, 216, 224, 240, 257, 258, 260, 264, 272, 288, 320, 384}
numbers that need 10 adders to go
{1024, 513, 514, 516, 520, 528, 544, 576, 127, 640, 139, 141, 142, 143, 151, 155, 157, 158, 159, 167, 169, 171, 173, 174, 175, 177, 178, 179, 181, 182, 183, 185, 186, 187, 188, 189, 190, 197, 199, 201, 202, 203, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 217, 218, 219, 220, 221, 222, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 236, 238, 241, 242, 243, 244, 245, 246, 248, 249, 250, 252, 255, 768, 259, 261, 262, 265, 266, 268, 270, 273, 274, 276, 280, 281, 289, 290, 291, 292, 293, 294, 296, 297, 298, 300, 304, 306, 308, 312, 321, 322, 323, 324, 325, 326, 328, 330, 332, 336, 340, 344, 352, 360, 368, 385, 386, 387, 388, 390, 392, 396, 400, 408, 416, 432, 448, 480}
numbers that need 11 adders to go
{2048, 1025, 1026, 1536, 515, 517, 518, 1028, 1032, 521, 522, 524, 1040, 529, 530, 532, 536, 540, 1056, 545, 546, 548, 552, 553, 560, 561, 562, 1088, 577, 578, 579, 580, 581, 582, 584, 585, 586, 588, 592, 594, 596, 600, 608, 612, 616, 624, 1152, 641, 642, 643, 644, 645, 646, 648, 650, 652, 656, 660, 664, 672, 680, 688, 191, 704, 720, 223, 736, 235, 237, 239, 247, 251, 253, 254, 1280, 769, 770, 771, 772, 774, 263, 776, 267, 780, 269, 271, 784, 275, 277, 278, 279, 792, 282, 283, 284, 285, 286, 287, 800, 295, 299, 301, 302, 303, 816, 305, 307, 309, 310, 311, 313, 314, 315, 316, 317, 318, 319, 832, 327, 329, 331, 333, 334, 335, 337, 338, 339, 341, 342, 343, 345, 346, 347, 348, 349, 350, 351, 864, 353, 354, 355, 356, 357, 358, 359, 361, 362, 363, 364, 365, 366, 367, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 380, 381, 382, 896, 389, 391, 393, 394, 395, 397, 398, 399, 401, 402, 403, 404, 405, 406, 409, 410, 411, 412, 413, 414, 415, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 428, 429, 430, 433, 434, 435, 436, 437, 438, 440, 441, 442, 444, 447, 960, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 462, 464, 466, 468, 472, 476, 481, 482, 483, 484, 485, 486, 488, 489, 490, 492, 495, 496, 498, 500, 504, 510}
JetfiRex
  • 2,451