0
$\begingroup$

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]
$\endgroup$
2
  • $\begingroup$ What do you want as output of exp=Sin[A[r,z]+B[s]^2]? $\endgroup$ Jan 13 '14 at 1:28
  • $\begingroup$ Just for my unknow functions, so I want it as: exp=Sin[A+B^2] $\endgroup$ Jan 13 '14 at 1:39
2
$\begingroup$

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]])
$\endgroup$
4
  • $\begingroup$ Is there a function that returns a list of all known functions in MMA? $\endgroup$
    – s0rce
    Jan 13 '14 at 2:04
  • $\begingroup$ @s0rce, I guess Names["System`*"] $\endgroup$
    – RunnyKine
    Jan 13 '14 at 2:06
  • $\begingroup$ Hrmm, why doesn't replacing funcs with Names["System`*"] work? $\endgroup$
    – s0rce
    Jan 13 '14 at 2:12
  • 1
    $\begingroup$ @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. $\endgroup$
    – RunnyKine
    Jan 13 '14 at 2:14
1
$\begingroup$

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.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.