Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushik94 committed Dec 9, 2014
0 parents commit 34810cf
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 0 deletions.
64 changes: 64 additions & 0 deletions FiniteGroup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from group import Group

"""
from group import Set
from group import Function
"""

class FiniteGroup(Group):
def __init__(self, group, function):
self.set = group
self.function = function
_check_if_group(group, function)
self.identity = self._find_identity()

def cayley_table(self):
cayley = [self.function(a, b) for a in self.set for b in self.set]
return cayley

def print_cayley_table(self):
"""
Need a better way to print this shit !!
"""
print self.cayley_table()

@property
def isFinite(self):
return True

@property
def identity(self):
return self.identity

@property
def isAbelian(self):
if all(self.function(a, b) == self.function(b, a) for a in self.set for b in self.set):
return True
return False

def _find_identity(self):
for element in self.set:
if all(element*x == x for x in self.set):
return element
raise TypeError('The given set has no identity element on the function')

@property
def order(self):
return len(self.set)


def _check_if_group(group, function):
if not _check_closure(group, function):
raise TypeError('The set is not closed under the given function')
if not _check_associativity(group, function):
raise TypeError('The function is not associative on the group')

def _check_closure(group, function):
if not all(function(a, b)%len(group) in group for a in group for b in group):
return False
return True

def _check_associativity(group, function):
if not all(function(a, function(b, c)) == function(function(a, b), c) for a in group for b in group for c in group):
return False
return True
Binary file added FiniteGroup.pyc
Binary file not shown.
64 changes: 64 additions & 0 deletions FiniteGroup.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from group import Group

"""
from group import Set
from group import Function
"""

class FiniteGroup(Group):
def __init__(self, group, function):
self.set = group
self.function = function
_check_if_group(group, function)
self.identity = self._find_identity()

def cayley_table(self):
cayley = [self.function(a, b) for a in self.set for b in self.set]
return cayley

def print_cayley_table(self):
"""
Need a better way to print this shit !!
"""
print self.cayley_table()

@property
def isFinite(self):
return True

@property
def identity(self):
return self.identity

@property
def isAbelian(self):
if all(self.function(a, b) == self.function(b, a) for a in self.set for b in self.set):
return True
return False

def _find_identity(self):
for element in self.set:
if all(element*x == x for x in self.set):
return element
raise TypeError('The given set has no identity element on the function')

@property
def order(self):
return len(self.set)


def _check_if_group(group, function):
if not _check_closure(group, function):
raise TypeError('The set is not closed under the given function')
if not _check_associativity(group, function):
raise TypeError('The function is not associative on the group')

def _check_closure(group, function):
if not all(function(a, b)%len(group) in group for a in group for b in group):
return False
return True

def _check_associativity(group, function):
if not all(function(a, function(b, c)) == function(function(a, b), c) for a in group for b in group for c in group):
return False
return True
39 changes: 39 additions & 0 deletions group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import types

def check_if_group(group, function):
if not len(group):
return False, "the set is empty"
if not _check_associvity(group, function):
return False, "the function is not associative on the group elements"
if not _check_closure(group, function):
return False, "the function is not closed"

class Group():
def __init__(self, group, function=None):
self.is_multiplicative = False
if function is None:
self.is_multiplicative = True
pass
elif not isinstance(function, types.FunctionType):
raise TypeError('should supply a function')
self.group = group
self.function = function

def cayley_table(self):
raise NotImplementedError

@property
def isFinite(self):
return True

@property
def isAbelian(self):
raise NotImplementedError

@property
def order(self):
raise NotImplementedError

@property
def is_Multiplicative(self):
return self.is_multiplicative
Binary file added group.pyc
Binary file not shown.
39 changes: 39 additions & 0 deletions group.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import types

def check_if_group(group, function):
if not len(group):
return False, "the set is empty"
if not _check_associvity(group, function):
return False, "the function is not associative on the group elements"
if not _check_closure(group, function):
return False, "the function is not closed"

class Group():
def __init__(self, group, function=None):
self.is_multiplicative = False
if function is None:
self.is_multiplicative = True
pass
elif not isinstance(function, types.FunctionType):
raise TypeError('should supply a function')
self.group = group
self.function = function

def cayley_table(self):
raise NotImplementedError

@property
def isFinite(self):
return True

@property
def isAbelian(self):
raise NotImplementedError

@property
def order(self):
raise NotImplementedError

@property
def is_Multiplicative(self):
return self.is_multiplicative
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from distutils.core import setup
1 change: 1 addition & 0 deletions setup.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from distutils.core import setup
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import types
func = lambda x, y : x*y
print func(3, 4)
print isinstance(func, types.FunctionType)
4 changes: 4 additions & 0 deletions test.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import types
func = lambda x, y : x*y
print func(3, 4)
print isinstance(func, types.FunctionType)
5 changes: 5 additions & 0 deletions test_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from group import Group as G
from FiniteGroup import FiniteGroup as FG

x = FG([0, 1, 2, 3], lambda x, y: x-y)
print x.isAbelian
5 changes: 5 additions & 0 deletions test_groups.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from group import Group as G
from FiniteGroup import FiniteGroup as FG

x = FG([0, 1, 2, 3], lambda x, y: x-y)
print x.isAbelian

0 comments on commit 34810cf

Please sign in to comment.