Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

forall - Prolog

Tags:

prolog

Can someone explain how should the predefine predicate forall to find the minimum values within a list?

like image 905
Simon Avatar asked Dec 12 '10 11:12

Simon


2 Answers

For a list L, you can use:

member(Min,L), forall(member(N,L), N>=Min).

However, while this is a nice demonstration of forall, it is not efficient (square complexity instead of linear).

like image 128
Little Bobby Tables Avatar answered Oct 08 '22 05:10

Little Bobby Tables


or you can use the predicate findall/3

findall(Value, minimumValues(Value), minimumValuesList)

it returns a list (minimumValuesList) with elements (all the minimum values, right).

like image 20
rellene Avatar answered Oct 08 '22 05:10

rellene