Author: workhouse123

  • Concatenation

    Concatenation

    Concatenating two lists’ means adding the elements of the second list after the first one. For example, if we have a list with elements [a,b,c,d] and another list with elements [e,f,g,h], then the concatenated list will have elements [a,b,c,d,e,f,g,h]. To implement list_concat predicate in Prolog, add the following lines in kb5.pl file and execute the…

  • Length Calculation

    Length Calculation

    This is used to find the length of list L. We will define one predicate to do this task. Suppose the predicate name is list_length(L,N). This takes L and N as input argument. This will count the elements in a list L and instantiate N to their number. As was the case with our previous…

  • Lists in Prolog

    Lists in Prolog

    List is a simple data structure that can contain any number of items. Individual items of a list are placed within square brackets ([]). For example, a list of students, we will write, [‘Manya’, ‘Amyra’,’Raman’,’John’,’Zeenat’]. We can also define an empty list by writing, a Prolog atom, []. A list with element(s) have two important…

  • Conjunction

    Conjunction

    Conjunction, commonly known as AND logic, is implemented using the comma (,) operator. That is, two predicates separated by comma are joined with AND statement. For example, if we have two predicates, We can write the rule as, The rule states that nina is the mother of kimaya if nina is the female parent of…

  • Decision Making

    Decision Making

    Like in other programming languages, decision statements in Prolog are If-Then-Else statements. We check a condition. If it is true, then a task is performed and if it false, another set of tasks is performed. The syntax to use a decision statement in Prolog is, To implement decision making, create a new file, write the…

  • Arithmetic Operators in Prolog

    Arithmetic Operators in Prolog

    Arithmetic operators are used to perform arithmetic operations. Some popularly used arithmetic operators are given in Table. To implement these operators, create a new file and save it as ao.pl. Write the following code in it. calc :- X is 10 + 20, write(‘10 + 20 is ‘),write(X),nl, Y is 30 – 15, write(‘30 –…

  • Working with Relationships in Prolog

    Working with Relationships in Prolog

    We can easily express relationships in Prolog. These relationships exist between objects and their properties. For example, if we say, Tina has a car, then, it means Tina is the owner of a car. Here, owner is the relationship that exist between two objects- Tina and car. When we pose a query, “Does Tina own…

  • Using Variables

    Using Variables

    We will use knowledge base 1 (kb1.pl) to demonstrate working with variables. Remember that, name of the variable starts with a capital letter. For example, if we want to know who all the students are, then we can write, student(X). In the result, names of the students will be displayed one by one. Press the…

  • Creating Facts and Rules

    Creating Facts and Rules

    In this section, we will focus on creating the knowledge base for problem solving. This KB is the fundamental part of Logic Programming and contains facts, rules and questions/queries. Facts represent an explicit relationship between objects, and properties. They are unconditionally true in nature. For example,   Tom is a dog Ria loves to eat…

  • What is Prolog?

    What is Prolog?

    To solve a problem in Prolog, we need not specify the following three things: Applications of Prolog Prolog is used in different areas to automate several tasks including, Installing Prolog In this section, we have used GNU Prolog version 1.5. You can download it from the official GNU Prolog website, http://www.gprolog.org/ or you can straight away go…