Finding Polynomial Loop Invariants for Probabilistic Programs

  • Yijun Feng
  • Lijun Zhang
  • David N. Jansen
  • Naijun Zhan
  • Bican Xia
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10482)


Quantitative loop invariants are an essential element in the verification of probabilistic programs. Recently, multivariate Lagrange interpolation has been applied to synthesizing polynomial invariants. In this paper, we propose an alternative approach. First, we fix a polynomial template as a candidate of a loop invariant. Using Stengle’s Positivstellensatz and a transformation to a sum-of-squares problem, we find sufficient conditions on the coefficients. Then, we solve a semidefinite programming feasibility problem to synthesize the loop invariants. If the semidefinite program is unfeasible, we backtrack after increasing the degree of the template. Our approach is semi-complete in the sense that it will always lead us to a feasible solution if one exists and numerical errors are small. Experimental results show the efficiency of our approach.



This work has been supported by the National Natural Science Foundation of China (Grants 61532019 and 61472473), the CAS/SAFEA International Partnership Program for Creative Research Teams, and the Sino-German CDZ project CAP (GZ 1023).


  1. 1.
    Barthe, G., Espitau, T., Ferrer Fioriti, L.M., Hsu, J.: Synthesizing probabilistic invariants via Doob’s decomposition. arXiv preprint arXiv:1605.02765 (2016)
  2. 2.
    Blekherman, G., Parrilo, P.A., Thomas, R.R. (eds.): Semidefinite Optimization and Convex Algebraic Geometry. SIAM, Philadelphia (2012). doi: 10.1137/1.9781611972290 zbMATHGoogle Scholar
  3. 3.
    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). doi: 10.1007/978-3-642-39799-8_34 CrossRefGoogle Scholar
  4. 4.
    Chakarov, A., Sankaranarayanan, S.: Expectation invariants for probabilistic program loops as fixed points. In: Müller-Olm, M., Seidl, H. (eds.) SAS 2014. LNCS, vol. 8723, pp. 85–100. Springer, Cham (2014). doi: 10.1007/978-3-319-10936-7_6 Google Scholar
  5. 5.
    Chatterjee, K., Fu, H., Goharshady, A.K.: Termination analysis of probabilistic programs through positivstellensatz’s. In: Chaudhuri, S., Farzan, A. (eds.) CAV 2016. LNCS, vol. 9779, pp. 3–22. Springer, Cham (2016). doi: 10.1007/978-3-319-41528-4_1 Google Scholar
  6. 6.
    Chatterjee, K., Fu, H., Novotný, P., Hasheminezhad, R.: Algorithmic analysis of qualitative and quantitative termination problems for affine probabilistic programs. In: Bodik, R., Majumdar, R. (eds.) POPL’16, pp. 327–342. ACM, New York (2016). doi: 10.1145/2837614.2837639
  7. 7.
    Chen, Y.-F., Hong, C.-D., Wang, B.-Y., Zhang, L.: Counterexample-guided polynomial loop invariant generation by lagrange interpolation. In: Kroening, D., Păsăreanu, C.S. (eds.) CAV 2015. LNCS, vol. 9206, pp. 658–674. Springer, Cham (2015). doi: 10.1007/978-3-319-21690-4_44 CrossRefGoogle Scholar
  8. 8.
    Colón, M.A., Sankaranarayanan, S., Sipma, H.B.: Linear invariant generation using non-linear constraint solving. In: Hunt Jr., W.A., Somenzi, F. (eds.) CAV 2003. LNCS, vol. 2725, pp. 420–432. Springer, Berlin (2003). doi: 10.1007/978-3-540-45069-6_39 CrossRefGoogle Scholar
  9. 9.
    Dai, L., Xia, B., Zhan, N.: Generating non-linear interpolants by semidefinite programming. In: Sharygina, N., Veith, H. (eds.) CAV 2013. LNCS, vol. 8044, pp. 364–380. Springer, Heidelberg (2013). doi: 10.1007/978-3-642-39799-8_25 CrossRefGoogle Scholar
  10. 10.
    Dijkstra, E.: A Discipline of Programming, vol. 4. Prentice-Hall, Englewood Cliffs (1976)zbMATHGoogle Scholar
  11. 11.
    Feller, W.: An Introduction to Probability Theory and Its Applications, vol. 1. Wiley, Hoboken (1968)zbMATHGoogle Scholar
  12. 12.
    Feng, Y., Zhang, L., Jansen, D.N., Zhan, N., Xia, B.: Finding polynomial loop invariants for probabilistic programs. arXiv:1707.02690 (2017)
  13. 13.
    Ferrer Fioriti, L.M., Hermanns, H.: Probabilistic termination: soundness, completeness, and compositionality. In: POPL 2015, Principles of Programming Languages, pp. 489–501. ACM, New York (2015). doi: 10.1145/2775051.2677001
  14. 14.
    Gordon, A.D., Henzinger, T.A., Nori, A.V., Rajamani, S.K.: Probabilistic programming. In: Dwyer, M.B., Herbsleb, J. (eds.) Future of Software Engineering (FOSE 2014), pp. 167–181. ACM, New York (2014). doi: 10.1145/2593882.2593900
  15. 15.
    Gretz, F., Katoen, J.-P., McIver, A.: Prinsys—on a quest for probabilistic loop invariants. In: Joshi, K., Siegle, M., Stoelinga, M., D’Argenio, P.R. (eds.) QEST 2013. LNCS, vol. 8054, pp. 193–208. Springer, Heidelberg (2013). doi: 10.1007/978-3-642-40196-1_17 CrossRefGoogle Scholar
  16. 16.
    Gretz, F., Katoen, J.-P., McIver, A.: Operational versus weakest pre-expectation semantics for the probabilistic guarded command language. Perf. Eval. 73, 110–132 (2014). doi: 10.1016/j.peva.2013.11.004 CrossRefGoogle Scholar
  17. 17.
    Han, J., Jin, Z., Xia, B.: Proving inequalities and solving global optimization problems via simplified CAD projection. J. Symb. Comput. 72, 206–230 (2016). doi: 10.1016/j.jsc.2015.02.007 MathSciNetCrossRefzbMATHGoogle Scholar
  18. 18.
    Hoare, C.A.R.: An axiomatic basis for computer programming. Commun. ACM 12(10), 576–580 (1969). doi: 10.1145/363235.363259 CrossRefzbMATHGoogle Scholar
  19. 19.
    Kaltofen, E.L., Li, B., Yang, Z., Zhi, L.: Exact certification in global polynomial optimization via sums-of-squares of rational functions with rational coefficients. J. Symb. Comput. 47(1), 1–15 (2012). doi: 10.1016/j.jsc.2011.08.002 MathSciNetCrossRefzbMATHGoogle Scholar
  20. 20.
    Kaminski, B.L., Katoen, J.-P.: On the hardness of almost–sure termination. In: Italiano, G.F., Pighizzini, G., Sannella, D.T. (eds.) MFCS 2015. LNCS, vol. 9234, pp. 307–318. Springer, Heidelberg (2015). doi: 10.1007/978-3-662-48057-1_24 CrossRefGoogle Scholar
  21. 21.
    Katoen, J.-P., McIver, A.K., Meinicke, L.A., Morgan, C.C.: Linear-invariant generation for probabilistic programs: In: Cousot, R., Martel, M. (eds.) SAS 2010. LNCS, vol. 6337, pp. 390–406. Springer, Berlin (2010). doi: 10.1007/978-3-642-15769-1_24 CrossRefGoogle Scholar
  22. 22.
    Löfberg, J.: YALMIP: a toolbox for modeling and optimization in MATLAB. In: 2004 IEEE International Symposium on Computer Aided Control Systems Design (CACSD), pp. 284–289. IEEE, Piscataway (2004). doi: 10.1109/CACSD.2004.1393890
  23. 23.
    McIver, A., Morgan, C.C.: Abstraction, Refinement and Proof for Probabilistic Systems. Springer, New York (2005). doi: 10.1007/b138392 zbMATHGoogle Scholar
  24. 24.
    Morgan, C., McIver, A., Seidel, K.: Probabilistic predicate transformers. ACM Trans. Progr. Lang. Syst. 18(3), 325–353 (1996). doi: 10.1145/229542.229547 CrossRefGoogle Scholar
  25. 25.
    Parrilo, P.A.: Semidefinite programming relaxations for semialgebraic problems. Math. Program. Ser. B 96(2), 293–320 (2003). doi: 10.1007/s10107-003-0387-5 MathSciNetCrossRefzbMATHGoogle Scholar
  26. 26.
    Peyrl, H., Parrilo, P.A.: Computing sum of squares decompositions with rational coefficients. Theoret. Comput. Sci. 409(2), 269–281 (2008). doi: 10.1016/j.tcs.2008.09.025 MathSciNetCrossRefzbMATHGoogle Scholar
  27. 27.
    Putinar, M.: Positive polynomials on compact semi-algebraic sets. Indiana Univ. Math. J. 42(3), 969–984 (1993)MathSciNetCrossRefzbMATHGoogle Scholar
  28. 28.
    Rodríguez-Carbonell, E., Kapur, D.: Generating all polynomial invariants in simple loops. J. Symb. Comput. 42(4), 443–476 (2007). doi: 10.1016/j.jsc.2007.01.002 MathSciNetCrossRefzbMATHGoogle Scholar
  29. 29.
    Stengle, G.: A nullstellensatz and a positivstellensatz in semialgebraic geometry. Math. Ann. 207(2), 87–97 (1974). doi: 10.1007/BF01362149 MathSciNetCrossRefzbMATHGoogle Scholar
  30. 30.
    Sturm, J.F.: Using SeDuMi 1.02, a MATLAB toolbox for optimization over symmetric cones. Optim. Methods Softw. 11(1–4), 625–653 (1999). doi: 10.1080/10556789908805766 MathSciNetCrossRefzbMATHGoogle Scholar

Copyright information

© Springer International Publishing AG 2017

Authors and Affiliations

  1. 1.LMAM and School of Mathematical SciencesPeking UniversityBeijingChina
  2. 2.State Key Laboratory of Computer Science, Institute of SoftwareCASBeijingChina
  3. 3.University of Chinese Academy of SciencesBeijingChina

Personalised recommendations