Horn clauses If four legs and has a tail, then a dog D is a dog if has four legs, has a tail dog(D) if legs(D, 4) & has_tail(D) dog(D) :- legs(D, 4), has_tail(D). “if” “and”

even(2). even(4). even(6). Prolog, how does it work? 1. Write facts 2. Ask a question with a variable ?- even(X). prolog, 2 is even prolog, 4 is even prolog, 6 is even prolog, can you ﬁnd an even X?

even(2). even(4). even(6). Prolog, how does it work? 1. Write facts 2. Ask a question with a variable ?- even(X). 3. Prolog solves for the variable prolog, 2 is even prolog, 4 is even prolog, 6 is even prolog, can you ﬁnd an even X? X = 2 ; X = 4 ; X = 6.

Todo list just_before(laundry, homework). just_before(dishes, laundry). ?- just_before(X, homework). X = laundry. code repl just_before just_before Before After laundry homework dishes laundry

Todo list code repl before before Before After laundry homework dishes laundry dishes homework just_before just_before Before After laundry homework dishes laundry

Todo list before(X, Y) :- just_before(X, Y). before(X, Y) :- just_before(X, T), before(T, Y). ?- before(X, homework). X = laundry ; X = dishes. code repl before before Before After laundry homework dishes laundry dishes homework

Todo list tag(homework, work). tag(laundry, home). tag(dishes, home). tag(talk, work). ?- tag(dishes, T). T = home. ?- tag(X, work). X = homework ; X = talk. code repl tag tag Task Tag homework work laundry home dishes home talk work

How to think about logic programming? 1. functional = imperative – mutable state logic = functional – manual search 2. combining database and program 3. an implementation of mathematical logic

How to think about logic programming? 1. functional = imperative – mutable state logic = functional – manual search 2. combining database and program 3. an implementation of mathematical logic not really

/** * Type class witnessing that `A` is less than or equal to `B`. * * @author Miles Sabin */ trait LTEq[A <: Nat, B <: Nat] object LTEq { import Nat._0 type <=[A <: Nat, B <: Nat] = LTEq[A, B] implicit def ltEq1 = new <=[_0, _0] {} implicit def ltEq2[B <: Nat] = new <=[_0, Succ[B]] {} implicit def ltEq3[A <: Nat, B <: Nat](implicit lt : A <= B) = new <=[Succ[A], Succ[B]] {} } Scala shapeless library Try ﬁnding the logic