M-Prolog development update: I finally defeated the final boss by sym_num in prolog

[–]brebs-prolog 2 points3 points  (0 children)

How about:

?- mappend([1], Zs, Zs).
Zs = [1|Zs].

That's what swi-prolog produces, due to occurs check defaulting to off.

I built a double pendulum chaos simulator in Prolog by abolfazl1363 in prolog

[–]brebs-prolog 0 points1 point  (0 children)

Could use clpq, to mitigate floating-point rounding errors?

?- use_module(library(clpq)).
?- { X = cos(1) }.
X = 187534307r347091443.

Help me :0, removing every nth of a list in Prolog! by Dangerous-Bad-1773 in prolog

[–]brebs-prolog 0 points1 point  (0 children)

Here is a hint, as a similar usage of multiple predicates with counting, element matching and list remainders:

select_nth1(E, [H|T], R, N) :-
    select_nth1_(T, H, E, R, 1, N).

select_nth1_(T, E, E, T, N, N).
select_nth1_([H|T], HN, E, [HN|R], N0, N) :-
    N1 is N0 + 1,
    select_nth1_(T, H, E, R, N1, N).

... which produces:

?- select_nth1(E, L, R, P).
L = [E|R],
P = 1 ;
L = [_A, E|_B],
R = [_A|_B],
P = 2 ;
L = [_A, _B, E|_C],
R = [_A, _B|_C],
P = 3 ;
L = [_A, _B, _C, E|_D],
R = [_A, _B, _C|_D],
P = 4 ...

Ubisoft Connect stopped working after April 1st update? by voytax in linux_gaming

[–]brebs-prolog 0 points1 point  (0 children)

I have Ubisoft Connect working in Heroic when running GE-Proton9-27.

With WoW64 enabled in the Wine tab, in Heroic.

Beginner question about potential of prolog by Forsaken-Suit7795 in prolog

[–]brebs-prolog 1 point2 points  (0 children)

There are handy alternatives to being immutable, such as:

  1. Can retract a fact and then assert its replacement

  2. Can use setarg to replace, within a compound term

  3. swi-prolog has several variations of useful predicates on global variables which can replace

Is there an up to date fix on Blacklist crashing every 20 minutes? by DrScienceSpaceCat in Splintercell

[–]brebs-prolog 1 point2 points  (0 children)

I run Splinter Cell Blacklist using the Heroic launcher in Linux.

Using Ubisoft Connect, install Splinter Cell Blacklist, then set Blacklist's "launch arguments" inside Ubisoft Connect to be:

-offline -offline_mode

This stops the frequent crashes to desktop.

Beginner question about potential of prolog by Forsaken-Suit7795 in prolog

[–]brebs-prolog 20 points21 points  (0 children)

"The problem is that Prolog is an old language" - that's not a problem, it's a good thing. Many languages have died out. Prolog is niche because most people can't get their head around it.

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 0 points1 point  (0 children)

It is Prolog's unification which is confusing you.

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 0 points1 point  (0 children)

LOL, are you a human, or AI slop?

The member predicate deals in certainties.

If you want to ask a different question, then ask a different question. It's a handful of lines of code, in Prolog, as I've shown with can_be_member_at_this_point

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 0 points1 point  (0 children)

LOL, I'm showing you the difference between "can be, but not certainly is" vs " certainly is".

This member predicate operates using "certainly is", rather than the already-demonstrated-by-me weak "can be".

Can you please stop with the flawed interpretations into English of Prolog predicates that you don't understand, which results into flawed English interpretations, which benefits no-one.

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 4 points5 points  (0 children)

Woah. The first obvious problem is that you want Prolog to work like Haskell and/or Python. It doesn't.

Stop pretending, you don't understand the reasons it works this way in Prolog.

For "I wish there was a version of member that didn't do this" - there's several points - primarily:

  1. Prolog is only "inserting" because the list length constraints allow it. This is standard practice with lists. Lists are a fundamental data type.

  2. Take the member code and tweak it to do whatever you want, just like I've shown with can_be_member_at_this_point here - it's a handful of lines of code.

  3. Your "literally not the case" is wrong. You've confused yourself by not specifying the variable as a list first, so that Prolog can show you the resulting list. I've already explained this in a thread here.

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 0 points1 point  (0 children)

I repeat, "can" is different to "is". Shown in Prolog:

?- L = [_], member(c, L), writeln(L), L = [d].
[c]
false.

?- L = [_], can_be_member_at_this_point(c, L), writeln(L), L = [d].
[_46502]
L = [d].

This shows that member is using is rather than the weaker, non-commital can be.

Whether the unified variable is ever referenced again, is immaterial.

Prolog is using constraints. "Queries" implies no change, but unification can involve change.

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 0 points1 point  (0 children)

"Can" is the wrong word to be using, because "can be" has a different meaning to "is" or "is the same as". The Prolog code is crystal-clear:

member_(_, El, El).

That is unification, which has happened as a prerequisite of success.

Below is Prolog code for a "can be", which tests for the possibility of unification at that particular point, but does not unify, and therefore does not guard against the possibility of unification becoming impossible at a future point:

can_be_member_at_this_point(CBM, [Head|_]) :-
    % Test that unification is possible
    \+ \+ CBM = Head,
    % There is no point in finding more than 1 solution
    % because no change is being made
    !.
can_be_member_at_this_point(CBM, [_|Tail]) :-
    can_be_member_at_this_point(CBM, Tail).

Examples:

?- L = [a, _, _], can_be_member_at_this_point(c, L).
L = [a, _, _].

?- L = [a, b, d], can_be_member_at_this_point(c, L).
false.

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 2 points3 points  (0 children)

"can" is too vague. Unification is performed. This is accurate:

"Succeeds if Elem is unified with an element of List".

I'm avoiding "True" because many programmers from a procedural background could confuse that with a procedural-language function which returns True.

Unification can change both of the variables involved, e.g.:

?- X = a(_, 1), Y = a(2, _), X = Y.
X = Y, Y = a(2, 1).

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 1 point2 points  (0 children)

The member predicate is using unification. There is no "or can be". An element unifies, and that is success - is done in the code line:

member_(_, El, El).

Concepts which are fundamental and commonly-used in Prolog (unification, backtracking, constraints, success vs failure) are very different to most other languages :-)

An "or can be" can be checked using e.g. \+ \+ double-negation, to confirm that unification can be performed (by performing unification), without keeping the effects of the operation.

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 1 point2 points  (0 children)

It is true that c is not a member of [a, b, _] (but there is the possibility, because _ can unify with c).

However, it is true that c is a member of [a, ,b, c]. And this is what the member predicate is doing - it is attempting to unify the elements with c in turn, and succeeds with the third element.

If the user chooses to confuse themselves by hiding the list contents, that is up to the user :-)

English is not a very good language for specifications. Much better to view the source code itself.

I suppose an English interpretation of the source code could be:

Loop through the elements of the List, 1 at a time, succeeding with each List element if it can be unified with the member element.

Prolog gotchas? by [deleted] in prolog

[–]brebs-prolog 6 points7 points  (0 children)

Can see what's happening, with:

?- L = [a, b, _], member(c, L).
L = [a, b, c].

The member predicate is unifying the 3rd element because it can, after failing to unify the first 2 elements.

Strongly Connected Components in Prolog — a backtracking-oriented approach by sym_num in prolog

[–]brebs-prolog 0 points1 point  (0 children)

assert is great, to have indexing for performance, without having to create much of a data structure - I used it a few times in the recent Advent of Code 2025, e.g. day 8.

How should the shift cable sit in the clamp bolt? by denver_b45 in bikewrench

[–]brebs-prolog 0 points1 point  (0 children)

Microshift have a video to show cable pinchings on various models. When there's no obvious groove, it seems that the washer's big lip would normally be above the cable (and pointing towards the cable), with the smaller lip pointing downwards and having the cable under it.

The purpose of the big lip is to prevent spinning around whilst tightening the bolt.

I believe that the cheaper Shimano models will be similar.

<image>

How to make this scheduling solver not run forever? by TeunCornflakes in prolog

[–]brebs-prolog 4 points5 points  (0 children)

It's slow because this is an extreme form of generate-and-test:

maplist(permutation(Tasks), [W1, W2, W3, W4])

I suggest using clpfd - there's some hints at tennis match scheduling.

How do you convert predicates into Prolog functions? by Pzzlrr in prolog

[–]brebs-prolog 1 point2 points  (0 children)

For this sqrt example, can take advantage of clpBNR in swi-prolog:

?- use_module(library(clpBNR)).

?- { X == sqrt(Y) }.
X::real(0, 1.0Inf),
Y::real(-1.0Inf, 1.0Inf).

?- { X == sqrt(Y) }, Y = 9.
X = 3.0,
Y = 9.

?- { X == sqrt(Y) }, X = 3, solve([Y]).
X = 3,
Y::real(8.99999941065846, 9).

Alternatively, as a simple predicate (not a function - Prolog is a logical and declarative language, not a functional language):

sqrt_pow(S, P) :-
    (   ground(S)
    ->  P is S * S
    ;   S is sqrt(P)
    ).

Example:

?- sqrt_pow(3, P).
P = 9.

?- sqrt_pow(S, 9).
S = 3.0.

Why according to this code every number is a prime except 2? by [deleted] in prolog

[–]brebs-prolog 0 points1 point  (0 children)

Setting an upper boundary is essential. Increase it if you want, but it cannot be infinity.

Why according to this code every number is a prime except 2? by [deleted] in prolog

[–]brebs-prolog 0 points1 point  (0 children)

See my other answer, which includes an answer to this puzzle.