# Minus sign to index-dependent power

+1 vote

I am trying to use a replacement rule which inserts a minus sign in front of an operator depending on one of its index. However, I don't manage to do anything and I don't understand what could be the correct syntax.

For giving some context, I want to implement BPZ conjugation of operators in a 2d CFT (for string theory).

Here is my code:

bpzrl := {
\alpha_{n}^{\mu} -> - (-1)**{n} \alpha_{- n}^{\mu}
};

def bpz(ex):
distribute(ex)
substitute(ex, bpzrl)
sort_product(ex)
return ex

XX := \alpha_{1}^{\mu}.
bpz(XX);

and the output : $$- \alpha_{-1}^\mu -1^1$$

It's doing the correct thing to the expression, but the result is not written in canonical form, and because of that displays incorrectly. What it's actually showing is

- \alpha_{-1}^{\mu} { -1 }^{1}

and because the curly brackets around the -1 do not show, you get this weird looking result.

The quickest way to fix this is to add an

expand_power(ex)

inside your bpz function; that will turn (-1)^1 into (-1) which then gets absorbed into product correctly. Using simplify(ex) will also work, but is much slower and requires a roundtrip through sympy's simplify function.

It's a bug of course, I have registered it as https://github.com/kpeeters/cadabra2/issues/247.

by (65.1k points)
selected

Thanks a lot, this works perfectly!

I am discovering Cadabra and it's really amazing, thanks for creating it!