Update: Consistency check.

From: Dirk Mittler (mdirk_at_sympatico.ca)
Date: 10/27/04


Date: Wed, 27 Oct 2004 13:48:57 -0400


>From time to time I've revisited my exercise, to write a Prolog program
which, given a term, will do its best to determine if that term is
consistent, as far as attributes of unbound variables go. Having said that,
I recognize that (1) I'm still a novice at Prolog, and (2) for entire
expressions, there is no universal way to do this. Therefore my program
passes expressions until they can be proven impossible, by choice.

Yet, it's understood that to Prolog in general,

X = X + 1

is entirely plausible, especially if your version accepts infinite, or
cyclic terms. In that case this is just a cyclic term with itself as its
first argument, and a (1) attached to it via a meaningless (+) symbol. This
is due to the fact that this (+) symbol does not necessarily imply a
mathematical function in Prolog. My program does not change this, or assume
Math is being used itself.

I had posted earlier code, and find that because this code was seen once, I
need to update it from time to time. The reality is that I only occupy
myself with this wonderful language from time to time, and here is my latest
version:

lousy_attrib(X) :-
 freeze(X, fail).

good_attrib(X) :-
 freeze(X, (X = 5)).

% consistent_s/1 will change argument !!!

consistent_s(X) :- nonvar(X).

consistent_s(X) :- var(X),
 \+ attvar(X);
 get_attrs(X, Attributes),
 test_attrs(Attributes).

test_attrs([]).

test_attrs(att(_, Value, More)) :-
 callable(Value),
 consistent_call(Value),
 test_attrs(More).

test_attrs(att(_, Value, More)) :-
 \+ callable(Value),
 test_attrs(More).

% consistent_l/1 will change arguments !!!

consistent_l([]).

consistent_l([Head | Tail]) :- is_list(Head),
 consistent_l(Head),
 consistent_l(Tail).

consistent_l([Head | Tail]) :- \+ is_list(Head),
 consistent_s(Head),
 consistent_l(Tail).

consistent_call(E) :-
 catch(E, _, true),
 E =.. L,
 consistent_l(L).

% Always use consistent/1 or consistent_all/1 !!!

consistent_all(List) :- \+ \+ consistent_l(List).

consistent(E) :- callable(E), !,
 \+ \+ consistent_call(E).

consistent(E) :- nonvar(E),
 E =.. L,
 \+ \+ consistent_l(L).

consistent(E) :- var(E),
 \+ \+ consistent_s(E).



Relevant Pages

  • How to get the terms of a compund term (predicate: simplfy)?
    ... Following Bratko's "PROLOG: Programming for Artificial ... Intelligence" I found an exercise: ... Let the procedure rearrange ... the expressions so that all the symbols precede ...
    (comp.lang.prolog)
  • Re: Value Assignment Operator
    ... but this does not compile under both Sicstus Prolog and SWI ... expressions can be unified, and succeeds by effectively ... bound to expressions that cannot be unified. ... X = Y to succeed by "changing" the assignment of X. ...
    (comp.lang.prolog)
  • Re: matrix
    ... > I've to make an Exercise in prolog, I'd like to work with matrices ... > 3) There are some link to look for array/matrix computation in prolog? ... needed functor+arg representations are better than lists of lists. ...
    (comp.lang.prolog)
  • Re: Tileworld Game
    ... Since I learned prolog ... it was a good exercise for me. ... Now that last one, update_intensions(Observation, Intentions, Intentions1) ... The code states in agent_cycle: ...
    (comp.lang.prolog)
  • matrix
    ... I've to make an Exercise in prolog, I'd like to work with matrices ... I make a matrix like a list of lists, ... I'm using SWI-prolog. ...
    (comp.lang.prolog)