def __init__(self, *kargs, **kwargs): kwargs = metric.test_init_slots(Lt.init_slots, **kwargs) mat_rep = kargs[0] ga = kwargs['ga'] self.fct_flg = kwargs['f'] self.Ga = ga self.coords = ga.lt_coords self.X = ga.lt_x self.spinor = False if isinstance(mat_rep, dict): # Dict input self.mv_dict = {} self.lt_dict = {} for key in mat_rep: self.lt_dict[key] = mat_rep[key] elif isinstance(mat_rep, list): # List input self.lt_dict = {} self.mv_dict = {} if not isinstance(mat_rep[0], list): for (lt_i, base) in zip(mat_rep, self.Ga.basis): self.lt_dict[base] = lt_i else: mat_rep = map(list, zip(*mat_rep)) # Transpose list of lists for (row, base1) in zip(mat_rep, self.Ga.basis): tmp = 0 for (col, base2) in zip(row, self.Ga.basis): tmp += col * base2 self.lt_dict[base1] = tmp elif isinstance(mat_rep, mv.Mv): # Spinor input self.spinor = True self.R = mat_rep self.Rrev = mat_rep.rev() elif isinstance(mat_rep, str): # String input root = mat_rep mat_rep = [] for row in self.Ga.coords: row_str = '' for col in self.Ga.coords: row_str += root + '_' + str(row) + str(col) + ',' if self.fct_flg: fct_names = row_str[:-1].split(',') mat_rep.append([Function(fct_name)(*self.Ga.coords) for fct_name in fct_names]) else: mat_rep.append(list(symbols(row_str[:-1]))) self.__init__(mat_rep, ga=self.Ga) else: # F is a multivector function to be tested for linearity F = mat_rep a = mv.Mv('a', 'vector', ga=self.Ga) b = mv.Mv('b', 'vector', ga=self.Ga) if F(a + b) == F(a) + F(b): self.lt_dict = {} for base in self.Ga.basis: self.lt_dict[base] = (F(mv.Mv(base, ga=self.Ga))).obj else: raise ValueError(str(mat_rep) + ' is not supported for Lt definition\n')
def __init__(self, *kargs, **kwargs): """ Except for the spinor representation the linear transformation is stored as a dictionary with basis vector keys and vector values self.lt_dict so that a is a vector a = a^{i}e_{i} then self(a) = a^{i} * self.lt_dict[e_{i}]. For the spinor representation the linear transformation is stored as the even multivector self.R so that if a is a vector self(a) = self.R * a * self.R.rev(). """ kwargs = metric.test_init_slots(Lt.init_slots, **kwargs) mat_rep = kargs[0] ga = kwargs['ga'] self.fct_flg = kwargs['f'] self.mode = kwargs['mode'] # General g, s, or a transformation self.Ga = ga self.coords = ga.lt_coords self.X = ga.lt_x self.spinor = False self.rho_sq = None self.lt_dict = {} self.mv_dict = None if isinstance(mat_rep, tuple): # tuple input for key in mat_rep: self.lt_dict[key] = mat_rep[key] elif isinstance(mat_rep, dict): # Dictionary input for key in mat_rep: self.lt_dict[key] = mat_rep[key] elif isinstance(mat_rep, list): # List of lists input if not isinstance(mat_rep[0], list): for (lt_i, base) in zip(mat_rep, self.Ga.basis): self.lt_dict[base] = lt_i else: mat_rep = map(list, zip(*mat_rep)) # Transpose list of lists for (row, base1) in zip(mat_rep, self.Ga.basis): tmp = 0 for (col, base2) in zip(row, self.Ga.basis): tmp += col * base2 self.lt_dict[base1] = tmp elif isinstance(mat_rep, mv.Mv): # Spinor input self.spinor = True self.R = mat_rep self.Rrev = mat_rep.rev() self.rho_sq = self.R * self.Rrev if self.rho_sq.is_scalar(): self.rho_sq = self.rho_sq.scalar() if self.rho_sq == S(1): self.rho_sq = None else: raise ValueError('In Spinor input for Lt, S*S.rev() not a scalar!\n') elif isinstance(mat_rep, str): # String input root = mat_rep mat_rep = [] for row in self.Ga.coords: # First set up general transformation row_str = '' for col in self.Ga.coords: row_str += root + '_' + str(row) + str(col) + ',' if self.fct_flg: fct_names = row_str[:-1].split(',') mat_rep.append([Function(fct_name)(*self.Ga.coords) for fct_name in fct_names]) else: mat_rep.append(list(symbols(row_str[:-1]))) if self.mode == 'g': pass elif self.mode == 's': # Symmetric linear transformation n_range = range(len(mat_rep)) for i in n_range: for j in n_range: if i > j: mat_rep[i][j] = mat_rep[j][i] elif self.mode == 'a': # Antisymmetric linear transformation n_range = range(len(mat_rep)) for i in n_range: mat_rep[i][i] = S(0) for i in n_range: for j in n_range: if i > j: mat_rep[j][i] = -mat_rep[i][j] else: raise ValueError(str(self.mode) + ' not allowed in constructing lt.\n') self.__init__(mat_rep, ga=self.Ga) else: # Linear multivector function input # F is a multivector function to be tested for linearity F = mat_rep a = mv.Mv('a', 'vector', ga=self.Ga) b = mv.Mv('b', 'vector', ga=self.Ga) if F(a + b) == F(a) + F(b): self.lt_dict = {} for base in self.Ga.basis: r = F(mv.Mv(base, ga=self.Ga)) self.lt_dict[base] = r.obj if not r.is_vector(): raise ValueError(str(mat_rep) + ' is not supported for Lt definition\n') else: raise ValueError(str(mat_rep) + ' is not supported for Lt definition\n')
def __init__(self, *kargs, **kwargs): """ Except for the spinor representation the linear transformation is stored as a dictionary with basis vector keys and vector values self.lt_dict so that a is a vector a = a^{i}e_{i} then self(a) = a^{i} * self.lt_dict[e_{i}]. For the spinor representation the linear transformation is stored as the even multivector self.R so that if a is a vector self(a) = self.R * a * self.R.rev(). For the general representation of a linear transformation the linear transformation is represented as a dictionary self.lt_dict where the keys are the basis symbols, {e_i}, and the dictionary entries are the object vector images (linear combination of sympy non-commutative basis symbols) of the keys so that if L is the linear transformation then L(e_i) = self.Ga.mv(L.lt_dict[e_i]) """ kwargs = metric.test_init_slots(Lt.init_slots, **kwargs) mat_rep = kargs[0] ga = kwargs['ga'] self.fct_flg = kwargs['f'] self.mode = kwargs['mode'] # General g, s, or a transformation self.Ga = ga self.coords = ga.lt_coords self.X = ga.lt_x self.spinor = False self.rho_sq = None self.lt_dict = {} self.mv_dict = None self.mat = None self.Ga.inverse_metric( ) # g^{-1} needed for standard matrix representation if isinstance(mat_rep, tuple): # tuple input for key in mat_rep: self.lt_dict[key] = mat_rep[key] elif isinstance(mat_rep, dict): # Dictionary input for key in mat_rep: self.lt_dict[key] = mat_rep[key] elif isinstance(mat_rep, list): # List of lists input if not isinstance(mat_rep[0], list): for (lt_i, base) in zip(mat_rep, self.Ga.basis): self.lt_dict[base] = lt_i else: #mat_rep = map(list, zip(*mat_rep)) # Transpose list of lists for (row, base1) in zip(mat_rep, self.Ga.basis): tmp = 0 for (col, base2) in zip(row, self.Ga.basis): tmp += col * base2 self.lt_dict[base1] = tmp elif isinstance(mat_rep, Matrix): # Matrix input self.mat = mat_rep mat_rep = self.mat * self.Ga.g_inv self.lt_dict = Matrix_to_dictionary(mat_rep, self.Ga.basis) elif isinstance(mat_rep, mv.Mv): # Spinor input self.spinor = True self.R = mat_rep self.Rrev = mat_rep.rev() self.rho_sq = self.R * self.Rrev if self.rho_sq.is_scalar(): self.rho_sq = self.rho_sq.scalar() if self.rho_sq == S(1): self.rho_sq = None else: raise ValueError( 'In Spinor input for Lt, S*S.rev() not a scalar!\n') elif isinstance(mat_rep, str): # String input Amat = Symbolic_Matrix(mat_rep, coords=self.Ga.coords, mode=self.mode, f=self.fct_flg) self.__init__(Amat, ga=self.Ga) else: # Linear multivector function input # F is a multivector function to be tested for linearity F = mat_rep a = mv.Mv('a', 'vector', ga=self.Ga) b = mv.Mv('b', 'vector', ga=self.Ga) if F(a + b) == F(a) + F(b): self.lt_dict = {} for base in self.Ga.basis: self.lt_dict[base] = (F(mv.Mv(base, ga=self.Ga))).obj if not self.lt_dict[base].is_vector(): raise ValueError( str(mat_rep) + ' is not supported for Lt definition\n') else: raise ValueError( str(mat_rep) + ' is not supported for Lt definition\n')
def __init__(self, *kargs, **kwargs): """ Except for the spinor representation the linear transformation is stored as a dictionary with basis vector keys and vector values self.lt_dict so that a is a vector a = a^{i}e_{i} then self(a) = a^{i} * self.lt_dict[e_{i}]. For the spinor representation the linear transformation is stored as the even multivector self.R so that if a is a vector self(a) = self.R * a * self.R.rev(). For the general representation of a linear transformation the linear transformation is represented as a dictionary self.lt_dict where the keys are the basis symbols, {e_i}, and the dictionary entries are the object vector images (linear combination of sympy non-commutative basis symbols) of the keys so that if L is the linear transformation then L(e_i) = self.Ga.mv(L.lt_dict[e_i]) """ kwargs = metric.test_init_slots(Lt.init_slots, **kwargs) mat_rep = kargs[0] ga = kwargs['ga'] self.fct_flg = kwargs['f'] self.mode = kwargs['mode'] # General g, s, or a transformation self.Ga = ga self.coords = ga.lt_coords self.X = ga.lt_x self.spinor = False self.rho_sq = None self.lt_dict = {} self.mv_dict = None self.mat = None self.Ga.inverse_metric() # g^{-1} needed for standard matrix representation if isinstance(mat_rep, tuple): # tuple input for key in mat_rep: self.lt_dict[key] = mat_rep[key] elif isinstance(mat_rep, dict): # Dictionary input for key in mat_rep: self.lt_dict[key] = mat_rep[key] elif isinstance(mat_rep, list): # List of lists input if not isinstance(mat_rep[0], list): for (lt_i, base) in zip(mat_rep, self.Ga.basis): self.lt_dict[base] = lt_i else: #mat_rep = map(list, zip(*mat_rep)) # Transpose list of lists for (row, base1) in zip(mat_rep, self.Ga.basis): tmp = 0 for (col, base2) in zip(row, self.Ga.basis): tmp += col * base2 self.lt_dict[base1] = tmp elif isinstance(mat_rep, Matrix): # Matrix input self.mat = mat_rep mat_rep = self.mat * self.Ga.g_inv self.lt_dict = Matrix_to_dictionary(mat_rep, self.Ga.basis) elif isinstance(mat_rep, mv.Mv): # Spinor input self.spinor = True self.R = mat_rep self.Rrev = mat_rep.rev() self.rho_sq = self.R * self.Rrev if self.rho_sq.is_scalar(): self.rho_sq = self.rho_sq.scalar() if self.rho_sq == S(1): self.rho_sq = None else: raise ValueError('In Spinor input for Lt, S*S.rev() not a scalar!\n') elif isinstance(mat_rep, str): # String input Amat = Symbolic_Matrix(mat_rep, coords=self.Ga.coords,mode=self.mode,f=self.fct_flg) self.__init__(Amat, ga=self.Ga) else: # Linear multivector function input # F is a multivector function to be tested for linearity F = mat_rep a = mv.Mv('a', 'vector', ga=self.Ga) b = mv.Mv('b', 'vector', ga=self.Ga) if F(a + b) == F(a) + F(b): self.lt_dict = {} for base in self.Ga.basis: self.lt_dict[base] = (F(mv.Mv(base, ga=self.Ga))).obj if not self.lt_dict[base].is_vector(): raise ValueError(str(mat_rep) + ' is not supported for Lt definition\n') else: raise ValueError(str(mat_rep) + ' is not supported for Lt definition\n')