Hi,
Functional requirement:
?- Y = g(_,_), X = f(Y,C,D,Y), term_singletons(X, L),
L == [C,D].
?- Y = g(A,X,B), X = f(Y,C,D), term_singletons(X, L),
L == [A,B,C,D].
Non-Functional requirement:
?- member(N,[5,10,15]), time(singletons(N)), fail; true.
% Zeit 1 ms, GC 0 ms, Lips 4046000, Uhr 11.08.2025 01:36
% Zeit 3 ms, GC 0 ms, Lips 1352000, Uhr 11.08.2025 01:36
% Zeit 3 ms, GC 0 ms, Lips 1355333, Uhr 11.08.2025 01:36
true.
Can your Prolog system do that?
P.S.: Benchmark was:
singletons(N) :-
hydra2(N,Y),
between(1,1000,_), term_singletons(Y,_), fail; true.
hydra2(0, _) :- !.
hydra2(N, s(X,X)) :-
M is N-1,
hydra2(M, X).
Bye
Hi,
How would we do a reverse sorted map?
I find in Java:
TreeMap(Comparator<? super K> comparator)
Constructs a new, empty tree map, ordered
according to the given comparator. https://docs.oracle.com/javase/8/docs/api/java/util/TreeMap.html
Or in Dogelog Player:
tree_new(T):
tree_new(T, F):
The predicate succeeds in R with a new red-black tree.
The binary predicate allows specifying a term compare F. https://www.dogelog.ch/typtab/doclet/book/12_lang/05_libraries/03_util/06_tree.html
Here is an example, using the destructive API. But
the same constructor works also for the non-destructive API.
?- tree_new(_T), tree_add(_T, 0rInf, foo),
tree_add(_T, 0rNaN, bar), tree_pairs(_T, L).
L = [0rNaN-bar, 0rInf-foo].
And now using a comparator modifier, aggregate with a comparator,
as a closure. Some Joy of Higher Order logic programming:
reverse(C, R, X, Y) :- call(C, R, Y, X).
?- tree_new(_T,reverse(compare)), tree_add(_T, 0rInf, foo),
tree_add(_T, 0rNaN, bar), tree_pairs(_T, L).
L = [0rInf-foo, 0rNaN-bar].
?- tree_new(_T,reverse(reverse(compare))), tree_add(_T, 0rInf, foo),
tree_add(_T, 0rNaN, bar), tree_pairs(_T, L).
L = [0rNaN-bar, 0rInf-foo].
Just toying around with my new NaNs.
Have Fun!
Bye
Mild Shock schrieb:
Hi,
Functional requirement:
?- Y = g(_,_), X = f(Y,C,D,Y), term_singletons(X, L),
L == [C,D].
?- Y = g(A,X,B), X = f(Y,C,D), term_singletons(X, L),
L == [A,B,C,D].
Non-Functional requirement:
?- member(N,[5,10,15]), time(singletons(N)), fail; true.
% Zeit 1 ms, GC 0 ms, Lips 4046000, Uhr 11.08.2025 01:36
% Zeit 3 ms, GC 0 ms, Lips 1352000, Uhr 11.08.2025 01:36
% Zeit 3 ms, GC 0 ms, Lips 1355333, Uhr 11.08.2025 01:36
true.
Can your Prolog system do that?
P.S.: Benchmark was:
singletons(N) :-
hydra2(N,Y),
between(1,1000,_), term_singletons(Y,_), fail; true.
hydra2(0, _) :- !.
hydra2(N, s(X,X)) :-
M is N-1,
hydra2(M, X).
Bye
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,105 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 492342:58:10 |
| Calls: | 14,158 |
| Calls today: | 2 |
| Files: | 186,284 |
| D/L today: |
1,667 files (640M bytes) |
| Messages: | 2,502,648 |