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 6022277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:50:07+00:00 2026-05-23T03:50:07+00:00

here is the plus code that i don’t understand plus(0,X,X):-natural_number(X). plus(s(X),Y,s(Z)) :- plus(X,Y,Z). while

  • 0

here is the plus code that i don’t understand

plus(0,X,X):-natural_number(X).
plus(s(X),Y,s(Z)) :- plus(X,Y,Z).

while given :

natural_number(0).
natural_number(s(X)) :- natural_number(X).

I don’t understand this recursion. If I have plus(s(0),s(s(s(0))),Z) how can i get the answer of 1+3=4?

I need some explanation for the first code. I try that plus(0,X,X) will stop the recursion but I think that I do it wrong.

  • 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-23T03:50:08+00:00Added an answer on May 23, 2026 at 3:50 am

    So, let’s start with natural_number(P). Read this as “P is a natural number”. We’re given natural_number(0)., which tells us that 0 is always a natural number (i.e. there are no conditions that must be met for it to be a fact). natural_number(s(X)) :- natural_number(X). tells us that s(X) is a natural number if X is a natural number. This is the normal inductive definition of natural numbers, but written “backwards” as we read Prolog “Q := P” as “Q is true if P is true”.

    Now we can look at plus(P, Q, R). Read this as “plus is true if P plus Q equals R”. We then look at the cases we’re given:

    1. plus(0,X,X) :- natural_number(X).. Read as Adding 0 to X results in X if X is a natural number. This is our inductive base case, and is the natural definition of addition.
    2. plus(s(X),Y,s(Z)) :- plus(X,Y,Z). Read as “Adding the successor of X to Y results in the successor Z if adding X to Y is Z’. If we change the notation, we can read it algebraically as “X + 1 + Y = Z + 1 if X + Y = Z”, which is very natural again.

    So, to answer you direct question “If I have plus(s(0),s(s(s(0))),z), how can i get the answer of 1+3=4?”, let’s consider how we can unify something with z each step of the induction

    1. Apply the second definition of plus, as it’s the only one that unifies with the query. plus(s(0),s(s(s(0))), s(z')) is true if plus(0, s(s(s(0))), z') is true for some z
    2. Now apply the first definition of plus, as it’s the only unifying definition: plus(0, s(s(s(0))), z') if z' is s(s(s(0))) and s(s(s(0))) is a natural number.
    3. Unwind the definition of natural_number a few times on s(s(s(0))) to see that is true.
    4. So the overall statement is true, if s(s(s(0))) is unified with z' and s(z') is unified with z.

    So the interpreter returns true, with z' = s(s(s(0))) and z = s(z'), i.e. z = s(s(s(s(0)))). So, z is 4.

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

Sidebar

Related Questions

Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here's a coding problem for those that like this kind of thing. Let's see
I'm using Grails 1.3.7. I have some code that uses the built-in base64Encode function
I have a sectioned UITableView using dictionaries adapting code from a tutorial (I don't
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is my code, which takes two version identifiers in the form 1, 5,
Here is the scenario: I'm writing an app that will watch for any changes
Here we go again, the old argument still arises... Would we better have a

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.