# 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]

-

## marked as duplicate by Mr.Wizard♦Jan 13 '14 at 9:01

What do you want as output of exp=Sin[A[r,z]+B[s]^2]? – belisarius has settled Jan 13 '14 at 1:28
Just for my unknow functions, so I want it as: exp=Sin[A+B^2] – Giovanni F. 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? – s0rce Jan 13 '14 at 2:04
@s0rce, I guess Names["System*"] – RunnyKine Jan 13 '14 at 2:06
Hrmm, why doesn't replacing funcs with Names["System*"] work? – s0rce 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. – RunnyKine 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]] – Giovanni F. Jan 13 '14 at 1:42
Fixed but pretty crude, must be a better way. – s0rce Jan 13 '14 at 1:47