5 Replies - 617 Views - Last Post: 25 September 2012 - 03:13 PM Rate Topic: -----

#1 Hiatus  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 27-May 09

Understanding Xor

Posted 25 September 2012 - 02:25 PM

Hey all, im having trouble understanding what this means:

commutative(op,S) is a function that takes two arguments and returns True only if the first argument op, an operator that takes two arguments, is commutative on the finite set S.

Would op be an actual operator such as +,-,/,*?

And if one were to test this function, how would one go about doing so?

Thanks.

This post has been edited by Hiatus: 25 September 2012 - 02:26 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Understanding Xor

#2 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Understanding Xor

Posted 25 September 2012 - 02:50 PM

Operations are not limited to the basic ones (+, -, /, *) for example XOR could be classed as an operation, AND, OR, EQUIVALANCE.. don't you have some reference as to what operations are valid? Or perhaps any function at all?

In Python, functions are first class so, they can be passed as parameters so that isn't a problem. Commutative basically means that the operation will work if you switch the operands around:

So,

4 + 5 is equal to 5 + 4 so "+" is commutative (or add(x, y) as a function)

4 - 5 is NOT equal to 5 - 4 so "-" is not commutative (or subtract(x, y) as a function)

How would you go about testing if an operand (or function) is commutative or not?

This post has been edited by Simown: 25 September 2012 - 02:56 PM

Was This Post Helpful? 1
  • +
  • -

#3 Hiatus  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 27-May 09

Re: Understanding Xor

Posted 25 September 2012 - 02:59 PM

View PostSimown, on 25 September 2012 - 03:50 PM, said:

Operations are not limited to the basic ones (+, -, /, *) for example XOR could be classed as an operation, AND, OR, EQUIVALANCE.. don't you have some reference as to what operations are valid? Or perhaps any function at all?

In Python, functions are first class so, they can be passed as parameters so that isn't a problem. Commutative basically means that the operation will work if you switch the operands around:

So,

4 + 5 is equal to 5 + 4 so "+" is commutative (or add(x, y) as a function)

4 - 5 is NOT equal to 5 - 4 so "-" is not commutative (or subtract(x, y) as a function)

How would you go about testing if an operand (or function) is commutative or not?


Hi, thanks for the informative response! :)

Well to test if something was commutative in a set S, then I would go about testing if S[0] + S[1] = S[1] + S[0] and traverse the set from there. Is this correct logic? And if so, would I need a for loop to keep track of the index?
Was This Post Helpful? 0
  • +
  • -

#4 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Understanding Xor

Posted 25 September 2012 - 03:07 PM

Yes, that's exactly how to test! But, we want to test every element against every other element to ensure the entire set of items is commutative against the same set without writing S[0] + S[1] = S[1] + S[0].... S[39] + S[40]..... + S[81]... well, you get it.

So, we need to loop, I assume you understand them?

It will go something like this:
def commutative(op, S):
  # First iteration of the set
  for first in S:
    # Second iteration of the same set so every item is compared against the first
    for second in S:
     # Remember the double equals
     if(op(first,second) == op(second, first))



Ok, stop there, now what's left? Finish the code!

This post has been edited by Simown: 25 September 2012 - 11:46 PM

Was This Post Helpful? 1
  • +
  • -

#5 Hiatus  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 27-May 09

Re: Understanding Xor

Posted 25 September 2012 - 03:10 PM

View PostSimown, on 25 September 2012 - 04:07 PM, said:

Yes, that's exactly how to test! But, we want to test every element against every other element to ensure the entire set it commutative in the set without writing S[0] + S[1] = S[1] + S[0].... S[39] + S[40]..... + S[81]... well, you get it.

So, we need to loop, I assume you understand them?

It will go something like this:
def(op, S):
  # First iteration of the set
  for first in S:
    # Second iteration of the same set
    for second in S:
     # Remember the double equals
     if(op(first,second) == op(second, first)



Ok, stop there, now what's left? Finish the code!


Thank you so much! :)

Ill try to finish the code from there.

Thanks again for all of your help!

Rep +1 :D
Was This Post Helpful? 0
  • +
  • -

#6 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Understanding Xor

Posted 25 September 2012 - 03:13 PM

Sure, post back here if you have any more problems and I'm sure anyone will be happy to help.

But really, it's nearly done :)

This post has been edited by Simown: 25 September 2012 - 03:14 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1