An alternative to data structures that can quickly deliver minimum or maximum would be to use a directional tabulation mode. In the tabulation mode in the mode, you can specify the necessary aggregate functions:
f(5).
f(4).
f(6).
:- table min_f(min).
min_f(X) :- f(X).
The minimum will be calculated only once, here is an example request. It works in SWI-Prolog, and from version 1.4.0 also in Jekejeke Prolog:
?- min_f(X).
X = 4.
Theoretically, this remains with the implementation of the tab, as it calculates the min. At present, developments are also taking place, additional tabulations that will make f / 1 dynamic, and then track changes.