A few years ago Nick learned set theory, and liked it so much that sets became the subject of his bachelor’s thesis. Nick’s thesis describes a new kind of mathematical equations — set equations. Set equations are composed of set variables, which represent various subsets of a universal set Ω. The following four operations are defined for set variables:
- Intersection ∩: A ∩ B := {x : x ∈ A ∧ x ∈ B}.
- Union ∪: A ∪ B := {x : x ∈ A ∨ x ∈ B}.
- Difference −: A − B := {x : x ∈ A ∧ x ∉ B}.
- Symmetrical difference 4: A 4 B := (A − B) ∪ (B − A).
The operations are listed in the order of their precedence, i.e. intersection has the highest precedence, union has lower precedence than intersection, difference has lower precedence than union, and symmetrical difference has the lowest precedence. Parentheses can be used to change operations precedence as usual.
The thesis includes a chapter dedicated to automated solving of some specific classes of set equations. Nick has already elaborated a notation for storing equations in text files. Here is some quotation from the thesis:
The following notation is used for describing set equations:
Operators ∪, ∩, − and 4 are encoded with tokens ‘+’, ‘*’, ‘-’ and ‘^’ respectively. The ‘=’ token denotes the operator of set equality.
It is possible to assign values to some variable using the following notation:
Unfortunately Nick is not very skilled in programming so he asks you to help and write a program module for automated solving of one specific simple class of equations — the equations where each variable, except Ω, occurs exactly one time.