Seeking an efficient way to calculate $sum_{k=2}^nfrac{1}{a_k}$ in a computer program, where the $a_k$ are...
$begingroup$
I need an efficient way to compute sums of reciprocal of numbers using a computer program. Currently, I have a set of integers ${a_{0}, a_{1}, ldots a_{n}}$, and I want to compute
$$sum_{i=0}^{n} frac{1}{a_{0}}$$
as a fraction.
I know what $n$ is. Is there a good way to do this? For example, if $n = 1$, it's just $1/a_{0}$. If $n = 2$, it's $(a_{0} + a_{1})/(a_{0} cdot a_{1})$.
But, it gets more complicated for $n = 3$.
More specifically, I'm writing a computer program to compute the sum $S$ given by
$$S = sum_{k=2}^{N} frac{1}{v(k)u(k)}$$
where $v(k)$ and $u(k)$ are guaranteed to be integers. I don't think what the functions are doing actually matters for my question, but $v(k)$ represents the largest prime $p$ that does not exceed $k$, and the function $u(k)$ represents the smallest prime strictly greater than $k$. Also, $N$ is passed in as a parameter. Currently, I've stored each of the products of $v(k)u(k)$ in a vector.
algebra-precalculus number-theory
$endgroup$
add a comment |
$begingroup$
I need an efficient way to compute sums of reciprocal of numbers using a computer program. Currently, I have a set of integers ${a_{0}, a_{1}, ldots a_{n}}$, and I want to compute
$$sum_{i=0}^{n} frac{1}{a_{0}}$$
as a fraction.
I know what $n$ is. Is there a good way to do this? For example, if $n = 1$, it's just $1/a_{0}$. If $n = 2$, it's $(a_{0} + a_{1})/(a_{0} cdot a_{1})$.
But, it gets more complicated for $n = 3$.
More specifically, I'm writing a computer program to compute the sum $S$ given by
$$S = sum_{k=2}^{N} frac{1}{v(k)u(k)}$$
where $v(k)$ and $u(k)$ are guaranteed to be integers. I don't think what the functions are doing actually matters for my question, but $v(k)$ represents the largest prime $p$ that does not exceed $k$, and the function $u(k)$ represents the smallest prime strictly greater than $k$. Also, $N$ is passed in as a parameter. Currently, I've stored each of the products of $v(k)u(k)$ in a vector.
algebra-precalculus number-theory
$endgroup$
1
$begingroup$
If I understand correctly what you are doing & asking for, then why not store each of the partial sums in a vector instead? This way, you can just quickly access the appropriate value, if it's in the vector, else if it's past the end, use the last value to calculate the remaining values (without recalculating the earlier ones), including adding values to your vector, if you have room in memory & the vector. Also, this seems to be more of a computer question than a math one, so is there any particular reason you are using MSE?
$endgroup$
– John Omielan
Jan 13 at 0:39
$begingroup$
@JohnOmielan My final answer needs to be expressed as a fraction. By default, the partial sums are stored as decimals
$endgroup$
– joseph
Jan 13 at 0:46
add a comment |
$begingroup$
I need an efficient way to compute sums of reciprocal of numbers using a computer program. Currently, I have a set of integers ${a_{0}, a_{1}, ldots a_{n}}$, and I want to compute
$$sum_{i=0}^{n} frac{1}{a_{0}}$$
as a fraction.
I know what $n$ is. Is there a good way to do this? For example, if $n = 1$, it's just $1/a_{0}$. If $n = 2$, it's $(a_{0} + a_{1})/(a_{0} cdot a_{1})$.
But, it gets more complicated for $n = 3$.
More specifically, I'm writing a computer program to compute the sum $S$ given by
$$S = sum_{k=2}^{N} frac{1}{v(k)u(k)}$$
where $v(k)$ and $u(k)$ are guaranteed to be integers. I don't think what the functions are doing actually matters for my question, but $v(k)$ represents the largest prime $p$ that does not exceed $k$, and the function $u(k)$ represents the smallest prime strictly greater than $k$. Also, $N$ is passed in as a parameter. Currently, I've stored each of the products of $v(k)u(k)$ in a vector.
algebra-precalculus number-theory
$endgroup$
I need an efficient way to compute sums of reciprocal of numbers using a computer program. Currently, I have a set of integers ${a_{0}, a_{1}, ldots a_{n}}$, and I want to compute
$$sum_{i=0}^{n} frac{1}{a_{0}}$$
as a fraction.
I know what $n$ is. Is there a good way to do this? For example, if $n = 1$, it's just $1/a_{0}$. If $n = 2$, it's $(a_{0} + a_{1})/(a_{0} cdot a_{1})$.
But, it gets more complicated for $n = 3$.
More specifically, I'm writing a computer program to compute the sum $S$ given by
$$S = sum_{k=2}^{N} frac{1}{v(k)u(k)}$$
where $v(k)$ and $u(k)$ are guaranteed to be integers. I don't think what the functions are doing actually matters for my question, but $v(k)$ represents the largest prime $p$ that does not exceed $k$, and the function $u(k)$ represents the smallest prime strictly greater than $k$. Also, $N$ is passed in as a parameter. Currently, I've stored each of the products of $v(k)u(k)$ in a vector.
algebra-precalculus number-theory
algebra-precalculus number-theory
edited Jan 13 at 0:51
Blue
49.7k870158
49.7k870158
asked Jan 13 at 0:36
josephjoseph
494111
494111
1
$begingroup$
If I understand correctly what you are doing & asking for, then why not store each of the partial sums in a vector instead? This way, you can just quickly access the appropriate value, if it's in the vector, else if it's past the end, use the last value to calculate the remaining values (without recalculating the earlier ones), including adding values to your vector, if you have room in memory & the vector. Also, this seems to be more of a computer question than a math one, so is there any particular reason you are using MSE?
$endgroup$
– John Omielan
Jan 13 at 0:39
$begingroup$
@JohnOmielan My final answer needs to be expressed as a fraction. By default, the partial sums are stored as decimals
$endgroup$
– joseph
Jan 13 at 0:46
add a comment |
1
$begingroup$
If I understand correctly what you are doing & asking for, then why not store each of the partial sums in a vector instead? This way, you can just quickly access the appropriate value, if it's in the vector, else if it's past the end, use the last value to calculate the remaining values (without recalculating the earlier ones), including adding values to your vector, if you have room in memory & the vector. Also, this seems to be more of a computer question than a math one, so is there any particular reason you are using MSE?
$endgroup$
– John Omielan
Jan 13 at 0:39
$begingroup$
@JohnOmielan My final answer needs to be expressed as a fraction. By default, the partial sums are stored as decimals
$endgroup$
– joseph
Jan 13 at 0:46
1
1
$begingroup$
If I understand correctly what you are doing & asking for, then why not store each of the partial sums in a vector instead? This way, you can just quickly access the appropriate value, if it's in the vector, else if it's past the end, use the last value to calculate the remaining values (without recalculating the earlier ones), including adding values to your vector, if you have room in memory & the vector. Also, this seems to be more of a computer question than a math one, so is there any particular reason you are using MSE?
$endgroup$
– John Omielan
Jan 13 at 0:39
$begingroup$
If I understand correctly what you are doing & asking for, then why not store each of the partial sums in a vector instead? This way, you can just quickly access the appropriate value, if it's in the vector, else if it's past the end, use the last value to calculate the remaining values (without recalculating the earlier ones), including adding values to your vector, if you have room in memory & the vector. Also, this seems to be more of a computer question than a math one, so is there any particular reason you are using MSE?
$endgroup$
– John Omielan
Jan 13 at 0:39
$begingroup$
@JohnOmielan My final answer needs to be expressed as a fraction. By default, the partial sums are stored as decimals
$endgroup$
– joseph
Jan 13 at 0:46
$begingroup$
@JohnOmielan My final answer needs to be expressed as a fraction. By default, the partial sums are stored as decimals
$endgroup$
– joseph
Jan 13 at 0:46
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
You can store each partial sum as a fraction by using 2 vectors, or one vector of an object with 2 integers. In particular, you store the numerator and denominator, starting off with $1$ for the numerator and the first value of the denominator. Then for each next value to add, you can create the next partial sum of a numerator and denominator as follows for the $m$'th (for $m ge 2$) term, where $n_{m - 1}$ is the latest stored numerator, $d_{m - 1}$ is the latest stored denominator and $frac{1}{a_m}$ is the next fraction value:
$$cfrac{n_{m - 1}}{d_{m - 1}} + cfrac{1}{a_m} = cfrac{a_m n_{m - 1} + d_{m - 1}}{a_m d_{m - 1}} tag{1}label{eq1} $$
This means the new next numerator can be stored as $n_m = a_m n_{m - 1} + d_{m - 1}$ and the new next denominator can be stored as $d_m = a_m d_{m - 1}$. To get a particular value, as I suggested in my comment to your question, you can either retrieve it from the vector(s), if they're already there, or use the last available one to calculate additional terms, potentially also adding each set of numerator / denominator values to your vector (if there is enough memory available).
This is one of the simplest ways to handle this issue. However, you may wish to optimize things like trying to find any common factors of the numerator and denominator to reduce their values as, depending on the type of integer type objects you are using & have available, how large each integral value can be and what sort of maximum size of $n$ is permitted, you can get numeric overflow. However, this is mainly a computing issue that you can determine on your own or ask elsewhere, such as an appropriate other forum on StackExchange.
$endgroup$
add a comment |
$begingroup$
Using the method described by John Omielan to get the values of $S$ for $n<20$, I examined the output and was able to find this closed-form solution:
$$sum_{k=2}^{n} frac{1}{v(k)u(k)}=frac{v(n)u(n)-2(v(n)+u(n)-n-1)}{2v(n)u(n)}$$
$endgroup$
$begingroup$
Yes, I got that same answer this morning. In fact, it's possible to write the sum as a telescoping series. Thanks
$endgroup$
– joseph
Jan 13 at 21:02
add a comment |
$begingroup$
To repeat myself, from another site, on a different problem:
The way I'd do it? Build a class representing fractions. Obviously, this class would have two integer fields for the numerator and denominator.
Methods to implement:
Reduction to lowest terms. Find the gcd of the numerator and denominator, and divide both by it. Swap signs if necessary so that the denominator becomes positive. This one's behind the scenes - you should never need to call it from the outside, only from other methods.
A constructor, that takes a pair of integers as input and gives you that fraction.
Arithmetic. The problem technically only calls for addition, but subtraction and multiplication aren't any harder. Division or inverses call for error handling, if you go there.
If you're going to reuse this for other purposes, some other things like comparison would be worthwhile. I was thinking in Java terms when I wrote this originally; the details of the jargon might change, but the concepts will be there in any standard programming language.
$endgroup$
add a comment |
Your Answer
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3071570%2fseeking-an-efficient-way-to-calculate-sum-k-2n-frac1a-k-in-a-computer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You can store each partial sum as a fraction by using 2 vectors, or one vector of an object with 2 integers. In particular, you store the numerator and denominator, starting off with $1$ for the numerator and the first value of the denominator. Then for each next value to add, you can create the next partial sum of a numerator and denominator as follows for the $m$'th (for $m ge 2$) term, where $n_{m - 1}$ is the latest stored numerator, $d_{m - 1}$ is the latest stored denominator and $frac{1}{a_m}$ is the next fraction value:
$$cfrac{n_{m - 1}}{d_{m - 1}} + cfrac{1}{a_m} = cfrac{a_m n_{m - 1} + d_{m - 1}}{a_m d_{m - 1}} tag{1}label{eq1} $$
This means the new next numerator can be stored as $n_m = a_m n_{m - 1} + d_{m - 1}$ and the new next denominator can be stored as $d_m = a_m d_{m - 1}$. To get a particular value, as I suggested in my comment to your question, you can either retrieve it from the vector(s), if they're already there, or use the last available one to calculate additional terms, potentially also adding each set of numerator / denominator values to your vector (if there is enough memory available).
This is one of the simplest ways to handle this issue. However, you may wish to optimize things like trying to find any common factors of the numerator and denominator to reduce their values as, depending on the type of integer type objects you are using & have available, how large each integral value can be and what sort of maximum size of $n$ is permitted, you can get numeric overflow. However, this is mainly a computing issue that you can determine on your own or ask elsewhere, such as an appropriate other forum on StackExchange.
$endgroup$
add a comment |
$begingroup$
You can store each partial sum as a fraction by using 2 vectors, or one vector of an object with 2 integers. In particular, you store the numerator and denominator, starting off with $1$ for the numerator and the first value of the denominator. Then for each next value to add, you can create the next partial sum of a numerator and denominator as follows for the $m$'th (for $m ge 2$) term, where $n_{m - 1}$ is the latest stored numerator, $d_{m - 1}$ is the latest stored denominator and $frac{1}{a_m}$ is the next fraction value:
$$cfrac{n_{m - 1}}{d_{m - 1}} + cfrac{1}{a_m} = cfrac{a_m n_{m - 1} + d_{m - 1}}{a_m d_{m - 1}} tag{1}label{eq1} $$
This means the new next numerator can be stored as $n_m = a_m n_{m - 1} + d_{m - 1}$ and the new next denominator can be stored as $d_m = a_m d_{m - 1}$. To get a particular value, as I suggested in my comment to your question, you can either retrieve it from the vector(s), if they're already there, or use the last available one to calculate additional terms, potentially also adding each set of numerator / denominator values to your vector (if there is enough memory available).
This is one of the simplest ways to handle this issue. However, you may wish to optimize things like trying to find any common factors of the numerator and denominator to reduce their values as, depending on the type of integer type objects you are using & have available, how large each integral value can be and what sort of maximum size of $n$ is permitted, you can get numeric overflow. However, this is mainly a computing issue that you can determine on your own or ask elsewhere, such as an appropriate other forum on StackExchange.
$endgroup$
add a comment |
$begingroup$
You can store each partial sum as a fraction by using 2 vectors, or one vector of an object with 2 integers. In particular, you store the numerator and denominator, starting off with $1$ for the numerator and the first value of the denominator. Then for each next value to add, you can create the next partial sum of a numerator and denominator as follows for the $m$'th (for $m ge 2$) term, where $n_{m - 1}$ is the latest stored numerator, $d_{m - 1}$ is the latest stored denominator and $frac{1}{a_m}$ is the next fraction value:
$$cfrac{n_{m - 1}}{d_{m - 1}} + cfrac{1}{a_m} = cfrac{a_m n_{m - 1} + d_{m - 1}}{a_m d_{m - 1}} tag{1}label{eq1} $$
This means the new next numerator can be stored as $n_m = a_m n_{m - 1} + d_{m - 1}$ and the new next denominator can be stored as $d_m = a_m d_{m - 1}$. To get a particular value, as I suggested in my comment to your question, you can either retrieve it from the vector(s), if they're already there, or use the last available one to calculate additional terms, potentially also adding each set of numerator / denominator values to your vector (if there is enough memory available).
This is one of the simplest ways to handle this issue. However, you may wish to optimize things like trying to find any common factors of the numerator and denominator to reduce their values as, depending on the type of integer type objects you are using & have available, how large each integral value can be and what sort of maximum size of $n$ is permitted, you can get numeric overflow. However, this is mainly a computing issue that you can determine on your own or ask elsewhere, such as an appropriate other forum on StackExchange.
$endgroup$
You can store each partial sum as a fraction by using 2 vectors, or one vector of an object with 2 integers. In particular, you store the numerator and denominator, starting off with $1$ for the numerator and the first value of the denominator. Then for each next value to add, you can create the next partial sum of a numerator and denominator as follows for the $m$'th (for $m ge 2$) term, where $n_{m - 1}$ is the latest stored numerator, $d_{m - 1}$ is the latest stored denominator and $frac{1}{a_m}$ is the next fraction value:
$$cfrac{n_{m - 1}}{d_{m - 1}} + cfrac{1}{a_m} = cfrac{a_m n_{m - 1} + d_{m - 1}}{a_m d_{m - 1}} tag{1}label{eq1} $$
This means the new next numerator can be stored as $n_m = a_m n_{m - 1} + d_{m - 1}$ and the new next denominator can be stored as $d_m = a_m d_{m - 1}$. To get a particular value, as I suggested in my comment to your question, you can either retrieve it from the vector(s), if they're already there, or use the last available one to calculate additional terms, potentially also adding each set of numerator / denominator values to your vector (if there is enough memory available).
This is one of the simplest ways to handle this issue. However, you may wish to optimize things like trying to find any common factors of the numerator and denominator to reduce their values as, depending on the type of integer type objects you are using & have available, how large each integral value can be and what sort of maximum size of $n$ is permitted, you can get numeric overflow. However, this is mainly a computing issue that you can determine on your own or ask elsewhere, such as an appropriate other forum on StackExchange.
edited Jan 13 at 1:03
answered Jan 13 at 0:58
John OmielanJohn Omielan
5,0542218
5,0542218
add a comment |
add a comment |
$begingroup$
Using the method described by John Omielan to get the values of $S$ for $n<20$, I examined the output and was able to find this closed-form solution:
$$sum_{k=2}^{n} frac{1}{v(k)u(k)}=frac{v(n)u(n)-2(v(n)+u(n)-n-1)}{2v(n)u(n)}$$
$endgroup$
$begingroup$
Yes, I got that same answer this morning. In fact, it's possible to write the sum as a telescoping series. Thanks
$endgroup$
– joseph
Jan 13 at 21:02
add a comment |
$begingroup$
Using the method described by John Omielan to get the values of $S$ for $n<20$, I examined the output and was able to find this closed-form solution:
$$sum_{k=2}^{n} frac{1}{v(k)u(k)}=frac{v(n)u(n)-2(v(n)+u(n)-n-1)}{2v(n)u(n)}$$
$endgroup$
$begingroup$
Yes, I got that same answer this morning. In fact, it's possible to write the sum as a telescoping series. Thanks
$endgroup$
– joseph
Jan 13 at 21:02
add a comment |
$begingroup$
Using the method described by John Omielan to get the values of $S$ for $n<20$, I examined the output and was able to find this closed-form solution:
$$sum_{k=2}^{n} frac{1}{v(k)u(k)}=frac{v(n)u(n)-2(v(n)+u(n)-n-1)}{2v(n)u(n)}$$
$endgroup$
Using the method described by John Omielan to get the values of $S$ for $n<20$, I examined the output and was able to find this closed-form solution:
$$sum_{k=2}^{n} frac{1}{v(k)u(k)}=frac{v(n)u(n)-2(v(n)+u(n)-n-1)}{2v(n)u(n)}$$
answered Jan 13 at 21:01
Daniel MathiasDaniel Mathias
1,41518
1,41518
$begingroup$
Yes, I got that same answer this morning. In fact, it's possible to write the sum as a telescoping series. Thanks
$endgroup$
– joseph
Jan 13 at 21:02
add a comment |
$begingroup$
Yes, I got that same answer this morning. In fact, it's possible to write the sum as a telescoping series. Thanks
$endgroup$
– joseph
Jan 13 at 21:02
$begingroup$
Yes, I got that same answer this morning. In fact, it's possible to write the sum as a telescoping series. Thanks
$endgroup$
– joseph
Jan 13 at 21:02
$begingroup$
Yes, I got that same answer this morning. In fact, it's possible to write the sum as a telescoping series. Thanks
$endgroup$
– joseph
Jan 13 at 21:02
add a comment |
$begingroup$
To repeat myself, from another site, on a different problem:
The way I'd do it? Build a class representing fractions. Obviously, this class would have two integer fields for the numerator and denominator.
Methods to implement:
Reduction to lowest terms. Find the gcd of the numerator and denominator, and divide both by it. Swap signs if necessary so that the denominator becomes positive. This one's behind the scenes - you should never need to call it from the outside, only from other methods.
A constructor, that takes a pair of integers as input and gives you that fraction.
Arithmetic. The problem technically only calls for addition, but subtraction and multiplication aren't any harder. Division or inverses call for error handling, if you go there.
If you're going to reuse this for other purposes, some other things like comparison would be worthwhile. I was thinking in Java terms when I wrote this originally; the details of the jargon might change, but the concepts will be there in any standard programming language.
$endgroup$
add a comment |
$begingroup$
To repeat myself, from another site, on a different problem:
The way I'd do it? Build a class representing fractions. Obviously, this class would have two integer fields for the numerator and denominator.
Methods to implement:
Reduction to lowest terms. Find the gcd of the numerator and denominator, and divide both by it. Swap signs if necessary so that the denominator becomes positive. This one's behind the scenes - you should never need to call it from the outside, only from other methods.
A constructor, that takes a pair of integers as input and gives you that fraction.
Arithmetic. The problem technically only calls for addition, but subtraction and multiplication aren't any harder. Division or inverses call for error handling, if you go there.
If you're going to reuse this for other purposes, some other things like comparison would be worthwhile. I was thinking in Java terms when I wrote this originally; the details of the jargon might change, but the concepts will be there in any standard programming language.
$endgroup$
add a comment |
$begingroup$
To repeat myself, from another site, on a different problem:
The way I'd do it? Build a class representing fractions. Obviously, this class would have two integer fields for the numerator and denominator.
Methods to implement:
Reduction to lowest terms. Find the gcd of the numerator and denominator, and divide both by it. Swap signs if necessary so that the denominator becomes positive. This one's behind the scenes - you should never need to call it from the outside, only from other methods.
A constructor, that takes a pair of integers as input and gives you that fraction.
Arithmetic. The problem technically only calls for addition, but subtraction and multiplication aren't any harder. Division or inverses call for error handling, if you go there.
If you're going to reuse this for other purposes, some other things like comparison would be worthwhile. I was thinking in Java terms when I wrote this originally; the details of the jargon might change, but the concepts will be there in any standard programming language.
$endgroup$
To repeat myself, from another site, on a different problem:
The way I'd do it? Build a class representing fractions. Obviously, this class would have two integer fields for the numerator and denominator.
Methods to implement:
Reduction to lowest terms. Find the gcd of the numerator and denominator, and divide both by it. Swap signs if necessary so that the denominator becomes positive. This one's behind the scenes - you should never need to call it from the outside, only from other methods.
A constructor, that takes a pair of integers as input and gives you that fraction.
Arithmetic. The problem technically only calls for addition, but subtraction and multiplication aren't any harder. Division or inverses call for error handling, if you go there.
If you're going to reuse this for other purposes, some other things like comparison would be worthwhile. I was thinking in Java terms when I wrote this originally; the details of the jargon might change, but the concepts will be there in any standard programming language.
answered Jan 13 at 1:03
jmerryjmerry
17.1k11633
17.1k11633
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3071570%2fseeking-an-efficient-way-to-calculate-sum-k-2n-frac1a-k-in-a-computer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
$begingroup$
If I understand correctly what you are doing & asking for, then why not store each of the partial sums in a vector instead? This way, you can just quickly access the appropriate value, if it's in the vector, else if it's past the end, use the last value to calculate the remaining values (without recalculating the earlier ones), including adding values to your vector, if you have room in memory & the vector. Also, this seems to be more of a computer question than a math one, so is there any particular reason you are using MSE?
$endgroup$
– John Omielan
Jan 13 at 0:39
$begingroup$
@JohnOmielan My final answer needs to be expressed as a fraction. By default, the partial sums are stored as decimals
$endgroup$
– joseph
Jan 13 at 0:46