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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:55:56+00:00 2026-06-15T01:55:56+00:00

So I have an assignment to work on and there is one thing I’m

  • 0

So I have an assignment to work on and there is one thing I’m confused about. Here is a similar problem to what I’m trying to accomplish. Say I have these rules:

size(3).
size(5).
size(7).
size(1).
size(2).
size(9).

And I want to find the minimum of size by taking the value 3 and comparing it to 5, storing 3 and comparing it to 7, then comparing it to 1, storing 1 and comparing it to 2…returning a value of 1.

The only way I can see of doing that without a high order procedure would be some form of backtracking while there are still size(X) values and each time altering the size variable. However, I don’t see how you can both backtrack and save the new minimum value. I was wondering if anyone could help put me on the right track.

  • 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-15T01:55:57+00:00Added an answer on June 15, 2026 at 1:55 am

    your assignment is intended to make you thinking about the peculiar control flow of Prolog, and indeed you are now to the point. I’ve coded the solution and placed some explanatory comment: fill in the ellipsis to complete the code

    find_min_size(MinSize) :-
        size(Hypothesis),
        !,  % without this cut the minimum is obtained more times...
        find_min_size(Hypothesis, MinSize).
    
    find_min_size(SoFar, MinSize) :-
        % when I should keep searching?
        ...
    
    % the exhaustive search come to end!
    find_min_size(MinSize, MinSize).
    

    I don’t think in Prolog is possible to get O(N) performance, without ‘higher order procedures’ ( do you mean findall etc..? ). The code above will run in O(N^2). Indexing can’t play a role, because size/1 will restart with unbound variable…

    An interesting O(N) alternative is using a failure driven loop and the tech that @false explained so well when introducing call_nth, (also, see here a follow up). All of these are in the ‘impure’ realm of Prolog, though…

    edit here the failure driven loop

    find_min_size(MinSize) :-
        State = (_, _),
        (   size(V),
            arg(1, State, C),
            ( ( var(C) ; V < C ) -> U = V ; U = C ),
            nb_setarg(1, State, U),
            fail
        ;   arg(1, State, MinSize)
        ).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have assignment to work on producer and consumer problem by use thread and
I have an assignment about fftw and I was trying to write a small
I have an assignment (i think a pretty common one) where the goal is
I have a homework assignment, and i am finished other then one question (see
I seem to have a reasonable understanding of volatiles in general, but there's one
I am a student trying to finish a lab assignment. I have two files,
I'm working on assignment 2 of CS193P - Stanford's IOS programming course. One thing
Is it possible to have assignment in a condition? For ex. if (a=some_func()): #
I have an assignment in which I have to allow a user to plot
I have an assignment to create a GUI using MATLAB GUIDE and am having

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.