diff --git a/logic_programming/1_IntroProlog.ipynb b/logic_programming/1_IntroProlog.ipynb index 328498427d5ac5b645a90e4077c46f4cd5aea459..a54008435e7ae2030fddeb66178dc799851679c9 100644 --- a/logic_programming/1_IntroProlog.ipynb +++ b/logic_programming/1_IntroProlog.ipynb @@ -13,6 +13,7 @@ "id": "49fd5211", "metadata": {}, "source": [ + "### Propositions\n", "Prolog programs consist of <b>clauses</b>.\n", "A clause is always terminated by a dot (```.```).\n", "The simplest clauses are facts. Here we define two propositions to be true:" @@ -151,6 +152,7 @@ "id": "d7254b1b", "metadata": {}, "source": [ + "### Predicates\n", "Instead of propositions we can also use predicates with arguments within our clauses. The arguments to predicates denote objects for which the predicate is true. Arguments which start with an upper-case letter are logical variables. Below ```X``` is such a variable and it can stand for any object." ] }, @@ -466,6 +468,60 @@ "jupyter:retry" ] }, + { + "cell_type": "markdown", + "id": "3dce4ccd", + "metadata": {}, + "source": [ + "Jupyter provides a feature to compute all solutions of a goal and display them in a table:" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "4d656338", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/markdown": [ + "X | \n", + ":- | \n", + "sokrates | \n", + "schopenhauer | \n", + "locke | \n", + "hobbes | " + ], + "text/plain": [ + "X | \n", + ":- | \n", + "sokrates | \n", + "schopenhauer | \n", + "locke | \n", + "hobbes | " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "\u001b[1mtrue" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "jupyter:print_table(mortal(X))" + ] + }, { "cell_type": "markdown", "id": "d90546b0", @@ -503,6 +559,7 @@ "id": "74c96ce2", "metadata": {}, "source": [ + "### Prolog lists and using append\n", "The result is a Prolog list. Lists play an important role in Prolog and they can be written using square brackets. ```[]``` denotes the empty list. The built-in predicate ```append``` can be used to concatenate two lists:" ] }, @@ -794,9 +851,19 @@ "?-append(_,[X],[a,b,c,d])." ] }, + { + "cell_type": "markdown", + "id": "466ece27", + "metadata": {}, + "source": [ + "### Family tree example\n", + "\n", + "We now load a Prolog file describing the family tree of \"Game of Thrones\"." + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "id": "5627c07e", "metadata": { "vscode": { @@ -804,6 +871,553 @@ } }, "outputs": [], + "source": [ + ":- consult('prolog_files/1_got_family_tree.pl')." + ] + }, + { + "cell_type": "markdown", + "id": "068e1fdc", + "metadata": {}, + "source": [ + "It contains facts for four basic predicates male/1, female/1, child/2 and couple/2." + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "428e3101", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[1mX = Aegon V Targaryen" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "?-male(X)." + ] + }, + { + "cell_type": "markdown", + "id": "c2a8192b", + "metadata": {}, + "source": [ + "We an now find the parents of X:" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "5134897e", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[1mX = Aegon V Targaryen,\n", + "Y = Maekar Targaryen" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "?-male(X),child(X,Y)." + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "cd9a4bf2", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "% Retrying goal: male(X),child(X,Y)\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "\u001b[1mX = Aegon V Targaryen,\n", + "Y = Dyanna Dayne" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "jupyter:retry." + ] + }, + { + "cell_type": "markdown", + "id": "fa7eb5e5", + "metadata": {}, + "source": [ + "Let us now define derived predicates for father and mother:" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "edfb9af1", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "% Asserting clauses for user:father/2\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "% Asserting clauses for user:mother/2\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "father(A,B) :- child(B,A),male(A).\n", + "mother(A,B) :- child(B,A),female(A)." + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "e8aaec06", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[1mA = Eddard Stark" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "?-father(A,'Sansa Stark')." + ] + }, + { + "cell_type": "markdown", + "id": "53b594a2", + "metadata": {}, + "source": [ + "We can visualise the father/mother relationships in graphical way in Jupyter:" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "d4664fd8", + "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:parent_relation/3 were retracted (click to expand)</summary><pre>:- dynamic parent_relation/3.\n", + "\n", + "parent_relation(A, B, father) :-\n", + " father(A, B).\n", + "parent_relation(A, B, mother) :-\n", + " mother(A, B).\n", + "</pre></details>" + ], + "text/plain": [ + "Previously defined clauses of user:parent_relation/3 were retracted:\n", + ":- dynamic parent_relation/3.\n", + "\n", + "parent_relation(A, B, father) :-\n", + " father(A, B).\n", + "parent_relation(A, B, mother) :-\n", + " mother(A, B).\n" + ] + }, + "metadata": { + "application/json": {} + }, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "% Asserting clauses for user:parent_relation/3\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "parent_relation(A,B,'father') :- father(A,B).\n", + "parent_relation(A,B,'mother') :- mother(A,B)." + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "08715fa2", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 6.0.1 (20220911.1526)\n -->\n<!-- Pages: 1 -->\n<svg width=\"1921pt\" height=\"392pt\"\n viewBox=\"0.00 0.00 1920.79 392.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 388)\">\n<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-388 1916.79,-388 1916.79,4 -4,4\"/>\n<!-- Maekar Targaryen -->\n<g id=\"node1\" class=\"node\">\n<title>Maekar Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"499.24\" cy=\"-366\" rx=\"75.29\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"499.24\" y=\"-362.3\" font-family=\"Times,serif\" font-size=\"14.00\">Maekar Targaryen</text>\n</g>\n<!-- Aegon V Targaryen -->\n<g id=\"node2\" class=\"node\">\n<title>Aegon V Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"764.24\" cy=\"-279\" rx=\"79.89\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"764.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Aegon V Targaryen</text>\n</g>\n<!-- Maekar Targaryen->Aegon V Targaryen -->\n<g id=\"edge1\" class=\"edge\">\n<title>Maekar Targaryen->Aegon V Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M545,-351.65C561.35,-346.02 579.6,-338.73 595.24,-330 604.64,-324.76 604.55,-319.67 614.24,-315 628.76,-308.01 662.86,-299.84 694.88,-293.16\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"695.64,-296.57 704.73,-291.13 694.23,-289.72 695.64,-296.57\"/>\n<text text-anchor=\"middle\" x=\"630.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Aerion Targaryen -->\n<g id=\"node3\" class=\"node\">\n<title>Aerion Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"593.24\" cy=\"-279\" rx=\"72.59\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"593.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Aerion Targaryen</text>\n</g>\n<!-- Maekar Targaryen->Aerion Targaryen -->\n<g id=\"edge2\" class=\"edge\">\n<title>Maekar Targaryen->Aerion Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M495.06,-347.76C493.57,-337.36 493.63,-324.36 500.24,-315 506.65,-305.94 515.7,-299.22 525.68,-294.25\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"527.28,-297.36 535.04,-290.14 524.48,-290.95 527.28,-297.36\"/>\n<text text-anchor=\"middle\" x=\"516.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Aemon Targaryen -->\n<g id=\"node4\" class=\"node\">\n<title>Aemon Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"427.24\" cy=\"-279\" rx=\"74.99\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"427.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Aemon Targaryen</text>\n</g>\n<!-- Maekar Targaryen->Aemon Targaryen -->\n<g id=\"edge3\" class=\"edge\">\n<title>Maekar Targaryen->Aemon Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M467.89,-349.51C459.64,-344.24 451.35,-337.7 445.24,-330 439.92,-323.29 436.09,-314.88 433.37,-306.87\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"436.68,-305.71 430.49,-297.11 429.97,-307.69 436.68,-305.71\"/>\n<text text-anchor=\"middle\" x=\"461.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Duncan Targaryen -->\n<g id=\"node5\" class=\"node\">\n<title>Duncan Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"758.24\" cy=\"-192\" rx=\"75.29\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"758.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Duncan Targaryen</text>\n</g>\n<!-- Aegon V Targaryen->Duncan Targaryen -->\n<g id=\"edge4\" class=\"edge\">\n<title>Aegon V Targaryen->Duncan Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M763.03,-260.8C762.21,-249.16 761.1,-233.55 760.17,-220.24\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"763.65,-219.9 759.46,-210.18 756.67,-220.4 763.65,-219.9\"/>\n<text text-anchor=\"middle\" x=\"778.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Aerys II Targaryen -->\n<g id=\"node6\" class=\"node\">\n<title>Aerys II Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"408.24\" cy=\"-192\" rx=\"77.19\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"408.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Aerys II Targaryen</text>\n</g>\n<!-- Aegon V Targaryen->Aerys II Targaryen -->\n<g id=\"edge5\" class=\"edge\">\n<title>Aegon V Targaryen->Aerys II Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M705.4,-266.64C657.4,-257.29 596.67,-245.22 591.24,-243 579.95,-238.37 579.5,-232.71 568.24,-228 551.7,-221.07 512.61,-212.47 477.22,-205.53\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"477.84,-202.09 467.35,-203.62 476.5,-208.96 477.84,-202.09\"/>\n<text text-anchor=\"middle\" x=\"607.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Rhaella Targaryen -->\n<g id=\"node7\" class=\"node\">\n<title>Rhaella Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"227.24\" cy=\"-192\" rx=\"75.29\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"227.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Rhaella Targaryen</text>\n</g>\n<!-- Aegon V Targaryen->Rhaella Targaryen -->\n<g id=\"edge6\" class=\"edge\">\n<title>Aegon V Targaryen->Rhaella Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M707.41,-266.25C696.75,-264.3 685.68,-262.45 675.24,-261 584.21,-248.36 560.18,-256.32 469.24,-243 407.09,-233.9 336.88,-218.85 288.15,-207.64\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"288.92,-204.23 278.39,-205.38 287.34,-211.04 288.92,-204.23\"/>\n<text text-anchor=\"middle\" x=\"485.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Daeron Targaryen -->\n<g id=\"node8\" class=\"node\">\n<title>Daeron Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"586.24\" cy=\"-192\" rx=\"74.19\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"586.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Daeron Targaryen</text>\n</g>\n<!-- Aegon V Targaryen->Daeron Targaryen -->\n<g id=\"edge7\" class=\"edge\">\n<title>Aegon V Targaryen->Daeron Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M741.86,-261.66C726.69,-251.09 705.91,-237.58 686.24,-228 672,-221.06 656.02,-214.83 641.09,-209.61\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"642.05,-206.24 631.45,-206.34 639.79,-212.87 642.05,-206.24\"/>\n<text text-anchor=\"middle\" x=\"729.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Rhaegar Targaryen -->\n<g id=\"node9\" class=\"node\">\n<title>Rhaegar Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"509.24\" cy=\"-105\" rx=\"77.19\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"509.24\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\">Rhaegar Targaryen</text>\n</g>\n<!-- Aerys II Targaryen->Rhaegar Targaryen -->\n<g id=\"edge8\" class=\"edge\">\n<title>Aerys II Targaryen->Rhaegar Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M428.2,-174.21C443.51,-161.32 464.83,-143.38 481.76,-129.13\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"484.28,-131.59 489.67,-122.47 479.77,-126.23 484.28,-131.59\"/>\n<text text-anchor=\"middle\" x=\"481.24\" y=\"-144.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Viserys Targaryen -->\n<g id=\"node10\" class=\"node\">\n<title>Viserys Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"255.24\" cy=\"-105\" rx=\"74.99\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"255.24\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\">Viserys Targaryen</text>\n</g>\n<!-- Aerys II Targaryen->Viserys Targaryen -->\n<g id=\"edge9\" class=\"edge\">\n<title>Aerys II Targaryen->Viserys Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M404.73,-173.87C401.63,-162.98 396.04,-149.39 386.24,-141 380.62,-136.18 348.85,-127.64 318.01,-120.2\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"318.61,-116.74 308.07,-117.83 316.98,-123.55 318.61,-116.74\"/>\n<text text-anchor=\"middle\" x=\"413.24\" y=\"-144.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Daenerys Targaryen -->\n<g id=\"node11\" class=\"node\">\n<title>Daenerys Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"81.24\" cy=\"-105\" rx=\"81.49\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"81.24\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\">Daenerys Targaryen</text>\n</g>\n<!-- Aerys II Targaryen->Daenerys Targaryen -->\n<g id=\"edge10\" class=\"edge\">\n<title>Aerys II Targaryen->Daenerys Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M352.01,-179.56C331,-174.05 307.37,-166.35 287.24,-156 277.67,-151.08 278.04,-145.44 268.24,-141 228.31,-122.89 214.34,-131.07 171.24,-123 164.63,-121.76 157.74,-120.47 150.85,-119.17\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"151.26,-115.69 140.78,-117.27 149.96,-122.57 151.26,-115.69\"/>\n<text text-anchor=\"middle\" x=\"303.24\" y=\"-144.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Rhaella Targaryen->Rhaegar Targaryen -->\n<g id=\"edge31\" class=\"edge\">\n<title>Rhaella Targaryen->Rhaegar Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M273,-177.65C289.35,-172.02 307.6,-164.73 323.24,-156 332.64,-150.76 332.5,-145.56 342.24,-141 347.01,-138.77 398.04,-128.21 442.45,-119.27\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"443.27,-122.67 452.39,-117.27 441.89,-115.81 443.27,-122.67\"/>\n<text text-anchor=\"middle\" x=\"362.24\" y=\"-144.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Rhaella Targaryen->Viserys Targaryen -->\n<g id=\"edge32\" class=\"edge\">\n<title>Rhaella Targaryen->Viserys Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M224.97,-173.86C224.3,-163.98 224.55,-151.48 228.24,-141 229.43,-137.64 231.07,-134.35 232.96,-131.21\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"235.95,-133.05 238.8,-122.85 230.21,-129.04 235.95,-133.05\"/>\n<text text-anchor=\"middle\" x=\"248.24\" y=\"-144.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Rhaella Targaryen->Daenerys Targaryen -->\n<g id=\"edge33\" class=\"edge\">\n<title>Rhaella Targaryen->Daenerys Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M199.78,-175.01C176.68,-161.56 143.45,-142.22 118.05,-127.43\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"119.48,-124.21 109.08,-122.21 115.96,-130.26 119.48,-124.21\"/>\n<text text-anchor=\"middle\" x=\"183.24\" y=\"-144.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Rhaenys Targaryen -->\n<g id=\"node12\" class=\"node\">\n<title>Rhaenys Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"504.24\" cy=\"-18\" rx=\"78.79\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"504.24\" y=\"-14.3\" font-family=\"Times,serif\" font-size=\"14.00\">Rhaenys Targaryen</text>\n</g>\n<!-- Rhaegar Targaryen->Rhaenys Targaryen -->\n<g id=\"edge11\" class=\"edge\">\n<title>Rhaegar Targaryen->Rhaenys Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M506.31,-86.96C505.47,-81.27 504.66,-74.88 504.24,-69 503.72,-61.67 503.55,-53.72 503.54,-46.36\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"507.04,-46.18 503.64,-36.15 500.04,-46.11 507.04,-46.18\"/>\n<text text-anchor=\"middle\" x=\"520.24\" y=\"-57.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Aegon Targaryen -->\n<g id=\"node13\" class=\"node\">\n<title>Aegon Targaryen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"674.24\" cy=\"-18\" rx=\"71.49\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"674.24\" y=\"-14.3\" font-family=\"Times,serif\" font-size=\"14.00\">Aegon Targaryen</text>\n</g>\n<!-- Rhaegar Targaryen->Aegon Targaryen -->\n<g id=\"edge12\" class=\"edge\">\n<title>Rhaegar Targaryen->Aegon Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M522.47,-87C531.71,-76.16 544.93,-62.59 559.24,-54 574.65,-44.76 592.7,-37.77 609.88,-32.57\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"611.21,-35.83 619.86,-29.71 609.29,-29.1 611.21,-35.83\"/>\n<text text-anchor=\"middle\" x=\"575.24\" y=\"-57.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Rhaego -->\n<g id=\"node15\" class=\"node\">\n<title>Rhaego</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"354.24\" cy=\"-18\" rx=\"37.89\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"354.24\" y=\"-14.3\" font-family=\"Times,serif\" font-size=\"14.00\">Rhaego</text>\n</g>\n<!-- Daenerys Targaryen->Rhaego -->\n<g id=\"edge36\" class=\"edge\">\n<title>Daenerys Targaryen->Rhaego</title>\n<path fill=\"none\" stroke=\"black\" d=\"M126.32,-89.96C178.46,-73.73 263.54,-47.24 313.68,-31.63\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"315.02,-34.88 323.52,-28.56 312.93,-28.2 315.02,-34.88\"/>\n<text text-anchor=\"middle\" x=\"254.24\" y=\"-57.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Drogo -->\n<g id=\"node14\" class=\"node\">\n<title>Drogo</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"381.24\" cy=\"-105\" rx=\"33.29\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"381.24\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\">Drogo</text>\n</g>\n<!-- Drogo->Rhaego -->\n<g id=\"edge13\" class=\"edge\">\n<title>Drogo->Rhaego</title>\n<path fill=\"none\" stroke=\"black\" d=\"M375.91,-87.21C372.16,-75.41 367.07,-59.38 362.76,-45.82\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"366.02,-44.52 359.66,-36.05 359.35,-46.64 366.02,-44.52\"/>\n<text text-anchor=\"middle\" x=\"386.24\" y=\"-57.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Rickard Stark -->\n<g id=\"node16\" class=\"node\">\n<title>Rickard Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1489.24\" cy=\"-366\" rx=\"59.59\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1489.24\" y=\"-362.3\" font-family=\"Times,serif\" font-size=\"14.00\">Rickard Stark</text>\n</g>\n<!-- Brandon Stark -->\n<g id=\"node17\" class=\"node\">\n<title>Brandon Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1720.24\" cy=\"-279\" rx=\"61.99\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1720.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Brandon Stark</text>\n</g>\n<!-- Rickard Stark->Brandon Stark -->\n<g id=\"edge14\" class=\"edge\">\n<title>Rickard Stark->Brandon Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1502.26,-348.36C1512.02,-337.1 1526.39,-322.89 1542.24,-315 1585.42,-293.53 1601.99,-306.62 1649.24,-297 1654.31,-295.97 1659.57,-294.83 1664.83,-293.65\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1665.93,-296.99 1674.89,-291.35 1664.36,-290.17 1665.93,-296.99\"/>\n<text text-anchor=\"middle\" x=\"1558.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Eddard Stark -->\n<g id=\"node18\" class=\"node\">\n<title>Eddard Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1379.24\" cy=\"-279\" rx=\"57.39\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1379.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Eddard Stark</text>\n</g>\n<!-- Rickard Stark->Eddard Stark -->\n<g id=\"edge15\" class=\"edge\">\n<title>Rickard Stark->Eddard Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1446.38,-353.24C1432.41,-347.85 1417.59,-340.3 1406.24,-330 1399.13,-323.54 1393.53,-314.76 1389.31,-306.37\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1392.46,-304.84 1385.13,-297.19 1386.09,-307.74 1392.46,-304.84\"/>\n<text text-anchor=\"middle\" x=\"1422.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Lyanna Stark -->\n<g id=\"node19\" class=\"node\">\n<title>Lyanna Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1246.24\" cy=\"-279\" rx=\"57.69\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1246.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Lyanna Stark</text>\n</g>\n<!-- Rickard Stark->Lyanna Stark -->\n<g id=\"edge16\" class=\"edge\">\n<title>Rickard Stark->Lyanna Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1443.29,-354.46C1418.18,-348.24 1386.68,-339.7 1359.24,-330 1334.05,-321.09 1306.62,-309.02 1285.09,-298.96\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1286.49,-295.75 1275.95,-294.65 1283.5,-302.08 1286.49,-295.75\"/>\n<text text-anchor=\"middle\" x=\"1375.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Benjen Stark -->\n<g id=\"node20\" class=\"node\">\n<title>Benjen Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1856.24\" cy=\"-279\" rx=\"56.59\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1856.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Benjen Stark</text>\n</g>\n<!-- Rickard Stark->Benjen Stark -->\n<g id=\"edge17\" class=\"edge\">\n<title>Rickard Stark->Benjen Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1538.63,-355.72C1575.42,-348.4 1622.28,-338.11 1640.24,-330 1650.7,-325.28 1650.59,-319.24 1661.24,-315 1715.43,-293.42 1734.04,-308.4 1791.24,-297 1795.86,-296.08 1800.64,-295.03 1805.41,-293.91\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1806.26,-297.3 1815.15,-291.53 1804.61,-290.5 1806.26,-297.3\"/>\n<text text-anchor=\"middle\" x=\"1677.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Robb Stark -->\n<g id=\"node21\" class=\"node\">\n<title>Robb Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1046.24\" cy=\"-192\" rx=\"50.89\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1046.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Robb Stark</text>\n</g>\n<!-- Eddard Stark->Robb Stark -->\n<g id=\"edge18\" class=\"edge\">\n<title>Eddard Stark->Robb Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1337.9,-266.36C1329.77,-264.36 1321.28,-262.45 1313.24,-261 1238.48,-247.49 1213.6,-271.67 1143.24,-243 1133.28,-238.94 1133.44,-233.58 1124.24,-228 1113.13,-221.26 1100.49,-215.04 1088.67,-209.76\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1089.97,-206.51 1079.41,-205.75 1087.19,-212.94 1089.97,-206.51\"/>\n<text text-anchor=\"middle\" x=\"1159.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Sansa Stark -->\n<g id=\"node22\" class=\"node\">\n<title>Sansa Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"903.24\" cy=\"-192\" rx=\"51.99\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"903.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Sansa Stark</text>\n</g>\n<!-- Eddard Stark->Sansa Stark -->\n<g id=\"edge19\" class=\"edge\">\n<title>Eddard Stark->Sansa Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1338.65,-266.29C1330.31,-264.23 1321.54,-262.33 1313.24,-261 1194.5,-241.92 1160.45,-269.93 1043.24,-243 1025.95,-239.03 1022.87,-234.19 1006.24,-228 987.87,-221.16 967.47,-214.12 949.7,-208.15\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"950.72,-204.81 940.13,-204.96 948.51,-211.45 950.72,-204.81\"/>\n<text text-anchor=\"middle\" x=\"1059.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Arya Stark -->\n<g id=\"node23\" class=\"node\">\n<title>Arya Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1432.24\" cy=\"-192\" rx=\"49.29\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1432.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Arya Stark</text>\n</g>\n<!-- Eddard Stark->Arya Stark -->\n<g id=\"edge20\" class=\"edge\">\n<title>Eddard Stark->Arya Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1398.99,-262.01C1404.85,-256.49 1410.87,-249.93 1415.24,-243 1419.67,-235.99 1423.09,-227.7 1425.66,-219.91\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1429.09,-220.67 1428.57,-210.09 1422.37,-218.69 1429.09,-220.67\"/>\n<text text-anchor=\"middle\" x=\"1439.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Bran Stark -->\n<g id=\"node24\" class=\"node\">\n<title>Bran Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1174.24\" cy=\"-192\" rx=\"48.99\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1174.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Bran Stark</text>\n</g>\n<!-- Eddard Stark->Bran Stark -->\n<g id=\"edge21\" class=\"edge\">\n<title>Eddard Stark->Bran Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1337.74,-266.57C1310.76,-258.9 1278.27,-249.1 1265.24,-243 1254.19,-237.83 1252.79,-234.13 1242.24,-228 1232.49,-222.33 1221.72,-216.57 1211.68,-211.4\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1213.21,-208.25 1202.71,-206.84 1210.04,-214.49 1213.21,-208.25\"/>\n<text text-anchor=\"middle\" x=\"1281.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Rickon Stark -->\n<g id=\"node25\" class=\"node\">\n<title>Rickon Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1304.24\" cy=\"-192\" rx=\"57.39\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1304.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Rickon Stark</text>\n</g>\n<!-- Eddard Stark->Rickon Stark -->\n<g id=\"edge22\" class=\"edge\">\n<title>Eddard Stark->Rickon Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1375.66,-260.84C1372.83,-250.47 1368.02,-237.47 1360.24,-228 1355.54,-222.27 1349.64,-217.21 1343.45,-212.84\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1345.21,-209.81 1334.92,-207.3 1341.41,-215.68 1345.21,-209.81\"/>\n<text text-anchor=\"middle\" x=\"1386.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Jon Snow -->\n<g id=\"node26\" class=\"node\">\n<title>Jon Snow</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1546.24\" cy=\"-192\" rx=\"45.49\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1546.24\" y=\"-188.3\" font-family=\"Times,serif\" font-size=\"14.00\">Jon Snow</text>\n</g>\n<!-- Eddard Stark->Jon Snow -->\n<g id=\"edge23\" class=\"edge\">\n<title>Eddard Stark->Jon Snow</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1412.7,-264.33C1427.18,-258.16 1444.22,-250.58 1459.24,-243 1477.58,-233.76 1497.47,-222.42 1513.6,-212.89\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1515.83,-215.64 1522.63,-207.51 1512.24,-209.62 1515.83,-215.64\"/>\n<text text-anchor=\"middle\" x=\"1502.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">father</text>\n</g>\n<!-- Dyanna Dayne -->\n<g id=\"node27\" class=\"node\">\n<title>Dyanna Dayne</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"672.24\" cy=\"-366\" rx=\"63.89\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"672.24\" y=\"-362.3\" font-family=\"Times,serif\" font-size=\"14.00\">Dyanna Dayne</text>\n</g>\n<!-- Dyanna Dayne->Aegon V Targaryen -->\n<g id=\"edge24\" class=\"edge\">\n<title>Dyanna Dayne->Aegon V Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M689.98,-348.61C703.77,-335.88 723.08,-318.03 738.55,-303.74\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"741.27,-305.99 746.24,-296.63 736.52,-300.84 741.27,-305.99\"/>\n<text text-anchor=\"middle\" x=\"744.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Dyanna Dayne->Aerion Targaryen -->\n<g id=\"edge25\" class=\"edge\">\n<title>Dyanna Dayne->Aerion Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M667.55,-347.81C664.06,-337.43 658.47,-324.43 650.24,-315 645.68,-309.77 640.14,-305.07 634.32,-300.94\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"635.98,-297.84 625.69,-295.31 632.15,-303.71 635.98,-297.84\"/>\n<text text-anchor=\"middle\" x=\"680.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Dyanna Dayne->Aemon Targaryen -->\n<g id=\"edge26\" class=\"edge\">\n<title>Dyanna Dayne->Aemon Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M624.42,-354.03C602.77,-348.22 577.17,-340.17 555.24,-330 544.17,-324.86 543.23,-320.31 532.24,-315 517.2,-307.74 500.26,-301.37 484.45,-296.13\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"485.37,-292.75 474.78,-293.01 483.22,-299.41 485.37,-292.75\"/>\n<text text-anchor=\"middle\" x=\"575.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Unknown Targaryen Queen -->\n<g id=\"node28\" class=\"node\">\n<title>Unknown Targaryen Queen</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"226.24\" cy=\"-279\" rx=\"108.58\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"226.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Unknown Targaryen Queen</text>\n</g>\n<!-- Unknown Targaryen Queen->Duncan Targaryen -->\n<g id=\"edge27\" class=\"edge\">\n<title>Unknown Targaryen Queen->Duncan Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M301.97,-266.09C315.68,-264.19 329.87,-262.4 343.24,-261 405.25,-254.51 565.03,-265.33 623.24,-243 633.29,-239.15 632.7,-232.97 642.24,-228 658.61,-219.47 677.39,-212.67 695,-207.42\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"695.98,-210.78 704.64,-204.67 694.06,-204.05 695.98,-210.78\"/>\n<text text-anchor=\"middle\" x=\"662.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Unknown Targaryen Queen->Aerys II Targaryen -->\n<g id=\"edge28\" class=\"edge\">\n<title>Unknown Targaryen Queen->Aerys II Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M260.9,-261.81C290.85,-247.83 334.21,-227.58 366.14,-212.66\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"367.66,-215.81 375.24,-208.41 364.7,-209.47 367.66,-215.81\"/>\n<text text-anchor=\"middle\" x=\"348.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Unknown Targaryen Queen->Rhaella Targaryen -->\n<g id=\"edge29\" class=\"edge\">\n<title>Unknown Targaryen Queen->Rhaella Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M226.45,-260.8C226.58,-249.16 226.77,-233.55 226.92,-220.24\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"230.42,-220.22 227.04,-210.18 223.42,-220.13 230.42,-220.22\"/>\n<text text-anchor=\"middle\" x=\"247.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Unknown Targaryen Queen->Daeron Targaryen -->\n<g id=\"edge30\" class=\"edge\">\n<title>Unknown Targaryen Queen->Daeron Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M303.92,-266.34C317.03,-264.48 330.52,-262.63 343.24,-261 415.1,-251.79 438.23,-270.51 505.24,-243 515.2,-238.91 515.31,-234 524.24,-228 531.63,-223.05 539.75,-218.11 547.63,-213.58\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"549.37,-216.62 556.35,-208.65 545.92,-210.52 549.37,-216.62\"/>\n<text text-anchor=\"middle\" x=\"544.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Elia Martell -->\n<g id=\"node29\" class=\"node\">\n<title>Elia Martell</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"670.24\" cy=\"-105\" rx=\"53.89\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"670.24\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\">Elia Martell</text>\n</g>\n<!-- Elia Martell->Rhaenys Targaryen -->\n<g id=\"edge34\" class=\"edge\">\n<title>Elia Martell->Rhaenys Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M648.07,-88.43C632.58,-77.94 611.18,-64.21 591.24,-54 579.58,-48.03 566.65,-42.35 554.41,-37.37\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"555.35,-33.98 544.77,-33.54 552.77,-40.49 555.35,-33.98\"/>\n<text text-anchor=\"middle\" x=\"636.24\" y=\"-57.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Elia Martell->Aegon Targaryen -->\n<g id=\"edge35\" class=\"edge\">\n<title>Elia Martell->Aegon Targaryen</title>\n<path fill=\"none\" stroke=\"black\" d=\"M671.05,-86.8C671.6,-75.16 672.33,-59.55 672.96,-46.24\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"676.46,-46.33 673.43,-36.18 669.47,-46 676.46,-46.33\"/>\n<text text-anchor=\"middle\" x=\"693.24\" y=\"-57.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Lyarra Stark -->\n<g id=\"node30\" class=\"node\">\n<title>Lyarra Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1641.24\" cy=\"-366\" rx=\"54.69\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1641.24\" y=\"-362.3\" font-family=\"Times,serif\" font-size=\"14.00\">Lyarra Stark</text>\n</g>\n<!-- Lyarra Stark->Brandon Stark -->\n<g id=\"edge37\" class=\"edge\">\n<title>Lyarra Stark->Brandon Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1671,-350.76C1680.28,-345.25 1689.97,-338.26 1697.24,-330 1703.17,-323.27 1707.84,-314.75 1711.38,-306.67\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1714.71,-307.75 1715.15,-297.16 1708.21,-305.17 1714.71,-307.75\"/>\n<text text-anchor=\"middle\" x=\"1728.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Lyarra Stark->Eddard Stark -->\n<g id=\"edge38\" class=\"edge\">\n<title>Lyarra Stark->Eddard Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1622.11,-349.02C1606.15,-336.03 1584.45,-319.19 1574.24,-315 1520.7,-293 1502.03,-308.24 1445.24,-297 1440.56,-296.07 1435.71,-295.01 1430.86,-293.89\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1431.52,-290.45 1420.98,-291.51 1429.88,-297.25 1431.52,-290.45\"/>\n<text text-anchor=\"middle\" x=\"1617.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Lyarra Stark->Lyanna Stark -->\n<g id=\"edge39\" class=\"edge\">\n<title>Lyarra Stark->Lyanna Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1596.13,-355.75C1551.6,-346.56 1488.58,-333.37 1477.24,-330 1459.44,-324.71 1456.21,-319.69 1438.24,-315 1383.93,-300.84 1368.3,-307.92 1313.24,-297 1308.29,-296.02 1303.16,-294.9 1298.04,-293.72\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1298.8,-290.3 1288.26,-291.38 1297.18,-297.11 1298.8,-290.3\"/>\n<text text-anchor=\"middle\" x=\"1497.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Lyarra Stark->Benjen Stark -->\n<g id=\"edge40\" class=\"edge\">\n<title>Lyarra Stark->Benjen Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1681.54,-353.8C1702.82,-347.51 1729.23,-339.11 1752.24,-330 1775.08,-320.96 1799.89,-309.12 1819.55,-299.22\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1821.15,-302.34 1828.48,-294.69 1817.98,-296.1 1821.15,-302.34\"/>\n<text text-anchor=\"middle\" x=\"1804.24\" y=\"-318.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Unknown_Jon_Mother -->\n<g id=\"node31\" class=\"node\">\n<title>Unknown_Jon_Mother</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1547.24\" cy=\"-279\" rx=\"92.88\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1547.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Unknown_Jon_Mother</text>\n</g>\n<!-- Unknown_Jon_Mother->Jon Snow -->\n<g id=\"edge41\" class=\"edge\">\n<title>Unknown_Jon_Mother->Jon Snow</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1547.04,-260.8C1546.9,-249.16 1546.72,-233.55 1546.56,-220.24\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1550.06,-220.13 1546.44,-210.18 1543.06,-220.22 1550.06,-220.13\"/>\n<text text-anchor=\"middle\" x=\"1567.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Catelyn Stark -->\n<g id=\"node32\" class=\"node\">\n<title>Catelyn Stark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"1083.24\" cy=\"-279\" rx=\"59.29\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"1083.24\" y=\"-275.3\" font-family=\"Times,serif\" font-size=\"14.00\">Catelyn Stark</text>\n</g>\n<!-- Catelyn Stark->Robb Stark -->\n<g id=\"edge42\" class=\"edge\">\n<title>Catelyn Stark->Robb Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1025.47,-274.97C1003.3,-270.63 980.05,-261.54 966.24,-243 954,-226.56 972.84,-214.25 995.3,-205.95\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"996.72,-209.17 1005.07,-202.65 994.47,-202.54 996.72,-209.17\"/>\n<text text-anchor=\"middle\" x=\"986.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Catelyn Stark->Sansa Stark -->\n<g id=\"edge43\" class=\"edge\">\n<title>Catelyn Stark->Sansa Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1028.41,-272.23C987.18,-266.83 935.16,-257.41 919.24,-243 912.71,-237.09 908.83,-228.51 906.53,-220.12\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"909.92,-219.24 904.44,-210.18 903.07,-220.68 909.92,-219.24\"/>\n<text text-anchor=\"middle\" x=\"939.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Catelyn Stark->Arya Stark -->\n<g id=\"edge44\" class=\"edge\">\n<title>Catelyn Stark->Arya Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1132.54,-269.04C1147.52,-266.38 1164.05,-263.5 1179.24,-261 1231.59,-252.37 1248.58,-264.14 1297.24,-243 1307.11,-238.71 1306.7,-232.97 1316.24,-228 1322.65,-224.66 1355.62,-214.81 1384.78,-206.41\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1385.84,-209.75 1394.48,-203.63 1383.91,-203.02 1385.84,-209.75\"/>\n<text text-anchor=\"middle\" x=\"1336.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Catelyn Stark->Bran Stark -->\n<g id=\"edge45\" class=\"edge\">\n<title>Catelyn Stark->Bran Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1079.1,-260.78C1077.62,-250.39 1077.68,-237.39 1084.24,-228 1089.64,-220.28 1107.65,-212.59 1126.15,-206.39\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1127.36,-209.68 1135.81,-203.3 1125.22,-203.02 1127.36,-209.68\"/>\n<text text-anchor=\"middle\" x=\"1104.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n<!-- Catelyn Stark->Rickon Stark -->\n<g id=\"edge46\" class=\"edge\">\n<title>Catelyn Stark->Rickon Stark</title>\n<path fill=\"none\" stroke=\"black\" d=\"M1124.67,-266.11C1142.08,-260.31 1162.2,-252.51 1179.24,-243 1188.64,-237.76 1188.77,-233.1 1198.24,-228 1214.51,-219.25 1233.35,-212.16 1250.6,-206.72\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1251.99,-209.95 1260.54,-203.7 1249.96,-203.25 1251.99,-209.95\"/>\n<text text-anchor=\"middle\" x=\"1218.24\" y=\"-231.8\" font-family=\"Times,serif\" font-size=\"14.00\">mother</text>\n</g>\n</g>\n</svg>\n", + "text/plain": [ + "digraph {\n", + " \"Maekar Targaryen\" -> \"Aegon V Targaryen\" [label=\"father\"]\n", + " \"Maekar Targaryen\" -> \"Aerion Targaryen\" [label=\"father\"]\n", + " \"Maekar Targaryen\" -> \"Aemon Targaryen\" [label=\"father\"]\n", + " \"Aegon V Targaryen\" -> \"Duncan Targaryen\" [label=\"father\"]\n", + " \"Aegon V Targaryen\" -> \"Aerys II Targaryen\" [label=\"father\"]\n", + " \"Aegon V Targaryen\" -> \"Rhaella Targaryen\" [label=\"father\"]\n", + " \"Aegon V Targaryen\" -> \"Daeron Targaryen\" [label=\"father\"]\n", + " \"Aerys II Targaryen\" -> \"Rhaegar Targaryen\" [label=\"father\"]\n", + " \"Aerys II Targaryen\" -> \"Viserys Targaryen\" [label=\"father\"]\n", + " \"Aerys II Targaryen\" -> \"Daenerys Targaryen\" [label=\"father\"]\n", + " \"Rhaegar Targaryen\" -> \"Rhaenys Targaryen\" [label=\"father\"]\n", + " \"Rhaegar Targaryen\" -> \"Aegon Targaryen\" [label=\"father\"]\n", + " \"Drogo\" -> \"Rhaego\" [label=\"father\"]\n", + " \"Rickard Stark\" -> \"Brandon Stark\" [label=\"father\"]\n", + " \"Rickard Stark\" -> \"Eddard Stark\" [label=\"father\"]\n", + " \"Rickard Stark\" -> \"Lyanna Stark\" [label=\"father\"]\n", + " \"Rickard Stark\" -> \"Benjen Stark\" [label=\"father\"]\n", + " \"Eddard Stark\" -> \"Robb Stark\" [label=\"father\"]\n", + " \"Eddard Stark\" -> \"Sansa Stark\" [label=\"father\"]\n", + " \"Eddard Stark\" -> \"Arya Stark\" [label=\"father\"]\n", + " \"Eddard Stark\" -> \"Bran Stark\" [label=\"father\"]\n", + " \"Eddard Stark\" -> \"Rickon Stark\" [label=\"father\"]\n", + " \"Eddard Stark\" -> \"Jon Snow\" [label=\"father\"]\n", + " \"Dyanna Dayne\" -> \"Aegon V Targaryen\" [label=\"mother\"]\n", + " \"Dyanna Dayne\" -> \"Aerion Targaryen\" [label=\"mother\"]\n", + " \"Dyanna Dayne\" -> \"Aemon Targaryen\" [label=\"mother\"]\n", + " \"Unknown Targaryen Queen\" -> \"Duncan Targaryen\" [label=\"mother\"]\n", + " \"Unknown Targaryen Queen\" -> \"Aerys II Targaryen\" [label=\"mother\"]\n", + " \"Unknown Targaryen Queen\" -> \"Rhaella Targaryen\" [label=\"mother\"]\n", + " \"Unknown Targaryen Queen\" -> \"Daeron Targaryen\" [label=\"mother\"]\n", + " \"Rhaella Targaryen\" -> \"Rhaegar Targaryen\" [label=\"mother\"]\n", + " \"Rhaella Targaryen\" -> \"Viserys Targaryen\" [label=\"mother\"]\n", + " \"Rhaella Targaryen\" -> \"Daenerys Targaryen\" [label=\"mother\"]\n", + " \"Elia Martell\" -> \"Rhaenys Targaryen\" [label=\"mother\"]\n", + " \"Elia Martell\" -> \"Aegon Targaryen\" [label=\"mother\"]\n", + " \"Daenerys Targaryen\" -> \"Rhaego\" [label=\"mother\"]\n", + " \"Lyarra Stark\" -> \"Brandon Stark\" [label=\"mother\"]\n", + " \"Lyarra Stark\" -> \"Eddard Stark\" [label=\"mother\"]\n", + " \"Lyarra Stark\" -> \"Lyanna Stark\" [label=\"mother\"]\n", + " \"Lyarra Stark\" -> \"Benjen Stark\" [label=\"mother\"]\n", + " \"Unknown_Jon_Mother\" -> \"Jon Snow\" [label=\"mother\"]\n", + " \"Catelyn Stark\" -> \"Robb Stark\" [label=\"mother\"]\n", + " \"Catelyn Stark\" -> \"Sansa Stark\" [label=\"mother\"]\n", + " \"Catelyn Stark\" -> \"Arya Stark\" [label=\"mother\"]\n", + " \"Catelyn Stark\" -> \"Bran Stark\" [label=\"mother\"]\n", + " \"Catelyn Stark\" -> \"Rickon Stark\" [label=\"mother\"]\n", + "}" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "\u001b[1mtrue" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "jupyter:print_transition_graph(parent_relation/3, 1, 2, 3)." + ] + }, + { + "cell_type": "markdown", + "id": "e2ed5de7", + "metadata": {}, + "source": [ + "Let us now define the grandfather and grandmother relationships:" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "313194bb", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "% Asserting clauses for user:grandfather/2\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "% Asserting clauses for user:grandmother/2\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "grandfather(A,B) :- child(B,C) , child(C,A), male(A).\n", + "grandmother(A,B) :- child(B,C) , child(C,A), female(A)." + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "e0eed7cc", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[1mGF = Rickard Stark" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "?-grandfather(GF,'Sansa Stark')." + ] + }, + { + "cell_type": "markdown", + "id": "d0e8eb01", + "metadata": {}, + "source": [ + "Finally let us use recursion in Prolog to define arbitrary ancestors:" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "c2615402", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "% Asserting clauses for user:parent/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:ancestor/2 were retracted (click to expand)</summary><pre>:- dynamic ancestor/2.\n", + "\n", + "ancestor(A, B) :-\n", + " parent(A, B).\n", + "ancestor(A, B) :-\n", + " parent(C, B),\n", + " ancestor(A, C).\n", + "</pre></details>" + ], + "text/plain": [ + "Previously defined clauses of user:ancestor/2 were retracted:\n", + ":- dynamic ancestor/2.\n", + "\n", + "ancestor(A, B) :-\n", + " parent(A, B).\n", + "ancestor(A, B) :-\n", + " parent(C, B),\n", + " ancestor(A, C).\n" + ] + }, + "metadata": { + "application/json": {} + }, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "% Asserting clauses for user:ancestor/2\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "parent(A,B) :- child(B,A).\n", + "ancestor(A,B):- parent(A,B).\n", + "ancestor(A,B):- parent(C,B), ancestor(A,C)." + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "d2b8accc", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[1mGF = Eddard Stark" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "?-ancestor(GF,'Sansa Stark')." + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "05f68119", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [ + { + "data": { + "text/markdown": [ + "X | \n", + ":- | \n", + "Eddard Stark | \n", + "Catelyn Stark | \n", + "Rickard Stark | \n", + "Lyarra Stark | " + ], + "text/plain": [ + "X | \n", + ":- | \n", + "Eddard Stark | \n", + "Catelyn Stark | \n", + "Rickard Stark | \n", + "Lyarra Stark | " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "\u001b[1mtrue" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "jupyter:print_table(ancestor(X,'Sansa Stark'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da2e206f", + "metadata": { + "vscode": { + "languageId": "prolog" + } + }, + "outputs": [], "source": [] } ], diff --git a/logic_programming/prolog_files/1_got_family_tree.pl b/logic_programming/prolog_files/1_got_family_tree.pl new file mode 100644 index 0000000000000000000000000000000000000000..106f29ce64618711e70a6acc21901711d99fb19f --- /dev/null +++ b/logic_programming/prolog_files/1_got_family_tree.pl @@ -0,0 +1,195 @@ +% from https://github.com/ozym4nd145/COL226-Assignments/blob/master/Family_Tree/family.pl + +%Targaryen Males +male('Aegon V Targaryen'). +male('Aerion Targaryen'). +male('Aemon Targaryen'). +male('Duncan Targaryen'). +male('Aerys II Targaryen'). +male('Daeron Targaryen'). +male('Rhaegar Targaryen'). +male('Viserys Targaryen'). +male('Aegon Targaryen'). +male('Rhaego'). +male('Drogo'). +male('Maekar Targaryen'). + +%Stark Males +male('Rickard Stark'). +male('Brandon Stark'). +male('Eddard Stark'). +male('Benjen Stark'). +male('Robb Stark'). +male('Tyrion Lannister'). +male('Ramsay Bolton'). +male('Bran Stark'). +male('Rickon Stark'). +male('Jon Snow'). + +%Targaryen Females +female('Rhaenys Targaryen'). +female('Rhaella Targaryen'). +female('Elia Martell'). +female('Daenerys Targaryen'). +female('Unknown Targaryen Queen'). +female('Dyanna Dayne'). + +%Stark Females +female('Catelyn Stark'). +female('Lyanna Stark'). +female('Lyarra Stark'). +female('Talisa Stark'). +female('Sansa Stark'). +female('Arya Stark'). +female('Unknown_Jon_Mother'). + +%Targaryen Parent +child('Aegon V Targaryen','Maekar Targaryen'). +child('Aerion Targaryen','Maekar Targaryen'). +child('Aemon Targaryen','Maekar Targaryen'). + +child('Aegon V Targaryen','Dyanna Dayne'). +child('Aerion Targaryen','Dyanna Dayne'). +child('Aemon Targaryen','Dyanna Dayne'). + +child('Duncan Targaryen','Aegon V Targaryen'). +child('Aerys II Targaryen','Aegon V Targaryen'). +child('Rhaella Targaryen','Aegon V Targaryen'). +child('Daeron Targaryen','Aegon V Targaryen'). + +child('Duncan Targaryen','Unknown Targaryen Queen'). +child('Aerys II Targaryen','Unknown Targaryen Queen'). +child('Rhaella Targaryen','Unknown Targaryen Queen'). +child('Daeron Targaryen','Unknown Targaryen Queen'). + +child('Rhaegar Targaryen','Aerys II Targaryen'). +child('Viserys Targaryen','Aerys II Targaryen'). +child('Daenerys Targaryen','Aerys II Targaryen'). +child('Rhaegar Targaryen','Rhaella Targaryen'). +child('Viserys Targaryen','Rhaella Targaryen'). +child('Daenerys Targaryen','Rhaella Targaryen'). +child('Rhaenys Targaryen','Rhaegar Targaryen'). +child('Aegon Targaryen','Rhaegar Targaryen'). +child('Rhaenys Targaryen','Elia Martell'). +child('Aegon Targaryen','Elia Martell'). +child('Rhaego','Daenerys Targaryen'). +child('Rhaego','Drogo'). + +%Stark Parent +child('Brandon Stark','Rickard Stark'). +child('Eddard Stark','Rickard Stark'). +child('Lyanna Stark','Rickard Stark'). +child('Benjen Stark','Rickard Stark'). + +child('Brandon Stark','Lyarra Stark'). +child('Eddard Stark','Lyarra Stark'). +child('Lyanna Stark','Lyarra Stark'). +child('Benjen Stark','Lyarra Stark'). + +child('Robb Stark','Eddard Stark'). +child('Sansa Stark','Eddard Stark'). +child('Arya Stark','Eddard Stark'). +child('Bran Stark','Eddard Stark'). +child('Rickon Stark','Eddard Stark'). +% Controversial +child('Jon Snow','Eddard Stark'). +child('Jon Snow','Unknown_Jon_Mother'). + +child('Robb Stark','Catelyn Stark'). +child('Sansa Stark','Catelyn Stark'). +child('Arya Stark','Catelyn Stark'). +child('Bran Stark','Catelyn Stark'). +child('Rickon Stark','Catelyn Stark'). + +%Targaryen Couples +couple('Aerys II Targaryen','Rhaella Targaryen'). +couple('Daenerys Targaryen','Drogo'). +couple('Elia Martell','Rhaegar Targaryen'). +couple('Aegon V Targaryen','Unknown Targaryen Queen'). + + +%Stark Couples +couple('Rickard Stark','Lyarra Stark'). +couple('Eddard Stark','Catelyn Stark'). +couple('Robb Stark','Talisa Stark'). +couple('Tyrion Lannister','Sansa Stark'). +couple('Ramsay Bolton','Sansa Stark'). +couple('Maekar Targaryen','Dyanna Dayne'). + +%Rules + +/* commented out so that we can define them in Jupyter: + +married(A,B) :- couple(B,A). +married(A,B) :- couple(A,B). + +sibling(A,B) :- child(A,C),child(B,C),male(C),married(C,D),child(A,D),child(B,D),A\=B. + +parent(A,B) :- child(B,A). + +father(A,B) :- child(B,A),male(A). +mother(A,B) :- child(B,A),female(A). + +wife(A,B) :- married(A,B),female(A),male(B). +husband(A,B) :- married(A,B),male(A),female(B). + +son(A,B) :- child(A,B),male(A). +daughter(A,B) :- child(A,B),female(A). + +brother(A,B) :- male(A),sibling(A,B). +sister(A,B) :- female(A),sibling(A,B). + +bastard(A,B) :- child(A,B),married(B,C),not(child(A,C)). + +grandfather(A,B) :- child(B,C) , child(C,A), male(A). +grandmother(A,B) :- child(B,C) , child(C,A), female(A). + +granddaughter(A,B) :- grandfather(B,A),female(A). +granddaughter(A,B) :- grandmother(B,A),female(A). + +grandson(A,B) :- grandmother(B,A),male(A). +grandson(A,B) :- grandfather(B,A),male(A). + +brother_in_law(A,B) :- male(A),sister(C,B),married(A,C). +sister_in_law(A,B) :- female(A),brother(C,B),married(A,C). + +in_law(A,B) :- sibling(C,B),married(A,C). + +uncle(A,B) :- male(A),child(B,C) , sibling(A,C). +uncle(A,B) :- male(A),child(B,C) , in_law(A,C). +aunt(A,B) :- female(A),child(B,C) , sibling(A,C). +aunt(A,B) :- female(A),child(B,C) , in_law(A,C). + +grandparent(A,B) :- grandfather(A,B). +grandparent(A,B) :- grandmother(A,B). + +ancestor(A,B):- parent(A,B). +ancestor(A,B):- parent(C,B), ancestor(A,C). +descendant(A,B) :- ancestor(B,A). +first_cousin(A,B) :- parent(C,A),sibling(C,D),parent(D,B),A\=B. + +nephew(A,B) :- male(A),parent(C,A),sibling(C,B). +neice(A,B) :- female(A),parent(C,A),sibling(C,B). + +half_sibling(A,B) :- child(A,P1),child(B,P1),child(A,P2),child(B,P3),P2\=P3,P1\=P2,P1\=P3. + +relation(A,B,'married') :- married(A,B). +relation(A,B,'brother') :- brother(A,B). +relation(A,B,'sister') :- sister(A,B). +relation(A,B,'father') :- father(A,B). +relation(A,B,'mother') :- mother(A,B). +relation(A,B,'bastard') :- bastard(A,B). +relation(A,B,'ancestor') :- ancestor(A,B). +relation(A,B,'descendant') :- descendant(A,B). +relation(A,B,'nephew') :- nephew(A,B). +relation(A,B,'neice') :- neice(A,B). +relation(A,B,'uncle') :- uncle(A,B). +relation(A,B,'aunt') :- aunt(A,B). +relation(A,B,'half_sibling') :- half_sibling(A,B). +relation(A,B,'first_cousin') :- first_cousin(A,B). +relation(A,B,'brother_in_law') :- brother_in_law(A,B). +relation(A,B,'sister_in_law') :- sister_in_law(A,B). +*/ + +% References - http://gameofthrones.wikia.com/wiki/House_Targaryen +% http://gameofthrones.wikia.com/wiki/House_Stark \ No newline at end of file