Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following problem at hand.

1.) I have a list of definitions like


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

2.) Now I have a sum of terms like


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.


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]][[2]]] -> a*DownValues[L][[i]][[1]], {i, 1, 14}]

It does what I want though :)

share|improve this question
Possible duplicates: – Mr.Wizard Feb 4 '14 at 9:52

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]


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.

share|improve this answer
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 '14 at 10:45
@rasher FML? Famous Last Words? – Mr.Wizard Feb 4 '14 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) – A friendly helper Feb 4 '14 at 12:58

You have to correctly define the pattern for z.

For example:



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

share|improve this answer
Updated problem above. – A friendly helper Feb 4 '14 at 9:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.