Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:16:30+00:00 2026-06-13T18:16:30+00:00

I am a beginner to Prolog and i want help with this this functor

  • 0

I am a beginner to Prolog and i want help with this
this functor calculate the fibonacci of a number … first time it adds Y = 0 and Z = 1 then it calls itself wtih Y = Z and Z = Y + Z and each time it increments the value of the counter C until the counter equals to X…..
the problem is the result always is equal to 1 because prolog never executes second clause even if X not equal to M but i don’t know why …..

X: the fibonacci to be calculated
Y : the first number in fibonacci series
Z : second number in fibonacci series
C : counter with 0 as intial value
T : Y + Z

predicates
fib_tail(integer,integer, integer,integer, real)
clauses
fib_tail(X,Y , Z,M, T):- X=M,T = Y + Z,!.
fib_tail(X,Y ,Z, C , T):-
  T = Y + Z,
  NY = Z,
  NZ = Y + Z,
  NC = C + 1,
  fib_tail(X, NY, NZ, NC, NT).

goal
fib_tail(5 ,0 ,1 ,0, T)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:16:31+00:00Added an answer on June 13, 2026 at 6:16 pm

    your second clause fib_tail has 2 flaws:

    • X is never incremented
    • NT is a singleton, thus doesn’t ‘transmit’ any value to the caller.

    edit the comment highlight that X doesn’t need to be incremented, being compared against the correctly incremented C.

    I think you should before try to implement the doubly recursive definition, and when that’s working optimize removing the costly call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a prolog beginner. I would really appreciate any help for compiling this example.
Beginner at Django here, I've been trying to fix this for a long time
Beginner help needed :) I am doign an example form a php book which
JS beginner here. I need help with a script to place different content in
Python beginner here, I have a list of lists and want to refer to
Beginner question here! look at picture, I want the butten-edittext-button to fill the width
Beginner here: In this answer to my question of how to insert data into
(Beginner to HTML) I have made a Photoshop mock-up of the website I want
Beginner here See - http://www.w3schools.com/js/tryit.asp?filename=try_dom_tablerow_cells In this example, when change content is pressed, new
Complete prolog beginner here. Let's say I have a prolog knowledge base which contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.