def doit(self): args, indices, free, dum = TensMul._tensMul_contract_indices(self.args) obj = self.func(*args) obj._indices = indices obj._free = free obj._dum = dum return obj
def _contract_indices_for_derivative(cls, expr, variables): variables_opposite_valence = [] for i in variables: i_free_indices = i.get_free_indices() variables_opposite_valence.append( i.xreplace({k: -k for k in i_free_indices})) args, indices, free, dum = TensMul._tensMul_contract_indices( [expr] + variables_opposite_valence, replace_indices=True) for i in range(1, len(args)): i_indices = args[i].get_free_indices() args[i] = args[i].xreplace({k: -k for k in i_indices}) return args, indices, free, dum
def __new__(cls, expr, *variables): # Flatten: if isinstance(expr, PartialDerivative): variables = expr.variables + variables expr = expr.expr # TODO: check that all variables have rank 1. args, indices, free, dum = TensMul._tensMul_contract_indices( [expr] + list(variables), replace_indices=True) obj = TensExpr.__new__(cls, *args) obj._indices = indices obj._free = free obj._dum = dum return obj
def __new__(cls, expr, *variables): # Flatten: if isinstance(expr, PartialDerivative): variables = expr.variables + variables expr = expr.expr # TODO: check that all variables have rank 1. args, indices, free, dum = TensMul._tensMul_contract_indices([expr] + list(variables), replace_indices=True) obj = TensExpr.__new__(cls, *args) obj._indices = indices obj._free = free obj._dum = dum return obj