モジュール lillib:tools

Useful predicates galore.

バージョン

09/11/98

著者


目次

述語


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

述語

min/3

書式min(+A, +B, ?Min)
引数
+Anumber
+Bnumber
?Minminimum between A & B
Calculates the minimum between A and B, or succeeds if the minimum is equal to Min

lmin/2

書式lmin(+L, ?Min)
引数
+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

書式max(+A, +B, ?Max)
引数
+Anumber
+Bnumber
?Maxmaximum between A & B
Calculates the maximum between A and B, or succeeds if the maximum is equal to Max

lmax/2

書式lmax(+L, ?Max)
引数
+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

書式qsort_divide(+List, +Pivot, +CmpPred, +LeftIn, +RightIn, -LeftOut, -RightOut)
引数
+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

書式qsort(+List, +CmpPred, -Sorted)
引数
+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

書式repeat
succeeds over and over. To be used in backtracking

while/1

書式while(+P)
引数
+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

書式forwhile(Var,L,P)
引数
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

コメントはこちら:
Roland Steiner

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