2
$\begingroup$

I am having an issue with the command TreeForm.

Suppose I have a list L of lists I would like to apply TreeForm to:

L = Groupings[{0,0,0,0}, {2, Orderless}]

{{{{0, 0}, 0}, 0}, {{0, 0}, {0, 0}}}

I do not understand why the following two lines of code return different trees:

TreeForm[{{{0, 0}, 0}, 0}]
TreeForm[L[[1]]]

The second one is truncated at some depth, with one node labelled "{0,0}".

$\endgroup$
  • $\begingroup$ I no loner have the issue if I replace 0 by a symbol a. $\endgroup$ – M. Brandt Jul 11 '17 at 9:59
  • $\begingroup$ Right, the reason is that symbolic arrays cannot be packed! $\endgroup$ – Henrik Schumacher Jul 11 '17 at 10:06
3
$\begingroup$

The answer may be that Groupings tries to give its output (or parts of if) as PackedArray if possible. And TreeForm was instructed not to unpack PackedArrays. See here:

L = Groupings[{0, 0, 0, 0}, {2, Orderless}];
a = {{{0, 0}, 0}, 0};
b = L[[1]];
Developer`PackedArrayQ[a[[1, 1]]]
Developer`PackedArrayQ[b[[1, 1]]] 

returns

(* False *)
(* True *)

Or at least TreeForm does not unpack PackedArrays that are leaves of a nodes that are not themselves PackedArrays. Pure PackedArrays are displayed "correctly".

$\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.