Fuzzy Control and Fuzzy Logic Programming

by
Giangiacomo Gerla
Department of Mathematics and Computer Science, University of Salerno
Via S. Allende 84081 Baronissi (Salerno) Italy
gerla@libero.it

Abstract. We propose an implementation of fuzzy and classical logic programming inspired to Clark's completion method of a program (see[2]). Also, since we can consider fuzzy control as a chapter of fuzzy logic programming (see [6] and [7]), we show that the same algorithms are useful tools for fuzzy control. We confine ourselves to function-free first order languages.

Introduction

Fuzzy logic programming is defined as a suitable extension of classical logic programming. As in the classical case, we start from a "fuzzy program", i.e. a fuzzy subset  p : Cl →[0,1] of the set Cl of program clauses and we associate p with the related "last fuzzy Herbrand model", i.e. the fuzzy subset of ground atomic formulas we can prove from p (see [3], [4], [7], [12], [16] and [17]). In turn, as proposed in [6] and [7], fuzzy programming logic enables us to give a rigorous approach to fuzzy control. The idea is that the fuzzy function associated with a given system of IF-THEN fuzzy rules is the interpretation of a (vague) predicate in the least fuzzy Herbrand model of a suitable fuzzy program. The intended meaning of such a predicate is that "the control y is correct given the situation x".  
	In this paper we show how to implement these ideas in Mathematica. Namely, in Section 1 we consider classical logic programming by applying some rewriting rules inspired to Clark's completion of a program (see [2]). In order to give a general framework for fuzzy logic programming, Section 2 we sketch the main definitions in the theory of the fuzzy deduction systems. In Section 3 we propose an implementation of fuzzy logic programming as a simple extension of the one proposed in Section 1. In Section 4 we recall the main definitions in fuzzy control and in Section 5 we show how to consider fuzzy control as a chapter of fuzzy logic programming. Finally, in Section 6 we show that the proposed logical interpretation gives useful suggestions and new tools for fuzzy control. In all the cases, we confine ourselves to function-free first order languages. For a theoretical justification of the proposed algorithms see the quoted papers.

1.  Classical logic Programming

loves[x_, 
        y_] := (y === x) || (x === carl && 
            y === john)  ||  (x === mary && 
            y === mary) || ((x === carl) && women[y]  &&  
            beautiful[y])
women[x_] :=  (x === mary) || ( x === louise)
young[x_] := x===louise 
tall[x_] := x === louise
beautiful[
        x_] := (Italian[x]) || (tall[x] && 
            young[x])
Italian[x_] := False

Observe that no loop occurs in these definitions since the program P is "stratified". 
	Now we can ask whether a fact is true or not in the Herbrand model associated with P, i.e. whether a fact is a theorem of P or not. Indeed, we simply have to calculate the (Boolean) value of the corresponding function.

loves[carl, louise]

In order to illustrate the role of R2, we can add to P the definite clause   
	sympathizes(x,y) ← loves(x,z)∧loves(z,y)
in which the variable z occurs in the body and does not occur in the head. We cannot translate this clause into a Mathematica equation as

sympathizes[x_, y_] := loves[x, z] && loves[z, y]

As an example, if we ask for the truth value of the formula sympathizes(louise,carl), we obtain the value False while the correct answer is True.

sympathizes[carl,louise]

The reason is that the evaluation of loves[louise,z] gives False since z is not interpreted as a free variable. Instead, by R2 we can transform sympathizes(x,y) ← loves(x,z)∧loves(z,y)  into the equivalent formula sympathizes(x,y) ← ∃z(loves(x,z)∧loves(z,y)). Then, it remains to interpret by the existential quantifier. In accordance with logic programming ideas, we can refer to the Herbrand universe U of the program. Since the language of our program is function-free, U coincides with the (finite) set of constants. Then the valuation of an existential formula reduces to the valuation of a finite disjunction of formulas. At first we define the Herbrand universe U and its Cartesian product.

U := {carl, john,  louise, mary} ;
Cartesian[l_, m_] := 
      Flatten[Outer[List, l, m], 1]
UxU := Cartesian[U, U]

Then, we define the predicate Thereis[x_,U_,A_] whose meaning is that there is an x in the universe U satisfying the formula A.

Vel[{X_, Y_}] := Or[X, Y]; 
    Vel[L_] := Or[First[L], Vel[Rest[L]]]; 
Thereis[x_, Universe_, A_] := 
      Vel[Map[Function[x, A], Universe]]

Finally, we are ready to give a correct definition of the predicate Sympathizes.

sympathizes[x_, y_] := 
        Thereis[z, U, Unevaluated[loves[x, z] && loves[z, y]]];

sympathizes[carl, louise]

We conclude this section by noticing that there are several methods to recover information. As an example we can search for all the individual satisfying a given predicate. To this aim we use the function "Select".

Select[U, beautiful]

loves[{X_, Y_}] := loves[X, Y];
Select[UxU, loves]

More complexes queries are possible by using "Function" to transform a logic expression into a function with Boolean values.

Select[U, Function[X, loves[carl, X] && Not[beautiful[X]]]]

2. Fuzzy logic

In this section we sketch some basic notions on the inferential apparatus of a fuzzy logic (see [8], [13], [14] and [15]). The starting point is that instead of the Boolean algebra {False,True} we can consider as set of truth values the interval [0,1]. We interpret 0 as False and 1 as True. This leads to extend the notions of subset and relation in the following way. Given a set S, we define a fuzzy subset of S as a map s : S → [0,1]. For any x∈S, we interpret the number s(x) as the membership degree of x in s. We say that s is crisp provided that for any x∈S either s(x) = 0 or s(x) = 1. Then we can identify the (characteristic functions of the) subsets of S with the crisp fuzzy subsets of S. Given two sets S and T, a fuzzy relation from S to T is a fuzzy subset of the Cartesian product S×T, i.e. a map f : S×T→[0,1]. A fuzzy relation f is also called a (non deterministic) fuzzy function. The intended meaning is that, given an input x∈S, the output is the fuzzy subset s : T → [0,1] defined by setting s(y) = f(x,y). 
	Consider a first order language in which properties and relations which are vague in nature are admitted. As an example properties as "slow", "big", relations as "near", "similar" and so on. Then we interpret these properties and relations by fuzzy subsets and fuzzy relations, respectively. We can extend such an interpretation to the whole set of formulas 𝔽 by a suitable interpretation of the logical connectives and of the quantifiers. Usually, one interprets the negation ¬ by the operation ∼(x) = 1-x and the conjunction ∧ by a suitable continuous triangular norm ⊗ : [0,1]×[0,1]→[0,1], i.e. a commutative, associative, order preserving operation ⊗ such that x⊗1 = x for any x∈[0,1]. Moreover, the disjunction ∨ is interpreted by the co-norm ⊕ associated with ⊗, i.e. the operation defined by setting x⊕y= ∼(∼x⊗∼y), and the implication → is interpreted by the operation ↦ defined by setting x↦y = Sup{z∈[0,1] : x⊗z≤y}. Finally, the existential and the universal quantifiers are interpreted by the greatest lower bound and the least upper bound, respectively. 

Examples. We can set x⊗y = Min{x,y} by obtaining a continuous triangular norm whose co-norm is the Max operation and whose implication is defined by setting x↦y = 1 if x≤y and x↦y = y otherwise. Another example is the usual product whose associated co-norm is the operation x+y-xy an whose implication is defined by setting x↦y = Min{y/x,1}.  Finally, a famous example is furnished by the Lukasiewicz norm obtained by setting x⊗y = Max{x+y-1,0}. In such a case x⊕y= Min{x+y,1} and x↦y = Min{1-x+y,1} = (∼x)⊕y. 

Any interpretation of the logical connectives gives corresponding definitions of the basic set-theoretical operations. Indeed, the complement of a fuzzy subset s is the fuzzy subset -s defined by setting s(x) = ∼s(x). The union of two fuzzy subsets s : S → [0,1]  and t : S → [0,1] is the fuzzy subset s⋃t defined by setting (s⋃t)(x) = s(x)⊕t(x). The intersection is the fuzzy subset s⋂t defined by setting (s⋂t)(x) = s(x)⊗t(x). We also define s→t as the fuzzy subset defined by setting (s→t)(x) = s(x)→t(x). Finally, we call Cartesian product of s and t the fuzzy subset s×t : X×Y → [0,1] defined by setting (s×t)(x,y) = s(x)⊗t(y). 
	The deduction apparatus of a fuzzy logic is defined in the following way. We define a fuzzy Hilbert system as a pair 𝒮 = (a, ℝ) where a is a fuzzy subset of 𝔽, the fuzzy subset of logical axioms, and ℝ is a set of fuzzy rules of inference. In turn, a fuzzy inference rule is a pair r = (r',r"), where 
  - r' is a partial n-ary operation on 𝔽 whose domain we denote by Dom(r),
  - r" is an n-ary operation on [0,1] preserving the least upper bound in each variable, i.e.
	 		r"((Subscript[x, 1]),..., Supi∈I yi, ..., xn) = Supi∈I r"((Subscript[x, 1]), ..., yi, ..., xn).
In other words, an inference rule r consists 
  - of a syntactical component r' that operates on formulas (in fact, it is a rule of inference in the usual sense),
  - of a valuation component r" to calculate information on the truth-value of the conclusion from information on the truth-values of the premises (see [8], [13] and [19]). 
Namely, we interpret an application of an n-ary inference rule r by saying that:
	IF    		you know that α1,…,αn  are true (at least) to the degree  λ1,…,λn
	THEN    	r'(α1,…,αn) is true (at least) at level r"(λ1,…,λn).
Given a formula α, we interpret a(α) as the a prior information on the truth value of α, i.e. the information "the truth value of α is at least a(α)". A proof π of  α is a sequence α1,...,αm of formulas such that αm = α together with the related "justifications". This means that, for any formula αi, we must specify whether
  (i)    αi is assumed as a logical axiom; or
  (ii)   αi is assumed as an hypothesis; or
  (iii)  αi is obtained by an inference rule (in this case we must indicate also the rule and the formulas from α1,...,αi-1 used to obtain αi). 
Observe that we have only two proofs of  whose length is equal to 1. The formula α with the justification that α is assumed as a logical axiom and the formula  α with the justification that α is assumed as an hypothesis. Moreover, as in the classical case, for any i ≤ m, the initial segment α1,...,αi  is a proof of αi we denote by π(i). Differently from the crisp case, the justifications are necessary since different justifications of the same formula give rise to different valuations. We assume that the available information is a fuzzy set of formulas v : 𝔽 →[0,1] we call fuzzy subset of hypotheses. Given a formula α, we interpret the value v(α) as the claim "the truth value of α is at least v(α)". Let π be a proof. Then the valuation Val(π,v) of π with respect to v is defined by induction on the length m of π as follows. If the length of  is 1, then we set 
	Val(π,v) = a(α1) if  α1 is assumed as a logical axiom, 
	Val(π,v) = v(α1) if α1  is assumed as an hypothesis. 
Otherwise, we set

 Val(π,v) = {({{a(αm)                                                              ,     if  αm is assumed as a logical axiom,}, {v(αm)                                                                ,   if  αm  is assumed as an hypothesis,       }, { r"(Val((i(1)),v),…,Val((i(n)),v)), if αm = r'((Subscript[α, i(1)]),…,(Subscript[α, i (n)])),                    }})
           	                  
where, i(1)<m,…,1 i(n)<m. If α is the formula proven by π, the meaning we assign to Val(π,v) is that:  given the information v, π assures that α holds at least at level Val(π,v). In accordance, if π and π'  are two different proofs of the same formula α, then, since we can claim that α holds at least at level Val(π,v) and at least at level Val(π',v), we can claim that α holds at least at level Max{Val(π,v), Val(π',v)}. This observation suggests the following definition.

Definition 2.1. Given a fuzzy Hilbert system, and a fuzzy subset of hypotheses v, the fuzzy subset of theorems we can derive from v is the fuzzy subset 𝒟(v) of formulas defined by setting, 
	𝒟(v)(α) = Sup{Val(π,v) : π  is a proof of α},	                                                              (2.1)
for every formula α.

The meaning of the number 𝒟(v)(α) is still
	 given the information v,  α holds at least at level 𝒟(v)(α),
but we have also that
	𝒟(v)(α) is the best possible valuation we can draw from the information v.

Definition 2.2. Let 𝒮 = (a, ℝ) be a fuzzy Hilbert system in a first order language containing the logical connectives ∧, →. Then a fuzzy program is a fuzzy subset p :  Cl → [0,1] of the set Cl of program clauses. The least fuzzy Herbrand's model of p is the fuzzy subset of facts we can prove from p, i.e. the restriction of 𝒟(p) to the set of facts.

3. Fuzzy logic programming

In order to sketch a Mathematica algorithm for fuzzy logic programming, we consider a very simple fuzzy Hilbert system whose language is any function-free first order language. In such a system there is no logical axiom (i.e. the fuzzy set of logical axioms a is constantly equal to zero) and we have the following inference rules:

-  Modus Ponens Rule
given  α           (at degree   λ) and    α→β  (at degree  μ), . . . we can obtain  β  (at degree   λ⊗μ)
- Particularization Rule 
given   ∀x α  (at degree  λ), . . . we can  obtain            α(x/c)                                  \((at\ degree\ \ λ)\)
- Conjunction Rule
given   α  (at degree  λ) and  β  (at degree  μ), ... we can obtain   α∧β               (at degree λ⊗μ).

As an example, consider  the following  fuzzy program p : Cl →[0,1] we obtain  from the program exposed  in Section 1 and in which each formula is asserted  with a truth value in [0,1].

loves(x,x) 					[0.6]
	loves(carl,john)				[0.7]
	loves(mary,mary)				[0.9]
	loves(carl,y)←women(y)∧beautiful(y)		[0.9]
	women(mary)					[1]
	women(louise)					[1]
	young(louise)					[0.8]
	tall(louise)					[0.7]
	beautiful(x) ← Italian(x)			[0.6]
	beautiful(x)←tall(x)∧young(x)		[0.9]
	sympathizes(x,y) ← loves(x,z)∧loves(z,y)	[0.8]

The proofs from this program are very simple. As an example, in order to prove loves(carl,louise), observe that by the Particularization Rule	
	loves(carl,louise)←women(louise)∧beautiful(louise) 	at degree 0.9.
Then, since
	women(louise)						at degree 1,
it remain to prove the formula beautiful(louise). Now this can be done in two way. We can observe directly that
	beautiful(louise) 					at degree 0.5,
and therefore to conclude 
	loves(carl,louise)					at degree 1⊗0.5⊗0.9 = 0.45
Also, since by Particularization
	beautiful(louise)←tall(louise)∧young(louise)		at degree 0.9
and  
	tall(louise)						at degree 0.7
	young(louise)						at degree 0.8
we can prove
	beautiful(louise) 					at degree 0.7⊗0.8⊗0.9 = 0.504.
In such a case we prove
	loves(carl,louise) 					at degree 0.9⊗1⊗0.504 = 0.4536.
Thus, in accordance with Definition 2.1, loves(carl,louise) was proved at degree Max{0.45, 0.4536} = 0.4536. 
	Now, in order to translate such a fuzzy program into a set of definitions, we can try to go on by the same normalization method as in  Section 1. Now, it is easy to see that R1 and R2 apply also in this case and therefore that the fuzzy program p is equivalent with the following fuzzy program (see the note at the end of the section).

loves(x,y)←y = x					[0.6]
	loves(x,y)←(x = carl)∧(y = john)			[0.7]
	loves(x,y)←(x = mary)∧(y = mary)			[0.9]
	loves(x,y)←(x = carl)∧women(y)∧beautiful(y)		[0.9]
	women(x)←x = mary					[1]
	women(x)←x = louise					[1]
	young(x)←x=louise					[0.8]
	tall(x)←x = louise					[0.7]
	beautiful(x)←Italian(x)					[0.6]
	beautiful(x)←tall(x)∧young(x)				[0.9]
	sympathizes(x,y) ← ∃z(loves(x,z)∧loves(z,y))		[0.8]

Unfortunately we cannot substitute the set of clauses whose head is love(x,y) with an unique formula as
	loves(x,y)←((y=x)∨((x=carl)∧(x=john))
                                ∨((x=mary)∧(y=mary))∨((x=carl)∧women(y)∧beautiful(y)))     [λ].
In fact, in such a case we should able to prove both loves(mary,mary) and loves(carl,john) at degree λ. Instead, the clause
	loves(x,y)←(x = mary)∧(y = mary)			[0.9]
enables us to prove   loves(mary,mary) at degree 0.9 and the clause
	loves(x,y)←(x = carl)∧(y = john) 			[0.7]
enables us to prove loves(carl,john) at degree 0.7. Then, in accordance with Definition 2.1, to calculate the degree at which we can prove a fact as loves(c,c') we have to consider all the proofs arising from the clauses whose head is loves(x,y) and then to calculate the maximum of the corresponding valuations. This leads to the following definitions where we have to define at first the interpretation of the existential operator and of the triangular norm (here, we assume that ⊗ is the usual product). Also, we define the identity as a function assuming values in {0,1} and not in {True, False}.

Thereis[X_, Universe_, condition_] := 
      Max[Map[Function[X, condition], Universe]]
x_⊗y_ := (x*y) ;  
    eq[x_, y_] := If[y === x, 1, 0]

loves[x_, y_] := 
      Max[
eq[x, 
            y]⊗0.6, 
(eq[x, 
                carl]⊗eq[y, 
                john])⊗0.7, 
(eq[x, 
                mary]⊗eq[y, 
                mary])⊗0.9, 
(eq[x, 
                carl]⊗women[y])⊗( 
            beautiful[y]⊗0.9)]
loves[{x_, y_}] := loves[x, y]

    
women[x_] :=  
      Max[
eq[x, mary], 
eq[x, 
          louise]]

    
young[x_] := eq[x, louise]⊗0.8 
\(\(\(tall[x_] := eq[x, louise]⊗0.7\)\(
\)
    \)\)
\(\(\(beautiful[x_] := 
      Max[
Italian[
            x]⊗0.6, 
\((tall[
                x]⊗young[x])\)⊗0.9]\)\(
\)
    \)\)
sympathizes[x_, y_] := 
      Thereis[z, U, 
        Unevaluated[(loves[x, z]⊗loves[z, 
                  y])⊗0.8]]

    
Italian[x_] := 0

To recover information, we can ask directly for the truth value of a fact

loves[carl, louise]

sympathizes[carl, louise]

sympathizes[carl, louise]

Also, we can fix a threshold  λ  and to select all the elements (the pairs) satisfying a given predicate at least with the threshold λ

Select[UxU, 
      Function[Z, 
        loves[Z]⊗beautiful[Z[[2]]] > 0.3]]

Finally, we can list all the answers to a query together with the related degrees.Namely, we select the answers whose truth degree is different from zero. To this aim we define the predicate "pos"

pos[{a_, b_}] := b > 0

And we use the Select function

Select[Map[Function[X, {X, loves[carl, X]}], U], pos]

Or, to obtain answers ordered with respect to the truth degree

Sort[Select[Map[Function[X, {X, loves[carl, X]}], U], pos], 
      Last[#2] < Last[#1] &]

sympathizes[carl, louise]

Note. To justify R2, consider the formula 
	sympathizes(x,y) ← loves(x,z)∧loves(z,y)	[0.8]
where z is a free variable. Then, from the point of view of the proposed deduction apparatus such a formula is equivalent to the fuzzy subset of formulas
	sympathizes(x,y) ← loves(x,c")∧loves(c",y)  	[0.8]
where c" varies in U. Let c and c' be two elements in U. Then, for any c" ∈ U, we can prove sympathizes(c,c') at degree  |loves(c,c")|⊗|loves(c",c')|⊗0.8. where |loves(c,c")| and |loves(c",c')|  denote the degree at which we can prove loves(c,c") and loves(c",c'), respectively. Consequently, in accordance with Definition 2.1, we can prove loves(c,c')  at degree
	 Max{|loves(c,c")|⊗|loves(c",c')|⊗0.8 : c" ∈U}.
On the other hand, if we start form the formula
	sympathizes(x,y) ← ∃z(loves(x,z)∧loves(z,y))	[0.8],
then, since the valuation of  ∃z(loves(x,z)∧loves(z,y)) is Max{|loves(c,c")|⊗|loves(c",c')| : c" ∈U}, we can prove sympathizes(c,c') at degree (Max{|loves(c,c")|⊗|loves(c",c')| : c" ∈U})⊗0.8.  Since ⊗ is distributive with respect to Max, this proves the validity of R2. Observe that such an equivalence holds only since the existential quantifier is evaluated by the Max function in the Herbrand universeU. This explains also way in fuzzy logic the existential quantifier is interpreted by the least upper bound Sup : P([0,1])→[0,1]. This in spite of the fact that this quantifier looks to be an extension of the disjunction and therefore that the natural candidate for its interpretation is the operator ⊕ : P([0,1])→[0,1] defined by setting ⊕(X) = Sup{(Subscript[x, 1])⊕...⊕(Subscript[x, n]) : (Subscript[x, 1])∈X,... ,(Subscript[x, n])∈X}.

4. Triangular-norm based fuzzy control

As an application of the sketched fuzzy logic programming theory, we will consider the main success of fuzzy set theory: fuzzy control. Recall that the aim of classical control theory is to individuate a function f : X → Y such that f(x) is the correct control given the input x. To do this, the starting point is a general theory about the phenomenon under consideration. From this theory we obtain some differential equations and then f is obtained as a solution of these equations. The paradigm used in fuzzy control theory, as devised by Zadeh in [19] and by Mamdani in [11], is totally different. Indeed, in fuzzy control one tries to obtain f from the verbal information given by an expert on the control under consideration (imagine the expert as a cleaver “old hand” with no theoretical knowledge or mathematical competence). Such an information is expressed by a system of IF-THEN rules as

	IF x is Little 	 	THEN  	y is Slow,
	IF x is Small		THEN  	y is Fast,
 	IF x is Medium 	THEN  	y is Moderate,	
	IF x is Big 	 	THEN  	y is Veryfast,
	IF x is Verybig  	THEN  	y is Moderate,

where "Little", "Slow", "Small", "Fast", "Medium", "Moderate", "Big", "Veryfast", "Verybig" are labels for the fuzzy quantities 
	little : X  → [0,1] ,  		small : X → [0,1], 		medium : X → [0,1]
	big : X → [0,1],        	 	verybig : X → [0,1],		slow : Y  → [0,1],  
	fast : Y → [0,1],         	moderate : Y → [0,1],	veryfast : Y → [0,1],  
respectively. The whole system of rules can be represented by the table:

                                               ({{x, y}, {Little, Slow}, {Small, Fast}, {Medium, Moderate}, {Big, Veryfast}, {Verybig, Moderate}})
 
Also, any pair defines a fuzzy point obtained as the corresponding Cartesian product and the whole system is associated with the fuzzy function obtained as the union of the fuzzy points obtained in this way. In our example,
	f = (little×slow)⋃(small×fast)⋃(medium×moderate)⋃(big×veryfast)⋃(verybig×moderate).

Definition 4.1. (Conjunction-based fuzzy control). A system  of IF-THEN fuzzy rules is a system of rules like
	IF x is A1 THEN y is B1
	. . .
	IF x is An THEN y is Bn
where the labels Ai and Bi are interpreted by the fuzzy quantities ai : X → [0,1] and bi : Y → [0,1]. We associate any rule IF x is Ai THEN y is Bi with the fuzzy point ai×bi : X × Y → [0,1] and the whole system of rules with the fuzzy function f : X × Y → [0,1] defined by setting   f = ⋃i=1,...,n ai×bi.

Usually the union is defined by the Max operator and therefore 
	f(x,y) = Max{ai(x)⊗bi(y) : i = 1,...,n}. 
Notice that, in a sense, this approach is the fuzzy counterpart of the discretization process in which a function f is partially represented by a table like

                                                                          ({{x, y}, {(Subscript[x, 1]), (Subscript[y, 1])}, {..., ...}, {..., ...}, {..., ...}, {(Subscript[x, n]), (Subscript[y, n])}})

where x1,...,xn are elements of X and y1,...,yn the corresponding elements in Y, i.e.  f  is approximate by the union of a finite number of points (x1,y1), ..., (xn ,yn). 
	From the fuzzy function f : X × Y →[0,1] we can derive a crisp function  g : X → Y  by a "defuzzification  process". Usually the defuzzification process is obtained by the centroid method where we set, for every r∈X,
   					g(r) = (((∫_Y)f(r,y)y dy)/((∫_Y)f(r,y) dy))
	The final phase is the learning process in which the rules and the fuzzy quantities associated with the labels are changed until we can accept g as a good approximation of the ideal function f. 
	As an example, we can define the fuzzy quantities by the function triangle. Namely, given the numbers a, b, and c, we define triangle[x,a,b,c] as the function represented by a triangle whose vertexes are (a,0), (b,1) and (c,0).

\(triangle[x_, a_, b_, c_] := 
\ \ Which[x <= a, 0, x <= b, 
        x/\((b - a)\) - a/\((b - a)\), x <= c, x/\((b - c)\) - c/\((b - c)\), 
        x > c, 0]\)

Assuming that X = [0,10] and  Y = [0,5], we define in X the fuzzy quantities "Little", "Small", "Medium", . . . . and in Y the fuzzy quantities "Fast", "Moderate", ... .

little[x_] := triangle[x, -1.5, 0.6, 2.5]
small[x_] := triangle[x, 0.5, 2.5, 4.5]
medium[x_] := triangle[x, 3, 5, 7]
big[x_] := triangle[x, 5, 7, 12]
verybig[x_] := triangle[x, 6, 10, 17]
slow[y_] := triangle[y, 0, 0, 3]
moderate[y_] := triangle[y, 1, 2.5, 4]
fast[y_] := triangle[y, 3, 4.5, 5]
veryfast[y_] := triangle[y, 4, 4.5, 6]

This is the definition of the fuzzy function  f : X × Y → [0,1] in accordance with Definition 4.1.

f[x_, y_] := 
      Max[little[x]⊗slow[y], small[x]⊗fast[y], 
        medium[x]⊗moderate[y], big[x]⊗veryfast[y], 
        verybig[x]⊗moderate[y]]

ContourPlot[f[x, y], {x, 0, 10}, {y, 0, 5}, 
        AspectRatio -> Automatic]; Print["    The fuzzy function f :X × Y → [0,1] ."]

By the defuzzification process we obtain the crisp function g

g[r_] := (Sum[f[r, y]*y, {y, 0, 5, 0.2}])/(Sum[
            f[r, y], {y, 0, 5, 0.2}])

Plot[g[y], {y, 0, 10}, PlotRange -> {0, 5}];  
    Print["  The result of the defuzzification process"]

Now, in spite of the great success of Definition 4.1 to calculate the fuzzy function f, there is no convincing theoretical justification for such a definition. It is also surprising that to the IF-THEN structure of the system corresponds an algorithm based on conjunction. Obviously, the first temptation is to interpret the IF-THEN in a rule as a logical implication. As an example, we could interpret a rule as "If x is Little then y is Slow" by the first order formula Little(x)→Slow(y). Indeed, in literature exists also the following definition:

Definition 4.2.  (Implication-based fuzzy control).  Consider a system  of IF-THEN fuzzy rules like
	IF x is A1 THEN y is B1
	. . .
	IF x is An THEN y is Bn
where the labels Ai and Bi are interpreted by the fuzzy quantities ai : X → [0,1] and bi : Y → [0,1]. Then the implication-based fuzzy function  (Subscript[g, 2]) : X × Y → [0,1] associated with such a system is defined by setting  (Subscript[g, 2]) =⋂i=1,...,n ai→bi.

Usually, the intersection is defined by the operator Min and therefore 
	(Subscript[g, 2])(x,y) = Mini=1,...,n {ai(x)↦bi(y) i = 1,...,n}. 
The following is a program to calculate (Subscript[g, 2]). Recall that in the case the triangular norm is the product, we have that x↦y = Min{y/x,1}.

entails[x_, y_] :=  If[x ≤  y, 1, y/x]

\(g2[x_, y_] := 
      Min[
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ entails[
          little[x], slow[y]], 			
		\ \ \ \ \ entails[
          small[x], fast[y]], 
			entails[medium[x], 
          moderate[y]], 
			entails[big[x], 
          veryfast[y]], 
		\ \ \ \ \ \ \ \ \ entails[verybig[x], 
          moderate[y]]
			]\)

ContourPlot[g2[x, y], {x, 0, 10}, {y, 0, 5}, 
      AspectRatio -> Automatic]; 
    Print["  The implication-based fuzzy control"]

The result of this approach is rather unsatisfactory since the initial intuition is not well represented. This is not surprising. As an example, assume that r is an input such that Little(r) is false. Then the formula Little(r)→Slow(t) is true for any t∈Y and therefore any t∈Y gives a correct control, an absurdity.
	As matter of fact, we cannot interpret a system of IF-THEN fuzzy rules as a set of logical implications in a direct way. In the next section we will show how to translate the system into a set of formulas in fuzzy logic.

5. Fuzzy Control as a chapter of programming logic

The main idea in this section is that any fuzzy control system S (as usually defined) is representable as a fuzzy theory in a fuzzy logic, namely, by a fuzzy program. Indeed, to give a logical interpretation to a system as 
	IF x is Little 	 	THEN  	y is Slow,
	IF x is Small 		THEN  	y is Fast,
 	IF x is Medium 	THEN  	y is Moderate,	
	IF x is Big 	 	THEN  	y is Veryfast,
	IF x is Verybig  	THEN  	y is Moderate,
we introduce a new predicate good(x,y) whose interpretation is that "y is a correct control given x". Moreover, we translate the fuzzy system into the following fuzzy program p : Cl →[0,1]
	good(x,y) ←   little(x)⋀slow(y)              	[λ\(\_1\)]
	good(x,y) ←  small(x)⋀fast(y)               	[(Subscript[λ, 2])]
	good(x,y) ←  medium(x)⋀moderate(y)  	[(Subscript[λ, 3])]
	good(x,y) ←  big(x)⋀veryfast(y)           	[(Subscript[λ, 4])]
	good(x,y) ← verybig(x)⋀moderate(y)   	[(Subscript[λ, 5])]
	little(r)                		                  	[little(r)]
	fast(t)                  		                  	[fast(t)]
	. . .
where 
  - λ\(\_1\), ..., λ\(\_5\) are elements in [0,1],
  - we write α  [(Subscript[λ, i])]  to denote that p(α) = (Subscript[λ, i]),
  - we list only the clauses α for which p(α) ≠ 0,
  - X and Y are finite approximations of the intervals [0,10] and [0,5], respectively,
  -  r is any element in X and t is any element in Y we interpret as constants.
The idea is that the fuzzy program p is not a tool to define a function f :X→Y representing the correct answer f(x) given the input x. The fuzzy program p is able only to define a binary fuzzy predicate "good", expressing, given an input x, our graded opinion (degree of preference, tastes) on a possible control y. We denote by good(r,t) the degree at which we can prove the fact good(r,t) given the available information. Therefore, the number good(r,t) represents the information "given r the control y is good at degree good(r,t)".  It is immediate that by applying the procedure of Section 3 for fuzzy logic programming in the case λ\(\_1\)= ...= λ\(\_5\) = 1, we obtain the fuzzy function proposed by the classical fuzzy control. In general, the fuzzy function good depends on the parameters  λ\(\_1\), ..., λ\(\_5\).

good[x_, y_, l1_, l2_, l3_, l4_, l5_] := 
      Max[
(little[x]⊗slow[
                y])⊗l1, 
(small[
                x]⊗fast[
                y])⊗l2, 
(medium[
                x]⊗moderate[
                y])⊗l3, 
(big[
                x]⊗veryfast[
                y])⊗l4, 
(verybig[
                x]⊗moderate[y])⊗l5]

The following picture represents the graphic of the fuzzy function good corresponding to the parameters 1, 1, 0.6, 0.2, 0.9.

ContourPlot[
          good[x, y, 1, 1, 0.6, 0.2, 0.9], {x, 0, 10}, {y, 0, 5}, 
          AspectRatio -> Automatic] ; 
 Print["The predicare good corresponding to the parameters 1, 1, 0.6, 0.2, 0.9"]

From this fuzzy function we obtain a crisp function g: X→Y by the defuzzification process:

g[r_, l1_, l2_, l3_, l4_, 
        l5_] := (Sum[
            good[r, y, l1, l2, l3, l4, l5]*y, {y, 0, 5, 0.1}])/(Sum[
            good[r, y, l1, l2, l3, l4, l5], {y, 0, 5, 0.1}])

Also, we set

good[x_, y_] := good[x, y, 1, 1, 1, 1, 1];   g[y_] := 
      g[y, 1, 1, 1, 1, 1]

The following picture represents both the functions resulting from the parameters 1, 0.5, 1, 1, 1 and the parameters 1, 1, 0.6, 0.2, 0.9.

Plot[{g[x, 1, 0.5, 1, 1, 1], g[x, 1, 1, 0.6, 0.2, 0.9]}, {x, 0, 10}, 
        PlotRange -> {0, 5}, 
        PlotStyle -> {RGBColor[0, 0, 0], 
            RGBColor[1, 0, 0]}];

As a matter of fact the parameters  λ\(\_1\), ..., λ\(\_5\) have to be the result of a learning process to obtain a function g sufficiently close to the ideal function f . In this process it is useful to introduce further parameters in the fuzzy program. As an example in defining the interpretations of the predicates little, slow,... . This is in accordance with the fact that the interpretation of a vague predicate is, in turn, vague, i.e. there are infinite many fuzzy subsets which are reasonable interpretations of the predicate. Observe that our logical approach to fuzzy control makes the learning process in fuzzy control very similar to the learning process in inductive logic. In both the cases we have to find a logical theory fitting well with the available data. Moreover the learning process looks to be more simple in our case. This thanks to the presence of real parameters, the fact that we can accept approximate solutions and the fact that the whole process is continuous with respect to these parameters.

6. Completeness,  linguistic modifiers, negative information and others

The logical approach to fuzzy control suggests new tools and possible extensions of the usual techniques. As an example, observe that the information about the exact controls are complete provided that for every possible input x a control y exists such that good(x,y) is satisfied, i.e. provided that the ∀x∃ygood(x,y) is true. Then, in account of the fact that the existential quantifier is interpreted by the least upper bound and the universal quantifier by the greatest lower bound, we can propose the following definition.

Definition 6.1. The degree of completeness of a fuzzy function good is the number 
                completeness[good] = (Subscript[Inf, x∈X])(Subscript[Sup, y ∈ Y])good(x,y)

\(completeness[z_, l1_, l2_, l3_, l4_, l5_] := 
	
      Min[Table[
          Max[Table[
              z[x, y, l1, l2, l3, l4, l5], {y, 0, 5, 0.2}]], 
					{x, 
            0, 10, 0.2}]]\)
\(completeness[z_] := 
	
      Min[Table[
          Max[Table[z[x, y], {y, 0, 5, 0.2}]], 
					{x, 0, 10, 
            0.2}]]\)

completeness[good]

completeness[good, 0.4, 1, 1, 0.4, 1]

Another interesting possibility is the introduction of linguistic modifiers in the language used to describe the correct control. As an example, we can define the linguistic modifiers  clearly[x] and vaguely[x].

clearly[x_] := x^2
vaguely[x_] := x^(1/2)

As an example, these modifiers enables us to define the following modifications of the predicate good.

vaggood[x_, y_] := vaguely[good[x, y]];
clegood[x_, y_] := clearly[good[x, y]]

It is interesting to examine the completeness degree of the two predicates just defined.

completeness[vaggood]

completeness[clegood]

ContourPlot[vaguely[good[x, y]], {x, 0, 10}, {y, 0, 5}, 
        AspectRatio -> Automatic];Print["     The predicate vaguely good"]

ContourPlot[clearly[good[x, y]], {x, 0, 10}, {y, 0, 5}, 
        AspectRatio -> Automatic]; Print["    The predicate clearly good"]

The linguistic modifiers can be also applied to the predicate that are premises in a clause.

good3[x_, y_, l1_, l2_, l3_, l4_, l5_] := 
      Max[
(vaguely[little[x]]⊗slow[
                y])⊗l1, 
(small[
                x]⊗fast[
                y])⊗l2, 
(medium[
                x]⊗moderate[
                y])⊗l3, 
(clearly[
                big[x]]⊗veryfast[
                y])⊗l4, 
(verybig[
                x]⊗moderate[y])⊗l5]

ContourPlot[good3[x, y, 1, 1, 1, 1, 1], {x, 0, 10}, {y, 0, 5}, 
        AspectRatio -> Automatic];

It is also possible to consider "negative" information by describing the control we have to avoid. To this purpose, we have to define the negation.

neg[x_] := 1 - x

As an example, we can consider dangerous a control x in the case x is either fast or very fast.

dangerous[x_, y_] := Max[fast[y], veryfast[y]]

Moreover, we are  interested on the controls that are both good and not dangerous.

goodsafe[x_, y_] := 
      good[x, y]⊗neg[dangerous[x, y]]

ContourPlot[goodsafe[x, y], {x, 0, 10}, {y, 0, 5}, 
        AspectRatio -> Automatic]; Print[" The predicate good and not dangerous"]

Observe that usually the introduction of the negation gives rise to difficulties which are both logic and computational. As an example, a clause as  dangerous(x)←¬dangerous(x) is consistent but the corresponding assignment dangerous[x_] := neg[dangerous[x]] causes a loop for any input x. This in accordance with the fact that the formula dangerous(x)↔¬dangerous(x) expressing such an assignment is inconsistent. Anyway, since we confine ourselves to stratified program, these difficulties don't arise. 
	We can increase the completeness degree by defining a default clause in the cases no condition little, medium, ... is satisfied. Namely we define the set of elements in which the fuzzy function is defined by the formulas defined(x)←small(x), defined(x)←little(x) . . . we admit ad degree 1. As a consequence, we set

defined[x_] := 
      Max[small[x], little[x], medium[x], big[x], verybig[x], 
        slow[x]]

\(Plot[defined[x], {x, 0, 10}, PlotRange -> {0, 1}]; \ 
    Print["The fuzzy subset of elements in which the control is defined"]\)

Also, we can add to the fuzzy program the default clause  
	good(x,y)←(¬defined(x))∧moderate(y)   	[0.7]

defaultgood[x_, y_] := 
      Max[
little[x]⊗slow[
            y], 
small[x]⊗fast[
            y], 
medium[x]⊗moderate[
            y], 
big[x]⊗veryfast[
            y], 
verybig[x]⊗moderate[y], 
        neg[defined[x]]⊗moderate[y]]

ContourPlot[defaultgood[x, y], {x, 0, 10}, {y, 0, 5}, 
        AspectRatio -> Automatic]; Print[" The extension of the predicate good by default"]

completeness[defaultgood]

g[r_] := (Sum[defaultgood[r, y]*y, {y, 0, 5, 0.1}])/(Sum[
            defaultgood[r, y], {y, 0, 5, 0.1}])

Plot[g[x], {x, 0, 10}];  
        Print["The result of the defuzzification process"]

Note. The usual fuzzy control is a one-step process in which the fuzzy inputs are given directly and cannot be calculate from others IF-THEN rules. Now, the power of logic, in particular of fuzzy logic, is on many-steps deductions and the fact that any theorem is a basis for new theorems.Then our translation suggests a fuzzy control able to define predicates which, in turn, are used to define new predicates and so on. In other words, we can define a stratified fuzzy control. The proposed definitions of the predicates  goodsave and defaultgood are examples in such a direction.

References

1.	Biacino L., Gerla G., Recursively enumerable L-sets, Zeitschr. f. math. Logik und Grundlagen d. Math., 33 (1987) pp. 107-113.
2.	Clark K. L., Negation as failure, in H. Gallaire and J. Minker ed., Logic and Data Bases, pp. 293-322, Plenum Press (1978).
3.	Dubois D., Prade H., What are fuzzy rules and how to use them, Fuzzy Sets and Systems, 84 (1996) pp. 169-185.
4.	Fitting M., Bilattices and semantics of logic programming, Journal of Logic Programming, 11 (1991) pp. 91-116. 
5.	Gerla G., Fuzzy logic: Mathematical Tools for Approximate Reasoning, Kluwer Academic Publishers, Dordrecht, The Netherlands, 2000.
6.	Gerla G., Fuzzy control as a fuzzy deduction system, Fuzzy Sets and Systems, 121 (2001) pp. 409-425.
7.	Gerla G., Fuzzy Logic Programming and Fuzzy Control, to appear on Studia Logica.
8.	Goguen J. A., The logic of inexact concepts, Synthese, 19 (1968/69) pp. 325-373.
9.	Hájek P., Metamathematics of Fuzzy Logic, Kluwer Academic Publishers, Dordrecht, The Netherlands, 1998.
10. 	Klir G., Yuan B., Fuzzy sets and fuzzy logic; theory and applications, Prentice Hall, Englewood Cliffs, N. Y. (USA), 1995.
11.	Mamdani, E., Application of fuzzy logic to approximate reasoning using linguistic systems, Fuzzy Sets and Systems, 26 (1977) pp. 1182-1191.
12.	Medina J., Ojeda-Arciego M., Vojtas P., Multi-adjoint logic programming with continuous semantics. In Proc. LPNMR’01, 2001, to appear.
13.	Pavelka J., On fuzzy logic I: Many-valued rules of inference, Zeitschr. f. math. Logik und Grundlagen d. Math., 25 (1979) pp. 45-52. 
14.	Pavelka J., On fuzzy logic II: Enriched residuated lattices and semantics of propositional calculi, Zeitschr. f. math. Logik und Grundlagen d. Math., 25 (1979) pp. 119-134. 
15.	Pavelka J., On fuzzy logic III: Semantical completeness of some many-valued propositional calculi, Zeitschr. f. math. Logik und Grundlagen d. Math., 25 (1979) pp. 447-464. 
16.	Vojtas P., Many valued logic programming handling uncertainty in AI, Proceedings of LACS, Warsawa, 1966.
17.	Vojtas P., Fuzzy logic programming, Fuzzy Sets and Systems, 124 (2001) pp. 361-370.
18.	Zadeh L.A., Fuzzy Sets, Information and Control, 12 (1965) pp. 338-353.
19.	Zadeh L.A., Fuzzy logic and approximate reasoning , Synthese, 30 (1965) pp. 407-428.

The author is full Professor in "Computability Theory" at the University of Salerno (Italy). His interests are in fuzzy logic, fuzzy computability and pointless geometry.He is author of about 90 papers.