# The Young tableau
#
#   i k
#   j
# 
# is defined by:
#
def test01():
    __cdbkernel__=create_scope()
    obj1:= b*a^{i j k};
    sym(_, $^{i},^{k} $)
    # FIXME: if you put a space in front of the ^ operator, it turns into a wedge, and asym fails.
    asym(_, $^{i},^{j} $)
    tst1:= b/4*( a^{i j k} + a^{k j i} - a^{j i k} - a^{k i j} ) - @(obj1);
    distribute(_)
    assert(tst1==0)
    print('Test 01 passed')

test01()

# It is possible to (anti)symmetrise modulo implicit
# (anti)symmetrisations:
#
# obj2:= A_{m n p} B_{q r s};
# @asym!(%){_{m},_{n},_{q}}{0,1};
# tst2:= 1/3 * A_{m n p} * B_{q r s}
#     - 1/3 * A_{m q p} * B_{n r s}
#     + 1/3 * A_{q m p} * B_{n r s} - @(obj2);
# @collect_terms!(%);
# @assert(tst2);

# Symmetrising in sets:

def test03():
    __cdbkernel__=create_scope()
    obj3:= A_{i k l m}*q;
    asym(_, $ {_{i},_{k}}, {_{l},_{m}} } $)
    tst3:= (1/2) * A_{i k l m}*q - (1/2) * A_{l m i k}*q - @(obj3);
    assert(tst3==0)
    print('Test 03 passed')

test03()

def test04():
    __cdbkernel__=create_scope()
    R_{a b c d}::WeylTensor.
    obj4:= R_{r1 r2 r3 r4}*q;
    asym(_, $ _{r1}, _{r2} $)
    asym(_, $ _{r3}, _{r4} $)
    sym(_,  $ {_{r1},_{r2}}, {_{r3},_{r4}} $)
    tst4:= R_{r1 r2 r3 r4}*q - @(obj4);
    indexsort(_)
    assert(tst4==0)
    print('Test 04 passed')

test04()

def test05():
    __cdbkernel__=create_scope()
    R_{a b c d}::WeylTensor.
    obj5:= R_{r1 r2 r4 r3}*q;
    asym(_, $ {_{r1},_{r2}}, {_{r3},_{r4}} $)
    tst5:= (1/2) * R_{r1 r2 r4 r3}*q - (1/2) * R_{r4 r3 r1 r2}*q - @(obj5);
    assert(tst5==0)
    print('Test 05 passed')

test05()

# Generating subsets of permutations, in order to split up
# very large ones (no longer possible in v2)
#
# obj6:= q*A_{a b c d};
# @sym!(%){_{a},_{b},_{c},_{d}}{Start:>2}{End:>4};
# tst6:= q/24 A_{a c b d} + q/24 A_{a c d b} - @(obj6);
# @collect_terms!(%);
# @assert(tst6);


# Test 8: sym/asym on whole tensors, with different index lengths

def test08():
    __cdbkernel__=create_scope()
    obj8:=A_{a b} B_{c};
    sym(_, $ A_{a b}, B_{c} $)
    tst8:=1/2 A_{a b} B_{c} + 1/2 B_{c} A_{a b} - @(obj8);
    assert(tst8==0)
    print('Test 08 passed')
		
test08()	 

def test09():
    __cdbkernel__=create_scope()
    ex:= 1/2 A_{a b} B_{c d};
    slot_asym(ex, [1,2], deep=False)
    tst:= 1/4 A_{a b} B_{c d} - 1/4 A_{a c} B_{b d} - @(ex);
    assert(tst==0)
    print("Test 09 passed")

test09()
