Adding Inference Rules · For all X and Y · Y is an offspring of X if · X is a parent of Y offspring(Y,X):parent(X,Y). Rules: Conclusion is True if Conditions Satisfied. All Rules Have Two Parts: Conclusion, Consequent or Head (Left-hand side). Antecedents, Condtions or Body (Right-hand side). A Fact is a Rule with no Conditions.
Summary So Far · Prolog Program is a Set of Clauses. · Prolog Clauses: Facts, Rules, Queries. Facts declare unconditional truths. Rules declare truths based on conditions. Queries are used to ask Prolog what is true. · Prolog Clauses have a head and body.
Is That All There is to It? · Yes. · But there is more to know: Built-in predicates Designing Algorithms (programming) Predicates are sub-programs Decisions (ifs) are Predicates with multiple clauses Loops via recursion or Repeat/Fail Variables don't vary. Data Structures: Complex terms
Adding a Decision If temp is greater than 90: print a heat warning if temp is less than 30: print a cold warning warn(T, 'It''s really hot') :- T > 90. warn(T,'Brass monkey danger') :- T < 30. warn(T, '') :- T >= 30, T <= 90.
Adding a Loop Sentinel Loop Get an Input While input is valid number Convert to Fahrenheit Output temp and warnings Get next input As a Decision Get an Input 1if input is a number: 1 Do the conversion Get another input Do the loop again if input is 'quit' just do it.
Using Recusion to Loop run2 :getInput(C), convert_loop(C). convert_loop(C) :number(C), convert(C,F), ... getInput(C1), convert_loop(C1). convert_loop(quit). If input is a number: Do the conversion Get another input Do the loop again if input is 'quit' just do it.