Hide function arguments (from unknown functions) for simpler output [duplicate]

How can I print my expression with my function's arguments hidden?

For example:

exp=A[r,z]+B[s]^2;

HideArgs[exp]


Output:

A+B^2


The expression that could be tested is this one:

r^3*(Br[r, z]^2+Bz[r, z]^2)==E^(6\[Psi][r, z])*(r*D[\[Psi][r, z], z, z]+r*D[\[Psi][r, z],r,r])


Where the unknown functions are:

Br[r,z],Bz[r,z],\[Psi][r, z]

• What do you want as output of exp=Sin[A[r,z]+B[s]^2]? Jan 13 '14 at 1:28
• Just for my unknow functions, so I want it as: exp=Sin[A+B^2] Jan 13 '14 at 1:39

Here is another crude way but it seems flexible.

funcs = {Plus, Times, Power, Sin, Equal};
SetAttributes[HideArgs, HoldAll];
HideArgs[expr_] :=  expr /. {x_[__] /; And @@ (UnsameQ[x, #] & /@ funcs) :> x}


You can continue to add functions to funcs that shouldn't have their arguments hidden. For your example:

HideArgs[A[r, z] + B[s]^2]


Gives:

A + B^2


Also:

HideArgs[A[r, z]]


Gives:

A


Finally:

HideArgs[Sin[A[r, z] + B[s]^2]]


Gives:

Sin[A + B^2]


To test your real equation, I've added Equal to funcs:

HideArgs[r^3*(Br[r, z]^2 + Bz[r, z]^2) == E^(6 \[Psi][r, z])*(r*D[\[Psi][r, z], z, z] +
r*D[\[Psi][r, z], r, r])]


Gives:

(Br^2 + Bz^2)*r^3 == E^(6*\[Psi])*(r*Derivative[0, 2][\[Psi]] + r*Derivative[2, 0][\[Psi]])

• Is there a function that returns a list of all known functions in MMA? Jan 13 '14 at 2:04
• @s0rce, I guess Names["System*"] Jan 13 '14 at 2:06
• Hrmm, why doesn't replacing funcs with Names["System*"] work? Jan 13 '14 at 2:12
• @s0rce, I think that expression not only includes the MMA functions but the ones you've defined so it's probably not a good idea to use. Jan 13 '14 at 2:14

This should work for polynomials but is a bit messy:

HideArgs[exp_] := With[{exp2 = exp + 0[_]}, Replace[exp2, #[__] -> # & /@ Variables[exp2][[All, 0]], \[Infinity]]]

HideArgs[A[r,z]+B[s]^2]


A + B^2

HideArgs[A[r, z]]


A

There might be a cleaner way.

• Thanks sOrce, it's this what I want, but it fails to work for example on HideArgs[A[r,z]] Jan 13 '14 at 1:42
• Fixed but pretty crude, must be a better way. Jan 13 '14 at 1:47