Knowledge Representation and Reasoning with Answer Set Programming

Knowledge Representation and Reasoning with Answer Set Programming

Read about the difference between declarative and imperative programming and learn from code examples (Answer Set Programming, Python and C).

Introduction

The amount of computational problems seems to be unlimited in both industry and science. There is a huge demand for new insights from the vast amount of available data. To obtain this knowledge, dedicated people use all kinds of programming languages for designing and implementing algorithms.

However, many of the current real-world problems are complex (combinatorial) search problems with which we try to automate and optimize processes as well as support people in their decisions. This does not involve encoding of algorithms but encoding given knowledge. In other words, given knowledge about all the rules and constraints to be considered to what is counted as a solution. Instead of writing statements describing the control flow of a computation, declarative programming expresses its logic. What do we want to achieve, not statements about how we can achieve it.

This is called declarative programming.

Why declarative programming?

Using a promising declarative programming paradigm, namely Answer Set Programming (ASP, sometimes also Answer Set Prolog), offers unexpected advantages over the popular imperative programming approach, for example:

  • Short solutions (as measured by lines of code)
  • Transparency (including readability)
  • Reliability

and many more. Once you have broken the problem down into its smallest pieces and written down all the necessary knowledge, you will not only solve the computational challenge. A big advantage is that you have digitized the knowledge and can use it for further problems or make it available in other ways.

Experience and knowledge can be sustainably secured and protected against loss (e.g. through retirement or termination of employees).

Furthermore, it strengthens the cooperation between ‘business people’ and programmers. The integration of artificial intelligence is supported and acceptance at all levels will increase. This is a fundamental process that can only be achieved in cooperation with all departments of a company.

What is ASP and how does it work?

An answer set program consists of given knowledge formulated as facts, rules (head(X) :- body(X).) or constraints. The program is loaded by a solver and returns a “stable model”. This so called answer set consists of all facts that can be derived using the given rules and constraints. A finite amount of stable models are generated as solutions, of which one is finally selected.

_Note: _grounding and solving the problems are not within the scope of this article.

Let us consider a famous example from logic about birds and penguins. It is a well known fact that birds can fly. This can be encoded as an answert set rule:

canFly(X) :- bird(X).

The rule is read as “If `X_` is a bird, then `X_`_ can fly”_. Now let’s add more knowledge! For example, facts that tell the unconditional truth, just as seagull ‘Malvin’ is a bird, but also penguin ‘Roger’ is one.

canFly(X) :- bird(X).
bird(malvin).
bird(roger).

== MODEL OUTPUT ==
Anwer: 1
bird(malvin) bird(roger) canFly(malvin) canFly(roger)
SATISFIABLE

As a result, the answer set tells us the known facts that Malvin and Roger are birds but also concluded that they are able to fly. The biology enthusiasts among us know, that penguins are unable to fly thus the model is wrong!

Image for post

Seagull ‘Malvin’ — slightly showing off because he can fly. (Photo by Phil Botha on Unsplash)

In order to get acceptable results we need to add more knowledge in form of facts and integrity constraints to the program. Here, the model needs to know that Roger is not only a bird but also a penguin and that there is no bird that is a penguin which is able to fly.

canFly(X) :- bird(X).
bird(malvin).
bird(roger).
seagull(malvin).
penguin(roger).
:- canFly(X), penguin(X).
== MODEL OUTPUT ==
UNSATISFIABLE

This does not bring the expected result and shows how important it is to think thoroughly and very carefully about the problem as well as the solution. The model tells, like stated by the programmer, that a bird can fly but there is no advise for birds that belong to the penguin family. To avoid this, we could add that only birds that are not penguins are able to fly.

canFly(X) :- bird(X), not penguin(X).
bird(malvin).
bird(roger).
seagull(malvin).
penguin(roger).
:- canFly(X), penguin(X).
== MODEL OUTPUT ==
Answer: 1
bird(malvin) bird(roger) seagull(malvin) penguin(roger) canFly(malvin)
SATISFIABLE

Adding this knwoledge in Line [1], the stable model consists of the expected outcome.

answer-set-programming knowledge-representation logical-reasoning artificial-intelligence digital-transformation

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Knowledge Representation and Reasoning with Answer Set Programming

Read about the difference between declarative and imperative programming and learn from code examples (Answer Set Programming, Python and C).

AI Innovations in Artificial Intelligence

Innovations in Artificial Intelligence - Various sectors in which AI is remarkably used & has brought changes in humanity - Education, Healthcare,automobile

Transforming Advertisement and Graphic Design Industries Through Artificial Intelligence

Transforming Advertisement and Graphic Design Industries Through Artificial Intelligence. In this article, see how to transform advertisement and graphic design industries through AI.

Digital Transformation - Security Solutions, Technologies, Challenges and Vision

The Digital Transformation practises is getting standardized in SME's and Enterprises with crucial precautions raised against cybersecurity attacks. We have emphasized the dire need for a resilient security solutions for digital systems to avert...

Top 10 Artificial Intelligence (AI) Interview Questions & Answers

In this Artificial Intelligence Interview Questions blog, you will understand the most frequently asked AI questions and their solutions.