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

  • SEARCH
  • Home
  • 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 3998600
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:32:45+00:00 2026-05-20T07:32:45+00:00

I’m using swipl 5.10.2. I started today learning Prolog for my AI course. I’ve

  • 0

I’m using swipl 5.10.2. I started today learning Prolog for my AI course.
I’ve started with a pretty straight forward example:

father(giovanni,maria).
brother(paolo,pietro).

grandpa(X,Y) :-
        father(X,Z),
        father(Z,Y).
grandpa(X,Y) :-
        father(X,Z),
        mother(Z,Y).

mother(maria,paolo).
mother(I,J) :-
        mother(I,K),
        brother(K,J).

Not a big deal, if I try this goal grandpa(giovanni,pietro), it work and it gives me true. Then I want to spicy up the challenge and I modified the code like this:

father(giovanni,maria).
brother(paolo,pietro).

grandpa(X,Y,Z) :-
        father(X,Z),
        father(Z,Y).
grandpa(X,Y,Z) :-
        father(X,Z),
        mother(Z,Y).

mother(maria,paolo).
mother(I,J) :-
        mother(I,K),
        brother(K,J).

because I wanted to know the middle-man but when I run it here’s what happens:

?- grandpa(giovanni,pietro,M).
M = maria ;
ERROR: Out of local stack

That’s because, imho, there’s a left recursion in mother, the tree keeps expanding without finding closure.

Then I wrote this:

father(giovanni,maria).
brother(paolo,pietro).
mother(maria,paolo).

grandpa(X,Y,Z) :-
        father(X,Z),
        father(Z,Y).
grandpa(X,Y,Z) :-
        father(X,Z),
        mother(Z,Y).

mother(I,J) :-
        brother(K,J),
        mother(I,K).

This is the output:

?- grandpa(giovanni,pietro,M).
M = maria ;
false.

It is right. So is it just a left recursion problem or am I missing something about swipl behaviour? And when I have a “ERROR: Out of local stack”, is it always a recursion problem?

  • 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-05-20T07:32:46+00:00Added an answer on May 20, 2026 at 7:32 am

    I believe the Out of local stack error is almost always (or always) from recursions that are too deep; in simple programs, those recursions are likely to be infinite. The problem in your code is indeed the left recursion issue; trying to solve mother(anything, B) will try to solve mother(anything, B1), mother(anything, B2), and so on until you run out of stack space.

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

Sidebar

Related Questions

No related questions found

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.