skip to main content
research-article
Open Access

A modular cost analysis for probabilistic programs

Published:13 November 2020Publication History
Skip Abstract Section

Abstract

We present a novel methodology for the automated resource analysis of non-deterministic, probabilistic imperative programs, which gives rise to a modular approach. Program fragments are analysed in full independence. Moreover, the established results allow us to incorporate sampling from dynamic distributions, making our analysis applicable to a wider class of examples, for example the Coupon Collector’s problem.

We have implemented our contributions in the tool , exploiting a constraint-solver over iterative refineable cost functions facilitated by off-the-shelf SMT solvers. We provide ample experimental evidence of the prototype’s algorithmic power. Our experiments show that our tool runs typically at least one order of magnitude faster than comparable tools. On more involved examples, it may even be the case that execution times of seconds become milliseconds. At the same time we retain the precision of existing tools.

The extensions in applicability and the greater efficiency of our prototype, yield scalability of sorts. This effects into a wider class of examples, whose expected cost analysis can be thus be performed fully automatically.

Skip Supplemental Material Section

Supplemental Material

oopsla20main-p190-p-video.mp4

mp4

50.3 MB

References

  1. S. Agrawal, K. Chatterjee, and P. Novotný. 2018. Lexicographic Ranking Supermartingales: An Eficient Approach to Termination of Probabilistic Programs. PACMPL 2, POPL ( 2018 ), 34 : 1-34 : 32. https://doi.org/10.1145/3385412.3386002 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. E. Albert, P. Gordillo, A. Rubio, and I. Sergey. 2019. Running on Fumes-Preventing Out-of-Gas Vulnerabilities in Ethereum Smart Contracts Using Static Resource Analysis. In Proc. of 13th VECoS (LNCS, Vol. 11847 ). Springer, 63-78. https: //doi.org/10.1007/978-3-030-35092-5_5 Google ScholarGoogle ScholarCross RefCross Ref
  3. C. Alias, A. Darte, P. Feautrier, and L. Gonnord. 2010. Multi-dimensional Rankings, Program Termination, and Complexity Bounds of Flowchart Programs. In Proc. of 17th SAS (LNCS, Vol. 6337 ). Springer, 117-133. https://doi.org/10.1007/978-3-642-15769-1_8 Google ScholarGoogle ScholarCross RefCross Ref
  4. M. Avanzini, U. Dal Lago, and A. Ghyselen. 2019. Type-Based Complexity Analysis of Probabilistic Functional Programs. In Proc. of 34th LICS. IEEE, 1-13. https://doi.org/10.1109/LICS. 2019.8785725 Google ScholarGoogle ScholarCross RefCross Ref
  5. M. Avanzini, U. Dal Lago, and A. Yamada. 2020. On Probabilistic Term Rewriting. SCP 185 ( 2020 ), 102338. https: //doi.org/10.1016/j.scico. 2019.102338 Google ScholarGoogle ScholarCross RefCross Ref
  6. M. Avanzini, G. Moser, and M. Schaper. 2016. TcT: Tyrolean Complexity Tool. In Proc. of 2nd TACAS (LNCS). Springer, 407-423. https://doi.org/10.1007/978-3-662-49674-9_24 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. M. Avanzini and A. Yamada. 2020. Weighted Rewriting. Technical Report. NII and INRIA.Google ScholarGoogle Scholar
  8. G. Barthe, B. Grégoire, and S. Z. Béguelin. 2009. Formal Certification of Code-based Cryptographic Proofs. In Proc. of 36th POPL. ACM, 90-101. https://doi.org/10.1145/1480881.1480894 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. A. Ben-Amram. 2011. Monotonicity Constraints for Termination in the Integer Domain. LMCS 7, 3 ( 2011 ), 1-43. https: //doi.org/10.2168/LMCS-7( 3 :4) 2011 Google ScholarGoogle ScholarCross RefCross Ref
  10. A. Ben-Amram. 2015. Mortality of Iterated Piecewise Afine Functions over the Integers: Decidability and Complexity. Computability 4, 1 ( 2015 ), 19-56. https://doi.org/10.3233/COM-150032 Google ScholarGoogle ScholarCross RefCross Ref
  11. A. Ben-Amram and G. Hamilton. 2019. Tight Worst-Case Bounds for Polynomial Loop Programs. In Proc. of 22th FOSSACS (LNCS, Vol. 11425 ). Springer, 80-97. https://doi.org/10.1007/978-3-030-17127-8_5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. A. M. Ben-Amram and L. Kristiansen. 2012. On the Edge of Decidability in Complexity Analysis of Loop Programs. JFCS 23, 7 ( 2012 ), 1451-1464. https://doi.org/10.1142/S0129054112400588 Google ScholarGoogle ScholarCross RefCross Ref
  13. O. Bournez and F. Garnier. 2005. Proving Positive Almost-Sure Termination. In Proc. of 16th RTA (LNCS, Vol. 3467 ). Springer, 323-337. https://doi.org/10.1142/S0129054112400588 Google ScholarGoogle ScholarCross RefCross Ref
  14. T. Brázdil, S. Kiefer, A. Kucera, and I.H. Vareková. 2015. Runtime Analysis of Probabilistic Programs with Unbounded Recursion. JCSS 81, 1 ( 2015 ), 288-310. https://doi.org/10.1016/j.jcss. 2014. 06.005 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. F. Breuvart and U. Dal Lago. 2018. On Intersection Types and Probabilistic Lambda Calculi. In Proc. of 20th PPDP. ACM, 8 : 1-8 : 13. https://doi.org/10.1145/3236950.3236968 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. M. Brockschmidt, F. Emmes, S. Falke, C. Fuhs, and J. Giesl. 2014. Alternating Runtime and Size Complexity Analysis of Integer Programs. In Proc. of 20th TACAS (LNCS, Vol. 8413 ). Springer, 140-155. https://doi.org/10.1007/978-3-642-54862-8_10 Google ScholarGoogle ScholarCross RefCross Ref
  17. M. Brockschmidt, F. Emmes, S. Falke, C. Fuhs, and J. Giesl. 2016. Analyzing Runtime and Size Complexity of Integer Programs. TOPLAS 38, 4 ( 2016 ), 13 : 1-13 : 50. https://doi.org/10.1145/2866575 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Q. Carbonneaux, J. Hofmann, and Z. Shao. 2015. Compositional Certified Resource Bounds. In Proc. of 36th PLDI. ACM, 467-478. https://doi.org/10.1145/2813885.2737955 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. O. Celiku and A. McIver. 2005. Compositional Specification and Analysis of Cost-Based Properties in Probabilistic Programs. In Proc. of FM 2005 (LNCS, Vol. 3582 ). Springer, 107-122. https://doi.org/10.1007/11526841_9 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. A. Chakarov and S. Sankaranarayanan. 2013. Probabilistic Program Analysis with Martingales. In Proc. of 25th CAV (LNCS, Vol. 8044 ). Springer, 511-526. https://doi.org/10.1007/978-3-642-39799-8_34 Google ScholarGoogle ScholarCross RefCross Ref
  21. A. Chakarov and S. Sankaranarayanan. 2014. Expectation Invariants for Probabilistic Program Loops as Fixed Points. In Proc. of 21th SAS (LNCS). Springer, 85-100. https://doi.org/10.1007/978-3-319-10936-7_6 Google ScholarGoogle ScholarCross RefCross Ref
  22. K. Chatterjee, H. Fu, and A. K. Goharshady. 2016. Termination Analysis of Probabilistic Programs Through Positivstellensatz's. In Proc. of 28th CAV (LNCS, Vol. 9779 ). Springer, 3-22. https://doi.org/10.1007/978-3-319-41528-4_1 Google ScholarGoogle ScholarCross RefCross Ref
  23. K. Chatterjee, H. Fu, and A. Murhekar. 2017a. Automated Recurrence Analysis for Almost-Linear Expected-Runtime Bounds. In Proc. of 29th CAV (LNCS, Vol. 10426 ). Springer, 118-139. https://doi.org/10.1007/978-3-319-63387-9_6 Google ScholarGoogle ScholarCross RefCross Ref
  24. K. Chatterjee, P. Novotný, and D. Zikelic. 2017b. Stochastic Invariants for Probabilistic Termination. In Proc. of 44th POPL. ACM, 145-160. https://doi.org/10.1145/3093333.3009873 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. J. Cohen and C. Zuckerman. 1974. Two Languages for Estimating Program Eficiency. Comm. ACM 17, 6 ( 1974 ), 301-308. https://doi.org/10.1145/355616.361015 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. E. Contejean, C. Marché, A.-P. Tomás, and X. Urbain. 2005. Mechanically Proving Termination Using Polynomial Interpretations. JAR 34, 4 ( 2005 ), 325-363. https://doi.org/10.1007/s10817-005-9022-x Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. P. Cousot and R. Cousot. 2002. Modular Static Program Analysis. In Proc. of 11th CC (LNCS, Vol. 2304 ). Springer, 159-178. https://doi.org/10.1007/3-540-45937-5_13 Google ScholarGoogle ScholarCross RefCross Ref
  28. J. Dean and S. Ghemawat. 2008. MapReduce: Simplified Data Processing on Large Clusters. Commun. ACM 51, 1 ( 2008 ), 107-113. https://doi.org/10.1145/1327452.1327492 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. T. Dillig. 2011. A Modular and Symbolic Approach to Static Program Analysis. Ph.D. Dissertation. Stanford University.Google ScholarGoogle Scholar
  30. J. Esparza, A. Kucera, and R. Mayr. 2005. Quantitative Analysis of Probabilistic Pushdown Automata: Expectations and Variances. In Proc. of 20th LICS. IEEE, 117-126. https://doi.org/10.1109/LICS. 2005.39 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. T. Fiedor, L. Holík, A. Rogalewicz, M. Sinn, T. Vojnar, and F. Zuleger. 2018. From Shapes to Amortized Complexity. In Proc. of 19th VMCAI (LNCS, Vol. 10747 ). Springer, 205-225. https://doi.org/10.1007/978-3-319-73721-8_10 Google ScholarGoogle ScholarCross RefCross Ref
  32. F. Frohn and J. Giesl. 2017. Complexity Analysis for Java with AProVE. In Proc. of the 13th IFM (LNCS, Vol. 10510 ). Springer, 85-101. https://doi.org/10.1007/978-3-319-66845-1_6 Google ScholarGoogle ScholarCross RefCross Ref
  33. C. Fuhs, J. Giesl, A. Middeldorp, P. Schneider-Kamp, R. Thiemann, and H. Zankl. 2007. SAT Solving for Termination Analysis with Polynomial Interpretations. In Proc. of 10th SAT (LNCS, Vol. 4501 ). Springer, 340-354. https://doi.org/10.1007/978-3-540-72788-0_33 Google ScholarGoogle ScholarCross RefCross Ref
  34. T. Gehr, S. Misailovic, and M. Vechev. 2016. PSI: Exact Symbolic Inference for Probabilistic Programs. In Proc. of 28th CAV (LNCS, Vol. 9779 ). Springer, 62-83. https://doi.org/10.1007/978-3-319-41528-4_4 Google ScholarGoogle ScholarCross RefCross Ref
  35. S. Gulwani, K.K. Mehra, and T.M. Chilimbi. 2009. SPEED: Precise and Eficient Static Estimation of Program Computational Complexity. In Proc. of 36th POPL. ACM, 127-139. https://doi.org/10.1145/1594834.1480898 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. S. Gulwani and A. Tiwari. 2006. Combining Abstract Interpreters. In Proc. of PLDI'06. ACM, 376-386. https://doi.org/10. 1145/1133981.1134026 Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. S. Gulwani and F. Zuleger. 2010. The Reachability-Bound Problem. In Proc. of PLDI'10. ACM, 292-304. https://doi.org/10. 1145/1809028.1806630 Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. D. Handelman. 1988. Representing Polynomials by Positive Linear Functions on Compact Convex Polyhedra. PJM 132, 1 ( 1988 ), 35-62. https://doi.org/10.2140/pjm. 1988. 132.35 Google ScholarGoogle ScholarCross RefCross Ref
  39. M. D. Hill and M.R. Marty. 2008. Amdahl's Law in the Multicore Era. Computer 41, 7 ( 2008 ), 33-38. https://doi.org/10.1109/ MC. 2008.209 Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. N. Hirokawa and G. Moser. 2008. Automated Complexity Analysis Based on the Dependency Pair Method. In Proc. of 4th IJCAR (LNAI, Vol. 5195 ). Springer, 364-380. https://doi.org/10.1007/978-3-540-71070-7_32 Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. J. Hofmann, A. Das, and S.-C. Weng. 2017. Towards Automatic Resource Bound Analysis for OCaml. In Proc. of 44th POPL. ACM, 359-373. https://doi.org/10.1145/3009837.3009842 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. N. D. Jones and L. Kristiansen. 2009. A Flow Calculus of mwp-Bounds for Complexity Analysis. TOCL 10, 4 ( 2009 ), 28 : 1-28 : 41. https://doi.org/10.1145/1555746.1555752 Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. B. L. Kaminski and J.-P. Katoen. 2017. A Weakest Pre-expectation Semantics for Mixed-sign Expectations. In Proc. of 32nd LICS. IEEE, 1-12. https://doi.org/10.1109/LICS. 2017.8005153 Google ScholarGoogle ScholarCross RefCross Ref
  44. B. Lucien Kaminski, J.-P. Katoen, C. Matheja, and F. Olmedo. 2016. Weakest Precondition Reasoning for Expected Run-Times of Probabilistic Programs. In Proc. of 25th ESOP (LNCS, Vol. 9632 ). Springer, 364-389. https://doi.org/10.1007/978-3-662-49498-1_15 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. B. L. Kaminski, J.-P. Katoen, C. Matheja, and F. Olmedo. 2018. Weakest Precondition Reasoning for Expected Runtimes of Randomized Algorithms. JACM 65, 5 ( 2018 ), 30 : 1-30 : 68. https://doi.org/10.1145/3208102 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. B. L. Kaminski and J.-P. Katoen. 2015. On the Hardness of Almost-Sure Termination. In MFCS 2015, Part I (LNCS ). Springer, 307-318. https://doi.org/10.1007/978-3-662-48057-1_24 Google ScholarGoogle ScholarCross RefCross Ref
  47. J.-P. Katoen. 2016. The Probabilistic Model Checking Landscape. In Proc. of 31nd LICS. ACM, 31-45. https://doi.org/10.1145/ 2933575.2934574 Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. J.-P. Katoen, A. McIver, L. Meinicke, and C.C. Morgan. 2010. Linear-Invariant Generation for Probabilistic Programs:-Automated Support for Proof-Based Methods. In Proc. of 17th SAS (LNCS, Vol. 6337 ). Springer, 390-406. https://doi.org/ 10.1007/978-3-642-15769-1_24 Google ScholarGoogle ScholarCross RefCross Ref
  49. C. Kim and A. K. Agrawala. 1989. Analysis of the Fork-join Queue. IEEE TC 38, 2 ( 1989 ), 250-255. https://doi.org/10.1109/ 12.16501 Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. D. Kozen. 1981. Semantics of Probabilistic Programs. J. Comput. Syst. Sci. 22, 3 ( 1981 ), 328-350.Google ScholarGoogle ScholarCross RefCross Ref
  51. D. Kozen. 1985. A Probabilistic PDL. JCSC 30, 2 ( 1985 ), 162-178. https://doi.org/10.1016/ 0022-0000 ( 85 ) 90012-1 Google ScholarGoogle ScholarCross RefCross Ref
  52. A. Levitin. 2007. The Design and Analysis of Algorithms. Pearson.Google ScholarGoogle Scholar
  53. A. McIver, C. Morgan, B. L. Kaminski, and J-P Katoen. 2018. A New Proof Rule for Almost-sure Termination. PACMPL 2, POPL ( 2018 ), 33 : 1-33 : 28. https://doi.org/10.1145/3158121 Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. D. A. Menascé. 2004. Response-Time Analysis of Composite Web Services. IEEE IC 8, 1 ( 2004 ), 90-92. https://doi.org/10. 1109/MIC. 2004.1260710 Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. M. Mitzenmacher and E. Upfal. 2005. Probability and Computing: Randomized Algorithms and Probabilistic Analysis. Cambridge University Press.Google ScholarGoogle Scholar
  56. D. Monniaux. 2001. An Abstract Analysis of the Probabilistic Termination of Programs. In Proc. of 8th SAS (LNCS, Vol. 2126 ). Springer, 111-126. https://doi.org/10.1007/3-540-47764-0_7 Google ScholarGoogle ScholarCross RefCross Ref
  57. G. Moser and M. Schaper. 2018. From Jinja Bytecode to Term Rewriting: A Complexity Reflecting Transformation. IC 261, Part ( 2018 ), 116-143. https://doi.org/10.1016/j.ic. 2018. 05.007 Google ScholarGoogle ScholarCross RefCross Ref
  58. N. C. Ngo, Q. Carbonneaux, and J. Hofmann. 2018. Bounded Expectations: Resource Analysis for Probabilistic Programs. In Proc. of 39th PLDI. ACM, 496-512. https://doi.org/10.1145/3296979.3192394 Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. V. Chan Ngo, M. Dehesa-Azuara, M. Fredrikson, and J. Hofmann. 2017. Verifying and Synthesizing Constant-Resource Implementations with Types. In Proc. of 38th S&P. 710-728.Google ScholarGoogle Scholar
  60. F. Olmedo, B. L. Kaminski, J.-P. Katoen, and C. Matheja. 2016. Reasoning about Recursive Probabilistic Programs. In Proc. of 31nd LICS. ACM, 672-681. https://doi.org/10.1145/2933575.2935317 Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. A. Podelski and A. Rybalchenko. 2004. A Complete Method for the Synthesis of Linear Ranking Functions. In Proc. of 5th VMCAI (LNCS, Vol. 2937 ). Springer, 239-251. https://doi.org/10.1007/978-3-540-24622-0_20 Google ScholarGoogle ScholarCross RefCross Ref
  62. R. Sedgewick and P. Flajolet. 1996. An Introduction to the Analysis of Algorithms. Addison-Wesley-Longman. https: //doi.org/10.1142/10875 Google ScholarGoogle ScholarCross RefCross Ref
  63. M. Sinn, F. Zuleger, and H. Veith. 2016. A Simple and Scalable Static Analysis for Bound Analysis and Amortized Complexity Analysis. In Proc. of 26th CAV (LNCS, Vol. 8559 ). Springer, 745-761. https://doi.org/10.1007/978-3-319-08867-9_50 Google ScholarGoogle ScholarDigital LibraryDigital Library
  64. M. Sinn, F. Zuleger, and H. Veith. 2017. Complexity and Resource Bound Analysis of Imperative Programs Using Diference Constraints. JAR 59, 1 ( 2017 ), 3-45. https://doi.org/10.1007/s10817-016-9402-4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  65. T. Takisaka, Y. Oyabu, N. Urabe, and I. Hasuo. 2018. Ranking and Repulsing Supermartingales for Reachability in Probabilistic Programs. In Proc. of 16th ATVA (LNCS, Vol. 11138 ). Springer, 476-493. https://doi.org/10.1007/978-3-030-01090-4_28 Google ScholarGoogle ScholarCross RefCross Ref
  66. D. Wang, J. Hofmann, and T. W. Reps. 2018. PMAF: An Algebraic Framework for Static Analysis of Probabilistic Programs. In Proc. of 39th PLDI. ACM, 513-528. https://doi.org/10.1145/3192366.3192408 Google ScholarGoogle ScholarDigital LibraryDigital Library
  67. P. Wang, H. Fu, A. K. Goharshady, K. Chatterjee, X. Qin, and W. Shi. 2019. Cost Analysis of Nondeterministic Probabilistic Programs. In Proc. of 40th PLDI. ACM, 204-220. https://doi.org/10.1145/3314221.3314581 Google ScholarGoogle ScholarDigital LibraryDigital Library
  68. B. Wegbreit. 1975. Mechanical Program Analysis. Comm. ACM 18, 9 ( 1975 ), 528-539. https://doi.org/10.1145/361002.361016 Google ScholarGoogle ScholarDigital LibraryDigital Library
  69. B. Wegbreit. 1976. Verifying Program Performance. JACM 23, 4 ( 1976 ), 691-699. https://doi.org/10.1145/321978.321987 Google ScholarGoogle ScholarDigital LibraryDigital Library
  70. R. Wilhelm, J. Engblom, A. Ermedahl, N. Holsti, S. Thesing, D. Whalley, G. Bernat, C. Ferdinand, R. Heckmann, T. Mitra, F. Mueller, I. Puaut, P. Puschner, J. Staschulat, and P. Stenstrom. 2008. The Worst Case Execution Time Problem-Overview of Methods and Survey of Tools. TECS 7, 3 ( 2008 ), 1-53. https://doi.org/10.1145/1347375.1347389 Google ScholarGoogle ScholarDigital LibraryDigital Library
  71. R. Wilhelm and D. Grund. 2014. Computation Takes Time, But How Much? Comm. ACM 57, 2 ( 2014 ), 94-103. https: //doi.org/10.1145/2500886 Google ScholarGoogle ScholarDigital LibraryDigital Library
  72. G. Winskel. 1993. The Formal Semantics of Programming Languages. MIT Press. https://doi.org/10.7551/mitpress/3054.003. 0004 Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. A modular cost analysis for probabilistic programs

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image Proceedings of the ACM on Programming Languages
          Proceedings of the ACM on Programming Languages  Volume 4, Issue OOPSLA
          November 2020
          3108 pages
          EISSN:2475-1421
          DOI:10.1145/3436718
          Issue’s Table of Contents

          Copyright © 2020 Owner/Author

          This work is licensed under a Creative Commons Attribution International 4.0 License.

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 13 November 2020
          Published in pacmpl Volume 4, Issue OOPSLA

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader