I got two expressions to list all lists of bits using Prolog:
bit(0).
bit(1).
bitlist1([]).
bitlist1([B|Bs]) :-
bit(B),
bitlist1(Bs).
bitlist2([]).
bitlist2([B|Bs]) :-
bitlist2(Bs),
bit(B).
I can't quite see if they are logically equivalent and even if they both really list ALL bit lists.
As I'm using SWI-Prolog I got the following outputs:
?- bitlist1(Bs).
Bs = [] ;
Bs = [0] ;
Bs = [0, 0] ;
Bs = [0, 0, 0] ;
Bs = [0, 0, 0, 0] ;
Bs = [0, 0, 0, 0, 0] ;
Bs = [0, 0, 0, 0, 0, 0] ;
Bs = [0, 0, 0, 0, 0, 0, 0] ;
Bs = [0, 0, 0, 0, 0, 0, 0, 0] ;
Bs = [0, 0, 0, 0, 0, 0, 0, 0, 0] ;
Bs = [0, 0, 0, 0, 0, 0, 0, 0, 0|...] ;
...
?- bitlist2(Bs).
Bs = [] ;
Bs = [0] ;
Bs = [1] ;
Bs = [0, 0] ;
Bs = [1, 0] ;
Bs = [0, 1] ;
Bs = [1, 1] ;
Bs = [0, 0, 0] ;
Bs = [1, 0, 0] ;
Bs = [0, 1, 0] ;
Bs = [1, 1, 0] ;
Bs = [0, 0, 1] ;
Bs = [1, 0, 1] ;
Bs = [0, 1, 1] ;
Bs = [1, 1, 1] ;
Bs = [0, 0, 0, 0] ;
...
bitlist1 starts listing all bit lists containing only zeros and starts listing all others afterwards but this actually can't be seen as Prolog lists an endless stream of bit lists containing only zeros.
bitlist2 lists all combinations of 0 and 1 of every length and afterwards continues with the bit lists with the length higher length.
So they are logically equivalent imo, only the output order of the bit lists differ.
Maybe anyone can confirm my guess or explain why the two expressions aren't logically equivalent? Would be great.