Thinking in logical relations
Now that we are well versed with the various constructs from the core.logic
library, let's look at some real world problems that can be solved through logic programming.
Solving the n-queens problem
The n-queens problem is an interesting problem that can be implemented using logical relations. The objective of the n-queens problem is to place n queens on an n x n sized chessboard such that no two queens are a threat to each other. This problem is a generalization of the eight queens problem published by Max Bezzel in 1848, which involves eight queens. In fact, we can actually solve the n-queens problem for any number of queens, as long as we are dealing with four or more queens. Traditionally, this problem can be solved using an algorithmic technique called backtracking, which is essentially an exhaustive search for all possible solutions to a given problem. However, in this section, we will solve it using logical relations.
Let's first define how...