Docsity

Programming Using Automata and Transducers, Thesis of Theory of Computation

Toggle sidebar
bg1
PROGRAMMING USING AUTOMATA AND TRANSDUCERS
Loris D’Antoni
A DISSERTATION
in
Computer Science
Presented to the Faculties of the University of Pennsylvania
in
Partial Fulfilment of the Requirements for the
Degree of Doctor of Philosophy
2015
Supervisor of Dissertation
Rajeev Alur, Zisman Family Professor of Computer and Information Science
Graduate Group Chairperson
Lyle H. Ungar, Professor of Computer and Information Science
Dissertation Committee
Chaired by Sampath Kannan, Henry Salvatori Professor of Computer and Information Science
Benjamin C. Pierce, Henry Salvatori Professor of Computer and Information Science
Val Tannen, Professor of Computer and Information Science
Margus Veanes (External), Senior Researcher at Microsoft Research
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Programming Using Automata and Transducers and more Thesis Theory of Computation in PDF only on Docsity!

PROGRAMMING USING AUTOMATA AND TRANSDUCERS

Loris D’Antoni A DISSERTATION in Computer Science Presented to the Faculties of the University of Pennsylvania in Partial Fulfilment of the Requirements for the Degree of Doctor of Philosophy 2015

Supervisor of Dissertation

Rajeev Alur, Zisman Family Professor of Computer and Information Science

Graduate Group Chairperson

Lyle H. Ungar, Professor of Computer and Information Science

Dissertation Committee Chaired by Sampath Kannan, Henry Salvatori Professor of Computer and Information Science Benjamin C. Pierce, Henry Salvatori Professor of Computer and Information Science Val Tannen, Professor of Computer and Information Science Margus Veanes (External), Senior Researcher at Microsoft Research

ii

To Christian, Marinella, Monica, and Stefano

iv

ABSTRACT
PROGRAMMING USING AUTOMATA AND TRANSDUCERS

Loris D’Antoni Dr. Rajeev Alur

Automata, the simplest model of computation, have proven to be an effective tool in reasoning about programs that operate over strings. Transducers augment automata to produce outputs and have been used to model string and tree transformations such as natural language translations. The success of these models is primarily due to their closure properties and decidable procedures, but good properties come at the price of limited expressiveness. Concretely, most models only support finite alphabets and can only represent small classes of languages and transformations. We focus on addressing these limitations and bridge the gap between the theory of au- tomata and transducers and complex real-world applications: Can we extend automata and transducer models to operate over structured and infinite alphabets? Can we design lan- guages that hide the complexity of these formalisms? Can we define executable models that can process the input efficiently? First, we introduce succinct models of transducers that can operate over large alpha- bets and design BEX, a language for analysing string coders. We use BEX to prove the correctness of UTF and BASE64 encoders and decoders. Next, we develop a theory of tree transducers over infinite alphabets and design FAST, a language for analysing tree-manipulating programs. We use FAST to detect vulnerabilities in HTML sanitizers, check whether augmented reality taggers conflict, and optimize and analyze functional programs that operate over lists and trees. Finally, we focus on laying the foundations of stream processing of hierarchical data such as XML files and program traces. We introduce two new efficient and executable models that can process the input in a left- to-right linear pass: symbolic visibly pushdown automata and streaming tree trans- ducers. Symbolic visibly pushdown automata are closed under Boolean operations and can specify and efficiently monitor complex properties for hierarchical structures over infinite alphabets. Streaming tree transducers can express and efficiently process complex XML transformations while enjoying decidable procedures.

v

Contents

Acknowledgements iii

Abstract iv

List of tables xii

List of figures xiii

1 Introduction 1 1.1 Preamble..................................... 1 1.2 Automata, languages, and program properties............... 2 1.3 Transducers, transformations, and programs................ 3 1.4 Limitations of existing models......................... 5 1.5 Contributions.................................. 6 1.5.1 Foundational results.......................... 6 1.5.2 Language design and implementation................ 7 1.5.3 Applications............................... 7 1.6 Acknowledgements............................... 8

xiii

  • I Transducer-based programming languages
  • 2 BEX: a language for verifying string coders
    • 2.1 Introduction
      • 2.1.1 Challenges in verifying real-world coders
      • 2.1.2 Contributions
    • 2.2 Verifying BASE64 in BEX
    • 2.3 Symbolic extended finite automata and transducers
      • 2.3.1 Preliminaries
      • 2.3.2 Model definitions
      • 2.3.3 From BEX to S-EFTs
      • 2.3.4 Cartesian S-EFAs and S-EFTs
      • 2.3.5 Monadic S-EFAs and S-EFTs
    • 2.4 Properties of symbolic extended finite automata
    • 2.5 Equivalence of symbolic extended finite transducers
      • 2.5.1 Equivalence of S-EFTs is undecidable
      • 2.5.2 Equivalence of Cartesian S-EFTs is Decidable
    • 2.6 Composition of symbolic extended finite transducers
      • 2.6.1 S-EFTs are not closed under composition
      • 2.6.2 A practical algorithm for composing S-EFTs
    • 2.7 Experiments and applications
      • 2.7.1 Analysis of string encoders
      • 2.7.2 Deep packet inspection
      • 2.7.3 Verification of list manipulating programs
    • 2.8 Related work
      • 2.8.1 From S-FA/S-FT to S-EFA/S-EFT
      • 2.8.2 Models that allow binary predicates Contents vii
      • 2.8.3 Models over finite alphabets
  • 3 FAST: a transducer-based language for manipulating trees
    • 3.1 Introduction
      • 3.1.1 Limitations of current models
      • 3.1.2 Contributions
    • 3.2 Overview of FAST
    • 3.3 Symbolic tree transducers and FAST
      • 3.3.1 Background
      • 3.3.2 Alternating symbolic tree automata
      • 3.3.3 Symbolic tree transducers with regular look-ahead
      • 3.3.4 The role of regular look-ahead
      • 3.3.5 Operations on automata and transducers
    • 3.4 Composition of S-TTRs
      • 3.4.1 Composition algorithm
      • 3.4.2 Proof of correctness
    • 3.5 Evaluation
      • 3.5.1 HTML sanitization
      • 3.5.2 Conflicting augmented reality applications
      • 3.5.3 Deforestation
      • 3.5.4 Analysis of functional programs
      • 3.5.5 CSS analysis
    • 3.6 Related work
      • 3.6.1 Tree transducers
      • 3.6.2 Symbolic transducers
      • 3.6.3 DSLs for tree manipulation Contents viii
      • 3.6.4 Applications
      • 3.6.5 Open problems
  • II Executable models for hierarchical data
  • 4 Symbolic visibly pushdown automata
    • 4.1 Introduction
      • 4.1.1 Existing models
      • 4.1.2 Contributions
    • 4.2 Motivating example
    • 4.3 Model definition
    • 4.4 Closure Properties and Decision Procedures
      • 4.4.1 Closure Properties
      • 4.4.2 Decision Procedures
    • 4.5 Applications and Evaluation
      • 4.5.1 XML Validation
      • 4.5.2 HTML Filters
      • 4.5.3 Runtime Program Monitors
      • 4.5.4 Experimental results
  • 5 Streaming tree transducers
    • 5.1 Introduction
      • 5.1.1 Existing models of tree transducers
      • 5.1.2 Contributions
      • 5.1.3 Organization
    • 5.2 The features of streaming tree transducers
  • 5.3 Model definition Contents ix
    • 5.3.1 Nested words
    • 5.3.2 Nested words with holes
    • 5.3.3 Nested word expressions
    • 5.3.4 Single use restriction
    • 5.3.5 Transducer definition
    • 5.3.6 STT syntax
    • 5.3.7 STT semantics
  • 5.4 Examples
    • 5.4.1 Reverse
    • 5.4.2 Tag-based sorting
    • 5.4.3 Conditional swap
  • 5.5 Properties and variants
    • 5.5.1 Regular nested-word languages
    • 5.5.2 Copyless STTs
    • 5.5.3 Bottom-up transducers
    • 5.5.4 Regular look-ahead
    • 5.5.5 Multi-parameter STTs
    • 5.5.6 Closure under composition
  • 5.6 Restricted inputs
    • 5.6.1 Mapping strings
    • 5.6.2 Mapping ranked trees
  • 5.7 Restricted outputs
    • 5.7.1 Mapping nested words to strings
    • 5.7.2 Mapping nested words to ranked trees
  • 5.8 Expressiveness - 5.8.1 MSO for nested-word transductions Contents x - 5.8.2 Macro tree transducers - 5.8.3 MSO equivalence
    • 5.9 Decision problems
      • 5.9.1 Output analysis
      • 5.9.2 Functional equivalence
    • 5.10 Related work
      • 5.10.1 Executable models
      • 5.10.2 Regular look-ahead
      • 5.10.3 From SSTs to STTs
      • 5.10.4 Succinctness
      • 5.10.5 Input/output encoding
      • 5.10.6 Streaming algorithms
      • 5.10.7 Complexity of checking equivalence
      • 5.10.8 Alphabet limitations
  • III Conclusion
  • 6 Future work
    • 6.1 Declarative languages
    • 6.2 Algorithms
    • 6.3 New models
    • 6.4 Data-parallelism
    • 6.5 New applications
      • 6.5.1 Direct memory access in device drivers
      • 6.5.2 Networking
    • 6.5.3 Deep packet inspection Contents xi
    • 6.5.4 Binary assemblers and disassemblers
    • 6.5.5 Binary code similarity analysis
  • Bibliography
  • 1.1 Examples of finite automata. List of Figures
  • 1.2 Functional programs that can be modeled using transducers.
  • 1.3 Examples of finite state transducers.
  • 2.1 Role of string encoders and decoders.
  • 2.2 BASE64 encoding
  • 2.3 BASE64 analysis in BEX.
  • 2.4 Running times for equivalence/inequivalence checking.
  • 3.1 Implementation and analysis of an HTML sanitizer in FAST.
  • 3.2 Encoding of .
  • 3.3 Result of applying sani to the tree in Figure 3.2.
  • 3.4 Syntax of FAST.
  • 3.5 Tree languages in FAST.
  • 3.6 Depiction of an S-TT linear rule of rank 3.
  • 3.7 Conditional flip.
  • 3.8 S-TTs for which the composition is naturally expressible by an S-TTR
  • 3.9 Non-composable S-TTR-definable transformations.
  • 3.10 Augmented reality: running times for operations on transducers.
  • 3.11 Deforestation advantage for a list of 4,096 integers.
  • 3.12 Analysis of functional programs in FAST.
  • 4.1 Example of S-VPA over the theory of integers.
  • 4.2 Example XML Schema with an equivalent S-VPA.
  • 4.3 S-VPAs for HTML filtering.
  • 4.4 S-VPA W accepting well-formed HTML documents.
  • 4.5 Time to filter an HTML file.
  • 4.6 Running times for S-VPA equivalence and determinization.
  • 5.1 Depiction of the transformation tree swap.
  • 5.2 Example of paramter tree update.
  • 5.3 Example of symbolic variable assignment.
  • 5.4 Encoding of an STT’s computation in MSO.

xiv

“When you do things right, people won’t be sure you’ve done anything at all.”

— The cosmic entity, Futurama

Introduction 2

q 0

T

G

q 0

A

C

all_TG all_AC

FIGURE 1.1: Examples of finite automata.

IH08, MSV00, BDM+06, Bec03, MBPS05]. We build on these models and identify novel ones that can be used to analyze many real-world programs.

1.2 Automata, languages, and program properties

Finite automata define sets of strings, also called languages. They are used in many applications, most notably in analysis of regular expressions and program monitor- ing [LG07]. Intuitively a finite automaton is a labeled graph with initial and final states (nodes). The labels of the edges are symbols over an input alphabet and each path through the graph corresponds to a string. The language defined by a particular au- tomaton is the set of all strings for which there is a path from an initial to a final state. For example, the automaton all_TG in Figure 1.1 accepts the language of all strings containing only the symbols T and G. Automata can capture computations. In particular, they can be seen as programs that map lists to Boolean values. Examples of such programs can be seen in Figure 1.2. In particular, the programs all_TG and all_AC (lines 11–20) can be modeled using the automata depicted in Fig. 1.1 that accept strings over the alphabet base = {A, T, G, C}. Similarly, the programs is_dna and is_empty (lines 4–10) can be captured by two automata accepting all strings and only the empty string respectively. What is the advantage of representing programs as automata? Unlike general purpose programs, finite automata enjoy many properties that can enable forms of program analysis. Automata can be complemented, intersected, determinized, and minimized, and it is decidable whether two automata accept the same languages. This opens a door of opportunities on what type of properties we can check for our programs in

Introduction 3

Figure 1.2. For example, we can prove that the programs all_TG and all_AC accept disjoint languages by checking that the intersection of their corresponding automata is equivalent to the empty language.

1.3 Transducers, transformations, and programs

Although automata enjoy many useful properties, they can only model very limited classes of programs. Finite transducers extend finite automata to model partial func- tions from strings to strings, also called string transformations. This is done by adding an output component to transitions. A finite state transducer is a labeled graph with initial and final states (nodes), where each edge carries an input symbol and a sequence of output symbols. Each path corresponding to an input string also produces an out- put string by outputting sequences of characters at each transition. The concatenation of such sequences is the output corresponding to the traversed path. The transforma- tion defined by a transducer is the set of all input/output string pairs for which there is a path from an initial to a final state. For example, the transducer map_base in Fig- ure 1.3 defines the transformation that outputs the DNA sequence matching the input one (maps each base to the matching one, e.g. A to T). Transducers can be seen as programs that map lists into lists. Examples of such pro- grams can be seen in Figure 1.2. The programs map_base and filter_AC (lines 21–35) can be modeled using the transducers depicted in Figure 1.3. Again, what is the advantage of modeling programs using transducers? Finite trans- ducers also enjoy a variety of properties that enable powerful analysis. In particular, transducers are closed under sequential composition, and it is decidable whether two transducers define the same transformations. Also, given a transducer T , and two au- tomata I and O, it is decidable whether for every string accepted by the automaton I, the transducer T produces an output accepted by O. This problem is called regular type-checking. Consider the programs in Fig. 1.2. We can use the transducers’ clo- sure under sequential composition to automatically generate a transducer m_f_DNA that processes the input in a single pass without producing intermediate results (on the right Fig. 1.3). Similarly, we can build a transducer for the transformation f_m_f_DNA. We can then use type-checking to statically prove that for every list for which dnaseq returns true, the function f_m_f_DNA outputs a list in the language is_empty (i.e. the empty list).

Introduction 5

q 0

A/T

map_base

T/A

G/C C/G

q 0

A/A T/ε

G/ε C/C filter_AC

q 0

A/ε T/ A

G/C C/ε m_f_DNA FIGURE 1.3: Examples of finite state transducers.

1.4 Limitations of existing models

Interesting programs can be modeled using finite automata and transducers. However, the capabilities of these formalisms are limited: they only operate over strings, they can only capture limited classes of languages and transformations (e.g. reverse in Fig. 1. cannot be modeled as a finite state transducer), and they are limited to finite alphabets. Many models and techniques have been proposed to attenuate these limitations. Au- tomata and transducers have been extended to trees [Eng75, Eng77, CDG+07], richer transducer models have been presented to handle more complex functions [AC10, AC11, EH01], there have been extensions to support infinite and structured alpha- bets [VHL+12, KF94], and a few programming languages were implemented to sim- plify programming in these models [PS12, MK08]. Although all these extensions have progressed towards addressing many of the limitations, there are simple domains that could potentially benefit from transducer-based analysis that cannot be modeled using existing models. The following limitations still exist:

Alphabet expressiveness: Although several extensions have been proposed, many tree and string transformations and XML languages over infinite domains cannot be expressed using existing models; Executable models: Most models proposed to capture larger classes of functions are not efficiently executable. In particular, they typically require multiple passes over the input. Usability: Automata and transducers are complex to use for an average user and the integration between programming languages and these models is still limited.

Introduction 6

1.5 Contributions

The goal of this dissertation is to bridge part of the gap between practical applications and the theory of automata and transducers. Its contributions are divided between the following areas:

Foundational results: We define novel automata and transducer models that can express large classes of languages and transformations. For many of these models we provide strong theoretical guarantees and exactly characterize their expressive- ness. Implementation: We implement two programming languages, FAST and BEX, that have their semantics given in terms of automata and transducers. Using these seman- tics, programs written in FAST and BEX can be statically analyzed. We also de- velop the open-source automata library SVPAlib, for coding automata over infi- nite alphabets. Applications: We show how transducer-based languages are beneficial in proving prop- erties of real-world programs. We use BEX to prove the correctness of BASE 64 and UTF8 coders, and FAST to prove the absence of malicious outputs in HTML sanitizers, to check interference of augmented reality applications, to optimize functional language compilation, and to analyze functional programs over trees.

The rest of this chapter expands on each of these contributions in detail.

1.5.1 Foundational results

Automata are the pillars of computability and they are used in many domains thanks to their decidable procedures and closure properties. Our first contribution is to ex- tend existing automata and transducer models to capture richer classes of languages and transformations. For these extended versions we prove closure properties and provide upper bounds for several decision procedures. Chapter 2 introduces symbolic extended finite automata and transducers, which extend finite automata and trans- ducer with predicates to support infinite alphabets and the ability to process multiple adjacent symbols in a single transition. We prove negative properties for these models and show that for a restricted version, called Cartesian, checking equivalence is de- cidable. Chapter 3 defines symbolic tree transducers with regular look-ahead, which extend their classic counterpart with predicates to support infinite alphabets. We show that this model is closed under composition under the same assumptions that are nec- essary in the non-symbolic setting. Chapter 4 presents symbolic visibly pushdown