-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added XNOR Function to SymPy #1154
Conversation
There is a test failure. See Test1 in Before pull request please run those commands to be sure that all tests passed:
as it is described in Running tests, Development workflow |
""" | ||
Logical XNOR function. | ||
|
||
Evaluates the XOR function and returns its inverse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a full-stop at the end of the sentence.
As discussed on the list,
|
@toolforger On 2): XNOR and Equivalent are only the same when the number of arguments is 2. We could, say, write it so that it returns true when an even number of arguments is true (in comparison to XOR, which returns true when an odd number or arguments is true), but I don't think this is standard. |
@tesserahub: Nope, they're the same. |
We define NAND(A, B, C) as NOT(A AND B AND C), not A NAND B NAND C, so I don't see why we can't define XNOR likewise. Equivalent(A, B, C) is true only if all of A, B, C are true or all of A, B, C are false. Equivalent(True, False, False) returns False. However, (A XNOR B) XNOR C returns true if A = True, B = False, C = False. Not the same. |
Hm. I see. Not just for Nand but also for other operators. |
You shouldn't consider NAND(A, B, C) to be (A NAND B) NAND C, just as we don't think of EQUIV(A, B, C) as (A EQUIV B) EQUIV C. Things like Logic gates consider NAND(a, b, c...) as NOT(AND(a, b, c, ...)), so I don't think it's a bug. Think of them as n-ary operators rather than a reduction of n-1 binary operators. I think this request should be reopened... |
I tried to throw a look at how the corresponding multiple input logic gates work:
In my reading, this means that This is certainly different from equivalence and I agree with Joachim on the matter that binary operations are usually extended to more than two (finitely many) arguments by inductively applying the operation to pairs: |
That link on multiple input logic gates was quite instructive: "Many authorities contend that the shaped XOR gate's behavior should correspond to the odd parity gate, but there is not agreement on this point." If no agreement can be reached, the case should be undefined, i.e. XOR, XNOR, NAND etc. should be defined to have exactly two parameters. To cover the inductive case, we could have a class that accepts an operator and an unlimited list of parameters. That way, we don't have to write an inductive variant for every operator. |
That's a great idea. I think this might be a good thing to do for a patch requirement ;-) |
The class should probably be named Reduce, in analogy to functools.reduce. |
I'll reopen this by adjusting the design and adding the full stops where appropriate! |
@tesserahub I agree with you. If NAND and NOR are defined in this manner so should XNOR. @scolobb I suppose your definition is in harmony with mine. Therefore, I've adjusted the design flaws and reopened the pull request. |
None of these changes address the basic issue: that it's unclear what the semantics of a multi-parameter XNOR should be. This does not mean that your patch requirement is not fulfilled; I think @asmeurer has to decide that. |
@toolforger Your inputs are valuable. My project proposal has more to do with creating an Android app so my knowledge of the Python code should, hopefully, be considered less important. I'll wait to see what @asmeurer has to say! |
@toolforger @scolobb |
SymPy Bot Summary: ✳️ All tests have passed. Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYtakUDA Interpreter: /usr/bin/python2.6 (2.6.7-final-0) Automatic review by SymPy Bot. |
This PR as it is cannot be merged, so I am closing this for now. Feel free to reopen it if more work is done. |
Added the "XNor" Function to sympy/logic/boolalg.py since it was missing