For Programmers: Free Programming Magazines  


Home > Archive > Prolog > August 2005 > I now realize WHY my 'consistency check' was pointless: CLP.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author I now realize WHY my 'consistency check' was pointless: CLP.
Dirk Mittler

2005-08-24, 6:58 pm

I'm still very much a newbie at Prolog, but one of my first experiments was
to write some code which attempted to find contradictions in the constraints
or attributes of unbound variables, at a point in time before they could be
instantiated.

Since then I've learned that constraints in Prolog, even though they don't
have to be, are often mathematical ones. At which point I added some rules
to my database for finding obvious math contradictions. But it was only
after that, that I really learned what constraints are.

As I understand it now, a constraint differs in how it's used from general
Prolog, in that general Prolog predicates basically require at least one of
their arguments to be instantiated in order to succeed. Which can result in
the other variables becoming instantiated, or in the instruction succeeding
or failing depending on whether the relationship is true. But as I
understand it now, a constraint can be given only unbound variables and
still succeed. Then, this constraint can be called, if you will, two or
three more times, before it solves the system. Or it might solve after being
used *many* more times.

As I understand it now, calling the constraint puts attributes on the
variables which are tested whenever any code tries to instantiate them.
Further, it seems to me, that there exists non-constraint code to help
define the constraint, which tries to assign such values. I would have said
that this code belongs to the constraint and is layered 'under' the
constraint handling rules. But this code suggests solutions to the system.
Importantly, if no attempt is ever made to instantiate the variable, no
solutions are found, and a program might loop for a long time, just adding
more and more attributes to them.

However, general Prolog code which calls the constraint could be said to be
layered 'above' the constraint handling rules, and can be used to synthesize
functions. Or to define the problem.

It's clear to me today, that code which tries to call all the attributes
until either many unbound variables have been unified, or until an exception
is thrown due to uninstantiated ones leading to tentative success, is only
of very limited value. If the attributes contradict each other, this is hard
to determine, and attempts which must exist to instantiate the variable are
doomed to fail anyway. Meanwhile, the constrained variables do not in
general need a test to see if they can stand for something real. Only, the
Prolog interpreter could waste a lot of time when attempts are made to
assign a value to them, because ultimately the backtracking takes time.
Thus, if contradictions in the attributes could be found as early as
possible, it might speed up the program.

And to me this generalized test is probably not worth the effort for most
kinds of programming any more. On the other hand, I also did not put much
effort into writing it either.

Dirk


--
You can visit my CGI at:

http://www.cam.org/~mdirk/GallIndex.htm
(Spelled ... lower-case el - el - Capital Eye ... ndex.htm)


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com