All pastes #2102899 Raw Edit

Untitled

public text v1 · immutable
#2102899 ·published 2012-01-14 06:17 UTC
rendered paste body
from numpy import matrix
from math import trunc
from math import sqrt

table1=matrix([[0,1],[0,1]])


def size(a):
	return trunc(sqrt(a.size))
def inrange(a,b,max):
	return a>=0 and b>=0 and a<max and b<max

def finbin(a,b,op):
	if inrange(a,b,size(op)):
		return op[a,b]
	else:
		return False	
	
def assoc(op):
	for a in range(size(op)):
		for b in range(size(op)):
			for c in range(size(op)):
				x1=finbin(finbin(a,b,op),c,op)
				x2=finbin(a,finbin(b,c,op),op)
				#print "(",a,b,")",c,"=",x1,"?", x2,"=", a,"(",b,c,")"
				if x1!=x2:
					return False
					print "Not Associative"
	return True

def identity(op): #returns identity element if it exists -1 otherwise
	for fix in range(size(op)):
		ident=True
		for var in range(size(op)):
			ident=ident and op[fix,var]==var==op[var,fix]
			if not ident:
				break
		if ident:
			return fix
	print "No Inverse"
	return -1

def inverses(op):
	#columns
	outerx=True
	outery=True
	ident=identity(op)
	if ident==-1:
		return False
	for a in range(size(op)):
		innerx=False
		innery=False
		for b in range(size(op)):
			innerx=innerx ^ op[a,b]==ident
			innery=innery ^ op[b,a]==ident
		outerx=outerx and innerx
		outery=outery and innery
		if outerx==outery==False:
			print "No Inverses"
			return False
	return True

def groupcheck(op):
	if assoc(op) and inverses(op):
		print "It is a group"
		return True
	else: return False

def abelcheck(op):
	if not groupcheck(op): return False
 	for i in range(size(op)):
		for j in range(size(op)):
			if op[i,j]!=op[j,i]:
				return False
	print "Abelian"
	return True




for i in [matrix([[0,1],[1,a]]) for a in range(2)]:
	print inverses(i)