示例#1
0
    def test_mul(self):
        x1, x2, x3 = xx = st.symb_vector('x1:4', commutative=False)

        s = sp.Symbol('s', commutative=False)
        C = sp.Symbol('C', commutative=False)

        Q = sp.Matrix([[x3 / sin(x1), 1, 0], [-tan(x1), 0, x3]])

        W = pc.VectorDifferentialForm(1, xx, coeff=Q)

        W1 = s * W

        W2 = W * C

        self.assertEqual(W1.coeff, nct.nc_mul(s, W.coeff))
        self.assertNotEqual(W1.coeff, nct.nc_mul(W.coeff, s))

        self.assertEqual(W2.coeff, nct.nc_mul(W.coeff, C))
        self.assertNotEqual(W2.coeff, nct.nc_mul(C, W.coeff))

        alpha = pc.DifferentialForm(1, xx)
        with self.assertRaises(TypeError) as cm:
            alpha * W1
        with self.assertRaises(TypeError) as cm:
            W1 * alpha

        M = sp.eye(2)
        with self.assertRaises(sp.SympifyError) as cm:
            M * W1
        with self.assertRaises(TypeError) as cm:
            W1 * M
示例#2
0
    def test_unimod_inv3(self):
        y1, y2 = yy = st.symb_vector('y1, y2', commutative=False)
        s = sp.Symbol('s', commutative=False)
        ydot1, ydot2 = yyd1 = st.time_deriv(yy, yy, order=1, commutative=False)
        yddot1, yddot2 = yyd2 = st.time_deriv(yy,
                                              yy,
                                              order=2,
                                              commutative=False)
        yyd3 = st.time_deriv(yy, yy, order=3, commutative=False)
        yyd4 = st.time_deriv(yy, yy, order=4, commutative=False)
        yya = st.row_stack(yy, yyd1, yyd2, yyd3, yyd4)

        M3 = sp.Matrix([[ydot2, y1 * s],
                        [
                            y2 * yddot2 + y2 * ydot2 * s, y1 * yddot2 +
                            y2 * y1 * s**2 + y2 * ydot1 * s + ydot2 * ydot1
                        ]])

        M3inv = nct.unimod_inv(M3, s, time_dep_symbs=yya)

        product3a = nct.right_shift_all(nct.nc_mul(M3, M3inv),
                                        s,
                                        func_symbols=yya)
        product3b = nct.right_shift_all(nct.nc_mul(M3inv, M3),
                                        s,
                                        func_symbols=yya)
        res3a = nct.make_all_symbols_commutative(product3a)[0]
        res3b = nct.make_all_symbols_commutative(product3b)[0]
        res3a.simplify()
        res3b.simplify()

        self.assertEqual(res3a, sp.eye(2))
        self.assertEqual(res3b, sp.eye(2))
示例#3
0
    def test_unimod_inv(self):
        y1, y2 = yy = st.symb_vector('y1, y2', commutative=False)
        s = sp.Symbol('s', commutative=False)
        ydot1, ydot2 = yyd1 = st.time_deriv(yy, yy, order=1, commutative=False)
        yddot1, yddot2 = yyd2 = st.time_deriv(yy,
                                              yy,
                                              order=2,
                                              commutative=False)
        yyd3 = st.time_deriv(yy, yy, order=3, commutative=False)
        yyd4 = st.time_deriv(yy, yy, order=4, commutative=False)
        yya = st.row_stack(yy, yyd1, yyd2, yyd3, yyd4)

        M1 = sp.Matrix([yy[0]])
        M1inv = nct.unimod_inv(M1, s, time_dep_symbs=yy)
        self.assertEqual(M1inv, M1.inv())

        M2 = sp.Matrix([[y1, y1 * s], [0, y2]])
        M2inv = nct.unimod_inv(M2, s, time_dep_symbs=yy)

        product2a = nct.right_shift_all(nct.nc_mul(M2, M2inv),
                                        s,
                                        func_symbols=yya)
        product2b = nct.right_shift_all(nct.nc_mul(M2inv, M2),
                                        s,
                                        func_symbols=yya)

        res2a = nct.make_all_symbols_commutative(product2a)[0]
        res2b = nct.make_all_symbols_commutative(product2b)[0]
        self.assertEqual(res2a, sp.eye(2))
        self.assertEqual(res2b, sp.eye(2))
示例#4
0
    def test_nc_multiplication(self):
        a, b = sp.symbols("a, b", commutative=False)
        E = sp.eye(2)

        Mb = b*E
        Mab = a*b*E

        res = nct.nc_mul(a, Mb) - Mab
        self.assertEqual(res, 0*E)

        res2 = nct.nc_mul(a*E, b*E)
        self.assertEqual(res2, Mab)

        res3 = nct.nc_mul(Mb, Mab)
        self.assertEqual(res3, b*a*b*E)
示例#5
0
    def test_right_shift_all2(self):
        a, b = sp.symbols("a, b", commutative=False)

        ab = sp.Matrix([a, b])
        adot, bdot = ab_dot = st.time_deriv(ab, ab)

        sab = sp.Matrix([s*a, s*b])

        res1 = nct.right_shift_all(sab, func_symbols=ab)
        res2 = ab_dot + nct.nc_mul(ab, s)

        self.assertEqual(res1, res2)

        res = nct.right_shift_all(s, s, t)
        self.assertEqual(res, s)

        res = nct.right_shift_all(s**2, s, t)
        self.assertEqual(res, s**2)

        res = nct.right_shift_all(a, s, t)
        self.assertEqual(res, a)

        res = nct.right_shift_all(a**(sp.S(1)/2), s, t)
        self.assertEqual(res, a**(sp.S(1)/2))

        res = nct.right_shift_all(s*1/a, s, func_symbols=ab)
        self.assertEqual(res, 1/a*s -1/a**2*adot)

        res = nct.right_shift_all(s + sp.sin(a), s, func_symbols=ab)
        self.assertEqual(res, s + sp.sin(a))

        self.assertRaises( ValueError, nct.right_shift_all, s**(sp.S(1)/2), s, t)

        self.assertRaises( ValueError, nct.right_shift_all, sp.sin(s), s, t)
示例#6
0
    def calculate_P_Matrix(self):
        """ specifies system with P(d/dt) = P00 + P10*s
        """
        P10 = self._myStack.get_iteration(0).P1
        P00 = self._myStack.get_iteration(0).P0

        P10_nc = self.make_symbols_non_commutative(P10)
        P00_nc = self.make_symbols_non_commutative(P00)

        self.P = P00_nc + nct.nc_mul(P10_nc, s)
        return self.P
示例#7
0
文件: core.py 项目: cknoll/pycartan
    def __rmul__(self, a):
        if not st.is_scalar(a):
            msg = "Reverse multiplication of %s and %s not (currently) not allowed. " \
                  "Maybe use .left_mul_by(...)."
            msg = msg % (type(self), type(a))
            raise TypeError(msg)

        new_vector_form = VectorDifferentialForm(self.degree, self.basis)
        new_vector_form.coeff = nct.nc_mul(a, self.coeff)

        return new_vector_form
示例#8
0
    def calculate_P_Matrix(self):
        """ specifies system with P(d/dt) = P00 + P10*s
        """
        P10 = self._myStack.get_iteration(0).P1
        P00 = self._myStack.get_iteration(0).P0

        P10_nc = self.make_symbols_non_commutative(P10)
        P00_nc = self.make_symbols_non_commutative(P00)

        self.P = P00_nc + nct.nc_mul(P10_nc, s)
        return self.P
示例#9
0
    def test_nc_multiplication(self):
        a, b = sp.symbols("a, b", commutative=False)
        E = sp.eye(2)

        Mb = b * E
        Mab = a * b * E

        res = nct.nc_mul(a, Mb) - Mab
        self.assertEqual(res, 0 * E)

        res2 = nct.nc_mul(a * E, b * E)
        self.assertEqual(res2, Mab)

        res3 = nct.nc_mul(Mb, Mab)
        self.assertEqual(res3, b * a * b * E)

        # this was a bug 2019-02-08 10:18:36
        Mb2 = sp.ImmutableDenseMatrix(Mb)
        self.assertEqual(nct.nc_mul(a, Mb2), Mb * a)
        self.assertEqual(nct.nc_mul(Mb2, a), a * Mb)
        self.assertFalse(Mb * a == a * Mb)
示例#10
0
    def test_unimod_inv3(self):
        y1, y2 = yy = st.symb_vector('y1, y2', commutative=False)
        s = sp.Symbol('s', commutative=False)
        ydot1, ydot2 = yyd1 = st.time_deriv(yy, yy, order=1, commutative=False)
        yddot1, yddot2 = yyd2 = st.time_deriv(yy, yy, order=2, commutative=False)
        yyd3 = st.time_deriv(yy, yy, order=3, commutative=False)
        yyd4 = st.time_deriv(yy, yy, order=4, commutative=False)
        yya = st.row_stack(yy, yyd1, yyd2, yyd3, yyd4)

        M3 = sp.Matrix([[ydot2,                                              y1*s],
                       [y2*yddot2 + y2*ydot2*s, y1*yddot2 + y2*y1*s**2 + y2*ydot1*s + ydot2*ydot1]])

        M3inv = nct.unimod_inv(M3, s, time_dep_symbs=yya)

        product3a = nct.right_shift_all( nct.nc_mul(M3, M3inv), s, func_symbols=yya)
        product3b = nct.right_shift_all( nct.nc_mul(M3inv, M3), s, func_symbols=yya)
        res3a = nct.make_all_symbols_commutative(product3a)[0]
        res3b = nct.make_all_symbols_commutative(product3b)[0]
        res3a.simplify()
        res3b.simplify()

        self.assertEqual(res3a, sp.eye(2))
        self.assertEqual(res3b, sp.eye(2))
示例#11
0
    def test_unimod_inv(self):
        y1, y2 = yy = st.symb_vector('y1, y2', commutative=False)
        s = sp.Symbol('s', commutative=False)
        ydot1, ydot2 = yyd1 = st.time_deriv(yy, yy, order=1, commutative=False)
        yddot1, yddot2 = yyd2 = st.time_deriv(yy, yy, order=2, commutative=False)
        yyd3 = st.time_deriv(yy, yy, order=3, commutative=False)
        yyd4 = st.time_deriv(yy, yy, order=4, commutative=False)
        yya = st.row_stack(yy, yyd1, yyd2, yyd3, yyd4)

        M1 = sp.Matrix([yy[0]])
        M1inv = nct.unimod_inv(M1, s, time_dep_symbs=yy)
        self.assertEqual(M1inv, M1.inv())

        M2 = sp.Matrix([[y1, y1*s], [0, y2]])
        M2inv = nct.unimod_inv(M2, s, time_dep_symbs=yy)

        product2a = nct.right_shift_all( nct.nc_mul(M2, M2inv), s, func_symbols=yya)
        product2b = nct.right_shift_all( nct.nc_mul(M2inv, M2), s, func_symbols=yya)

        res2a = nct.make_all_symbols_commutative( product2a)[0]
        res2b = nct.make_all_symbols_commutative( product2b)[0]
        self.assertEqual(res2a, sp.eye(2))
        self.assertEqual(res2b, sp.eye(2))
示例#12
0
    def test_unimod_inv4(self):
        path = make_abspath('test_data', 'unimod_matrix_unicycle.pcl')
        with open(path, 'rb') as pfile:
            pdict = pickle.load(pfile)

        PQ = pdict['PQ']
        s = [ symb for symb in PQ.s if str(symb) == "s"][0]
        self.assertTrue(s in PQ.s)

        abc = pdict['abc']
        #kk = pdict['kk']
        #JEh = pdict['JEh']

        inv = nct.unimod_inv(PQ, s, None, abc, max_deg=2)
        res = nct.nc_mul(inv, PQ)
        res2 = nct.right_shift_all(res, s, None, abc)
        res3, tmp = nct.make_all_symbols_commutative(res2)
        res4 = st.subs_random_numbers(res3, prime=True)
        self.assertEqual(res4, sp.eye(3))