Re: [eclipse-clp-users] Implying Initial Domains for Certain Arguments of Predicates

From: Gökhan Solak <solakg_at_itu.edu.tr>
Date: Tue, 6 Oct 2015 15:48:42 +0300
Thank you for your answer.

Moving from your suggestion, I came up with a solution.

What I wanted to do was to give an initial domain to the variables,
according to their role as an argument in some predicates.

To do this task I created a new predicate *init_domain/1*. And defined the
init_domain with predicate-domain pairs as such:

init_domain(X) :- age(_A, X), human(_A), X :: 1..130.
init_domain(X) :- age(_, X), integers(X).
init_domain(X) :- height(_A, X), human(_A), X :: 30..230.
...

For every such predicate-domain pair, definition of init_domain should be
extended. This way, when init_domain is called for every variable in the
system, they will automatically be constrained with appropriate initial
domains.

Note: In first post I was using integer/1 built-in predicate but in the
final solution I used integers/1 from ic library.

Regards,
Gökhan Solak

2015-10-03 0:49 GMT+03:00 Joachim Schimpf <jschimpf_at_coninfer.com>:

> On 02/10/15 14:48, Gökhan Solak wrote:
> > Hello,
> >
> > First of all, I would like to inform that I'm a novice in Prolog.
> >
> > What I want to do is to imply predefined domains for the variables which
> takes
> > part in arguments of certain predicates.
> >
> > For example, for the custom predicate *age( A, X)*, which means in my
> model
> > /"age of the object A is X"/, it follows that X is an integer. Moreover
> if A is
> > a human, domain of X is [1,130] (broadly speaking).
> >
> > In predicate logic with constraints, I think this can be defined by the
> > following clauses:
> > age(A, X) -> integer(X).
> > age(A, X) and human(A) -> X € [1,130].
> >
> > I translated this into Prolog program as:
> > integer(X) :- age( _, X).
> > X :: 1..130 :- age( _A, X), human( _A).
> >
> > age/2 and human/1 are defined in the same file. lib(ic) is imported.
>
>
> You should probably start with some further reading on Prolog, in
> particular
> the differences between a predicate definition and a goal/query.  What you
> write on the left hand side of :- is what you *define*.  When you write
>
>    integer(X) :- age( _, X).
>
> you are defining a predicate integer/1 by saying that for every X, if X is
> an age, then it is an integer.  While this statement may be true, it is is
> certainly not the definition of what an integer is.  And of course the
> system already knows what an integer is, you don't need to define that.
>
>
> It is not completely clear to me what you want to achieve, but you may
> try to define database-style predicates like the following:
>
>    lifespan(human,    Age) :- Age :: 0..130.
>    lifespan(mouse,    Age) :- Age :: 0..4.
>    lifespan(tortoise, Age) :- Age :: 0..200.
>
>    type(fred, human).
>    type(wilma, human).
>    type(toto, tortoise).
>    type(charlie, mouse).
>
> then you can ask queries like
>
> ?- X = charlie, type(X, T), lifespan(T, A).
> X = charlie
> T = mouse
> A = A{0 .. 4}
> Yes (0.00s cpu)
>
>
> Cheers,
> Joachim
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>
Received on Tue Oct 06 2015 - 12:49:29 CEST

This archive was generated by hypermail 2.2.0 : Wed Oct 07 2015 - 18:13:12 CEST