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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:29:56+00:00 2026-05-15T20:29:56+00:00

i am searching for a possibility to transform this code zero(0). positive(X) :- \+

  • 0

i am searching for a possibility to transform this code

zero(0).
positive(X) :- \+ zero(X).

so that calls like

?- positive(X).

will generate values for X.

Actually only calls with specific values for X are tested correctly but no values can be generated.

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-15T20:29:57+00:00Added an answer on May 15, 2026 at 8:29 pm

    You could write virtually straightforward

    positive(1).
    positive(X) :- positive(Y), X is Y + 1.
    

    and this indeed will work

    ?- positive(X).
    X = 1 ;
    X = 2 ;
    X = 3 ;
    X = 4 ;
    etc
    

    but have in mind, that being not tail-recursive this algorithm is exponentially complex.
    I mean:

     ?- time((positive(X),X>4000)).
    % 8,010,001 inferences, 3.70 CPU in 3.73 seconds (99% CPU, 2163038 Lips)
    X = 4001.
    

    Note the time for generation of 4000 positives.

    But if we right it like:

    positive1(X) :- from(1,X).
    
    from(From,From).
    from(From,X):-From1 is From + 1, from(From1,X).
    

    All works fast now:

     ?- time((positive1(X),X>4000)).
    % 8,002 inferences, 0.00 CPU in 0.00 seconds (?% CPU, Infinite Lips)
    X = 4001.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Searching on Google reveals x2 code snippets. The first result is to this code
I'm searching for a possibility to get a list of installed printers. I'm using
Searching for some sample code for converting a point in WGS84 coordinate system to
Im searching for the best way to mantain combo box values within a Mysql
Im searching a Template Lib or Template Engine for generating HTML (XML) that runs
Searching for a string within a string is extremely well supported in .NET but
Im searching a tool which allows me to specify some folders as bookmarks and
While searching the interweb for a solution for my VB.net problems I often find
After searching online, the best solution I've found so far is to just make
been searching for a quick example of sorting a IQueryable (Using Linq To SQL)

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.