Semantic and Declarative Technologies

AIT Budapest

Péter Szeredi, László Kabódi, Péter Tóth

Semantic? Declarative? What the hell…?

  • According to the Merriam-Webster dictionary:
    • Semantic (adjective):
      relating to the meanings of words and phrases
    • Declarative (adjective), linguistics:
      (a sentence) having the form of a statement as opposed to a question or a command
  • And in conjunction with computers?
    • Semantic web: search engines should understand the web, not just read it
    • Declarative programming: program using statements rather than commands
  • Why together in the same course?
    • Common foundation: (mathematical) logic

Topics and layout of the course

Duration Topic
2 weeks Propositional & First Order Logic
5 weeks Logic Programming:
the Prolog programming language
5 weeks CLPFD:
Constraint Logic Programming on Finite Domains
2 weeks Description Logics for Semantic Web

Requirements

  • Two programming assignments:
    Prolog (Sudoku solver), CLPFD (Skyscraper sudoku solver)
    15% each, total 30%


  • Two tests: mid-term & final 20% each, total 40%


  • Many small exercises + class activity 30%

PrologProgramming in logic

  • A Prolog program consists of simple logic statements
  • The slogan of Prolog: WHAT rather than HOW
  • A Prolog program describes WHAT to do, but it is also important to know HOW Prolog executes the program
  • A sample logic statement (also called predicate):
                                    
                                    has_gp(GC, GP) :-
                                        has_p(GC, P),
                                        has_p(P, GP).
                                    
                                
                                    
                                        % GC has grandparent GP if
                                        % GC has parent P and
                                        % P has parent GP.
                                    
                                
  • Prolog is a symbolic language: 1+1 is a tree structure, not evaluated to 2 by default

Countdown puzzle

Countdown in Prolog


                            countdown(Ints, T, Expr) :-        % Expr is a solution of the task with ints Ints and target T
                                subseq(Ints, Ints1, _),        %  if Ints has a subsequence Ints1
                                permutation(Ints1, Ints2),     %   & Ints1 has a permutation Ints2
                                expr_leaves(Expr, Ints2),      %   & Expr is a formula with list of leaves Ints2
                                Expr =:= T.                    %   & Expr evaluates to T.

                            expr_leaves(Expr, Ints) :-         % Expr is a valid formula with list of leaves Ints
                                append(LInts, RInts, Ints),    %  if Ints is the concatenation of LInts and RInts
                                LInts \== [], RInts \== [],    %   & neither of these is an empty list
                                expr_leaves(LExpr, LInts),     %   & LExpr is a formula with leaves LInts
                                expr_leaves(RExpr, RInts),     %   & RExpr is a formula with leaves RInts
                                build_expr(LExpr, RExpr, Expr).%   & combining LExpr and RExpr may yield Expr.
                            expr_leaves(Int, [Int]) :-         % Int is a valid formula with list of leaves [Int]
                                integer(Int).                  %  if Int is an integer.

                            build_expr(X, Y, X+Y).             % combining exprs X and Y may yield X+Y.
                            build_expr(X, Y, X*Y).             % combining exprs X and Y may yield X*Y.
                            build_expr(X, Y, X-Y) :- X > Y.    % combining exprs X and Y may yield X-Y if X > Y.
                            build_expr(X, Y, X/Y) :-           % combining exprs X and Y may yield X/Y
                                X mod Y =:= 0.                 %   if X divided by Y gives a 0 remainder.
                        

                            | ?- countdown([75,7,9,3,3,9], 852, Expr).
                            Expr = (75-(7-3))*(3+9) ? ; ...
                        



Constraint Logic Programming (CLP)

  • CLP is an extension of Prolog with special reasoning techniques for a given domain
  • In this course we will cover CLP(FD) for reasoning on integer domains
  • Example cryptarithmetic puzzle: AT + RAT = ART, where letters represent different digits, no initial 0’s allowed
  • A solution using CLP(FD):
    
                                    domain([A,R,T], 0, 9),      % A, R and T are digits
                                    A #> 0, R #> 0,             % A and R can not be 0
                                    all_distinct([A,R,T]),      % A, R and T are all different
                                    (10*A + T) + (100*R + 10*A + T) #= (100*A + 10*R + T).
                                
    R = 8, A = 9, T = 0

The Semantic Web (SW)

  • Math side — Description Logics: decidable subsets of First Order Logic
  • Software side — the Web Ontology Language OWL from W3C, and the Protegé knowledge editor from Stanford Univ.
  • An example puzzle:
    There is an island where some people are optimistic (opt).
    The following statements hold on this island:
    • Someone having an opt parent is bound to be opt.
    • Someone having a non-opt friend is also bound to be opt.
    • Susan's father has her mother as a friend.
  • Can you prove that Susan has to be optimistic?

    Protegé can:

Why should you attend this course?
  • Learn a very different programming paradigm, which you can also use in other languages.
  • Learn techniques to quickly and concisely solve difficult algorithmic problems
  • Learn Description Logics – the maths behind the next generation “intelligent” Web
  • Learn from one of the 15 Founders of Logic Programming (as recognized by the Association for Logic Programming)
  • Enjoy the PLWIN (Prolog Web Interface) based practice apps, developed by the authors of this course https://ait.plwin.dev/

Go to the web page
szeredi.hu
to access the slides and further content