def test_tensor_product_simp(): assert tensor_product_simp(TP(A, B)*TP(B, C)) == TP(A*B, B*C) # tests for Pow-expressions assert tensor_product_simp(TP(A, B)**x) == TP(A**x, B**x) assert tensor_product_simp(x*TP(A, B)**2) == x*TP(A**2,B**2) assert tensor_product_simp(x*(TP(A, B)**2)*TP(C,D)) == x*TP(A**2*C,B**2*D) assert tensor_product_simp(TP(A,B)-TP(C,D)**x) == TP(A,B)-TP(C**x,D**x)
def test_tensor_product_simp(): assert tensor_product_simp(TP(A, B) * TP(B, C)) == TP(A * B, B * C) # tests for Pow-expressions assert tensor_product_simp(TP(A, B)**x) == TP(A**x, B**x) assert tensor_product_simp(x * TP(A, B)**2) == x * TP(A**2, B**2) assert tensor_product_simp(x * (TP(A, B)**2) * TP(C, D)) == x * TP(A**2 * C, B**2 * D) assert tensor_product_simp(TP(A, B) - TP(C, D)**x) == TP(A, B) - TP(C**x, D**x)
def _generate_outer_prod(self, arg1, arg2): c_part1, nc_part1 = arg1.args_cnc() c_part2, nc_part2 = arg2.args_cnc() if len(nc_part1) == 0 or len(nc_part2) == 0: raise ValueError("Atleast one-pair of" " Non-commutative instance required" " for outer product.") # Muls of Tensor Products should be expanded # before this function is called if isinstance(nc_part1[0], TensorProduct) and len(nc_part1) == 1 and len(nc_part2) == 1: op = tensor_product_simp(nc_part1[0] * Dagger(nc_part2[0])) else: op = Mul(*nc_part1) * Dagger(Mul(*nc_part2)) return Mul(*c_part1) * Mul(*c_part2) * op
def _generate_outer_prod(self, arg1, arg2): c_part1, nc_part1 = arg1.args_cnc() c_part2, nc_part2 = arg2.args_cnc() if (len(nc_part1) == 0 or len(nc_part2) == 0): raise ValueError('Atleast one-pair of' ' Non-commutative instance required' ' for outer product.') # Muls of Tensor Products should be expanded # before this function is called if (isinstance(nc_part1[0], TensorProduct) and len(nc_part1) == 1 and len(nc_part2) == 1): op = tensor_product_simp(nc_part1[0] * Dagger(nc_part2[0])) else: op = Mul(*nc_part1) * Dagger(Mul(*nc_part2)) return Mul(*c_part1) * Mul(*c_part2) * op
def test_tensor_product_simp(): assert tensor_product_simp(TP(A, B) * TP(B, C)) == TP(A * B, B * C)
def test_tensor_product_simp(): assert tensor_product_simp(TP(A,B)*TP(B,C)) == TP(A*B,B*C)
def _generate_outer_prod(self, arg1, arg2): if isinstance(arg1, TensorProduct): return tensor_product_simp(arg1 * Dagger(arg2)) else: return arg1 * Dagger(arg2)