[R] [FORGED] Logical Operators' inconsistent Behavior

William Michels wjm1 at caa.columbia.edu
Mon May 22 06:35:57 CEST 2017


Looking below and online, R's truth tables for NOT, AND, OR are
identical to the NOT, AND, OR truth tables originating from Stephen
Cole Kleene's "strong logic of indeterminacy", as demonstrated on the
Wikipedia page entitled, "Three-Valued Logic"--specifically in the
section entitled "Kleene and Priest Logics":

https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_and_Priest_logics

>
> ttNOT <- cbind(c(FALSE, NA, TRUE), !c(FALSE, NA, TRUE))
> rownames(ttNOT) <- c("False", "na", "True")
> colnames(ttNOT) <- c("A", "Not(A)")
> ttNOT
          A Not(A)
False FALSE   TRUE
na       NA     NA
True   TRUE  FALSE
>
> ttAND <- outer(c(FALSE, NA, TRUE), c(FALSE, NA, TRUE), "&" )
> rownames(ttAND) <- c("False", "na", "True")
> colnames(ttAND) <- c("False", "na", "True")
> ttAND
      False    na  True
False FALSE FALSE FALSE
na    FALSE    NA    NA
True  FALSE    NA  TRUE
>
> ttOR <- outer(c(FALSE, NA, TRUE), c(FALSE, NA, TRUE), "|" )
> rownames(ttOR) <- c("False", "na", "True")
> colnames(ttOR) <- c("False", "na", "True")
> ttOR
      False   na True
False FALSE   NA TRUE
na       NA   NA TRUE
True   TRUE TRUE TRUE
>
>

The bottom section of the same Wikipedia page (section entitled
"Application in SQL" ), and an additional Wikipedia page entitled
"Null (SQL)" discusses how the Kleene logic described above is
differentially implemented in SQL.

https://en.wikipedia.org/wiki/Null_(SQL)

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