1

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]
Giovanni F.
  • 1,911
  • 13
  • 20

2 Answers2

3

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]])
RunnyKine
  • 33,088
  • 3
  • 109
  • 176
1

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.

s0rce
  • 9,632
  • 4
  • 45
  • 78