# Extracting powers of a sum

Given a sum in the form

Sum[n^k, {k, kl}]


for some natural n and natural list kl, is it possible to extract the values of kl? In other words, I want to know if a sum of the form $$\sum_{i=1}^n n^{k_i}$$ uniquely determines the tuple $$(k_1,...,k_n)$$ (up to permutations). This seems true due to the uniqueness of base-$$n$$ representation, but I am not sure how to implement a function to extract the tuple $$(k_1,...,k_n)$$. Any ideas?

My attempt: Following the discussion here, I tried to use BaseForm. If we assume $$\{k_i\}$$ are different, then, as an example,

n = 3;
kl = {1, 2, 3};
BaseForm[Sum[n^k, {k, kl}], n]


yields $$1110_3$$ which tells me that kl = {1, 2, 3} (in no particular order). How can I produce this list from BaseForm? Alternatively, is there a way to transform the representation $$1110_3$$ into the list {1, 1, 1, 0}?

Also, in the case where $$\{k_i\}$$ are all the same, we may simply take

ConstantArray[Log[n, Sum[n^k, {k, kl}]] - 1, n]


Could a straightforward computation for both cases (equal $$\{k_i\}$$ and not) be done? Perhaps using base $$n+1$$ instead?

Edit: I forgot to mention. The length of kl must be exactly n. Apologies to whoever started working on this without this assumption.

• @JimB That works, given you know the list, correct? The idea is to not rely on the list. In general, I do not know its values, but I know the sum has that specific shape for some list of powers. Commented Jul 19, 2022 at 14:10
• Yes, but I am writing it in that way (poorly, perhaps), just to compute something in my example. In general, I can take S as any sum which I know can be written in that format (where kl is unknown), and apply BaseForm[S, n] to extract the uniquely defined powers. In other words, I am just confirming that I do get that list, as I would expect. I am wondering if I can do this more straightforwardly by looking at the $n+1$ case, for example. The way it is written seems a bit redundant, I agree, but if you look at the linked question on MathSE, it perhaps becomes clearer. Commented Jul 19, 2022 at 14:25
• @JimB Oh! You just reminded me of an important thing that I forgot to mention. The length of kl must be exactly n! Apologies, I will edit the question to add this. With this, the case kl = {1, 2, 2, 2, 2} is not valid. Commented Jul 19, 2022 at 14:50
• OK. Just one more: So for a given integer $m$, you're looking for an $n$ and $k_1,\ldots,k_n$ such that $m=\sum_{i=1}^n n^{k_i}$ and hoping there is just one solution?
– JimB
Commented Jul 19, 2022 at 15:01
• Yes, phrased differently, I think that is equivalent to what I am asking. Commented Jul 19, 2022 at 15:05

(* some prior computations... *)
n = 3;
kl = {1, 2, 3};
value = Sum[n^k, {k, kl}];


Now, assuming that you know what n was used,

IntegerDigits[value, 3]
(* returns {1, 1, 1, 0} *)


Edit I'm still not sure I entirely get the second part, but if the goal is to reconstruct the "exponent list" (we've been using the variable kl for this), then maybe this does what you want:

ToExponentList[base_, num_] :=
Flatten[
MapIndexed[ConstantArray[#2 - 1, #1] &, Reverse@IntegerDigits[num, base]]]


(probably a cleaner way to do this, but does this at least produce the correct behavior?)

Proof:

ToExponentList[3, Sum[3^k, {k, {1, 2, 3}}]] == {1, 2, 3}
ToExponentList[10, Sum[10^k, {k, {0, 0, 0, 1, 1, 2}}]] == {0, 0, 0, 1, 1, 2}


Edit 2

ToWolfeList[base_Integer, num_Integer] :=
With[
{digits = IntegerDigits[num, base]},
Which[
1 == Total[digits], ConstantArray[Length@digits - 2, base],
base != Total[digits], NullWolfeList[],
True, Flatten[MapIndexed[ConstantArray[#2 - 1, #1] &, Reverse@digits]]]]


It seems like if the sum of the digits does not equal the base, then there is no solution (so I return a NullWolfeList[]). If there is just a digit 1, then we construct a constant array of the appropriate value. Otherwise, we fall back to my previous implementation, which still feels too awkward, but I haven't thought of anything better without resorting to computing logs or some such.

• Great, I didn't know about IntegerDigits. However, that fails when kl = {3, 3, 3}, for example. Any way to include the cases when kl is a constant array? I have my approach, but I was wondering if I could get all at once. Commented Jul 19, 2022 at 14:28
• yeah, I don't understand that part of your question. Commented Jul 19, 2022 at 14:29
• Well, essentially, I want to avoid needing to test whether the value of the sum is a power of n. Because, if it is, then kl is a constant array, and the solution with BaseForm or IntegerDigits does not work. In that case, I compute the logarithm like I mentioned. This is a minor thing, but perhaps using a higher base, like n+1, could hint at a straightforward bijection between the sum values and the list of powers, kl. Commented Jul 19, 2022 at 14:35
• Please see the edit! It was obvious from the mathematical description, but just in case. Commented Jul 19, 2022 at 14:51
• okay, I had just glossed over the fact that n was a constraint on the number of terms in the sum. See edit #2 to my answer. Commented Jul 19, 2022 at 16:14