• AOT Compiled Inner if-then-else (Was: VIP0909: VibeCore ImprovementProposal [term_singletons])

    From Mild Shock@[email protected] to comp.lang.prolog on Wed Nov 5 20:23:16 2025
    From Newsgroup: comp.lang.prolog

    Hi,

    Now that we managed to conceive nested arrow
    functions, next step on the menu is inner if-then-else
    or disjunction, like inside a findall/3 or inside

    (\+)/1, doing ahead of time compilation (AOT).
    That it leads to problems of rational trees was
    more a psyop easter egg of mine. Although I am not

    yet sure, in the long run the compiler should
    be able to handle rational trees, like copy_term/2
    can handle them. But before tackling inner

    if-then-else, first check the occurence frequency
    of then. Do they happen often? Is it worth AOT-ing
    them. Then also before tackling inner if-then-else,

    does the code use (,)/2, (;)/2 or (->)/2 in
    scenarios where it is used for meta programming
    i.e. _,_, _;_ or _->_ pattern for deconstruction

    or construction. And do these cases fall into
    the new arrow viability check adopte to a if-then-else
    viability check, or fall they through?

    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

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mild Shock@[email protected] to comp.lang.prolog on Wed Nov 5 21:19:00 2025
    From Newsgroup: comp.lang.prolog

    Hi,

    Credits go to myself (an old Stackoverflow
    post of mine from 2020):

    The algorithm "A" according to Antoni Diller looks fairly simple: https://stackoverflow.com/questions/65066544/bracket-abstraction-in-prolog

    The OrReference aka Anonymous Predicate is just another variant
    of combinatorial logic. You can view OrReference having the same
    logtical status as a closed SKI expression.

    Plus to this guys here also already in 2004:

    Hiord: A Type-Free Higher-Order Logic Programming
    Language with Predicate Abstraction
    Daniel Cabeza, Manuel V. Hermenegildo, Manuel V. Hermenegildo https://www.researchgate.net/publication/221052995

    Only they botched it, since recursion and mutual recursion
    needs still some fixpoint operator construction. But
    the Anonymous Predicate thingy is beautiful, without

    any fixpoint operator construction needed:

    test(Even) :-
    Even = ((X) => Y^(X = n; X = s(Y), call(Odd, Y))),
    Odd = ((X) => Y^(X = s(Y), call(Even, Y))).

    ?- listing(test).
    test(A) :-
    A = 0rReference(B),
    B = 0rReference(A).

    Basically evaluating a rational tree closure:

    ?- test(_X), call(_X, s(s(s(s(n))))).
    true.

    ?- test(_X), call(_X, s(s(s(s(s(n)))))).
    fail.

    ?- test(_X), call(_X, s(s(s(s(s(s(n))))))).
    true.

    Bye

    Mild Shock schrieb:
    Hi,

    Now that we managed to conceive nested arrow
    functions, next step on the menu is inner if-then-else
    or disjunction, like inside a findall/3 or inside

    (\+)/1, doing ahead of time compilation (AOT).
    That it leads to problems of rational trees was
    more a psyop easter egg of mine. Although I am not

    yet sure, in the long run the compiler should
    be able to handle rational trees, like copy_term/2
    can handle them. But before tackling inner

    if-then-else, first check the occurence frequency
    of then. Do they happen often? Is it worth AOT-ing
    them. Then also before tackling inner if-then-else,

    does the code use (,)/2, (;)/2 or (->)/2 in
    scenarios where it is used for meta programming
    i.e. _,_, _;_ or _->_ pattern for deconstruction

    or construction. And do these cases fall into
    the new arrow viability check adopte to a if-then-else
    viability check, or fall they through?

    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


    --- Synchronet 3.21a-Linux NewsLink 1.2