#P7653. Minimal Basic Logic Expressions

    ID: 20845 Type: Default 1000ms 256MiB

Minimal Basic Logic Expressions

Minimal Basic Logic Expressions

We are given five logic expressions R1, R2, R3, R4 and R5. Each expression is composed solely of the logic variables a, b, c, d, e, f, g, h and the three logical operators: \(\#\) (not), \(&\) (and) and \( + \) (or). Parentheses may also be used to override the default operator precedence. The operator precedence is as follows:

  1. \(\#\) (not)
  2. \(&\) (and)
  3. \( + \) (or)

A single logical operation with one or two parameters may be used to express an expression in any one of the following four forms (with the condition that the indices are distinct when required):

  • \(R_i = R_j\) (i.e. the two expressions are identical)
  • \(R_i = \# R_j\) (i.e. \(R_i\) is the negation of \(R_j\))
  • \(R_i = R_j \; & \; R_k\) (conjunction)
  • \(R_i = R_j \; + \; R_k\) (disjunction)

An expression is considered basic if it cannot be represented in any one of the forms above using the other expressions. Otherwise, the expression is non‐basic and should be representable using a single logical operation whose parameters come from the basic set.

Your task is to write a program that, given the five expressions as input, determines:

  1. A minimal set of basic expressions.
  2. For each non‐basic expression, one valid representation using a single logical operation taken from the basic set. (If multiple representations exist, any one is acceptable.)

inputFormat

Input consists of 5 lines. Each line is of the form:

Ri =

where i is an integer from 1 to 5. The expression may contain any of the variables a, b, c, d, e, f, g, h, the operators (#), (&) and (+), as well as parentheses. There will be no extra spaces except as needed.

outputFormat

The output should begin with a single line listing the basic expressions (e.g. "R1 R3 R5") separated by a space. Then, for each non-basic expression (in the order R1 to R5), output a line in the format:

Ri=

where is one of the valid forms described above (i.e. one of: Rj, #Rj, Rj&Rk or Rj+Rk) using expressions from the basic set.

sample

a
b
#a
a&b
a+b
R1 R2

R3=#R1 R4=R1&R2 R5=R1+R2

</p>