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 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

I have a problem with running SQL*Plus in the bash. Here is my code
I am reading Chapter 17 of C Primer Plus, and here is the code
Here is the code in a function I'm trying to revise. This example works
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
I have an application you can access here . When you open the application
There is a basic monad question in here, unrelated to Repa, plus several Repa-specific
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {

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.