No.792 Let's Make a Truth Function
Problem Statement
Note: The output of this problem contains non-ASCII characters.
The non-ASCII characters contained are as follows: ∧∨¬⊥⊤
For $N$ atomic formulas $P_1, P_2, \cdots, P_N$, consider the following truth table.
$
\large
\begin{array}{cccc|c}
P_1 & P_2 & \cdots & P_N & A \\
\hline
Q_{1,1} & Q_{1,2} & \cdots & Q_{1,N} & R_1 \\
Q_{2,1} & Q_{2,2} & \cdots & Q_{2,N} & R_2 \\
\vdots & \vdots & \ddots & \vdots & \vdots \\
Q_{2^N,1} & Q_{2^N,2} & \cdots & Q_{2^N, N} & R_{2^N}
\end{array}
$
$Q_{i,j}$ is $1$ or $0$, where 1 represents true and 0 represents false.
Also, $R_i$ is $1$ or $0$, and represents true or false in the same way.
Output a logical formula $A$ that is valid for the truth function represented by this truth table.
Input
$N$
$Q_{1,1} \, Q_{1,2} \, \cdots \, Q_{1,N} \, R_1$
$Q_{2,1} \, Q_{2,2} \, \cdots \, Q_{2,N} \, R_2$
$\vdots$
$Q_{2^n,1} \, Q_{2^n,2} \, \cdots \, Q_{2^n,N} \, R_{2^N}$
$1 \le N \le 12$
Each of $Q_{i,j}, R_i(1 \le i \le 2^N,\, 1 \le j \le N)$ is $0$ or $1$.
Output
Output a logical formula $A$ that is valid for the given truth function. The output must follow the format below.
- Start with "A=".
- If $P_i$ is true, output $P_i$; if it is false, output $\lnot P_i$.
- For every i, $P_i$ is represented in the output as "P_i". (Regardless of how many digits i has; for example, when i=12 it is represented as P_12.)
- If $R_i$ is true, include in the logical formula A a formula of the form "($Q_1$∧$Q_2$∧$\cdots$∧$Q_N$)" based on the i-th row of the truth table.
- Here, $Q_i$ denotes "P_i" if $P_i$ is true, and otherwise $Q_i$ denotes "¬P_i".
- Letting $X_1, X_2, \cdots, X_N$ be the formulas included here, the logical formula $A$ must be represented in the form "A=$X_1$∨$X_2$∨$\cdots$∨$X_N$".
- When $i > j$, $X_j$ must appear before $X_i$ in the logical formula A.
- When $i > j$, $Q_j$ must appear before $Q_i$ in the logical formula $X_k$.
- If $R_i$ is true for all $i$, the logical formula A is represented as "A=⊤". (Not T. ⊤ is read as top.)
- If $R_i$ is false for all $i$, the logical formula A is represented as "A=⊥". (⊥ represents a contradiction. It is read as bottom.)
Sample
Sample 1
Input
2 1 1 0 1 0 1 0 1 1 0 0 0
Output
A=(P_1∧¬P_2)∨(¬P_1∧P_2)
In this case, $R_2$ and $R_3$ are true. Rows 2 and 3 of the truth table show that this truth function is true when $P_1$ and not $P_2$, or when not $P_1$ and $P_2$.
Sample 2
Input
1 0 0 1 0
Output
A=⊥
$R_i$ is false for every $i$, so the output is as shown above.
Sample 3
Input
2 1 1 1 1 0 1 0 1 1 0 0 1
Output
A=⊤
$R_i$ is true for every $i$, so the output is as shown above.
Sample 4
Input
4 1 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 1 1 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 1 1 0 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1
Output
A=(P_1∧P_2∧P_3∧¬P_4)∨(P_1∧P_2∧¬P_3∧¬P_4)∨(P_1∧¬P_2∧P_3∧¬P_4)∨(P_1∧¬P_2∧¬P_3∧¬P_4)∨(¬P_1∧P_2∧P_3∧¬P_4)∨(¬P_1∧P_2∧¬P_3∧¬P_4)∨(¬P_1∧¬P_2∧P_3∧¬P_4)∨(¬P_1∧¬P_2∧¬P_3∧¬P_4)
Sample 5
Input
2 1 1 1 1 0 1 0 1 0 0 0 0
Output
A=(P_1∧P_2)∨(P_1∧¬P_2)
The truth value is determined by $P_1$ alone regardless of the truth value of $P_2$, but output the formula without simplifying it.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。