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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:53:41+00:00 2026-06-14T08:53:41+00:00

I am a beginner in Prolog and I figured I could try to write

  • 0

I am a beginner in Prolog and I figured I could try to write a simple test to check if a set of integers mod K (L) is a group. I started by trying to find if the said set is additive, ie. if the sum of every two elements of L is also an element of L.

I wrote the following:

group(A,K):-member(B,A),member(C,A),As is B+C, Bs is mod(As,K), member(Bs,A).

I then tried it with this:

trace. group([0,1,2],3).

This, naturally, produces all possible sums and, correctly, answers that the answer is true for all of them.

But after all these cases it finally prints the following:

  1    1  Redo: group([0,1,2],3) ? 
  6    2  Redo: member(1,[0,1,2]) ? 
  6    2  Fail: member(1,[0,1,2]) ? 
  1    1  Fail: group([0,1,2],3) ?
  no

Why the program checks this final case, that, to me, seems nonsensical?

The last case before this is:

  1    1  Redo: group([0,1,2],3) ? 
  6    2  Redo: member(0,[0,1,2]) ? 
  6    2  Fail: member(0,[0,1,2]) ? 
  3    2  Redo: member(1,[0,1,2]) ? 
  3    2  Exit: member(2,[0,1,2]) ? 
  4    2  Call: _158 is 2+2 ? 
  4    2  Exit: 4 is 2+2 ? 
  5    2  Call: _186 is 4 mod 3 ? 
  5    2  Exit: 1 is 4 mod 3 ? 
  6    2  Call: member(1,[0,1,2]) ? 
  6    2  Exit: member(1,[0,1,2]) ? 
  1    1  Exit: group([0,1,2],3) ? 

  true

which does what it should.

  • 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-14T08:53:42+00:00Added an answer on June 14, 2026 at 8:53 am

    Using a tracer for such a purpose is not very helpful. It shows you lots of detail that is irrelevant. Instead, concentrate on a good formulation of the problem. Concentrate on meaningful names. You use A for the set, and B and C for elements. That can be improved!

    What you currently test is this:

    There exist two elements of a set whose sum modulo K is in the same set.

    What you want to test is that :

    For all X, Y in S: ( (X+Y) mod K ) in S.

    The operation itself can be written as:Z is (X+Y) mod K

    How can a tracer explain that to you?

    group(S, K) :-
       \+ (
             member(X,S), member(Y,S), Z is (X+Y) mod K,
             \+ member(Z,S)
       ).
    
    ?- group([0,1,2],3).
       true.
    ?- group([0,2],3).
       false.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner question perhaps: I'm trying to check my user permissions from facebook with Koala.
Beginner here trying to get a pipeline working in bash. If somebody can see
Beginner in Android development. My code crashes. I have made a simple Java method
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Beginner question. I'm making a simple Gtk notepad in C# and MonoDevelop and everything
Beginner here! Forgive me in advance for raising what is probably an incredibly simple
Beginner at Django here, I've been trying to fix this for a long time
Beginner question here: I'm trying to understand the some basic memory management. if I'm
I'm a beginner in Prolog, and I came across a question that I couldn't
Complete prolog beginner here. Let's say I have a prolog knowledge base which contains

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.