Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I.Bratko chapter #1

6 views
Skip to first unread message

Hrvoje Blazevic

unread,
Dec 25, 2009, 10:52:02 AM12/25/09
to
In chapter 1.2 Bratko presents relation sister which uses predicate
different. He "assumes" that it is known to the prolog system. However,
both SWI prolog and Gnu prolog do not know about it.

I understand that this is a trivial matter, however the relation sister
is needed to solve several exercises in this section of the book,
therefore preventing me to test whether my solutions are correct.

I did try to find "different" in the book, but it is not in the index,
therefore help is needed.

- Hrvoje

Chip Eastham

unread,
Dec 25, 2009, 9:18:06 PM12/25/09
to
On Dec 25, 10:52 am, Hrvoje Blazevic <hrvoje.blaze...@ri.t-com.hr>
wrote:

Right, "different" is not a standard predicate.

I don't have a copy of Bratko, so take this as
a suggestion off the top of my head, but:

different(X,Y) :- not(X=Y).

This succeeds iff X and Y cannot be unified,
so it is a strong kind of "different". Because
the check is wrapped inside of metapredicate
not/1, no unification will be done by calling
this predicate (whether or not it succeeds).

regards, chip

Markus Triska

unread,
Dec 25, 2009, 9:27:19 PM12/25/09
to
Hrvoje Blazevic <hrvoje....@ri.t-com.hr> writes:

> In chapter 1.2 Bratko presents relation sister which uses predicate
> different. He "assumes" that it is known to the prolog system. However,
> both SWI prolog and Gnu prolog do not know about it.

In SWI Prolog as well as in many others like B-Prolog, SICStus and YAP,
there is dif/2, which is true if its arguments are different.

--
comp.lang.prolog FAQ: http://www.logic.at/prolog/faq/

Hrvoje Blazevic

unread,
Dec 26, 2009, 4:12:11 AM12/26/09
to


Thanks. This works, but the explanation is above my head.

- Hrvoje

Hrvoje Blazevic

unread,
Dec 26, 2009, 4:13:33 AM12/26/09
to
Markus Triska wrote:
> Hrvoje Blazevic <hrvoje....@ri.t-com.hr> writes:
>
>> In chapter 1.2 Bratko presents relation sister which uses predicate
>> different. He "assumes" that it is known to the prolog system. However,
>> both SWI prolog and Gnu prolog do not know about it.
>
> In SWI Prolog as well as in many others like B-Prolog, SICStus and YAP,
> there is dif/2, which is true if its arguments are different.
>

Thanks. Took me a while to realize that this /2 is not part of the name.

- Hrvoje

Chip Eastham

unread,
Dec 26, 2009, 9:58:45 AM12/26/09
to
On Dec 26, 4:12 am, Hrvoje Blazevic <hrvoje.blaze...@ri.t-com.hr>

Perhaps a few words of explanation (encouragement?)
are helpful. As you've already deduced, we often
put the "arity" (number of arguments) of a predicate
after the name (separated by a slash), since Prolog
allows the same predicate name to be used with
varying numbers of arguments. So not/1 just means
predicate "not" defined with one argument.

not/1 is a built-in predicate which takes a
Prolog goal as its one argument. Negation is a
tricky thing to implement in logic programming, as
one does not so much "prove the negative" as fail
to prove the goal. That is, not(Goal) succeeds
when Goal fails, and conversely.

So here not(X=Y) succeeds if X and Y cannot be
unified or "equated with each other". If X and
Y are bound (terms that have a definite value),
then this is surely what different/2 ought to
mean. different(X,Y) will succeed exactly when
the bound terms X,Y represent distinct (and thus
not unifiable) values (or fail, if X,Y represent
the same value bindings).

The case when one or both of X,Y are free is a
little complicated. What do we want different/2
to do in that case? E.g. if X is known but Y is
as yet unknown, are we in a position to say if
X and Y are different? No, or at least not yet.

The way I defined different/2 for you, the goal
different(X,Y) will fail if one or both of the
arguments are free (because a free variable can
always unify with another term). The dif/2
predicate that Markus pointed out to you will
behave in another way for those cases, but in
a similar manner if X,Y are already bound at
the time dif(X,Y) is called. dif/2 invokes
"coroutining" so that execution of the
constraint that X,Y should be different is
delayed until the binding of X and Y allows
determination of whether they are distinct
values or not. This is a more advanced topic
than I suspect Bratko would entail in Chapter
1...

regards, chip

Markus Triska

unread,
Dec 26, 2009, 10:49:19 AM12/26/09
to
Chip Eastham <hard...@gmail.com> writes:

> This is a more advanced topic than I suspect Bratko would entail in
> Chapter 1

There is absolutely no reason why dif/2 should not be covered early in a
textbook, at least as early as =/2. The =/2 and dif/2 constraints have a
lot in common: You put them as goals into the toplevel, and then you get
equivalent goals out - and no matter how you rearrange a sequence of =/2
and dif/2 goals, its truth remains unchanged. This does not hold for =/2
and \+/1, which is therefore considerably harder to explain and
understand. I suspect Bratko does not mention dif/2 at all.

Hrvoje Blazevic

unread,
Dec 26, 2009, 12:37:22 PM12/26/09
to

Thanks for the encouragement (or are you trying to scare me off?) :-)
Just as long as you understand that you are talking here to the guy that
doesn't even know how to write 2 + 2 in prolog ... yet.
And no, I did not realize that /n is the arity. That was helpful.

- Hrvoje

Chip Eastham

unread,
Dec 28, 2009, 10:03:36 AM12/28/09
to
On Dec 26, 10:49 am, Markus Triska <tri...@logic.at> wrote:

> Chip Eastham <hardm...@gmail.com> writes:
> > This is a more advanced topic than I suspect Bratko
> > would entail in Chapter 1
>
> There is absolutely no reason why dif/2 should not be
> covered early in a textbook, at least as early as =/2.
> The =/2 and dif/2 constraints have a lot in common:
> You put them as goals into the toplevel, and then you
> get equivalent goals out - and no matter how you
> rearrange a sequence of =/2 and dif/2 goals, its truth
> remains unchanged. This does not hold for =/2
> and \+/1, which is therefore considerably harder to
> explain and understand. I suspect Bratko does not
> mention dif/2 at all.

Hi, Markus:

The "advanced topic" I meant was coroutining, without
which I don't see how to properly introduce dif/2,
any more than one can introduce =/2 without explaining
unification.

Likely my lack of familiarity with corouting in Prolog
and its contribution to constraint handling extensions
biases me.

regards, chip

0 new messages