(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 9592, 355]*) (*NotebookOutlinePosition[ 10329, 381]*) (* CellTagsIndexPosition[ 10285, 377]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Logic Programming", "Title", TextAlignment->Center, TextJustification->0, Background->GrayLevel[0.900008]], Cell["\<\ Abstract This is a notebook that is inspired in the computer language Prolog and \ shows a possible way to emulate it with Mathematica. \ \>", "Text", TextAlignment->Center, TextJustification->0, Background->GrayLevel[0.900008]], Cell[BoxData[ \(Needs["\", "\"]\)], "Input",\ CellLabel->"In[1]:=", Background->GrayLevel[0.900008]], Cell[CellGroupData[{ Cell["Example 1", "SectionFirst", Background->GrayLevel[0.900008]], Cell["\<\ The program begins with a defined statements wich are used to obtain further \ conclusions.\ \>", "Text", Background->GrayLevel[0.900008]], Cell[BoxData[ \(Knowledge = Statements[\nLoves[Jhon, Flowers], \nLoves[Jhon, Mary], \n Loves[Paul, Mary]\t\t\n\t\t]; \n SetAttributes[Statements, {Flat, Orderless}]\)], "Input", CellLabel->"In[2]:=", Background->GrayLevel[0.900008]], Cell["Then we start with questions about our bank of statements.", "Text", Background->GrayLevel[0.900008]], Cell["Is there anything that Jhon loves?", "Text", Background->GrayLevel[0.900008]], Cell[CellGroupData[{ Cell[BoxData[ \(Question[Knowledge, Loves[Jhon, X_], X]\)], "Input", CellLabel->"In[3]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`{Flowers, Mary}\)], "Output", CellLabel->"Out[3]="] }, Open ]], Cell["Is There anything that Mary loves?", "Text", Background->GrayLevel[0.900008]], Cell[CellGroupData[{ Cell[BoxData[ \(Question[Knowledge, Loves[X_, Mary]\ , X]\)], "Input", CellLabel->"In[4]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`{Jhon, Paul}\)], "Output", CellLabel->"Out[4]="] }, Open ]], Cell["Is it True that Jhon Loves the flowers?", "Text", Background->GrayLevel[0.900008]], Cell[CellGroupData[{ Cell[BoxData[ \(Question[Knowledge, Loves[Jhon, Flowers]\ ]\)], "Input", CellLabel->"In[5]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`True\)], "Output", CellLabel->"Out[5]="] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Example 2", "Section", Background->GrayLevel[0.900008]], Cell["Lets work with other statements. ", "Text", Background->GrayLevel[0.900008]], Cell[BoxData[ \(Knowledge = Statements[\n\t\tLoves[Mary, \ food], \n\t\tLoves[Mary, wine], \n\t\t Loves[Jhon, wine], \n\t\tLoves[Jhon, Mary]\n\t\t]; \n\n SetAttributes[Statements, {Flat, Orderless}]\)], "Input", CellLabel->"In[6]:=", Background->GrayLevel[0.900008]], Cell["Is there anything that both Jhon and Mary loves ?", "Text", Background->GrayLevel[0.900008]], Cell[CellGroupData[{ Cell[BoxData[ \(Question[Knowledge, \n Statements[\tLoves[Mary, X_]\ , \ Loves[Jhon, X_]\ ]\ , X]\)], "Input", CellLabel->"In[7]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`{wine}\)], "Output", CellLabel->"Out[7]="] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Question[Knowledge, \ Loves[Jhon, wine]\ ]\)], "Input", CellLabel->"In[8]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`True\)], "Output", CellLabel->"Out[8]="] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Question[Knowledge, \ Loves[Jhon, food]\ ]\)], "Input", CellLabel->"In[9]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`False\)], "Output", CellLabel->"Out[9]="] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Example 3", "Section", Background->GrayLevel[0.900008]], Cell["This example is about a family.", "Text", Background->GrayLevel[0.900008]], Cell[BoxData[ \(\(Knowledge\ = \ Statements[Male[Albert], \n\t\tMale[Edward], \n\t\tFemale[Alice], \n\t\t Female[Victory], \n\t\tFathers[Edward, Victory, \ Albert], \n\t\t Fathers[Alice, Victory, Albert]\n\t\t]; \)\)], "Input", CellLabel->"In[10]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(SetAttributes[Statements, {Flat, Orderless}]\)], "Input", CellLabel->"In[11]:=", Background->GrayLevel[0.900008]], Cell["Now we want to find who can be Sister of anyone else. ", "Text", Background->GrayLevel[0.900008]], Cell[CellGroupData[{ Cell[BoxData[ \(Question[Knowledge, \n\t Statements[\ Female[X_]\ , \ Fathers[X_, M_, F_], Fathers[Y_, M_, F_]], \ Sister[X, Y]\ ]\)], "Input", CellLabel->"In[12]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`{Sister(Alice, Edward)}\)], "Output", CellLabel->"Out[12]="] }, Open ]], Cell["\<\ The last answer not only tell us who can be Sister, but also tells a sister \ of whom.\ \>", "Text", Background->GrayLevel[0.900008]] }, Open ]], Cell[CellGroupData[{ Cell["Example 4", "Section", Background->GrayLevel[0.900008]], Cell["\<\ In this example the knowledge is not only given as a set of statements, but \ also as a Rule that must be taken into account.\ \>", "Text", Background->GrayLevel[0.900008]], Cell[BoxData[{ \(Knowledge0\ = \ Statements[\n\t\tThief[Jhon], \n\t\tLikes[Mary, food], \n\t\t Likes[Mary, wine]\t\t\n\t\t\t\t]; \n SetAttributes[Statements, {Flat, Orderless}]\n\), \(\(Rule1\ = \ Likes[X_, wine] -> Likes[Jhon, X]; \)\)}], "Input", CellLabel->"In[13]:=", Background->GrayLevel[0.900008]], Cell["The knowledge must be updated with AddKnowledge.", "Text", Background->GrayLevel[0.900008]], Cell[BoxData[ \(\(Knowledge1\ = \ AddKnowledge[Knowledge0, Rule1]; \)\)], "Input", CellLabel->"In[15]:=", Background->GrayLevel[0.900008]], Cell["Now is time to ask what can be stolen by whom.", "Text", Background->GrayLevel[0.900008]], Cell[CellGroupData[{ Cell[BoxData[ \(Question[\n\tKnowledge1, \n\tStatements[Thief[X_], Likes[X_, Y_]]\t, \n \tCanSteal[X, Y]\n\t]\)], "Input", CellLabel->"In[16]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`{CanSteal(Jhon, Mary)}\)], "Output", CellLabel->"Out[16]="] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Example 5", "Section", Background->GrayLevel[0.900008]], Cell["\<\ In this example we want to find wheter or not a King was into the power in a \ certain date. \ \>", "Text", Background->GrayLevel[0.900008]], Cell[BoxData[ \(Knowledge\ = \ Statements[\n\tRulerKing[A, 844, 878], \n\tRulerKing[B, 878, 916], \n\t RulerKing[C, 916, 950], \n\tRulerKing[D, 950, 979]\n\t\t\t\t]; \n SetAttributes[Statements, {Flat, Orderless}]\)], "Input", CellLabel->"In[17]:=", Background->GrayLevel[0.900008]], Cell["The function that answers the question is the following:", "Text", Background->GrayLevel[0.900008]], Cell[BoxData[ \(RulerKingDate[A_, Z_] := Question[Knowledge, \ \ RulerKing[A, X_, Y_]\ , Z > X\ && \ Z < Y\ ] \)], "Input", CellLabel->"In[18]:=", Background->GrayLevel[0.900008]], Cell["And now we can ask for particular values", "Text", Background->GrayLevel[0.900008]], Cell[CellGroupData[{ Cell[BoxData[ \(RulerKingDate[A, 879]\)], "Input", CellLabel->"In[19]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`{False}\)], "Output", CellLabel->"Out[19]="] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(RulerKingDate[A, 845]\)], "Input", CellLabel->"In[20]:=", Background->GrayLevel[0.900008]], Cell[BoxData[ \(TraditionalForm\`{True}\)], "Output", CellLabel->"Out[20]="] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["References", "Section", Background->GrayLevel[0.900008]], Cell["\<\ Clockssin Mellish, Programming in Prolog , Springer Verlag ,1984\ \>", "Reference", Background->GrayLevel[0.900008]] }, Open ]] }, Open ]] }, FrontEndVersion->"Microsoft Windows 3.0", ScreenRectangle->{{0, 1024}, {0, 735}}, WindowToolbars->"EditBar", WindowSize->{928, 581}, WindowMargins->{{10, Automatic}, {Automatic, 23}}, Magnification->2, StyleDefinitions -> "ARTICLECLASSIC.NB" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1731, 51, 118, 3, 161, "Title"], Cell[1852, 56, 245, 7, 139, "Text"], Cell[2100, 65, 153, 4, 83, "Input"], Cell[CellGroupData[{ Cell[2278, 73, 68, 1, 129, "SectionFirst"], Cell[2349, 76, 150, 4, 110, "Text"], Cell[2502, 82, 259, 6, 213, "Input"], Cell[2764, 90, 109, 1, 81, "Text"], Cell[2876, 93, 86, 1, 81, "Text"], Cell[CellGroupData[{ Cell[2987, 98, 131, 3, 83, "Input"], Cell[3121, 103, 90, 2, 57, "Output"] }, Open ]], Cell[3226, 108, 86, 1, 81, "Text"], Cell[CellGroupData[{ Cell[3337, 113, 133, 3, 83, "Input"], Cell[3473, 118, 87, 2, 57, "Output"] }, Open ]], Cell[3575, 123, 90, 1, 81, "Text"], Cell[CellGroupData[{ Cell[3690, 128, 135, 3, 83, "Input"], Cell[3828, 133, 79, 2, 57, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[3956, 141, 63, 1, 143, "Section"], Cell[4022, 144, 84, 1, 81, "Text"], Cell[4109, 147, 293, 6, 264, "Input"], Cell[4405, 155, 100, 1, 81, "Text"], Cell[CellGroupData[{ Cell[4530, 160, 179, 4, 109, "Input"], Cell[4712, 166, 81, 2, 57, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4830, 173, 134, 3, 83, "Input"], Cell[4967, 178, 79, 2, 57, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[5083, 185, 134, 3, 83, "Input"], Cell[5220, 190, 80, 2, 57, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[5349, 198, 63, 1, 143, "Section"], Cell[5415, 201, 82, 1, 81, "Text"], Cell[5500, 204, 315, 6, 239, "Input"], Cell[5818, 212, 137, 3, 83, "Input"], Cell[5958, 217, 106, 1, 81, "Text"], Cell[CellGroupData[{ Cell[6089, 222, 220, 5, 161, "Input"], Cell[6312, 229, 99, 2, 57, "Output"] }, Open ]], Cell[6426, 234, 145, 4, 81, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[6608, 243, 63, 1, 143, "Section"], Cell[6674, 246, 184, 4, 110, "Text"], Cell[6861, 252, 338, 7, 264, "Input"], Cell[7202, 261, 99, 1, 81, "Text"], Cell[7304, 264, 147, 3, 83, "Input"], Cell[7454, 269, 97, 1, 81, "Text"], Cell[CellGroupData[{ Cell[7576, 274, 192, 4, 186, "Input"], Cell[7771, 280, 98, 2, 57, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[7918, 288, 63, 1, 143, "Section"], Cell[7984, 291, 152, 4, 110, "Text"], Cell[8139, 297, 310, 6, 239, "Input"], Cell[8452, 305, 107, 1, 81, "Text"], Cell[8562, 308, 203, 5, 109, "Input"], Cell[8768, 315, 91, 1, 81, "Text"], Cell[CellGroupData[{ Cell[8884, 320, 114, 3, 83, "Input"], Cell[9001, 325, 83, 2, 57, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[9121, 332, 114, 3, 83, "Input"], Cell[9238, 337, 82, 2, 57, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[9369, 345, 64, 1, 143, "Section"], Cell[9436, 348, 128, 3, 67, "Reference"] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)