How to solve $1+sum_{k=1}^r 3^kbinom{n}{k}$ (using, say, $ S{n} = frac{a_1(1-r^n)}{1-r} $) so I can use it...












1














Following the solution to my previous post in:
Counting unique element output from a product of combination



where the number of unique string-variants generated from a given string is:



$$
1+sum_{k=1}^r 3^kbinom{n}{k}
$$



How to solve the summation so that I could use this formula for large $r$?



My attempt:
I try to solve it using a general formula:
$$
S{n} = frac{a_1(1-r^n)}{1-r}
$$

for $a = 3$ and the common factor $r = 3$. But it turns out that is wrong since the formula above did not has anything to do with the binomial coefficient. Anyone can help?










share|cite|improve this question
























  • Please try to make the titles of your questions more informative. For example, Why does $a<b$ imply $a+c<b+c$? is much more useful for other users than A question about inequality. From How can I ask a good question?: Make your title as descriptive as possible. In many cases one can actually phrase the title as the question, at least in such a way so as to be comprehensible to an expert reader. You can find more tips for choosing a good title here.
    – Shaun
    Dec 28 '18 at 7:21










  • I've edited the $LaTeX$. Did you mean $S{ n}$ or something else?
    – Shaun
    Dec 28 '18 at 7:21










  • What is an example of a large $r$? Are $n$ and $r$ integers? positive?
    – Eric Towers
    Dec 28 '18 at 7:27
















1














Following the solution to my previous post in:
Counting unique element output from a product of combination



where the number of unique string-variants generated from a given string is:



$$
1+sum_{k=1}^r 3^kbinom{n}{k}
$$



How to solve the summation so that I could use this formula for large $r$?



My attempt:
I try to solve it using a general formula:
$$
S{n} = frac{a_1(1-r^n)}{1-r}
$$

for $a = 3$ and the common factor $r = 3$. But it turns out that is wrong since the formula above did not has anything to do with the binomial coefficient. Anyone can help?










share|cite|improve this question
























  • Please try to make the titles of your questions more informative. For example, Why does $a<b$ imply $a+c<b+c$? is much more useful for other users than A question about inequality. From How can I ask a good question?: Make your title as descriptive as possible. In many cases one can actually phrase the title as the question, at least in such a way so as to be comprehensible to an expert reader. You can find more tips for choosing a good title here.
    – Shaun
    Dec 28 '18 at 7:21










  • I've edited the $LaTeX$. Did you mean $S{ n}$ or something else?
    – Shaun
    Dec 28 '18 at 7:21










  • What is an example of a large $r$? Are $n$ and $r$ integers? positive?
    – Eric Towers
    Dec 28 '18 at 7:27














1












1








1


1





Following the solution to my previous post in:
Counting unique element output from a product of combination



where the number of unique string-variants generated from a given string is:



$$
1+sum_{k=1}^r 3^kbinom{n}{k}
$$



How to solve the summation so that I could use this formula for large $r$?



My attempt:
I try to solve it using a general formula:
$$
S{n} = frac{a_1(1-r^n)}{1-r}
$$

for $a = 3$ and the common factor $r = 3$. But it turns out that is wrong since the formula above did not has anything to do with the binomial coefficient. Anyone can help?










share|cite|improve this question















Following the solution to my previous post in:
Counting unique element output from a product of combination



where the number of unique string-variants generated from a given string is:



$$
1+sum_{k=1}^r 3^kbinom{n}{k}
$$



How to solve the summation so that I could use this formula for large $r$?



My attempt:
I try to solve it using a general formula:
$$
S{n} = frac{a_1(1-r^n)}{1-r}
$$

for $a = 3$ and the common factor $r = 3$. But it turns out that is wrong since the formula above did not has anything to do with the binomial coefficient. Anyone can help?







combinatorics summation binomial-coefficients






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 28 '18 at 7:27









Shaun

8,805113680




8,805113680










asked Dec 28 '18 at 7:15









Vic Brown

113




113












  • Please try to make the titles of your questions more informative. For example, Why does $a<b$ imply $a+c<b+c$? is much more useful for other users than A question about inequality. From How can I ask a good question?: Make your title as descriptive as possible. In many cases one can actually phrase the title as the question, at least in such a way so as to be comprehensible to an expert reader. You can find more tips for choosing a good title here.
    – Shaun
    Dec 28 '18 at 7:21










  • I've edited the $LaTeX$. Did you mean $S{ n}$ or something else?
    – Shaun
    Dec 28 '18 at 7:21










  • What is an example of a large $r$? Are $n$ and $r$ integers? positive?
    – Eric Towers
    Dec 28 '18 at 7:27


















  • Please try to make the titles of your questions more informative. For example, Why does $a<b$ imply $a+c<b+c$? is much more useful for other users than A question about inequality. From How can I ask a good question?: Make your title as descriptive as possible. In many cases one can actually phrase the title as the question, at least in such a way so as to be comprehensible to an expert reader. You can find more tips for choosing a good title here.
    – Shaun
    Dec 28 '18 at 7:21










  • I've edited the $LaTeX$. Did you mean $S{ n}$ or something else?
    – Shaun
    Dec 28 '18 at 7:21










  • What is an example of a large $r$? Are $n$ and $r$ integers? positive?
    – Eric Towers
    Dec 28 '18 at 7:27
















Please try to make the titles of your questions more informative. For example, Why does $a<b$ imply $a+c<b+c$? is much more useful for other users than A question about inequality. From How can I ask a good question?: Make your title as descriptive as possible. In many cases one can actually phrase the title as the question, at least in such a way so as to be comprehensible to an expert reader. You can find more tips for choosing a good title here.
– Shaun
Dec 28 '18 at 7:21




Please try to make the titles of your questions more informative. For example, Why does $a<b$ imply $a+c<b+c$? is much more useful for other users than A question about inequality. From How can I ask a good question?: Make your title as descriptive as possible. In many cases one can actually phrase the title as the question, at least in such a way so as to be comprehensible to an expert reader. You can find more tips for choosing a good title here.
– Shaun
Dec 28 '18 at 7:21












I've edited the $LaTeX$. Did you mean $S{ n}$ or something else?
– Shaun
Dec 28 '18 at 7:21




I've edited the $LaTeX$. Did you mean $S{ n}$ or something else?
– Shaun
Dec 28 '18 at 7:21












What is an example of a large $r$? Are $n$ and $r$ integers? positive?
– Eric Towers
Dec 28 '18 at 7:27




What is an example of a large $r$? Are $n$ and $r$ integers? positive?
– Eric Towers
Dec 28 '18 at 7:27










2 Answers
2






active

oldest

votes


















2














This sum does not have an elementary representation. Let $f(r,n)$ be your sum. By a CAS
begin{align*}
f(r,n) &= 1 + sum_{k=1}^r 3^k binom{n}{k} \
&= 4^n - 3^{r+1}binom{n}{r+1}{}_2F_1(1,r-n+1;r+2;-3)
end{align*}



where ${}_2F_1$ is the Gaussian hypergeometric function. Even assuming $r$ and $n$ integers with $0 < r < n$, there are no simplifications to elementary functions.



For $1 leq r < n$, use the sum. This is easy as long as $n$ is not large. You give no hints about the size of $n$ in your question. Your prior post claims you are only interested in $1 leq r leq 4$, so this sum is nearly immediate.



For $r geq n$, $f(r,n) = 4^n$. This follows from your sum since $binom{n}{n+1} = binom{n}{n+2} = cdots = 0$, so the sum cuts itself off after $r = n$, and a standard identity (first one at that link, taking $x = 3$ and realizing the $k = 0$ term is the "$1+$" in $f$). In the context of your previous post (not having read it in detail) -- once you've decided to replace every character in your string, then you have any $n$-length string you want from your 4 character alphabet, giving $4^n$ possibilities.





Digging through OP's referenced Question, he most likely intends $1 leq r leq 4$ and $r leq n$. These constraints appear nowhere in the current Question. With those constraints ...
begin{align*}
f(1,n) &= 1 + 3n text{,} \
f(2,n) &= 1 + 3n + frac{9}{2}n(n-1) text{,} \
f(3,n) &= frac{1}{2}(9n^2 -3n+2) + frac{9}{2}n(n-1)(n-2) text{, and} \
f(4,n) &= frac{1}{2}(9n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.}
end{align*}



For example, $f(4,10,000) = 33,734,252,812,372,501$. I note this because representing such quantities in a programming language as precise integers (instead of imprecise floating point approximations) can require some effort. Letting $r$ and $n$ be "large" necessitates this effort. If you intend to generate these numbers in a programming language, it would help to know which language you are targetting.





Just testing for timing, I get the complete set of results for $n = 10,000$ in about 180 ms using this code:



import itertools
import time

class sumterm:
"""Iterator to produce terms of a specific sum counting replaced strings."""
def __init__(self, nInit):
# Rememember: Iterators start in a "prior to the first element" state
# and are expected to yield the first element on the first call to
# __next__().
self.n = nInit
self.k = 0
self.term = 1 # 3^k binom(n,k) = 1 binom(n,0) = 1, when k = 0

def __iter__(self):
try: self.n
except NameError: raise ValueError("sumterm objects must be initialized before iterating.")

return self

def __next__(self):
if self.k < self.n:
# 3^(k+1) binom(n,k+1) = 3^k binom(n,k) * 3(n-k)/(k+1)
# Integer division ( // ) is safe because divisibility is ensured.
self.term = self.term * 3*(self.n - self.k) // (self.k+1)
self.k += 1
return self.term
else:
raise StopIteration

n = 10000
tBefore = time.time()
terms = list(iter(sumterm(n)))
partialSums = [1+x for x in itertools.accumulate(terms) ]
tAfter = time.time()

print("For n = ", n, ", k = 1 .. 11: ", partialSums[:11])
print("Took", tAfter - tBefore, " seconds.")


Don't bother trying to print the last few terms. $4^{10,000}$ is too large to usefully look at.



Note that partialSums[k-1] is $f(k,n)$ for $k leq n$.





begin{align*}
f(1,n) &= 1 + sum_{k=1}^1 3^k binom{n}{k} \
&= 1 + 3^1 binom{n}{1} \
&= 1 + 3 n text{, } \
f(2,n) &= 1 + sum_{k=1}^2 3^k binom{n}{k} \
&= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} \
&= 1 + 3 n + 9frac{n(n-1)}{2} text{, } \
f(3,n) &= 1 + sum_{k=1}^3 3^k binom{n}{k} \
&= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} \
&= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} \
&= frac{1}{2}(2 + 6n + 9n(n-1)) + frac{9}{2}n(n-1)(n-2) \
&= frac{1}{2}(9n^2 - 3 n + 2) + frac{9}{2}n(n-1)(n-2) text{,}
end{align*}

and
begin{align*}
f(4,n) &= 1 + sum_{k=1}^4 3^k binom{n}{k} \
&= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} + 3^4 binom{n}{4} \
&= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} + 81frac{n(n-1)(n-2)(n-3)}{24} \
&= frac{1}{2}(2 + 6n + 9n(n-1) + 9n(n-1)(n-2)) + frac{27}{8}n(n-1)(n-2)(n-3) \
&= frac{1}{2}(9 n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.} \
end{align*}






share|cite|improve this answer























  • Thanks. Yes, I only intend to use $1 leq r < 4$ since the substituents only composed of four characters. I am just curious whether the formula $1+sum_{k=1}^r 3^kbinom{n}{k}$ could be simplified to elementary function so that it could be used for n let's say 10,000 and r at most equals to n. Sum it up for such n and r would be cumbersome.
    – Vic Brown
    Dec 30 '18 at 5:35










  • @VicBrown : So it can't be simplified to an elementary function. Perhaps it can be approximated with something elementary. Would an approximation (and if so, how precise and accurate would you require) suffice?
    – Eric Towers
    Dec 30 '18 at 18:25










  • @VicBrown : Officially, answers to questions on this site are evaluated (by the crowds) as answers to the Question as asked. Your Question does not include the constraints $1 leq r leq 4$ and $r leq n$, which I infer from your referenced question. Since those are not part of the current question, they cannot be assumed in an Answer.
    – Eric Towers
    Dec 30 '18 at 22:57










  • @VicBrown : As the extension to my question shows, for $n = 10,000$, $f(r,n)$ quickly exceeds usual integral representations in some programming languages. If you intend to compute these with software, it would be helpful to know what your targetted software is.
    – Eric Towers
    Dec 30 '18 at 23:16












  • Your solution above and it is similar to what I solve using polynomial equation for r = 1 to 4 and n = 3 to 10, where: $$ f(1,n) = 3n + 1 $$ $$ f(2,n) = frac{9}{2}n^2 - frac{3}{2}n + 1 $$ $$ f(3,n) = frac{27}{6}n^3 - 9n^2 + 15n + 1 $$ $$ f(4,n) = frac{27}{8}n^4 - frac{63}{4}n^3 + frac{225}{8}n^2 - frac{51}{4}n + 1 $$ I do not intend to apply such equation into my program (I am using Python 3 by the way). I just only wanted to provide mathematical proof that a list of unique string variants generated by the program is correct.
    – Vic Brown
    Dec 31 '18 at 5:36





















0














In case you are interested in asymptotics:



$$begin{align}
s(n,r)&=sum_{k=1}^r 3^kbinom{n}{k}\
&=2^nsum_{k=1}^r 3^kfrac{binom{n}{k}}{2^n}\
&approx frac{2^n}{sqrt{pi n /2}} int_0^r 3^x expleft( -frac{2}{n}(x-n/2)^2 right)
dx \
end{align}$$



If $r > 0.78 n$ we can apply Laplace's method and get the first order approximation:



$$ frac{log (s(n,r))}{n} to log(2) + frac{log^2(3)+ 4 log 3}{8}approx 1.393$$



For smaller $r$ , a similar approximation can be obtained (tell me if you are interested) but it involves both $(n,r)$ variables.






share|cite|improve this answer























    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "69"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3054644%2fhow-to-solve-1-sum-k-1r-3k-binomnk-using-say-s-n-fraca-1%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    This sum does not have an elementary representation. Let $f(r,n)$ be your sum. By a CAS
    begin{align*}
    f(r,n) &= 1 + sum_{k=1}^r 3^k binom{n}{k} \
    &= 4^n - 3^{r+1}binom{n}{r+1}{}_2F_1(1,r-n+1;r+2;-3)
    end{align*}



    where ${}_2F_1$ is the Gaussian hypergeometric function. Even assuming $r$ and $n$ integers with $0 < r < n$, there are no simplifications to elementary functions.



    For $1 leq r < n$, use the sum. This is easy as long as $n$ is not large. You give no hints about the size of $n$ in your question. Your prior post claims you are only interested in $1 leq r leq 4$, so this sum is nearly immediate.



    For $r geq n$, $f(r,n) = 4^n$. This follows from your sum since $binom{n}{n+1} = binom{n}{n+2} = cdots = 0$, so the sum cuts itself off after $r = n$, and a standard identity (first one at that link, taking $x = 3$ and realizing the $k = 0$ term is the "$1+$" in $f$). In the context of your previous post (not having read it in detail) -- once you've decided to replace every character in your string, then you have any $n$-length string you want from your 4 character alphabet, giving $4^n$ possibilities.





    Digging through OP's referenced Question, he most likely intends $1 leq r leq 4$ and $r leq n$. These constraints appear nowhere in the current Question. With those constraints ...
    begin{align*}
    f(1,n) &= 1 + 3n text{,} \
    f(2,n) &= 1 + 3n + frac{9}{2}n(n-1) text{,} \
    f(3,n) &= frac{1}{2}(9n^2 -3n+2) + frac{9}{2}n(n-1)(n-2) text{, and} \
    f(4,n) &= frac{1}{2}(9n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.}
    end{align*}



    For example, $f(4,10,000) = 33,734,252,812,372,501$. I note this because representing such quantities in a programming language as precise integers (instead of imprecise floating point approximations) can require some effort. Letting $r$ and $n$ be "large" necessitates this effort. If you intend to generate these numbers in a programming language, it would help to know which language you are targetting.





    Just testing for timing, I get the complete set of results for $n = 10,000$ in about 180 ms using this code:



    import itertools
    import time

    class sumterm:
    """Iterator to produce terms of a specific sum counting replaced strings."""
    def __init__(self, nInit):
    # Rememember: Iterators start in a "prior to the first element" state
    # and are expected to yield the first element on the first call to
    # __next__().
    self.n = nInit
    self.k = 0
    self.term = 1 # 3^k binom(n,k) = 1 binom(n,0) = 1, when k = 0

    def __iter__(self):
    try: self.n
    except NameError: raise ValueError("sumterm objects must be initialized before iterating.")

    return self

    def __next__(self):
    if self.k < self.n:
    # 3^(k+1) binom(n,k+1) = 3^k binom(n,k) * 3(n-k)/(k+1)
    # Integer division ( // ) is safe because divisibility is ensured.
    self.term = self.term * 3*(self.n - self.k) // (self.k+1)
    self.k += 1
    return self.term
    else:
    raise StopIteration

    n = 10000
    tBefore = time.time()
    terms = list(iter(sumterm(n)))
    partialSums = [1+x for x in itertools.accumulate(terms) ]
    tAfter = time.time()

    print("For n = ", n, ", k = 1 .. 11: ", partialSums[:11])
    print("Took", tAfter - tBefore, " seconds.")


    Don't bother trying to print the last few terms. $4^{10,000}$ is too large to usefully look at.



    Note that partialSums[k-1] is $f(k,n)$ for $k leq n$.





    begin{align*}
    f(1,n) &= 1 + sum_{k=1}^1 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} \
    &= 1 + 3 n text{, } \
    f(2,n) &= 1 + sum_{k=1}^2 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} text{, } \
    f(3,n) &= 1 + sum_{k=1}^3 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} \
    &= frac{1}{2}(2 + 6n + 9n(n-1)) + frac{9}{2}n(n-1)(n-2) \
    &= frac{1}{2}(9n^2 - 3 n + 2) + frac{9}{2}n(n-1)(n-2) text{,}
    end{align*}

    and
    begin{align*}
    f(4,n) &= 1 + sum_{k=1}^4 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} + 3^4 binom{n}{4} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} + 81frac{n(n-1)(n-2)(n-3)}{24} \
    &= frac{1}{2}(2 + 6n + 9n(n-1) + 9n(n-1)(n-2)) + frac{27}{8}n(n-1)(n-2)(n-3) \
    &= frac{1}{2}(9 n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.} \
    end{align*}






    share|cite|improve this answer























    • Thanks. Yes, I only intend to use $1 leq r < 4$ since the substituents only composed of four characters. I am just curious whether the formula $1+sum_{k=1}^r 3^kbinom{n}{k}$ could be simplified to elementary function so that it could be used for n let's say 10,000 and r at most equals to n. Sum it up for such n and r would be cumbersome.
      – Vic Brown
      Dec 30 '18 at 5:35










    • @VicBrown : So it can't be simplified to an elementary function. Perhaps it can be approximated with something elementary. Would an approximation (and if so, how precise and accurate would you require) suffice?
      – Eric Towers
      Dec 30 '18 at 18:25










    • @VicBrown : Officially, answers to questions on this site are evaluated (by the crowds) as answers to the Question as asked. Your Question does not include the constraints $1 leq r leq 4$ and $r leq n$, which I infer from your referenced question. Since those are not part of the current question, they cannot be assumed in an Answer.
      – Eric Towers
      Dec 30 '18 at 22:57










    • @VicBrown : As the extension to my question shows, for $n = 10,000$, $f(r,n)$ quickly exceeds usual integral representations in some programming languages. If you intend to compute these with software, it would be helpful to know what your targetted software is.
      – Eric Towers
      Dec 30 '18 at 23:16












    • Your solution above and it is similar to what I solve using polynomial equation for r = 1 to 4 and n = 3 to 10, where: $$ f(1,n) = 3n + 1 $$ $$ f(2,n) = frac{9}{2}n^2 - frac{3}{2}n + 1 $$ $$ f(3,n) = frac{27}{6}n^3 - 9n^2 + 15n + 1 $$ $$ f(4,n) = frac{27}{8}n^4 - frac{63}{4}n^3 + frac{225}{8}n^2 - frac{51}{4}n + 1 $$ I do not intend to apply such equation into my program (I am using Python 3 by the way). I just only wanted to provide mathematical proof that a list of unique string variants generated by the program is correct.
      – Vic Brown
      Dec 31 '18 at 5:36


















    2














    This sum does not have an elementary representation. Let $f(r,n)$ be your sum. By a CAS
    begin{align*}
    f(r,n) &= 1 + sum_{k=1}^r 3^k binom{n}{k} \
    &= 4^n - 3^{r+1}binom{n}{r+1}{}_2F_1(1,r-n+1;r+2;-3)
    end{align*}



    where ${}_2F_1$ is the Gaussian hypergeometric function. Even assuming $r$ and $n$ integers with $0 < r < n$, there are no simplifications to elementary functions.



    For $1 leq r < n$, use the sum. This is easy as long as $n$ is not large. You give no hints about the size of $n$ in your question. Your prior post claims you are only interested in $1 leq r leq 4$, so this sum is nearly immediate.



    For $r geq n$, $f(r,n) = 4^n$. This follows from your sum since $binom{n}{n+1} = binom{n}{n+2} = cdots = 0$, so the sum cuts itself off after $r = n$, and a standard identity (first one at that link, taking $x = 3$ and realizing the $k = 0$ term is the "$1+$" in $f$). In the context of your previous post (not having read it in detail) -- once you've decided to replace every character in your string, then you have any $n$-length string you want from your 4 character alphabet, giving $4^n$ possibilities.





    Digging through OP's referenced Question, he most likely intends $1 leq r leq 4$ and $r leq n$. These constraints appear nowhere in the current Question. With those constraints ...
    begin{align*}
    f(1,n) &= 1 + 3n text{,} \
    f(2,n) &= 1 + 3n + frac{9}{2}n(n-1) text{,} \
    f(3,n) &= frac{1}{2}(9n^2 -3n+2) + frac{9}{2}n(n-1)(n-2) text{, and} \
    f(4,n) &= frac{1}{2}(9n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.}
    end{align*}



    For example, $f(4,10,000) = 33,734,252,812,372,501$. I note this because representing such quantities in a programming language as precise integers (instead of imprecise floating point approximations) can require some effort. Letting $r$ and $n$ be "large" necessitates this effort. If you intend to generate these numbers in a programming language, it would help to know which language you are targetting.





    Just testing for timing, I get the complete set of results for $n = 10,000$ in about 180 ms using this code:



    import itertools
    import time

    class sumterm:
    """Iterator to produce terms of a specific sum counting replaced strings."""
    def __init__(self, nInit):
    # Rememember: Iterators start in a "prior to the first element" state
    # and are expected to yield the first element on the first call to
    # __next__().
    self.n = nInit
    self.k = 0
    self.term = 1 # 3^k binom(n,k) = 1 binom(n,0) = 1, when k = 0

    def __iter__(self):
    try: self.n
    except NameError: raise ValueError("sumterm objects must be initialized before iterating.")

    return self

    def __next__(self):
    if self.k < self.n:
    # 3^(k+1) binom(n,k+1) = 3^k binom(n,k) * 3(n-k)/(k+1)
    # Integer division ( // ) is safe because divisibility is ensured.
    self.term = self.term * 3*(self.n - self.k) // (self.k+1)
    self.k += 1
    return self.term
    else:
    raise StopIteration

    n = 10000
    tBefore = time.time()
    terms = list(iter(sumterm(n)))
    partialSums = [1+x for x in itertools.accumulate(terms) ]
    tAfter = time.time()

    print("For n = ", n, ", k = 1 .. 11: ", partialSums[:11])
    print("Took", tAfter - tBefore, " seconds.")


    Don't bother trying to print the last few terms. $4^{10,000}$ is too large to usefully look at.



    Note that partialSums[k-1] is $f(k,n)$ for $k leq n$.





    begin{align*}
    f(1,n) &= 1 + sum_{k=1}^1 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} \
    &= 1 + 3 n text{, } \
    f(2,n) &= 1 + sum_{k=1}^2 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} text{, } \
    f(3,n) &= 1 + sum_{k=1}^3 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} \
    &= frac{1}{2}(2 + 6n + 9n(n-1)) + frac{9}{2}n(n-1)(n-2) \
    &= frac{1}{2}(9n^2 - 3 n + 2) + frac{9}{2}n(n-1)(n-2) text{,}
    end{align*}

    and
    begin{align*}
    f(4,n) &= 1 + sum_{k=1}^4 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} + 3^4 binom{n}{4} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} + 81frac{n(n-1)(n-2)(n-3)}{24} \
    &= frac{1}{2}(2 + 6n + 9n(n-1) + 9n(n-1)(n-2)) + frac{27}{8}n(n-1)(n-2)(n-3) \
    &= frac{1}{2}(9 n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.} \
    end{align*}






    share|cite|improve this answer























    • Thanks. Yes, I only intend to use $1 leq r < 4$ since the substituents only composed of four characters. I am just curious whether the formula $1+sum_{k=1}^r 3^kbinom{n}{k}$ could be simplified to elementary function so that it could be used for n let's say 10,000 and r at most equals to n. Sum it up for such n and r would be cumbersome.
      – Vic Brown
      Dec 30 '18 at 5:35










    • @VicBrown : So it can't be simplified to an elementary function. Perhaps it can be approximated with something elementary. Would an approximation (and if so, how precise and accurate would you require) suffice?
      – Eric Towers
      Dec 30 '18 at 18:25










    • @VicBrown : Officially, answers to questions on this site are evaluated (by the crowds) as answers to the Question as asked. Your Question does not include the constraints $1 leq r leq 4$ and $r leq n$, which I infer from your referenced question. Since those are not part of the current question, they cannot be assumed in an Answer.
      – Eric Towers
      Dec 30 '18 at 22:57










    • @VicBrown : As the extension to my question shows, for $n = 10,000$, $f(r,n)$ quickly exceeds usual integral representations in some programming languages. If you intend to compute these with software, it would be helpful to know what your targetted software is.
      – Eric Towers
      Dec 30 '18 at 23:16












    • Your solution above and it is similar to what I solve using polynomial equation for r = 1 to 4 and n = 3 to 10, where: $$ f(1,n) = 3n + 1 $$ $$ f(2,n) = frac{9}{2}n^2 - frac{3}{2}n + 1 $$ $$ f(3,n) = frac{27}{6}n^3 - 9n^2 + 15n + 1 $$ $$ f(4,n) = frac{27}{8}n^4 - frac{63}{4}n^3 + frac{225}{8}n^2 - frac{51}{4}n + 1 $$ I do not intend to apply such equation into my program (I am using Python 3 by the way). I just only wanted to provide mathematical proof that a list of unique string variants generated by the program is correct.
      – Vic Brown
      Dec 31 '18 at 5:36
















    2












    2








    2






    This sum does not have an elementary representation. Let $f(r,n)$ be your sum. By a CAS
    begin{align*}
    f(r,n) &= 1 + sum_{k=1}^r 3^k binom{n}{k} \
    &= 4^n - 3^{r+1}binom{n}{r+1}{}_2F_1(1,r-n+1;r+2;-3)
    end{align*}



    where ${}_2F_1$ is the Gaussian hypergeometric function. Even assuming $r$ and $n$ integers with $0 < r < n$, there are no simplifications to elementary functions.



    For $1 leq r < n$, use the sum. This is easy as long as $n$ is not large. You give no hints about the size of $n$ in your question. Your prior post claims you are only interested in $1 leq r leq 4$, so this sum is nearly immediate.



    For $r geq n$, $f(r,n) = 4^n$. This follows from your sum since $binom{n}{n+1} = binom{n}{n+2} = cdots = 0$, so the sum cuts itself off after $r = n$, and a standard identity (first one at that link, taking $x = 3$ and realizing the $k = 0$ term is the "$1+$" in $f$). In the context of your previous post (not having read it in detail) -- once you've decided to replace every character in your string, then you have any $n$-length string you want from your 4 character alphabet, giving $4^n$ possibilities.





    Digging through OP's referenced Question, he most likely intends $1 leq r leq 4$ and $r leq n$. These constraints appear nowhere in the current Question. With those constraints ...
    begin{align*}
    f(1,n) &= 1 + 3n text{,} \
    f(2,n) &= 1 + 3n + frac{9}{2}n(n-1) text{,} \
    f(3,n) &= frac{1}{2}(9n^2 -3n+2) + frac{9}{2}n(n-1)(n-2) text{, and} \
    f(4,n) &= frac{1}{2}(9n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.}
    end{align*}



    For example, $f(4,10,000) = 33,734,252,812,372,501$. I note this because representing such quantities in a programming language as precise integers (instead of imprecise floating point approximations) can require some effort. Letting $r$ and $n$ be "large" necessitates this effort. If you intend to generate these numbers in a programming language, it would help to know which language you are targetting.





    Just testing for timing, I get the complete set of results for $n = 10,000$ in about 180 ms using this code:



    import itertools
    import time

    class sumterm:
    """Iterator to produce terms of a specific sum counting replaced strings."""
    def __init__(self, nInit):
    # Rememember: Iterators start in a "prior to the first element" state
    # and are expected to yield the first element on the first call to
    # __next__().
    self.n = nInit
    self.k = 0
    self.term = 1 # 3^k binom(n,k) = 1 binom(n,0) = 1, when k = 0

    def __iter__(self):
    try: self.n
    except NameError: raise ValueError("sumterm objects must be initialized before iterating.")

    return self

    def __next__(self):
    if self.k < self.n:
    # 3^(k+1) binom(n,k+1) = 3^k binom(n,k) * 3(n-k)/(k+1)
    # Integer division ( // ) is safe because divisibility is ensured.
    self.term = self.term * 3*(self.n - self.k) // (self.k+1)
    self.k += 1
    return self.term
    else:
    raise StopIteration

    n = 10000
    tBefore = time.time()
    terms = list(iter(sumterm(n)))
    partialSums = [1+x for x in itertools.accumulate(terms) ]
    tAfter = time.time()

    print("For n = ", n, ", k = 1 .. 11: ", partialSums[:11])
    print("Took", tAfter - tBefore, " seconds.")


    Don't bother trying to print the last few terms. $4^{10,000}$ is too large to usefully look at.



    Note that partialSums[k-1] is $f(k,n)$ for $k leq n$.





    begin{align*}
    f(1,n) &= 1 + sum_{k=1}^1 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} \
    &= 1 + 3 n text{, } \
    f(2,n) &= 1 + sum_{k=1}^2 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} text{, } \
    f(3,n) &= 1 + sum_{k=1}^3 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} \
    &= frac{1}{2}(2 + 6n + 9n(n-1)) + frac{9}{2}n(n-1)(n-2) \
    &= frac{1}{2}(9n^2 - 3 n + 2) + frac{9}{2}n(n-1)(n-2) text{,}
    end{align*}

    and
    begin{align*}
    f(4,n) &= 1 + sum_{k=1}^4 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} + 3^4 binom{n}{4} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} + 81frac{n(n-1)(n-2)(n-3)}{24} \
    &= frac{1}{2}(2 + 6n + 9n(n-1) + 9n(n-1)(n-2)) + frac{27}{8}n(n-1)(n-2)(n-3) \
    &= frac{1}{2}(9 n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.} \
    end{align*}






    share|cite|improve this answer














    This sum does not have an elementary representation. Let $f(r,n)$ be your sum. By a CAS
    begin{align*}
    f(r,n) &= 1 + sum_{k=1}^r 3^k binom{n}{k} \
    &= 4^n - 3^{r+1}binom{n}{r+1}{}_2F_1(1,r-n+1;r+2;-3)
    end{align*}



    where ${}_2F_1$ is the Gaussian hypergeometric function. Even assuming $r$ and $n$ integers with $0 < r < n$, there are no simplifications to elementary functions.



    For $1 leq r < n$, use the sum. This is easy as long as $n$ is not large. You give no hints about the size of $n$ in your question. Your prior post claims you are only interested in $1 leq r leq 4$, so this sum is nearly immediate.



    For $r geq n$, $f(r,n) = 4^n$. This follows from your sum since $binom{n}{n+1} = binom{n}{n+2} = cdots = 0$, so the sum cuts itself off after $r = n$, and a standard identity (first one at that link, taking $x = 3$ and realizing the $k = 0$ term is the "$1+$" in $f$). In the context of your previous post (not having read it in detail) -- once you've decided to replace every character in your string, then you have any $n$-length string you want from your 4 character alphabet, giving $4^n$ possibilities.





    Digging through OP's referenced Question, he most likely intends $1 leq r leq 4$ and $r leq n$. These constraints appear nowhere in the current Question. With those constraints ...
    begin{align*}
    f(1,n) &= 1 + 3n text{,} \
    f(2,n) &= 1 + 3n + frac{9}{2}n(n-1) text{,} \
    f(3,n) &= frac{1}{2}(9n^2 -3n+2) + frac{9}{2}n(n-1)(n-2) text{, and} \
    f(4,n) &= frac{1}{2}(9n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.}
    end{align*}



    For example, $f(4,10,000) = 33,734,252,812,372,501$. I note this because representing such quantities in a programming language as precise integers (instead of imprecise floating point approximations) can require some effort. Letting $r$ and $n$ be "large" necessitates this effort. If you intend to generate these numbers in a programming language, it would help to know which language you are targetting.





    Just testing for timing, I get the complete set of results for $n = 10,000$ in about 180 ms using this code:



    import itertools
    import time

    class sumterm:
    """Iterator to produce terms of a specific sum counting replaced strings."""
    def __init__(self, nInit):
    # Rememember: Iterators start in a "prior to the first element" state
    # and are expected to yield the first element on the first call to
    # __next__().
    self.n = nInit
    self.k = 0
    self.term = 1 # 3^k binom(n,k) = 1 binom(n,0) = 1, when k = 0

    def __iter__(self):
    try: self.n
    except NameError: raise ValueError("sumterm objects must be initialized before iterating.")

    return self

    def __next__(self):
    if self.k < self.n:
    # 3^(k+1) binom(n,k+1) = 3^k binom(n,k) * 3(n-k)/(k+1)
    # Integer division ( // ) is safe because divisibility is ensured.
    self.term = self.term * 3*(self.n - self.k) // (self.k+1)
    self.k += 1
    return self.term
    else:
    raise StopIteration

    n = 10000
    tBefore = time.time()
    terms = list(iter(sumterm(n)))
    partialSums = [1+x for x in itertools.accumulate(terms) ]
    tAfter = time.time()

    print("For n = ", n, ", k = 1 .. 11: ", partialSums[:11])
    print("Took", tAfter - tBefore, " seconds.")


    Don't bother trying to print the last few terms. $4^{10,000}$ is too large to usefully look at.



    Note that partialSums[k-1] is $f(k,n)$ for $k leq n$.





    begin{align*}
    f(1,n) &= 1 + sum_{k=1}^1 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} \
    &= 1 + 3 n text{, } \
    f(2,n) &= 1 + sum_{k=1}^2 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} text{, } \
    f(3,n) &= 1 + sum_{k=1}^3 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} \
    &= frac{1}{2}(2 + 6n + 9n(n-1)) + frac{9}{2}n(n-1)(n-2) \
    &= frac{1}{2}(9n^2 - 3 n + 2) + frac{9}{2}n(n-1)(n-2) text{,}
    end{align*}

    and
    begin{align*}
    f(4,n) &= 1 + sum_{k=1}^4 3^k binom{n}{k} \
    &= 1 + 3^1 binom{n}{1} + 3^2 binom{n}{2} + 3^3 binom{n}{3} + 3^4 binom{n}{4} \
    &= 1 + 3 n + 9frac{n(n-1)}{2} + 27frac{n(n-1)(n-2)}{6} + 81frac{n(n-1)(n-2)(n-3)}{24} \
    &= frac{1}{2}(2 + 6n + 9n(n-1) + 9n(n-1)(n-2)) + frac{27}{8}n(n-1)(n-2)(n-3) \
    &= frac{1}{2}(9 n^3 - 18 n^2 + 15 n + 2) + frac{27}{8}n(n-1)(n-2)(n-3) text{.} \
    end{align*}







    share|cite|improve this answer














    share|cite|improve this answer



    share|cite|improve this answer








    edited 2 days ago

























    answered Dec 28 '18 at 8:12









    Eric Towers

    31.9k22265




    31.9k22265












    • Thanks. Yes, I only intend to use $1 leq r < 4$ since the substituents only composed of four characters. I am just curious whether the formula $1+sum_{k=1}^r 3^kbinom{n}{k}$ could be simplified to elementary function so that it could be used for n let's say 10,000 and r at most equals to n. Sum it up for such n and r would be cumbersome.
      – Vic Brown
      Dec 30 '18 at 5:35










    • @VicBrown : So it can't be simplified to an elementary function. Perhaps it can be approximated with something elementary. Would an approximation (and if so, how precise and accurate would you require) suffice?
      – Eric Towers
      Dec 30 '18 at 18:25










    • @VicBrown : Officially, answers to questions on this site are evaluated (by the crowds) as answers to the Question as asked. Your Question does not include the constraints $1 leq r leq 4$ and $r leq n$, which I infer from your referenced question. Since those are not part of the current question, they cannot be assumed in an Answer.
      – Eric Towers
      Dec 30 '18 at 22:57










    • @VicBrown : As the extension to my question shows, for $n = 10,000$, $f(r,n)$ quickly exceeds usual integral representations in some programming languages. If you intend to compute these with software, it would be helpful to know what your targetted software is.
      – Eric Towers
      Dec 30 '18 at 23:16












    • Your solution above and it is similar to what I solve using polynomial equation for r = 1 to 4 and n = 3 to 10, where: $$ f(1,n) = 3n + 1 $$ $$ f(2,n) = frac{9}{2}n^2 - frac{3}{2}n + 1 $$ $$ f(3,n) = frac{27}{6}n^3 - 9n^2 + 15n + 1 $$ $$ f(4,n) = frac{27}{8}n^4 - frac{63}{4}n^3 + frac{225}{8}n^2 - frac{51}{4}n + 1 $$ I do not intend to apply such equation into my program (I am using Python 3 by the way). I just only wanted to provide mathematical proof that a list of unique string variants generated by the program is correct.
      – Vic Brown
      Dec 31 '18 at 5:36




















    • Thanks. Yes, I only intend to use $1 leq r < 4$ since the substituents only composed of four characters. I am just curious whether the formula $1+sum_{k=1}^r 3^kbinom{n}{k}$ could be simplified to elementary function so that it could be used for n let's say 10,000 and r at most equals to n. Sum it up for such n and r would be cumbersome.
      – Vic Brown
      Dec 30 '18 at 5:35










    • @VicBrown : So it can't be simplified to an elementary function. Perhaps it can be approximated with something elementary. Would an approximation (and if so, how precise and accurate would you require) suffice?
      – Eric Towers
      Dec 30 '18 at 18:25










    • @VicBrown : Officially, answers to questions on this site are evaluated (by the crowds) as answers to the Question as asked. Your Question does not include the constraints $1 leq r leq 4$ and $r leq n$, which I infer from your referenced question. Since those are not part of the current question, they cannot be assumed in an Answer.
      – Eric Towers
      Dec 30 '18 at 22:57










    • @VicBrown : As the extension to my question shows, for $n = 10,000$, $f(r,n)$ quickly exceeds usual integral representations in some programming languages. If you intend to compute these with software, it would be helpful to know what your targetted software is.
      – Eric Towers
      Dec 30 '18 at 23:16












    • Your solution above and it is similar to what I solve using polynomial equation for r = 1 to 4 and n = 3 to 10, where: $$ f(1,n) = 3n + 1 $$ $$ f(2,n) = frac{9}{2}n^2 - frac{3}{2}n + 1 $$ $$ f(3,n) = frac{27}{6}n^3 - 9n^2 + 15n + 1 $$ $$ f(4,n) = frac{27}{8}n^4 - frac{63}{4}n^3 + frac{225}{8}n^2 - frac{51}{4}n + 1 $$ I do not intend to apply such equation into my program (I am using Python 3 by the way). I just only wanted to provide mathematical proof that a list of unique string variants generated by the program is correct.
      – Vic Brown
      Dec 31 '18 at 5:36


















    Thanks. Yes, I only intend to use $1 leq r < 4$ since the substituents only composed of four characters. I am just curious whether the formula $1+sum_{k=1}^r 3^kbinom{n}{k}$ could be simplified to elementary function so that it could be used for n let's say 10,000 and r at most equals to n. Sum it up for such n and r would be cumbersome.
    – Vic Brown
    Dec 30 '18 at 5:35




    Thanks. Yes, I only intend to use $1 leq r < 4$ since the substituents only composed of four characters. I am just curious whether the formula $1+sum_{k=1}^r 3^kbinom{n}{k}$ could be simplified to elementary function so that it could be used for n let's say 10,000 and r at most equals to n. Sum it up for such n and r would be cumbersome.
    – Vic Brown
    Dec 30 '18 at 5:35












    @VicBrown : So it can't be simplified to an elementary function. Perhaps it can be approximated with something elementary. Would an approximation (and if so, how precise and accurate would you require) suffice?
    – Eric Towers
    Dec 30 '18 at 18:25




    @VicBrown : So it can't be simplified to an elementary function. Perhaps it can be approximated with something elementary. Would an approximation (and if so, how precise and accurate would you require) suffice?
    – Eric Towers
    Dec 30 '18 at 18:25












    @VicBrown : Officially, answers to questions on this site are evaluated (by the crowds) as answers to the Question as asked. Your Question does not include the constraints $1 leq r leq 4$ and $r leq n$, which I infer from your referenced question. Since those are not part of the current question, they cannot be assumed in an Answer.
    – Eric Towers
    Dec 30 '18 at 22:57




    @VicBrown : Officially, answers to questions on this site are evaluated (by the crowds) as answers to the Question as asked. Your Question does not include the constraints $1 leq r leq 4$ and $r leq n$, which I infer from your referenced question. Since those are not part of the current question, they cannot be assumed in an Answer.
    – Eric Towers
    Dec 30 '18 at 22:57












    @VicBrown : As the extension to my question shows, for $n = 10,000$, $f(r,n)$ quickly exceeds usual integral representations in some programming languages. If you intend to compute these with software, it would be helpful to know what your targetted software is.
    – Eric Towers
    Dec 30 '18 at 23:16






    @VicBrown : As the extension to my question shows, for $n = 10,000$, $f(r,n)$ quickly exceeds usual integral representations in some programming languages. If you intend to compute these with software, it would be helpful to know what your targetted software is.
    – Eric Towers
    Dec 30 '18 at 23:16














    Your solution above and it is similar to what I solve using polynomial equation for r = 1 to 4 and n = 3 to 10, where: $$ f(1,n) = 3n + 1 $$ $$ f(2,n) = frac{9}{2}n^2 - frac{3}{2}n + 1 $$ $$ f(3,n) = frac{27}{6}n^3 - 9n^2 + 15n + 1 $$ $$ f(4,n) = frac{27}{8}n^4 - frac{63}{4}n^3 + frac{225}{8}n^2 - frac{51}{4}n + 1 $$ I do not intend to apply such equation into my program (I am using Python 3 by the way). I just only wanted to provide mathematical proof that a list of unique string variants generated by the program is correct.
    – Vic Brown
    Dec 31 '18 at 5:36






    Your solution above and it is similar to what I solve using polynomial equation for r = 1 to 4 and n = 3 to 10, where: $$ f(1,n) = 3n + 1 $$ $$ f(2,n) = frac{9}{2}n^2 - frac{3}{2}n + 1 $$ $$ f(3,n) = frac{27}{6}n^3 - 9n^2 + 15n + 1 $$ $$ f(4,n) = frac{27}{8}n^4 - frac{63}{4}n^3 + frac{225}{8}n^2 - frac{51}{4}n + 1 $$ I do not intend to apply such equation into my program (I am using Python 3 by the way). I just only wanted to provide mathematical proof that a list of unique string variants generated by the program is correct.
    – Vic Brown
    Dec 31 '18 at 5:36













    0














    In case you are interested in asymptotics:



    $$begin{align}
    s(n,r)&=sum_{k=1}^r 3^kbinom{n}{k}\
    &=2^nsum_{k=1}^r 3^kfrac{binom{n}{k}}{2^n}\
    &approx frac{2^n}{sqrt{pi n /2}} int_0^r 3^x expleft( -frac{2}{n}(x-n/2)^2 right)
    dx \
    end{align}$$



    If $r > 0.78 n$ we can apply Laplace's method and get the first order approximation:



    $$ frac{log (s(n,r))}{n} to log(2) + frac{log^2(3)+ 4 log 3}{8}approx 1.393$$



    For smaller $r$ , a similar approximation can be obtained (tell me if you are interested) but it involves both $(n,r)$ variables.






    share|cite|improve this answer




























      0














      In case you are interested in asymptotics:



      $$begin{align}
      s(n,r)&=sum_{k=1}^r 3^kbinom{n}{k}\
      &=2^nsum_{k=1}^r 3^kfrac{binom{n}{k}}{2^n}\
      &approx frac{2^n}{sqrt{pi n /2}} int_0^r 3^x expleft( -frac{2}{n}(x-n/2)^2 right)
      dx \
      end{align}$$



      If $r > 0.78 n$ we can apply Laplace's method and get the first order approximation:



      $$ frac{log (s(n,r))}{n} to log(2) + frac{log^2(3)+ 4 log 3}{8}approx 1.393$$



      For smaller $r$ , a similar approximation can be obtained (tell me if you are interested) but it involves both $(n,r)$ variables.






      share|cite|improve this answer


























        0












        0








        0






        In case you are interested in asymptotics:



        $$begin{align}
        s(n,r)&=sum_{k=1}^r 3^kbinom{n}{k}\
        &=2^nsum_{k=1}^r 3^kfrac{binom{n}{k}}{2^n}\
        &approx frac{2^n}{sqrt{pi n /2}} int_0^r 3^x expleft( -frac{2}{n}(x-n/2)^2 right)
        dx \
        end{align}$$



        If $r > 0.78 n$ we can apply Laplace's method and get the first order approximation:



        $$ frac{log (s(n,r))}{n} to log(2) + frac{log^2(3)+ 4 log 3}{8}approx 1.393$$



        For smaller $r$ , a similar approximation can be obtained (tell me if you are interested) but it involves both $(n,r)$ variables.






        share|cite|improve this answer














        In case you are interested in asymptotics:



        $$begin{align}
        s(n,r)&=sum_{k=1}^r 3^kbinom{n}{k}\
        &=2^nsum_{k=1}^r 3^kfrac{binom{n}{k}}{2^n}\
        &approx frac{2^n}{sqrt{pi n /2}} int_0^r 3^x expleft( -frac{2}{n}(x-n/2)^2 right)
        dx \
        end{align}$$



        If $r > 0.78 n$ we can apply Laplace's method and get the first order approximation:



        $$ frac{log (s(n,r))}{n} to log(2) + frac{log^2(3)+ 4 log 3}{8}approx 1.393$$



        For smaller $r$ , a similar approximation can be obtained (tell me if you are interested) but it involves both $(n,r)$ variables.







        share|cite|improve this answer














        share|cite|improve this answer



        share|cite|improve this answer








        edited yesterday

























        answered Jan 2 at 1:39









        leonbloy

        40.4k645107




        40.4k645107






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematics Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3054644%2fhow-to-solve-1-sum-k-1r-3k-binomnk-using-say-s-n-fraca-1%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            An IMO inspired problem

            Management

            Has there ever been an instance of an active nuclear power plant within or near a war zone?