Computing Expected Runtimes for Constant Probability Programs

Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11716)


We introduce the class of constant probability (CP) programs and show that classical results from probability theory directly yield a simple decision procedure for (positive) almost sure termination of programs in this class. Moreover, asymptotically tight bounds on their expected runtime can always be computed easily. Based on this, we present an algorithm to infer the exact expected runtime of any CP program.


Probabilistic programs Expected runtimes (Positive) almost sure termination Complexity Decidability 



We would like to thank Nicos Georgiou and Vladislav Vysotskiy for drawing our attention to Wald’s Lemma and to the work of Frank Spitzer on random walks, and Benjamin Lucien Kaminski and Christoph Matheja for many helpful discussions. Furthermore, we thank Tom Küspert who helped with the implementation of our technique in our tool KoAT.


  1. 1.
    Agrawal, S., Chatterjee, K., Novotný, P.: Lexicographic ranking supermartingales: an efficient approach to termination of probabilistic programs. Proc. ACM Program. Lang. (POPL) 2, 34:1–34:32 (2018). Scholar
  2. 2.
    Ash, R.B., Doleans-Dade, C.A.: Probability and Measure Theory. Elsevier/Academic Press (2000)Google Scholar
  3. 3.
    Bazzi, L., Mitter, S.: The solution of linear probabilistic recurrence relations. Algorithmica 36(1), 41–57 (2003). Scholar
  4. 4.
    Bournez, O., Garnier, F.: Proving positive almost-sure termination. In: Giesl, J. (ed.) RTA 2005. LNCS, vol. 3467, pp. 323–337. Springer, Heidelberg (2005). Scholar
  5. 5.
    Braverman, M.: Termination of integer linear programs. In: Ball, T., Jones, R.B. (eds.) CAV 2006. LNCS, vol. 4144, pp. 372–385. Springer, Heidelberg (2006). Scholar
  6. 6.
    Brázdil, T., Brozek, V., Etessami, K.: One-counter stochastic games. In: Lodaya, K., Mahajan, M. (eds.) FSTTCS 2010, LIPIcs, vol. 8, pp. 108–119 (2010).
  7. 7.
    Brázdil, T., Kučera, A., Novotný, P., Wojtczak, D.: Minimizing expected termination time in one-counter Markov decision processes. In: Czumaj, A., Mehlhorn, K., Pitts, A., Wattenhofer, R. (eds.) ICALP 2012. LNCS, vol. 7392, pp. 141–152. Springer, Heidelberg (2012). Scholar
  8. 8.
    Brázdil, T., Esparza, J., Kiefer, S., Kucera, A.: Analyzing probabilistic pushdown automata. Formal Methods Syst. Des. 43(2), 124–163 (2013). Scholar
  9. 9.
    Brockschmidt, M., Emmes, F., Falke, S., Fuhs, C., Giesl, J.: Analyzing runtime and size complexity of integer programs. ACM Trans. Program. Lang. Syst. 38(4), 13:1–13:50 (2016). Scholar
  10. 10.
    Chakarov, A., Sankaranarayanan, S.: Probabilistic program analysis with martingales. In: Sharygina, N., Veith, H. (eds.) CAV 2013. LNCS, vol. 8044, pp. 511–526. Springer, Heidelberg (2013). Scholar
  11. 11.
    Chatterjee, K., Fu, H., Murhekar, A.: Automated recurrence analysis for almost-linear expected-runtime bounds. In: Majumdar, R., Kunčak, V. (eds.) CAV 2017. LNCS, vol. 10426, pp. 118–139. Springer, Cham (2017). Scholar
  12. 12.
    Chatterjee, K., Novotný, P., Zikelic, D.: Stochastic invariants for probabilistic termination. In: Castagna, G., Gordon, A.D. (eds.) POPL 2017, pp. 145–160 (2017). Scholar
  13. 13.
    Chatterjee, K., Fu, H., Novotný, P., Hasheminezhad, R.: Algorithmic analysis of qualitative and quantitative termination problems for affine probabilistic programs. ACM Trans. Program. Lang. Syst. 40(2), 7:1–7:45 (2018). Scholar
  14. 14.
    Elaydi, S.: An Introduction to Difference Equations. Springer, New York (2005). Scholar
  15. 15.
    Esparza, J., Kucera, A., Mayr, R.: Quantitative analysis of probabilistic pushdown automata: expectations and variances. In: Panangaden, P. (ed.) LICS 2005, pp. 117–126 (2005).
  16. 16.
    Feller, W.: An Introduction to Probability Theory and Its Applications, Probability and Mathematical Statistics, vol. 1. Wiley, Hoboken (1950)zbMATHGoogle Scholar
  17. 17.
    Fioriti, L.M.F., Hermanns, H.: Probabilistic termination: soundness, completeness, and compositionality. In: Rajamani, S.K., Walker, D. (eds.) POPL 2015, pp. 489–501 (2015).
  18. 18.
    Frohn, F., Giesl, J.: Termination of triangular integer loops is decidable. In: Dillig, I., Tasiran, S. (eds.) CAV 2019. LNCS, vol. 11562, pp. 426–444. Springer, Cham (2019). CrossRefGoogle Scholar
  19. 19.
    Fu, H., Chatterjee, K.: Termination of nondeterministic probabilistic programs. In: Enea, C., Piskac, R. (eds.) VMCAI 2019. LNCS, vol. 11388, pp. 468–490. Springer, Cham (2019). Scholar
  20. 20.
    Giesl, J., Giesl, P., Hark, M.: Computing expected runtimes for constant probability programs. CoRR abs/1905.09544 (2019).
  21. 21.
    Grimmett, G., Stirzaker, D.: Probability and Random Processes. Oxford University Press, Oxford (2001)zbMATHGoogle Scholar
  22. 22.
    Johansson, F., et al.: MpMath: a Python library for arbitrary-precision floating-point arithmetic.
  23. 23.
    Kaminski, B.L., Katoen, J.: On the hardness of almost-sure termination. In: Italiano, G.F., Pighizzini, G., Sannella, D. (eds.) MFCS 2015. LNCS, vol. 9234, pp. 307–318. Springer, Heidelberg (2015). Scholar
  24. 24.
    Kaminski, B.L., Katoen, J.-P., Matheja, C., Olmedo, F.: Weakest precondition reasoning for expected run–times of probabilistic programs. In: Thiemann, P. (ed.) ESOP 2016. LNCS, vol. 9632, pp. 364–389. Springer, Heidelberg (2016). Scholar
  25. 25.
    Karp, R.M.: Probabilistic recurrence relations. J. ACM 41(6), 1136–1150 (1994). Scholar
  26. 26.
    Kozen, D.: Semantics of probabilistic programs. In: Kosaraju, S.R. (ed.) FOCS 1979, pp. 101–114 (1979).
  27. 27.
    McIver, A., Morgan, C.: Abstraction, Refinement and Proof for Probabilistic Systems. Springer, New York (2005). Scholar
  28. 28.
    McIver, A., Morgan, C., Kaminski, B.L., Katoen, J.: A new proof rule for almost-sure termination. Proc. ACM Program. Lang. (POPL) 2, 33:1–33:28 (2018). Scholar
  29. 29.
    Meurer, A., et al.: SymPy: symbolic computing in Python. Peer J Comput. Sci. 3, e103 (2017). Scholar
  30. 30.
    Ngo, V.C., Carbonneaux, Q., Hoffmann, J.: Bounded expectations: resource analysis for probabilistic programs. In: Foster, J.S., Grossman, D. (eds.) PLDI 2018, pp. 496–512 (2018). Extended Version available at
  31. 31.
    Ouaknine, J., Pinto, J.S., Worrell, J.: On termination of integer linear loops. In: Indyk, P. (ed.) SODA 2015, pp. 957–969 (2015).
  32. 32.
    Puterman, M.L.: Markov Decision Processes: Discrete Stochastic Dynamic Programming. Wiley, New York (1994)CrossRefGoogle Scholar
  33. 33.
    Spitzer, F.: Principles of Random Walk. Springer, New York (1964). Scholar
  34. 34.
    Tassarotti, J., Harper, R.: Verified tail bounds for randomized programs. In: Avigad, J., Mahboubi, A. (eds.) ITP 2018. LNCS, vol. 10895, pp. 560–578. Springer, Cham (2018). Scholar
  35. 35.
    Tiwari, A.: Termination of linear programs. In: Alur, R., Peled, D.A. (eds.) CAV 2004. LNCS, vol. 3114, pp. 70–82. Springer, Heidelberg (2004). Scholar

Copyright information

© Springer Nature Switzerland AG 2019

Authors and Affiliations

  1. 1.LuFG Informatik 2RWTH Aachen UniversityAachenGermany
  2. 2.Department of MathematicsUniversity of SussexBrightonUK

Personalised recommendations