-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 34810cf
Showing
12 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from distutils.core import setup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from distutils.core import setup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |