Skip to content

Instantly share code, notes, and snippets.

@ernestyalumni
Created May 24, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ernestyalumni/903eefd01be1f214598b to your computer and use it in GitHub Desktop.
Save ernestyalumni/903eefd01be1f214598b to your computer and use it in GitHub Desktop.
Topology.sage Use Sage Math and Set function/module to check if a set is a topology and other implementations for Topology
## topology.sage
## This is my implementation of Topology
## utilizing
## Sage Math
## from
##
## The main reference that I'll liberally copy from is from is
## Lecture 1: Topology (International Winter School on Gravity and Light 2015)
## Frederic P Schuller
## The WE-Heraeus International Winter School on Gravity and Light 2015
##
## and http://people.math.sfu.ca/~jtmulhol/math302/notes/2-SetTheory.pdf
## Lecture 2: A Bit of Set Theory
## Jamie Mulholland, Spring 2010 Math 302
##
################################################################################
## Copyleft 2015, Ernest Yeung <ernestyalumni@gmail.com>
##
## 20150524
##
## This program, along with all its code, is free software; you can redistribute
## it and/or modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the License,
## or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You can have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software Foundation, Inc.,
## S1 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA
##
## Governing the ethics of using this program, I default to the Caltech
## Honor Code:
## ``No member of the Caltech community shall take unfair advantage of
## any other member of the Caltech community.''
##
## If you like what I'm doing and would like to help and contribute support,
## please take a look at my crowdfunding campaign at ernestyalumni.tilt.com
## and Patreon, read my mission statement and give your financial support,
## no matter how small or large, if you can and to keep checking my
## ernestyalumni.wordpress.com blog and various social media channels
## for updates as I try to keep putting out great stuff.
##
## Fund Science! & Help Ernest in Physics Research! :
## quantum super-A-polynomials - researched by Ernest Yeung
##
## ernestyalumni.tilt.com
##
## Facebook : ernestyalumni
## gmail : ernestyalumni
## google : ernestyalumni
## linkedin : ernestyalumni
## Patreon : ernestyalumni
## Tilt/Open : ernestyalumni
## tumblr : ernestyalumni
## twitter : ernestyalumni
## youtube : ernestyalumni
## wordpress : ernestyalumni
##
##
################################################################################
emptyset = Set([]) # cf. http://doc.sagemath.org/html/en/reference/structure/sage/sets/set.html an_element()
# cf. Exercise 2: Topologies on a simple set, Topology tutorial sheet, The WE-Heraeus International Winter School on Gravity and Light 2015
M = Set(x for x in range(1,5))
O_1 = Set( [ emptyset, Set([1]), M ] )
O_2 = Set( [ emptyset, Set([1]), Set([2]), M ])
# this is an example of checking Axiom 1 of the definition of a topology, that the empty set is in the topology
emptyset in O_1 # True
def chaotictopology(set):
"""
chaotictopology = chaotictopology(set)
Returns a Set
chaotic topology is also known as trivial topology or indiscrete topology (all the same thing)
"""
return Set([emptyset, set])
def Axiom2check(topology):
"""
Axiom2check = Axiom2check(topology)
checks Axiom 2, the finite intersection axiom for topology
e.g. Example of Usage
Axiom2check(O_1) # True
"""
for U in topology:
for V in topology:
if U.intersection(V) not in topology:
print "This did not satisfy Axiom 2: ", U.intersection(V)
return False
return True
def Axiom3check(topology):
"""
Axiom3check = Axiom3check(topology)
checks Axiom 3, that the union of any subset of a topology is in the topology
e.g. Example of Usage
Axiom3check(O_1)
"""
P = topology.subsets() # power set
for subset in P.list():
if subset != emptyset:
if subset.cardinality() > 1:
union_alpha = subset[0]
for U in subset:
union_alpha = union_alpha.union(U)
if union_alpha not in topology:
print "This did not satisfy Axiom 3: ", union_alpha
return False
return True
def checkcont(targettopology,domaintopology,invfunc):
for V in targettopology:
preimg = []
for element in V:
preimg.append(invfunc(element))
preimg = Set(preimg)
if preimg not in domaintopology:
print "This V in the target topology makes the function not continuous: ", V
return False
return True
####################################################################################################
# So going back to Exercise 2: Topologies on a simple set, Topology tutorial sheet, The WE-Heraeus International Winter School on Gravity and Light 2015
####################################################################################################
# Question: Does O1 := {∅, {1}, {1, 2, 3, 4}} constitute a topology on M ?
# Answer: Yes since
emptyset in O_1
Axiom2check(O_1) # True
Axiom3check(O_1) # True
# Question: What about O2 := {∅, {1}, {2}, {1, 2, 3, 4}}?
# Answer: No since
emptyset in O_2
Axiom2check(O_2) # True
Axiom3check(O_2) # False
####################################################################################################
# Topology tutorial sheet, The WE-Heraeus International Winter School on Gravity and Light 2015
# cf. Exercise 3: Continuous functions
####################################################################################################
# Question: Let M = {1, 2, 3, 4} and consider the identity map idM : M → M defined by idM(1) = 1, idM(2) = 2, idM(3) = 3, idM(4) = 4.
# Is the map idM continuous if the domain is equipped with the chaotic topology and the target with the topology Otarget := {∅, {1}, {1, 2, 3, 4}}?
# Answer: No
domain31 = chaotictopology(M)
target31 = Set( [ emptyset, Set([1]), M ])
f = lambda(x) : x
checkcont(target31,domain31,f) # False
# Question: Consider the inverse id−1 : M → M of the identity map idM , such that now the target is M
# equipped with the chaotic topology and the domain with the topology {∅, {1}, {1, 2, 3, 4}}. Provide the values of the map id−1 and decide whether id−1 is continuous!
# Answer: Yes
checkcont(domain31, target31, f) # True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment