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.
> 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/
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
Although this is syntactical correct Prolog, IMNHO this is no longer
logic programming but a procedural construct done in Prolog language.