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.
- Samson Abramsky. 1994. Handbook of Logic in Computer Science. 3, Clarendon Press. http://www.cs.bham.ac.uk/~axj/papers.htmlGoogle Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
- Christel Baier and Joost-Pieter Katoen. 2008. Principles of Model Checking. MIT Press.Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- Stefano Bistarelli, Ugo Montanari, and Francesca Rossi. 1997. Semiring-based Constraint Logic Programming. In IJCAI (1). Morgan Kaufmann, 352–357.Google Scholar
- Allan Borodin and Ran El-Yaniv. 1998. Online Computation and Competitive Analysis. Cambridge University Press.Google Scholar
Digital Library
- 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 Scholar
Digital Library
- Quentin Carbonneaux. 2018. Modular and certified resource-bound analyses. Ph. D. Dissertation. Yale University.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Brunella Gerla. 2003. Many-valued logic and semirings. Neural Network World, 13 (2003), 01.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- Jeff Horen. 1985. Linear Programming. Networks, 15, 2 (1985), 273–274. https://doi.org/10.1002/net.3230150211 Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- Claire Jones. 1990. Probabilistic Non-Determinism. Ph. D. Dissertation. University of Edinburgh, UK.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Dennis Komm. 2016. An Introduction to Online Computation - Determinism, Randomization, Advice. Springer. https://doi.org/10.1007/978-3-319-42749-2 Google Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Matilde Marcolli and Ryan Thorngren. 2011. Thermodynamic Semirings. CoRR, abs/1108.2874 (2011), https://doi.org/10.48550/arXiv.1108.2874Google Scholar
- 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 Scholar
Cross Ref
- Annabelle McIver and Carroll Morgan. 2005. Abstraction, Refinement and Proof for Probabilistic Systems. Springer. https://doi.org/10.1007/b138392 Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- Russel O’Conner. 2012. A Very General Method of Computing Shortest Paths. Personal blog entry. http://r6.ca/blog/20110808T035622Z.htmlGoogle Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- Marc Pouly. 2010. Semirings for Breakfast. https://marcpouly.ch/pdf/internal_100712.pdf Visited on 2022-03-21.Google Scholar
- 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 Scholar
Cross Ref
- Alexander Schrijver. 1999. Theory of Linear and Integer Programming. Wiley.Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Günther J. Wirsching, Markus Huber, and Christian Kölbl. 2010. The confidence-probability semiring. Fakultät für Angewandte Informatik.Google Scholar
- Linpeng Zhang and Benjamin Lucien Kaminski. 2022. Quantitative Strongest Post. CoRR, abs/2202.06765 (2022), https://doi.org/10.48550/arXiv.2202.06765Google Scholar
- Linpeng Zhang and Benjamin Lucien Kaminski. 2022. Quantitative Strongest Post. PACMPL, https://doi.org/10.1145/3527331 To appear Google Scholar
Digital Library
Index Terms
Weighted programming: a programming paradigm for specifying mathematical models
Recommendations
A Domain-Theoretic Model Of Nominally-Typed Object-Oriented Programming
The majority of contemporary mainstream object-oriented (OO) software is written using nominally-typed OO programming languages. Extant domain-theoretic models of OOP developed to analyze OO type systems miss crucial features of these mainstream OO ...






Comments