Higher-Order Rules

Compound terms can also be used to support a form of higher-order logic. Flora allows variables to range over properties, classes, or even formulas.

For example, recall our rule to get the number of children of a person:

?person [ numberOfChildren -> ?num ] :-
  ?num = count{?x | ?person [ child -> ?x ]}.

Now suppose we also want number of cousins, number of uncles, and so forth. We could create a new property, and a new rule, for each such case, but that would force us to repeat ourselves a lot, which is never a good idea. Instead, we can use a “higher-order” property with the relation type as an argument:

?person [ numberOf(?relation) -> ?num ] :-
  ?num = count{?x | ?person [ ?relation -> ?x ]}.

Now, we can use expressions like

?person [ numberOf(child) -> ?num ]
?person [ numberOf(uncle) -> ?num ]

and so forth. The ?relation variable in the rule ranges over properties like child and uncle, and the numberOf property takes other properties as an argument.

As mentioned earlier, it is also possible to use entire formulas as parameters. See the section “Reification” in the Flora-2 Manual [1]. This feature is not needed for most users.

[1]Kifer, Michael, Guizhen Yang, Wan Hui, and Chang Zhao. 2014. Flora-2: User’s Manual. 1.0. Stony Brook University, Stony Brook: Department of Computer Science.