Esempio n. 1
0
 def cups(left, right):
     if not isinstance(left, Dim):
         raise TypeError(messages.type_err(Dim, left))
     if not isinstance(right, Dim):
         raise TypeError(messages.type_err(Dim, right))
     if left.r != right:
         raise AxiomError(messages.are_not_adjoints(left, right))
     return Tensor(left @ right, Dim(1), Id(left).array)
Esempio n. 2
0
 def __init__(self, x, y):
     if not isinstance(x, Ty):
         raise TypeError(messages.type_err(Ty, x))
     if not isinstance(y, Ty):
         raise TypeError(messages.type_err(Ty, y))
     if x != y.r and x.r != y:
         raise AxiomError(messages.are_not_adjoints(x, y))
     if len(x) != 1 or len(y) != 1:
         raise ValueError(messages.cap_vs_caps(x, y))
     if x.r == y:
         raise NotImplementedError(messages.pivotal_not_implemented())
     super().__init__('CAP', Ty(), x @ y)
Esempio n. 3
0
 def __init__(self, left, right):
     if not isinstance(left, Ty):
         raise TypeError(messages.type_err(Ty, left))
     if not isinstance(right, Ty):
         raise TypeError(messages.type_err(Ty, right))
     if len(left) != 1 or len(right) != 1:
         raise ValueError(messages.cap_vs_caps(left, right))
     if left != right.r and left.r != right:
         raise AxiomError(messages.are_not_adjoints(left, right))
     self.left, self.right = left, right
     super().__init__("Cap({}, {})".format(left, right), Ty(), left @ right)
     self.draw_as_wires = True
Esempio n. 4
0
 def __init__(self, left, right):
     if not isinstance(left, Ty):
         raise TypeError(messages.type_err(Ty, left))
     if not isinstance(right, Ty):
         raise TypeError(messages.type_err(Ty, right))
     if len(left) != 1 or len(right) != 1:
         raise ValueError(messages.cup_vs_cups(left, right))
     if left.r != right and left != right.r:
         raise AxiomError(messages.are_not_adjoints(left, right))
     if left == right.r:
         raise AxiomError(messages.wrong_adjunction(left, right, cup=True))
     self.left, self.right, self.draw_as_wire = left, right, True
     super().__init__("Cup({}, {})".format(left, right), left @ right, Ty())
Esempio n. 5
0
 def __init__(self, left, right):
     if not isinstance(left, Ty):
         raise TypeError(messages.type_err(Ty, left))
     if not isinstance(right, Ty):
         raise TypeError(messages.type_err(Ty, right))
     if len(left) != 1 or len(right) != 1:
         raise ValueError(messages.cap_vs_caps(left, right))
     if left != right.r and left.r != right:
         raise AxiomError(messages.are_not_adjoints(left, right))
     monoidal.BinaryBoxConstructor.__init__(self, left, right)
     Box.__init__(
         self, "Cap({}, {})".format(left, right), Ty(), left @ right)
     self.draw_as_wires = True
Esempio n. 6
0
def cups(left, right, ar_factory=Diagram, cup_factory=Cup, reverse=False):
    """ Constructs a diagram of nested cups. """
    for typ in left, right:
        if not isinstance(typ, Ty):
            raise TypeError(messages.type_err(Ty, typ))
    if left.r != right and right.r != left:
        raise AxiomError(messages.are_not_adjoints(left, right))
    result = ar_factory.id(left @ right)
    for i in range(len(left)):
        j = len(left) - i - 1
        cup = cup_factory(left[j:j + 1], right[i:i + 1])
        layer = ar_factory.id(left[:j]) @ cup @ ar_factory.id(right[i + 1:])
        result = result << layer if reverse else result >> layer
    return result
Esempio n. 7
0
 def ba(left, right):
     """ Backward application. """
     if right.left != left:
         raise AxiomError(messages.are_not_adjoints(left, right))
     return BA(right)
Esempio n. 8
0
 def fa(left, right):
     """ Forward application. """
     if left.right != right:
         raise AxiomError(messages.are_not_adjoints(left, right))
     return FA(left)