Topologies

A topology tau for a positive integer n is a set of integers with the following rules :
	1. tau is a subset of {0, 1, ..., (2^n) - 1}.
	2. tau has both 0 and (2^n - 1) as members.
	3. For a and b, where  and b are any two members of tau, both a/\b and a \/ b, where /\ and \/ are "bitwise and" and "bitwise or" respectively, are in tau.

TopologyQ[tau_]:=
Apply[And,
Table[
Apply[And,
Table[
And[
MemberQ[tau,BitAnd[Extract[tau,{i}],Extract[tau,{j}]]],
(*check if the BitAnd of the i'th and j'th element is in the set*)
MemberQ[tau,BitOr[Extract[tau,{i}],Extract[tau,{j}]]]
(*check if the BitOr of the i'th and j'th element is in the set*)
],{j,i+1,Length[tau]}
]
],{i,1,Length[tau]-1}
]
](*true if tau is a topology*)

CountTopologies[n_]:=Module[{p,s,t,topologies},
p=Range[2^n-2];(*list all possible elements of any tau beside 0 and 2^n-1;they'll be added back in later.p will be used to generate candidate topologies*)
s=Subsets[p];(*take the subsets of p*)
t=Map[(Prepend[Append[#,2^n-1],0])&,s];(*all topologies have to have 0 and 2^n-1 so add them in to the front now*)
topologies=Select[t,TopologyQ];(*take all the candidate topologies which pass the test for being topologies*)
Length[topologies](*count them*)
]