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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:35:51+00:00 2026-05-15T11:35:51+00:00

well i’m having a hard time working with prolog (gprolog). My problem is this,

  • 0

well i’m having a hard time working with prolog (gprolog). My problem is this, I’ve the next predicate:

prob(factA,factB,X,first):-   X=<50.
prob(factA,factB,X,second):-  X>50,X=<80.
prob(factA,factB,X,none):-  X>80,X=<100.

that is factA have 50% of probability of occur, factB a 30%, and lastly 20% of non of the facts occur. Also i’ve others predicate where change the factB but not factA, also change the X intervals.

Now i have the functor:

result(X,Y,N):- random(1,100,I),
  prob(X,Y,I,N).

this predicate tells what is N for X an Y in prob. This predicate handle the case:

result(factA,factB,N).

but now i have to handle:

result(factB,factA,N).

and it will return a valid result, any idea?, i did something like this:

result(X,Y,N):- Y = factA,
     random(1,100,I),
     prob(Y,X,I,N).
            J is 100-I,
     prob(Y,X,J,N).

but this doesn’t manage well the ‘none’ result.

Somebody has any idea?

Thanks!

  • 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-15T11:35:52+00:00Added an answer on May 15, 2026 at 11:35 am

    Looking at my comment above: if first is 50% (and with some optimisation if you “know” random value will be between 1 and 100):

    prob(X,first):- X=<50, !.
    prob(X,second):- X=<80, !.
    prob(X,none).
    

    I guess this is not what you meant since it does not depend on facts at all, so they’re not needed as arguments.

    Thus, assuming factA is 50%, a bit more complex but basically the same idea as yours:

    fact_prob(factA, 50).
    fact_prob(factB, 30).
    
    random_fact(X, _, I, R) :-
      fact_prob(X, XP),
      I <= XP, !,
      R = first.
    random_fact(X, Y, I, R) :-
      fact_prob(X, XP),
      fact_prob(Y, YYP),
      XYP is XP + YP,
      I <= XYP, !,
      R = second.
    random_fact(_, _, _, none).
    

    Disclaimer: I never worked with gprolog, you might need to adjust details to your dialect.

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

Sidebar

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.