Investigating the Non-termination of Affine Loops a thesis presented in partial fulfilment of the requirements for the degree of master of science at the university of stellenbosch By K. Durant October 2012 Supervised by: Prof. W. Visser Stellenbosch University http://scholar.sun.ac.za Declaration I the undersigned hereby declare that the work contained in this thesis is my own original work and has not previously in its entirety or in part been submitted at any university for a degree. Signature: .................. Date: .................. ii Stellenbosch University http://scholar.sun.ac.za Summary Thesearchfornon-terminatingpathswithinaprogramisacrucialpartofsoftwareverification, as the detection of an infinite path is often the only manner of falsifying program termination — the failure of a termination prover to verify termination does not necessarily imply that a program is non-terminating. This document describes the development and implementation of two focussed techniques for investigating the non-termination of affine loops. The developed techniques depend on the known non-termination concepts of recurrent sets and Jordan matrix decomposition respectively, and imply the decidability of single-variable and cyclic affine loops. Furthermore, the techniques prove to be practically capable methods for both the location of non-terminating paths, as well as the generation of preconditions for non-termination. iii Stellenbosch University http://scholar.sun.ac.za Afrikaans summary Sagtewareverifikasie vereis of die bewys van die be¨eindiging van ’n program, of die deteksie van oneindige uitvoerings. In hierdie tesis ontwikkel en implementeer ons twee tegnieke om oor die oneindige eienskap van affiene lusse te beslis. Die tegnieke wat ontwikkel word is gebaseeropkonseptesoosJordanmatriksdekomposisieenherhaaldegroepewatalindieverlede gebruik is om die be¨eindiging van lusse te ondersoek. Die tegnieke kan gebruik word om die uitvoerbaarheid van beide een-veranderlike en sikliese affiene lusse te bepaal. Feitlik alle nie-eindige affiene lusse kan ge¨ıdentifiseer word en die toestande waaronder hierdie oneindige eienskap verskyn kan beskryf word. iv Stellenbosch University http://scholar.sun.ac.za Acknowledgements I would like to thank: • Prof. Willem Visser, for providing me with both the opportunity and supervision to perform this work; and • Prof. Stephan Wagner, for his innate ability to produce apt counter-examples. v Stellenbosch University http://scholar.sun.ac.za Contents 1 Introduction 1 1.1 Document outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Background 4 2.1 A brief review of software verification and falsification . . . . . . . . . . . . . . 4 2.1.1 Safety and liveness properties . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.2 State representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.3 Invariants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.2 Problem description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.3 Related work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3.1 Decidability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3.2 Termination verification . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3.3 Conditional termination . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.3.4 Termination falsification . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3 Approach 11 3.1 Affine loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.2 Non-termination via recurrent sets . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.2.1 Single-variable affine loops . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.2.2 Cyclic affine loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.2.3 Termination verification via recurrent sets . . . . . . . . . . . . . . . . . 23 3.2.4 Non-linear loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.3 Non-termination via Jordan decomposition . . . . . . . . . . . . . . . . . . . . 25 3.3.1 Diagonalisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 vi Stellenbosch University http://scholar.sun.ac.za 3.3.2 Jordan decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.3.3 Sums of exponential functions . . . . . . . . . . . . . . . . . . . . . . . . 36 3.3.4 Proving non-termination . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 3.3.5 Approximating the set of non-termination witnesses . . . . . . . . . . . 49 3.3.6 Constraining polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . 62 3.3.7 Deciding termination for simple affine loops . . . . . . . . . . . . . . . . 64 3.3.8 Termination verification via sign permutations . . . . . . . . . . . . . . 65 3.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 4 Implementation 68 4.1 Detecting loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 4.1.1 Detecting loop boundaries . . . . . . . . . . . . . . . . . . . . . . . . . . 69 4.1.2 Constructing affine loops . . . . . . . . . . . . . . . . . . . . . . . . . . 72 4.2 Non-termination algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 4.3 Non-termination via recurrent sets . . . . . . . . . . . . . . . . . . . . . . . . . 78 4.4 Non-termination via Jordan decomposition . . . . . . . . . . . . . . . . . . . . 80 4.5 Algorithm complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 5 Evaluation 86 5.1 Non-termination detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 5.2 Conditional non-termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 5.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 6 Conclusion 98 6.1 Further work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 6.1.1 Termination verification and conditional termination . . . . . . . . . . . 99 6.1.2 Complex loop forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 6.1.3 Test case generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 A Supporting Concepts 101 A.1 Simple program representation . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 A.2 Complex arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 A.3 Complex eigenvalues and Lemma 4 . . . . . . . . . . . . . . . . . . . . . . . . . 102 vii Stellenbosch University http://scholar.sun.ac.za B Implementation Notes 105 B.1 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 B.2 Class structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 B.3 Example loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Bibliography 112 viii Stellenbosch University http://scholar.sun.ac.za List of Tables 3.1 The maximal periods K(n) of cyclic loops with few loop variables. . . . . . . . 23 3.2 Several values of the function in Figure 3.16 at positive integer intervals. . . . . 41 ix Stellenbosch University http://scholar.sun.ac.za List of Figures 3.1 An unnested program loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.2 The general form of an affine loop. . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.3 A periodically monotonic loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.4 A general single-variable loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.5 A non-terminating single-variable loop. . . . . . . . . . . . . . . . . . . . . . . . 20 3.6 A loop which is not periodically monotonic. . . . . . . . . . . . . . . . . . . . . 21 3.7 A 2-cyclic non-terminating loop. . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.8 A 2-cyclic terminating loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.9 A non-terminating, non-cyclic loop. . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.10 A loop for which termination can easily be verified. . . . . . . . . . . . . . . . . 24 3.11 A diagonalisable two-variable (excluding the auxiliary variable x(cid:48)) loop. . . . . 28 3.12 A loop which is not diagonalisable. . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.13 A sampling of exponential functions. . . . . . . . . . . . . . . . . . . . . . . . . 36 3.14 Exponential sums with two positive coefficients. . . . . . . . . . . . . . . . . . . 37 3.15 Exponential sums with mixed (sign) coefficients. . . . . . . . . . . . . . . . . . 38 3.16 An exponential sum in three parts. . . . . . . . . . . . . . . . . . . . . . . . . . 39 3.17 An exponential sum of three terms, as a pair function and an exponential function. 40 3.18 A loop whose exponential sum is not dominated by the leading term. . . . . . . 46 3.19 A loop which engenders the eigenvalue zero. . . . . . . . . . . . . . . . . . . . . 53 3.20 A non-terminating loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 3.21 A non-terminating loop which is detected by the techniques in Section 3.3.5, but not those of Section 3.2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 3.22 A positive polynomial with complex roots. . . . . . . . . . . . . . . . . . . . . . 62 x
Description: