2
$\begingroup$

I have a list of (undefined) functions, for example:

{f1[x, y, z], f2[x, y, z], f3[x, y, z]}

and I'd like to display it as

{f1, f2, f3}

therefore hiding the variable dependence in all the outputs. With a single function it's easy, because it suffice to use

Format[f[___]]:= f

In the case of the list, my first idea was to simply plug it inside the format function, meaning:

Format[{f1[___], f2[___], f3[___]}]:= {f1, f2, f3}

but I get the following error "Tag List in MakeBoxes [...] is protected". Another possible idea was using a for cicle:

For[j=1, j<4, j++, Format[Subscript[f, j][___]]:=Subscript[f, j]]

but the output was {f_3, f_3, f_3}.

Is there another way to display lists differently? I know that a function called ListFormat exists, but it seems not to work either. Probably one could Unprotect the List, but I have no idea how to reformat the whole thing then.

Thanks in advance for your help!

$\endgroup$
2
  • 1
    $\begingroup$ You could create the formatting rule for each symbol, e.g. Format[f1[___]] := f1 (and similarly for f2, f3). Or you could just use Head: Head /@ {f1[x, y, z], f2[x, y, z], f3[x, y, z]}. Or Part: {f1[x, y, z], f2[x, y, z], f3[x, y, z]}[[All, 0]]. There are a multitude of ways to do this depending on what format your original list is in and how much control you have over creating it. $\endgroup$ Commented Oct 10, 2024 at 16:18
  • $\begingroup$ Thanks for the answer! So, the first solution would be fine, but I have lists with many entries and I would like to avoid formatting them one by one. Regarding the use of Head: these lists are then used in expressions, therefore I'd like a global function that adjusts everything once and for all. $\endgroup$ Commented Oct 10, 2024 at 16:24

1 Answer 1

3
$\begingroup$
$Version

(* "14.1.0 for Mac OS X ARM (64-bit) (July 16, 2024)" )

Clear["Global`*"]

Rather than naming functions f1, f2, f3,...; use indexes, e.g., f[1], f[2], f[3],... Then

Format[f[n_]] := Subscript[f, n]

Format[f[n_][___]] := f[n]

{f[1][x, y, z], f[2][x, y, z], f[3][x, y, z]}

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks a lot for the answer! I had to adapt it a little bit to my needs, but it works perfectly! $\endgroup$ Commented Oct 13, 2024 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.