def test_conjugate(self):
        m = Matrx([
            Vector([Cartesian((-6, 1)), Cartesian((3, 8))]),
            Vector([Cartesian((2, -6)), Cartesian((3, 0))])
        ])
        mC = Matrx([
            Vector([Cartesian((-6, -1)),
                    Cartesian((3, -8))]),
            Vector([Cartesian((2, 6)), Cartesian((3, 0))])
        ])

        self.assertEqual(m.conjugate(), mC)
    def test_addInverse(self):
        m = Matrx([
            Vector([Cartesian((7, 3)), Cartesian((-1, 7))]),
            Vector([Cartesian((-9, -4)),
                    Cartesian((-7, -9))])
        ])
        mAI = Matrx([
            Vector([Cartesian((-7, -3)),
                    Cartesian((1, -7))]),
            Vector([Cartesian((9, 4)), Cartesian((7, 9))])
        ])

        self.assertEqual(m.addInverse(), mAI)
    def test_scalarProd(self):
        c = Cartesian((-2, 3))
        m = Matrx([
            Vector([Cartesian((3, -2)), Cartesian((8, -4))]),
            Vector([Cartesian((4, -10)),
                    Cartesian((-2, -8))])
        ])
        cm = Matrx([
            Vector([Cartesian((0, 13)),
                    Cartesian((-4, 32))]),
            Vector([Cartesian((22, 32)),
                    Cartesian((28, 10))])
        ])

        self.assertEqual(m.scalarProd(c), cm)
Ejemplo n.º 4
0
def to_Matrix(m):
    M = []
    for i in range(len(m)):
        temp = []
        for j in range(len(m)):
            temp.append( Cartesian(tuple(m[i][j])) )
        M.append( Vector(temp) )
    return Matrx(M)
    def test_mul(self):
        a = Matrx([
            Vector([Cartesian((-6, 2)),
                    Cartesian((0, 6)),
                    Cartesian((7, 2))]),
            Vector([Cartesian((6, 9)),
                    Cartesian((7, 7)),
                    Cartesian((-6, -6))]),
            Vector([Cartesian((5, 8)),
                    Cartesian((-6, 8)),
                    Cartesian((6, 9))])
        ])
        b = Matrx([
            Vector(
                [Cartesian((9, -6)),
                 Cartesian((-3, -4)),
                 Cartesian((5, -2))]),
            Vector(
                [Cartesian((3, 6)),
                 Cartesian((-1, -5)),
                 Cartesian((0, -5))]),
            Vector(
                [Cartesian((9, 9)),
                 Cartesian((8, -4)),
                 Cartesian((-8, -4))])
        ])
        c = Matrx([
            Vector([
                Cartesian((-33, 153)),
                Cartesian((120, 0)),
                Cartesian((-44, -22))
            ]),
            Vector([
                Cartesian((87, 0)),
                Cartesian((-26, -117)),
                Cartesian((107, 70))
            ]),
            Vector([
                Cartesian((0, 165)),
                Cartesian((147, 26)),
                Cartesian((69, -36))
            ])
        ])

        self.assertEqual(a * b, c)
    def test_dagger(self):
        m = Matrx([
            Vector([Cartesian((7, 7)),
                    Cartesian((3, 8)),
                    Cartesian((8, 4))]),
            Vector(
                [Cartesian((5, 0)),
                 Cartesian((8, -6)),
                 Cartesian((-10, -1))])
        ])
        mD = Matrx([
            Vector([Cartesian((7, -7)), Cartesian((5, 0))]),
            Vector([Cartesian((3, -8)), Cartesian((8, 6))]),
            Vector([Cartesian((8, -4)),
                    Cartesian((-10, 1))])
        ])

        self.assertEqual(m.dagger(), mD)
    def test_add(self):
        m1 = Matrx([
            Vector(
                [Cartesian((-8, -3)),
                 Cartesian((-6, -4)),
                 Cartesian((0, -4))]),
            Vector(
                [Cartesian((-1, 8)),
                 Cartesian((6, -10)),
                 Cartesian((8, -5))]),
            Vector([Cartesian((4, 0)),
                    Cartesian((8, 5)),
                    Cartesian((-7, -9))])
        ])
        m2 = Matrx([
            Vector(
                [Cartesian((-7, -2)),
                 Cartesian((-4, -2)),
                 Cartesian((7, 7))]),
            Vector([Cartesian((5, 9)),
                    Cartesian((0, 3)),
                    Cartesian((6, -5))]),
            Vector([Cartesian((1, 5)),
                    Cartesian((-6, -6)),
                    Cartesian((5, 8))])
        ])
        m3 = Matrx([
            Vector([
                Cartesian((-15, -5)),
                Cartesian((-10, -6)),
                Cartesian((7, 3))
            ]),
            Vector(
                [Cartesian((4, 17)),
                 Cartesian((6, -7)),
                 Cartesian((14, -10))]),
            Vector(
                [Cartesian((5, 5)),
                 Cartesian((2, -1)),
                 Cartesian((-2, -1))])
        ])

        self.assertEqual(m1 + m2, m3)
    def test_transposed(self):
        m = Matrx([
            Vector(
                [Cartesian((5, 9)),
                 Cartesian((-7, -5)),
                 Cartesian((-1, -4))]),
            Vector(
                [Cartesian((8, 2)),
                 Cartesian((-3, -7)),
                 Cartesian((7, -8))])
        ])
        mT = Matrx([
            Vector([Cartesian((5, 9)), Cartesian((8, 2))]),
            Vector([Cartesian((-7, -5)),
                    Cartesian((-3, -7))]),
            Vector([Cartesian((-1, -4)),
                    Cartesian((7, -8))])
        ])

        self.assertEqual(m.transposed(), mT)
    def test_isUnitary(self):
        a = Matrx([
            Vector([
                Cartesian((1 / math.sqrt(2), 0)),
                Cartesian((0, 1 / math.sqrt(2)))
            ]),
            Vector([
                Cartesian((0, 1 / math.sqrt(2))),
                Cartesian((1 / math.sqrt(2), 0))
            ])
        ])
        b = Matrx([
            Vector([Cartesian((0, 1)),
                    Cartesian((1, 0)),
                    Cartesian((0, 0))]),
            Vector([Cartesian((0, 0)),
                    Cartesian((0, 1)),
                    Cartesian((1, 0))]),
            Vector([Cartesian((1, 0)),
                    Cartesian((0, 0)),
                    Cartesian((0, 1))])
        ])

        self.assertEqual(a.isUnitary(), True)
        self.assertEqual(b.isUnitary(), False)
Ejemplo n.º 10
0
    def test_actOnVect(self):
        m = Matrx([
            Vector(
                [Cartesian((-1, 5)),
                 Cartesian((1, -7)),
                 Cartesian((-6, 3))]),
            Vector(
                [Cartesian((-3, -9)),
                 Cartesian((2, -5)),
                 Cartesian((1, -10))]),
            Vector(
                [Cartesian((-6, 5)),
                 Cartesian((6, -5)),
                 Cartesian((3, -2))])
        ])
        v = Vector([Cartesian((1, -3)), Cartesian((4, 3)), Cartesian((-3, 1))])
        mv = Vector(
            [Cartesian((54, -32)),
             Cartesian((0, 17)),
             Cartesian((41, 30))])

        self.assertEqual(m.actOnVect(v), mv)
Ejemplo n.º 11
0
    def test_isHermitian(self):
        a = Matrx([
            Vector([Cartesian((3, 0)),
                    Cartesian((2, -1)),
                    Cartesian((0, -3))]),
            Vector([Cartesian((2, 1)),
                    Cartesian((0, 0)),
                    Cartesian((1, -1))]),
            Vector([Cartesian((0, 3)),
                    Cartesian((1, 1)),
                    Cartesian((0, 0))])
        ])
        b = Matrx([
            Vector([Cartesian((1, 0)), Cartesian((3, -1))]),
            Vector([Cartesian((3, 1)), Cartesian((0, 1))])
        ])

        self.assertEqual(a.isHermitian(), True)
        self.assertEqual(b.isHermitian(), False)
m = Matrx([
    Vector([
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0))
    ]),
    Vector([
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0))
    ]),
    Vector([
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0))
    ]),
    Vector([
        Cartesian((1 / 6, 0)),
        Cartesian((1 / 3, 0)),
        Cartesian((0, 0)),
        Cartesian((1, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0))
    ]),
    Vector([
        Cartesian((1 / 6, 0)),
        Cartesian((1 / 3, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((1, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0))
    ]),
    Vector([
        Cartesian((1 / 3, 0)),
        Cartesian((1 / 3, 0)),
        Cartesian((1 / 3, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((1, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0))
    ]),
    Vector([
        Cartesian((1 / 6, 0)),
        Cartesian((0, 0)),
        Cartesian((1 / 3, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((1, 0)),
        Cartesian((0, 0))
    ]),
    Vector([
        Cartesian((1 / 6, 0)),
        Cartesian((0, 0)),
        Cartesian((1 / 3, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((0, 0)),
        Cartesian((1, 0))
    ])
])
Ejemplo n.º 13
0
import numpy as np
import matplotlib.pyplot as plt
from sys import stdin
from Matrx import *

a = 1/math.sqrt(12)
b = 1/math.sqrt(6)
c = -1/math.sqrt(12)
d = -1/math.sqrt(6)

m = Matrx([Vector([Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0))]),
           Vector([Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0))]),
           Vector([Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0))]),
           Vector([Cartesian((c, a)), Cartesian((d, b)), Cartesian((0, 0)), Cartesian((1, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0))]),
           Vector([Cartesian((c, c)), Cartesian((d, d)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((1, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0))]),
           Vector([Cartesian((0, 0)), Cartesian((d, b)), Cartesian((b, d)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((1, 0)), Cartesian((0, 0)), Cartesian((0, 0))]),
           Vector([Cartesian((c, c)), Cartesian((0, 0)), Cartesian((d, d)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((1, 0)), Cartesian((0, 0))]),
           Vector([Cartesian((c, a)), Cartesian((0, 0)), Cartesian((b, d)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((1, 0))])])

p = 1/math.sqrt(2)

v = Vector([Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((0, 0)), Cartesian((c, a)), Cartesian((c, c)), Cartesian((0, 0)), Cartesian((c, c)), Cartesian((c, a))])

clicks = 2
for i in range(clicks):
    v = m.actOnVect(v)

labels = ["Pto.0", "Pto.1", "Pto.2", "Pto.3", "Pto.4", "Pto.5", "Pto.6", "Pto.7"]
estado = [v.numbers[0].element_1,
          v.numbers[1].element_1,
          v.numbers[2].element_1,
Ejemplo n.º 14
0
    def test_tensorProduct(self):
        a = Matrx([
            Vector([Cartesian((1, 1)), Cartesian((0, 0))]),
            Vector([Cartesian((1, 0)), Cartesian((0, 1))])
        ])
        b = Matrx([
            Vector(
                [Cartesian((-1, 2)),
                 Cartesian((-2, -2)),
                 Cartesian((0, 2))]),
            Vector([Cartesian((2, 3)),
                    Cartesian((3, 1)),
                    Cartesian((2, 2))]),
            Vector([Cartesian((-2, 1)),
                    Cartesian((1, -1)),
                    Cartesian((2, 1))])
        ])
        c = Matrx([
            Vector([
                Cartesian((-3, 1)),
                Cartesian((0, -4)),
                Cartesian((-2, 2)),
                Cartesian((0, 0)),
                Cartesian((0, 0)),
                Cartesian((0, 0))
            ]),
            Vector([
                Cartesian((-1, 5)),
                Cartesian((2, 4)),
                Cartesian((0, 4)),
                Cartesian((0, 0)),
                Cartesian((0, 0)),
                Cartesian((0, 0))
            ]),
            Vector([
                Cartesian((-3, -1)),
                Cartesian((2, 0)),
                Cartesian((1, 3)),
                Cartesian((0, 0)),
                Cartesian((0, 0)),
                Cartesian((0, 0))
            ]),
            Vector([
                Cartesian((-1, 2)),
                Cartesian((-2, -2)),
                Cartesian((0, 2)),
                Cartesian((-2, -1)),
                Cartesian((2, -2)),
                Cartesian((-2, 0))
            ]),
            Vector([
                Cartesian((2, 3)),
                Cartesian((3, 1)),
                Cartesian((2, 2)),
                Cartesian((-3, 2)),
                Cartesian((-1, 3)),
                Cartesian((-2, 2))
            ]),
            Vector([
                Cartesian((-2, 1)),
                Cartesian((1, -1)),
                Cartesian((2, 1)),
                Cartesian((-1, -2)),
                Cartesian((1, 1)),
                Cartesian((-1, 2))
            ])
        ])

        self.assertEqual(a.tensorProduct(b), c)