Equivalence between ceil and floor functions












1












$begingroup$


I was reading heap data structures from various sources. They used to explain heap as stored in array. One source has array starting at index 0. Other has it starting at 1. They specify different equations for getting index of a parent for node at index 1.



Consider this heap:



enter image description here



1 based indices will be:



Elements: 78    56    32    45    8    23    19
Indices 1 2 3 4 5 6 7


I came across following two equations which correctly gave parent for 0-based indices, when I checked for indices 5 and 6, that is 23 and 19, both have parent 32 at index 2:



$lfloor frac{i-1}{2} rfloor$ and $lfloor frac{i+1}{2}-1 rfloor$



I came across following three equations which correctly gave parent for 1-based indices, when I checked for indices 5 and 6, that is 8 and 23. 8 have parent 56 at index 1 and 23 have parent 32 at index 3:



$lceil frac{i-1}{2} rceil$,$lceil frac{i+1}{2} rceil-1$ and $lfloor frac{i}{2} rfloor$



How can I build mathematical intuition to just tell whether two equations involving ceil and floor functions are equal just at sight. Or given one equation with ceil and floor function, how can I derive all that are equivalent to it?



For example how can I quickly tell





  • $lfloor frac{i-1}{2} rfloor$ is equivalent to $lfloor frac{i+1}{2}-1 rfloor$ but not to $lfloor frac{i+1}{2} rfloor-1$


  • $lceil frac{i-1}{2} rceil$ is equivalent to $lceil frac{i+1}{2} rceil-1$, but not to $lceil frac{i-1}{2} +1rceil$


Is it possible to tell this only by trying out examples? Because I can guess at least 12 equations involving (add 1/substract 1/do nothng) in (numerator/inside/outside) of ceil/floor functions.



Pardon me for asking possibly primary maths question.










share|cite|improve this question









$endgroup$

















    1












    $begingroup$


    I was reading heap data structures from various sources. They used to explain heap as stored in array. One source has array starting at index 0. Other has it starting at 1. They specify different equations for getting index of a parent for node at index 1.



    Consider this heap:



    enter image description here



    1 based indices will be:



    Elements: 78    56    32    45    8    23    19
    Indices 1 2 3 4 5 6 7


    I came across following two equations which correctly gave parent for 0-based indices, when I checked for indices 5 and 6, that is 23 and 19, both have parent 32 at index 2:



    $lfloor frac{i-1}{2} rfloor$ and $lfloor frac{i+1}{2}-1 rfloor$



    I came across following three equations which correctly gave parent for 1-based indices, when I checked for indices 5 and 6, that is 8 and 23. 8 have parent 56 at index 1 and 23 have parent 32 at index 3:



    $lceil frac{i-1}{2} rceil$,$lceil frac{i+1}{2} rceil-1$ and $lfloor frac{i}{2} rfloor$



    How can I build mathematical intuition to just tell whether two equations involving ceil and floor functions are equal just at sight. Or given one equation with ceil and floor function, how can I derive all that are equivalent to it?



    For example how can I quickly tell





    • $lfloor frac{i-1}{2} rfloor$ is equivalent to $lfloor frac{i+1}{2}-1 rfloor$ but not to $lfloor frac{i+1}{2} rfloor-1$


    • $lceil frac{i-1}{2} rceil$ is equivalent to $lceil frac{i+1}{2} rceil-1$, but not to $lceil frac{i-1}{2} +1rceil$


    Is it possible to tell this only by trying out examples? Because I can guess at least 12 equations involving (add 1/substract 1/do nothng) in (numerator/inside/outside) of ceil/floor functions.



    Pardon me for asking possibly primary maths question.










    share|cite|improve this question









    $endgroup$















      1












      1








      1





      $begingroup$


      I was reading heap data structures from various sources. They used to explain heap as stored in array. One source has array starting at index 0. Other has it starting at 1. They specify different equations for getting index of a parent for node at index 1.



      Consider this heap:



      enter image description here



      1 based indices will be:



      Elements: 78    56    32    45    8    23    19
      Indices 1 2 3 4 5 6 7


      I came across following two equations which correctly gave parent for 0-based indices, when I checked for indices 5 and 6, that is 23 and 19, both have parent 32 at index 2:



      $lfloor frac{i-1}{2} rfloor$ and $lfloor frac{i+1}{2}-1 rfloor$



      I came across following three equations which correctly gave parent for 1-based indices, when I checked for indices 5 and 6, that is 8 and 23. 8 have parent 56 at index 1 and 23 have parent 32 at index 3:



      $lceil frac{i-1}{2} rceil$,$lceil frac{i+1}{2} rceil-1$ and $lfloor frac{i}{2} rfloor$



      How can I build mathematical intuition to just tell whether two equations involving ceil and floor functions are equal just at sight. Or given one equation with ceil and floor function, how can I derive all that are equivalent to it?



      For example how can I quickly tell





      • $lfloor frac{i-1}{2} rfloor$ is equivalent to $lfloor frac{i+1}{2}-1 rfloor$ but not to $lfloor frac{i+1}{2} rfloor-1$


      • $lceil frac{i-1}{2} rceil$ is equivalent to $lceil frac{i+1}{2} rceil-1$, but not to $lceil frac{i-1}{2} +1rceil$


      Is it possible to tell this only by trying out examples? Because I can guess at least 12 equations involving (add 1/substract 1/do nothng) in (numerator/inside/outside) of ceil/floor functions.



      Pardon me for asking possibly primary maths question.










      share|cite|improve this question









      $endgroup$




      I was reading heap data structures from various sources. They used to explain heap as stored in array. One source has array starting at index 0. Other has it starting at 1. They specify different equations for getting index of a parent for node at index 1.



      Consider this heap:



      enter image description here



      1 based indices will be:



      Elements: 78    56    32    45    8    23    19
      Indices 1 2 3 4 5 6 7


      I came across following two equations which correctly gave parent for 0-based indices, when I checked for indices 5 and 6, that is 23 and 19, both have parent 32 at index 2:



      $lfloor frac{i-1}{2} rfloor$ and $lfloor frac{i+1}{2}-1 rfloor$



      I came across following three equations which correctly gave parent for 1-based indices, when I checked for indices 5 and 6, that is 8 and 23. 8 have parent 56 at index 1 and 23 have parent 32 at index 3:



      $lceil frac{i-1}{2} rceil$,$lceil frac{i+1}{2} rceil-1$ and $lfloor frac{i}{2} rfloor$



      How can I build mathematical intuition to just tell whether two equations involving ceil and floor functions are equal just at sight. Or given one equation with ceil and floor function, how can I derive all that are equivalent to it?



      For example how can I quickly tell





      • $lfloor frac{i-1}{2} rfloor$ is equivalent to $lfloor frac{i+1}{2}-1 rfloor$ but not to $lfloor frac{i+1}{2} rfloor-1$


      • $lceil frac{i-1}{2} rceil$ is equivalent to $lceil frac{i+1}{2} rceil-1$, but not to $lceil frac{i-1}{2} +1rceil$


      Is it possible to tell this only by trying out examples? Because I can guess at least 12 equations involving (add 1/substract 1/do nothng) in (numerator/inside/outside) of ceil/floor functions.



      Pardon me for asking possibly primary maths question.







      floor-function ceiling-function






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Jan 14 at 16:38









      aniranir

      420211




      420211






















          1 Answer
          1






          active

          oldest

          votes


















          1












          $begingroup$

          Regarding your two examples, note that $frac{i+1}{2}-1 = frac{i+1-2}{2} = frac{i-1}{2}$, and $frac{i-1}{2}+1 = frac{i-1+2}{2} = frac{i+1}{2}$. So it's not really about ceil and floor here, the expressions inside are just equal.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            But then what about equivalences like: those in which ceil and floor $lceil frac{i-1}{2} rceil = lceil frac{i+1}{2} rceil-1$. Doesnt ceil function plays any role here?
            $endgroup$
            – anir
            Jan 14 at 19:31






          • 1




            $begingroup$
            Assume $i=2k+1, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ so they are equal. Now let $i=2k, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ once again. So they are equal. For a division by 3 you will have to check 3 cases ($3k, 3k+1, 3k+2$), for a division by $n$, you would have to check $n$ cases.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:36










          • $begingroup$
            (1) Thats same as I checked with 5 and 6, right? You very well generalized it for arbitrary denominator. (2) And if I understood it all correct, we really have to manually check for such equivalences involving ceil and floor functions. Right?
            $endgroup$
            – anir
            Jan 14 at 19:45






          • 1




            $begingroup$
            Not exactly the same, but close enough. And yes, I do think you need to check the cases based on the denominator for expressions that are not equivalent inside the ceil.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:52












          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3073424%2fequivalence-between-ceil-and-floor-functions%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1












          $begingroup$

          Regarding your two examples, note that $frac{i+1}{2}-1 = frac{i+1-2}{2} = frac{i-1}{2}$, and $frac{i-1}{2}+1 = frac{i-1+2}{2} = frac{i+1}{2}$. So it's not really about ceil and floor here, the expressions inside are just equal.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            But then what about equivalences like: those in which ceil and floor $lceil frac{i-1}{2} rceil = lceil frac{i+1}{2} rceil-1$. Doesnt ceil function plays any role here?
            $endgroup$
            – anir
            Jan 14 at 19:31






          • 1




            $begingroup$
            Assume $i=2k+1, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ so they are equal. Now let $i=2k, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ once again. So they are equal. For a division by 3 you will have to check 3 cases ($3k, 3k+1, 3k+2$), for a division by $n$, you would have to check $n$ cases.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:36










          • $begingroup$
            (1) Thats same as I checked with 5 and 6, right? You very well generalized it for arbitrary denominator. (2) And if I understood it all correct, we really have to manually check for such equivalences involving ceil and floor functions. Right?
            $endgroup$
            – anir
            Jan 14 at 19:45






          • 1




            $begingroup$
            Not exactly the same, but close enough. And yes, I do think you need to check the cases based on the denominator for expressions that are not equivalent inside the ceil.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:52
















          1












          $begingroup$

          Regarding your two examples, note that $frac{i+1}{2}-1 = frac{i+1-2}{2} = frac{i-1}{2}$, and $frac{i-1}{2}+1 = frac{i-1+2}{2} = frac{i+1}{2}$. So it's not really about ceil and floor here, the expressions inside are just equal.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            But then what about equivalences like: those in which ceil and floor $lceil frac{i-1}{2} rceil = lceil frac{i+1}{2} rceil-1$. Doesnt ceil function plays any role here?
            $endgroup$
            – anir
            Jan 14 at 19:31






          • 1




            $begingroup$
            Assume $i=2k+1, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ so they are equal. Now let $i=2k, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ once again. So they are equal. For a division by 3 you will have to check 3 cases ($3k, 3k+1, 3k+2$), for a division by $n$, you would have to check $n$ cases.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:36










          • $begingroup$
            (1) Thats same as I checked with 5 and 6, right? You very well generalized it for arbitrary denominator. (2) And if I understood it all correct, we really have to manually check for such equivalences involving ceil and floor functions. Right?
            $endgroup$
            – anir
            Jan 14 at 19:45






          • 1




            $begingroup$
            Not exactly the same, but close enough. And yes, I do think you need to check the cases based on the denominator for expressions that are not equivalent inside the ceil.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:52














          1












          1








          1





          $begingroup$

          Regarding your two examples, note that $frac{i+1}{2}-1 = frac{i+1-2}{2} = frac{i-1}{2}$, and $frac{i-1}{2}+1 = frac{i-1+2}{2} = frac{i+1}{2}$. So it's not really about ceil and floor here, the expressions inside are just equal.






          share|cite|improve this answer









          $endgroup$



          Regarding your two examples, note that $frac{i+1}{2}-1 = frac{i+1-2}{2} = frac{i-1}{2}$, and $frac{i-1}{2}+1 = frac{i-1+2}{2} = frac{i+1}{2}$. So it's not really about ceil and floor here, the expressions inside are just equal.







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Jan 14 at 17:33









          lightxbulblightxbulb

          1,169311




          1,169311












          • $begingroup$
            But then what about equivalences like: those in which ceil and floor $lceil frac{i-1}{2} rceil = lceil frac{i+1}{2} rceil-1$. Doesnt ceil function plays any role here?
            $endgroup$
            – anir
            Jan 14 at 19:31






          • 1




            $begingroup$
            Assume $i=2k+1, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ so they are equal. Now let $i=2k, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ once again. So they are equal. For a division by 3 you will have to check 3 cases ($3k, 3k+1, 3k+2$), for a division by $n$, you would have to check $n$ cases.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:36










          • $begingroup$
            (1) Thats same as I checked with 5 and 6, right? You very well generalized it for arbitrary denominator. (2) And if I understood it all correct, we really have to manually check for such equivalences involving ceil and floor functions. Right?
            $endgroup$
            – anir
            Jan 14 at 19:45






          • 1




            $begingroup$
            Not exactly the same, but close enough. And yes, I do think you need to check the cases based on the denominator for expressions that are not equivalent inside the ceil.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:52


















          • $begingroup$
            But then what about equivalences like: those in which ceil and floor $lceil frac{i-1}{2} rceil = lceil frac{i+1}{2} rceil-1$. Doesnt ceil function plays any role here?
            $endgroup$
            – anir
            Jan 14 at 19:31






          • 1




            $begingroup$
            Assume $i=2k+1, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ so they are equal. Now let $i=2k, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ once again. So they are equal. For a division by 3 you will have to check 3 cases ($3k, 3k+1, 3k+2$), for a division by $n$, you would have to check $n$ cases.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:36










          • $begingroup$
            (1) Thats same as I checked with 5 and 6, right? You very well generalized it for arbitrary denominator. (2) And if I understood it all correct, we really have to manually check for such equivalences involving ceil and floor functions. Right?
            $endgroup$
            – anir
            Jan 14 at 19:45






          • 1




            $begingroup$
            Not exactly the same, but close enough. And yes, I do think you need to check the cases based on the denominator for expressions that are not equivalent inside the ceil.
            $endgroup$
            – lightxbulb
            Jan 14 at 19:52
















          $begingroup$
          But then what about equivalences like: those in which ceil and floor $lceil frac{i-1}{2} rceil = lceil frac{i+1}{2} rceil-1$. Doesnt ceil function plays any role here?
          $endgroup$
          – anir
          Jan 14 at 19:31




          $begingroup$
          But then what about equivalences like: those in which ceil and floor $lceil frac{i-1}{2} rceil = lceil frac{i+1}{2} rceil-1$. Doesnt ceil function plays any role here?
          $endgroup$
          – anir
          Jan 14 at 19:31




          1




          1




          $begingroup$
          Assume $i=2k+1, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ so they are equal. Now let $i=2k, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ once again. So they are equal. For a division by 3 you will have to check 3 cases ($3k, 3k+1, 3k+2$), for a division by $n$, you would have to check $n$ cases.
          $endgroup$
          – lightxbulb
          Jan 14 at 19:36




          $begingroup$
          Assume $i=2k+1, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ so they are equal. Now let $i=2k, k in mathbb{N}$, then the right hand side evaluates to $k$ and the left hand side evaluates to $k+1-1$ once again. So they are equal. For a division by 3 you will have to check 3 cases ($3k, 3k+1, 3k+2$), for a division by $n$, you would have to check $n$ cases.
          $endgroup$
          – lightxbulb
          Jan 14 at 19:36












          $begingroup$
          (1) Thats same as I checked with 5 and 6, right? You very well generalized it for arbitrary denominator. (2) And if I understood it all correct, we really have to manually check for such equivalences involving ceil and floor functions. Right?
          $endgroup$
          – anir
          Jan 14 at 19:45




          $begingroup$
          (1) Thats same as I checked with 5 and 6, right? You very well generalized it for arbitrary denominator. (2) And if I understood it all correct, we really have to manually check for such equivalences involving ceil and floor functions. Right?
          $endgroup$
          – anir
          Jan 14 at 19:45




          1




          1




          $begingroup$
          Not exactly the same, but close enough. And yes, I do think you need to check the cases based on the denominator for expressions that are not equivalent inside the ceil.
          $endgroup$
          – lightxbulb
          Jan 14 at 19:52




          $begingroup$
          Not exactly the same, but close enough. And yes, I do think you need to check the cases based on the denominator for expressions that are not equivalent inside the ceil.
          $endgroup$
          – lightxbulb
          Jan 14 at 19:52


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Mathematics Stack Exchange!


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

          But avoid



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

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


          Use MathJax to format equations. MathJax reference.


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




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3073424%2fequivalence-between-ceil-and-floor-functions%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Cabo Verde

          Gyllenstierna