Next: Non-DeterminismDATALOG Relationalizing, Up: DATAFUN as a Previous: Footed Facts and

Footed Rules and the density Example

In [WPP77] there are also DATALOG Horn facts about population (in millions), which we think should be `functionalized' to DATAFUN footed facts as demonstrated for area. On this basis the paper supplies the population density (per square mile) of a country, using the DATALOG rule (somewhat extralogical because of the is-call for D)


density(C,D) :- pop(C,P), area(C,A), D is (P*1000)/A.
This can be mimicked by the equivalent DATAFUN rule (with is-calls for P and A)

density(C)  :-  P is pop(C), A is area(C)  &  /(*(P,1000),A).
which may be condensed to the DATAFUN rule (without is-calls or auxiliary variables)

density(C)  :-&  /(*(pop(C),1000),area(C)).
Rules containing an ``&'' separator are called footed rules. The rule premises to the left of ``&'' are called body premises and act exactly like the premises of a hornish rule. The premise to the right of ``&'' is called a foot premise and differs from the other premises only in that its value becomes the value of the entire rule. Together, these premises form a valued conjunction, which like an ``&''-less conjunction can also be used directly as a query. Footed facts are special footed rules with an empty conjunction of body premises (the separator sequence ``:- &'' is normally joined to ``:-&'') and a foot premise which just denotes a value (without evaluation). So the shortened footed density rule above is not a footed fact since its foot evaluates an expression. The most natural use of the DATAFUN database would be functional calls like density(usa), returning the density value for usa. However, these rule formulations could also be inverted or even be called freely to enumerate all country/density pairs as in the relational call density(Cntry,Dnsty) (delivering both countries and their densities as bindings) or the functional call density(Cntry) (delivering countries as bindings with their densities as values).

To conclude the density example of [WPP77], PROLOG's ``database query'' rule


ans(C1,D1,C2,D2) :- density(C1,D1), density(C2,D2),
                    D1 > D2, 20*D1 < 21*D2.
and request ans(C1,D1,C2,D2) for finding countries whose population density differs by less than 5%, in RELFUN could be mimicked directly but can also be rewritten as a single valued conjunction

D1 is density(C1), D2 is density(C2), >(D1,D2), <(*(20,D1),*(21,D2))  &
                                                          ans[C1,D1,C2,D2]
where the auxiliary global ans relation transmutes to a temporary ans constructor.



Next: Non-DeterminismDATALOG Relationalizing, Up: DATAFUN as a Previous: Footed Facts and


Harold Boley & Michael Sintek (sintek@dfki.uni-kl.de)