7
$\begingroup$

Is there some function in Mathematica which returns {c, i, j} for an input c[i,j]?

$\endgroup$

3 Answers 3

7
$\begingroup$

A simple approach is

c[i, j];
{Head[%], %1[[1]], %[[2]]}
(* {c, i, j} *)

Slightly more generally, use

f[x_] := Join[{Head[x]}, List @@ x]
f[c[i, j]]
(* {c, i, j} *)
$\endgroup$
1
  • 1
    $\begingroup$ {Head[#], Sequence @@ #} &[c[i, j]] also works. $\endgroup$ Commented Aug 19, 2016 at 19:39
13
$\begingroup$

Another possible way using Level and Heads.

Level[c[i, j], 1, Heads -> True]
(* {c, i, j} *)
$\endgroup$
6
$\begingroup$

using pattern-matching/deconstruction

c[i, j] /. a_[b_, c_] -> {a, b, c}

or define your own function:

f[a_[b_, c_]]:={a, b, c}
f[  c[i, j] ]  

{c, i, j}

$\endgroup$

Your Answer

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

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