0
$\begingroup$

I would like to define a rule that suppress any arguments of a function for visibility. I tried:

rule = f_[x__] -> f

While this works well with individual terms (including derivatives of expressions), products of functions don't work, such as

f[x] R[r] /. rule

which outputs "Times" for some reason?

$\endgroup$
4
  • 3
    $\begingroup$ It's because Head[f[x] R[r]] is Times. $\endgroup$ Nov 8 '19 at 11:47
  • 4
    $\begingroup$ What should be displayed for f[ g[x] ]? $\endgroup$
    – Kuba
    Nov 8 '19 at 11:57
  • 1
    $\begingroup$ Good question. While this may be seen as unfortunate, the answer to that question would be just "f", since g(x) is an argument. $\endgroup$
    – Patrick.B
    Nov 10 '19 at 21:12
  • 2
    $\begingroup$ I think I have a good answer to this question, so it would be nice to reopen. $\endgroup$
    – Carl Woll
    Nov 29 '19 at 5:09
4
$\begingroup$

It's because Head[f[x] R[r]] is Times. You should rewrite your rule as

rule = f_[x__] /; ! MatchQ[f, Times] :> f

Now

f[x] R[r] /. rule    
f R

I would like to define a rule that suppress any arguments of a function for visibility.

I think my shortInputForm function can be of interest for you. It doesn't completely suppress arguments but rather shortens long lists of numbers for readability.

$\endgroup$
2
$\begingroup$

I think you can create a wrapper that modifies the box generation code so that it never generates brackets:

MakeBoxes[SuppressBracketArguments[expr_], StandardForm] ^:= ReplaceAll[
    MakeBoxes[expr,StandardForm],
    RowBox[{h_, "[",___,"]"}]->h
]

A couple examples:

f[g[x]] //SuppressBracketArguments
f[x] g[y] //SuppressBracketArguments

f

f g

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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