5
$\begingroup$

I am trying to understand how logical functions are evaluated if no arguments are passed to them.

{Or[], Nor[], And[], Nand[], Xor[], Xnor[]}

{False, True, True, False, False, True}

I tried Trace but it didn't offer many clues. Mathematica (12.2.0 on Win7-x64) evaluates these expressions without any messages.

Thanks in advance for your help.

$\endgroup$
6
  • $\begingroup$ If you have a look in the Properties and relations section you will see that it zero-argument evaluates to False. reference.wolfram.com/language/ref/Or.html $\endgroup$
    – user49048
    Feb 28, 2022 at 8:39
  • $\begingroup$ Similar situation in Java developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… $\endgroup$
    – user49048
    Feb 28, 2022 at 8:39
  • $\begingroup$ Perhaps this is the way they are supposed to be constructed based on theoretical coding principles? Sorry for the triple comment...I am horrible $\endgroup$
    – user49048
    Feb 28, 2022 at 8:40
  • 3
    $\begingroup$ These are simply the trivial cases for these functions. And, for example, is True unless one of it's arguments is False. The zero-argument case is just an extension of that. $\endgroup$ Feb 28, 2022 at 11:05
  • 4
    $\begingroup$ One sees similar behavior with Plus and Times (where it might be more obviously plausible). Symbols with the OneIdentity attribute will, when given an empty argument list, evaluate to their respective identity elements. $\endgroup$ Feb 28, 2022 at 15:57

2 Answers 2

6
$\begingroup$

I am pretty sure that Syed figured out the question by now, but for future visitors I thought it a good idea to write something.

  1. Why does Or[] return False?

From the docs we read

It evaluates its arguments in order, giving True immediately if any of them are True, and False if they are all False.

which is another way of saying that it returns True if any or all of its arguments is true and False otherwise.

  1. Why does Nor[] return True?

The easiest way to realize this -I think- is again to have a look at the documentation where we find that it is equivalent to Not[Or[]]. So, Not[False] is True.

  1. Why does And[] return True?

Well, again this can be seen directly from the docs and also from the comment by @Sjoerd Smit.

It evaluates to False if any of its arguments are false, and to True otherwise.

  1. Why does Nand[] return False?

Similar to the explanation of Nor in this case. Nand[] is equivalent to Not[And[]] and hence Not[True] which is False.

  1. Why does Xor[] return False?

Well, it has to evaluate all of its argument and yields True if an odd number of them is True and False otherwise. Since, we do not have an odd number of True statements, it returns False

  1. Why does Xnor[] return True?

Xnor[] is equivalent to Not[Xor[]]

$\endgroup$
4
  • 1
    $\begingroup$ Thanks for the write up. $\endgroup$
    – Syed
    Jan 14, 2023 at 12:56
  • $\begingroup$ @Syed if you want to add more to it, let me know and I will turn it into a wiki :-) $\endgroup$
    – bmf
    Jan 14, 2023 at 12:58
  • 1
    $\begingroup$ It seems that in your description of Nor True and False should be reversed. $\endgroup$
    – yarchik
    Jan 14, 2023 at 19:26
  • $\begingroup$ @yarchik yes, of course you are right. thanks for spotting this :-) $\endgroup$
    – bmf
    Jan 15, 2023 at 1:38
3
$\begingroup$

The answer of @bmf is perfect, but I would like to bring some arguments that allow us to better remember the results. It also shows a connection to other MA functions.

The Xor function can be seen as Sum modulo 2. In fact

Sum[1, {i, 0}]
(* 0 *)

which explains why Xor[] == False.

The And function can be regarded as the Product modulo 2. In fact

Product[1, {i, 0}]
(* 1 *)

which explains why And[] == True.

See also a comment of @DanielLichtblau above, which argues in terms of Plus and Times.

$\endgroup$
1
  • $\begingroup$ (+1) that's a very neat description!!! $\endgroup$
    – bmf
    Jan 15, 2023 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.