# Understanding TagSetDelayed

I was reading What is the distinction between DownValues, UpValues, SubValues, and OwnValues? and I started to be confused with the part "Upvalues" of the first answer.

Some of my confusion comes from the fact I don't really understand TagSetDelayed, I took a look at mathematica documentation but I'm more confused.

May I have a simple explanation of how it works with simple examples ?

The documentation take the example :

g /: f[g[x_]] := fg[x]
{f[g[2]], f[h[2]]}

{fg[2], f[h[2]]}


So, allright it means that when I call f[g[2]] it will be replaced by fg[2] But it seems to be more general as they do f[h[2]]. What happens in this case ? h is replacing g in the expression then we have f[h[2]].

Well I don't really get what is happening and how it can be usefull

• This and this could be helpful – Lukas Lang Dec 30 '18 at 14:37
• Is your question why wasn't h case converted? – Kuba Jan 2 '19 at 21:59