Nick has been learning about a special kind of set called artinian sets, or artinals for short. Their advantage is that each one has a finite representation, so a computer can process it. The formal definition is a little involved:
Every artinal of height ≤N is also an artinal of height ≤N+1, so for any artinal A we define its height h(A) as the smallest N for which A is an artinal of height ≤N. An artinal of height N is called an N-artinal.
Two further notions are needed: the canonical order on U (written <) and the canonical form of an artinal.
The canonical representation of an artinal is a string over the characters {, } and ,: repr(∅) = {}, and if A={A1,…,As} in canonical form, then repr(A) = { + repr(A1) + , + ⋯ + , + repr(As) + }.
Canonical representations become long, so a shorthand is introduced. For each integer N≥0 the finite ordinal N is defined by induction: 0:=∅ and N+1:={N}∪N, so that N={0,1,…,N−1}. The reduced canonical representation is obtained from the canonical representation by replacing, with the decimal numeral N, every occurrence of the ordinal N that is not contained inside an occurrence of some larger ordinal M (with M>N).
The following operations on artinals are defined, from highest priority to lowest:
The following relations between artinals are defined:
You must run a small program that computes with artinals. The program is a sequence of operators, one per line. There are five kinds:
:=⟨expr⟩ — sets the variable ⟨ident⟩ to the value of ⟨expr⟩.!⟨expr⟩ — evaluates ⟨expr⟩ and prints its reduced canonical representation on its own line.?⟨expr⟩⟨relation⟩⟨expr⟩ — evaluates the condition and prints TRUE or FALSE on its own line.#⟨any characters⟩ — the whole line is copied to the output.The grammar uses these definitions:
_0 | 1 | … | 9A | … | Z | a | … | z{ [ ⟨expr⟩ { ,⟨expr⟩ } ] } | ⟨ident⟩ | ⟨expr⟩⟨binop⟩⟨expr⟩ | ⟨unop⟩⟨expr⟩ | (⟨expr⟩)+ | * | - | ^+ | *< | > | = | <= | >= | <> | -> | <- | << | >>The binary operators +, *, -, ^ denote ∪, ∩, −, △ respectively; the unary operators +, * denote ∪ and ∩. The relations <, >, =, <=, >=, <>, ->, <-, <<, >> denote <, >, =, ≤, ≥, ≠, ∈, ∋, ⊂, ⊃ respectively. Parentheses ( and ) change precedence as usual. Any two tokens — except the ⟨alpha⟩ characters that make up a single ⟨ident⟩ — may be separated by any number of blank characters (spaces and tabs).
Before the program runs, every variable whose name is the decimal representation (without leading zeros) of a non-negative integer N is preset to the finite ordinal N. Every other variable starts as ∅. Identifiers are case-sensitive.
The input consists of at most one hundred lines, each holding a single operator. No line is longer than 254 characters.
Produce one line of output for every ?, ! and # operator, as described above. The input is guaranteed to cause no run-time errors (for example, unary ∩ is never applied to the empty set).