I'm trying to make an 'implies' operator for logical variables in R to make propositional calculus easier. However it doesn't seem to be playing nice with the negation operator. As the last 4 lines here indicate, I have to wrap negated variables in parentheses to get the implication operator to work correctly.
I suspect that operator precedence is the issue but I'm not sure. And from what I read there isn't a way to change an infix operator's precedence. Is there a way I could redefine implies()
so that the parentheses in (!q) %->% (!p)
wouldn't be necessary?
> implies <- function(p, q) !p | q
> "%->%" <- implies
>
> p <- c(TRUE, TRUE, FALSE, FALSE)
> q <- c(TRUE, FALSE, TRUE, FALSE)
> p %->% q
[1] TRUE FALSE TRUE TRUE
> !q %->% !p
[1] TRUE FALSE FALSE FALSE
> (!q) %->% !p
[1] TRUE FALSE TRUE TRUE