# 16通りのブール演算:ぱらぱらめくる『クヌース本4.1』

• という演算はの値の取り方４通りのそれぞれに(0,1)のいずれかを対応付けることで網羅できるから、通りある
• 16種類の演算のそれぞれについて2x2テーブルを作ってみる
boolean.op <- array(c(t(expand.grid(rep(list(0:1),4)))),c(2,2,16))

# The i-th operation's output is:
i <- 3
boolean.op[,,i]
# The first argument is x (=0,1) and the second argument y (=0,1).

x <- 0
y <- 1

boolean.op[x+1,y+1,i]

> boolean.op[,,1]
[,1] [,2]
[1,]    0    0
[2,]    0    0

> boolean.op[,,16]
[,1] [,2]
[1,]    1    1
[2,]    1    1

> boolean.op[,,9]
[,1] [,2]
[1,]    0    0
[2,]    0    1

> boolean.op[,,8]
[,1] [,2]
[1,]    1    1
[2,]    1    0

• Material nonimplication、
> boolean.op[,,3]
[,1] [,2]
[1,]    0    0
[2,]    1    0

• 含意(条件式)、
> boolean.op[,,14]
[,1] [,2]
[1,]    1    1
[2,]    0    1

• 命題P、
> boolean.op[,,11]
[,1] [,2]
[1,]    0    0
[2,]    1    1

• 否定P、
> boolean.op[,,6]
[,1] [,2]
[1,]    1    1
[2,]    0    0

> boolean.op[,,5]
[,1] [,2]
[1,]    0    1
[2,]    0    0

• Nonimplication、
> boolean.op[,,12]
[,1] [,2]
[1,]    1    0
[2,]    1    1

• 命題Q、
> boolean.op[,,13]
[,1] [,2]
[1,]    0    1
[2,]    0    1

• 否定Q、
> boolean.op[,,4]
[,1] [,2]
[1,]    1    0
[2,]    1    0

> boolean.op[,,7]
[,1] [,2]
[1,]    0    1
[2,]    1    0

> boolean.op[,,10]
[,1] [,2]
[1,]    1    0
[2,]    0    1

> boolean.op[,,15]
[,1] [,2]
[1,]    0    1
[2,]    1    1

> boolean.op[,,2]
[,1] [,2]
[1,]    1    0
[2,]    0    0