sort(Xs, Ys) :-
sort(Xs, Ys, [], Ys).
sort([], [], Ys, Ys).
sort([X|Xs], [_|Bound], Rs, Ys) :-
sort(Xs, Bound, [X|Rs], Ys).
My code compiles. I try my predicate at the repl: 110 ?- sort([2,3,1,5,6], Sorted).
Sorted = [6, 5, 1, 3, 2].
What went wrong?There is no specification in your prolog example, in lean we explicitly check that the expression in lean is GRH (and this is about half a page of lean and has been checked by many many mathematicians), and then can arrive at a formal proof for that specification.
You are confusing the issue for people who don't understand what a formal proof means with this non-sequitur.