Inferring Expected Runtimes of Probabilistic Integer Programs Using Expected Sizes

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


We present a novel modular approach to infer upper bounds on the expected runtimes of probabilistic integer programs automatically. To this end, it computes bounds on the runtimes of program parts and on the sizes of their variables in an alternating way. To evaluate its power, we implemented our approach in a new version of our open-source 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. 2(POPL) (2017),
  2. 2.
    Albert, E., Arenas, P., Genaim, S., Puebla, G.: Closed-form upper bounds in static cost analysis. J. Autom. Reasoning 46(2), 161–203 (2011),
  3. 3.
    Albert, E., Arenas, P., Genaim, S., Puebla, G., Zanardini, D.: Cost analysis of object-oriented bytecode programs. Theor. Comput. Sci. 413(1), 142–159 (2012),
  4. 4.
    Albert, E., Genaim, S., Masud, A.N.: On the inference of resource usage upper and lower bounds. ACM Trans. Comput. Log. 14(3) (2013),
  5. 5.
    Albert, E., Bofill, M., Borralleras, C., Martin-Martin, E., Rubio, A.: Resource analysis driven by (conditional) termination proofs. Theory Pract. Log. Program. 19(5-6), 722–739 (2019),
  6. 6.
    Alias, C., Darte, A., Feautrier, P., Gonnord, L.: Multi-dimensional rankings, program termination, and complexity bounds of flowchart programs. In: Proc. SAS ’10. LNCS, vol. 6337, pp. 117–133 (2010),
  7. 7.
    Ash, R.B., Doléans-Dade, C.A.: Probability and Measure Theory. Harcourt Academic Press, 2nd edn. (2000)Google Scholar
  8. 8.
    Avanzini, M., Moser, G.: A combination framework for complexity. In: Proc. RTA 13. LIPIcs, vol. 21, pp. 55–70 (2013),
  9. 9.
    Avanzini, M., Moser, G., Schaper, M.: TcT: Tyrolean Complexity Tool. In: Proc. TACAS ’16. LNCS, vol. 9636, pp. 407–423 (2016),
  10. 10.
    Avanzini, M., Moser, G., Schaper, M.: A modular cost analysis for probabilistic programs. Proc. ACM Program. Lang. 4(OOPSLA) (2020),
  11. 11.
    Avanzini, M., Dal Lago, U., Yamada, A.: On probabilistic term rewriting. Sci. Comput. Program. 185 (2020),
  12. 12.
    Ben-Amram, A.M., Genaim, S.: Ranking functions for linear-constraint loops. J. ACM 61(4) (2014),
  13. 13.
    Ben-Amram, A.M., Genaim, S.: On multiphase-linear ranking functions. In: Proc. CAV ’17. LNCS, vol. 10427, pp. 601–620 (2017),
  14. 14.
    Ben-Amram, A.M., Doménech, J.J., Genaim, S.: Multiphase-linear ranking functions and their relation to recurrent sets. In: Proc. SAS ’19. LNCS, vol. 11822, pp. 459–480 (2019),
  15. 15.
    Bournez, O., Garnier, F.: Proving positive almost-sure termination. In: Proc. RTA ’05. LNCS, vol. 3467, pp. 323–337 (2005),
  16. 16.
    Bournez, O., Garnier, F.: Proving positive almost sure termination under strategies. In: Proc. RTA ’06. LNCS, vol. 4098, pp. 357–371 (2006),
  17. 17.
    Bradley, A.R., Manna, Z., Sipma, H.B.: Linear ranking with reachability. In: Proc. CAV ’05. LNCS, vol. 3576, pp. 491–504 (2005),
  18. 18.
    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) (2016),
  19. 19.
    Burstall, R.M., Darlington, J.: A transformation system for developing recursive programs. J. ACM 24(1), 44–67 (1977),
  20. 20.
    Carbonneaux, Q., Hoffmann, J., Shao, Z.: Compositional certified resource bounds. In: Proc. PLDI ’15. pp. 467–478 (2015),
  21. 21.
    Carbonneaux, Q., Hoffmann, J., Reps, T.W., Shao, Z.: Automated resource analysis with Coq proof objects. In: CAV ’17. LNCS, vol. 10427, pp. 64–85 (2017),
  22. 22.
    Chakarov, A., Sankaranarayanan, S.: Probabilistic program analysis with martingales. In: Proc. CAV ’13. LNCS, vol. 8044, pp. 511–526 (2013),
  23. 23.
    Chatterjee, K., Novotný, P., Zikelic, D.: Stochastic invariants for probabilistic termination. In: Proc. POPL ’17. pp. 145–160 (2017),
  24. 24.
    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) (2018),
  25. 25.
    Chatterjee, K., Fu, H., Novotný, P.: Termination analysis of probabilistic programs with martingales. In: Barthe, G., Katoen, J., Silva, A. (eds.) Foundations of Probabilistic Programming, pp. 221—258. Cambridge University Press (2020),
  26. 26.
    Ferrer Fioriti, L.M., Hermanns, H.: Probabilistic termination: Soundness, completeness, and compositionality. In: Proc. POPL ’15. pp. 489–501 (2015),
  27. 27.
    Flores-Montoya, A., Hähnle, R.: Resource analysis of complex programs with cost equations. In: Proc. APLAS ’14. LNCS, vol. 8858, pp. 275–295 (2014),
  28. 28.
    Flores-Montoya, A.: Upper and lower amortized cost bounds of programs expressed as cost relations. In: Proc. FM ’16. LNCS, vol. 9995, pp. 254–273 (2016),
  29. 29.
    Fu, H., Chatterjee, K.: Termination of nondeterministic probabilistic programs. In: Proc. VMCAI ’19. LNCS, vol. 11388, pp. 468–490 (2019),
  30. 30.
    Giesl, J., Aschermann, C., Brockschmidt, M., Emmes, F., Frohn, F., Fuhs, C., Hensel, J., Otto, C., Plücker, M., Schneider-Kamp, P., Ströder, T., Swiderski, S., Thiemann, R.: Analyzing program termination and complexity automatically with AProVE. J. Autom. Reasoning 58(1), 3–31 (2017),
  31. 31.
    Giesl, J., Rubio, A., Sternagel, C., Waldmann, J., Yamada, A.: The termination and complexity competition. In: Proc. TACAS ’19. LNCS, vol. 11429, pp. 156–166 (2019),
  32. 32.
    Giesl, J., Giesl, P., Hark, M.: Computing expected runtimes for constant probability programs. In: Proc. CADE ’19. LNAI, vol. 11716, pp. 269–286 (2019),
  33. 33.
    Hark, M., Kaminski, B.L., Giesl, J., Katoen, J.: Aiming low is harder: Induction for lower bounds in probabilistic program verification. Proc. ACM Program. Lang. 4(POPL) (2020),
  34. 34.
    Hoffmann, J., Aehlig, K., Hofmann, M.: Multivariate amortized resource analysis. ACM Trans. Program. Lang. Syst. 34(3) (2012),
  35. 35.
    Hoffmann, J., Shao, Z.: Type-based amortized resource analysis with integers and arrays. J. Funct. Program. 25 (2015),
  36. 36.
    Hoffmann, J., Das, A., Weng, S.C.: Towards automatic resource bound analysis for OCaml. In: Proc. POPL ’17. pp. 359–373 (2017),
  37. 37.
    Huang, M., Fu, H., Chatterjee, K.: New approaches for almost-sure termination of probabilistic programs. In: Proc. APLAS ’18. LNCS, vol. 11275, pp. 181–201 (2018),
  38. 38.
    Huang, M., Fu, H., Chatterjee, K., Goharshady, A.K.: Modular verification for almost-sure termination of probabilistic programs. Proc. ACM Program. Lang. 3(OOPSLA) (2019),
  39. 39.
    Jeannet, B., Miné, A.: Apron: A library of numerical abstract domains for static analysis. In: Proc. CAV ’09. pp. 661–667 (2009),
  40. 40.
    Kallenberg, O.: Foundations of Modern Probability. Springer, New York (2002),
  41. 41.
    Kaminski, B.L., Katoen, J., Matheja, C., Olmedo, F.: Weakest precondition reasoning for expected runtimes of randomized algorithms. J. ACM 65 (2018),
  42. 42.
    Kaminski, B.L., Katoen, J., Matheja, C.: Expected runtime analyis by program verification. In: Barthe, G., Katoen, J., Silva, A. (eds.) Foundations of Probabilistic Programming, pp. 185—220. Cambridge University Press (2020),
  43. 43.
    KoAT: Web interface, binary, Docker image, and examples available at the web site The source code is available at
  44. 44.
    Kozen, D.: Semantics of probabilistic programs. J. Comput. Syst. Sci. 22(3), 328–350 (1981),
  45. 45.
    McIver, A., Morgan, C.: Abstraction, Refinement and Proof for Probabilistic Systems. Springer (2005),
  46. 46.
    McIver, A., Morgan, C., Kaminski, B.L., Katoen, J.: A new proof rule for almost-sure termination. Proc. ACM Program. Lang. 2(POPL) (2018),
  47. 47.
    Meyer, F., Hark, M., Giesl, J.: Inferring expected runtimes of probabilistic integer programs using expected sizes. CoRR abs/2010.06367 (2020),
  48. 48.
    Moosbrugger, M., Bartocci, E., Katoen, J., Kovács, L.: Automated termination analysis of polynomial probabilistic programs. In: Proc. ESOP ’21. LNCS (2021), to appear.Google Scholar
  49. 49.
    de Moura, L., Bjørner, N.: Z3: An efficient SMT solver. In: Proc. TACAS ’08. LNCS, vol. 4963, pp. 337–340 (2008),
  50. 50.
    Ngo, V.C., Carbonneaux, Q., Hoffmann, J.: Bounded expectations: Resource analysis for probabilistic programs. In: Proc. PLDI ’18. pp. 496–512 (2018),, tool artifact and benchmarks available from
  51. 51.
    Noschinski, L., Emmes, F., Giesl, J.: Analyzing innermost runtime complexity of term rewriting by dependency pairs. J. Autom. Reasoning 51(1), 27–56 (2013),
  52. 52.
    Olmedo, F., Kaminski, B.L., Katoen, J., Matheja, C.: Reasoning about recursive probabilistic programs. In: Proc. LICS ’16. pp. 672–681 (2016),
  53. 53.
    Podelski, A., Rybalchenko, A.: A complete method for the synthesis of linear ranking functions. In: Proc. VMCAI ’04. LNCS, vol. 2937, pp. 239–251 (2004),
  54. 54.
    Puterman, M.L.: Markov Decision Processes: Discrete Stochastic Dynamic Programming. John Wiley & Sons (2005)Google Scholar
  55. 55.
    RaML (Resource Aware ML),
  56. 56.
    Sankaranarayanan, S., Sipma, H.B., Manna, Z.: Constraint-based linear-relations analysis. In: Proc. SAS ’04. LNCS, vol. 3148, pp. 53–68 (2004),
  57. 57.
    Sinn, M., Zuleger, F., Veith, H.: Complexity and resource bound analysis of imperative programs using difference constraints. J. Autom. Reasoning 59(1), 3–45 (2017),
  58. 58.
    Srikanth, A., Sahin, B., Harris, W.R.: Complexity verification using guided theorem enumeration. In: Proc. POPL ’17. pp. 639–652 (2017),
  59. 59.
    TPDB (Termination Problems Data Base),
  60. 60.
    Vardi, M.Y.: Automatic verification of probabilistic concurrent finite-state programs. In: Proc. FOCS ’85. pp. 327–338 (1985),
  61. 61.
    Wang, D., Kahn, D.M., Hoffmann, J.: Raising expectations: automating expected cost analysis with types. Proc. ACM Program. Lang. 4(ICFP) (2020),
  62. 62.
    Wang, P., Fu, H., Goharshady, A.K., Chatterjee, K., Qin, X., Shi, W.: Cost analysis of nondeterministic probabilistic programs. In: Proc. PLDI ’19. pp. 204–220 (2019),

Copyright information

© The Author(s) 2021

Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.

The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

Authors and Affiliations

  1. 1.LuFG Informatik 2, RWTH Aachen UniversityAachenGermany

Personalised recommendations