locked
Logical XOR (Migrated from community.research.microsoft.com) RRS feed

  • Question

  • vtan posted on 03-31-2011 8:28 PM

    Hi John,

    I'm using Infer.NET to solve a decoding problem in GF(2). I am trying to do a logical XOR of  Variable<bool>[ ] m, since there's no inbuilt logical XOR. I've attached the code to the end of this message. It compiles fine but the inference results are not symmetric in the arguments of the array m, when I think it should be since GF(2) + (or logical XOR) is commutative. Any help would be appreciated.  

    Thanks,

    Vincent Tan

     

     s1 = gf2sum4vectors(m1);

     private Variable<bool> gf2sum4vectors(Variable<bool>[] m)
            {
                Variable<bool>[] partialSums = new Variable<bool>[m.Length];
                for (int i = 0; i < m.Length; i++)
                {
                    if (i == 0)
                        partialSums[i] = m[0];
                    else
                        partialSums[i] = gf2sum(partialSums[i - 1], m[i]);
                }

                return partialSums[m.Length - 1];
            }

            private Variable<bool> gf2sum(Variable<bool> a, Variable<bool> b)
            {
                return ((a & (!b)) | (b & (!a)));
            }

    Friday, June 3, 2011 6:43 PM

Answers

  • vtan replied on 04-01-2011 10:46 AM

    Hi John,

    (a!=b) is a nice way of implementing XOR. Strangely though, in my application, doing (a & !b) | (b & !a) yields results that are more correct. I can't explain why.

    Vincent

    Friday, June 3, 2011 6:43 PM

All replies

  • John Guiver replied on 04-01-2011 10:18 AM

    Hi Vincent

    Have you seen the following post: http://community.research.microsoft.com/forums/t/4202.aspx? This discusses how to do XOR for single variables - i.e. your gf2sum method. Try that, and if there are still problems, please repost.

    John

    Friday, June 3, 2011 6:43 PM
  • vtan replied on 04-01-2011 10:46 AM

    Hi John,

    (a!=b) is a nice way of implementing XOR. Strangely though, in my application, doing (a & !b) | (b & !a) yields results that are more correct. I can't explain why.

    Vincent

    Friday, June 3, 2011 6:43 PM