117 lines
3.0 KiB
Markdown
117 lines
3.0 KiB
Markdown
---
|
|
title: "Exercices"
|
|
weight: 70
|
|
---
|
|
|
|
# Exercices
|
|
|
|
## Conditions (pseudo-)imbriquées
|
|
|
|
Représenter (naïvement) la condition suivante avec une constellation de telle
|
|
sorte à ce qu'elle retourne `message(use more duct tape);` avec la constellation
|
|
`@+it_moves(1); @+it_should_move(0);` :
|
|
|
|
```
|
|
if it moves and it should move
|
|
no problem
|
|
if it moves and it should not move
|
|
use more duct tape
|
|
if it does not move and it should move
|
|
use more lube
|
|
if it does not move and it should not move
|
|
no problem
|
|
```
|
|
|
|
{{< details title="Solution" open=false >}}
|
|
```
|
|
-it_moves(1) -it_should_move(1) message(no problem);
|
|
-it_moves(1) -it_should_move(0) message(use more duct tape);
|
|
-it_moves(0) -it_should_move(1) message(use more lube);
|
|
-it_moves(0) -it_should_move(0) message(no problem);
|
|
|
|
@+it_moves(1);
|
|
@+it_should_move(0);
|
|
```
|
|
{{< /details >}}
|
|
|
|
{{< hint info >}}
|
|
Il n'est pas nativement possible la condition suivante :
|
|
```
|
|
if it moves
|
|
if it should move
|
|
no problem
|
|
else
|
|
use more duct tape
|
|
else
|
|
if it should move
|
|
use more lube
|
|
else
|
|
no problem
|
|
```
|
|
car cela requiert des mécanismes de liaisons séquentielles.
|
|
{{< /hint >}}
|
|
|
|
## Bases de connaissance et requêtes
|
|
|
|
Prendre la base de connaissance suivante :
|
|
|
|
```
|
|
+father(francisco paulo);
|
|
+father(joao paulo);
|
|
+father(ana francisco);
|
|
+mother(rita roberta);
|
|
+mother(joao roberta);
|
|
+mother(francisco roberta);
|
|
+mother(roberta maria);
|
|
```
|
|
|
|
1. Quelle étoile ajouter pour demander si le père d'ana est francisco de telle
|
|
sorte à ce que l'exécution renvoie ok quand c'est bien le cas ?
|
|
|
|
{{< details title="Solution" open=false >}}
|
|
@-father(ana francisco) ok;
|
|
{{< /details >}}
|
|
|
|
2. Même exercice pour demander qui est la mère de joao de telle sorte à ce que
|
|
l'exécution renvoie le nom de la mère de joao.
|
|
|
|
{{< details title="Solution" open=false >}}
|
|
@-mother(joao X) X;
|
|
{{< /details >}}
|
|
|
|
3. Même exercice pour demander qui sont les enfants de roberta et paulo.
|
|
|
|
{{< details title="Solution" open=false >}}
|
|
+children(X M F) -mother(X M) -father(X F);
|
|
@-children(X roberta paulo) X;
|
|
{{< /details >}}
|
|
|
|
4. Définir une constellation qui permet de donner le grand-père d'une personne.
|
|
|
|
{{< details title="Solution" open=false >}}
|
|
+grand-father(X GF) -father(X F) -father(F GF);
|
|
{{< /details >}}
|
|
|
|
5. Définir une requête qui permet de lister toutes les relations de
|
|
petit-fils/grand-père.
|
|
|
|
{{< details title="Solution" open=false >}}
|
|
+grand-father(X GF) -father(X F) -father(F GF);
|
|
@-grand-father(X Y) grand-father(X Y);
|
|
{{< /details >}}
|
|
|
|
6. Donner une nouvelle représentation de la base de connaissance qui permet de
|
|
lister toutes les relations père et mère à l'aide d'une étoile
|
|
`@-parent(R X Y) parent(R X Y)` où `R` correspond à la relation entre `X` et `Y`.
|
|
|
|
{{< details title="Solution" open=false >}}
|
|
```
|
|
+parent(father francisco paulo);
|
|
+parent(father joao paulo);
|
|
+parent(father ana francisco);
|
|
+parent(mother rita roberta);
|
|
+parent(mother joao roberta);
|
|
+parent(mother francisco roberta);
|
|
+parent(mother roberta maria);
|
|
```
|
|
{{< /details >}} |