%% binary numbers
% Empty string of bits, or a string of bits preceded by
% either b0 or b1.
% Read little-endian (LSB first)
% e.g. b0(b1(e)) is 2
bin(e).
bin(b0(M)) :- bin(M).
bin(b1(M)) :- bin(M).

inc_(e, b1(e)).
inc_(b0(M), b1(M)).
inc_(b1(M), b0(N)) :- inc_(M, N).

inc(e, b1(e)).
%inc(b0(e), b1(e)).
inc(b0(b0(N)), b1(b0(N))).
inc(b0(b1(N)), b1(b1(N))).
inc(b1(M), b0(N)) :- inc_(M, N).

std(e).
%std(b0(N)) :- std(N), N \= e.
std(b0(b0(N))) :- std(b0(N)).
%std(b0(b1(N))) :- std(b1(N)).
std(b0(b1(N))) :- std(N).
std(b1(N)) :- std(N).
