(load(bitwise),0);
0$

declare(di,integer);
'done$
declare(dj,integer);
'done$
declare(dk,integer);
'done$
assume(dk>=0);
'[dk>=0]$
declare(de,even);
'done$
declare(d_o,odd);
'done$


bit_not(8);
-9$
bit_not(x);
'bit_not(x)$
bit_not(bit_not(x));
x$
bit_not(di);
-di-1$


bit_and();
-1$
bit_and(42);
42$
bit_and(x);
x$
bit_and(0,x);
0$
bit_and(-1,x);
x$
bit_and(42,z,63,y,127,x);
'bit_and(42,x,y,z)$
bit_and(x,x,x,y);
'bit_and(x,y)$
bit_and(di,-di-1,y);
0$
bit_and(x,bit_not(x),y);
0$
bit_and(de,1);
0$
bit_and(d_o,1);
1$


bit_or();
0$
bit_or(x);
x$
bit_or(x,x,x,y);
'bit_or(x,y)$
bit_or(0,x,y);
'bit_or(x,y)$
bit_or(-1,x,y);
-1$
bit_or(di,-di-1,y);
-1$
bit_or(x,bit_not(x),y);
-1$
bit_or(1,de,y);
'bit_or(de+1,y)$
bit_or(1,de,-de-2);
-1$
bit_or(1,x,d_o);
'bit_or(d_o,x)$


bit_xor();
0$
bit_xor(7);
7$
bit_xor(x);
x$
bit_xor(x,x);
0$
bit_xor(0,x);
x$
bit_xor(-1,x);
'bit_not(x)$
bit_xor(-1,di);
-di-1$
bit_xor(5,7,15,x);
'bit_xor(13,x)$
bit_xor(x,bit_not(x));
-1$
bit_xor(x,bit_not(x),y,z);
'bit_xor(bit_not(y),z)$
bit_xor(x,bit_not(x),di);
-di-1$
bit_xor(2*x,-di-1,bit_not(2*x),di,y,z);
'bit_xor(y,z)$
bit_xor(1,de);
de+1$
bit_xor(1,d_o,x);
'bit_xor(d_o-1,x)$
bit_xor(1,d_o,-d_o);
-1$


bit_lsh(21,1);
42$
bit_lsh(21,-1);
10$
bit_lsh(x,-1);
'bit_lsh(x,-1)$
bit_lsh(x,3);
8*x$
bit_lsh(17,dk);
17*2^dk$
bit_lsh(17,-dk);
'bit_lsh(17,-dk)$
bit_lsh(x,dk);
2^dk*x$


bit_rsh(21,1);
10$
bit_rsh(21,-1);
42$
bit_rsh(x,-3);
8*x$
bit_rsh(x,1);
'bit_lsh(x,-1)$


bit_onep(8,3);
true$
bit_onep(8,2);
false$
bit_onep(de,0);
false$
bit_onep(d_o,0);
true$
assume(0<=xx,xx<2^7);
'[xx>=0,xx<128]$
bit_onep(xx,7);
false$
bit_onep(xx,6);
'bit_onep(xx,6)$
bit_onep(2^dk,dk);
true$
bit_onep(4^dk,2*dk);
true$
bit_onep(di^dj,dj*log(di)/log(2));
true$


bit_length(8);
4$
bit_length(2^dk);
dk+1$
bit_length(4^dk);
2*dk+1$
