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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:47:58+00:00 2026-05-21T06:47:58+00:00

I have the following prolog expression in my file which is pretty self explanatory.

  • 0

I have the following prolog expression in my file which is pretty self explanatory. I have all the required functions which is needed for this rule (call it 1) implemented and tested correctly.

cal(plus(X,Y),Z):-cal(X,int(Z1)),cal(Y,int(Z2)),add(Z1,Z2,Z3),Z=int(Z3) ; cal(X,real(Z1)),cal(Y,real(Z2)),add(Z1,Z2,Z3),Z=real(Z3).

After hours of trying I couldn’t figure out the following:

?-call(plus(int(9),int(10)),Z). 

works correctly and returns:-

Z = int(19).

but it doesn’t unify with

?-call(plus(real(9.0),real(10.0),Z).

I tried many things and concluded that this is due to the integer part(before 😉 in the rule 1 been specified first than the real part(I exchanged the two and it started working in the reverse way). It tries to unify with the first part and goes on repeatedly. As there is no such fact out there it just goes into an infinite loop.
Please specify an alternative way to do the same. This is the only part of my assignment that is left and I am struck on it for hours.

Thanks in advance!

  • 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-21T06:47:58+00:00Added an answer on May 21, 2026 at 6:47 am

    Well, here’s the answer.

    cal(plus(X,Y),G,Z):-cal(X,G,Z1),cal(Y,G,Z2),((Z2 = int(Z22),Z1 = int(Z11));(Z2 = real(Z22),Z1 = real(Z11))),add(Z11,Z22,Z3),(Z3=int(Z4) -> Z=int(Z3); Z=real(Z3)).
    

    You should call cal function only once for a particular input . Redundant calling causes problems.

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

Sidebar

Related Questions

I have the following Prolog definite clause grammar: s-->[a],s,[b]. s-->[]. This will result in
How can I count nested list elements in Prolog? I have the following predicates
I have written the following code in SWI-Prolog: :- dynamic state_a/1 . :- dynamic
I have following class. In this, Iris is another class with some attributes. public
I have following class public abstract class Rule { protected Rule() { Nodes =
I have been progressing through Learn Prolog Now! as self-study and am now learning
I have the following prolog code: equiAngularTriangle(T) :- equiLateralTriangle(T). equiLateralTriangle(T) :- equiAngularTriangle(T). Is there
I have the following context free grammar in a text file 'grammar.txt' S ::=
I'm trying to implement an increment in prolog, and have written the following code:
I have the following Prolog program: father(person1,person2). mother(person3,person2). say_hi(X) :- father(X,person1) , write('Hello1'). say_hi(X)

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.