def __init__(self, n): n = int(n) self._abelian = True super(Zx, self).__init__([i for i in range(1, n)], getop('multmod', n, cache=0), 1 if n > 1 else None, name='Zx(' + str(n) + ')')
def __init__(self, s, g, op=None, name=None): s = int(s) m = [] def loop_rec(g, n, l={}, rows=[]): if n >= 1: for a in g: l[n] = a rows = loop_rec(g, n - 1, l, rows) else: r = [] for i in l: r.append(l[i]) rows.append(r) return rows rows = loop_rec(g, s) matrices = loop_rec(rows, s, {}, []) for mat in matrices: t = Matrix(mat) if self.det_case(t): m.append(t) if name == None: name = 'M(' + str(s) + ', ' + (format(g, '#') if isinstance( g, FiniteGroup) else str(g)) + ')' if op == None: op = getop('mult', cache=len(m)**2) super(M, self).__init__(m, op, name)
def __init__(self, n): n = int(n) self._abelian = True super(Z, self).__init__([i for i in range(n)], getop('addmod', n, cache=0), 0 if n > 0 else None, name='Z(' + str(n) + ')')
def __init__(self, n): n = int(n) self._abelian = True super(U, self).__init__([i for i in range(n) if gcd(i, n) == 1] if n != 1 else [1], getop('multmod', n, cache=0), 1 if n > 0 else None, name='U(' + str(n) + ')')
def __init__(self, l, op=getop('mult'), name=None): p = None if len(l) > 0 and not isinstance(l[0], Matrix): p = [] for i in l: p.append(Matrix(i)) e = None super(MatrixGroup, self).__init__(p if p != None else l, op, name=name)
def __init__(self, l, e=Permutation([]), name=None): p = None if len(l) > 0 and not isinstance(l[0], Permutation): p = [] for i in l: p.append(Permutation(i)) super(PermutationGroup, self).__init__(p if p != None else l, getop('mult', cache=len(l)**2), e, name=name)
def __init__(self, n): m = None if int(n) % 4 and int(n) not in [1, 2 ] or int(n) <= 0 else int( int(n) / 4) if int(n) == 1: super(Dic, self).__init__([1], getop('mult', cache=0), name='Q(' + str(n) + ')') else: super(Q, self).__init__(m) self.name = 'Q(' + str(n) + ')'
def __init__(self, m, op=None, name=None): g = m if not isinstance(m, Matrix): if len(m[0]) > 0 and isinstance(m[0][0], list): g = [] for h in m: g.append(Matrix(h)) else: g = Matrix(m) super(MatrixGeneratorGroup, self).__init__(g, op if op != None else getop("mult"), name=name)
def __init__(self, g, op=None): m = [] for a in g: if a != 0: for b in g: m.append(Matrix([[a, b], [0, 1]])) if op == None: op = getop('mult', (len(m)**2)) super(Aff, self).__init__( m, op, name='Aff(' + (format(g, '#') if isinstance(g, FiniteGroup) else str(g)) + ')')
def __init__(self, p, pname=None, name=None): g = p if not isinstance(p, Permutation): if len(p[0]) > 0 and isinstance(p[0][0], list): g = [] s = 0 for h in p: s += 1 g.append( Permutation(h, pname + str(s) if pname != None else None)) else: g = Permutation(p, pname) super(PermutationGeneratorGroup, self).__init__(g, getop('mult'), name=name)
def __init__(self, n): n = int(n) if n != None else -1 m = [] if n == 0: m = [Quaternion(r=-1.0)] elif n == 1: m = [Quaternion(i=1.0)] elif n > 1: a = Quaternion(r=cos(pi / n), i=sin(pi / n)) m = [a, Quaternion(j=1.0)] if n >= 2: self._abelian = False else: self._abelian = True super(Dic, self).__init__(m, getop('mult', cache=1.5 * (4 * n)**2), name='Dic(' + str(n) + ')')
def parse_group(g): if g[0] not in group_type_list: print('Warning: Group type', g[0], 'not available.') return None else: skip = False in_equality = [] scope = [] group_args = [] if len(g) > 1: g_args = re.compile("(<|>|{|}|\[|\]|,|=)").split(g[1]) for i, arg in enumerate(g_args): if skip or arg in [',', '']: skip = False continue elif arg in ['<', '{', '[']: scope = [(arg, [])] + scope elif scope: if scope[0][0] == '{': if arg == '}': new_scope_arg = [[], {}] for o in scope[0][1]: if isinstance(o, dict): for k in o: new_scope_arg[1][k] = o[k] else: new_scope_arg[0].append(o) if len(scope) > 1: scope[1][1].append(new_scope_arg[0][0]( *new_scope_arg[0][1:], **new_scope_arg[1])) else: if in_equality: group_args.append({ in_equality[0]: new_scope_arg[0][0]( *new_scope_arg[0][1:], **new_scope_arg[1]) }) else: group_args.append(new_scope_arg[0][0]( *new_scope_arg[0][1:], **new_scope_arg[1])) scope.pop(0) elif arg == '=': scope[0][1].pop() scope[0][1].append( {g_args[i - 1]: g_args[i + 1]}) skip = True elif scope[0][1]: scope[0][1].append(arg) elif arg in group_type_list: scope[0][1].append(group_type_list[arg]) else: print('Warning: Group type', arg, 'not available.') return None elif scope[0][0] == '[': if arg == ']': if len(scope) > 1: scope[1][1].append(scope[0][1]) else: if in_equality: group_args.append( {in_equality[0]: scope[0][1]}) else: group_args.append(scope[0][1]) scope.pop(0) else: # Parse list elements as ints until better solution found scope[0][1].append(int(arg)) elif scope[0][0] == '<': if arg == '>': new_scope_arg = [[], {}] for o in scope[0][1]: if isinstance(o, dict): for k in o: new_scope_arg[1][k] = o[k] else: new_scope_arg[0].append(o) if len(scope) > 1: scope[1][1].append( getop(new_scope_arg[0][0], *new_scope_arg[0][1:], **new_scope_arg[1])) else: if in_equality: group_args.append({ in_equality[0]: getop(new_scope_arg[0][0], *new_scope_arg[0][1:], **new_scope_arg[1]) }) else: group_args.append( getop(new_scope_arg[0][0], *new_scope_arg[0][1:], **new_scope_arg[1])) scope.pop(0) elif arg == '=': scope[0][1].pop() scope[0][1].append( {g_args[i - 1]: g_args[i + 1]}) skip = True else: scope[0][1].append(arg) elif arg == '=': group_args.pop() if g_args[i + 1] not in ['<', '{', '[', '']: group_args.append({g_args[i - 1]: g_args[i + 1]}) skip = True else: in_equality = [g_args[i - 1]] elif arg: group_args.append(arg) if i == len(g_args) - 1 and (scope or skip): return None new_group_arg = [[], {}] for o in group_args: if isinstance(o, dict): for k in o: new_group_arg[1][k] = o[k] else: new_group_arg[0].append(o) return (group_type_list[g[0]], new_group_arg[0], new_group_arg[1])
def __init__(self): super(NullGroup, self).__init__([], getop('null'), name='NullGroup')