Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uunet!newsflash.concordia.ca!news.mcgill.ca!clouso.crim.ca!sunqbc.risq.net!hobbit.ireq.hydro.qc.ca!rabaska!laurent
From: laurent@rabaska.ua2344.ge.hydro.qc.ca (Laurent Bilodeau,,4525,)
Subject: Re: Fibonacci Number
Message-ID: <D3nn2u.FLn@ireq.hydro.qc.ca>
Sender: news@ireq.hydro.qc.ca (Netnews Admin)
Reply-To: laurent@rabaska.ua2344.ge.hydro.qc.ca
Organization: Sun Microsystems, Inc.
Date: Wed, 8 Feb 1995 00:08:54 GMT
Lines: 34


In article <3g75bo$i61@newstand.syr.edu>, Wen-shyan  Wang wrote:
>Does anyone know how to use Prolog to solve Fibonacci Number?  I am the novice 
>of Prolog, and I just begin to write a program using Prolog to solve Fibonacci
>Number.  However, it seems too hard for me to start with.  Can anyone help me?
>I'm very appreciate.
>
oz1lia@login.dknet.dk (Jonathan Lerwill) gave
one possible algorithm.

Here's another one that is simpler
but also has quirks of his own.
(Attention students...Find out why as an exercise...)

/* Laurent's Fibonacci For Fun */

DOMAINS
  n = integer

PREDICATES
  fibonacci (n,n)

CLAUSES
  fibonacci (0,0):-!.
  fibonacci (1,1):-!.
  fibonacci (N,F):-
    write("Looking for the Fibonacci of ",N,". \n"),
    NM1 = N-1,
    fibonacci(NM1,FM1),
    NM2 = N-2,
    fibonacci (NM2,FM2),
    F = FM1+FM2.

GOAL fibonacci (10)
