<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">Hello.</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
I'm new to Python; for a project to get to know the language I wrote up an api for representing finite topologies, and for subsets of topologies for which the orbit (the number of ways to use closure, interior, and complement operators to get separate sets) is fourteen.
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">It can be used like this:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">some_set = [[1, 2, 3], [1, 2], [2, 3], [1, 3], [1], [2], [3], []]</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">a = FiniteTopology(some_set, [1, 2, 3])
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">...</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">With all attendant methods. The constructor will take a list of lists or a set of sets.</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">orbits_of_fourteen(8)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
will generate all topologies on subsets of [1, 2, 3, 4, 5, 6, 7, 8], and look for subsets of those topologies whose orbits are of length fourteen. (It will also never end. I wouldn't recommend trying that; I put it in as an exercise.)
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">One thing I'm not sure of: if the user tries to create a FiniteTopology with a collection of sets that's not a topology, I throw a NotATopologyError in the constructor. But it looks like the FiniteTopology instance is still created. Is there any way to keep the instance from being created at all?
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">I'm also interested in tips about documentation and style.
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">Thanks a lot!</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">Best,</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">James</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
<br class="khtml-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">#!/usr/bin/env python
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">class NotATopologyError(Exception):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; pass</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">class FiniteTopology(object):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &quot;&quot;&quot;This represents a finite topology on a set of elements that can be</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; represented by Python's builtin set class. Its representation is of a set
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; of frozensets, but its constructor will take a list of lists; let it be</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; stressed that the elements on which the topology is defined must be</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; immutable.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def __init__(self, topology, main_set):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;Creates an instance of FiniteTopology, checking first to make sure
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; that it *is* a topology. If it isn't, we raise a NotATopology</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; exception.&quot;&quot;&quot;
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; self.topology = set([frozenset(element) for element in topology])
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; self.main_set = set(main_set)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; if not self._is_a_topology():</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise NotATopologyError()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def get_topology(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return self.topology</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def _is_a_topology(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;Checks if self.topology
 is a topology.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; check_one = self._check_contains_empty_main()
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; check_two = self._check_unions()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; check_three = self._check_intersections()
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return check_one and check_two and check_three
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def _check_contains_empty_main(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;A topology contains its set and the empty set.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; return self.main_set in self.topology and set([]) in self.topology</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; def _check_unions(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;A topology contains all unions of open sets.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; for i in xrange(1, len(self.topology) + 1):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for subset in combinations(self.as_list(), i):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current_union = set()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for one_set in subset:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current_union = current_union.union(one_set)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not current_union in self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return False</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return True</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br>
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def _check_intersections(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;A topology contains all pairwise intersections of open sets.&quot;&quot;&quot;
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; for item in self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for next_item in self.topology
:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intersect = set(item).intersection(next_item)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not intersect in 
self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return False</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return True</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def as_list(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;Returns a list representation of the topology.&quot;&quot;&quot;
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return [[i for i in j] for j in self.topology]</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br>
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def orbit(self, subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;Calculates the maximum number of ways we can use take complements,
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; interiors, and closures of a set to make unique sets. There are at</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; most 14 ways to do this, and usually less.&quot;&quot;&quot;
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit = set()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; complement = self.complement</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; closure = self.closure</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; interior = 
self.interior</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(subset))</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(complement(subset)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(complement(interior(subset))))
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(complement(interior(complement(subset)))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; 
orbit.add(frozenset(complement(interior(complement(closure(subset))))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(interior(subset)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(interior(closure(subset))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(interior(complement(subset))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(interior(complement(interior(subset)))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(interior(closure(interior(subset)))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(interior(closure(interior(complement(subset))))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(closure(subset)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(closure(interior(subset))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; orbit.add(frozenset(closure(interior(complement(subset)))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return orbit</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; def closure(self, subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;A limit point p of a set X is such that all open sets containing p</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; contain another point of X not equal to p. The closure of a set is the</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; set plus all of its limit points.</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; This finds all of the limit points of the subset and adds them.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; subset = set(subset)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; set_of_lps = set()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; for maybe_lp in self.main_set:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is_lp = True</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for open_set in self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if maybe_lp in open_set:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = [i for i in open_set if i != maybe_lp and i in subset]</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not len(p):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is_lp = False</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if is_lp:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_of_lps.add(maybe_lp)
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return subset.union(set_of_lps)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def interior(self, subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;The interior of a subset X is the union of all open subsets of X.&quot;&quot;&quot;
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; subsets = set()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; for one_set in self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if set(one_set).issubset(subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subsets = subsets.union(one_set)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return subsets</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; def complement(self, subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;Returns the complement of a subset.&quot;&quot;&quot;
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; return set(self.main_set) - set(subset)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">def combinations(sequence, n):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &quot;&quot;&quot;Generates all unique n-combinations of a sequence.&quot;&quot;&quot;
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; if n == 0:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; yield []</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; else:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; for i in xrange(len(sequence) - (n - 1)):</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for smaller_comb in combinations(sequence[i + 1:], n - 1):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yield [sequence[i]] + smaller_comb
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">def power_set(some_set, return_as_sets=False):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &quot;&quot;&quot;This returns the power set (set of all subsets) of some set, as a list</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; of lists or a set of sets.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; # set_list = [[i for i in j] for j in some_set]</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; power_set = [[]]</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; for i in xrange(1, len(some_set) + 1):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; for j in combinations(some_set, i):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; power_set.extend([j])</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; if return_as_sets:
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; power_set = set([frozenset(subset) for subset in power_set])</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; return power_set</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
def all_collections(some_set):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &quot;&quot;&quot;This returns all collections of subsets of a particular set, as a list</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; of lists. Takes a list.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; the_power_set = power_set(some_set)
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; collections = []</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; for i in xrange(1, len(the_power_set) + 1):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; for j in combinations(the_power_set, i):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; collections.append(j)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; return collections
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">def all_topologies_on_set_of_ints(upper_index):</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &quot;&quot;&quot;This will find all topologies on a set like [1, 2, ..., upper_index].</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; They'll be returned as a list.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; all_topologies = []</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; coll = all_collections(range(1, upper_index + 1))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; for some_set in coll:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; try:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; curr_top = FiniteTopology(some_set, some_set[len(some_set) - 1])</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; except:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; else:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; all_topologies.append(some_set)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; return all_topologies</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">def orbits_of_fourteen(upper_index):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; &quot;&quot;&quot;Prints topologies and subsets for which the orbit of that subset in the
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; topology is fourteen.&quot;&quot;&quot;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; all_t = all_topologies_on_set_of_ints(upper_index)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; for i in all_t:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">        </span>for j in xrange(1, len(i[len(i) - 1]) + 1):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">                </span>for comb in combinations(i[len(i) - 1], j):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">
                        </span>orb_len = len(FiniteTopology(i, i[len(i) - 1]).orbit(comb))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">                        </span>if orb_len == 14:
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">                                </span>print str(comb) + &quot; &quot; + str(all_t)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">def main():</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; possible_topology = [[1, 2, 3], [1, 2], [1, 3], [2, 3], [1], [2], [3], []]
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; FiniteTopology(possible_topology, [1, 2, 3])</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">if __name__ == '__main__':</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">&nbsp; &nbsp; main()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px">
<br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans; min-height: 15.0px"><br><br></p><div><br class="khtml-block-placeholder"></div><div><br class="khtml-block-placeholder"></div>