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

I love Prolog

32 views
Skip to first unread message

Terrence Brannon

unread,
Dec 28, 2009, 10:15:02 AM12/28/09
to
I'm nowhere near being a prolog expert. I dont know what difference
lists are, etc. But I love stating facts and having Prolog do the
rest.

I just wrote a computer program to calculate the importance of food
versus water versus heat in survival in Prolog:

http://github.com/metaperl/metaphysics/blob/master/survival/survival.prolog

And it was sheer joy. Time to buy a book on Prolog, I think "Learn
Prolog Now" is what I will get unless there are other suggestions?

weeks_to_seconds(W,S) :- D is 7*W, days_to_seconds(D,S).
days_to_seconds(D,S) :- H is D*24, M is 60*H, S is 60*M.

% Can survive without adequate heat for 1 second
survive_without(heat,1).

% Can survive without water for 7 days (3-5 days cited)
% http://en.wikipedia.org/wiki/Survival_skills#Water
% comes out to 604,800 seconds
survive_without(water,X) :- days_to_seconds(7,X).


% If Mahatma Gandhi can live on water for 21 days at age 74, then
% any average person could expect to do the same
% http://www.scientificamerican.com/article.cfm?id=how-long-can-a-person-sur
% comes out to 1,814,400 seconds
survive_without(food,X) :- weeks_to_seconds(3,X).

more_important(N1,N2,I) :-
survive_without(N1,S1),
survive_without(N2,S2),
I is S2 / S1.

% Conclusions (based on survival levels, not necessarily optimal)
% ---------------------------------------------------------------
% water is 3 times more important than food
% heat is 600,000 times more important than water

% Given that the body is 70 percent water, and that every
% process in the body requires water, it is no surprise that water
% is many times more important than food.

bart demoen

unread,
Dec 28, 2009, 3:13:53 PM12/28/09
to
On Mon, 28 Dec 2009 07:15:02 -0800, Terrence Brannon wrote:

> And it was sheer joy. Time to buy a book on Prolog, I think "Learn
> Prolog Now" is what I will get unless there are other suggestions?

There is an online version at http://www.learnprolognow.org/
It is "old" but very good as a starter. Make sure you have SWI with you:
it is a hands-on book. Skip the part on DCGs.
This book will keep your enthusiasm high, and it does not dig deep:
you should be able to cover it in a few evenings.
After a while, you might want to look at books by Bratko
or Sterling&Shapiro or O'Keefe.
Don't run before you have enjoyed walking.

And keep posting your programs !

Cheers

Bart Demoen

ps. very nice Subject line !

YauHsienHuang

unread,
Dec 30, 2009, 12:45:06 PM12/30/09
to
On Dec 28, 11:15 pm, Terrence Brannon <metap...@gmail.com> wrote:
> I'm nowhere near being a prolog expert. I dont know what difference
> lists are, etc. But I love stating facts and having Prolog do the
> rest.
>
> I just wrote a computer program to calculate the importance of food
> versus water versus heat in survival in Prolog:
>
> http://github.com/metaperl/metaphysics/blob/master/survival/survival....

>
> And it was sheer joy. Time to buy a book on Prolog, I think "Learn
> Prolog Now" is what I will get unless there are other suggestions?

Walk through the P-99: Night-nine Prolog Problems,
https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/ , and you will
learn a lot. :)

> weeks_to_seconds(W,S) :- D is 7*W, days_to_seconds(D,S).
> days_to_seconds(D,S) :- H is D*24, M is 60*H, S is 60*M.
>
> % Can survive without adequate heat for 1 second
> survive_without(heat,1).
>
> % Can survive without water for 7 days (3-5 days cited)

> %http://en.wikipedia.org/wiki/Survival_skills#Water


> % comes out to 604,800 seconds
> survive_without(water,X) :- days_to_seconds(7,X).
>
> % If Mahatma Gandhi can live on water for 21 days at age 74, then
> % any average person could expect to do the same

> %http://www.scientificamerican.com/article.cfm?id=how-long-can-a-perso...


> % comes out to 1,814,400 seconds
> survive_without(food,X) :- weeks_to_seconds(3,X).
>
> more_important(N1,N2,I) :-
> survive_without(N1,S1),
> survive_without(N2,S2),
> I is S2 / S1.
>
> % Conclusions (based on survival levels, not necessarily optimal)
> % ---------------------------------------------------------------
> % water is 3 times more important than food
> % heat is 600,000 times more important than water
>
> % Given that the body is 70 percent water, and that every
> % process in the body requires water, it is no surprise that water
> % is many times more important than food.

The elements for survival program is to describe a sentence "Water is
more important than food, and heat is even more important than water."
Interesting!

Hrvoje Blazevic

unread,
Jan 2, 2010, 8:53:23 PM1/2/10
to

A beginners comment:
I haven't read "Learn Prolog Now", but have started with Bratko, simply
because I acquired that book some years ago (must have gotten
sidetracked). Apart from the earlier (minor) complaint about "different"
predicate, the book seems well written, and interesting. I managed to
complete first three chapters without serious problems (with all
exercises solved without peeking). However, it probably depends on one's
background as a programmer. Mine is FP. As chapter #3 deals with lists
and recursion, I probably would not have done that well with the book
alone, because Bratko's explanation of recursive process is very terse.

- Hrvoje

0 new messages