<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">
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">
"""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"> 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"> 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">
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"> immutable."""</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 __init__(self, topology, main_set):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """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"> 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"> exception."""
</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"> 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"> 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">
if not self._is_a_topology():</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> def get_topology(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> def _is_a_topology(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """Checks if self.topology
is a 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"> check_one = self._check_contains_empty_main()
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> check_two = self._check_unions()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> 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"> def _check_contains_empty_main(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
"""A topology contains its set and the empty 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">
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">
def _check_unions(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """A topology contains all unions of open sets."""</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
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"> 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">
current_union = set()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> for one_set in subset:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
current_union = current_union.union(one_set)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> if not current_union in self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
return False</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> def _check_intersections(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """A topology contains all pairwise intersections of open sets."""
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> for item in self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> for next_item in self.topology
:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> intersect = set(item).intersection(next_item)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> if not intersect in
self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> return False</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> def as_list(self):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """Returns a list representation of the topology."""
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> def orbit(self, subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """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"> 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"> most 14 ways to do this, and usually less."""
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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">
complement = self.complement</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> closure = self.closure</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> orbit.add(frozenset(subset))</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> orbit.add(frozenset(complement(subset)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> orbit.add(frozenset(complement(interior(subset))))
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> orbit.add(frozenset(complement(interior(complement(subset)))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
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"> orbit.add(frozenset(interior(subset)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
orbit.add(frozenset(interior(closure(subset))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> orbit.add(frozenset(interior(complement(subset))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
orbit.add(frozenset(interior(complement(interior(subset)))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> orbit.add(frozenset(interior(closure(interior(subset)))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
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"> orbit.add(frozenset(closure(subset)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
orbit.add(frozenset(closure(interior(subset))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> 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">
def closure(self, subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """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">
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"> 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"> This finds all of the limit points of the subset and adds them."""</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"> subset = set(subset)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> for maybe_lp in self.main_set:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> is_lp = True</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
for open_set in self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> if maybe_lp in open_set:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
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"> if not len(p):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
is_lp = False</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> if is_lp:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> 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"> def interior(self, subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """The interior of a subset X is the union of all open subsets of X."""
</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"> subsets = set()</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
for one_set in self.topology:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> if set(one_set).issubset(subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
subsets = subsets.union(one_set)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> def complement(self, subset):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> """Returns the complement of a subset."""
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> """Generates all unique n-combinations of a sequence."""
</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 n == 0:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
yield []</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> else:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> 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"> 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">
"""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"> 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"> # 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"> 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">
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"> for j in combinations(some_set, i):</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
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"> if return_as_sets:
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> 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"> """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">
of lists. Takes a list."""</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"> the_power_set = power_set(some_set)
</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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">
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"> 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">
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"> 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"> """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">
They'll be returned as a list."""</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">
all_topologies = []</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> for some_set in coll:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> try:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
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"> except:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans">
pass</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> else:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> 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"> 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"> """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"> topology 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">
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">
for i in all_t:</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Lucida Sans"> <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">
<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"> <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"> <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"> <span class="Apple-tab-span" style="white-space:pre">                                </span>print str(comb) + " " + 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"> 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"> 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"> 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>