<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Teaching Prolog and Logic Programming with Jupyter Notebooks</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Galileo Sartor</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Adam Wyner</string-name>
        </contrib>
      </contrib-group>
      <pub-date>
        <year>2025</year>
      </pub-date>
      <abstract>
        <p>This short paper presents the use of a JupyterHub server to teach Prolog and Logic Programming in the context of a University course in Artificial Intelligence. The server is used to simplify how student exercises are distributed, collected, accessed, and automatically assessed. The server allows the opportunity to provide a standardized environment for students to test their code. With the right mix of addons and extensions, it can be used to explore graphical web applications built with Prolog as the backend. The paper discusses the context of the course, the implementation of the server, and how it was used to teach Prolog and Logic Programming in an interactive way.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Prolog</kwd>
        <kwd>Logic Programming</kwd>
        <kwd>Jupyter</kwd>
        <kwd>Artificial Intelligence</kwd>
        <kwd>Education</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
    </sec>
    <sec id="sec-2">
      <title>2. Prior Work</title>
      <p>
        There is a substantial body of literature on teaching Prolog and logic programming, reflecting decades
of experience in both computer science and artificial intelligence curricula. Early work by Clocksin
and Mellish [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] established Prolog as a language suitable for introducing declarative programming
concepts. Prolog has been used to teach logic programming principles, problem-solving techniques,
and the foundations of artificial intelligence [
        <xref ref-type="bibr" rid="ref2 ref3">2, 3</xref>
        ]. Subsequent studies have explored pedagogical
strategies, such as using visualizations [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], interactive environments [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], and problem-based learning [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]
to enhance student engagement and comprehension.
      </p>
      <p>
        Several textbooks and course designs emphasize the importance of relating logic programming to
familiar computational paradigms, while also highlighting its unique features, such as unification and
backtracking [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. More recent approaches leverage other systems to build interactive programs based
on Prolog [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], using web-based tools and notebooks to lower the barrier to entry and provide immediate
feedback and test-driven learning. Examples of this are the Ciao Prolog Playground [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], SWISH [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], and
GUPU [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]. Focusing more specifically on teaching AI, there are several online resources [
        <xref ref-type="bibr" rid="ref10 ref9">9, 10, 11</xref>
        ].
      </p>
      <p>
        Despite these advances, challenges remain in helping students to add declarative thinking to their
computational thinking as an addition to imperative programming. In addition, there are challenges in
designing assessments that accurately capture such conceptual understanding [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ].
      </p>
      <p>Overall, the literature suggests that efective teaching of Prolog benefits from a combination of
interactive tools, carefully chosen examples, and explicit connections to broader themes in computer
science and artificial intelligence.</p>
      <p>In the world of Generative AI, it is important to teach Prolog in a way that highlights its strengths in
reasoning and knowledge representation, especially as these concepts become increasingly relevant
in AI applications in diferent domains such as the law [ 12] and the arts [13]. It is also worthwhile
considering its potential interaction with the new generative systems [14, 15].</p>
      <p>
        Recent work has highlighted the importance of integrating logic programming with contemporary AI
topics, including explainable AI and knowledge representation [
        <xref ref-type="bibr" rid="ref7">15, 7</xref>
        ]. These connections help students
appreciate the relevance of logic programming in modern AI systems and foster a deeper understanding
of foundational concepts.
      </p>
    </sec>
    <sec id="sec-3">
      <title>3. Context</title>
      <p>The course in which we decided to embed and test the JupyterHub Server is a course in Artificial
Intelligence, in the second year of the Bachelor in Computer Science at Swansea University. In the course,
the students are introduced to the basic concepts of symbolic AI, with a focus on Logic Programming. The
rationale is that sub-symbolic approaches (machine learning) and data science are taught elsewhere in
the curriculum, while the mathematical underpinnings, particularly logic, are largely not operationalised.
In our view, logic is an essential component of computational thinking. Moreover, the knowledge and
skills taught under the rubric of symbolic AI such as search methods, knowledge representation and
reasoning, syntactic and semantic parsing, planning, and causal reasoning have been and will continue
to be invaluable. This is particularly so where one is an analyst, designer, and evaluator with respect to
some new problem. It is preferable to have a diversity of tools in one’s computational toolbox, which
are appropriate to the problem at hand and integrated with other tools for an overall solution. In this,
teaching symbolic AI using Prolog contributes to so called neuro-symbolic AI.</p>
      <p>Most students have already been exposed previously to a short introduction to declarative
programming (including Prolog) in a prior module. The course is delivered with both frontal lectures and weekly
lab sessions, where students can practice the concepts introduced in the lectures with a set of tasks and
exercises provided.</p>
      <p>The initial use case of the JupyterHub server was to simplify the distribution and collection of the
exercises, giving students a simple way to access their work and submit it with continuous automated
tests to help them solve the exercises. The server also proved useful for students who wished to use
their own computer, as it allowed them to access the provided notebooks and exercises as well as their
previous work, while maintaining a standard environment. The programming environment does not
require installing anything locally, so it is easier to onboard students focusing less on installing on
diferent systems and configurations.</p>
      <p>The server is based on the work done at the University of Düsseldorf to build a Jupyter Kernel for
Prolog1, used for the course in ProB2. The version used in the course is based on SWI-Prolog, with
a server based installation using the compact Littlest JupyterHub3. The server is hosted by Swansea
University on a virtual machine with suficient resources to support the entire classes simultaneously.</p>
      <sec id="sec-3-1">
        <title>1Available at https://github.com/hhu-stups/prolog-jupyter-kernel 2Available at https://gitlab.cs.uni-duesseldorf.de/general/stups/prob-teaching-notebooks/-/tree/master/ 3Available at https://tljh.jupyter.org/en/latest</title>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Implementation and Use</title>
      <p>As mentioned in section 3, the JupyterHub server implementation is based on an existing Prolog Jupyter
Kernel. Changes were made to the server to enable the use of nbgrader4, a Jupyter extension that
allows instructors to create assignments which, once completed and submitted by the students, are
automatically graded. Automated tests are embedded within the assignments to provide immediate
feedback to students. When evaluating the student submissions there is also a custom grading option
to allow for qualitative assessment on the style/functionality of the code. The automated tests give
students immediate feedback on their work, allowing them to iterate and improve their solutions before
the final submission.</p>
      <p>Having set up the server, the next step was to create a set of notebooks that could be used in the
course. The notebooks were designed to cover the main topics of the course, including an introduction to
Prolog, to more advanced topics such as DCGs, constraint logic programming, and meta-programming
(e.g., building an expert system shell to query the user).</p>
      <p>
        Each notebook contains a mix of explanations, examples, and exercises. While this collection was
created independently, a translator script was developed to convert to/from SWISH notebooks, and
a similar tool was developed for Ciao Prolog Active Logic Documents [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. Technically notebooks
are a mixture of Prolog and Markdown text (as their Python counterparts), allowing students to read
explanations and examples, and then to write their own code in the same environment. The notebooks
can also include both visible tests that can be run to check the correctness of the code written by
the students, providing immediate feedback on their work, as well as hidden ones that are used for
evaluation after submission.
      </p>
      <sec id="sec-4-1">
        <title>4.1. Server specific configuration</title>
        <p>The server authentication was integrated with the university’s single sign-on system, allowing students
to log in using their institutional credentials. This streamlined the onboarding process and reduced
administrative overhead.</p>
        <p>SWI-Prolog was chosen as the Prolog implementation, as it is used in a course most students took
previously and was supported already by the Prolog Jupyter kernel. The Kernel itself is designed to
permit expansion with other implementations if desired.</p>
        <p>
          The server environment can be customized with pre-installed libraries, such as support for sCASP [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ]
and Logical English [16] along with tools to enhance the Prolog programming experience like Prolog
Syntax highlighting.
        </p>
        <p>Overall, the implementation focused on minimizing technical barriers for students, enabling them to
concentrate on learning Prolog and logic programming concepts. The combination of JupyterHub, the
Prolog kernel, and nbgrader created an interactive and supportive environment for both teaching and
learning.</p>
        <p>The adoption of JupyterHub with a Prolog kernel in the context of teaching logic programming
has yielded several notable outcomes and insights. The interactive nature of Jupyter notebooks
significantly lowers the entry barrier for students, especially those less familiar with command-line
interfaces or traditional Prolog environments. The ability to interleave explanatory text, code, and
immediate feedback within a single document can foster a more engaging and iterative learning process,
where the students can assess their understanding and if needed roll back to previous tasks. At the
moment there was no user study carried out, so this result is an impression from the lectures and lab
sessions, as well as discussions with students.</p>
        <p>Automated assessment through nbgrader proved useful for both students and instructors. Students
benefited from instant feedback on their solutions, which encouraged experimentation and self-directed
learning. Instructors, on the other hand, were able to eficiently manage assignments, monitor student
progress, and focus their attention on conceptual misunderstandings rather than routine grading.</p>
        <sec id="sec-4-1-1">
          <title>4Available at https://nbgrader.readthedocs.io/en/stable/</title>
        </sec>
      </sec>
      <sec id="sec-4-2">
        <title>4.2. Web Integration</title>
        <p>Part of this work was to integrate the Kernel with technologies the students were already familiar with
and to show how Prolog can be used as the engine for graphical applications, such as simple games.
For this purpose we created simple web applications that use Prolog as the backend. The first demo is
a simple Sudoku game, where one can play the game in a web browser. In this case Prolog is used to
check the validity of the user input or to solve the game. This was built with the possibility to show or
edit the Prolog code, so students could see what was driving the game validation and try changing the
rules to implement diferent variations of the game.</p>
        <p>Another goal with this sample web application was to show students how they could distribute small
Prolog programs, as they can integrate Prolog with other technologies they might be more familiar with
(HTML, CSS), and distribute a complete package, with graphical capabilities and no complex installation
required.</p>
        <p>While this portion of the course was not further developed, it may be a way to get students interested
in writing a small game or application themselves in the context of a course project. The idea is to show
how Prolog can be used to build applications that are not just about knowledge representation, but also
about building interactive systems that can be used in a web browser.</p>
      </sec>
      <sec id="sec-4-3">
        <title>4.3. Critical thinking in the age of Generative AI</title>
        <p>One of the driving forces behind this work is the need to teach students how to think critically about the
diferent tools they use, and how to pick the right one for the task at hand. With the pervasive exposure
of students to Generative AI, it is important to understand what the strengths and weaknesses of these
systems are, and how they can be used to complement each other. Not only is the teaching of Prolog
and Logic Programming important in knowledge representation and reasoning, or to understand the
fundamental importance of explanations and justifications in AI, but it is also important to understand
what the diferent systems are useful for in simple practical scenarios.</p>
        <p>Consider the following contrast. Suppose a student could use (or train) a Generative AI system to
solve Sudoku puzzles. But, would this be a good use of the tools available? How would it contribute to
the student’s intellectual and skills development, which may be called upon in future to solve problems?
In our point of view it is important to understand that for a similar application, where you can express
the rules of the game, and where you can check the validity of a solution, it is better to use a Prolog
program, as it will be more eficient, it will always give a valid solution (if one exists), and it will be
easier to understand and explain. Sudoku is a simple example, but it can be extended to more complex
problems, such as games with more complex rules, or diferent applications that require reasoning
about the world in a clear and transparent way. The sudoku example is a useful demonstration, as there
are many diferent rulesets that can be implemented making small changes to the Prolog rules.</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>5. Future Work</title>
      <p>The JupyterHub server has been used successfully in the course, and it would be interesting to extend
its use to other programming courses. Using Jupyter as a platform enables the use of other languages
and tools, that can complement the Prolog development, building user interfaces, or interacting with
other programming paradigms. Some of these capabilities are already available in Jupyter (Python)
notebooks, and they would need to be tied in to Prolog, such as UI menus/fields like web forms, or
graph generation, etc.</p>
      <p>Another update would be to rebuild the Jupyter Kernel component to support the WebAssembly
version of SWI-Prolog, which would allow running without a server, or using the server only for sharing
notebooks and code. Finally, the system could be integrated with a comprehensive set of lectures and
exercises, helping build shared course material for teaching Prolog and Logic Programming, which
could be used by other universities and institutions.</p>
      <p>Regarding the web integration, it would be interesting to extend the demos to include more complex
applications. This could be done by building a set of demos that show how Prolog can be used to build
interactive systems that can be used in a web browser, and how these systems can be used to solve
real-world problems e.g., in the medical or legal domain.</p>
      <p>Finally, to better assess the usefulness of such a system, it would be a good idea to carry out a proper
user study, and enable a continuous feedback with students that can suggest changes or inform us
on what works and what needs revision. This can also be done directly in Jupyter, to simplify the
requirements and encourage feedback.</p>
    </sec>
    <sec id="sec-6">
      <title>6. Conclusion</title>
      <p>In this paper, we have described the deployment and use of a JupyterHub server with a Prolog kernel to
support the teaching of Prolog and logic programming in a university setting. By leveraging Jupyter
notebooks, nbgrader, and web integration, we have created an interactive and accessible environment
that lowers technical barriers for students and enables immediate feedback and experimentation. This
approach not only facilitates the learning of declarative programming concepts but also encourages
students to critically evaluate the strengths of logic programming in comparison to contemporary
generative AI systems. Our experience suggests that integrating modern tools and pedagogical strategies
can enhance student engagement and understanding, and that further development of shared resources
and interactive applications will continue to benefit both educators and learners in the field of artificial
intelligence.</p>
    </sec>
    <sec id="sec-7">
      <title>Declaration on Generative AI</title>
      <sec id="sec-7-1">
        <title>The author(s) have not employed any Generative AI tools.</title>
        <p>[11] M. Triska, The Power of Prolog: Introduction to modern Prolog, 2025. URL: https://github.com/
triska/the-power-of-prolog.
[12] S. Sehgal, Y. A. Liu, Logical Lease Litigation: Prolog and LLMs for Rental Law Compliance
in New York, Electronic Proceedings in Theoretical Computer Science 416 (2025) 59–68. URL:
http://dx.doi.org/10.4204/EPTCS.416.4. doi:10.4204/eptcs.416.4.
[13] C. Jendreiko, Generative Logic: Teaching Prolog as Generative AI in Art and Design, volume 3799
of CEUR Workshop Proceedings, CEUR, 2024. URL: https://ceur-ws.org/Vol-3799/#paper9PEG2.0.
[14] P. Tarau, On Teaching Logic Programming in the Era of Generative AI, volume 3799 of CEUR</p>
        <p>Workshop Proceedings, CEUR, 2024. URL: https://ceur-ws.org/Vol-3799/#paper11PEG2.0.
[15] E. Saccon, A. Tikna, D. De Martini, E. Lamon, L. Palopoli, M. Roveri, When Prolog Meets Generative
Models: a New Approach for Managing Knowledge and Planning in Robotic Applications, 2024,
pp. 17065–17071. URL: https://ieeexplore.ieee.org/abstract/document/10610800. doi:10.1109/
ICRA57147.2024.10610800.
[16] R. Kowalski, J. Dávila, G. Sartor, M. Calejo, Logical English for Law and Education, in: D. S.</p>
        <p>Warren, V. Dahl, T. Eiter, M. V. Hermenegildo, R. Kowalski, F. Rossi (Eds.), Prolog: The Next 50
Years, Lecture Notes in Computer Science, Springer Nature Switzerland, Cham, 2023, pp. 287–299.
URL: https://doi.org/10.1007/978-3-031-35254-6_24. doi:10.1007/978-3-031-35254-6_24.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>W. F.</given-names>
            <surname>Clocksin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C. S.</given-names>
            <surname>Mellish</surname>
          </string-name>
          , Programming in Prolog, Springer Berlin Heidelberg,
          <year>2003</year>
          . doi:
          <volume>10</volume>
          . 1007/978-3-
          <fpage>642</fpage>
          -55481-0.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>P.</given-names>
            <surname>Brna</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Pain</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B. Du</given-names>
            <surname>Boulay</surname>
          </string-name>
          , Teaching,
          <source>Learning and Using Prolog: Understanding Prolog</source>
          <volume>19</volume>
          (
          <year>1990</year>
          )
          <fpage>247</fpage>
          -
          <lpage>256</lpage>
          . URL: https://www.jstor.org/stable/23370479.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>L.</given-names>
            <surname>Sterling</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E. Y.</given-names>
            <surname>Shapiro</surname>
          </string-name>
          ,
          <article-title>The Art of Prolog: Advanced Programming Techniques</article-title>
          , MIT Press,
          <year>1994</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>J. F.</given-names>
            <surname>Morales</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Abreu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Ferreiro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. V.</given-names>
            <surname>Hermenegildo</surname>
          </string-name>
          ,
          <article-title>Teaching Prolog with Active Logic Documents</article-title>
          , Springer Nature Switzerland,
          <year>2023</year>
          , pp.
          <fpage>171</fpage>
          -
          <lpage>183</lpage>
          . URL: https://doi.org/10.1007/ 978-3-
          <fpage>031</fpage>
          -35254-6_
          <fpage>14</fpage>
          . doi:
          <volume>10</volume>
          .1007/978-3-
          <fpage>031</fpage>
          -35254-6_
          <fpage>14</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>H.</given-names>
            <surname>Coelho</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. C.</given-names>
            <surname>Cotta</surname>
          </string-name>
          , Prolog by Example:
          <article-title>How to Learn, Teach</article-title>
          and Use It, Springer Science &amp; Business
          <string-name>
            <surname>Media</surname>
          </string-name>
          ,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>H. S.</given-names>
            <surname>Pedro</surname>
          </string-name>
          <string-name>
            <surname>Ribeiro</surname>
          </string-name>
          , Michel Ferreira,
          <source>Teaching Artificial Intelligence and Logic Programming in a Competitive Environment</source>
          <volume>8</volume>
          (
          <year>2009</year>
          )
          <fpage>85</fpage>
          -
          <lpage>100</lpage>
          . URL: https://www.ceeol.com/search/article-detail?id=
          <fpage>107606</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>J.</given-names>
            <surname>Wielemaker</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Lager</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Riguzzi</surname>
          </string-name>
          ,
          <source>SWISH: SWI-Prolog for Sharing</source>
          ,
          <year>2015</year>
          . URL: http://arxiv.org/ abs/1511.00915. doi:
          <volume>10</volume>
          .48550/arXiv.1511.00915. arXiv:
          <volume>1511</volume>
          .00915 [cs].
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>U.</given-names>
            <surname>Neumerkel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Kral</surname>
          </string-name>
          ,
          <source>Declarative program development in Prolog with GUPU</source>
          ,
          <year>2002</year>
          . URL: http: //arxiv.org/abs/cs/0207044. doi:
          <volume>10</volume>
          .48550/arXiv.cs/0207044. arXiv:cs/0207044.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>D. L.</given-names>
            <surname>Poole</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. K.</given-names>
            <surname>Mackworth</surname>
          </string-name>
          ,
          <source>Artificial Intelligence: Foundations of Computational Agents</source>
          , Cambridge University Press,
          <year>2023</year>
          . URL: https://www.cambridge.org/highereducation/books/ artificial-intelligence/C113F6CE284AB00F5489EBA5A59B93B7. doi:
          <volume>10</volume>
          .1017/9781009258227.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>P.</given-names>
            <surname>Blackburn</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Bos</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Striegnitz</surname>
          </string-name>
          , Learn Prolog Now!, volume
          <volume>7</volume>
          of Texts in Computing, College Publications,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>