"SAT: Model found: [branch(neg(x10)),branch(pos(x16)),branch(neg(x17)),branch(neg(x1)),branch(pos(x3)),branch(neg(x13)),branch(neg(x2)),unit(pos(x19)),branch(pos(x7)),unit(neg(x20)),unit(pos(x8)),unit(neg(x18)),unit(neg(x11)),unit(neg(x4)),branch(pos(x5)),unit(pos(x14)),unit(pos(x9)),branch(pos(x15)),branch(pos(x12))]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"\u001b[1mtrue"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"?- test(4)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc767ce8",
"metadata": {
"vscode": {
"languageId": "prolog"
}
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Prolog",
"language": "prolog",
"name": "prolog_kernel"
},
"language_info": {
"codemirror_mode": "prolog",
"file_extension": ".pl",
"mimetype": "text/x-prolog",
"name": "Prolog"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:markdown id:9eb5530a tags:
We can convert our Knights and Knaves puzzle to conjunctive normal form
```
(A ⇔ B C) ∧ (B ⇔ A)
(A → B C) ∧ (B C → A) ∧ (B → A)∧ (A → B)
(A B C) ∧ ((B C) A) ∧ (B A)∧ (A B)
(A B C) ∧ ((B ∧ C) A) ∧ (B A)∧ (A B)
(A B C) ∧ (B A) ∧ (C A) ∧(B A)∧ (A B)
{A B C, B A, C A, B A, A B}
```
Below is an encoding of the cnf as a list of lists.
%% Cell type:code id:964ebd52 tags:
``` prolog
:-discontiguousproblem/3.
:-dynamicproblem/3.
problem(1,'Knights & Knaves',
[[neg(a),neg(b),neg(c)],
[pos(b),pos(a)],
[pos(c),pos(a)],
[neg(b),pos(a)],
[neg(a),pos(b)]]).
negate(pos(A),neg(A)).
negate(neg(A),pos(A)).
```
%% Cell type:markdown id:fc6823ad tags:
We can pick two clauses and resolve them as follows: