• Re: Is old school mode directed compilation dead? (Was: thank you for t

    From Mild Shock@21:1/5 to Mild Shock on Fri Jan 24 17:58:06 2025
    Hi,

    Would need more testing but the
    present example is immune:

    /* SWI-Prolog 9.3.19 */
    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test1(X, Y), fail; true)).
    % 1,999,998 inferences, 0.094 CPU in 0.100 seconds (93% CPU, 21333312 Lips)

    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test2(X, Y), fail; true)).
    % 1,999,998 inferences, 0.094 CPU in 0.100 seconds (93% CPU, 21333312 Lips)

    ?- Y = j(1,2), time((between(1,1000000,_), test1(X, Y), fail; true)).
    % 1,999,998 inferences, 0.109 CPU in 0.100 seconds (109% CPU, 18285696 Lips)

    ?- Y = j(1,2), time((between(1,1000000,_), test2(X, Y), fail; true)).
    % 1,999,998 inferences, 0.094 CPU in 0.102 seconds (92% CPU, 21333312 Lips)

    Not all Prolog systems are that lucky:

    /* Scryer Prolog 0.9.4-286 */
    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test1(X, Y), fail; true)).
    % CPU time: 1.163s, 11_000_108 inferences

    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test2(X, Y), fail; true)).
    % CPU time: 1.248s, 11_000_131 inferences

    ?- Y = j(1,2), time((between(1,1000000,_), test1(X, Y), fail; true)).
    % CPU time: 0.979s, 11_000_131 inferences

    ?- Y = j(1,2), time((between(1,1000000,_), test2(X, Y), fail; true)).
    % CPU time: 1.338s, 11_000_131 inferences

    Bye

    Mild Shock schrieb:
    Hi,

    Just noticed that SICStus Prolog says that
    their mode declaration is a dummy declaration,
    does nothing. Now I tried whether I can force

    SWI Prolog to accept different manually compiled clauses:

    test1(X,Y) :- Y = j(C,D), g(C) = A, h(D) = B, f(A,B) = X.

    test2(X,Y) :- X = f(A,B), A = g(C), B = h(D), j(C,D) = Y.

    Difficult to archive in SWI-Prolog, since it
    orders unification on its own, test1/2 and test2/2
    will behave the same, since they are essentially the same:

    /* SWI-Prolog 9.3.19 */
    ?- listing(test1/2), listing(test2/2).
    test1(f(A, B), j(C, D)) :-
        A=g(C),
        B=h(D).

    test2(f(A, B), j(C, D)) :-
        A=g(C),
        B=h(D).

    But maybe not necessary since SWI-Prolog has an
    advanced instruction set and advanced Prolog
    logical variable representation?

    Bye

    Mild Shock schrieb:
    Hi,

    Given that Scryer Prolog is dead.
    This made me smile, traces of Scryer Prolog

    are found in FLOPs 2024 proceedings:

    7th International Symposium, FLOPS 2024,
    Kumamoto, Japan, May 15–17, 2024, Proceedings
    https://www.cs.ox.ac.uk/jeremy.gibbons/flops2024.pdf

    So why did it flop? Missing garbage collection
    in the Prolog System? Or did or is it to estimate
    that ChatGPT will also kill Scryer Prolog?

    Or simply a problem of using Rust as the
    underlying host language?

    Bye



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mild Shock@21:1/5 to All on Sat Jan 25 14:13:33 2025
    Possibly it does round away from zero and not half-even:

    /* Trealla Prolog 2.63.33 & SWI-Prolog 9.0.4 */
    ?- format('~0f ~0f', [1.5, 2.5]), nl.
    2 2

    /* Scryer Prolog 0.9.4-286 */
    ?- format("~0f ~0f", [1.5, 2.5]), nl.
    1 2

    Pitty there is no Prolog Improvement Proposals (PIP) for format/2.

    https://prolog-lang.org/ImplementersForum/PIPs

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mild Shock@21:1/5 to Mild Shock on Sat Jan 25 20:44:02 2025
    Hi,

    Lets say there are at least two unification
    spilling rewriting techniques in a Prolog system
    that would eliminate a (=)/2 call:

    /* Left Spilling into the Head */
    p(V, Q) :- V = T, ... ~~> p(T, Q) :- ...

    /* Right Spilling into a Goal */
    ..., V = T, p(V, Q), ... ~~> ..., p(T, Q), ...

    Maybe the head movement and the indexing benefit
    in SWI-Prolog was discovered because of DCG translation
    and not to eliminate mode directed compilation.

    Take this DCG rule:

    p --> [a], !, [b].

    I find that SWI-Prolog does left spilling:

    /* SWI-Prolog 9.3.19 */
    ?- listing(p/2).
    p([a|A], B) :-
    !,
    C=A,
    C=[b|B].

    Bye

    Mild Shock schrieb:
    Hi,

    Would need more testing but the
    present example is immune:

    /* SWI-Prolog 9.3.19 */
    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test1(X, Y), fail; true)).
    % 1,999,998 inferences, 0.094 CPU in 0.100 seconds (93% CPU, 21333312 Lips)

    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test2(X, Y), fail; true)).
    % 1,999,998 inferences, 0.094 CPU in 0.100 seconds (93% CPU, 21333312 Lips)

    ?- Y = j(1,2), time((between(1,1000000,_), test1(X, Y), fail; true)).
    % 1,999,998 inferences, 0.109 CPU in 0.100 seconds (109% CPU, 18285696
    Lips)

    ?- Y = j(1,2), time((between(1,1000000,_), test2(X, Y), fail; true)).
    % 1,999,998 inferences, 0.094 CPU in 0.102 seconds (92% CPU, 21333312 Lips)

    Not all Prolog systems are that lucky:

    /* Scryer Prolog 0.9.4-286 */
    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test1(X, Y), fail; true)).
       % CPU time: 1.163s, 11_000_108 inferences

    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test2(X, Y), fail; true)).
       % CPU time: 1.248s, 11_000_131 inferences

    ?- Y = j(1,2), time((between(1,1000000,_), test1(X, Y), fail; true)).
       % CPU time: 0.979s, 11_000_131 inferences

    ?- Y = j(1,2), time((between(1,1000000,_), test2(X, Y), fail; true)).
       % CPU time: 1.338s, 11_000_131 inferences

    Bye

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mild Shock@21:1/5 to Mild Shock on Sat Jan 25 20:44:46 2025
    I made a little experiment introducing both
    left spilling and right spilling into a DCG
    translator, which previously had neither:

    /* Dogelog Player 1.3.0 */
    ?- listing(p/2).
    p([a|A], B) :-
    !,
    A = [b|B].

    Now my benchmark suite DCG calculator runs 25% faster!

    Mild Shock schrieb:
    Hi,

    Lets say there are at least two unification
    spilling rewriting techniques in a Prolog system
    that would eliminate a (=)/2 call:

    /* Left Spilling into the Head */
    p(V, Q) :- V = T, ...         ~~>            p(T, Q) :- ...

    /* Right Spilling into a Goal */
    ..., V = T, p(V, Q), ...      ~~>            ..., p(T, Q), ...

    Maybe the head movement and the indexing benefit
    in SWI-Prolog was discovered because of DCG translation
    and not to eliminate mode directed compilation.

    Take this DCG rule:

    p --> [a], !, [b].

    I find that SWI-Prolog does left spilling:

    /* SWI-Prolog 9.3.19 */
    ?- listing(p/2).
    p([a|A], B) :-
        !,
        C=A,
        C=[b|B].

    Bye

    Mild Shock schrieb:
    Hi,

    Would need more testing but the
    present example is immune:

    /* SWI-Prolog 9.3.19 */
    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test1(X, Y), fail;
    true)).
    % 1,999,998 inferences, 0.094 CPU in 0.100 seconds (93% CPU, 21333312
    Lips)

    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test2(X, Y), fail;
    true)).
    % 1,999,998 inferences, 0.094 CPU in 0.100 seconds (93% CPU, 21333312
    Lips)

    ?- Y = j(1,2), time((between(1,1000000,_), test1(X, Y), fail; true)).
    % 1,999,998 inferences, 0.109 CPU in 0.100 seconds (109% CPU, 18285696
    Lips)

    ?- Y = j(1,2), time((between(1,1000000,_), test2(X, Y), fail; true)).
    % 1,999,998 inferences, 0.094 CPU in 0.102 seconds (92% CPU, 21333312
    Lips)

    Not all Prolog systems are that lucky:

    /* Scryer Prolog 0.9.4-286 */
    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test1(X, Y), fail;
    true)).
        % CPU time: 1.163s, 11_000_108 inferences

    ?- X = f(g(1),h(2)), time((between(1,1000000,_), test2(X, Y), fail;
    true)).
        % CPU time: 1.248s, 11_000_131 inferences

    ?- Y = j(1,2), time((between(1,1000000,_), test1(X, Y), fail; true)).
        % CPU time: 0.979s, 11_000_131 inferences

    ?- Y = j(1,2), time((between(1,1000000,_), test2(X, Y), fail; true)).
        % CPU time: 1.338s, 11_000_131 inferences

    Bye


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)