Prolog Arithmetic Operations within Function?

In summary, the conversation discusses learning Prolog and implementing rules for the "wumpus world". The rule for a "pit" existing at location (2,2) is explained, as well as the prolog code for representing breezes and pits. The issue of all locations returning false is brought up, but the solution is later found.
  • #1
tangodirt
54
1
So, I'm trying to learn prolog, and since it's used a lot in the AI community, I thought I would try my hand at implementing a few of the simple "wumpus world" rules.

The rule for a "pit" existing at location (2,2) means that a breeze is felt at locations (1,2), (2,1), (2,3), and (3,2). So, by telling the knowledge base that breezes are felt at those locations, means that querying pit(2,2) should return true, while all other locations should return false.

My prolog code looks like this:

Code:
breeze(1,2).
breeze(2,1).
breeze(2,3).
breeze(3,2).

pit(X,Y) :- breeze(X + 1,Y) , breeze(X,Y + 1) , breeze(X - 1,Y) , breeze(X,Y - 1) .

However, all locations for pit(X,Y) return false. Any ideas?
 
Technology news on Phys.org
  • #2
Nevermind, I've figured it out. The breeze locations need to be asserted, and the arithmetic operations should be extracted from within the function.
 

What is Prolog?

Prolog is a programming language based on logic and used primarily for artificial intelligence applications. It is a declarative language, meaning that instead of giving the computer a series of steps to follow, the programmer specifies the problem to be solved and lets the computer figure out how to solve it.

What are arithmetic operations in Prolog?

Arithmetic operations in Prolog are mathematical calculations performed on numeric values. These operations include addition, subtraction, multiplication, division, and exponentiation.

How are arithmetic operations performed in Prolog?

In Prolog, arithmetic operations are performed using built-in functions such as "is", ">", "<", and "=:=. These functions take in numeric values and evaluate them, returning a true or false value depending on the result of the operation.

Can arithmetic operations be used within functions in Prolog?

Yes, arithmetic operations can be used within functions in Prolog. These operations can be used within the body of a predicate to perform calculations on the input variables and return a result.

What are some examples of arithmetic operations in Prolog?

Some examples of arithmetic operations in Prolog include:

  • 2+3 = 5 (addition)
  • 7-4 = 3 (subtraction)
  • 6*2 = 12 (multiplication)
  • 10/5 = 2 (division)
  • 2**3 = 8 (exponentiation)

Similar threads

  • Special and General Relativity
Replies
7
Views
1K
  • Programming and Computer Science
Replies
31
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
4
Views
7K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
7
Views
3K
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
121
  • Programming and Computer Science
2
Replies
37
Views
8K
Back
Top