示例#1
0
def test_pi1_pi1adjoint():
    lc_1 = parse_concatenation('12-21')
    assert pi1(lc_1, 2) == lc_1

    lc_1 = parse_concatenation('12')
    assert pi1(lc_1, 2) == pi1(pi1(lc_1, 2), 2)

    lc_1 = parse_concatenation('123')
    lc.assert_almost_equal(pi1(lc_1, 3), pi1(pi1(lc_1, 3), 3))

    dim = 2
    n = 3
    for w in itertools.product(range(1, dim + 1), repeat=n):
        left = lc.lift(ShuffleWord(w))
        for v in itertools.product(range(1, dim + 1), repeat=n):
            right = lc.lift(ConcatenationWord(v))
            assert inner_product_sw_cw(left,
                                       pi1(right, n)) == inner_product_sw_cw(
                                           pi1adjoint(left, n), right)

    # pi1adjoint does _not_ depend on the realization of an element in the dual of Lie inside of T(\R^d).
    assert pi1adjoint(parse_shuffle('12'),
                      2) == pi1adjoint(parse_shuffle('[0.5] 12 - [0.5] 21'), 2)
    # For everything orthogonal on Lie, the result should be zero.
    zero = lc.LinearCombination()
    assert pi1adjoint(parse_shuffle('11'), 2) == zero
    assert pi1adjoint(parse_shuffle('22'), 2) == zero
    lc.assert_almost_equal(
        pi1adjoint(parse_shuffle('12') * parse_shuffle('21'), 4), zero)
示例#2
0
def exp(x, upto_level):
    xell = lc.lift(CompositionConcatenation())
    ret = xell
    for ell in range(upto_level + 1):
        xell = project_smaller_equal(xell * x, upto_level)
        ret += 1 / sympy.factorial(ell) * xell
    return ret
示例#3
0
 def _lie_bracket_of_expression2(expression):
     """Lie bracket of an expression like [[1],[[1],[2]]]."""
     if len(expression) == 1:
         return lc.lift(ConcatenationWord((expression[0], )))
     else:
         return lie_bracket(_lie_bracket_of_expression2(expression[0]),
                            _lie_bracket_of_expression2(expression[1]))
示例#4
0
    def lbpt(x):
        def wrap(ell):
            def q(z):
                if isinstance(z, int):
                    return (z, )
                else:
                    return wrap(z)

            return tuple(q(x) for x in ell)

        return lc.lift(LabeledBinaryPlanarTree(wrap(x)))
示例#5
0
 def finer_monomial(dp_mon):
     yield dp_mon
     lc_dp_mon = lc.lift( dp_mon )\
                      .coproduct()\
                      .apply_linear_function( lc.Tensor.fn_otimes_linear( id_, id_ ) )
     for x in lc_dp_mon.apply_linear_function(lc.Tensor.m):
         yield x
     for i in range(1, dp_mon.deg()):
         lc_dp_mon = lc_dp_mon\
                      .apply_linear_function( lc.Tensor.fn_otimes_linear( *( [CompositionConcatenation.coproduct] + [id_]*i ) ) )\
                      .apply_linear_function( lc.Tensor.fn_otimes_linear( * [id_] * (i+2)  ) )
         for x in lc_dp_mon.apply_linear_function(lc.Tensor.m):
             yield x
示例#6
0
def test_shuffle_word():
    t = lambda x, y: lc.Tensor((x, y))

    def sw(*args):
        return ShuffleWord(args)

    lc_1 = lc.lift(sw(1, 2))
    lc_2 = lc.lift(sw(3, ))
    assert lc.LinearCombination( {sw( 1,2,3 ):1, sw( 1,3,2 ):1, sw( 3,1,2 ):1} ) \
            == lc_1 * lc_2
    assert lc.LinearCombination( {t( sw(), sw(1,2) ):1, t(sw(1),sw(2)):1, t( sw(1,2), sw() ):1} ) \
            == lc_1.apply_linear_function( ShuffleWord.coproduct )

    # Condition on product vs coproduct: \Delta( \tau \tau' ) = \Delta(\tau) \Delta(\tau').
    lc_1 = lc.lift(sw(1, 2))
    lc_2 = lc.lift(sw())
    assert (lc_1 * lc_2).apply_linear_function( ShuffleWord.coproduct ) \
            == lc_1.apply_linear_function( ShuffleWord.coproduct ) \
             * lc_2.apply_linear_function( ShuffleWord.coproduct )

    lc_1 = lc.lift(sw(1, 2))
    lc_2 = lc.lift(sw(3, ))
    assert (lc_1 * lc_2).apply_linear_function( ShuffleWord.coproduct ) \
            == lc_1.apply_linear_function( ShuffleWord.coproduct ) \
             * lc_2.apply_linear_function( ShuffleWord.coproduct )

    # Condition on antipode: \Nabla (A \otimes id) \Delta = \eta \vareps.
    assert lc.LinearCombination() \
            == lc_1.apply_linear_function(ShuffleWord.coproduct)\
                .apply_linear_function( lc.Tensor.fn_otimes_linear(lc.id,ShuffleWord.antipode) )\
                .apply_linear_function( lc.Tensor.m12 )
    assert lc.lift(sw()) \
            == lc.lift(sw())\
                .apply_linear_function(ShuffleWord.coproduct)\
                .apply_linear_function( lc.Tensor.fn_otimes_linear(lc.id,ShuffleWord.antipode) )\
                .apply_linear_function( lc.Tensor.m12 )
    # Unit.
    assert lc_1 == ShuffleWord.unit() * lc_1
    # Counit.
    assert lc_1 == lc_1\
                    .apply_linear_function( ShuffleWord.coproduct )\
                    .apply_linear_function( lc.Tensor.id_otimes_fn( ShuffleWord.counit) )
示例#7
0
 def _LOG_dual_monomial(m):
     _ret = lc.LinearCombination()
     for C in finer(CompositionConcatenation((m, ))):
         _ret += sympy.Rational((-1)**(len(C) - 1), len(C)) * lc.lift(C)
     return _ret
示例#8
0
 def _EXP_dual_monomial(m):
     _ret = lc.LinearCombination()
     for C in finer(CompositionConcatenation((m, ))):
         _ret += sympy.Rational(1, sympy.factorial(len(C))) * lc.lift(C)
     return _ret
示例#9
0
def is_primitive(_x):
    e = lc.lift(CompositionConcatenation())
    return _x.apply_linear_function( CompositionConcatenation.coproduct )\
            == lc.LinearCombination.otimes(_x,e) + lc.LinearCombination.otimes(e, _x)
示例#10
0
def test_pi1():
    x = lc.lift(CompositionConcatenation((Monomial({'a': 2}), )))
    assert is_primitive(pi1(x, 2))
    assert pi1(x, 2) == pi1(pi1(x, 2), 2)
示例#11
0
def M_concat(*args):
    return reduce(operator.mul,\
            map( lambda d: lc.lift(CompositionConcatenation((Monomial(d),))), args),\
            lc.lift(CompositionConcatenation()))
示例#12
0
 def lcw(*args):
     return lc.lift(ConcatenationWord(args))
示例#13
0
def test_concatentation_word():
    def lcw(*args):
        return lc.lift(ConcatenationWord(args))

    assert lcw(1, 2, 3) + 77 * lcw(1, 9) == lc.LinearCombination.from_str(
        "123 + [77] 19", ConcatenationWord)

    t = lambda x, y: lc.Tensor((x, y))

    def cw(*args):
        return ConcatenationWord(args)

    lc_1 = lc.lift(cw(1, 2))
    lc_2 = lc.lift(cw(3))
    assert lc.LinearCombination({ConcatenationWord((1, 2, 3)):
                                 1}) == lc_1 * lc_2

    o = lc.LinearCombination.otimes(lc_1, lc_1 + 7 * lc_2)
    assert lc.LinearCombination( { t(cw(1,2,1,2), cw(1,2,1,2)):1, t(cw(1,2,1,2),cw(1,2,3)):7, t(cw(1,2,1,2),cw(3,1,2)):7, t(cw(1,2,1,2),cw(3,3)):49} )\
            == o * o

    lc_1 = lc.lift(cw(1, 2))
    lc_2 = lc.lift(cw(3, 4, 5))

    def id_otimes_coproduct(t):
        for x, c in ConcatenationWord.coproduct(t[1]):
            yield (lc.Tensor((t[0], x[0], x[1])), c)

    def coproduct_otimes_id(t):
        for x, c in ConcatenationWord.coproduct(t[0]):
            yield (lc.Tensor((x[0], x[1], t[1])), c)

    # Coassociativity.
    assert lc_1.apply_linear_function( ConcatenationWord.coproduct ).apply_linear_function( lc.Tensor.fn_otimes_linear( lc.id, ConcatenationWord.coproduct ) ) \
            == lc_1.apply_linear_function( ConcatenationWord.coproduct ).apply_linear_function( lc.Tensor.fn_otimes_linear( ConcatenationWord.coproduct, lc.id ) )
    assert lc_2.apply_linear_function( ConcatenationWord.coproduct ).apply_linear_function( lc.Tensor.fn_otimes_linear( lc.id, ConcatenationWord.coproduct ) ) \
            == lc_2.apply_linear_function( ConcatenationWord.coproduct ).apply_linear_function( lc.Tensor.fn_otimes_linear( ConcatenationWord.coproduct, lc.id ) )

    # Condition on product vs coproduct: \Delta( \tau \tau' ) = \Delta(\tau) \Delta(\tau').
    assert (lc_1 * lc_2).apply_linear_function( ConcatenationWord.coproduct ) \
            == lc_1.apply_linear_function( ConcatenationWord.coproduct ) \
             * lc_2.apply_linear_function( ConcatenationWord.coproduct )

    # Condition on antipode: \Nabla (A \otimes id) \Delta = \eta \vareps.
    assert lc.LinearCombination() \
            == lc_1.apply_linear_function(ConcatenationWord.coproduct)\
                .apply_linear_function( lc.Tensor.fn_otimes_linear(lc.id,ConcatenationWord.antipode) )\
                .apply_linear_function( lc.Tensor.m12 )
    assert lc.lift(cw()) \
            == lc.lift(cw())\
                .apply_linear_function(ConcatenationWord.coproduct)\
                .apply_linear_function( lc.Tensor.fn_otimes_linear(lc.id,ConcatenationWord.antipode) )\
                .apply_linear_function( lc.Tensor.m12 )

    # Unit.
    assert lc_1 == ConcatenationWord.unit() * lc_1
    # Counit.
    #assert lc_1 == lc_1.apply_linear_function( ConcatenationWord.coproduct )\
    #           .apply_linear_function( lc.Tensor.fn_otimes_linear( lc.id, ConcatenationWord.counit ) )\
    #           .apply_linear_function( lc.Tensor.projection(0) )
    assert lc_1 == lc_1.apply_linear_function( ConcatenationWord.coproduct )\
                       .apply_linear_function( lc.Tensor.id_otimes_fn( ConcatenationWord.counit ) )

    # The inner product is a bit awkward:
    # The natural dual of the concatenation algebra is the shuffle algebra.
    # But the method LinearCombination.inner_product only works with vectors of the exact same type.
    # Hence we need to transform one of them into the other.
    assert 1 == lc.LinearCombination.inner_product(lc_1, lc_1)

    lc_sw_1 = lc.lift(ShuffleWord((1, 2)))
    assert 0 == lc.LinearCombination.inner_product(lc_sw_1, lc_1)
    assert 1 == lc.LinearCombination.inner_product(
        lc_sw_1.apply_linear_function(shuffle_word_to_concatenation_word),
        lc_1)
示例#14
0
 def lsw(*args):
     return lc.lift(ShuffleWord(args))