Logical XOR (Migrated from community.research.microsoft.com)

Traitée Logical XOR (Migrated from community.research.microsoft.com)

  • Freitag, 3. Juni 2011 18:43
    Besitzer
     
     

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

Alle Antworten

  • Freitag, 3. Juni 2011 18:43
    Besitzer
     
     

    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

  • Freitag, 3. Juni 2011 18:43
    Besitzer
     
     Beantwortet

    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