# Removing the square-brackets and their contexts from an expression

Suppose I start with an expression like y[t] + x[t]: is there a function that lets me remove the [t] elements, so I obtain the expression y + x?

• What you asking is rather strange. What a you trying to accomplish? Also, are you aware that the Mathematica evaluator sees your expression as Plus[x[t], y[t]]; that there is another level of square brackets that the notebook editor doesn't normally show? – m_goldberg May 10 at 0:28
• Imagine this: I have an expression where x[t] and y[t] are functions that I evaluate for different values of t. I want to perform other manipulations of the expression, such as taking derivatives with respect to x or y, that no longer require keeping the argument [t]. – dtcitron May 10 at 1:39

try

exp= y[t] + x[t] ;


x+y

• Can you tell me more about the syntax you're using here? – dtcitron May 10 at 1:40
• this replaces x[t] with Head[x[t]] etc... – J42161217 May 10 at 1:49

For your example at least, the following works.

Replace[y[t] + x[t], u_[_] -> u, 2]


x + y

### Update

As I suspected, for the real problem underlying the question, the above method is not going to work. I would recommend using ReplaceAll and give a separate rule for each specific head involved. Like so.

Sin[y[t] + x[t]]/(1 + x[t]^2 + y[t]^2)^(1/2) /. {x[t] -> x, y[t] -> y}

Sin[x + y]/Sqrt[1 + x^2 + y^2]


As you see from the above example, this approach will handle quite complex expression involving x[t] and y[t] quite robustly.

• +1. I like Head /@ (y[t] + x[t]) for weird usage points... – ciao May 10 at 0:45
• This worked nicely - can you explain more the syntax with u_[_] here? – dtcitron May 10 at 1:31
• @dtcitron. u_[_] is a pattern that matches any expression with a single argument. When a match is made, Mathematica will bind u (temporarily) to the expression's head. The rule in which u_[_] appears tells Replace that, when a match occurs, to replace the matched expression with what u is bound to, namely the head. – m_goldberg May 10 at 3:15

Something like

f = (ToString /* StringDelete[Shortest["["~~___~~"]"]]);
f[y[t] + x[t] - z[u]]
(* x + y - z *)