// Datalog program. // Facts: likePizza('bun'); likePizza('john'); likePizza('mary'); hasPizza('bun'); hasPizza('john'); // Rules: if-then statement. // head :- body (p1, p2, p3,...); ,: and. happy(X) :- hasPizza(X), likePizza(X); happy('bun'); true happy('susan'); false happy(X); // X variable. X = bun X = john boss(X,Y) :- supervise(X,Y); R1 boss(X,Y) :- supervise(X,Z), boss(Z,Y); R2 supervise('joe','mary'); supervise('mary','peter'); supervise('mary','paul'); supervise('paul','stan'); supervise('paul','lee'); Queries boss('joe','mary'); true: R1 boss('mary','joe'); boss('mary','stan'); true: R2 (bind X; 'mary', Y: 'stan') Look for supervise('mary', Z), found supervise('mary','paul'): Z: 'paul' Look for boss('paul', 'stan') R1: Look for supervise('paul','stan'): T boss(X,'lee'); boss('joe',Y); boss(A,B);