110 likes | 268 Views
COSC 3340: Introduction to Theory of Computation. University of Houston Dr. Verma Lecture 23. Tree Automata. The automata concept is general and powerful ! (should be in every CS student toolkit)
E N D
COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 23 UofH - COSC 3340 - Dr. Verma
Tree Automata • The automata concept is general and powerful! (should be in every CS student toolkit) • Just as DFAs and NFAs work on strings, we can define automata that process trees, DAGs, graphs, matrices, etc. • We illustrate this generality thru tree automata UofH - COSC 3340 - Dr. Verma
Tree Automata • Process trees instead of strings • Can be bottom-up (we consider) or top-down • The tree automata TA has: • a finite set of states • 0 or more special states - final states • input alphabet • transition table containing rules of two kinds: a -> q , f(q1,…,qn) -> q UofH - COSC 3340 - Dr. Verma
Informally -- How does a TA work? • TA works from the leaves to the root of the tree. • TA goes into a loop until the entire tree is read. • In each step, TA consults its transition table and determines states for nodes higher up the tree based on (f,q1,…,qn) where • f – symbol at the node • q1, …, qn – states at the children of the node UofH - COSC 3340 - Dr. Verma
How does a TA work? (contd.) • For deterministic TA, after reading input tree, • if TA state final, input accepted • if TA state notfinal, input rejected • For nondeterministic TA, as long as one accepting computation exits, input is accepted; if none, input is rejected. • Language of TA -- set of all trees accepted by TA. • TAs have applications in XML, Xpath, compilers, logic, and verification UofH - COSC 3340 - Dr. Verma
Formal definition of NTA • NTA M = (Q, , Δ, F) • Where, • Q is a finite set of states • is the input alphabet • FQ is set of final states • Δis a set of transition rules of two kinds • a -> q where a is in and q is in Q • f(q1, …, qn) -> q where f is in and q, qi’s in Q UofH - COSC 3340 - Dr. Verma
Formal definition of L(M) • We can define the yields in one-step relation between two trees • Take its reflexive-transitive closure and define L(M) • Reference: Tree Automata and Applications book by Comon et al. (available on the web) UofH - COSC 3340 - Dr. Verma
DFAs are special case of TA • The DFA symbols become unary functions • The TA has rules: • a(q0) -> q1 • b(q0) -> q0 • a(q1) -> q0 • b(q1) -> q1 • q0 is final state UofH - COSC 3340 - Dr. Verma
Example of TA – boolean formula evaluation • 0 -> q0, 1 -> q1 • not(q0) -> q1, not(q1) -> q0 • and(q0, q0) -> q0, …, and(q1, q1) -> q1 • or(q0, q0) -> q0, …, or(q1, q1) -> q1 • q1 is final state • Evaluate: or(and(not(0), not(1)), and(0, 0)) UofH - COSC 3340 - Dr. Verma
More generally … • We can have rules of the form: • expr1 -> expr2, where lhs and rhs are expressions containing variables x, y, z and function symbols f, g, h, a, … • Example: x + 0 -> x and x + -x -> 0 • These rules are applied using pattern matching • A derivation: (0 + -0) + 0 => 0 + 0 => 0 UofH - COSC 3340 - Dr. Verma
How powerful are such rules? • As powerful as a Turing Machine! (Reference: TCS paper by Max Dauchet) • An interpreter, called LRR, for such rules has been implemented by me and my students • LRR saves every rule application in a compact data structure • Can be used for programming or verification • LRR Demo available for interested students (see me) UofH - COSC 3340 - Dr. Verma