Esempio n. 1
0
    def __new__(cls, *args, **assumptions):
        if assumptions.get('evaluate') is False:
            args = map(_sympify, args)
            obj = Expr.__new__(cls, *args, **assumptions)
            obj.is_commutative = all(arg.is_commutative for arg in args)
            return obj
        if len(args)==0:
            return cls.identity
        if len(args)==1:
            return _sympify(args[0])
        c_part, nc_part, order_symbols = cls.flatten(map(_sympify, args))
        if len(c_part) + len(nc_part) <= 1:
            if c_part:
                obj = c_part[0]
            elif nc_part:
                obj = nc_part[0]
            else:
                obj = cls.identity
        else:
            obj = Expr.__new__(cls, *(c_part + nc_part), **assumptions)
            obj.is_commutative = not nc_part

        if order_symbols is not None:
            obj = C.Order(obj, *order_symbols)
        return obj
Esempio n. 2
0
File: gate.py Progetto: rainly/sympy
 def _eval_args(cls, args):
     targets = args[0]
     if not isinstance(targets, (list, tuple, Tuple)):
         targets = (targets,)
     targets = Gate._eval_args(targets)
     _validate_targets_controls(targets)
     mat = args[1]
     if not isinstance(mat, Matrix):
         raise TypeError("Matrix expected, got: %r" % mat)
     dim = 2 ** len(targets)
     if not all([dim == shape for shape in mat.shape]):
         raise IndexError("Number of targets must match the matrix size: %r %r" % (targets, mat))
     return (targets, mat)
Esempio n. 3
0
 def _eval_args(cls, args):
     targets = args[0]
     if not isinstance(targets, (list, tuple, Tuple)):
         targets = (targets, )
     targets = Gate._eval_args(targets)
     _validate_targets_controls(targets)
     mat = args[1]
     if not isinstance(mat, Matrix):
         raise TypeError('Matrix expected, got: %r' % mat)
     dim = 2**len(targets)
     if not all([dim == shape for shape in mat.shape]):
         raise IndexError(
             'Number of targets must match the matrix size: %r %r' %\
             (targets, mat)
         )
     return (targets, mat)
Esempio n. 4
0
File: gate.py Progetto: fxkr/sympy
 def _eval_args(cls, args):
     targets = args[0]
     if not ordered_iter(targets, include=Tuple):
         targets = (targets,)
     targets = Gate._eval_args(targets)
     _validate_targets_controls(targets)
     mat = args[1]
     if not isinstance(mat, Matrix):
         raise TypeError('Matrix expected, got: %r' % mat)
     dim = 2**len(targets)
     if not all([dim == shape for shape in mat.shape]):
         raise IndexError(
             'Number of targets must match the matrix size: %r %r' %\
             (targets, mat)
         )
     return (targets, mat)
Esempio n. 5
0
 def eval_controls(self, qubit):
     """Return True/False to indicate if the controls are satisfied."""
     return all([qubit[bit] == self.control_value for bit in self.controls])
Esempio n. 6
0
File: gate.py Progetto: fxkr/sympy
 def eval_controls(self, qubit):
     """Return True/False to indicate if the controls are satisfied."""
     return all([qubit[bit]==self.control_value for bit in self.controls])
Esempio n. 7
0
 def independent(h):
     return all(not monom[0] for monom in h.monoms)
Esempio n. 8
0
 def independent(h):
     return all(not monom[0] for monom in h.monoms)