I would like to point that there is a curious behaviour of min/2 and max/2 with nan/0:
?- A is min(nan, 1). A = 1.
I would have expect A to be evaluated to nan/0!
Did you know ... | Search Documentation: |
Function min/2 |
I would like to point that there is a curious behaviour of min/2 and max/2 with nan/0:
?- A is min(nan, 1). A = 1.
I would have expect A to be evaluated to nan/0!
The predicates
min_list/2 and max_list/2
from library library(lists)
This should really be extended to take vectors:
Min is min(ListOfExpressions).
as in
Min is min([1,-1,X*44,Y-3]).
Sometimes one has a set of pairs Key-Value and one wants to find the pair with the extremal value (either max or min) and also know the corresponding key:
?- min_entry_of_dict(_{a:1,b:2,c:3,d:1,e:1,f:5},K,V). K = a, V = 1. ?- max_entry_of_dict(_{a:3,b:5,c:4},K,V). K = b, V = 5. ?- extremal_entry_of_dict(_{a:1,b:2,c:3,d:1,e:1,f:5},K,V,min,latest). K = e, V = 1.
And so, code: extremal.pl
This totally does not use function min/2 or function max/2 at all.
(Why isn't there a special notation to distinguish functions from predicates anyway? One could write `min/~2` for example.)