[R] [FORGED] Logical Operators' inconsistent Behavior
William Michels
wjm1 at caa.columbia.edu
Mon May 22 20:04:27 CEST 2017
Evaluation of the NOT, AND, OR logical statements below in MySQL
5.5.30-log Community Server (GPL) replicate R's truth tables for NOT,
AND, OR. See MySQL queries (below), which are in agreement with R
truth table code posted in this thread:
bash-3.2$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 346
Server version: 5.5.30-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SELECT FALSE, NULL, TRUE;
+-------+------+------+
| FALSE | NULL | TRUE |
+-------+------+------+
| 0 | NULL | 1 |
+-------+------+------+
1 row in set (0.00 sec)
mysql> SELECT NOT FALSE, NOT NULL, NOT TRUE;
+-----------+----------+----------+
| NOT FALSE | NOT NULL | NOT TRUE |
+-----------+----------+----------+
| 1 | NULL | 0 |
+-----------+----------+----------+
1 row in set (0.00 sec)
mysql> SELECT FALSE AND FALSE,
-> FALSE AND NULL,
-> FALSE AND TRUE;
+-----------------+----------------+----------------+
| FALSE AND FALSE | FALSE AND NULL | FALSE AND TRUE |
+-----------------+----------------+----------------+
| 0 | 0 | 0 |
+-----------------+----------------+----------------+
1 row in set (0.00 sec)
mysql> SELECT NULL AND NULL,
-> NULL AND TRUE,
-> TRUE AND TRUE;
+---------------+---------------+---------------+
| NULL AND NULL | NULL AND TRUE | TRUE AND TRUE |
+---------------+---------------+---------------+
| NULL | NULL | 1 |
+---------------+---------------+---------------+
1 row in set (0.00 sec)
mysql> SELECT TRUE OR TRUE,
-> NULL OR TRUE,
-> FALSE OR TRUE;
+--------------+--------------+---------------+
| TRUE OR TRUE | NULL OR TRUE | FALSE OR TRUE |
+--------------+--------------+---------------+
| 1 | 1 | 1 |
+--------------+--------------+---------------+
1 row in set (0.00 sec)
mysql> SELECT NULL OR NULL,
-> FALSE OR NULL,
-> FALSE OR FALSE;
+--------------+---------------+----------------+
| NULL OR NULL | FALSE OR NULL | FALSE OR FALSE |
+--------------+---------------+----------------+
| NULL | NULL | 0 |
+--------------+---------------+----------------+
1 row in set (0.00 sec)
mysql>
HTH,
Bill
William Michels, Ph.D.
On Sun, May 21, 2017 at 7:00 AM, Hadley Wickham <h.wickham at gmail.com> wrote:
> On Fri, May 19, 2017 at 6:38 AM, S Ellison <S.Ellison at lgcgroup.com> wrote:
>>> TRUE & FALSE is FALSE but TRUE & TRUE is TRUE, so TRUE & NA could be
>>> either TRUE or FALSE and consequently is NA.
>>>
>>> OTOH FALSE & (anything) is FALSE so FALSE & NA is FALSE.
>>>
>>> As I said *think* about it; don't just go with your immediate knee-jerk
>>> (simplistic) reaction.
>>
>> Hmm... not sure that was quite fair to the OP. Yes, FALSE & <anything> == FALSE. But 'NA' does not mean 'anything'; it means 'missing' (see ?'NA'). It is much less obvious that FALSE & <missing> should generate a non-missing value. SQL, for example, generally takes the view that any expression involving 'missing' is 'missing'.
>
> That's not TRUE ;)
>
> sqlite> select (3 > 2) OR NULL;
> 1
>
> sqlite> select (4 < 3) AND NULL;
> 0
>
> Hadley
>
>
> --
> http://hadley.nz
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list