Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

Hi,

In Cadabra 2.2.0 I am having some trouble cancelling numerical factors involving powers of 1/2 and minus 1/2.

For instance, if I evaluate

$2 1/2$;

Cadabra outputs correctly 1.

However if I evaluate

$2**(1/2) 2**(-1/2)$;

Cadabra outputs in TeX \sqrt{2} 2^{-1/2} and does not combine these.

If I try to make it do so using collectfactors(), I get a "The kernel crashed unexpectedly" message. (And actually I notice this happens in Cadabra 1 too...)

Conversely, it collects_factors correctly for

$X**(1/2) X**(-1/2)$;
collect_factors(_);

Is this meant to happen? Am I missing some very basic instruction on how to treat numbers?

Thanks!

in General questions by (160 points)

1 Answer

+1 vote
 
Best answer

No, this is a bug. You'd be surprised how many computations can be done without ever encountering this one... Will fix, thanks.

by (82.5k points)
selected by

A quick workaround is to use sympy to simplify this; the following works:

$2**(1/2) 2**(-1/2)$;
simplify(_);

(you need to have the sympy package for python installed, either by installing a python3-sympy package or something similar, or by installing it through sudo pip3 install sympy or similar).

Better and somewhat more robust is

 map_sympy(_, "simplify");

Okay, wow, that is indeed surprising. Thanks for the quick reply. In the meantime I will rescale my vielbein components...

Aha even better - have installed sympy as suggested and can now use simplify, which indeed works. Thanks a lot!

...