Context Logic and Tree Update
Total Page:16
File Type:pdf, Size:1020Kb
Context Logic and Tree Update Uri Zarfaty Abstract This thesis introduces Context Logic, a novel spatial logic which was developed to allow local Hoare-style reasoning about tree update, but which also permits reasoning about more general data update. Spatial logics have previously been used to describe properties of tree-like structures (as in Ambient Logic) and to reason locally about dynamic updates of heaps (as in Separation Logic). However, simple adaptations of the Ambient Logic are not expressive enough to capture dynamic updates of trees. Instead, one must reason explicitly about tree contexts in order to capture updates throughout the tree. For example, a typical update removes a portion of data and replaces it by inserting new data in the same place. Context Logic allows us to reason about both the data and the place of insertion. The thesis describes the general theory of Context Logic, presents a number of extensions and applications, and shows that Context Logic is a generalisation of the Logic of Bunched Implication, the underlying theory of Separation Logic. The thesis then uses Context Logic to reason locally about tree, heap and term update languages, adapting the local reasoning framework of Separation Logic and providing a generalisation of its Frame Rule. Completeness results for these program logics are provided by deriving the weakest preconditions of the update commands from the command axioms. Finally, the thesis introduces an extended imperative update language for manipulating trees with pointers, which incorporates path queries and atomic commands that act at multiple locations. Reasoning about this raises an important point regarding the link between local reasoning and local specifications. Contents List of Figures iv 1 Prologue 1 1.1 Motivation and Objectives . 1 1.2 Contributions................................ 2 1.3 StatementofOriginality . 3 1.4 Publications................................. 3 2 Introduction 4 2.1 SpatialLogics................................ 4 2.2 DataUpdateandLocalReasoning . 10 2.3 IntroductiontoContextLogic. 16 2.4 ThesisSummary .............................. 20 A Context Logic 21 3 A Basic Theory of Context Logic 22 3.1 BasicContextLogic ............................ 22 3.2 Examples .................................. 26 3.3 Basic Properties and Definitions . 27 3.4 FormulaClasses............................... 31 3.4.1 PureFormulæ ........................... 32 3.4.2 ExactFormulæ ........................... 34 3.4.3 PreciseFormulæ .......................... 36 3.4.4 UbiquitousFormulæ . 39 CONTENTS ii 4 Extended Theories of Context Logic 41 4.1 ContextComposition. .. .. .. .. .. .. .. .. 41 4.2 ContextLogicwithZero.. .. .. .. .. .. .. .. 46 4.3 Derived Connective on Data . 48 4.4 EmbeddingsandProjections . 53 5 Structured Data Models 62 5.1 Sequences .................................. 62 5.2 Multisets .................................. 67 5.3 LinearSequencesandSets. 69 5.4 Heaps .................................... 70 5.5 Trees..................................... 75 5.6 Terms .................................... 81 B Tree Update 85 6 Basic Tree Update 86 6.1 BasicUpdateLanguage .. .. .. .. .. .. .. .. 86 6.2 LocalHoareReasoning. .. .. .. .. .. .. .. .. 93 6.3 FrameRuleandLocality.. .. .. .. .. .. .. .. 95 6.4 SmallAxiomatisation ........................... 96 6.5 WeakestPreconditions . .. .. .. .. .. .. .. .. 98 6.6 Examples ..................................101 6.7 NodeRenaming...............................102 7 Heap Update and Term Rewriting 109 7.1 HeapUpdate ................................109 7.2 TermRewriting............................... 114 8 Extended Tree Update 120 8.1 MotivationandOutline . 120 8.2 ExtendedTreeModel . .. .. .. .. .. .. .. .. 121 8.3 LocalQueryLanguages . 124 8.4 ExtendedUpdateLanguage . 127 8.5 ContextLogicAdaptation . 132 CONTENTS iii 8.6 InductivePredicates . .. .. .. .. .. .. .. .. 136 8.7 ProgramLogic ...............................138 8.8 WeakestPreconditions . 144 8.9 ReasoningExample. .. .. .. .. .. .. .. .. 147 8.10Assessment .................................149 9 Conclusion 154 9.1 Achievements ................................154 9.2 FutureWork ................................155 Notation Index 160 Bibliography 161 List of Figures 3.1 CLProofTheory.............................. 24 4.1 CLp and CL∅,◦ ProofTheoryDerivations . 59 6.1 BTUOperationalSemantics. 90 6.2 BTUUpdateExamples .......................... 91 6.3 BTUInferenceRules............................ 94 6.4 BTUSmallAxioms............................. 97 6.5 BTUWeakestPreconditions. 99 6.6 BTUForwardReasoningExample . 103 6.7 Derivations of the BTU Weakest Preconditions . 106 7.1 HULOperationalSemantics. 110 7.2 HULSmallAxioms............................. 111 7.3 HULWeakestPreconditions. 112 7.4 Derivations of the HUL Weakest Preconditions . 113 7.5 TRLOperationalSemantics . 116 8.1 PQLQuerySemantics . .. .. .. .. .. .. .. .. 126 8.2 XTUUpdateCommands . .. .. .. .. .. .. .. 128 8.3 XTUOperationalSemantics. 130 8.4 CLxtree Semantics..............................134 8.5 XTUInferenceRules. .. .. .. .. .. .. .. .. 139 8.6 XTUCommandAxioms .. .. .. .. .. .. .. .. 142 8.7 XTUWeakestPreconditions. 145 8.8 XTUProgramReasoningExample . 148 8.9 Derivations of the XTU Weakest Preconditions . 151 Acknowledgements • to my supervisor, Philippa Gardner, for her guidance, encourage- ment and inspiration; • to my parents, and , for their love and support, and my sister , for being the best; • to Cristiano, for his patience and help; • to , , , marcvs and the other Imperialists, for bringing me to life and suffering me gladly; • and finally, to future readers, who by reading this will have made it worth writing. Chapter 1 Prologue This chapter contains a brief outline of the motivation and objectives of the work in this thesis, as well as its key contributions and the publications wherein they ap- peared. A fuller introductory account is given in the next chapter, which also contains important background information. 1.1 Motivation and Objectives The original motivation for the work in this thesis came from three overlapping areas of current research: tree update, spatial logics and local reasoning. The online presence of huge amounts of semistructured data, usually represented as trees using XML, has made research on in-place tree update an interesting and active field. In particular, very little work has yet been done on formal reasoning about tree update, making this an obvious challenge. At around the same time, a number of logics collectively known as ‘spatial logics’ appeared for describing spatial properties of structured data, typically using (de-)composition operators that split terms into parts and reason about them separately. The archetypal examples of these are Ambient Logic, which describes tree-like hierarchies, and the assertion language of Separation Logic, which describes memory heaps. Separation Logic also introduced a third area of research, comprising a Hoare reasoning framework for heap update based on local reasoning principles. These principles assert that program reasoning should be confined to the memory cells that a program actually accesses, which Separation Logic achieves by using its spatial assertion language to split heaps into the appropriate subheaps. Since its introduction, Separation Logic has been successfully applied to 1.2. CONTRIBUTIONS 2 a number of problems, and has helped make widespread program verification a more plausible goal. Like pieces in a puzzle, these three areas of work combined to form a simple objective, which was to attempt to reason about simple tree update by applying Separation Logic-style local reasoning based on some spatial logic. To do this, it was natural to try to adapt a pre-existing spatial logic for trees such as the Ambient Logic. It turned out, however, that the Ambient Logic was not expressive enough to capture dynamic updates of trees; instead, a real change in approach was required, resulting in the introduction of Context Logic and this work. As the work developed and Context Logic proved to be increasingly successful, the objectives were extended further to exploring the logical foundations of Context Logic, and attempting to use it to reason about other forms of data update, including more realistic tree update languages. 1.2 Contributions The key contributions of the work in this thesis can be summarised as follows: • Context Logic — the thesis introduces a novel spatial logic in the style of Separation Logic and the Ambient Logic, based on the simple idea of context application, but general enough to describe a wide range of inductive data structures. • Local reasoning using Context Logic — the thesis introduces a framework for local Hoare reasoning about data update using Context Logic, extending previ- ous work of Separation Logic and successfully applying it to new domains such as tree update and term rewriting. • Tree update reasoning — the thesis successfully applies local reasoning to an extended tree update language containing pointers, queries and atomic updates at multiple locations. This serves as a step towards reasoning about updates to semistructured data, and raises an interesting point concerning the link between local reasoning and local specifications. 1.3. STATEMENT OF ORIGINALITY 3 1.3 Statement of Originality I declare that this thesis was composed by myself, and that the work that it presents is my own, except where otherwise stated. 1.4 Publications While some of the work in this thesis is still unpublished,