skip to main content
research-article
Open Access

Weighted programming: a programming paradigm for specifying mathematical models

Published:29 April 2022Publication History
Skip Abstract Section

Abstract

We study weighted programming, a programming paradigm for specifying mathematical models. More specifically, the weighted programs we investigate are like usual imperative programs with two additional features: (1) nondeterministic branching and (2) weighting execution traces. Weights can be numbers but also other objects like words from an alphabet, polynomials, formal power series, or cardinal numbers. We argue that weighted programming as a paradigm can be used to specify mathematical models beyond probability distributions (as is done in probabilistic programming). We develop weakest-precondition- and weakest-liberal-precondition-style calculi à la Dijkstra for reasoning about mathematical models specified by weighted programs. We present several case studies. For instance, we use weighted programming to model the ski rental problem — an optimization problem. We model not only the optimization problem itself, but also the best deterministic online algorithm for solving this problem as weighted programs. By means of weakest-precondition-style reasoning, we can determine the competitive ratio of the online algorithm on source code level.

References

  1. Samson Abramsky. 1994. Handbook of Logic in Computer Science. 3, Clarendon Press. http://www.cs.bham.ac.uk/~axj/papers.htmlGoogle ScholarGoogle Scholar
  2. Alejandro Aguirre and Shin-ya Katsumata. 2020. Weakest Preconditions in Fibrations. In MFPS (Electronic Notes in Theoretical Computer Science, Vol. 352). Elsevier, 5–27. https://doi.org/10.1016/j.entcs.2020.09.002 Google ScholarGoogle ScholarCross RefCross Ref
  3. Rajeev Alur, Rastislav Bodík, Eric Dallal, Dana Fisman, Pranav Garg, Garvit Juniwal, Hadas Kress-Gazit, P. Madhusudan, Milo M. K. Martin, Mukund Raghothaman, Shambwaditya Saha, Sanjit A. Seshia, Rishabh Singh, Armando Solar-Lezama, Emina Torlak, and Abhishek Udupa. 2015. Syntax-Guided Synthesis. In Dependable Software Systems Engineering (NATO Science for Peace and Security Series, D: Information and Communication Security, Vol. 40). IOS Press, 1–25. https://doi.org/10.3233/978-1-61499-495-4-1 Google ScholarGoogle ScholarCross RefCross Ref
  4. Benjamin Aminof, Orna Kupferman, and Robby Lampert. 2009. Reasoning About Online Algorithms with Weighted Automata. In SODA. SIAM, 835–844. https://doi.org/10.1137/1.9781611973068.91 Google ScholarGoogle ScholarCross RefCross Ref
  5. Benjamin Aminof, Orna Kupferman, and Robby Lampert. 2010. Reasoning about Online algorithms with Weighted Automata. ACM Trans. Algorithms, 6, 2 (2010), 28:1–28:36. https://doi.org/10.1145/1721837.1721844 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Ralph-Johan Back and Joakim von Wright. 1998. Refinement Calculus - A Systematic Introduction. Springer. https://doi.org/10.1007/978-1-4612-1674-2 Google ScholarGoogle ScholarCross RefCross Ref
  7. Marc Bagnol. 2014. On the Resolution Semiring. (Sur le Semi-anneau de Résolution). Ph. D. Dissertation. Aix-Marseille University, Aix-en-Provence, France.Google ScholarGoogle Scholar
  8. Christel Baier and Joost-Pieter Katoen. 2008. Principles of Model Checking. MIT Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Esma Balkir, Daniel Gildea, and Shay B. Cohen. 2020. Tensors over Semirings for Latent-Variable Weighted Logic Programs. In IWPT 2020. Association for Computational Linguistics, 73–90. https://doi.org/10.18653/v1/2020.iwpt-1.8 Google ScholarGoogle ScholarCross RefCross Ref
  10. Kevin Batz, Mingshuai Chen, Benjamin Lucien Kaminski, Joost-Pieter Katoen, Christoph Matheja, and Philipp Schröer. 2021. Latticed k-Induction with an Application to Probabilistic Programs. In CAV (2) (Lecture Notes in Computer Science, Vol. 12760). Springer, 524–549. https://doi.org/10.1007/978-3-030-81688-9_25 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Kevin Batz, Adrian Gallus, Benjamin Lucien Kaminski, Joost-Pieter Katoen, and Tobias Winkler. 2022. Weighted Programming. CoRR, abs/2202.07577 (2022), https://doi.org/10.48550/arXiv.2202.07577Google ScholarGoogle Scholar
  12. Kevin Batz, Benjamin Lucien Kaminski, Joost-Pieter Katoen, Christoph Matheja, and Thomas Noll. 2019. Quantitative separation logic: a logic for reasoning about probabilistic pointer programs. Proc. ACM Program. Lang., 3, POPL (2019), 34:1–34:29. https://doi.org/10.1145/3290347 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Vaishak Belle and Luc De Raedt. 2020. Semiring Programming: A Semantic Framework for Generalized Sum Product problems. Int. J. Approx. Reason., 126 (2020), 181–201. https://doi.org/10.1016/j.ijar.2020.08.001 Google ScholarGoogle ScholarCross RefCross Ref
  14. Stefano Bistarelli, Ugo Montanari, and Francesca Rossi. 1997. Semiring-based Constraint Logic Programming. In IJCAI (1). Morgan Kaufmann, 352–357.Google ScholarGoogle Scholar
  15. Allan Borodin and Ran El-Yaniv. 1998. Online Computation and Competitive Analysis. Cambridge University Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Aloïs Brunel, Marco Gaboardi, Damiano Mazza, and Steve Zdancewic. 2014. A Core Quantitative Coeffect Calculus. In ESOP (Lecture Notes in Computer Science, Vol. 8410). Springer, 351–370. https://doi.org/10.1007/978-3-642-54833-8_19 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Quentin Carbonneaux. 2018. Modular and certified resource-bound analyses. Ph. D. Dissertation. Yale University.Google ScholarGoogle Scholar
  18. Quentin Carbonneaux, Jan Hoffmann, and Zhong Shao. 2015. Compositional certified resource bounds. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation, Portland, OR, USA, June 15-17, 2015, David Grove and Stephen M. Blackburn (Eds.). ACM, 467–478. https://doi.org/10.1145/2737924.2737955 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Shay B. Cohen, Robert J. Simmons, and Noah A. Smith. 2008. Dynamic Programming Algorithms as Products of Weighted Logic Programs. In ICLP (Lecture Notes in Computer Science, Vol. 5366). Springer, 114–129. https://doi.org/10.1007/978-3-540-89982-2_18 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Katrin M. Dannert, Erich Grädel, Matthias Naaf, and Val Tannen. 2019. Generalized Absorptive Polynomials and Provenance Semantics for Fixed-Point Logic. CoRR, abs/1910.07910 (2019), https://doi.org/10.48550/arXiv.1910.07910Google ScholarGoogle Scholar
  21. Edsger Wybe Dijkstra. 1975. Guarded Commands, Nondeterminacy and Formal Derivation of Programs. CACM, 18, 8 (1975), 453–457. https://doi.org/10.1145/360933.360975 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Stephen Dolan. 2013. Fun with Semirings: A Functional Pearl on the Abuse of Linear Algebra. In ICFP. ACM, 101–110. https://doi.org/10.1145/2500365.2500613 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Manfred Droste, Werner Kuich, and Heiko Vogler. 2009. Handbook of Weighted Automata (1st ed.). Springer Publishing Company, Incorporated. https://doi.org/10.1007/978-3-642-01492-5 Google ScholarGoogle ScholarCross RefCross Ref
  24. 1998. Online Algorithms, The State of the Art, Amos Fiat and Gerhard J. Woeginger (Eds.) (Lecture Notes in Computer Science, Vol. 1442). Springer. https://doi.org/10.1007/BFb0029561 the book grow out of a Dagstuhl Seminar, June 1996 Google ScholarGoogle ScholarCross RefCross Ref
  25. Marco Gaboardi, Shin-ya Katsumata, Dominic Orchard, and Tetsuya Sato. 2021. Graded Hoare Logic and its Categorical Semantics. In Programming Languages and Systems - 30th European Symposium on Programming, ESOP 2021, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2021, Luxembourg City, Luxembourg, March 27 - April 1, 2021, Proceedings, Nobuko Yoshida (Ed.) (Lecture Notes in Computer Science, Vol. 12648). Springer, 234–263. https://doi.org/10.1007/978-3-030-72019-3_9 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Martin Gavalec, Zuzana Nemcova, and Sergei Sergeev. 2015. Tropical linear algebra with the Ł ukasiewicz T-norm. Fuzzy Sets Syst., 276 (2015), 131–148. https://doi.org/10.1016/j.fss.2014.11.008 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Brunella Gerla. 2003. Many-valued logic and semirings. Neural Network World, 13 (2003), 01.Google ScholarGoogle Scholar
  28. Dan R. Ghica and Alex I. Smith. 2014. Bounded Linear Types in a Resource Semiring. In Programming Languages and Systems - 23rd European Symposium on Programming, ESOP 2014, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2014, Grenoble, France, April 5-13, 2014, Proceedings, Zhong Shao (Ed.) (Lecture Notes in Computer Science, Vol. 8410). Springer, 331–350. https://doi.org/10.1007/978-3-642-54833-8_18 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Leandro Gomes, Alexandre Madeira, and Luís Soares Barbosa. 2019. Generalising KAT to Verify Weighted Computations. Sci. Ann. Comput. Sci., 29, 2 (2019), 141–184. https://doi.org/10.7561/sacs.2019.2.141 Google ScholarGoogle ScholarCross RefCross Ref
  30. Andrew D. Gordon, Thomas A. Henzinger, Aditya V. Nori, and Sriram K. Rajamani. 2014. Probabilistic Programming. In FOSE. ACM, 167–181. https://doi.org/10.1145/2593882.2593900 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Wataru Hino, Hiroki Kobayashi, Ichiro Hasuo, and Bart Jacobs. 2016. Healthiness from Duality. In LICS. ACM, 682–691. https://doi.org/10.1145/2933575.2935319 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. C. A. R. Hoare. 1978. Some Properties of Predicate Transformers. J. ACM, 25, 3 (1978), 461–480. https://doi.org/10.1007/978-1-4612-3228-5_6 Google ScholarGoogle ScholarCross RefCross Ref
  33. Jeff Horen. 1985. Linear Programming. Networks, 15, 2 (1985), 273–274. https://doi.org/10.1002/net.3230150211 Google ScholarGoogle ScholarCross RefCross Ref
  34. Samin S. Ishtiaq and Peter W. O’Hearn. 2001. BI as an Assertion Language for Mutable Data Structures. In POPL. ACM, 14–26. https://doi.org/10.1145/360204.375719 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Claire Jones. 1990. Probabilistic Non-Determinism. Ph. D. Dissertation. University of Edinburgh, UK.Google ScholarGoogle Scholar
  36. Benjamin Lucien Kaminski. 2019. Advanced Weakest Precondition Calculi for Probabilistic Programs. Ph. D. Dissertation. RWTH Aachen University, Germany. https://doi.org/10.18154/RWTH-2019-01829 Google ScholarGoogle ScholarCross RefCross Ref
  37. Klaus Keimel. 2015. Healthiness Conditions for Predicate Transformers. In MFPS (Electronic Notes in Theoretical Computer Science, Vol. 319). Elsevier, 255–270. https://doi.org/10.1016/j.entcs.2015.12.016 Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Dennis Komm. 2016. An Introduction to Online Computation - Determinism, Randomization, Advice. Springer. https://doi.org/10.1007/978-3-319-42749-2 Google ScholarGoogle ScholarCross RefCross Ref
  39. Dexter Kozen. 1985. A Probabilistic PDL. J. Comput. Syst. Sci., 30, 2 (1985), 162–178. https://doi.org/10.1016/0022-0000(85)90012-1 Google ScholarGoogle ScholarCross RefCross Ref
  40. Dexter Kozen. 1999. On Hoare Logic and Kleene Algebra with Tests. In LICS. IEEE Computer Society, 167–172. https://doi.org/10.1109/lics.1999.782610 Google ScholarGoogle ScholarCross RefCross Ref
  41. Dexter Kozen. 2000. On Hoare Logic and Kleene Algebra with Tests. ACM Trans. Comput. Log., 1, 1 (2000), 60–76. https://doi.org/10.1145/343369.343378 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Jim Laird, Giulio Manzonetto, Guy McCusker, and Michele Pagani. 2013. Weighted Relational Models of Typed Lambda-Calculi. In LICS. IEEE Computer Society, 301–310. https://doi.org/10.1109/lics.2013.36 Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Johan Lofberg. 2004. YALMIP: A Toolbox for Modeling and Optimization in MATLAB. 2004 IEEE International Conference on Robotics and Automation (IEEE Cat. No.04CH37508), 284–289. https://doi.org/10.1109/cacsd.2004.1393890 Google ScholarGoogle ScholarCross RefCross Ref
  44. Zohar Manna and Richard J. Waldinger. 1980. A Deductive Approach to Program Synthesis. ACM Trans. Program. Lang. Syst., 2, 1 (1980), 90–121. https://doi.org/10.1145/357084.357090 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Matilde Marcolli and Ryan Thorngren. 2011. Thermodynamic Semirings. CoRR, abs/1108.2874 (2011), https://doi.org/10.48550/arXiv.1108.2874Google ScholarGoogle Scholar
  46. Matilde Marcolli and Ryan Thorngren. 2014. Thermodynamic semirings. Journal of Noncommutative Geometry, 8, 2 (2014), 337–392. https://doi.org/10.4171/jncg/159 Google ScholarGoogle ScholarCross RefCross Ref
  47. Annabelle McIver and Carroll Morgan. 2005. Abstraction, Refinement and Proof for Probabilistic Systems. Springer. https://doi.org/10.1007/b138392 Google ScholarGoogle ScholarCross RefCross Ref
  48. Carroll Morgan, Annabelle McIver, and Karen Seidel. 1996. Probabilistic Predicate Transformers. ACM Trans. Program. Lang. Syst., 18, 3 (1996), 325–353. https://doi.org/10.1145/229542.229547 Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Nicholas Nethercote, Peter J. Stuckey, Ralph Becket, Sebastian Brand, Gregory J. Duck, and Guido Tack. 2007. MiniZinc: Towards a Standard CP Modelling Language. In CP (Lecture Notes in Computer Science, Vol. 4741). Springer, 529–543. https://doi.org/10.1007/978-3-540-74970-7_38 Google ScholarGoogle ScholarCross RefCross Ref
  50. Antonio Nola and Brunella Gerla. 2005. Algebras of Lukasiewicz’s logic and their semiring reducts. Contemp. Math, 377 (2005), 01, isbn:9780821835388 https://doi.org/10.1090/conm/377/06988 Google ScholarGoogle ScholarCross RefCross Ref
  51. Russel O’Conner. 2012. A Very General Method of Computing Shortest Paths. Personal blog entry. http://r6.ca/blog/20110808T035622Z.htmlGoogle ScholarGoogle Scholar
  52. Tomas Petricek, Dominic A. Orchard, and Alan Mycroft. 2014. Coeffects: a calculus of context-dependent computation. In Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, Gothenburg, Sweden, September 1-3, 2014, Johan Jeuring and Manuel M. T. Chakravarty (Eds.). ACM, 123–135. https://doi.org/10.1145/2628136.2628160 Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Gordon D. Plotkin. 2004. A Structural Approach to Operational Semantics. The Journal of Logic and Algebraic Programming, 60-61 (2004), 17–139. https://doi.org/10.1016/j.jlap.2004.05.001 Google ScholarGoogle ScholarCross RefCross Ref
  54. Marc Pouly. 2010. Semirings for Breakfast. https://marcpouly.ch/pdf/internal_100712.pdf Visited on 2022-03-21.Google ScholarGoogle Scholar
  55. John C. Reynolds. 2002. Separation Logic: A Logic for Shared Mutable Data Structures. In LICS. IEEE Computer Society, 55–74. https://doi.org/10.1109/lics.2002.1029817 Google ScholarGoogle ScholarCross RefCross Ref
  56. Alexander Schrijver. 1999. Theory of Linear and Integer Programming. Wiley.Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. Mary Sheeran, Satnam Singh, and Gunnar Stålmarck. 2000. Checking Safety Properties Using Induction and a SAT-Solver. In FMCAD (Lecture Notes in Computer Science, Vol. 1954). Springer, 108–125. https://doi.org/doi.org/10.1007/3-540-40922-x_8 Google ScholarGoogle ScholarCross RefCross Ref
  58. Richard Sproat, Mahsa Yarmohammadi, Izhak Shafran, and Brian Roark. 2014. Applications of Lexicographic Semirings to Problems in Speech and Language Processing. Comput. Linguistics, 40, 4 (2014), 733–761. https://doi.org/10.1162/coli_a_00198 Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. Wouter Swierstra and Tim Baanen. 2019. A Predicate Transformer Semantics for Effects (functional pearl). Proc. ACM Program. Lang., 3, ICFP (2019), 103:1–103:26. https://doi.org/10.1145/3341707 Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. Robert Endre Tarjan. 1985. Amortized computational complexity. SIAM Journal on Algebraic Discrete Methods, 6, 2 (1985), 306–318. https://doi.org/10.1137/0606031 Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. Günther J. Wirsching, Markus Huber, and Christian Kölbl. 2010. The confidence-probability semiring. Fakultät für Angewandte Informatik.Google ScholarGoogle Scholar
  62. Linpeng Zhang and Benjamin Lucien Kaminski. 2022. Quantitative Strongest Post. CoRR, abs/2202.06765 (2022), https://doi.org/10.48550/arXiv.2202.06765Google ScholarGoogle Scholar
  63. Linpeng Zhang and Benjamin Lucien Kaminski. 2022. Quantitative Strongest Post. PACMPL, https://doi.org/10.1145/3527331 To appear Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Weighted programming: a programming paradigm for specifying mathematical models

            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

            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!