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

arithmetic predicate does not always compute unbound arguments

0 views
Skip to first unread message

metaperl

unread,
Nov 2, 2009, 3:40:03 PM11/2/09
to
The wonderful ability of Prolog to flexibly compute A given B or vice
versa seems to fail with arithmetic:

c_to_f(C,F) :-
F is C * 9 / 5 + 32.

It would be nice if there were some way to get C given F and vice
versa.

Markus Triska

unread,
Nov 2, 2009, 3:59:25 PM11/2/09
to
metaperl <sche...@gmail.com> writes:

> c_to_f(C,F) :-
> F is C * 9 / 5 + 32.
>
> It would be nice if there were some way to get C given F and vice
> versa.

Indeed, therefore we have the CLP(Q/R/FD) constraint libraries:

:- use_module(library(clpq)).

c_f(C, F) :- { F = C * 9 / 5 + 32 }.

Examples:

?- c_f(C, F).
%@ {F=32+9 rdiv 5*C}.

?- c_f(23, F).
%@ F = 367 rdiv 5.

?- c_f(C, 23).
%@ C = -5.

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

Chip Eastham

unread,
Nov 5, 2009, 11:55:36 AM11/5/09
to
On Nov 2, 3:59 pm, Markus Triska <tri...@logic.at> wrote:

> metaperl <scheme...@gmail.com> writes:
> > c_to_f(C,F) :-
> >   F is C * 9 / 5 + 32.
>
> > It would be nice if there were some way to get C given F and vice
> > versa.
>
> Indeed, therefore we have the CLP(Q/R/FD) constraint libraries:
>
>    :- use_module(library(clpq)).
>
>    c_f(C, F) :- { F = C * 9 / 5 + 32 }.

At a more elementary level you might have rules
that check to see whether C and/or F is free vs.
bound. E.g.

c_f(C,F) :-
( var(C) -> C is (F - 32)*5/9
; F is (C*9/5) + 32 ).

regards, chip

Cesar Rabak

unread,
Nov 6, 2009, 9:32:50 AM11/6/09
to
Chip Eastham escreveu:
Hi Chip,

Although this is syntactical correct Prolog, IMNHO this is no longer
logic programming but a procedural construct done in Prolog language.


0 new messages