# Forcing FullSimplify to use user defined functions

Is it possible to simplify the expression using user-defined functions? For example if I define:

m[l_, x_] := Sum[x^i/i, {i, 1, l - 1}]


I would like

x + x^2/2 // FullSimplify


to returns

m[3, x]


You can use the second argument of FullSimplify to specify (hopefully not too long) a list of equalities involving the forms that you wish to detect and keep in the input expression:

ClearAll[m]
m[l_, x_] := Sum[x^i / i, {i, 1, l-1}]

FullSimplify[10 + x + x^2/2, Array[m[#, x] == HoldForm[m[#, x]] &, 10]]


10 + m[3, x]

FullSimplify[5 + x + 5 (x + x^2/2) + y Log[x + x^2/2 + x^3/3],
Array[m[#, x] == HoldForm[m[#, x]] &, 10]]


5 + m[2, x]+ 5 m[3, x] + y Log[m[4, x]]