Module lillib:tools

Useful predicates galore.

Version

09/11/98

Author


Contents

Predicate


Top of this page Contents Index of this package LiLFeS Documents LiLFeS Home Page Tsujii laboratory

Predicate

min/3

Formatmin(+A, +B, ?Min)
Arguments
+Anumber
+Bnumber
?Minminimum between A & B
Calculates the minimum between A and B, or succeeds if the minimum is equal to Min

lmin/2

Formatlmin(+L, ?Min)
Arguments
+Llist of numbers
?Minthe minimum number among the list
Calculates the minimum of all numbers given in the list L, or succeeds if the minimum is equal to Min

max/3

Formatmax(+A, +B, ?Max)
Arguments
+Anumber
+Bnumber
?Maxmaximum between A & B
Calculates the maximum between A and B, or succeeds if the maximum is equal to Max

lmax/2

Formatlmax(+L, ?Max)
Arguments
+Llist of numbers
?Maxthe maximum number among the list
Calculates the maximum of all numbers given in the list L, or succeeds if the maximum is equal to Max

qsort_divide/7

Formatqsort_divide(+List, +Pivot, +CmpPred, +LeftIn, +RightIn, -LeftOut, -RightOut)
Arguments
+Listelements to divide into 'left' and 'right' of pivot element
+Pivotthe pivot element
+CmpPredcomparison predicate. predicates for which 'CmpPred(X,Pivot)' is true go to the left, others right
+LeftInelements sorted to the left so far
+RightInelements sorted to the right so far
-LeftOutfinished left list
-RightOutfinished right list
sorts elements to the left and right

qsort/3

Formatqsort(+List, +CmpPred, -Sorted)
Arguments
+Listlist of elements to sort
+CmpPredcomparison predicate. needs to be 2-ary. If true for 2 elements (A,B) then they are in correct order, otherwise they have to be switched
-Sortedsorted output list.
sorts the elements in List according to the comparison prediate with QuickSort

repeat/0

Formatrepeat
succeeds over and over. To be used in backtracking

while/1

Formatwhile(+P)
Arguments
+Ppredicate
succeeds as long as P succeeds. NOTE: P does NOT backtrack and is NOT bound/unified, e.g.:
"?- while(member(E,[1,2])), print(E), fail."
will NOT print "1,2", but result in an endless loop where E is always 'bot'! To achieve the intended effect, use 'pforall' instead, e.g.,
":- pforall((member(E,[1,2]), print(E)))."
'while' is useful for looping on arrays other predicates that normally only succeed only once, e.g.:
?- set_var(v1,0), while((get_var(v1,$V), $V < 5)), get_var(v1,$V), print($V), increment(v1), fail.
(Here please note that since $V is not bound after 'while', the value of the variable has to be fetched again).

forwhile/3

Formatforwhile(Var,L,P)
Arguments
Varthe variable
Llower(current) value
Plooping condition (predicate)
increments the variable starting from L, as long as the predicate succeeds NOTE: P is NOT bound and does NOT backtrack! See also above under 'while'

Top of this page Contents Index of this package LiLFeS Documents LiLFeS Home Page Tsujii laboratory

Send comments to:
Roland Steiner

This document is automatically created by lildoc on Fri Sep 24 14:13:59 2004