How to write for / while loop in mathematical notation

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|cite|improve this question



















  • 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














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.







share|cite|improve this question



















  • 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












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.







share|cite|improve this question











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.









share|cite|improve this question










share|cite|improve this question




share|cite|improve this question









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
















  • 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










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.






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',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    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%2f2871029%2fhow-to-write-for-while-loop-in-mathematical-notation%23new-answer', 'question_page');

    );

    Post as a guest






























    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.






    share|cite|improve this answer

























      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.






      share|cite|improve this answer























        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.






        share|cite|improve this answer













        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.







        share|cite|improve this answer













        share|cite|improve this answer



        share|cite|improve this answer











        answered Aug 3 at 13:56









        Deusovi

        2,0861920




        2,0861920






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            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













































































            Comments

            Popular posts from this blog

            What is the equation of a 3D cone with generalised tilt?

            Color the edges and diagonals of a regular polygon

            Relationship between determinant of matrix and determinant of adjoint?