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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:16:11+00:00 2026-06-14T11:16:11+00:00

I have the following prolog rules. b(b(true)) –> [true]. b(b(false)) –> [false]. b(b(E,[=],E)) –>

  • 0

I have the following prolog rules.

b(b(true)) --> [true].
b(b(false)) --> [false].
b(b(E,[=],E)) --> e(E),[=],e(E).
b(b([not],B)) --> [not],b(B).
e(e(I)) --> i(I).
e(e(N)) --> n(N).
e(e(N,O,E)) --> n(N),o(O),e(E).
e(e(I,O,E)) --> i(I),o(O),e(E).
o(o(+)) --> [+].
o(o(-))--> [-].
o(o(*))--> [*].
o(o(/)) --> [/].
i(i(x)) --> [x].
i(i(y)) --> [y].
i(i(z)) --> [z].
i(i(u)) --> [u].
i(i(v)) --> [v].
n(n(0)) --> [0].
n(n(1)) --> [1].
n(n(2)) --> [2].
n(n(3)) --> [3].
n(n(4)) --> [4].
n(n(5)) --> [5].
n(n(6)) --> [6].
n(n(7)) --> [7].
n(n(8)) --> [8].
n(n(9)) --> [9].

But I dunno why

[6] 26 ?- b(A,[x,=,4],[]).
false

fails. I tried to debug the code. 4 is not getting matched with n(n(4)). I couldn’t understand wat the problem is.

  • 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-14T11:16:12+00:00Added an answer on June 14, 2026 at 11:16 am

    (You would have received an answer much earlier if you would have used the prolog tag instead)

    So, how can we localize the error? Let’s start with your query:

    ?- phrase(b(A),[x,=,4]).
       false.
    

    Bad!
    Shall I really fire up a trace/debugger?
    What you are currently asking is: What are the solutions for A for a well-formed sentence.
    Alas, there is none.

    Can’t we ask Prolog a more general question?
    So, dear Prolog – at least – do you know any sentence?
    Please say a word!

    ?- phrase(b(A),L).
       A = b(true), L = [true]
    ;  A = b(false), L = [false]
    ;  ... .
    

    So there is something – I will remove the A, because we want to see the sentences, first.

    ?- phrase(b(_),L).
       L = [true]
    ;  L = [false]
    ;  L = [x,=,x]
    ;  L = [y,=,y]
    ;  L = [z,=,z]
    ;  L = [u,=,u]
    ;  L = [v,=,v]
    ;  L = [0,=,0]
    ;  L = [1,=,1]
    ;  L = [2,=,2]
    ;  L = [3,=,3]
    ;  L = [4,=,4]
    ;  L = [5,=,5]
    ;  L = [6,=,6]
    ;  L = [7,=,7]
    ;  L = [8,=,8]
    ;  L = [9,=,9]
    ;  L = [0,+,x,=,0,+,x]
    ;  ... .
    

    Do you see a pattern here?
    Maybe we can refine this.
    What are the sentences of length 3 you know of?

    ?- L = [_,_,_], phrase(b(_),L).
      L = [x,=,x]
    ;  L = [y,=,y]
    ;  L = [z,=,z]
    ;  L = [u,=,u]
    ;  L = [v,=,v]
    ;  L = [0,=,0]
    ;  L = [1,=,1]
    ;  L = [2,=,2]
    ;  L = [3,=,3]
    ;  L = [4,=,4]
    ;  L = [5,=,5]
    ;  L = [6,=,6]
    ;  L = [7,=,7]
    ;  L = [8,=,8]
    ;  L = [9,=,9]
    ;  L = [not,not,true]
    ;  L = [not,not,false]
    ;  false.
    

    In other words: There are no other three word sentences than those.
    Now, do you get it?
    There is a rule for sentences with =:

    b(b(E,[=],E)) -->
       e(E),[=],e(E).
    

    It requires that the expression on the left-hand side is the same as the expression on the right-hand side. Therefore only those sentences above.


    When debugging a Prolog program, there is much less need to type (on the keyboard) test data than in other languages. Instead, use variables to let Prolog fill-in-the-variables. After all, Prolog is much faster on that than we are ; and it does not suffer CTS.

    • 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 code: equiAngularTriangle(T) :- equiLateralTriangle(T). equiLateralTriangle(T) :- equiAngularTriangle(T). Is there
I'm trying to implement an increment in prolog, and have written the following code:
I have the following prolog code: predicates like(string) clauses like(apple). like(girl). q :- like(A),write(A).
I have the following Prolog code in my program: conn([oxford_circus, baker_street], 4). conn([baker_street, kings_cross],
I have the following snippet of prolog code: num(0). num(X) :- num(X1), X is
I have written the following code in SWI-Prolog: :- dynamic state_a/1 . :- dynamic
I have tried so many things but I could not found How I can
How can I count nested list elements in Prolog? I have the following predicates
I have following div in a page (I can not modify). <div id=:0.control>Click me</div>
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig

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.