relations/identities

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aarklon@gmail.com

    #1

    relations/identities

    Hi all,

    the following are the relations involving modulus operator that i have
    found working

    1) a = a %b + (a/b) * b ; for integral values of a and b

    2) w % n = w & (n-1);

    can any one give more examples for relations like this ...????
  • Richard Tobin

    #2
    Re: relations/identities

    In article <f10506df-970d-4404-bd0f-541a79dd83ae@b4 0g2000prf.googl egroups.com>,
    <aarklon@gmail. comwrote:
    >2) w % n = w & (n-1);
    You need a constraint on n here. 5 % 3 = 2 but 5 & 2 = 0.

    -- Richard
    --
    :wq

    Comment

    • aarklon@gmail.com

      #3
      Re: relations/identities

      On Dec 7, 1:42 pm, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
      In article <f10506df-970d-4404-bd0f-541a79dd8...@b4 0g2000prf.googl egroups.com>,
      >
      <aark...@gmail. comwrote:
      2) w % n = w & (n-1);
      >
      You need a constraint on n here. 5 % 3 = 2 but 5 & 2 = 0.
      >
      -- Richard
      --
      :wq
      sorry i made a mistake

      it should be rather w % (n-1) = w & n;

      now
      5 % 2 = 1
      5 & 3 = 1

      Comment

      • Peter Nilsson

        #4
        Re: relations/identities

        aark...@gmail.c om wrote:
        rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
        <aark...@gmail. comwrote:
        2) w % n = w & (n-1);
        You need a constraint on n here.
        And w.
        5 % 3 = 2 but 5 & 2 = 0.
        >
        sorry i made a mistake
        Your correction was a much bigger mistake.
        it should be rather w % (n-1) = w & n;
        Even on its own terms this makes no sense. [Try w == n.]

        --
        Peter

        Comment

        • aarklon@gmail.com

          #5
          Re: relations/identities

          On Dec 8, 2:30 am, Peter Nilsson <ai...@acay.com .auwrote:
          aark...@gmail.c om wrote:
          rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
          <aark...@gmail. comwrote:
          2) w % n = w & (n-1);
          >
          You need a constraint on n here.
          >
          And w.
          >
          5 % 3 = 2 but 5 & 2 = 0.
          >
          sorry i made a mistake
          >
          Your correction was a much bigger mistake.
          >
          it should be rather w % (n-1) = w & n;
          >
          Even on its own terms this makes no sense. [Try w == n.]
          let us add a constraint n < w and n >= 2

          Comment

          • Richard Heathfield

            #6
            Re: relations/identities

            aarklon@gmail.c om said:
            On Dec 8, 2:30 am, Peter Nilsson <ai...@acay.com .auwrote:
            >aark...@gmail. com wrote:
            rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
            <aark...@gmail. comwrote:
            2) w % n = w & (n-1);
            >>
            You need a constraint on n here.
            >>
            >And w.
            >>
            5 % 3 = 2 but 5 & 2 = 0.
            >>
            sorry i made a mistake
            >>
            >Your correction was a much bigger mistake.
            >>
            it should be rather w % (n-1) = w & n;
            >>
            >Even on its own terms this makes no sense. [Try w == n.]
            >
            let us add a constraint n < w and n >= 2
            Okay. Let n = 79, and let w = 83. w % n is 4, but w & (n - 1) is 66 if my
            bit-twiddling is right. Last I checked, 4 != 66.

            --
            Richard Heathfield <http://www.cpax.org.uk >
            Email: -http://www. +rjh@
            Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
            "Usenet is a strange place" - dmr 29 July 1999

            Comment

            • James Kuyper

              #7
              Re: relations/identities

              aarklon@gmail.c om wrote:
              Hi all,
              >
              the following are the relations involving modulus operator that i have
              found working
              ....
              2) w % n = w & (n-1);
              >
              can any one give more examples for relations like this ...????
              The second relationship is true only when n is a power of 2.

              Comment

              • aarklon@gmail.com

                #8
                Re: relations/identities

                On Dec 8, 7:57 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                aark...@gmail.c om said:
                >
                >
                >
                On Dec 8, 2:30 am, Peter Nilsson <ai...@acay.com .auwrote:
                aark...@gmail.c om wrote:
                rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
                <aark...@gmail. comwrote:
                2) w % n = w & (n-1);
                >
                You need a constraint on n here.
                >
                And w.
                >
                5 % 3 = 2 but 5 & 2 = 0.
                >
                sorry i made a mistake
                >
                Your correction was a much bigger mistake.
                >
                it should be rather w % (n-1) = w & n;
                >
                Even on its own terms this makes no sense. [Try w == n.]
                >
                let us add a constraint n < w and n >= 2
                >
                Okay. Let n = 79, and let w = 83. w % n is 4, but w & (n - 1) is 66 if my
                bit-twiddling is right. Last I checked, 4 != 66.
                I have seen this result in one book, but i don't remember it
                correctly.I think it is in your book "C unleashed"

                Comment

                • ptkmartin@gmail.com

                  #9
                  Re: relations/identities

                  On Dec 8, 10:00 am, aark...@gmail.c om wrote:
                  w % n = w & (n-1);
                  I have seen this result in one book, but i don't remember it correctly.
                  You remembered it wrong.

                  The formula above is guaranteed only if n is a power of 2.
                  That is, n must be 1, or 2, or 4, or 8, or 16, or 32...

                  Comment

                  Working...