@prefix list: <http://www.w3.org/2000/10/swap/list#>.
@prefix : <http://example.org/#>.

() :permutation ().
{ ?As :permutation ?Bs } <= {
    ?Bs list:firstRest (?B ?Cs).
    ?As list:select (?B ?Ds).
    ?Ds :permutation ?Cs.
}.
