User:ButterBookie/sandbox

This is my sandbox. Proposed Prolog lead paragraph:

Prolog is a general-purpose logic programming language in which a program consist of facts and rules that define predicates representing relations. Given a set of definitions, the programmer poses a query to invoke the system to deduce members of the defined relations.

Prolog is considered a declarative logic programming language because its rules (and facts) can be understood as logical implications that are true of the defined relations.

An example is a Prolog program that defines several familial relations. All the relations in this example contain pairs of people. The fact: mother_child(elizabeth, charles). expresses that the mother_child relation contains the pair elizabeth and charles. This can also be expressed by saying that mother_child(elizabeth,charles) is true.

The facts: father_child(charles, william). father_child(charles, harry). express that the father_child relation contains two specific pairs.

The rules: parent_child(X, Y) :- mother_child(X, Y). parent_child(X, Y) :- father_child(X, Y). express that parent_child contains the pairs of both mother_child and father_child. Here X and Y are variables, and in general variables start with upper-case letters; constants start with lower-case letters. The ":-" means "if."

And the rule: grandparent_child(X, Y) :- parent_child(X, Z), parent_child(Z, Y). expresses that the grandparent_child(X,Y) is true if parent_child(X,Z) is true and parent_child(Z,Y) is true, for any values for X, Y, and Z. The "," between the two conditions of the rule means "and."

A query to these definitions could be: ?- grandparent_child(elizabeth,Y). which asks for the values of Y such that grandparent_child(elizabeth,Y) is true.

Prolog finds the answers to query using goal-directed (or subgoal reduction or backward chaining) reasoning, as follows: grandparent_child(elizabeth,Y) parent_child(elizabeth,Z), parent_child(Z,Y) mother_child(elizabeth,Z), parent_child(Z,Y) (Z = charles) parent_child(charles,Y) mother_child(charles,Y) (fail) father_child(charles,Y) (Y = william) (answer) (Y = harry) (answer) father_child(elizabeth,Z), parent_child(Z,Y) (fail)

Each line contains a sequence of subgoals that remain to be satisfied. It starts with the initial goal, grandparent_child(elizabeth,Y). Then the first subgoal (in this case, only) is matched against a rule or fact, and if it matches, that goal is replaced by the condition of the rule (or simply removed if it matches a fact). Parenthesized expressions are comments indicating when variables get values, when deduction fails, or when deduction completes generating an answer. Alternative matches to the same subgoal appear at the same level of indentation.

Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is intended primarily as a declarative programming language. The language has been used for theorem proving,[9] expert systems,[10] term rewriting,[11] type systems,[12] and automated planning,[13] as well as its original intended field of use, natural language processing.[14][15]

Prolog supports lists and general record trees, in addition to constants, which makes it Turing-complete and well-suited for intelligent knowledge-processing applications.