https://github.com/debasish-dutta/prolog-practice
https://github.com/debasish-dutta/prolog-practice
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/debasish-dutta/prolog-practice
- Owner: debasish-dutta
- Created: 2023-04-21T05:06:02.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T06:18:10.000Z (about 2 years ago)
- Last Synced: 2025-01-19T07:45:16.875Z (4 months ago)
- Language: Prolog
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Logic Progamming with Prolog
## Intro to logic progamming
Logic progamming deals with relations rather than functions.
### **Relations**
A concrete view of a relation is as a table with n>= 0 columns and a possibly infinite set of rows.
Some basic relations are:
- **Rules**
*Rules* are written as in
```prolog
P if Q1 and Q2 and ... and Qk. for k>=0.
```This is also called a *Horn Clause*.
- **Facts**
A *fact* is a special case of a rule, in which k = 0 and P holds without any condition, written simply as
```prolog
P.
```A fact is always true.
- **Append**
The *append* relation is specified by two rules.
The first is a fact starting that triples of the form ([], Y, **Y**) are in relation append.```prolog
append [] and Y to get Y.
```The second rule for append is shown for completeness. It uses the [H|T] for a list with Head H and tail T:
```prolog
append [H|X] and Y to get [H|Z]
if append X and Y to get Z
```### **Queries**
Logic progamming is driven by queries about relation. The simplest queries ask whether a particular tuple belongs to a relation. The query
asks whether the triple `([a,b],[c,d],[a,b,c,d]) belongs to relation *append*.```prolog
append [a,b] and [c,d] to get [a,b,c,d]?
Answer: yes
```## Intro to **PROLOG**