Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prob-teaching-notebooks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
prob-teaching-notebooks
Commits
de95161a
Commit
de95161a
authored
2 years ago
by
Michael Leuschel
Browse files
Options
Downloads
Patches
Plain Diff
add precedence text
Signed-off-by:
Michael Leuschel
<
leuschel@uni-duesseldorf.de
>
parent
d1215d17
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
logic_programming/3_PropositionalLogic.ipynb
+70
-739
70 additions, 739 deletions
logic_programming/3_PropositionalLogic.ipynb
with
70 additions
and
739 deletions
logic_programming/3_PropositionalLogic.ipynb
+
70
−
739
View file @
de95161a
...
@@ -42,7 +42,7 @@
...
@@ -42,7 +42,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
23
,
"execution_count":
11
,
"id": "964ebd52",
"id": "964ebd52",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -50,66 +50,10 @@
...
@@ -50,66 +50,10 @@
}
}
},
},
"outputs": [
"outputs": [
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:wff/2 were retracted (click to expand)</summary><pre>:- dynamic wff/2.\n",
"\n",
"wff(A, B) :-\n",
" A=[112|B].\n",
"wff(A, B) :-\n",
" A=[113|B].\n",
"wff(A, B) :-\n",
" A=[40, 172|C],\n",
" wff(C, D),\n",
" D=[41|B].\n",
"wff(A, B) :-\n",
" A=[40|C],\n",
" wff(C, D),\n",
" D=[8743|E],\n",
" wff(E, F),\n",
" F=[41|B].\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:wff/2 were retracted:\n",
":- dynamic wff/2.\n",
"\n",
"wff(A, B) :-\n",
" A=[112|B].\n",
"wff(A, B) :-\n",
" A=[113|B].\n",
"wff(A, B) :-\n",
" A=[40, 172|C],\n",
" wff(C, D),\n",
" D=[41|B].\n",
"wff(A, B) :-\n",
" A=[40|C],\n",
" wff(C, D),\n",
" D=[8743|E],\n",
" wff(E, F),\n",
" F=[41|B].\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"
% Asserting clauses for user:wff/2\n
"
"
\u001b[1;31m% The Prolog server was restarted
"
]
]
},
},
"metadata": {},
"metadata": {},
...
@@ -129,7 +73,7 @@
...
@@ -129,7 +73,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1
7
,
"execution_count": 1
2
,
"id": "fc6823ad",
"id": "fc6823ad",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -153,7 +97,7 @@
...
@@ -153,7 +97,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1
8
,
"execution_count": 1
3
,
"id": "152289b6",
"id": "152289b6",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -177,7 +121,7 @@
...
@@ -177,7 +121,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
29
,
"execution_count":
14
,
"id": "2c3dd1bf",
"id": "2c3dd1bf",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -200,6 +144,27 @@
...
@@ -200,6 +144,27 @@
"%comment."
"%comment."
]
]
},
},
{
"cell_type": "markdown",
"id": "38b0a282",
"metadata": {},
"source": [
"This grammar does not talk about whitespace and requires parentheses for every connective used.\n",
"In practice, one typically uses operator precedences to avoid having to write too many parentheses:\n",
"- negation binds strongest\n",
"- then come conjunction and disjunction\n",
"- then come implication and equivalence.\n",
"\n",
"So instead of\n",
"- (((¬ p) ∧ (¬ q)) ⇒ ((¬ p) ∨ (¬ q)))\n",
"we can write\n",
"- ¬ p ∧ ¬ q ⇒ ¬ p ∨ ¬ q\n",
"\n",
"We will try not not mix conjunction/disjunction and implication/equivalence without parentheses.\n",
"We will also not try to improve our Prolog parser here to accomodate these precedences.\n",
"This is the subject of another course (on compiler construction)."
]
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "92b6dc2d",
"id": "92b6dc2d",
...
@@ -211,78 +176,14 @@
...
@@ -211,78 +176,14 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
24
,
"execution_count":
15
,
"id": "78163b60",
"id": "78163b60",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
"languageId": "prolog"
"languageId": "prolog"
}
}
},
},
"outputs": [
"outputs": [],
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:wff/3 were retracted (click to expand)</summary><pre>:- dynamic wff/3.\n",
"\n",
"wff(p, [112|A], A).\n",
"wff(q, A, B) :-\n",
" A=[113|B].\n",
"wff(not(A), B, C) :-\n",
" B=[40, 172|D],\n",
" wff(A, D, E),\n",
" E=[41|C].\n",
"wff(and(A, B), C, D) :-\n",
" C=[40|E],\n",
" wff(A, E, F),\n",
" F=[8743|G],\n",
" wff(B, G, H),\n",
" H=[41|D].\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:wff/3 were retracted:\n",
":- dynamic wff/3.\n",
"\n",
"wff(p, [112|A], A).\n",
"wff(q, A, B) :-\n",
" A=[113|B].\n",
"wff(not(A), B, C) :-\n",
" B=[40, 172|D],\n",
" wff(A, D, E),\n",
" E=[41|C].\n",
"wff(and(A, B), C, D) :-\n",
" C=[40|E],\n",
" wff(A, E, F),\n",
" F=[8743|G],\n",
" wff(B, G, H),\n",
" H=[41|D].\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:wff/3\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"source": [
" :- set_prolog_flag(double_quotes, codes).\n",
" :- set_prolog_flag(double_quotes, codes).\n",
"wff(p) --> \"p\". % atomic proposition\n",
"wff(p) --> \"p\". % atomic proposition\n",
...
@@ -296,7 +197,7 @@
...
@@ -296,7 +197,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
25
,
"execution_count":
16
,
"id": "8ddb568d",
"id": "8ddb568d",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -320,7 +221,7 @@
...
@@ -320,7 +221,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
26
,
"execution_count":
17
,
"id": "075dc3b2",
"id": "075dc3b2",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -344,7 +245,7 @@
...
@@ -344,7 +245,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
2
8,
"execution_count":
1
8,
"id": "338cb7dd",
"id": "338cb7dd",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -378,160 +279,14 @@
...
@@ -378,160 +279,14 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
8
,
"execution_count":
19
,
"id": "f6116612",
"id": "f6116612",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
"languageId": "prolog"
"languageId": "prolog"
}
}
},
},
"outputs": [
"outputs": [],
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:subtree/3 were retracted (click to expand)</summary><pre>:- dynamic subtree/3.\n",
"\n",
"subtree(A, B, C) :-\n",
" A=..[_|D],\n",
" nth1(B, D, C).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:subtree/3 were retracted:\n",
":- dynamic subtree/3.\n",
"\n",
"subtree(A, B, C) :-\n",
" A=..[_|D],\n",
" nth1(B, D, C).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:subtree/3\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:rec_subtree/2 were retracted (click to expand)</summary><pre>:- dynamic rec_subtree/2.\n",
"\n",
"rec_subtree(A, B) :-\n",
" A=B.\n",
"rec_subtree(A, B) :-\n",
" subtree(A, _, C),\n",
" rec_subtree(C, B).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:rec_subtree/2 were retracted:\n",
":- dynamic rec_subtree/2.\n",
"\n",
"rec_subtree(A, B) :-\n",
" A=B.\n",
"rec_subtree(A, B) :-\n",
" subtree(A, _, C),\n",
" rec_subtree(C, B).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:rec_subtree/2\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:subnode/3 were retracted (click to expand)</summary><pre>:- dynamic subnode/3.\n",
"\n",
"subnode(A, [shape/B, label/C], D) :-\n",
" rec_subtree(D, A),\n",
" functor(A, C, _),\n",
" ( atom(A)\n",
" -> B=egg\n",
" ; number(A)\n",
" -> B=oval\n",
" ; B=rect\n",
" ).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:subnode/3 were retracted:\n",
":- dynamic subnode/3.\n",
"\n",
"subnode(A, [shape/B, label/C], D) :-\n",
" rec_subtree(D, A),\n",
" functor(A, C, _),\n",
" ( atom(A)\n",
" -> B=egg\n",
" ; number(A)\n",
" -> B=oval\n",
" ; B=rect\n",
" ).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:subnode/3\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"source": [
"subtree(Term,Nr,SubTerm) :- \n",
"subtree(Term,Nr,SubTerm) :- \n",
" Term =.. [_|ArgList], %obtain arguments of the term\n",
" Term =.. [_|ArgList], %obtain arguments of the term\n",
...
@@ -548,7 +303,7 @@
...
@@ -548,7 +303,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
9
,
"execution_count":
20
,
"id": "d7e68593",
"id": "d7e68593",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -598,7 +353,7 @@
...
@@ -598,7 +353,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
7
,
"execution_count":
21
,
"id": "3646e3ee",
"id": "3646e3ee",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -656,320 +411,14 @@
...
@@ -656,320 +411,14 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2
1
,
"execution_count": 2
2
,
"id": "350b9756",
"id": "350b9756",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
"languageId": "prolog"
"languageId": "prolog"
}
}
},
},
"outputs": [
"outputs": [],
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:not/2 were retracted (click to expand)</summary><pre>:- dynamic not/2.\n",
"\n",
"not(true, false).\n",
"not(false, true).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:not/2 were retracted:\n",
":- dynamic not/2.\n",
"\n",
"not(true, false).\n",
"not(false, true).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:not/2\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:and/3 were retracted (click to expand)</summary><pre>:- dynamic and/3.\n",
"\n",
"and(true, A, A).\n",
"and(false, _, false).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:and/3 were retracted:\n",
":- dynamic and/3.\n",
"\n",
"and(true, A, A).\n",
"and(false, _, false).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:and/3\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:or/3 were retracted (click to expand)</summary><pre>:- dynamic or/3.\n",
"\n",
"or(true, _, true).\n",
"or(false, A, A).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:or/3 were retracted:\n",
":- dynamic or/3.\n",
"\n",
"or(true, _, true).\n",
"or(false, A, A).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:or/3\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:implies/3 were retracted (click to expand)</summary><pre>:- dynamic implies/3.\n",
"\n",
"implies(A, B, C) :-\n",
" not(A, D),\n",
" or(D, B, C).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:implies/3 were retracted:\n",
":- dynamic implies/3.\n",
"\n",
"implies(A, B, C) :-\n",
" not(A, D),\n",
" or(D, B, C).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:implies/3\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:equiv/3 were retracted (click to expand)</summary><pre>:- dynamic equiv/3.\n",
"\n",
"equiv(A, B, C) :-\n",
" implies(A, B, D),\n",
" implies(B, A, E),\n",
" and(D, E, C).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:equiv/3 were retracted:\n",
":- dynamic equiv/3.\n",
"\n",
"equiv(A, B, C) :-\n",
" implies(A, B, D),\n",
" implies(B, A, E),\n",
" and(D, E, C).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:equiv/3\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:truth_value/1 were retracted (click to expand)</summary><pre>:- dynamic truth_value/1.\n",
"\n",
"truth_value(true).\n",
"truth_value(false).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:truth_value/1 were retracted:\n",
":- dynamic truth_value/1.\n",
"\n",
"truth_value(true).\n",
"truth_value(false).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:truth_value/1\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:truth_table/7 were retracted (click to expand)</summary><pre>:- dynamic truth_table/7.\n",
"\n",
"truth_table(A, B, C, D, E, F, G) :-\n",
" truth_value(A),\n",
" truth_value(B),\n",
" not(A, C),\n",
" and(A, B, D),\n",
" or(A, B, E),\n",
" implies(A, B, F),\n",
" equiv(A, B, G).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:truth_table/7 were retracted:\n",
":- dynamic truth_table/7.\n",
"\n",
"truth_table(A, B, C, D, E, F, G) :-\n",
" truth_value(A),\n",
" truth_value(B),\n",
" not(A, C),\n",
" and(A, B, D),\n",
" or(A, B, E),\n",
" implies(A, B, F),\n",
" equiv(A, B, G).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:truth_table/7\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"source": [
"not(true,false).\n",
"not(true,false).\n",
"not(false,true).\n",
"not(false,true).\n",
...
@@ -994,7 +443,7 @@
...
@@ -994,7 +443,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2
2
,
"execution_count": 2
3
,
"id": "54b57ff8",
"id": "54b57ff8",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -1040,92 +489,14 @@
...
@@ -1040,92 +489,14 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2
3
,
"execution_count": 2
4
,
"id": "175c00d0",
"id": "175c00d0",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
"languageId": "prolog"
"languageId": "prolog"
}
}
},
},
"outputs": [
"outputs": [],
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:value/3 were retracted (click to expand)</summary><pre>:- dynamic value/3.\n",
"\n",
"value(A, B, C) :-\n",
" atomic(A),\n",
" member(A/C, B).\n",
"value(and(A, B), C, D) :-\n",
" value(A, C, E),\n",
" value(B, C, F),\n",
" and(E, F, D).\n",
"value(or(A, B), C, D) :-\n",
" value(A, C, E),\n",
" value(B, C, F),\n",
" or(E, F, D).\n",
"value(not(A), B, C) :-\n",
" value(A, B, D),\n",
" not(D, C).\n",
"value(implies(A, B), C, D) :-\n",
" value(or(not(A), B), C, D).\n",
"value(equiv(A, B), C, D) :-\n",
" value(and(implies(A, B), implies(B, A)),\n",
" C,\n",
" D).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:value/3 were retracted:\n",
":- dynamic value/3.\n",
"\n",
"value(A, B, C) :-\n",
" atomic(A),\n",
" member(A/C, B).\n",
"value(and(A, B), C, D) :-\n",
" value(A, C, E),\n",
" value(B, C, F),\n",
" and(E, F, D).\n",
"value(or(A, B), C, D) :-\n",
" value(A, C, E),\n",
" value(B, C, F),\n",
" or(E, F, D).\n",
"value(not(A), B, C) :-\n",
" value(A, B, D),\n",
" not(D, C).\n",
"value(implies(A, B), C, D) :-\n",
" value(or(not(A), B), C, D).\n",
"value(equiv(A, B), C, D) :-\n",
" value(and(implies(A, B), implies(B, A)),\n",
" C,\n",
" D).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:value/3\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"source": [
"value(X,Interpretation,Value) :- \n",
"value(X,Interpretation,Value) :- \n",
" atomic(X), % we could also use: proposition(X),\n",
" atomic(X), % we could also use: proposition(X),\n",
...
@@ -1143,7 +514,7 @@
...
@@ -1143,7 +514,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2
4
,
"execution_count": 2
5
,
"id": "eee17774",
"id": "eee17774",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -1213,78 +584,14 @@
...
@@ -1213,78 +584,14 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
35
,
"execution_count":
27
,
"id": "2ee60c15",
"id": "2ee60c15",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
"languageId": "prolog"
"languageId": "prolog"
}
}
},
},
"outputs": [
"outputs": [],
{
"data": {
"text/html": [
"\n",
" <style>\n",
" details {\n",
" font-family: Menlo, Consolas, 'DejaVu Sans Mono', monospace; font-size: 13px;\n",
" }\n",
"\n",
" details > summary {\n",
" cursor: pointer;\n",
" }\n",
" </style>\n",
" <details><summary>Previously defined clauses of user:subnode_val/4 were retracted (click to expand)</summary><pre>:- dynamic subnode_val/4.\n",
"\n",
"subnode_val(A, [shape/B, label/C, style/filled, fillcolor/D], E, F) :-\n",
" rec_subtree(E, A),\n",
" functor(A, C, _),\n",
" ( atom(A)\n",
" -> B=egg\n",
" ; number(A)\n",
" -> B=oval\n",
" ; B=rect\n",
" ),\n",
" ( value(A, F, true)\n",
" -> D=olive\n",
" ; D=salmon1\n",
" ).\n",
"</pre></details>"
],
"text/plain": [
"Previously defined clauses of user:subnode_val/4 were retracted:\n",
":- dynamic subnode_val/4.\n",
"\n",
"subnode_val(A, [shape/B, label/C, style/filled, fillcolor/D], E, F) :-\n",
" rec_subtree(E, A),\n",
" functor(A, C, _),\n",
" ( atom(A)\n",
" -> B=egg\n",
" ; number(A)\n",
" -> B=oval\n",
" ; B=rect\n",
" ),\n",
" ( value(A, F, true)\n",
" -> D=olive\n",
" ; D=salmon1\n",
" ).\n"
]
},
"metadata": {
"application/json": {}
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"% Asserting clauses for user:subnode_val/4\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"source": [
"\n",
"\n",
"subnode_val(Sub,[shape/S, label/F, style/filled, fillcolor/C],Formula,Interpretation) :- \n",
"subnode_val(Sub,[shape/S, label/F, style/filled, fillcolor/C],Formula,Interpretation) :- \n",
...
@@ -1295,7 +602,7 @@
...
@@ -1295,7 +602,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
39
,
"execution_count":
28
,
"id": "2b497dad",
"id": "2b497dad",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -1340,7 +647,7 @@
...
@@ -1340,7 +647,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
38
,
"execution_count":
29
,
"id": "0fd23f05",
"id": "0fd23f05",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
...
@@ -1385,13 +692,37 @@
...
@@ -1385,13 +692,37 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
30
,
"id": "23775624",
"id": "23775624",
"metadata": {
"metadata": {
"vscode": {
"vscode": {
"languageId": "prolog"
"languageId": "prolog"
}
}
},
},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[1mtrue"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"?- use_module(library(clpfd))."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a6e29ed",
"metadata": {
"vscode": {
"languageId": "prolog"
}
},
"outputs": [],
"outputs": [],
"source": []
"source": []
}
}
...
...
%% Cell type:markdown id:9eb5530a tags:
%% Cell type:markdown id:9eb5530a tags:
# Propositional Logic
# Propositional Logic
Syntax and Semantics Explained using a Prolog Implementation
Syntax and Semantics Explained using a Prolog Implementation
%% Cell type:markdown id:dba70591 tags:
%% Cell type:markdown id:dba70591 tags:
## Well-Formed Formulas (WFF)
## Well-Formed Formulas (WFF)
All atomic propositions are WFF)
All atomic propositions are WFF)
If a und b are WFF then so are:
If a und b are WFF then so are:
-
(¬ a)
-
(¬ a)
-
(a ∧ b)
-
(a ∧ b)
-
(a ∨ b)
-
(a ∨ b)
-
(a ⇒ b)
-
(a ⇒ b)
-
(a ⟺ b)
-
(a ⟺ b)
No other formulas are WFF.
No other formulas are WFF.
Comment: a, b are metavariablens outside the syntax of propositional logic.
Comment: a, b are metavariablens outside the syntax of propositional logic.
%% Cell type:markdown id:dd01f86a tags:
%% Cell type:markdown id:dd01f86a tags:
Maybe this reminds you of formal grammars from a theoretical computer science lecture.
Maybe this reminds you of formal grammars from a theoretical computer science lecture.
And indeed, the above can be written as a grammar using a non-terminal symbol wff.
And indeed, the above can be written as a grammar using a non-terminal symbol wff.
In Prolog, grammars can actually be written using DCG notation, which we will see and understand much later in the course.
In Prolog, grammars can actually be written using DCG notation, which we will see and understand much later in the course.
Here we simply write the grammar in Prolog style and can then use it to check if a formula is a WFF:
Here we simply write the grammar in Prolog style and can then use it to check if a formula is a WFF:
%% Cell type:code id:964ebd52 tags:
%% Cell type:code id:964ebd52 tags:
```
prolog
```
prolog
:-
set_prolog_flag
(
double_quotes
,
codes
).
:-
set_prolog_flag
(
double_quotes
,
codes
).
wff
-->
"p"
.
% atomic proposition
wff
-->
"p"
.
% atomic proposition
wff
-->
"q"
.
% atomic proposition
wff
-->
"q"
.
% atomic proposition
wff
-->
"(¬"
,
wff
,
")"
.
wff
-->
"(¬"
,
wff
,
")"
.
wff
-->
"("
,
wff
,
"∧"
,
wff
,
")"
.
wff
-->
"("
,
wff
,
"∧"
,
wff
,
")"
.
wff
-->
"("
,
wff
,
"∨"
,
wff
,
")"
.
wff
-->
"("
,
wff
,
"∨"
,
wff
,
")"
.
wff
-->
"("
,
wff
,
"⇒"
,
wff
,
")"
.
wff
-->
"("
,
wff
,
"⇒"
,
wff
,
")"
.
wff
-->
"("
,
wff
,
"⟺"
,
wff
,
")"
.
wff
-->
"("
,
wff
,
"⟺"
,
wff
,
")"
.
```
```
%% Output
%% Output
%% Cell type:code id:fc6823ad tags:
%% Cell type:code id:fc6823ad tags:
```
prolog
```
prolog
?-
wff
(
"p"
,
""
).
?-
wff
(
"p"
,
""
).
```
```
%% Output
%% Output
%% Cell type:code id:152289b6 tags:
%% Cell type:code id:152289b6 tags:
```
prolog
```
prolog
?-
wff
(
"(¬p)"
,
""
).
?-
wff
(
"(¬p)"
,
""
).
```
```
%% Output
%% Output
%% Cell type:code id:2c3dd1bf tags:
%% Cell type:code id:2c3dd1bf tags:
```
prolog
```
prolog
?-
wff
(
"(p∧(q∨(¬p)))"
,
""
).
?-
wff
(
"(p∧(q∨(¬p)))"
,
""
).
%comment.
%comment.
```
```
%% Output
%% Output
%% Cell type:markdown id:38b0a282 tags:
This grammar does not talk about whitespace and requires parentheses for every connective used.
In practice, one typically uses operator precedences to avoid having to write too many parentheses:
-
negation binds strongest
-
then come conjunction and disjunction
-
then come implication and equivalence.
So instead of
-
(((¬ p) ∧ (¬ q)) ⇒ ((¬ p) ∨ (¬ q)))
we can write
-
¬ p ∧ ¬ q ⇒ ¬ p ∨ ¬ q
We will try not not mix conjunction/disjunction and implication/equivalence without parentheses.
We will also not try to improve our Prolog parser here to accomodate these precedences.
This is the subject of another course (on compiler construction).
%% Cell type:markdown id:92b6dc2d tags:
%% Cell type:markdown id:92b6dc2d tags:
We will also see much later that Prolog allows one to annotate grammars with semantic values, here to generate
We will also see much later that Prolog allows one to annotate grammars with semantic values, here to generate
a Prolog term representing the logical formal in the form of a syntax tree:
a Prolog term representing the logical formal in the form of a syntax tree:
%% Cell type:code id:78163b60 tags:
%% Cell type:code id:78163b60 tags:
```
prolog
```
prolog
:-
set_prolog_flag
(
double_quotes
,
codes
).
:-
set_prolog_flag
(
double_quotes
,
codes
).
wff
(
p
)
-->
"p"
.
% atomic proposition
wff
(
p
)
-->
"p"
.
% atomic proposition
wff
(
q
)
-->
"q"
.
% atomic proposition
wff
(
q
)
-->
"q"
.
% atomic proposition
wff
(
not
(
A
))
-->
"(¬"
,
wff
(
A
),
")"
.
wff
(
not
(
A
))
-->
"(¬"
,
wff
(
A
),
")"
.
wff
(
and
(
A
,
B
))
-->
"("
,
wff
(
A
),
"∧"
,
wff
(
B
),
")"
.
wff
(
and
(
A
,
B
))
-->
"("
,
wff
(
A
),
"∧"
,
wff
(
B
),
")"
.
wff
(
or
(
A
,
B
))
-->
"("
,
wff
(
A
),
"∨"
,
wff
(
B
),
")"
.
wff
(
or
(
A
,
B
))
-->
"("
,
wff
(
A
),
"∨"
,
wff
(
B
),
")"
.
wff
(
impl
(
A
,
B
))
-->
"("
,
wff
(
A
),
"⇒"
,
wff
(
B
),
")"
.
wff
(
impl
(
A
,
B
))
-->
"("
,
wff
(
A
),
"⇒"
,
wff
(
B
),
")"
.
wff
(
equiv
(
A
,
B
))
-->
"("
,
wff
(
A
),
"⟺"
,
wff
(
B
),
")"
.
wff
(
equiv
(
A
,
B
))
-->
"("
,
wff
(
A
),
"⟺"
,
wff
(
B
),
")"
.
```
```
%% Output
%% Cell type:code id:8ddb568d tags:
%% Cell type:code id:8ddb568d tags:
```
prolog
```
prolog
?-
wff
(
Formula
,
"(¬p)"
,
""
).
?-
wff
(
Formula
,
"(¬p)"
,
""
).
```
```
%% Output
%% Output
%% Cell type:code id:075dc3b2 tags:
%% Cell type:code id:075dc3b2 tags:
```
prolog
```
prolog
?-
wff
(
Formula
,
"(¬(p∧q))"
,
""
).
?-
wff
(
Formula
,
"(¬(p∧q))"
,
""
).
```
```
%% Output
%% Output
%% Cell type:code id:338cb7dd tags:
%% Cell type:code id:338cb7dd tags:
```
prolog
```
prolog
?-
wff
(
Formula
,
"(p∧(q∨(¬p)))"
,
""
).
?-
wff
(
Formula
,
"(p∧(q∨(¬p)))"
,
""
).
```
```
%% Output
%% Output
%% Cell type:markdown id:f9005519 tags:
%% Cell type:markdown id:f9005519 tags:
The above Prolog term
`and(p,or(q,not(p)))`
represents the logical formula in tree form.
The above Prolog term
`and(p,or(q,not(p)))`
represents the logical formula in tree form.
We can display the tree as a dag (directed acyclic graph) using the following subsidiary code
We can display the tree as a dag (directed acyclic graph) using the following subsidiary code
(in future the Jupyter kernel will probably have a dedicated command to show a term graphically):
(in future the Jupyter kernel will probably have a dedicated command to show a term graphically):
%% Cell type:code id:f6116612 tags:
%% Cell type:code id:f6116612 tags:
```
prolog
```
prolog
subtree
(
Term
,
Nr
,
SubTerm
)
:-
subtree
(
Term
,
Nr
,
SubTerm
)
:-
Term
=..
[
_
|
ArgList
],
%obtain arguments of the term
Term
=..
[
_
|
ArgList
],
%obtain arguments of the term
nth1
(
Nr
,
ArgList
,
SubTerm
).
% get sub-argument and its position number
nth1
(
Nr
,
ArgList
,
SubTerm
).
% get sub-argument and its position number
% recursive and transitive closure of subtree
% recursive and transitive closure of subtree
rec_subtree
(
Term
,
Sub
)
:-
Term
=
Sub
.
rec_subtree
(
Term
,
Sub
)
:-
Term
=
Sub
.
rec_subtree
(
Term
,
Sub
)
:-
subtree
(
Term
,
_
,
X
),
rec_subtree
(
X
,
Sub
).
rec_subtree
(
Term
,
Sub
)
:-
subtree
(
Term
,
_
,
X
),
rec_subtree
(
X
,
Sub
).
subnode
(
Sub
,[
shape
/
S
,
label
/
F
],
Formula
)
:-
subnode
(
Sub
,[
shape
/
S
,
label
/
F
],
Formula
)
:-
rec_subtree
(
Formula
,
Sub
),
% any sub-formula Sub of Formula is a node in the graphical rendering
rec_subtree
(
Formula
,
Sub
),
% any sub-formula Sub of Formula is a node in the graphical rendering
functor
(
Sub
,
F
,
_
),
(
atom
(
Sub
)
->
S
=
egg
;
number
(
Sub
)
->
S
=
oval
;
S
=
rect
).
functor
(
Sub
,
F
,
_
),
(
atom
(
Sub
)
->
S
=
egg
;
number
(
Sub
)
->
S
=
oval
;
S
=
rect
).
```
```
%% Output
%% Cell type:code id:d7e68593 tags:
%% Cell type:code id:d7e68593 tags:
```
prolog
```
prolog
jupyter
:
print_table
(
subnode
(
Node
,
Dot
,
and
(
p
,
or
(
q
,
not
(
p
)))))
jupyter
:
print_table
(
subnode
(
Node
,
Dot
,
and
(
p
,
or
(
q
,
not
(
p
)))))
```
```
%% Output
%% Output
Node | Dot |
Node | Dot |
:- | :- |
:- | :- |
and(p,or(q,not(p))) | [shape/rect,label/and] |
and(p,or(q,not(p))) | [shape/rect,label/and] |
p | [shape/egg,label/p] |
p | [shape/egg,label/p] |
or(q,not(p)) | [shape/rect,label/or] |
or(q,not(p)) | [shape/rect,label/or] |
q | [shape/egg,label/q] |
q | [shape/egg,label/q] |
not(p) | [shape/rect,label/not] |
not(p) | [shape/rect,label/not] |
p | [shape/egg,label/p] |
p | [shape/egg,label/p] |
%% Cell type:code id:3646e3ee tags:
%% Cell type:code id:3646e3ee tags:
```
prolog
```
prolog
jupyter
:
show_graph
(
subnode
(
_
,
_
,
and
(
p
,
or
(
q
,
not
(
p
)))),
subtree
/
3
)
jupyter
:
show_graph
(
subnode
(
_
,
_
,
and
(
p
,
or
(
q
,
not
(
p
)))),
subtree
/
3
)
```
```
%% Output
%% Output
%% Cell type:markdown id:11b3a8ad tags:
%% Cell type:markdown id:11b3a8ad tags:
Below we will study how one can assign a truth-value to logical formulas like the one above.
Below we will study how one can assign a truth-value to logical formulas like the one above.
## Truth tables
## Truth tables
Every logical connective has a truth-table, indicating how it maps the truth of its arguments to its own truth value.
Every logical connective has a truth-table, indicating how it maps the truth of its arguments to its own truth value.
For example,
`and`
maps inputs
`true`
and
`false`
to
`false`
.
For example,
`and`
maps inputs
`true`
and
`false`
to
`false`
.
%% Cell type:code id:350b9756 tags:
%% Cell type:code id:350b9756 tags:
```
prolog
```
prolog
not
(
true
,
false
).
not
(
true
,
false
).
not
(
false
,
true
).
not
(
false
,
true
).
and
(
true
,
V
,
V
)
:-
truth_value
(
V
).
and
(
true
,
V
,
V
)
:-
truth_value
(
V
).
and
(
false
,
_
,
false
).
and
(
false
,
_
,
false
).
or
(
true
,
_
,
true
).
or
(
true
,
_
,
true
).
or
(
false
,
V
,
V
)
:-
truth_value
(
V
).
or
(
false
,
V
,
V
)
:-
truth_value
(
V
).
implies
(
A
,
B
,
Res
)
:-
not
(
A
,
NotA
),
or
(
NotA
,
B
,
Res
).
implies
(
A
,
B
,
Res
)
:-
not
(
A
,
NotA
),
or
(
NotA
,
B
,
Res
).
equiv
(
A
,
B
,
Res
)
:-
implies
(
A
,
B
,
AiB
),
implies
(
B
,
A
,
BiA
),
and
(
AiB
,
BiA
,
Res
).
equiv
(
A
,
B
,
Res
)
:-
implies
(
A
,
B
,
AiB
),
implies
(
B
,
A
,
BiA
),
and
(
AiB
,
BiA
,
Res
).
truth_value
(
true
).
truth_value
(
true
).
truth_value
(
false
).
truth_value
(
false
).
truth_table
(
A
,
B
,
NotA
,
AandB
,
AorB
,
AiB
,
AeB
)
:-
truth_table
(
A
,
B
,
NotA
,
AandB
,
AorB
,
AiB
,
AeB
)
:-
truth_value
(
A
),
truth_value
(
B
),
truth_value
(
A
),
truth_value
(
B
),
not
(
A
,
NotA
),
and
(
A
,
B
,
AandB
),
or
(
A
,
B
,
AorB
),
not
(
A
,
NotA
),
and
(
A
,
B
,
AandB
),
or
(
A
,
B
,
AorB
),
implies
(
A
,
B
,
AiB
),
equiv
(
A
,
B
,
AeB
).
implies
(
A
,
B
,
AiB
),
equiv
(
A
,
B
,
AeB
).
```
```
%% Output
%% Cell type:code id:54b57ff8 tags:
%% Cell type:code id:54b57ff8 tags:
```
prolog
```
prolog
jupyter
:
print_table
(
truth_table
(
A
,
B
,
NotA
,
AandB
,
AorB
,
AimpliesB
,
AequivB
))
jupyter
:
print_table
(
truth_table
(
A
,
B
,
NotA
,
AandB
,
AorB
,
AimpliesB
,
AequivB
))
```
```
%% Output
%% Output
A | B | NotA | AandB | AorB | AimpliesB | AequivB |
A | B | NotA | AandB | AorB | AimpliesB | AequivB |
:- | :- | :- | :- | :- | :- | :- |
:- | :- | :- | :- | :- | :- | :- |
true | true | false | true | true | true | true |
true | true | false | true | true | true | true |
true | false | false | false | true | false | false |
true | false | false | false | true | false | false |
false | true | true | false | true | true | false |
false | true | true | false | true | true | false |
false | false | true | false | false | true | true |
false | false | true | false | false | true | true |
%% Cell type:code id:175c00d0 tags:
%% Cell type:code id:175c00d0 tags:
```
prolog
```
prolog
value
(
X
,
Interpretation
,
Value
)
:-
value
(
X
,
Interpretation
,
Value
)
:-
atomic
(
X
),
% we could also use: proposition(X),
atomic
(
X
),
% we could also use: proposition(X),
member
(
X
/
Value
,
Interpretation
).
member
(
X
/
Value
,
Interpretation
).
value
(
and
(
A
,
B
),
I
,
Val
)
:-
value
(
A
,
I
,
VA
),
value
(
B
,
I
,
VB
),
value
(
and
(
A
,
B
),
I
,
Val
)
:-
value
(
A
,
I
,
VA
),
value
(
B
,
I
,
VB
),
and
(
VA
,
VB
,
Val
).
and
(
VA
,
VB
,
Val
).
value
(
or
(
A
,
B
),
I
,
Val
)
:-
value
(
A
,
I
,
VA
),
value
(
B
,
I
,
VB
),
value
(
or
(
A
,
B
),
I
,
Val
)
:-
value
(
A
,
I
,
VA
),
value
(
B
,
I
,
VB
),
or
(
VA
,
VB
,
Val
).
or
(
VA
,
VB
,
Val
).
value
(
not
(
A
),
I
,
Val
)
:-
value
(
A
,
I
,
VA
),
value
(
not
(
A
),
I
,
Val
)
:-
value
(
A
,
I
,
VA
),
not
(
VA
,
Val
).
not
(
VA
,
Val
).
value
(
implies
(
A
,
B
),
I
,
Val
)
:-
value
(
or
(
not
(
A
),
B
),
I
,
Val
).
value
(
implies
(
A
,
B
),
I
,
Val
)
:-
value
(
or
(
not
(
A
),
B
),
I
,
Val
).
value
(
equiv
(
A
,
B
),
I
,
Val
)
:-
value
(
equiv
(
A
,
B
),
I
,
Val
)
:-
value
(
and
(
implies
(
A
,
B
),
implies
(
B
,
A
)),
I
,
Val
).
value
(
and
(
implies
(
A
,
B
),
implies
(
B
,
A
)),
I
,
Val
).
```
```
%% Output
%% Cell type:code id:eee17774 tags:
%% Cell type:code id:eee17774 tags:
```
prolog
```
prolog
?-
value
(
and
(
p
,
or
(
q
,
not
(
p
))),
[
p
/
true
,
q
/
false
],
Res
).
?-
value
(
and
(
p
,
or
(
q
,
not
(
p
))),
[
p
/
true
,
q
/
false
],
Res
).
```
```
%% Output
%% Output
%% Cell type:code id:78473da0 tags:
%% Cell type:code id:78473da0 tags:
```
prolog
```
prolog
jupyter
:
print_table
(
value
(
and
(
p
,
or
(
q
,
not
(
p
))),
[
p
/
P
,
q
/
Q
],
Res
))
jupyter
:
print_table
(
value
(
and
(
p
,
or
(
q
,
not
(
p
))),
[
p
/
P
,
q
/
Q
],
Res
))
```
```
%% Output
%% Output
P | Q | Res |
P | Q | Res |
:- | :- | :- |
:- | :- | :- |
true | true | true |
true | true | true |
true | false | false |
true | false | false |
false | true | false |
false | true | false |
false | false | false |
false | false | false |
%% Cell type:code id:2ee60c15 tags:
%% Cell type:code id:2ee60c15 tags:
```
prolog
```
prolog
subnode_val
(
Sub
,[
shape
/
S
,
label
/
F
,
style
/
filled
,
fillcolor
/
C
],
Formula
,
Interpretation
)
:-
subnode_val
(
Sub
,[
shape
/
S
,
label
/
F
,
style
/
filled
,
fillcolor
/
C
],
Formula
,
Interpretation
)
:-
rec_subtree
(
Formula
,
Sub
),
% any sub-formula Sub of Formula is a node in the graphical rendering
rec_subtree
(
Formula
,
Sub
),
% any sub-formula Sub of Formula is a node in the graphical rendering
functor
(
Sub
,
F
,
_
),
(
atom
(
Sub
)
->
S
=
egg
;
number
(
Sub
)
->
S
=
oval
;
S
=
rect
),
functor
(
Sub
,
F
,
_
),
(
atom
(
Sub
)
->
S
=
egg
;
number
(
Sub
)
->
S
=
oval
;
S
=
rect
),
(
value
(
Sub
,
Interpretation
,
true
)
->
C
=
olive
;
C
=
sienna1
).
(
value
(
Sub
,
Interpretation
,
true
)
->
C
=
olive
;
C
=
sienna1
).
```
```
%% Output
%% Cell type:code id:2b497dad tags:
%% Cell type:code id:2b497dad tags:
```
prolog
```
prolog
jupyter
:
show_graph
(
subnode_val
(
_
,
_
,
and
(
p
,
or
(
q
,
not
(
p
))),[
p
/
true
,
q
/
false
]),
subtree
/
3
)
jupyter
:
show_graph
(
subnode_val
(
_
,
_
,
and
(
p
,
or
(
q
,
not
(
p
))),[
p
/
true
,
q
/
false
]),
subtree
/
3
)
```
```
%% Output
%% Output
%% Cell type:code id:0fd23f05 tags:
%% Cell type:code id:0fd23f05 tags:
```
prolog
```
prolog
jupyter
:
show_graph
(
subnode_val
(
_
,
_
,
and
(
p
,
or
(
q
,
not
(
p
))),[
p
/
true
,
q
/
true
]),
subtree
/
3
)
jupyter
:
show_graph
(
subnode_val
(
_
,
_
,
and
(
p
,
or
(
q
,
not
(
p
))),[
p
/
true
,
q
/
true
]),
subtree
/
3
)
```
```
%% Output
%% Output
%% Cell type:code id:23775624 tags:
%% Cell type:code id:23775624 tags:
```
prolog
```
prolog
?-
use_module
(
library
(
clpfd
)).
```
%% Output
%% Cell type:code id:7a6e29ed tags:
```
prolog
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment