# How to simplify a long expression by introducing a specific substitution?

I have just started using Mathematica, so I am still familiarising myself with it.

Now here is my issue: I have a matrix G, which looks something like:

G = {Underscript[1, 2]{-ω^(-kx-ky),ω^(-kx-ky),ω^(-kx-ky),ω^(-kx-ky)},
Underscript[1, 2]{ω^(-kx+ky),-ω^(-kx+ky),ω^(-kx+ky),ω^(-kx+ky)},
Underscript[1, 2]{ω^(kx-ky),ω^(kx-ky),-ω^(kx-ky),ω^(kx-ky)},
Underscript[1, 2]{ω^(kx+ky),ω^(kx+ky),ω^(kx+ky),-ω^(kx+ky)}}


Note that ω is fixed, and kx and ky are variables. I evaluate the eigenvectors of G using v = Eigenvectors[G].

The eigenvectors are quite long and messy, but I found that there is a certain expression that reappears, so I would like to substitute this with something else, to shorten it. In other words, I want to introduce the following substitution:

γ(kx_, ky_) = Sqrt[1 + 2 ω^(2 kx) + ω^(4 kx) +
2 ω^(2 ky) + ω^(4 ky) - 12 ω^(2 kx + 2 ky) +
2 ω^(4 kx + 2 ky) + 2 ω^(2 kx + 4 ky) + ω^(
4 kx + 4 ky)]


I am not sure how to let Mathematica carry out this substitution? Looking at other questions online, I tried the following:

Simplify[Eigenvectors[G],
Sqrt[1 + 2 ω^(2 kx) + ω^(4 kx) +
2 ω^(2 ky) + ω^(4 ky) - 12 ω^(2 kx + 2 ky) +
2 ω^(4 kx + 2 ky) + 2 ω^(2 kx + 4 ky) + ω^(
4 kx + 4 ky)] = γ (kx_, ky_)]


and also tried:

Solve[γ (kx_, ky_) == Sqrt[
1 + 2 ω^(2 kx) + ω^(4 kx) +
2 ω^(2 ky) + ω^(4 ky) -
12 ω^(2 kx + 2 ky) + 2 ω^(4 kx + 2 ky) +
2 ω^(2 kx + 4 ky) + ω^(4 kx + 4 ky)], kx, ky] //
FullSimplify // Expand // Union // Column // TraditionalForm


But I don't get any output for these inputs. What should I do?

Try e.g.:

v /. Sqrt[
1 + 2 ω^(2 kx) + ω^(4 kx) +
2 ω^(2 ky) + ω^(4 ky) - 12 ω^(2 kx + 2 ky) +
2 ω^(4 kx + 2 ky) +
2 ω^(2 kx + 4 ky) + ω^(4 kx + 4 ky)] -> γ[kx,
ky]


• Thanks, that's exactly what I was looking for. Just a quick follow up question. As I said, I am still familiarising myself with Mathematica, but I thought that if you want to define a function with arguments, you have to add an underscore, so gamma(kx_, ky_). Is that not necessary here? Commented Apr 26, 2023 at 14:15
• Sorry, I have another follow up question. It is very strange, but for some reason, it doesn't work anymore if I try to replace it with gamma[kx,ky], but it still replaces it with gamma[k,ky] or gamma[kx,k], or basically anything apart from gamma[kx,ky]. Do you know what could have caused that? Commented Apr 26, 2023 at 15:34
• First, note that a function is defined with square brackets: fun[x_,x_] :=... or fun[x_,x_]=.... The former is safer and evaluates the expression every time the function is called. This is useful if the function can not be calculated at define time. Look up "Set" and "SetDelayed" in the help. And the underscore is needed for formal arguments, that are replaced by real values when you call the function.. Second, Solve does not directly define a function, but it returns rules (look up "Rule" in the help) that can be used to define a function as I showed above. Commented Apr 26, 2023 at 16:16