How to write for / while loop in mathematical notation
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
In this question they suggest $$sum_iin S f(i)$$
I just wanted to clarify if it is okay to notate a while loop like this, where the while loop would be simply looping until some condition is met, executing a function.
b = 10
while (a < b)
x()
a++
or even
while (true)
x()
// ...
if (something) break
or wondering if it would also work for a for loop:
for (var i = 0; i < n; i++)
x()
where none of these functions actually create a sum explicitly, but instead execute a function some number of times.
functions notation
add a comment |Â
up vote
0
down vote
favorite
In this question they suggest $$sum_iin S f(i)$$
I just wanted to clarify if it is okay to notate a while loop like this, where the while loop would be simply looping until some condition is met, executing a function.
b = 10
while (a < b)
x()
a++
or even
while (true)
x()
// ...
if (something) break
or wondering if it would also work for a for loop:
for (var i = 0; i < n; i++)
x()
where none of these functions actually create a sum explicitly, but instead execute a function some number of times.
functions notation
Assuming that $x$ is a function, your first example is essentially $x^10$, i.e. the $10$-fold composition of $x$ with itself. Your second example comes down to the same thing (in mathematics, we don't typically "test" for truthiness in our notation, because statements are either true or false a priori). The last bit of pseudocode is basically the same as the first (I don't see the distinction).
– Xander Henderson
Aug 3 at 12:56
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In this question they suggest $$sum_iin S f(i)$$
I just wanted to clarify if it is okay to notate a while loop like this, where the while loop would be simply looping until some condition is met, executing a function.
b = 10
while (a < b)
x()
a++
or even
while (true)
x()
// ...
if (something) break
or wondering if it would also work for a for loop:
for (var i = 0; i < n; i++)
x()
where none of these functions actually create a sum explicitly, but instead execute a function some number of times.
functions notation
In this question they suggest $$sum_iin S f(i)$$
I just wanted to clarify if it is okay to notate a while loop like this, where the while loop would be simply looping until some condition is met, executing a function.
b = 10
while (a < b)
x()
a++
or even
while (true)
x()
// ...
if (something) break
or wondering if it would also work for a for loop:
for (var i = 0; i < n; i++)
x()
where none of these functions actually create a sum explicitly, but instead execute a function some number of times.
functions notation
asked Aug 3 at 12:48


Lance Pollard
1,090723
1,090723
Assuming that $x$ is a function, your first example is essentially $x^10$, i.e. the $10$-fold composition of $x$ with itself. Your second example comes down to the same thing (in mathematics, we don't typically "test" for truthiness in our notation, because statements are either true or false a priori). The last bit of pseudocode is basically the same as the first (I don't see the distinction).
– Xander Henderson
Aug 3 at 12:56
add a comment |Â
Assuming that $x$ is a function, your first example is essentially $x^10$, i.e. the $10$-fold composition of $x$ with itself. Your second example comes down to the same thing (in mathematics, we don't typically "test" for truthiness in our notation, because statements are either true or false a priori). The last bit of pseudocode is basically the same as the first (I don't see the distinction).
– Xander Henderson
Aug 3 at 12:56
Assuming that $x$ is a function, your first example is essentially $x^10$, i.e. the $10$-fold composition of $x$ with itself. Your second example comes down to the same thing (in mathematics, we don't typically "test" for truthiness in our notation, because statements are either true or false a priori). The last bit of pseudocode is basically the same as the first (I don't see the distinction).
– Xander Henderson
Aug 3 at 12:56
Assuming that $x$ is a function, your first example is essentially $x^10$, i.e. the $10$-fold composition of $x$ with itself. Your second example comes down to the same thing (in mathematics, we don't typically "test" for truthiness in our notation, because statements are either true or false a priori). The last bit of pseudocode is basically the same as the first (I don't see the distinction).
– Xander Henderson
Aug 3 at 12:56
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
In pure math, functions don't have "side-effects". Variables are not updated; they are either set to a specific value, or they range over all values simultaneously: there is no "updating", because there is no "time". So, under the strictest possible interpretation, this question doesn't make sense.
To talk about the effects of code purely mathematically, you effectively need to find a way to express it without directly talking about 'time'. The easiest way to do this is to use a recursive definition.
For instance, if x
is something like:
if(p(a))
a = f(a);
else
a = a+1;
then you might turn that into a sequence, and write:
Let $a_0 =$ [some starting value] . For all natural numbers $n>0$, define $a_n$ as:
$$a_n = begincasesf(a_n-1) & textif p(a) \ a_n-1 + 1 & textotherwiseendcases$$
Then, you can 'access' the value of a
after calling x
10 times by just writing $a_10$.
...or you can just write some pseudocode, and say "let $a_i$ be the value of a
after $i$ iterations of x
". As long as you make it clear what you're doing (and as long as your audience knows any programming at all), you should be able to get your point across.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
In pure math, functions don't have "side-effects". Variables are not updated; they are either set to a specific value, or they range over all values simultaneously: there is no "updating", because there is no "time". So, under the strictest possible interpretation, this question doesn't make sense.
To talk about the effects of code purely mathematically, you effectively need to find a way to express it without directly talking about 'time'. The easiest way to do this is to use a recursive definition.
For instance, if x
is something like:
if(p(a))
a = f(a);
else
a = a+1;
then you might turn that into a sequence, and write:
Let $a_0 =$ [some starting value] . For all natural numbers $n>0$, define $a_n$ as:
$$a_n = begincasesf(a_n-1) & textif p(a) \ a_n-1 + 1 & textotherwiseendcases$$
Then, you can 'access' the value of a
after calling x
10 times by just writing $a_10$.
...or you can just write some pseudocode, and say "let $a_i$ be the value of a
after $i$ iterations of x
". As long as you make it clear what you're doing (and as long as your audience knows any programming at all), you should be able to get your point across.
add a comment |Â
up vote
1
down vote
accepted
In pure math, functions don't have "side-effects". Variables are not updated; they are either set to a specific value, or they range over all values simultaneously: there is no "updating", because there is no "time". So, under the strictest possible interpretation, this question doesn't make sense.
To talk about the effects of code purely mathematically, you effectively need to find a way to express it without directly talking about 'time'. The easiest way to do this is to use a recursive definition.
For instance, if x
is something like:
if(p(a))
a = f(a);
else
a = a+1;
then you might turn that into a sequence, and write:
Let $a_0 =$ [some starting value] . For all natural numbers $n>0$, define $a_n$ as:
$$a_n = begincasesf(a_n-1) & textif p(a) \ a_n-1 + 1 & textotherwiseendcases$$
Then, you can 'access' the value of a
after calling x
10 times by just writing $a_10$.
...or you can just write some pseudocode, and say "let $a_i$ be the value of a
after $i$ iterations of x
". As long as you make it clear what you're doing (and as long as your audience knows any programming at all), you should be able to get your point across.
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
In pure math, functions don't have "side-effects". Variables are not updated; they are either set to a specific value, or they range over all values simultaneously: there is no "updating", because there is no "time". So, under the strictest possible interpretation, this question doesn't make sense.
To talk about the effects of code purely mathematically, you effectively need to find a way to express it without directly talking about 'time'. The easiest way to do this is to use a recursive definition.
For instance, if x
is something like:
if(p(a))
a = f(a);
else
a = a+1;
then you might turn that into a sequence, and write:
Let $a_0 =$ [some starting value] . For all natural numbers $n>0$, define $a_n$ as:
$$a_n = begincasesf(a_n-1) & textif p(a) \ a_n-1 + 1 & textotherwiseendcases$$
Then, you can 'access' the value of a
after calling x
10 times by just writing $a_10$.
...or you can just write some pseudocode, and say "let $a_i$ be the value of a
after $i$ iterations of x
". As long as you make it clear what you're doing (and as long as your audience knows any programming at all), you should be able to get your point across.
In pure math, functions don't have "side-effects". Variables are not updated; they are either set to a specific value, or they range over all values simultaneously: there is no "updating", because there is no "time". So, under the strictest possible interpretation, this question doesn't make sense.
To talk about the effects of code purely mathematically, you effectively need to find a way to express it without directly talking about 'time'. The easiest way to do this is to use a recursive definition.
For instance, if x
is something like:
if(p(a))
a = f(a);
else
a = a+1;
then you might turn that into a sequence, and write:
Let $a_0 =$ [some starting value] . For all natural numbers $n>0$, define $a_n$ as:
$$a_n = begincasesf(a_n-1) & textif p(a) \ a_n-1 + 1 & textotherwiseendcases$$
Then, you can 'access' the value of a
after calling x
10 times by just writing $a_10$.
...or you can just write some pseudocode, and say "let $a_i$ be the value of a
after $i$ iterations of x
". As long as you make it clear what you're doing (and as long as your audience knows any programming at all), you should be able to get your point across.
answered Aug 3 at 13:56


Deusovi
2,0861920
2,0861920
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2871029%2fhow-to-write-for-while-loop-in-mathematical-notation%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Assuming that $x$ is a function, your first example is essentially $x^10$, i.e. the $10$-fold composition of $x$ with itself. Your second example comes down to the same thing (in mathematics, we don't typically "test" for truthiness in our notation, because statements are either true or false a priori). The last bit of pseudocode is basically the same as the first (I don't see the distinction).
– Xander Henderson
Aug 3 at 12:56