How do I convert a simple algorithm to a mathematical notation?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
3












I am trying to write a simple algorithm given below in mathematical notation. I wrote the formula up to a certain point, but I have no idea of restrictions. For example, I used the NULL statement even though it was not "else". It also needs a "break" statement or equivalent.



 var thr = 0.5;
var M = 100;
var sum = 0;
var T = 0;

for i 0 to G

sum = sum + i;
if sum/M >= thr then

T = i;
break;



return T;


My math notations; I defined "sum" in equation as follows.
$$sum = sum_j=0^ij$$



(Eq.1)$$T = sum_i=0^Gf=
begincases
i & fracsum_j=0^ijMgeq thr\
mathrmNULL & textotherwise
endcases$$
(Eq.2)$$T = sum_i=0,fneq mathrmNULL^Gf=
begincases
i & fracsum_j=0^ijMgeq thr\
mathrmNULL & textotherwise
endcases$$



Thank you very much for your help already.







share|cite|improve this question





















  • What is the value you wish to get out?
    – Q the Platypus
    Jul 27 at 4:02










  • I want to get the value of the "i" that provides the condition. This is actually the P-tile algorithm. I use histogram information for this, but I've assigned constant variables to simplify the syntax.
    – Abdullah Elen
    Jul 27 at 4:10










  • what is G ? $$
    – mercio
    Jul 27 at 7:37










  • G can be selected as a number greater than 10. That is, it's big enough to provide the "if" condition.
    – Abdullah Elen
    Jul 27 at 22:21















up vote
4
down vote

favorite
3












I am trying to write a simple algorithm given below in mathematical notation. I wrote the formula up to a certain point, but I have no idea of restrictions. For example, I used the NULL statement even though it was not "else". It also needs a "break" statement or equivalent.



 var thr = 0.5;
var M = 100;
var sum = 0;
var T = 0;

for i 0 to G

sum = sum + i;
if sum/M >= thr then

T = i;
break;



return T;


My math notations; I defined "sum" in equation as follows.
$$sum = sum_j=0^ij$$



(Eq.1)$$T = sum_i=0^Gf=
begincases
i & fracsum_j=0^ijMgeq thr\
mathrmNULL & textotherwise
endcases$$
(Eq.2)$$T = sum_i=0,fneq mathrmNULL^Gf=
begincases
i & fracsum_j=0^ijMgeq thr\
mathrmNULL & textotherwise
endcases$$



Thank you very much for your help already.







share|cite|improve this question





















  • What is the value you wish to get out?
    – Q the Platypus
    Jul 27 at 4:02










  • I want to get the value of the "i" that provides the condition. This is actually the P-tile algorithm. I use histogram information for this, but I've assigned constant variables to simplify the syntax.
    – Abdullah Elen
    Jul 27 at 4:10










  • what is G ? $$
    – mercio
    Jul 27 at 7:37










  • G can be selected as a number greater than 10. That is, it's big enough to provide the "if" condition.
    – Abdullah Elen
    Jul 27 at 22:21













up vote
4
down vote

favorite
3









up vote
4
down vote

favorite
3






3





I am trying to write a simple algorithm given below in mathematical notation. I wrote the formula up to a certain point, but I have no idea of restrictions. For example, I used the NULL statement even though it was not "else". It also needs a "break" statement or equivalent.



 var thr = 0.5;
var M = 100;
var sum = 0;
var T = 0;

for i 0 to G

sum = sum + i;
if sum/M >= thr then

T = i;
break;



return T;


My math notations; I defined "sum" in equation as follows.
$$sum = sum_j=0^ij$$



(Eq.1)$$T = sum_i=0^Gf=
begincases
i & fracsum_j=0^ijMgeq thr\
mathrmNULL & textotherwise
endcases$$
(Eq.2)$$T = sum_i=0,fneq mathrmNULL^Gf=
begincases
i & fracsum_j=0^ijMgeq thr\
mathrmNULL & textotherwise
endcases$$



Thank you very much for your help already.







share|cite|improve this question













I am trying to write a simple algorithm given below in mathematical notation. I wrote the formula up to a certain point, but I have no idea of restrictions. For example, I used the NULL statement even though it was not "else". It also needs a "break" statement or equivalent.



 var thr = 0.5;
var M = 100;
var sum = 0;
var T = 0;

for i 0 to G

sum = sum + i;
if sum/M >= thr then

T = i;
break;



return T;


My math notations; I defined "sum" in equation as follows.
$$sum = sum_j=0^ij$$



(Eq.1)$$T = sum_i=0^Gf=
begincases
i & fracsum_j=0^ijMgeq thr\
mathrmNULL & textotherwise
endcases$$
(Eq.2)$$T = sum_i=0,fneq mathrmNULL^Gf=
begincases
i & fracsum_j=0^ijMgeq thr\
mathrmNULL & textotherwise
endcases$$



Thank you very much for your help already.









share|cite|improve this question












share|cite|improve this question




share|cite|improve this question








edited Jul 27 at 4:56
























asked Jul 27 at 3:57









Abdullah Elen

1235




1235











  • What is the value you wish to get out?
    – Q the Platypus
    Jul 27 at 4:02










  • I want to get the value of the "i" that provides the condition. This is actually the P-tile algorithm. I use histogram information for this, but I've assigned constant variables to simplify the syntax.
    – Abdullah Elen
    Jul 27 at 4:10










  • what is G ? $$
    – mercio
    Jul 27 at 7:37










  • G can be selected as a number greater than 10. That is, it's big enough to provide the "if" condition.
    – Abdullah Elen
    Jul 27 at 22:21

















  • What is the value you wish to get out?
    – Q the Platypus
    Jul 27 at 4:02










  • I want to get the value of the "i" that provides the condition. This is actually the P-tile algorithm. I use histogram information for this, but I've assigned constant variables to simplify the syntax.
    – Abdullah Elen
    Jul 27 at 4:10










  • what is G ? $$
    – mercio
    Jul 27 at 7:37










  • G can be selected as a number greater than 10. That is, it's big enough to provide the "if" condition.
    – Abdullah Elen
    Jul 27 at 22:21
















What is the value you wish to get out?
– Q the Platypus
Jul 27 at 4:02




What is the value you wish to get out?
– Q the Platypus
Jul 27 at 4:02












I want to get the value of the "i" that provides the condition. This is actually the P-tile algorithm. I use histogram information for this, but I've assigned constant variables to simplify the syntax.
– Abdullah Elen
Jul 27 at 4:10




I want to get the value of the "i" that provides the condition. This is actually the P-tile algorithm. I use histogram information for this, but I've assigned constant variables to simplify the syntax.
– Abdullah Elen
Jul 27 at 4:10












what is G ? $$
– mercio
Jul 27 at 7:37




what is G ? $$
– mercio
Jul 27 at 7:37












G can be selected as a number greater than 10. That is, it's big enough to provide the "if" condition.
– Abdullah Elen
Jul 27 at 22:21





G can be selected as a number greater than 10. That is, it's big enough to provide the "if" condition.
– Abdullah Elen
Jul 27 at 22:21











3 Answers
3






active

oldest

votes

















up vote
3
down vote



accepted










The idea here is that $T$ is equal to $i$, where $i$ is the first index in the loop for which $verb|sum|,/M ge verb|thr|$. This can be written in a formula as follows:
$$
T = begincases0 &tfrac1Mtextstylesum_j=0^Gj<verb|thr|\minimid iin 0,1,dots,G,tfrac1Mtextstylesum_j=0^ijge verb & textOtherwise
endcases
$$
So you take the set of $i$ for which the loop would have stopped by the $i^textth$ iteration, and declare $T$ to be the smallest (minimum) of this set.






share|cite|improve this answer























  • Thank you very much, Mike.
    – Abdullah Elen
    Jul 27 at 4:37






  • 1




    @AbdullahELEN By the way, see my edit, I originally forgot about what would happen if the loop ended before the sum got large enough.
    – Mike Earnest
    Jul 27 at 4:41










  • It's exactly what I wanted. Thank you again :)
    – Abdullah Elen
    Jul 27 at 4:47










  • I think we have a little problem. $T$ needs to be equal to $i$. As a result, the function must return $i$ value. Can i define it as follows? $displaystyle operatorname*argmin_i i$
    – Abdullah Elen
    Jul 29 at 1:27

















up vote
1
down vote













You need to think about what the code is doing, not just translate the code. Wehn you write $$sum = sum_j=0^ii$$
there is a small error that the iteration variable is $j$ so you should write
$$sum = sum_j=0^ij$$
More importantly, $sum$ is changing through the computation, so it would be better to write $$sum(i) = sum_j=0^ij$$
then you should perform the sum and write
$$sum(i)=frac 12i(i+1)$$
Then $T$ is the $i$ for which $sum$ exceeds $Mcdot thr$. Some analysis will show that $$T=leftlceilfrac 12(-1+sqrt1+8cdot Mcdot thr) right rceil$$
which is much more useful for someone trying to understand your code.
This last shows a way to get the result without iteration as well.






share|cite|improve this answer





















  • First of all thank you for your quick response. Oh yes. I wrote i instead of j and am going to fix it immediately. However, the "sum" statement does not need to be stored in stages. You can see this in the algorithm. I could express this mathematically.
    – Abdullah Elen
    Jul 27 at 4:21










  • My point is that you are trying to find the $i$ where the sum exceeds $Mcdot thr$. That is the first thing you should say-it is the spec for the algorithm. Then you don't compute sum all the way up to $G$, which just needs to be some large number. You compute it in stages and compare at each stage. Whether you store it or not is not important, the important thing is the value as a function of $i$. Writing it as a sum shows how you do it, writing it as $frac 12i(i+1)$ shows what it is.
    – Ross Millikan
    Jul 27 at 4:29










  • Yes. If you look at "if conditional", you can see the "break" statement there. For this reason, the loop does not operate until G.
    – Abdullah Elen
    Jul 27 at 4:36










  • Yes, I understood that. You asked about expressing the algorithm mathematically but you continue to talk about how the code works. The important thing is to say what value of $T$ is returned based on the input parameters. Mike Earnest's expression is very close to your code. I think it is much less useful to a reader.
    – Ross Millikan
    Jul 27 at 4:47










  • You're right. Not everybody has coding knowledge. For this reason, I should have written with a clearer expression.
    – Abdullah Elen
    Jul 27 at 4:53

















up vote
1
down vote













Your code is iterating $i$ from $0$ to $G$ and cumulatively incrementing the $textsum$ by that iterator, breaking when $textsum/Mgeq textthr$ (or $textsumgeq Mtimestextthr$ when rounding is not an issue ). Only when breaking is $T$ set to the iterator, otherwise it is left at zero.



Since $sum_i=0^n i =tfracn,(n+1)2$ , and the values of $M$ and $textthr$ are hard coded constants: $100$ and $0.5$, that code should result in



$$beginalignT & =begincases 0 &:& G,(G+1)< 100\ mintin0..G: t(t+1)geqslant 100 &:&textotherwise endcases \ &= begincases 0 &:& G<10\ 10 &:& Ggeq 10endcasesendalign$$






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%2f2864034%2fhow-do-i-convert-a-simple-algorithm-to-a-mathematical-notation%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    The idea here is that $T$ is equal to $i$, where $i$ is the first index in the loop for which $verb|sum|,/M ge verb|thr|$. This can be written in a formula as follows:
    $$
    T = begincases0 &tfrac1Mtextstylesum_j=0^Gj<verb|thr|\minimid iin 0,1,dots,G,tfrac1Mtextstylesum_j=0^ijge verb & textOtherwise
    endcases
    $$
    So you take the set of $i$ for which the loop would have stopped by the $i^textth$ iteration, and declare $T$ to be the smallest (minimum) of this set.






    share|cite|improve this answer























    • Thank you very much, Mike.
      – Abdullah Elen
      Jul 27 at 4:37






    • 1




      @AbdullahELEN By the way, see my edit, I originally forgot about what would happen if the loop ended before the sum got large enough.
      – Mike Earnest
      Jul 27 at 4:41










    • It's exactly what I wanted. Thank you again :)
      – Abdullah Elen
      Jul 27 at 4:47










    • I think we have a little problem. $T$ needs to be equal to $i$. As a result, the function must return $i$ value. Can i define it as follows? $displaystyle operatorname*argmin_i i$
      – Abdullah Elen
      Jul 29 at 1:27














    up vote
    3
    down vote



    accepted










    The idea here is that $T$ is equal to $i$, where $i$ is the first index in the loop for which $verb|sum|,/M ge verb|thr|$. This can be written in a formula as follows:
    $$
    T = begincases0 &tfrac1Mtextstylesum_j=0^Gj<verb|thr|\minimid iin 0,1,dots,G,tfrac1Mtextstylesum_j=0^ijge verb & textOtherwise
    endcases
    $$
    So you take the set of $i$ for which the loop would have stopped by the $i^textth$ iteration, and declare $T$ to be the smallest (minimum) of this set.






    share|cite|improve this answer























    • Thank you very much, Mike.
      – Abdullah Elen
      Jul 27 at 4:37






    • 1




      @AbdullahELEN By the way, see my edit, I originally forgot about what would happen if the loop ended before the sum got large enough.
      – Mike Earnest
      Jul 27 at 4:41










    • It's exactly what I wanted. Thank you again :)
      – Abdullah Elen
      Jul 27 at 4:47










    • I think we have a little problem. $T$ needs to be equal to $i$. As a result, the function must return $i$ value. Can i define it as follows? $displaystyle operatorname*argmin_i i$
      – Abdullah Elen
      Jul 29 at 1:27












    up vote
    3
    down vote



    accepted







    up vote
    3
    down vote



    accepted






    The idea here is that $T$ is equal to $i$, where $i$ is the first index in the loop for which $verb|sum|,/M ge verb|thr|$. This can be written in a formula as follows:
    $$
    T = begincases0 &tfrac1Mtextstylesum_j=0^Gj<verb|thr|\minimid iin 0,1,dots,G,tfrac1Mtextstylesum_j=0^ijge verb & textOtherwise
    endcases
    $$
    So you take the set of $i$ for which the loop would have stopped by the $i^textth$ iteration, and declare $T$ to be the smallest (minimum) of this set.






    share|cite|improve this answer















    The idea here is that $T$ is equal to $i$, where $i$ is the first index in the loop for which $verb|sum|,/M ge verb|thr|$. This can be written in a formula as follows:
    $$
    T = begincases0 &tfrac1Mtextstylesum_j=0^Gj<verb|thr|\minimid iin 0,1,dots,G,tfrac1Mtextstylesum_j=0^ijge verb & textOtherwise
    endcases
    $$
    So you take the set of $i$ for which the loop would have stopped by the $i^textth$ iteration, and declare $T$ to be the smallest (minimum) of this set.







    share|cite|improve this answer















    share|cite|improve this answer



    share|cite|improve this answer








    edited Jul 27 at 4:40


























    answered Jul 27 at 4:24









    Mike Earnest

    14.9k11644




    14.9k11644











    • Thank you very much, Mike.
      – Abdullah Elen
      Jul 27 at 4:37






    • 1




      @AbdullahELEN By the way, see my edit, I originally forgot about what would happen if the loop ended before the sum got large enough.
      – Mike Earnest
      Jul 27 at 4:41










    • It's exactly what I wanted. Thank you again :)
      – Abdullah Elen
      Jul 27 at 4:47










    • I think we have a little problem. $T$ needs to be equal to $i$. As a result, the function must return $i$ value. Can i define it as follows? $displaystyle operatorname*argmin_i i$
      – Abdullah Elen
      Jul 29 at 1:27
















    • Thank you very much, Mike.
      – Abdullah Elen
      Jul 27 at 4:37






    • 1




      @AbdullahELEN By the way, see my edit, I originally forgot about what would happen if the loop ended before the sum got large enough.
      – Mike Earnest
      Jul 27 at 4:41










    • It's exactly what I wanted. Thank you again :)
      – Abdullah Elen
      Jul 27 at 4:47










    • I think we have a little problem. $T$ needs to be equal to $i$. As a result, the function must return $i$ value. Can i define it as follows? $displaystyle operatorname*argmin_i i$
      – Abdullah Elen
      Jul 29 at 1:27















    Thank you very much, Mike.
    – Abdullah Elen
    Jul 27 at 4:37




    Thank you very much, Mike.
    – Abdullah Elen
    Jul 27 at 4:37




    1




    1




    @AbdullahELEN By the way, see my edit, I originally forgot about what would happen if the loop ended before the sum got large enough.
    – Mike Earnest
    Jul 27 at 4:41




    @AbdullahELEN By the way, see my edit, I originally forgot about what would happen if the loop ended before the sum got large enough.
    – Mike Earnest
    Jul 27 at 4:41












    It's exactly what I wanted. Thank you again :)
    – Abdullah Elen
    Jul 27 at 4:47




    It's exactly what I wanted. Thank you again :)
    – Abdullah Elen
    Jul 27 at 4:47












    I think we have a little problem. $T$ needs to be equal to $i$. As a result, the function must return $i$ value. Can i define it as follows? $displaystyle operatorname*argmin_i i$
    – Abdullah Elen
    Jul 29 at 1:27




    I think we have a little problem. $T$ needs to be equal to $i$. As a result, the function must return $i$ value. Can i define it as follows? $displaystyle operatorname*argmin_i i$
    – Abdullah Elen
    Jul 29 at 1:27










    up vote
    1
    down vote













    You need to think about what the code is doing, not just translate the code. Wehn you write $$sum = sum_j=0^ii$$
    there is a small error that the iteration variable is $j$ so you should write
    $$sum = sum_j=0^ij$$
    More importantly, $sum$ is changing through the computation, so it would be better to write $$sum(i) = sum_j=0^ij$$
    then you should perform the sum and write
    $$sum(i)=frac 12i(i+1)$$
    Then $T$ is the $i$ for which $sum$ exceeds $Mcdot thr$. Some analysis will show that $$T=leftlceilfrac 12(-1+sqrt1+8cdot Mcdot thr) right rceil$$
    which is much more useful for someone trying to understand your code.
    This last shows a way to get the result without iteration as well.






    share|cite|improve this answer





















    • First of all thank you for your quick response. Oh yes. I wrote i instead of j and am going to fix it immediately. However, the "sum" statement does not need to be stored in stages. You can see this in the algorithm. I could express this mathematically.
      – Abdullah Elen
      Jul 27 at 4:21










    • My point is that you are trying to find the $i$ where the sum exceeds $Mcdot thr$. That is the first thing you should say-it is the spec for the algorithm. Then you don't compute sum all the way up to $G$, which just needs to be some large number. You compute it in stages and compare at each stage. Whether you store it or not is not important, the important thing is the value as a function of $i$. Writing it as a sum shows how you do it, writing it as $frac 12i(i+1)$ shows what it is.
      – Ross Millikan
      Jul 27 at 4:29










    • Yes. If you look at "if conditional", you can see the "break" statement there. For this reason, the loop does not operate until G.
      – Abdullah Elen
      Jul 27 at 4:36










    • Yes, I understood that. You asked about expressing the algorithm mathematically but you continue to talk about how the code works. The important thing is to say what value of $T$ is returned based on the input parameters. Mike Earnest's expression is very close to your code. I think it is much less useful to a reader.
      – Ross Millikan
      Jul 27 at 4:47










    • You're right. Not everybody has coding knowledge. For this reason, I should have written with a clearer expression.
      – Abdullah Elen
      Jul 27 at 4:53














    up vote
    1
    down vote













    You need to think about what the code is doing, not just translate the code. Wehn you write $$sum = sum_j=0^ii$$
    there is a small error that the iteration variable is $j$ so you should write
    $$sum = sum_j=0^ij$$
    More importantly, $sum$ is changing through the computation, so it would be better to write $$sum(i) = sum_j=0^ij$$
    then you should perform the sum and write
    $$sum(i)=frac 12i(i+1)$$
    Then $T$ is the $i$ for which $sum$ exceeds $Mcdot thr$. Some analysis will show that $$T=leftlceilfrac 12(-1+sqrt1+8cdot Mcdot thr) right rceil$$
    which is much more useful for someone trying to understand your code.
    This last shows a way to get the result without iteration as well.






    share|cite|improve this answer





















    • First of all thank you for your quick response. Oh yes. I wrote i instead of j and am going to fix it immediately. However, the "sum" statement does not need to be stored in stages. You can see this in the algorithm. I could express this mathematically.
      – Abdullah Elen
      Jul 27 at 4:21










    • My point is that you are trying to find the $i$ where the sum exceeds $Mcdot thr$. That is the first thing you should say-it is the spec for the algorithm. Then you don't compute sum all the way up to $G$, which just needs to be some large number. You compute it in stages and compare at each stage. Whether you store it or not is not important, the important thing is the value as a function of $i$. Writing it as a sum shows how you do it, writing it as $frac 12i(i+1)$ shows what it is.
      – Ross Millikan
      Jul 27 at 4:29










    • Yes. If you look at "if conditional", you can see the "break" statement there. For this reason, the loop does not operate until G.
      – Abdullah Elen
      Jul 27 at 4:36










    • Yes, I understood that. You asked about expressing the algorithm mathematically but you continue to talk about how the code works. The important thing is to say what value of $T$ is returned based on the input parameters. Mike Earnest's expression is very close to your code. I think it is much less useful to a reader.
      – Ross Millikan
      Jul 27 at 4:47










    • You're right. Not everybody has coding knowledge. For this reason, I should have written with a clearer expression.
      – Abdullah Elen
      Jul 27 at 4:53












    up vote
    1
    down vote










    up vote
    1
    down vote









    You need to think about what the code is doing, not just translate the code. Wehn you write $$sum = sum_j=0^ii$$
    there is a small error that the iteration variable is $j$ so you should write
    $$sum = sum_j=0^ij$$
    More importantly, $sum$ is changing through the computation, so it would be better to write $$sum(i) = sum_j=0^ij$$
    then you should perform the sum and write
    $$sum(i)=frac 12i(i+1)$$
    Then $T$ is the $i$ for which $sum$ exceeds $Mcdot thr$. Some analysis will show that $$T=leftlceilfrac 12(-1+sqrt1+8cdot Mcdot thr) right rceil$$
    which is much more useful for someone trying to understand your code.
    This last shows a way to get the result without iteration as well.






    share|cite|improve this answer













    You need to think about what the code is doing, not just translate the code. Wehn you write $$sum = sum_j=0^ii$$
    there is a small error that the iteration variable is $j$ so you should write
    $$sum = sum_j=0^ij$$
    More importantly, $sum$ is changing through the computation, so it would be better to write $$sum(i) = sum_j=0^ij$$
    then you should perform the sum and write
    $$sum(i)=frac 12i(i+1)$$
    Then $T$ is the $i$ for which $sum$ exceeds $Mcdot thr$. Some analysis will show that $$T=leftlceilfrac 12(-1+sqrt1+8cdot Mcdot thr) right rceil$$
    which is much more useful for someone trying to understand your code.
    This last shows a way to get the result without iteration as well.







    share|cite|improve this answer













    share|cite|improve this answer



    share|cite|improve this answer











    answered Jul 27 at 4:13









    Ross Millikan

    275k21186351




    275k21186351











    • First of all thank you for your quick response. Oh yes. I wrote i instead of j and am going to fix it immediately. However, the "sum" statement does not need to be stored in stages. You can see this in the algorithm. I could express this mathematically.
      – Abdullah Elen
      Jul 27 at 4:21










    • My point is that you are trying to find the $i$ where the sum exceeds $Mcdot thr$. That is the first thing you should say-it is the spec for the algorithm. Then you don't compute sum all the way up to $G$, which just needs to be some large number. You compute it in stages and compare at each stage. Whether you store it or not is not important, the important thing is the value as a function of $i$. Writing it as a sum shows how you do it, writing it as $frac 12i(i+1)$ shows what it is.
      – Ross Millikan
      Jul 27 at 4:29










    • Yes. If you look at "if conditional", you can see the "break" statement there. For this reason, the loop does not operate until G.
      – Abdullah Elen
      Jul 27 at 4:36










    • Yes, I understood that. You asked about expressing the algorithm mathematically but you continue to talk about how the code works. The important thing is to say what value of $T$ is returned based on the input parameters. Mike Earnest's expression is very close to your code. I think it is much less useful to a reader.
      – Ross Millikan
      Jul 27 at 4:47










    • You're right. Not everybody has coding knowledge. For this reason, I should have written with a clearer expression.
      – Abdullah Elen
      Jul 27 at 4:53
















    • First of all thank you for your quick response. Oh yes. I wrote i instead of j and am going to fix it immediately. However, the "sum" statement does not need to be stored in stages. You can see this in the algorithm. I could express this mathematically.
      – Abdullah Elen
      Jul 27 at 4:21










    • My point is that you are trying to find the $i$ where the sum exceeds $Mcdot thr$. That is the first thing you should say-it is the spec for the algorithm. Then you don't compute sum all the way up to $G$, which just needs to be some large number. You compute it in stages and compare at each stage. Whether you store it or not is not important, the important thing is the value as a function of $i$. Writing it as a sum shows how you do it, writing it as $frac 12i(i+1)$ shows what it is.
      – Ross Millikan
      Jul 27 at 4:29










    • Yes. If you look at "if conditional", you can see the "break" statement there. For this reason, the loop does not operate until G.
      – Abdullah Elen
      Jul 27 at 4:36










    • Yes, I understood that. You asked about expressing the algorithm mathematically but you continue to talk about how the code works. The important thing is to say what value of $T$ is returned based on the input parameters. Mike Earnest's expression is very close to your code. I think it is much less useful to a reader.
      – Ross Millikan
      Jul 27 at 4:47










    • You're right. Not everybody has coding knowledge. For this reason, I should have written with a clearer expression.
      – Abdullah Elen
      Jul 27 at 4:53















    First of all thank you for your quick response. Oh yes. I wrote i instead of j and am going to fix it immediately. However, the "sum" statement does not need to be stored in stages. You can see this in the algorithm. I could express this mathematically.
    – Abdullah Elen
    Jul 27 at 4:21




    First of all thank you for your quick response. Oh yes. I wrote i instead of j and am going to fix it immediately. However, the "sum" statement does not need to be stored in stages. You can see this in the algorithm. I could express this mathematically.
    – Abdullah Elen
    Jul 27 at 4:21












    My point is that you are trying to find the $i$ where the sum exceeds $Mcdot thr$. That is the first thing you should say-it is the spec for the algorithm. Then you don't compute sum all the way up to $G$, which just needs to be some large number. You compute it in stages and compare at each stage. Whether you store it or not is not important, the important thing is the value as a function of $i$. Writing it as a sum shows how you do it, writing it as $frac 12i(i+1)$ shows what it is.
    – Ross Millikan
    Jul 27 at 4:29




    My point is that you are trying to find the $i$ where the sum exceeds $Mcdot thr$. That is the first thing you should say-it is the spec for the algorithm. Then you don't compute sum all the way up to $G$, which just needs to be some large number. You compute it in stages and compare at each stage. Whether you store it or not is not important, the important thing is the value as a function of $i$. Writing it as a sum shows how you do it, writing it as $frac 12i(i+1)$ shows what it is.
    – Ross Millikan
    Jul 27 at 4:29












    Yes. If you look at "if conditional", you can see the "break" statement there. For this reason, the loop does not operate until G.
    – Abdullah Elen
    Jul 27 at 4:36




    Yes. If you look at "if conditional", you can see the "break" statement there. For this reason, the loop does not operate until G.
    – Abdullah Elen
    Jul 27 at 4:36












    Yes, I understood that. You asked about expressing the algorithm mathematically but you continue to talk about how the code works. The important thing is to say what value of $T$ is returned based on the input parameters. Mike Earnest's expression is very close to your code. I think it is much less useful to a reader.
    – Ross Millikan
    Jul 27 at 4:47




    Yes, I understood that. You asked about expressing the algorithm mathematically but you continue to talk about how the code works. The important thing is to say what value of $T$ is returned based on the input parameters. Mike Earnest's expression is very close to your code. I think it is much less useful to a reader.
    – Ross Millikan
    Jul 27 at 4:47












    You're right. Not everybody has coding knowledge. For this reason, I should have written with a clearer expression.
    – Abdullah Elen
    Jul 27 at 4:53




    You're right. Not everybody has coding knowledge. For this reason, I should have written with a clearer expression.
    – Abdullah Elen
    Jul 27 at 4:53










    up vote
    1
    down vote













    Your code is iterating $i$ from $0$ to $G$ and cumulatively incrementing the $textsum$ by that iterator, breaking when $textsum/Mgeq textthr$ (or $textsumgeq Mtimestextthr$ when rounding is not an issue ). Only when breaking is $T$ set to the iterator, otherwise it is left at zero.



    Since $sum_i=0^n i =tfracn,(n+1)2$ , and the values of $M$ and $textthr$ are hard coded constants: $100$ and $0.5$, that code should result in



    $$beginalignT & =begincases 0 &:& G,(G+1)< 100\ mintin0..G: t(t+1)geqslant 100 &:&textotherwise endcases \ &= begincases 0 &:& G<10\ 10 &:& Ggeq 10endcasesendalign$$






    share|cite|improve this answer

























      up vote
      1
      down vote













      Your code is iterating $i$ from $0$ to $G$ and cumulatively incrementing the $textsum$ by that iterator, breaking when $textsum/Mgeq textthr$ (or $textsumgeq Mtimestextthr$ when rounding is not an issue ). Only when breaking is $T$ set to the iterator, otherwise it is left at zero.



      Since $sum_i=0^n i =tfracn,(n+1)2$ , and the values of $M$ and $textthr$ are hard coded constants: $100$ and $0.5$, that code should result in



      $$beginalignT & =begincases 0 &:& G,(G+1)< 100\ mintin0..G: t(t+1)geqslant 100 &:&textotherwise endcases \ &= begincases 0 &:& G<10\ 10 &:& Ggeq 10endcasesendalign$$






      share|cite|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        Your code is iterating $i$ from $0$ to $G$ and cumulatively incrementing the $textsum$ by that iterator, breaking when $textsum/Mgeq textthr$ (or $textsumgeq Mtimestextthr$ when rounding is not an issue ). Only when breaking is $T$ set to the iterator, otherwise it is left at zero.



        Since $sum_i=0^n i =tfracn,(n+1)2$ , and the values of $M$ and $textthr$ are hard coded constants: $100$ and $0.5$, that code should result in



        $$beginalignT & =begincases 0 &:& G,(G+1)< 100\ mintin0..G: t(t+1)geqslant 100 &:&textotherwise endcases \ &= begincases 0 &:& G<10\ 10 &:& Ggeq 10endcasesendalign$$






        share|cite|improve this answer













        Your code is iterating $i$ from $0$ to $G$ and cumulatively incrementing the $textsum$ by that iterator, breaking when $textsum/Mgeq textthr$ (or $textsumgeq Mtimestextthr$ when rounding is not an issue ). Only when breaking is $T$ set to the iterator, otherwise it is left at zero.



        Since $sum_i=0^n i =tfracn,(n+1)2$ , and the values of $M$ and $textthr$ are hard coded constants: $100$ and $0.5$, that code should result in



        $$beginalignT & =begincases 0 &:& G,(G+1)< 100\ mintin0..G: t(t+1)geqslant 100 &:&textotherwise endcases \ &= begincases 0 &:& G<10\ 10 &:& Ggeq 10endcasesendalign$$







        share|cite|improve this answer













        share|cite|improve this answer



        share|cite|improve this answer











        answered Jul 27 at 5:03









        Graham Kemp

        80k43275




        80k43275






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2864034%2fhow-do-i-convert-a-simple-algorithm-to-a-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?