Navigation
  • Home
  • Fuzzy Logic Programs
  • Multi-Adjoint Lattices
  • Syntax
  • Procedural Semantics
  • Prolog Code Generation
  • How to Use FLOPER
    • Starting
    • Managing Projects
    • Loaging Fuzzy Programs
    • Using Lattices
    • Executing Scripts
    • Running Programs
    • Execution Tree
    • Declarative Traces
  • Bibliography
  • Downloads
Interesting Links
  • fuzzyXPath Project
  • FLUS Tool
  • DEC-Tau
  • Similarities in FLOPER
Home

Translating fuzzy programs into Prolog code

This section is devoted to detail a simple, but powerful method for translating fuzzy programs into directly executable standard Prolog code. The final goal is that the compiled code be executed in any Prolog interpreter in a completely transparent way for the final user, i.e., our intention is that after introducing fuzzy programs and fuzzy goals to the system, it be able to return fuzzy computed answers (i.e., pairs including truth degrees and substitutions) even when all intermediate computations have been executed in a pure (not fuzzy) logic environment. The syntactic conventions that our system accepts when parsing multi-adjoint logic programs are very close to those seen in the previous section. During the parsing process, our system produces Prolog code following these guidelines:

  • Each atom appearing in a fuzzy rule is translated into a Prolog atom extended with an extra argument, called truth variable of the form _TVi . The intended objective of this anonymous variable is to contain the truth degree obtained after the subsequent evaluation of such atom.
  • The role of aggregator operators can be easily played by standard Prolog clauses defining aggregator predicates:

and_prod(X,Y,Z):-Z is X * Y.
and_godel(X,Y,Z):-(X=<Y,Z=X;X>Y,Z=Y).
and_luka(X,Y,Z):-H is X+Y-1, (H=<0,Z=0;H>0,Z=H).

  • Program facts (i.e., rules with no body) are expanded at compilation time to Prolog facts, where the additional argument of the (head) atom is not a truth variable but just the truth degree of the corresponding rule. For instance, rules four and five and R5 in our example, can be represented by the Prolog facts r(_,0.7) and s(b,0.9), respectively.
  • Program rules are translated into Prolog clauses by performing the appropriate calls to the atoms presented in their bodies. Regarding the calls to aggregator predicates, they must be postponed to the end of the body, in order to guarantee that the truth variables used as arguments be correctly instantiated when needed. In this sense, it is also important to respect an appropriate ordering when performing the calls. In particular, the last call must necessarily performed to the aggregator predicate modeling the adjoint conjunction of the implication operator of the rule, by also using its truth degree. For instance, the first three rules in our example can be represented by the Prolog clauses:

p(X,_TV0):- q(X,Y,_TV1),r(Y,_TV2),
            and_godel(_TV1,_TV2,_TV3),and_prod(0.8,_TV3,_TV0).
q(a,Y,_TV0) :- s(Y,_TV1), and_prod(0.7,_TV1,_TV0).
q(b,Y,_TV0) :- r(Y,_TV1), and_luka(0.8,_TV1,_TV0).

  • A fuzzy goal is translated into a Prolog goal where the corresponding calls to atoms appear in their textual order before the ones for aggregator predicates. Since aggregators are not associative in general, they must appear in an appropriate sequence, as also occurred with the translation of clause bodies explained before. For instance, the goal p(X) &godel r(a) in our example, can be represented by the following Prolog goal:

    ?- p(X,_TV1),r(a,_TV2),and_godel(_TV1,_TV2,_TV3).

Following this method, the FLOPER tool translates to standard Prolog code the multi-adjoint logic program and goal shown before. In particular, we have used Sicstus Prolog v.3.12.5 for executing them as well as for implementing the tool that we are going to explain immediately.