Inconsistencies in factor_out and factor_in

+1 vote

Hi!

I have some problems with factorin and factorout . They don't quite work as i expect them to and I didn't find any posts about it.
There are three different things i would like to mention:

First, factor_out is index-sensitive, but not really consistent about it:

ex:= g_{a b} p_c + g_{a b} q_c + g_{a c} p_b + g_{a c} q_b;
factor_out(_,$g_{a b}$);


and

ex:= g_{a b} p_c + g_{a b} q_c + g_{a c} p_b + g_{a c} q_b;
factor_out(_,$g_{a c}$);


give the expected result.

On the other hand:

ex:= g_{a b} p_c + g_{a b} q_c + g_{a c} p_b + g_{a c} q_b;
factor_out(_,$g_{b c}$);


factors out the g{a c}, but not the g{a b}.

Second, factorout and factorin do not work anymore, if the prefactors are too "complicated":

 ex2:= (a + b - c) d + (-a -b + c) d
factor_out(_,$d$);
factor_out(_,$a + b - c$);
factor_in(_,$d$);


all do nothing here. Of course I could just use "distribute" here, but i get complicated expressions, where I need to factor in $a,b,c$ first and only then can think about further simplifications.

Third, factor_out does not work, if products of tensors are used:

ex3:= g_{a b} g_{c d} p + g_{a b} g_{c d}  q;

factor_out(_,$g_{a b}$);
factor_out(_,$g_{a b}g_{c d}$);
factor_out(_,$g_{a b},g_{c d}$);


do not simplify the expression.

factor_in(_,$q,p$);


works just fine, but p and q themselves can take complicated forms and it's tedious to write them out in factor_in. Also, as mentioned before, this does not simplify the expressions anyway.

Thanks for working on the project, it is exactly what I was looking for and really like the "do it step by step" philosophy!

Let me first address the case which does work with the current version (at least for me):

ex2:= (a + b - c) d + (-a -b + c) d
factor_out(_,$d$);


correctly factors out $d$. Factoring out composite expressions (like the $a+b-c$) is currently not supported, unfortunately.

All the other cases have to do with factoring out tensors. In general, for that to work, you need to have the indices on the expression you want to factor out be the same on all terms (so sort the expression and rename_dummies first), and it needs to be un-ambiguous (your last example isn't, because the factor_out(_, $g_{a b}$) means 'factor out the g-tensor with two indices', not 'factor out the g-tensor with one index 'a' and one 'b'').

Fixing this has been on the TODO list for some time, but there are only 25 hours in each day unfortunately.

I'm propably not on latest version concerning the factoring out of $d$.