Expression Pattern Language (eXPL)

Introduction to eXPL

Logic programming is a quest to expand what is known to be true. Given certain facts, it is possible to establish new facts using rules, mathematics or whatever system is trusted to separate truth and falsehood. For example, given the fact "All politicians are liars" and "Joe is a politician", we are happy to deduce "Joe is a liar". Expression Pattern Language provides an original and practical approach to logic programming targeted at Java developers.

The mechanism used by the eXPL engine to create new facts is a two-step process, unification followed by evaluation. Unification works on two sets of terms, an axiom (known facts) containing constant terms and a template containing constant and variable terms. Unification attempts to pair an axiom to a template so they end up equivalent to each other. If this succeeds then evaluation of the template terms determines whether a solution has been found and what are the final values of the solution.

An expression pattern is a solution to a query stated as a sequence of unification terms which may contain expressions to define relationships or perform transformations.

Here is example of a simple eXPL query:

axiom city()
{"bilene", 1718}
{"addis ababa", 8000}
{"denver", 5280}
{"flagstaff", 6970}
{jacksonville", 8}
{"leadville", 10200}
{"madrid", 1305}
{"richmond",19}
{"spokane", 1909}
{"wichita", 1305};
template high_city(name ? altitude > 5000, altitude);
query high_cities (city : high_city);

The tutorial1 HighCities code example runs this query. The console output when the query is run, the solution generated is:

high_city(name = addis ababa, altitude = 8000)
high_city(name = denver, altitude = 5280)
high_city(name = flagstaff, altitude = 6970)
high_city(name = leadville, altitude = 10200)

The query pattern expression is high_city(name ? altitude > 5000, altitude), which states the solution consists of axioms with name "high_city" having 2 terms, the first is named "name" and the second is named "altitude". An expression in the first term excludes cities which do not have altitude greater than 5,000.

The order of the template terms is significant here because the city axiom source has anonymous terms, which causes unification pairing by position to occur. Term names can be specified by inserting a list after the name of the axiom source ie. axiom city(name, altitude): .... The order of the terms in the axiom source does not matter when the terms are named. See tutorial1 HighCities2 code example where the axiom terms are in reverse order to the template terms.