Calculate the number of topologies on {1,2,...,n} Task


  Write a function/program which takes n as a parameter/input and prints/returns the number of topologies (which is demonstrated below) on the set {1,2,...,n}.


Definition of Topology

Let X be any finite set, and assume that T, which is subset of the power set of X (i.e. a set containing subsets of X), satisfy these conditions:


X and the empty set are in T.
If two set U and V are in T, then the union of those two sets are in T.
If two set U and V are in T, then the intersection of those two sets are in T.


...then T is called the topology on X.

Specifications


Your program is either:


a function which takes n as a parameter
or a program which inputs n


and prints or returns the number of (distinct) topologies on the set {1,2,...,n}.
n is any non-negative integer which is less than 11 (of course there's no problem if your program handles n bigger than 11), and the output is a positive integer.
Your program should not use any kinds of library functions or native functions which  calculates the number of topology directly.


Example input (value of n) : 7

Example output/return : 9535241

You may check your return value at here or here.

Of course, shortest code wins.



The winner is decided, however, I may change the winner if shorter code appears..
Python, 147 chars

N=input()
S=lambda i,K:1+sum(0if len(set(j&amp;k for k in K)-K)-1 else S(j+1,K|set(j|k for k in K))for j in range(i,2**N))
print S(1,set([0,2**N-1]))


Quick for N&lt;=6, slow for N=7, unlikely N>=8 will ever complete.

Individual sets are represented by integer bitmasks, and topologies by sets of bitmasks.  S(i,K) computes the number of distinct topologies you can form by starting with K and adding sets with bitmasks >= i.