# How to "reversely" replace definitions?

I have the following problem at hand.

1.) I have a list of definitions like

L[{0},z]=H[{0},z]+H[{0},zp]
L[{1},z]=H[{1},z]+H[{1},zp]
L[{0,0},z]=H[{0,0},z]+H[{0,0},zp]+H[{0},z]H[{0},zp]
...


and many more of this and similar kind. Note that there is NO common pattern.

2.) Now I have a sum of terms like

g=1/2*H[{0},z]+1/2*H[{0},zp]+...


3.) Here comes the question:

How can I tell Mathematica to replace the terms in g by the (actually long list) definitions of 1.), e.g.

g=1/2L[{0},z]+...


I want to do this in an automated fashion just by somehow throwing all definitions of 1.) to 2.), i.e. I don't want to write a replace command by hand for all definitons of 1.)

Some more info: I am given the function g defined through the H's (which are polylogs). These polylogs can used to define a basis of another type of polylogs called L (denoted in 1.)). Now, my goal is to reexpress the function g given in the H-basis in the L-basis through the definitions in 1.).

Edit: z, and zp are the complex variable z and its conjugate.

To give an example: I have an expression like this:

-(1/16) (H[{0}, z] + H[{0}, zp])^2 + 1/4 (1/2 H[{0}, z] + 1/2 H[{0}, zp] + H[{1}, z] + H[{1}, zp])^2


which is equivalent to (just using the definitions from above)

-(1/16) (L[{0},z])^2 +  1/4 (1/2 L[{0}, z] + L[{1}, z])^2


Using FullSimplify on this would shadow the nice structure since the definitions of point 1 are already obvious here.

Probably very unelegant, my attempt (I have to put in the number of definitons of L by hand. Here = 14).

rules = Table[Expand[a_.*DownValues[L][[i]][]] -> a*DownValues[L][[i]][], {i, 1, 14}]


It does what I want though :)

I think your problem is a subset of a difficult one that has been (only partially) addressed multiple times; e.g.: Can I simplify an expression into form which uses my own definitions?

Nevertheless it is possible that if your transformations are as shown this may work, but I don't expect this to be at all robust:

L[{0}, z] = H[{0}, z] + H[{0}, zp];
L[{1}, z] = H[{1}, z] + H[{1}, zp];
L[{0, 0}, z] = H[{0, 0}, z] + H[{0, 0}, zp] + H[{0}, z] H[{0}, zp];

rules = Cases[DownValues[L], ((hp : HoldPattern)[lhs_] :> rhs_) :> hp[rhs] :> lhs]

ClearAll[L]

g = 1/2*H[{0}, z] + 1/2*H[{0}, zp];

FullSimplify[g, TransformationFunctions -> {Automatic, # /. rules &}]

1/2 L[{0}, z]


Note that I had to ClearAll[L] (after building rules) to prevent the final form from being immediately transformed by the original definitions for L.

• FML - I was trying the same thing, sans the clear...that's the magic dust... you are the master. +2 if I could.
– ciao
Feb 4, 2014 at 10:45
• @rasher FML? Famous Last Words? Feb 4, 2014 at 11:47
• Thanks! FullSimplify is not what I need, in this cases, as the equations are already simplified down to a level, where I have the patters of point 1 standing there. So, applying Fullsimplify rather destroys the nice patterns. Instead, how do refine the rules above to work like a_H[]+a_H[]+a_H[]...->aL. As I said, FullSimplify doesn't work in this context. (Updated the example above) Feb 4, 2014 at 12:58

You have to correctly define the pattern for z.

For example:

L[{0},z_]:=H[{0},z]+H[{0},zp]
L[{1},z_]:=H[{1},z]+H[{1},zp]
L[{0,0},z_]:=H[{0,0},z]+H[{0,0},zp]+H[{0},z]H[{0},zp]

g=1/2L[{0},z]+L[{1},z]


Expands automatically. (note that it's not clear what zp is and where it comes from, so it's treated as a global variable.)

• Updated problem above. Feb 4, 2014 at 9:47