Question: what is the opposite of expand for trig function?

After doing 

A:=tan(3*x);
B:=expand(A)

How to get A back from B? I tried

combine(B);
simplify(B,size);
simplify(B,trig);
simplify(B);

They do not give A back. tried few conversions to exp() and back and forth. Can't get original expression back.  trigsubs() does not help here.

This is all need to be done in code, assuming one can not look at the expression and decide what to do on any A/B pair. But I am mainly now looking at trig expressions.

Any suggestions?

Maple 2020.2

Please Wait...