1 Decompositions of Higher-Order Grammars to First-Order Transducers Kazuhiro Inaba.

Slides:



Advertisements
Similar presentations
1 Expressive Power of Safe HORS Examined Through Decomposition of Higher Order Programs to Garbage Free 1 st Order Form Kazuhiro Inaba Joint work with.
Advertisements

CS 345: Chapter 9 Algorithmic Universality and Its Robustness
1 CS 201 Compiler Construction Machine Code Generation.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Chapter 4: Trees Part II - AVL Tree
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Chap. 5, Top-Down Parsing J. H. Wang Mar. 29, 2011.
Simplifying CFGs There are several ways in which context-free grammars can be simplified. One natural way is to eliminate useless symbols those that cannot.
Introduction to Computability Theory
Tirgul 5 AVL trees.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
1 Other Models of Computation. 2 Models of computation: Turing Machines Recursive Functions Post Systems Rewriting Systems.
Parsing III (Eliminating left recursion, recursive descent parsing)
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Parsing — Part II (Ambiguity, Top-down parsing, Left-recursion Removal)
Chapter 10 Search Structures Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Cs466(Prasad)L8Norm1 Normal Forms Chomsky Normal Form Griebach Normal Form.
ECE 667 Synthesis and Verification of Digital Systems
Final Exam Review Cummulative Chapters 0, 1, 2, 3, 4, 5 and 7.
Streaming Tree Transducers Loris D'Antoni University of Pennsylvania Joint work with Rajeev Alur 1.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2005.
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
Streaming Tree Transducers Loris D'Antoni University of Pennsylvania Joint work with Rajeev Alur 1.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
THE COMPLEXITY OF TRANSLATION MEMBERSHIP FOR MACRO TREE TRANSDUCERS Kazuhiro Inaba (The University of Tokyo) Sebastian Maneth (NICTA & University of New.
Data Structures : Project 5 Data Structures Project 5 – Expression Trees and Code Generation.
Syntax Analysis The recognition problem: given a grammar G and a string w, is w  L(G)? The parsing problem: if G is a grammar and w  L(G), how can w.
Pushdown Automata (PDAs)
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
PART I: overview material
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Higher-Order Tree Transducers and Their Expressive Power Kazuhiro Inaba at Dagstuhl Seminar, May 2013.
Multi-Return Macro Tree Transducers The Univ. of Tokyo Kazuhiro Inaba The Univ. of Tokyo Haruo Hosoya NICTA, and UNSW Sebastian Maneth CIAA 2008, San Francisco.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
CS 3240 – Chapter 5. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Parsing — Part II (Top-down parsing, left-recursion removal) Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Top-down Parsing lecture slides from C OMP 412 Rice University Houston, Texas, Fall 2001.
The Complexity of Tree Transducer Output Languages FSTTCS 2008, Bengaluru The Univ. of Tokyo Kazuhiro Inaba NICTA, and UNSW Sebastian Maneth.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Top-down Parsing. 2 Parsing Techniques Top-down parsers (LL(1), recursive descent) Start at the root of the parse tree and grow toward leaves Pick a production.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Chapter 3 Context-Free Grammars Dr. Frank Lee. 3.1 CFG Definition The next phase of compilation after lexical analysis is syntax analysis. This phase.
Syntax Analysis – Part I EECS 483 – Lecture 4 University of Michigan Monday, September 17, 2006.
Top-Down Parsing.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
CMSC 330: Organization of Programming Languages Operational Semantics.
Costas Busch - LSU1 Parsing. Costas Busch - LSU2 Compiler Program File v = 5; if (v>5) x = 12 + v; while (x !=3) { x = x - 3; v = 10; } Add v,v,5.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Multi-Return Macro Tree Transducers Kazuhiro Inaba Haruo Hosoya University of Tokyo PLAN-X 2008, San Francisco.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
Compiler Construction Lecture Five: Parsing - Part Two CSC 2103: Compiler Construction Lecture Five: Parsing - Part Two Joyce Nakatumba-Nabende 1.
1 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5.
Context-Free Languages & Grammars (CFLs & CFGs) (part 2)
The Complexity of Translation Membership for Macro Tree Transducers
Parsing — Part II (Top-down parsing, left-recursion removal)
Complexity and Computability Theory I
Parsing Costas Busch - LSU.
Presentation transcript:

1 Decompositions of Higher-Order Grammars to First-Order Transducers Kazuhiro Inaba

2 Input: a string t Determine if t belongs to a regular language Regular Language O( |t| ) time O( 1 ) space ( 0 | 1 (0 (1*0)+)* 1)+

3 Input: a string t Context-Free Language O( |t| ω ) time = the order of matrix multiplication O( (log|t|) 2 ) space E ::= T | T + T | T – T T ::= F | F * F | F / F F ::= ( E ) | 0 | 1N N ::= 0 | 1 | 0N | 1N E ::= T | T + T | T – T T ::= F | F * F | F / F F ::= ( E ) | 0 | 1N N ::= 0 | 1 | 0N | 1N

4 string Nonterminals of CFG has type :: string. string->string (string, string)->string MG can have string->string or (string, string)->string, etc. Macro Language [Fischer68, Aho68, Rounds73] NP -complete O(|t|) space S() ::= T(,,) T(x,y,z) ::= T(ax,by,cz) | xyz S() ::= T(,,) T(x,y,z) ::= T(ax,by,cz) | xyz

5 ((tree->tree)->tree)->tree ((tree->tree)->tree)->tree etc. Higher-Order Tree Garmmers ????? time ????? space S ::= TWICE(X) TWICE(f) ::= f(f(1)) X(e) ::= Plus(e, e) | Minus(e, e) S ::= TWICE(X) TWICE(f) ::= f(f(1)) X(e) ::= Plus(e, e) | Minus(e, e) P P M M P P

6 For “safe” subset of higher order grammars, it is still: Goal of Today’s Talk (1) NP time O(|t|) space [Inaba09] K. Inaba, “Complexity and Expressiveness of Models of XML Transformations”, Dissertation

7 Conjecture: For any higher order grammars, it is still: Goal of Today’s Talk (2) NP time O(|t|) space

8 In this talk, we concentrate on the complexity with respect to the size of the input tree t. Regard grammar G as fixed. “O(|t|) space” means “O(|t| f(|G|)) space”. – Indeed, f(x) ≧ n-EXP where n is the highest order. Caution:

9 Overview of Our Approach 1) Introduce HTT: Higher-order Tree Transducers – A slight generalization of higher-order grammars. – Examine the problem:“Can t be an output of a HTT?” HTT: λ λ HTT: λ λ t ∋?∋?∋?∋?

10 Overview of Our Approach 2) First Order Decomposition – Show order-n HTT is simulatable by n composition of first order HTTs. t ∋?∋?∋?∋? τ1τ1 τ2τ2 τnτn t ∋?∋?∋?∋? HTT: λ λ HTT: λ λ

11 Overview of Our Approach 3) “Garbage Free Form” – Show that we can transform the HTTs so that all intermediate trees are smaller than t. τ1τ1 τ2τ2 τnτn t ∋?∋?∋?∋? s1s1 s2s2 S n-1 s0s0 τ' 1 τ' 2 τ' n τ ' del t ∋?∋?∋?∋?

12 Overview of Our Approach 4) Subproblem: translation membership – Given trees s1, s2 and 1-HTT τ, can we determine “τ(s1) ∋ s2 ?” in NP / O(|s1|+|s2|) space? s1s1 s2s2 S n-1 s0s0 τ' 1 τ' 2 τ' n τ ' del t ∋?∋?∋?∋?

13 Overview of Our Approach 5) Wrap up! Given HTT G and a tree t, - Convert G to garbage-free 1 st order composition - “Guess” (by NP / O(n) space) all intermediate trees s k. - Check each translation membership. s1s1 s2s2 S n-1 s0s0 τ' 1 τ' 2 τ' n τ ' del t ∋?∋?∋?∋? τ1τ1 τ2τ2 τnτn HTT: λ λ HTT: λ λ

14 HTT [Engelfriet&Vogler 88] Higher-order “single-input” “safe” tree transducer Mult :: Tree  Tree Mult(Pair(x 1,x 2 ))  Iter(x 1 )(Add(x 2 ))(Z) Iter :: Tree  (Tree  Tree)  Tree  Tree Iter(S(x))(f)(y)  Iter(x)(f)(f(y)) Iter(Z)(f)(y)  y Add :: Tree  Tree  Tree Add(S(x))(y)  Add(x)(S(y)) Add(Z)(y)  y

15 Iter :: Tree  (Tree  Tree)  Tree  Tree Iter(S(x))(f)(y)  Iter(x)(f)(f(y)) Iter(Z)(f)(y)  y HTT Set of mutually recursive functions – Defined in terms of induction on a single input tree Input trees are always consumed, not newly constructed Output trees are always created, but not destructed – Rest of the parameters are ordered by the order Multiple parameters of the same order is ok but in uncurried form Inductive Input ParamOrder-1 Param(s)Order-0 Param(s)Result

16 HTT Nondeterminism ( ∥ and ⊥ ) Subseq :: Tree  Tree Subseq(Cons(x,xs))  Cons(x, Subseq(xs)) ∥ Subseq(xs) Subseq(Nil)  Nil Subseq(Other)  ⊥ In this talk, evaluation strategy is unrestricted (= call-by-name). But call-by-value can also be dealt with.

17 HTT Notation: n-HTT – is the class of Tree  Tree functions representable by HTTs of order ≦ n. – { Subseq } is 0-HTT, { Mult, Iter, Add } ∈ 2-HTT Subseq :: Tree  Tree Mult :: Tree  Tree Iter :: Tree  (Tree  Tree)  Tree  Tree Add :: Tree  Tree  Tree

18 Order-n to Order-1 T HEOREM [EV88] [EV86] (n-HTT) ⊆ (1-HTT) n n-th order tree transducer is representable by a n-fold composition of 1 st -order tree transducers. [EV86] J. Engelfriet & H. Vogler, “Pushdown Machines for Macro Tree Transducers”, TCS 42 [EV88] ─, “High Level Tree Transducers and Iterated Pushdown Tree Transducers”, Acta Inf. 26

19 Proof: n-HTT = 1-HTT ∘ (n-1)-HTT Idea: Represent 1 st -order term Tree  Tree by a Tree. Represent 1 st -order application symbolically, too. F :: Tree  Tree  Tree F(Z)(y)  S(S(y)) F :: Tree  Tree F(Z)  S(S(Y)) … Z) …  F(x)(Z)

20 Proof: n-HTT = 1-HTT ∘ (n-1)-HTT Represent 1 st -order things symbolically. Then a 1-HTT performs the actual “application”. b))(y)  Eval(f, Eval(b)(y)) Eval(Y)(y)  y Eval(S(x))(y)  S(Eval(x)(y)) Eval(Z)(y)  Z F :: Tree  Tree F(Z)  S(S(Y)) … Z)

Z Z Add(S(Z)) Y Y Y Y Y Y S S Y Y Example Mult(Pair(x 1,x 2 )) 1 )(Add(x 2 )), Z) Y)) Iter(Z)(f)  Y Add(S(x)) Add(Z)  Y

22 Eval(, y= Y Y Y Y S S Y Y Eval(, y= ) Y Y Y Y S S Y Y Eval(,y=Eval(,y= ) Y Y Y Y S S Y Y Z Z S S b))(y)  Eval(f, Eval(b)(y)) Eval(Y)(y)  y Eval(S(x))(y)  S(Eval(x)(y)) Eval(Z)(y)  Z Eval(,y= ) Y Y S S Y Y

23 Why That Easy Relies on the ordered-by-order condition. – No variable renaming is required! [Blum&Ong 09] [BO09] W. Blum and C.-H. L. Ong, “The Safe Lambda Calculus”, LMCS 5 Eval(,y=Eval(,y= ) Y Y Y Y S S Y Y

24 Decomposed. n-HTT λ λ λ n-HTT λ λ λ 1-HTT n τ1τ1 τ2τ2 τnτn

25 Next, Make Intermediate Trees Small. 1-HTT n t s s1s1 s2s2 S n-1 s0s0 τ1τ1 τ2τ2 τnτn τ' 1 τ' 2 τ' n τ ' del t s

26 T HEOREM [I. & Maneth 08] [I. 09] (+ improvement) ∀ τ 1,..., τ n ∈ 1-HTT, ∃ τ’ del ∈ 0-LHTT, τ’ 1,..., τ’ n ∈ 1-HTT, for any (τ n ∘... ∘ τ 1 )(s) ∋ t, there exist τ’ del (s) ∋ s 0, τ’ i (s i ) ∋ s i+1, |s i | ≦ |s i+1 |, s n =t. [IM08] K. Inaba & S. Maneth, “The complexity of tree transducer output languages”, FSTTCS [Inaba09] K. Inaba, “Complexity and Expressiveness of Models of XML Transformations”, Dissertation t s s1s1 s2s2 S n-1 s0s0 τ1τ1 τ2τ2 τnτn τ' 1 τ' 2 τ' n τ ' del t s |s| = number of nodes

27 How to Construct the “Garbage-Free” Form Make each 1-HTT “productive” τ’ n τ n-1 t τnτn t

28 How to Construct the “Garbage-Free” Form Make each 1-HTT “productive” by separating its “deleting” part τ’ n τ n-1 t τ’ del τnτn τ n-1 t τnτn τ’ n τ’ del =

29 How to Construct the “Garbage-Free” Form Make each 1-HTT “productive” by separating its “deleting” part, and fuse the deleter to the left [En75,77][EnVo85][EnMa02] τ’ n τ’ n-1+del t τnτn τ n-1 t

30 Repeat τ4τ4 τ3τ3 τ2τ2 τ1τ1 τ3τ3 τ2τ2 τ1τ1 τ’ 4 τ’ 4d τ 34d τ2τ2 τ1τ1 τ’ 4 τ’ 3 τ2τ2 τ1τ1 τ’ 4 τ’ 34d τ’ 3 τ 234d τ1τ1 τ’ 4 τ’ 3 τ’ 2 τ1τ1 τ’ 4 τ’ 234d τ’ 3 τ’ 2 τ’ 4 τ 1234d τ’ 3 τ’ 2 τ’ 4 τ’ 1 τ’ 1234d Split Fuse Split Fuse Split Fuse Split

31 Separate the “deleting” transformation Key Part τ’ n = τ’ del τnτn ; =

32 Slogan: Work on every node (τ’ n must generate at least one node for each input node) Key Part τ’ n τ’ del ;

33 Deleting HTTs Work on Every Node ⇒ Visit All Nodes G(Z)(y 1 )  Z ∥ y 1 F(S(x 1,x 2 ))  F(x 1 ) ∥ F(x 2 ) ∥ G(x 1 )(F(x 2 )) τnτn may not recurse down to a subtree.

34 Nondeterministically delete every subtree! Work on Every Node ⇒ Visit All Nodes F(S(x 1,x 2 ))  G(x 1 )(F(x 2 )) τnτn F(S12(x 1,x 2 ))  G(x 1 )(F(x 2 )) F(S1_(x 1 ))  G(x 1 )( ⊥ ) F(S_2(x 2 ))  ⊥ F(S__())  ⊥ τ’ n Del(S(x 1,x 2 ))  S12(Del(x 1 ),Del(x 2 )) ∥ S1_(Del(x 1 )) ∥ S_2(Del(x 2 )) ∥ S__() τ’ del At least one choice of nodeterminism “deletes correctly”.

35 Work on Every Node ⇒ Work on Leaf Erasing HTTs F(S(x))  G(x)(Z) G(Z)(y)  y may be idle at leaves. τnτn

36 Work on Every Node ⇒ Work on Leaf F(S(Z))  Z τ’ n Inline Expansion Erasing HTTs F(S(x))  G(x)(Z) G(Z)(y)  y τnτn

37 Work on Every Node ⇒ Work on Monadic Nodes F(S(x))(y 1,y 2,y 3 )  F(x)(y 2,y 3,y 1 ) F(Z)(y 1,y 2,y 3 )  Done(y 1,y 2,y 3 ) Skipping HTTs are good at juggling. τnτn

38 Work on Every Node ⇒ Work on Monadic Nodes Nondeterministic deletion again. Remember how arguments would’ve been shuffled. F(Z123)(y 1,y 2,y 3 )  Done(y 1,y 2,y 3 ) F(Z231)(y 1,y 2,y 3 )  Done(y 2,y 3,y 1 ) F(Z312)(y 1,y 2,y 3 )  Done(y 3,y 1,y 2 ) F(S(x))(y 1,y 2,y 3 )  F(x)(y 2,y 3,y 1 ) F(Z)(y 1,y 2,y 3 )  Done(y 1,y 2,y 3 ) Skipping HTTs τnτn τ’ n

39 Input size = #leaf + #monadic + #others – For each leaf on the input, generate ≧ 1 node. – For each monadic node, generate ≧ 1 node. – Thus, #leaf + #monadic ≦ Output size. For any tree, #others < #leaf ≦ Output size. Add: #leaf + #monadic + #others ≦ Output size*2 So, Input size < Output Size * 2 Simple Arithmetic

40 Input size < Output Size * 2 This bound is sufficient for deriving the results, but we can improve this to Input size ≦ Output Size, by deterministic deletion of leaves + inline expansion. Work on Nodes with Rank-2,3,... Fr(Bin(x 1,x 2 ))(y)  Fr(x 1 )(Fr(x 2 )(y)) Fr(A)(y)  A(y) Fr(B)(y)  B(y)

41 Done! Intermediate trees are small! τ’ n τ’ del ;

42 Next. “Translation membership problem” s1s1 s2s2 S n-1 s0s0 τ' 1 τ' 2 τ' n τ ' del t ∋?∋?∋?∋?

43 Given trees s1, s2 and τ, can we determine “τ(s1) ∋ s2 ?” in NP / O(|s1|+|s2|) space? From the construction, τ is always – 1 st order HTT – Non-deleting/erasing/skipping. – Path-linear: recursive call to the same child node will not nest. OK: Node(f(x), g(x)) BAD: f(x, g(x))  height(s2) ∈ O(|s1|) Translation Membership s1s1 s2s2 τ

44 τ Example A A B B C C C C C C s1 Γ Γ β β α α Γ Γ Γ Γ s2 S(x)  F(x)(Δ) F(A(x1,x2))(y)  F(x1)(α(F(x2,y))) F(B(x1,x2))(y)  F(x2)(β(F(x2,y))) F(C)(y)  Γ(y)

45 Basic Idea: Just compute τ(s1) and compare. A A B B C C C C C C s1 τ Γ Γ β β α α Γ Γ Γ Γ τ(s1) Γ Γ β β α α Γ Γ Δ Δ s2 S(x)  F(x)(Δ) F(A(x1,x2))(y)  F(x1)(α(F(x2,y))) F(B(x1,x2))(y)  F(x2)(β(F(x2,y))) F(C)(y)  Γ(y) Δ Δ

46 τ(s1) may be very big  Compute τ(s1) incrementally. If it becomes larger than s2, return false immediately. τ may be nondeterministic  For NP algorithm, use the nondeterminism. “non-deleting” property ensures polynomial choices.  For linear space algorithm, do back-track search. The “call-stack” is linear-size bounded (next page), so it can be done in linear space. Key Points

47 Each node corresponds to a “call-stack” A A B B C C C C C C s1 S(x)  F(x)(Δ) F(A(x1,x2))(y)  F(x1)(α(F(x2,y))) F(B(x1,x2))(y)  F(x2)( β(F(x2,y))) F(C)(y)  Γ( y) τ τ(s2) Γ Γ β β α α Γ Γ Γ Γ s2 1 1 Γ Γ β β α α Γ Γ Γ Γ Δ Δ

48 Summary Safe n-HTT  (1-HTT) n Split input-deletion Split erasing Split skipping Fuse deleter Translation membership λ t s1s1 s2s2 S n-1 s0s0 τ1τ1 τ2τ2 τnτn τ' 1 τ' 2 τ' n τ ' del

49 What about UNSAFE HTT? UNSAFE n-HTT  (1-stack-HTT) n – ???: Now variable names matter. Use De Bruijn index. Split input-deletion – OK: same technique works (nondet deletion) Split erasing – OK: same technique works (inline expansion) Split skipping – ????????????????????? Fuse deleter – OK: same technique works (product construction) Translation membership – OK: same technique works (call-stack size argument)

50 Parameters are now passed as a stack. Stack-HTT F :: Tree  Stack  Tree F(ADD(x))(..., y1, y2)  F(x)(..., PLUS(y1, y2)) F(SUB(x))(..., y1, y2)  F(x)(..., MINUS(y1, y2)) F(ONE(x))(...)  F(x)(..., 1) F(EOP)(f)(..., y)  y PUSH! POP!

51 Unsafe substitution  C C B B A A s s s s (λx. λy. A(x, y))(B)(C) (λ. λ. A(1, 0))(B)(C) z z a))(...)  Eval(f)(..., Eval(a)(...)) Eval(s(x))(...,y)  Eval(x)(...) Eval(z)(...,y)  y Eval( )(, ) C C A A z z s s s s B B

52 F(σ(x...))(y0)...(yn)(z)  rhs where z :: tree F(σ(x...))(y0)...(yn)  [[rhs]] 0 [[ e ]] k+1 = s( [[ e ]] k ) if e :: tree [[ yi ]] 0 = s( yi )if yi :: tree [[ z ]] = z [[ x(...) ]] k = x( [[...]] k+1 ) if x(...) :: tree->tree... [[ e1(e2) ]] k [[e 1 ]] k+1, [[e 2 ]] k ) if e 1 :: tree->tree [[ e 1 (e 2 ) ]] k = [[ e 1 ]] k ( [[e 2 ]] k ) otherwise n-Unsafe-HTT  Substitution...something like this (the above presentation may not be correct) should work, I hope!

53 Example I :: tree I  S(A) S :: tree -> tree S(x)  F( G(F(x))(B) )(C) F :: tree -> tree -> tree F(x)(y) = D(x, y) G :: (tree->tree) -> tree -> tree G(u)(x) = u(x) I A) S  B))), C) F(x)  D(x, z) G(u) z)

C C A A D D z z z z I A) S  B))), C) F(x)  D(x, z) G(u) z) D D z z s s z z s s