# How to use an up-value assignment when all symbols are “too deep”?

I would like to make an up-value assignment such as

a/:Conjugate[a[x]]a[x]+Conjugate[b[x]]b[x] = 1


or

b/:Conjugate[a[x]]a[x]+Conjugate[b[x]]b[x] = 1


or

x/:Conjugate[a[x]]a[x]+Conjugate[b[x]]b[x] = 1


Unfortunately, in all cases Mathematica complains that the symbol is too deep to attach this up-value assignment to it. Is there a way to trick Mathematica to use this up-value, or realize it by some other means?

• With respect to tricking Mathematica to use up-values, the answer is no. As for "realize it by some other means", since you don't give any context for what you expect Mathematica to do with Conjugate[a[x]] a[x] + Conjugate[b[x]] b[x] = 1, that is unanswerable. – m_goldberg Apr 24 at 1:16
• @m_goldberg I believe an upvalue like x/:head[x]=y will substitute head[x]->y everywhere, while attaching the information about the substitution to x instead of head. In the case described in my question I would expect Mathematica to behave analogously. – Kagaratsch Apr 24 at 4:12

This is more of an extended comment than an answer.

If one allows for f = Plus, g = Times and h = Conjugate then the rhs of the assignments in the question can be written as f[g[a[x], h[a[x]]], g[b[x], h[b[x]]]].

Now, forgetting for a moment the attempted assignments and focusing only on the derived expression ie f[g[a[x], h[a[x]]], g[b[x], h[b[x]]]], it is evident that one cannot assign UpValues to symbols a, b, x because they appear too deep in the expression.

If the intended use of the code is to make algebraic manipulations of expressions involving symbols a, b and their Conjugate's then perhaps doing something like the following might be helpful:

1. Define UpValues for symbols a, b relating their use wrt to Times:

a /: a[x_] Conjugate[a[x_]] := timesConjugate[a[x]]
b /: b[x_] Conjugate[b[x_]] := timesConjugate[b[x]]


Please note that if the code intends to tackle more symbols like a, b eg like c then the list above should be extended in order to cover the use of those symbols, in a similar manner.

2. Define an UpValue for the auxiliary symbol timeConjugate wrt to Plus, when the arguments are a, b:

timesConjugate /: timesConjugate[b[x_]] + timesConjugate[a[x_]] = 1


Please note that if more symbols like a, b are used, then respective definitions of timeConjugate will have to be added to the list above in order to account for their use.

Now, hopefully after making the above definitions, expressions that involve a, b in the context of the expressions in the question, should evaluate to unity, as desired.

Hope this helps.

• Thank you, I think this tricks Mathematica into doing what I want alright! :) – Kagaratsch Apr 24 at 13:30