# Center for Analysis and Design of Intelligent Agents

### Site Tools

public:t-622-arti-11-1:lab_6_materials

## Lab 6: PowerLoom

In this lab we will work with First Order Logic and PowerLoom, a knowledge representation system. You will have to go through the following steps and create some logical statements representing Family Relations.

### PowerLoom

• The main webpage of PowerLoom;
• PowerLoom documentation in PDF or HTML version.
```(all-facts-of X) ;; prints out all known facts about X
(help assert)    ;; prints out help text about “assert”
(demo)           ;; leads you through various PowerLoom demonstrations```

### Doing Knowledge Representation and Reasoning with PowerLoom

1. Basic Commands:
Create a new, empty, module to work in and specify representation language syntax:
```(defmodule "PL-USER/FAMILY")
(in-module "FAMILY")
(reset-features)
(in-dialect KIF)```

```(save-module "FAMILY" "FAMILY.PLM")

(in-module "FAMILY")  ;; If not already in this module```
2. Defining a basic type/class predicate (a unary relation) called a “concept”:
```(defconcept Person(?p))          ;; Defining a Person
(defconcept Male (?p Person))    ;; A Male is a Person
(defconcept Female (?p Person))  ;; A Female is a Person```
```(assert (Male John))
(assert (Female Mary))

4. Adding First Order Logic (FOL) axioms:
Being a Male implies you are a person:
`(assert (forall (?x) (=> (Male ?x) (Person ?x))))`

Do the same for Females.

Returns one possible substitutions for ?p if it exists:
`(retrieve (Person ?p))`

Returns all possible substitutions for ?p:

`(retrieve all (Person ?p))`
6. The Open-World semantics:
The following should be unknown since it wouldn't conflict with the KB
`(ask (Male Mary))`

If we add this assertion, being a male implies you are not a female:

`(assert (forall (?p) (<=> (Male ?p) (not (Female ?p)))))`

Create the same assertion for Females.

7. Defining a regular relation predicate:
The following creates a new Predicate called BrotherOf:
```(defrelation BrotherOf ((?p1 Male) (?p2 Person)))
(assert (BrotherOf John Mary))
(assert (Person Olaf))
(assert (BrotherOf Olaf Mary))

(retrieve all (BrotherOf ?x Mary))    ;; Retrieve all Brothers of Mary```

Create a new predicate called ParentOf.

8. Defining a regular function and using it:
If a (binary) relation always maps its first argument to exactly one value (i.e., if it it “single-valued”) we can specify it as a function instead of a relation.
`(deffunction GetFather ((?p1 Person)) :-> (?p2 Male))   ;; The second value (after the symbol ":->") is the output variable of the function`

We can refer to a function in a sentence in this way:

`(assert (= (GetFather Mary) Zod))`

A new axiom that uses a function and equivalence

`(assert (<=> (= (GetFather ?c) ?f) (and (Male ?f) (ParentOf ?f ?c))))`

• Is Zod Male?
• Is Zod Mary's parent?
9. Defining more family Relations: