skip to main content

Algebro-geometric Algorithms for Template-Based Synthesis of Polynomial Programs

Published:06 April 2023Publication History
Related Artifact: PolySynth software https://doi.org/10.5281/zenodo.7697453
Skip Abstract Section

Abstract

Template-based synthesis, also known as sketching, is a localized approach to program synthesis in which the programmer provides not only a specification, but also a high-level "sketch" of the program. The sketch is basically a partial program that models the general intuition of the programmer, while leaving the low-level details as unimplemented "holes". The role of the synthesis engine is then to fill in these holes such that the completed program satisfies the desired specification. In this work, we focus on template-based synthesis of polynomial imperative programs with real variables, i.e. imperative programs in which all expressions appearing in assignments, conditions and guards are polynomials over program variables. While this problem can be solved in a sound and complete manner by a reduction to the first-order theory of the reals, the resulting formulas will contain a quantifier alternation and are extremely hard for modern SMT solvers, even when considering toy programs with a handful of lines. Moreover, the classical algorithms for quantifier elimination are notoriously unscalable and not at all applicable to this use-case.

In contrast, our main contribution is an algorithm, based on several well-known theorems in polyhedral and real algebraic geometry, namely Putinar's Positivstellensatz, the Real Nullstellensatz, Handelman's Theorem and Farkas' Lemma, which sidesteps the quantifier elimination difficulty and reduces the problem directly to Quadratic Programming (QP). Alternatively, one can view our algorithm as an efficient way of eliminating quantifiers in the particular formulas that appear in the synthesis problem. The resulting QP instances can then be handled quite easily by SMT solvers. Notably, our reduction to QP is sound and semi-complete, i.e. it is complete if polynomials of a sufficiently high degree are used in the templates. Thus, we provide the first method for sketching-based synthesis of polynomial programs that does not sacrifice completeness, while being scalable enough to handle meaningful programs. Finally, we provide experimental results over a variety of examples from the literature.

References

  1. Alessandro Abate, Cristina David, Pascal Kesseli, Daniel Kroening, and Elizabeth Polgreen. 2018. Counterexample guided inductive synthesis modulo theories. In CAV. 270–288. Google ScholarGoogle Scholar
  2. Sheshansh Agrawal, Krishnendu Chatterjee, and Petr Novotnỳ. 2017. Lexicographic ranking supermartingales: an efficient approach to termination of probabilistic programs. In POPL. Google ScholarGoogle Scholar
  3. Rajeev Alur, Rastislav Bodik, Garvit Juniwal, Milo MK Martin, Mukund Raghothaman, Sanjit A Seshia, Rishabh Singh, Armando Solar-Lezama, Emina Torlak, and Abhishek Udupa. 2013. Syntax-Guided Synthesis. FMCAD. Google ScholarGoogle Scholar
  4. Rajeev Alur, Dana Fisman, Saswat Padhi, Andrew Reynolds, Rishabh Singh, and Abhishek Udupa. 2019. SyGuS-Comp: Syntax-guided Synthesis Competition. https://sygus.org/ Google ScholarGoogle Scholar
  5. Rajeev Alur, Rishabh Singh, Dana Fisman, and Armando Solar-Lezama. 2018. Search-based program synthesis. Commun. ACM, 61, 12 (2018), 84–93. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Ali Asadi, Krishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady, and Mohammad Mahdavi. 2021. Polynomial reachability witnesses via Stellensätze. In PLDI. 772–787. Google ScholarGoogle Scholar
  7. Haniel Barbosa, Clark W. Barrett, Martin Brain, Gereon Kremer, Hanna Lachnitt, Makai Mann, Abdalrhman Mohamed, Mudathir Mohamed, Aina Niemetz, Andres Nötzli, Alex Ozdemir, Mathias Preiner, Andrew Reynolds, Ying Sheng, Cesare Tinelli, and Yoni Zohar. 2022. cvc5: A Versatile and Industrial-Strength SMT Solver. In TACAS, Dana Fisman and Grigore Rosu (Eds.). 415–442. Google ScholarGoogle Scholar
  8. Grigoriy Blekherman, Pablo A Parrilo, and Rekha R Thomas. 2012. Semidefinite optimization and convex algebraic geometry. SIAM. Google ScholarGoogle Scholar
  9. Jacek Bochnak, Michel Coste, and Marie-Françoise Roy. 2013. Real algebraic geometry. 36, Springer Science & Business Media. Google ScholarGoogle Scholar
  10. James Bornholt and Emina Torlak. 2018. Finding code that explodes under symbolic evaluation. In OOPSLA. 1–26. Google ScholarGoogle Scholar
  11. Krishnendu Chatterjee, Hongfei Fu, and Amir Kafshdar Goharshady. 2016. Termination analysis of probabilistic programs through Positivstellensatz’s. In CAV. 3–22. Google ScholarGoogle Scholar
  12. Krishnendu Chatterjee, Hongfei Fu, and Amir Kafshdar Goharshady. 2017. Non-polynomial Worst-Case Analysis of Recursive Programs. In CAV. 10427, 41–63. Google ScholarGoogle Scholar
  13. Krishnendu Chatterjee, Hongfei Fu, and Amir Kafshdar Goharshady. 2019. Non-polynomial Worst-Case Analysis of Recursive Programs. ACM Trans. Program. Lang. Syst., 41, 4 (2019), 20:1–20:52. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Krishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady, and Ehsan Kafshdar Goharshady. 2020. Polynomial invariant generation for non-deterministic recursive programs. In PLDI. 672–687. Google ScholarGoogle Scholar
  15. Krishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady, and Nastaran Okati. 2018. Computational Approaches for Stochastic Shortest Path on Succinct MDPs. In IJCAI. 4700–4707. Google ScholarGoogle Scholar
  16. Krishnendu Chatterjee, Hongfei Fu, and Petr Novotnỳ. 2020. Termination analysis of probabilistic programs with martingales. Foundations of Probabilistic Programming, 221–258. Google ScholarGoogle Scholar
  17. Krishnendu Chatterjee, Amir Kafshdar Goharshady, Tobias Meggendorfer, and Dorde Zikelic. 2022. Sound and Complete Certificates for Quantitative Termination Analysis of Probabilistic Programs. In CAV. 55–78. Google ScholarGoogle Scholar
  18. Alonzo Church. 1963. Application of recursive arithmetic to the problem of circuit synthesis. Journal of Symbolic Logic, 28, 4 (1963). Google ScholarGoogle Scholar
  19. Alessandro Cimatti, Alberto Griggio, Bastiaan Schaafsma, and Roberto Sebastiani. 2013. The MathSAT5 SMT Solver. In TACAS, Nir Piterman and Scott Smolka (Eds.). Google ScholarGoogle Scholar
  20. Michael A Colón, Sriram Sankaranarayanan, and Henny B Sipma. 2003. Linear invariant generation using non-linear constraint solving. In CAV. 420–432. Google ScholarGoogle Scholar
  21. Julius Farkas. 1902. Theory of simple inequalities.. Journal for pure and applied mathematics (Crelles Journal), 1902, 124 (1902), 1–27. Google ScholarGoogle Scholar
  22. Grigory Fedyukovich, Sumanth Prabhu, Kumar Madhukar, and Aarti Gupta. 2019. Quantified invariants via syntax-guided synthesis. In CAV. 259–277. Google ScholarGoogle Scholar
  23. Yijun Feng, Lijun Zhang, David N Jansen, Naijun Zhan, and Bican Xia. 2017. Finding polynomial loop invariants for probabilistic programs. In ATVA. 400–416. Google ScholarGoogle Scholar
  24. Amir Goharshady. 2020. Parameterized and algebro-geometric advances in static program analysis. Ph.D. Dissertation. Institute of Science and Technology Austria. Google ScholarGoogle Scholar
  25. Amir Goharshady, S. Hitarth, Fatemeh Mohammadi, and Harshit Motwani. 2023. Algebro-geometric Algorithms for Template-based Synthesis of Polynomial Programs (Full Version including Appendices). https://hal.science/hal-04012686 Google ScholarGoogle Scholar
  26. Amir Kafshdar Goharshady, S. Hitarth, Fatemeh Mohammadi, and Harshit Jitendra Motwani. 2023. Algebro-geometric Algorithms for Template-based Synthesis of Polynomial Programs (Artifact). https://doi.org/10.5281/zenodo.7697453 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Cordell Green. 1981. Application of theorem proving to problem solving. In Readings in Artificial Intelligence. 202–222. Google ScholarGoogle Scholar
  28. Sumit Gulwani. 2011. Automating string processing in spreadsheets using input-output examples. In POPL. 317–330. Google ScholarGoogle Scholar
  29. Sumit Gulwani, William R Harris, and Rishabh Singh. 2012. Spreadsheet data manipulation using examples. Commun. ACM, 55, 8 (2012), 97–105. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Sumit Gulwani, Susmit Jha, Ashish Tiwari, and Ramarathnam Venkatesan. 2011. Synthesis of loop-free programs. In PLDI. 62–73. Google ScholarGoogle Scholar
  31. Sumit Gulwani, Oleksandr Polozov, and Rishabh Singh. 2017. Program synthesis. Foundations and Trends in Programming Languages, 4, 1-2 (2017), 1–119. Google ScholarGoogle ScholarCross RefCross Ref
  32. Zheng Guo, Michael James, David Justo, Jiaxiao Zhou, Ziteng Wang, Ranjit Jhala, and Nadia Polikarpova. 2019. Program synthesis by type-guided abstraction refinement. In POPL. 1–28. Google ScholarGoogle Scholar
  33. David Handelman. 1988. Representing polynomials by positive linear functions on compact convex polyhedra. Pacific J. Math., 132, 1 (1988), 35–62. Google ScholarGoogle ScholarCross RefCross Ref
  34. Robin Hartshorne. 2013. Algebraic geometry. 52, Springer Science & Business Media. Google ScholarGoogle Scholar
  35. Qinheping Hu, Rishabh Singh, and Loris D’Antoni. 2022. Solving Program Sketches with Large Integer Values. TOPLAS, 44, 2 (2022), 9:1–9:28. Google ScholarGoogle Scholar
  36. Mingzhang Huang, Hongfei Fu, Krishnendu Chatterjee, and Amir Kafshdar Goharshady. 2019. Modular verification for almost-sure termination of probabilistic programs. In OOPSLA. 129:1–129:29. Google ScholarGoogle Scholar
  37. Andreas Humenberger, Maximilian Jaroschek, and Laura Kovács. 2018. Invariant Generation for Multi-Path Loops with Polynomial Assignments. In VMCAI. 10747, 226–246. Google ScholarGoogle Scholar
  38. Tristan Knoth, Di Wang, Nadia Polikarpova, and Jan Hoffmann. 2019. Resource-guided program synthesis. In PLDI. 253–268. Google ScholarGoogle Scholar
  39. Andrej Kolmogoroff. 1932. Zur deutung der intuitionistischen logik. Mathematische Zeitschrift, 35, 1 (1932), 58–65. Google ScholarGoogle ScholarCross RefCross Ref
  40. John R Koza. 1994. Genetic programming as a means for programming computers by natural selection. Statistics and computing, 4, 2 (1994), 87–112. Google ScholarGoogle Scholar
  41. Krzysztof Krawiec. 2016. Behavioral program synthesis with genetic programming. 618. Google ScholarGoogle Scholar
  42. Hongming Liu, Hongfei Fu, Zhiyong Yu, Jiaxin Song, and Guoqiang Li. 2022. Location-by-Location Linear Invariant Generation with Farkas’ Lemma. In OOPSLA. Google ScholarGoogle Scholar
  43. Ngoc Hoang Anh Mai and Victor Magron. 2022. On the complexity of Putinar–Vasilescu’s Positivstellensatz. Journal of Complexity, 101663. Google ScholarGoogle Scholar
  44. Zohar Manna and Richard J Waldinger. 1971. Toward automatic program synthesis. Commun. ACM, 14, 3 (1971), 151–165. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Aaron Meurer, Christopher P Smith, Mateusz Paprocki, Ondřej Čertík, Sergey B Kirpichev, Matthew Rocklin, AMiT Kumar, Sergiu Ivanov, Jason K Moore, and Sartaj Singh. 2017. SymPy: symbolic computing in Python. PeerJ Computer Science, 3 (2017), e103. Google ScholarGoogle ScholarCross RefCross Ref
  46. Leonardo de Moura and Nikolaj Bjørner. 2008. Z3: An efficient SMT solver. In TACAS. 337–340. Google ScholarGoogle Scholar
  47. Eike Neumann, Joël Ouaknine, and James Worrell. 2020. On ranking function synthesis and termination for polynomial programs. In CONCUR. Google ScholarGoogle Scholar
  48. Rong Pan, Qinheping Hu, Rishabh Singh, and Loris D’Antoni. 2020. Solving Program Sketches with Large Integer Values. In ESOP. 572–598. Google ScholarGoogle Scholar
  49. Amir Pnueli and Roni Rosner. 1989. On the synthesis of a reactive module. In POPL. 179–190. Google ScholarGoogle Scholar
  50. Nadia Polikarpova, Ivan Kuraj, and Armando Solar-Lezama. 2016. Program synthesis from polymorphic refinement types. In PLDI. 522–538. Google ScholarGoogle Scholar
  51. Mathias Preiner, Aina Niemetz, and Armin Biere. 2017. Counterexample-guided model synthesis. In TACAS. 264–280. Google ScholarGoogle Scholar
  52. Mihai Putinar. 1993. Positive polynomials on compact semi-algebraic sets. Indiana University Mathematics Journal, 42, 3 (1993), 969–984. Google ScholarGoogle ScholarCross RefCross Ref
  53. Andrew Reynolds, Morgan Deters, Viktor Kuncak, Cesare Tinelli, and Clark Barrett. 2015. Counterexample-guided quantifier instantiation for synthesis in SMT. In CAV. 198–216. Google ScholarGoogle Scholar
  54. Henry Gordon Rice. 1953. Classes of recursively enumerable sets and their decision problems. Transactions of the American Mathematical society, 74, 2 (1953), 358–366. Google ScholarGoogle ScholarCross RefCross Ref
  55. Enric Rodríguez-Carbonell. 2018. Some programs that need polynomial invariants in order to be verified. https://www.cs.upc.edu/ erodri/webpage/polynomial_invariants/list.html Google ScholarGoogle Scholar
  56. Sriram Sankaranarayanan, Henny B Sipma, and Zohar Manna. 2004. Constraint-based linear-relations analysis. In SAS. 53–68. Google ScholarGoogle Scholar
  57. Sriram Sankaranarayanan, Henny B Sipma, and Zohar Manna. 2004. Non-linear loop invariant generation using Gröbner bases. In POPL. 318–329. Google ScholarGoogle Scholar
  58. David E Shaw, William R Swartout, and C Cordell Green. 1975. Inferring LISP Programs From Examples. In IJCAI. 260–267. Google ScholarGoogle Scholar
  59. Xujie Si, Woosuk Lee, Richard Zhang, Aws Albarghouthi, Paraschos Koutris, and Mayur Naik. 2018. Syntax-guided synthesis of datalog programs. In ESEC/FSE. 515–527. Google ScholarGoogle Scholar
  60. David Canfield Smith. 1975. Pygmalion: a creative programming environment. Stanford University. Google ScholarGoogle Scholar
  61. Dominik Sobania, Dirk Schweim, and Franz Rothlauf. 2022. A Comprehensive Survey on Program Synthesis with Evolutionary Algorithms. IEEE Transactions on Evolutionary Computation. Google ScholarGoogle Scholar
  62. Armando Solar-Lezama. 2008. Program synthesis by sketching. University of California, Berkeley. Google ScholarGoogle ScholarDigital LibraryDigital Library
  63. Armando Solar-Lezama. 2009. The sketching approach to program synthesis. In APLAS. 4–13. Google ScholarGoogle Scholar
  64. Saurabh Srivastava, Sumit Gulwani, and Jeffrey S Foster. 2010. From program verification to program synthesis. In POPL. 313–326. Google ScholarGoogle Scholar
  65. Saurabh Srivastava, Sumit Gulwani, and Jeffrey S Foster. 2013. Template-based program verification and program synthesis. International Journal on Software Tools for Technology Transfer, 15, 5 (2013), 497–518. Google ScholarGoogle ScholarDigital LibraryDigital Library
  66. Toru Takisaka, Yuichiro Oyabu, Natsuki Urabe, and Ichiro Hasuo. 2018. Ranking and repulsing supermartingales for reachability in probabilistic programs. In ATVA. 476–493. Google ScholarGoogle Scholar
  67. Emina Torlak and Rastislav Bodík. 2014. A lightweight symbolic virtual machine for solver-aided host languages. In PLDI. 530–541. Google ScholarGoogle Scholar
  68. Anne S Troelstra. 1977. Aspects of constructive mathematics. In Studies in Logic and the Foundations of Mathematics. 90, 973–1052. Google ScholarGoogle ScholarCross RefCross Ref
  69. Jinyi Wang, Yican Sun, Hongfei Fu, Krishnendu Chatterjee, and Amir Kafshdar Goharshady. 2021. Quantitative analysis of assertion violations in probabilistic programs. In PLDI. 1171–1186. Google ScholarGoogle Scholar
  70. Peixin Wang, Hongfei Fu, Amir Kafshdar Goharshady, Krishnendu Chatterjee, Xudong Qin, and Wenjun Shi. 2019. Cost analysis of nondeterministic probabilistic programs. In PLDI. 204–220. Google ScholarGoogle Scholar
  71. David S Watkins. 2004. Fundamentals of matrix computations. 64, John Wiley & Sons. Google ScholarGoogle Scholar

Index Terms

  1. Algebro-geometric Algorithms for Template-Based Synthesis of Polynomial 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

        • Article Metrics

          • Downloads (Last 12 months)126
          • Downloads (Last 6 weeks)54

          Other Metrics

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!