diff --git a/logic_programming/2_IntroProlog.ipynb b/logic_programming/2_IntroProlog.ipynb index aa66247f5753275ebfd488269c6ff2d7456fb8e0..ffca183a0452fce1ff804f40ff0b2b6671e9642a 100644 --- a/logic_programming/2_IntroProlog.ipynb +++ b/logic_programming/2_IntroProlog.ipynb @@ -22,173 +22,14 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 2, "id": "93e05f7b-a91c-4262-861e-a399e094b710", "metadata": { "vscode": { "languageId": "prolog" } }, - "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:rains/0 were retracted (click to expand)</summary><pre>:- dynamic rains/0.\n", - "\n", - "rains.\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:rains/0 were retracted:\n", - ":- dynamic rains/0.\n", - "\n", - "rains.\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:rains/0\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:I am not wearing a hat/0 were retracted (click to expand)</summary><pre>:- dynamic'I am not wearing a hat'/0.\n", - "\n", - "'I am not wearing a hat'.\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:I am not wearing a hat/0 were retracted:\n", - ":- dynamic'I am not wearing a hat'/0.\n", - "\n", - "'I am not wearing a hat'.\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:I am not wearing a hat/0\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:The sun is shining/0 were retracted (click to expand)</summary><pre>:- dynamic'The sun is shining'/0.\n", - "\n", - "'The sun is shining'.\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:The sun is shining/0 were retracted:\n", - ":- dynamic'The sun is shining'/0.\n", - "\n", - "'The sun is shining'.\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:The sun is shining/0\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:beach/0 were retracted (click to expand)</summary><pre>:- dynamic beach/0.\n", - "\n", - "beach :-\n", - " fail.\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:beach/0 were retracted:\n", - ":- dynamic beach/0.\n", - "\n", - "beach :-\n", - " fail.\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:beach/0\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "rains.\n", "'I am not wearing a hat'.\n", @@ -230,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 4, "id": "20b05b2c", "metadata": { "vscode": { @@ -262,101 +103,14 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 5, "id": "2b8b84a0", "metadata": { "vscode": { "languageId": "prolog" } }, - "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:carry_umbrella/0 were retracted (click to expand)</summary><pre>:- dynamic carry_umbrella/0.\n", - "\n", - "carry_umbrella :-\n", - " rains,\n", - " 'I am not wearing a hat'.\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:carry_umbrella/0 were retracted:\n", - ":- dynamic carry_umbrella/0.\n", - "\n", - "carry_umbrella :-\n", - " rains,\n", - " 'I am not wearing a hat'.\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:carry_umbrella/0\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:rainbow/0 were retracted (click to expand)</summary><pre>:- dynamic rainbow/0.\n", - "\n", - "rainbow :-\n", - " rains,\n", - " 'The sun is shining'.\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:rainbow/0 were retracted:\n", - ":- dynamic rainbow/0.\n", - "\n", - "rainbow :-\n", - " rains,\n", - " 'The sun is shining'.\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:rainbow/0\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "carry_umbrella :- rains, 'I am not wearing a hat'.\n", "rainbow :- rains, 'The sun is shining'." @@ -364,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 6, "id": "4e6314e8", "metadata": { "vscode": { @@ -957,106 +711,20 @@ "metadata": {}, "source": [ "## Exercise\n", - "Let us try exercise 2.1.1 (iii) from the Art of Prolog (https://mitpress.mit.edu/9780262691635/the-art-of-prolog/), describing the layout of Figure 2.3 using `left_of/2` and `above/2`." + "Let us try exercise 2.1.1 (iii) from the Art of Prolog (https://mitpress.mit.edu/9780262691635/the-art-of-prolog/), describing the layout of Figure 2.3 using `left_of/2` and `above/2`.\n", + "" ] }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 10, "id": "9e3be61b", "metadata": { "vscode": { "languageId": "prolog" } }, - "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:left_of/2 were retracted (click to expand)</summary><pre>:- dynamic left_of/2.\n", - "\n", - "left_of(bicycle, camera).\n", - "left_of(pencil, hourglass).\n", - "left_of(hourglass, butterfly).\n", - "left_of(butterfly, fish).\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:left_of/2 were retracted:\n", - ":- dynamic left_of/2.\n", - "\n", - "left_of(bicycle, camera).\n", - "left_of(pencil, hourglass).\n", - "left_of(hourglass, butterfly).\n", - "left_of(butterfly, fish).\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:left_of/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:above/2 were retracted (click to expand)</summary><pre>:- dynamic above/2.\n", - "\n", - "above(bicycle, pencil).\n", - "above(camera, butterfly).\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:above/2 were retracted:\n", - ":- dynamic above/2.\n", - "\n", - "above(bicycle, pencil).\n", - "above(camera, butterfly).\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:above/2\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "left_of(bicycle,camera).\n", "left_of(pencil,hourglass).\n", @@ -1079,60 +747,14 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 11, "id": "6781d789", "metadata": { "vscode": { "languageId": "prolog" } }, - "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:edge/3 were retracted (click to expand)</summary><pre>:- dynamic edge/3.\n", - "\n", - "edge(A, above, B) :-\n", - " above(A, B).\n", - "edge(A, left_of, B) :-\n", - " left_of(A, B).\n", - "</pre></details>" - ], - "text/plain": [ - "Previously defined clauses of user:edge/3 were retracted:\n", - ":- dynamic edge/3.\n", - "\n", - "edge(A, above, B) :-\n", - " above(A, B).\n", - "edge(A, left_of, B) :-\n", - " left_of(A, B).\n" - ] - }, - "metadata": { - "application/json": {} - }, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "% Asserting clauses for user:edge/3\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "edge(A,above,B) :- above(A,B).\n", "edge(A,left_of,B) :- left_of(A,B)." @@ -1140,7 +762,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 12, "id": "bb98ad05", "metadata": { "vscode": { diff --git a/logic_programming/img/art_prolog_figure_2_3.svg b/logic_programming/img/art_prolog_figure_2_3.svg new file mode 100644 index 0000000000000000000000000000000000000000..1acc0a0f76d62c2c46fb51525d8e771e07db15a3 --- /dev/null +++ b/logic_programming/img/art_prolog_figure_2_3.svg @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns:dc="http://purl.org/dc/elements/1.1/" version="1.1" xmlns:xl="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" viewBox="141 178 358 157" width="358" height="157"> + <defs/> + <g id="Canvas_1" stroke-dasharray="none" fill="none" stroke-opacity="1" fill-opacity="1" stroke="none"> + <title>Canvas 1</title> + <rect fill="white" x="141" y="178" width="358" height="157"/> + <g id="Canvas_1_Layer_1"> + <title>Layer 1</title> + <g id="Graphic_2"> + <text transform="translate(146.59806 183.26172)" fill="black"> + <tspan font-family="Apple Color Emoji" font-size="48" fill="black" x="0" y="48" xml:space="preserve">🚲</tspan> + </text> + </g> + <g id="Graphic_3"> + <text transform="translate(349.41056 183.26172)" fill="black"> + <tspan font-family="Apple Color Emoji" font-size="48" fill="black" x="0" y="48" xml:space="preserve">📷</tspan> + </text> + </g> + <g id="Graphic_4"> + <text transform="translate(146.59806 266.86328)" fill="black"> + <tspan font-family="Apple Color Emoji" font-size="48" fill="black" x="0" y="48" xml:space="preserve">✏️</tspan> + </text> + </g> + <g id="Graphic_5"> + <text transform="translate(253.41056 266.86328)" fill="black"> + <tspan font-family="Apple Color Emoji" font-size="48" fill="black" x="0" y="48" xml:space="preserve">⏳ 🦋 🐟</tspan> + </text> + </g> + </g> + </g> +</svg>