Functorial Semantics as a Unifying Perspective on Logic Programming

Authors Tao Gu, Fabio Zanasi

Thumbnail PDF


  • Filesize: 0.94 MB
  • 22 pages

Document Identifiers

Author Details

Tao Gu
  • University College London, UK
Fabio Zanasi
  • University College London, UK

Cite AsGet BibTex

Tao Gu and Fabio Zanasi. Functorial Semantics as a Unifying Perspective on Logic Programming. In 9th Conference on Algebra and Coalgebra in Computer Science (CALCO 2021). Leibniz International Proceedings in Informatics (LIPIcs), Volume 211, pp. 17:1-17:22, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2021)


Logic programming and its variations are widely used for formal reasoning in various areas of Computer Science, most notably Artificial Intelligence. In this paper we develop a systematic and unifying perspective for (ground) classical, probabilistic, weighted logic programs, based on categorical algebra. Our departure point is a formal distinction between the syntax and the semantics of programs, now regarded as separate categories. Then, we are able to characterise the various variants of logic program as different models for the same syntax category, i.e. structure-preserving functors in the spirit of Lawvere’s functorial semantics. As a first consequence of our approach, we showcase a series of semantic constructs for logic programming pictorially as certain string diagrams in the syntax category. Secondly, we describe the correspondence between probabilistic logic programs and Bayesian networks in terms of the associated models. Our analysis reveals that the correspondence can be phrased in purely syntactical terms, without resorting to the probabilistic domain of interpretation.

Subject Classification

ACM Subject Classification
  • Theory of computation → Categorical semantics
  • string diagrams
  • functorial semantics
  • logic programming


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Samson Abramsky. Abstract scalars, loops, and free traced and strongly compact closed categories. In Algebra and Coalgebra in Computer Science: First International Conference, CALCO 2005, Swansea, UK, September 3-6, 2005, Proceedings, volume 3629, October 2009. URL:
  2. Joyal Andre, Ross Street, and Dominic Verity. Traced monoidal categories. Mathematical Proceedings of the Cambridge Philosophical Society, 119:447-468, April 1996. URL:
  3. Krzysztof R Apt, Howard A Blair, and Adrian Walker. Towards a theory of declarative knowledge. In Foundations of deductive databases and logic programming, pages 89-148. Elsevier, 1988. Google Scholar
  4. Samuel Balco and Alexander Kurz. Nominal string diagrams. In Markus Roggenbach and Ana Sokolova, editors, 8th Conference on Algebra and Coalgebra in Computer Science, CALCO 2019, June 3-6, 2019, London, United Kingdom, volume 139 of LIPIcs, pages 18:1-18:20. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2019. URL:
  5. Elena Bellodi, Marco Alberti, Fabrizio Riguzzi, and Riccardo Zese. Map inference for probabilistic logic programming. Theory and Practice of Logic Programming, 20(5):641-655, 2020. Google Scholar
  6. Filippo Bonchi and Fabio Zanasi. Saturated semantics for coalgebraic logic programming. In Algebra and Coalgebra in Computer Science - 5th International Conference, CALCO 2013, Warsaw, Poland, September 3-6, 2013. Proceedings, pages 80-94, 2013. URL:
  7. Filippo Bonchi and Fabio Zanasi. Bialgebraic semantics for logic programming. Logical Methods in Computer Science, 11(1), 2015. URL:
  8. Ivan Bratko. Prolog programming for artificial intelligence. Pearson education, 2001. Google Scholar
  9. Stefano Ceri, Georg Gottlob, and Letizia Tanca. Logic programming and databases. Springer Science & Business Media, 2012. Google Scholar
  10. Shay Cohen, Robert Simmons, and Noah Smith. Products of weighted logic programs. Computing Research Repository - CORR, 11, June 2010. URL:
  11. Jared Culbertson and Kirk Sturtz. A categorical foundation for bayesian probability. Applied Categorical Structures, 22(4):647-662, August 2013. URL:
  12. Eduardo Menezes de Morais and Marcelo Finger. Probabilistic answer set programming. In 2013 Brazilian Conference on Intelligent Systems, pages 150-156. IEEE, 2013. Google Scholar
  13. Luc De Raedt, Angelika Kimmig, and Hannu Toivonen. Problog: A probabilistic prolog and its application in link discovery. In Proceedings of the 20th International Joint Conference on Artifical Intelligence, IJCAI'07, pages 2468-2473, San Francisco, CA, USA, 2007. Morgan Kaufmann Publishers Inc. URL:
  14. Didier Dubois, Lluas Godo, and Henri Prade. Weighted logics for artificial intelligence : an introductory discussion. International Journal of Approximate Reasoning, 55(9):1819-1829, 2014. Weighted Logics for Artificial Intelligence. URL:
  15. Jason Eisner and John Blatz. Program transformations for optimization of parsing algorithms and other weighted logic programs. In Shuly Wintner, editor, Proceedings of FG 2006: The 11th Conference on Formal Grammar, pages 45-85. CSLI Publications, 2007. URL:
  16. Brendan Fong. Causal theories: A categorical perspective on bayesian networks. 2013. URL:
  17. Michael Gelfond. On stratified autoepistemic theories. In AAAI, volume 87, pages 207-211, 1987. Google Scholar
  18. Michael Gelfond and Vladimir Lifschitz. The stable model semantics for logic programming. In ICLP/SLP, volume 88, pages 1070-1080, 1988. Google Scholar
  19. Tao Gu and Fabio Zanasi. Coalgebraic Semantics for Probabilistic Logic Programming. Logical Methods in Computer Science, Volume 17, Issue 2, April 2021. URL:
  20. Gopal Gupta, Ajay Bansal, Richard Min, Luke Simon, and Ajay Mallya. Coinductive logic programming and its applications. In Véronica Dahl and Ilkka Niemelä, editors, Logic Programming, pages 27-44, Berlin, Heidelberg, 2007. Springer Berlin Heidelberg. Google Scholar
  21. Bart Jacobs. A channel-based exact inference algorithm for bayesian networks. CoRR, abs/1804.08032, 2018. URL:
  22. Bart Jacobs, Aleks Kissinger, and Fabio Zanasi. Causal inference by string diagram surgery. In Mikołaj Bojańczyk and Alex Simpson, editors, Foundations of Software Science and Computation Structures, pages 313-329, Cham, 2019. Springer International Publishing. Google Scholar
  23. Bart Jacobs and Fabio Zanasi. A predicate/state transformer semantics for bayesian learning. Electronic Notes in Theoretical Computer Science, 325:185-200, 2016. The Thirty-second Conference on the Mathematical Foundations of Programming Semantics (MFPS XXXII). URL:
  24. Bart Jacobs and Fabio Zanasi. A Formal Semantics of Influence in Bayesian Reasoning. In Kim G. Larsen, Hans L. Bodlaender, and Jean-Francois Raskin, editors, 42nd International Symposium on Mathematical Foundations of Computer Science (MFCS 2017), volume 83 of Leibniz International Proceedings in Informatics (LIPIcs), pages 21:1-21:14, Dagstuhl, Germany, 2017. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik. URL:
  25. Bart Jacobs and Fabio Zanasi. The logical essentials of bayesian reasoning. arXiv preprint arXiv:1804.01193, 2018. Google Scholar
  26. Ekaterina Komendantskaya and John Power. Coalgebraic semantics for derivations in logic programming. In Algebra and Coalgebra in Computer Science - 4th International Conference, CALCO 2011, Winchester, UK, August 30 - September 2, 2011. Proceedings, pages 268-282, 2011. URL:
  27. Ekaterina Komendantskaya and John Power. Logic programming: Laxness and saturation. J. Log. Algebraic Methods Program., 101:1-21, 2018. URL:
  28. Ekaterina Komendantskaya, John Power, and Martin Schmidt. Coalgebraic logic programming: from semantics to implementation. J. Log. Comput., 26(2):745-783, 2016. URL:
  29. F William Lawvere. Functorial semantics of algebraic theories. Proceedings of the National Academy of Sciences of the United States of America, 50(5):869, 1963. Google Scholar
  30. Vladimir Lifschitz. On the declarative semantics of logic programs with negation. In Foundations of deductive databases and logic programming, pages 177-192. Elsevier, 1988. Google Scholar
  31. Wannes Meert, Jan Struyf, and Hendrik Blockeel. Learning ground cp-logic theories by leveraging bayesian network learning techniques. Fundam. Inform., 89:131-160, January 2008. Google Scholar
  32. Stephen Muggleton and Luc de Raedt. Inductive logic programming: Theory and methods. The Journal of Logic Programming, 19-20:629-679, 1994. Special Issue: Ten Years of Logic Programming. URL:
  33. Ulf Nilsson and Jan Małuszyński. Logic, programming and Prolog. Wiley Chichester, 1990. Google Scholar
  34. Judea Pearl. Causality. Cambridge university press, 2009. Google Scholar
  35. Taisuke Sato. A statistical learning method for logic programs with distribution semantics. In Logic Programming, Proceedings of the Twelfth International Conference on Logic Programming, Tokyo, Japan, June 13-16, 1995, pages 715-729, 1995. Google Scholar
  36. Taisuke Sato and Yoshitaka Kameya. New advances in logic-based probabilistic modeling by prism. In Probabilistic inductive logic programming, pages 118-155. Springer, 2008. Google Scholar
  37. P. Selinger. A Survey of Graphical Languages for Monoidal Categories, pages 289-355. Springer Berlin Heidelberg, Berlin, Heidelberg, 2011. URL:
  38. Allen Van Gelder, Kenneth A Ross, and John S Schlipf. The well-founded semantics for general logic programs. Journal of the ACM (JACM), 38(3):619-649, 1991. Google Scholar
  39. Joost Vennekens, Marc Denecker, and Maurice Bruynooghe. Representing causal information about a probabilistic process. In Michael Fisher, Wiebe van der Hoek, Boris Konev, and Alexei Lisitsa, editors, Logics in Artificial Intelligence, pages 452-464, Berlin, Heidelberg, 2006. Springer Berlin Heidelberg. Google Scholar
  40. Joost Vennekens, Sofie Verbaeten, and Maurice Bruynooghe. Logic programs with annotated disjunctions. In Logic Programming, pages 431-445, Berlin, Heidelberg, 2004. Springer Berlin Heidelberg. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail