prologpropositional-calculus

Difficulty with propositional logic in prolog


I need to convert the following propositions into prolog code and I have do not understand how the operators work. I usually use java.

"Jeans are only casual, dress pants are only formal, kakis are only semi-formal, belts are not casual, black socks are acceptable anytime. Casual = C, Semi-Formal = SF, Formal = F, Jeans = J, Dress pants = DP, Kakis = K, Belts = B, Black socks = BS. J -> C, DP -> F, K -> SF, B -> !C, BS -> (C v SF v F)"

Here is the code I already have:

casual(jeans).
formal(dress_pants, belt, black_socks).
semiFormal(khakis).
formal(belt).
semiFormal(belt).
casual(black_socks).
formal(black_socks).
semiFormal(black_socks).

Solution

  • Informally, a unary predicate p can be viewed as a set P and, consequently, a literal p(X) can be viewed as the set membership test X∈P. Therefore, a goal p(X) will be true or false (i.e., a proposition), depending on whether X belongs to the set P or not.

    The sentences "Jeans are only casual, dress pants are only formal, kakis are only semi-formal, belts are not casual, black socks are acceptable anytime." can be represented as the sets:

    And these sets can be represented in Prolog by the facts:

    casual(jeans).
    casual(black_socks).
    
    formal(dress_pants).
    formal(belt).
    formal(black_socks).
    
    semi_formal(khakis).
    semi_formal(belt).
    semi_formal(black_socks).
    

    Here are some Prolog queries about these facts:

    ?- casual(jeans).
    true.
    
    ?- casual(belt).
    false.
    
    ?- casual(X).
    X = jeans ;
    X = black_socks.
    
    ?- formal(X).
    X = dress_pants ;
    X = belt ;
    X = black_socks.
    
    ?- semi_formal(X).
    X = khakis ;
    X = belt ;
    X = black_socks.