# Manipulate the effect of varying the level of flattening on a TreeForm expression

I want to visualize how Flatten works and have a slider that changes the level of flattening.

Here is the list of lists I'm using and Flatten function.

bifurcate[list_] := Nest[Partition[#, 2] &, list, Floor[Log[2, Length[list1]]]]

(structured = bifurcate[list1])//TreeForm

structured // Flatten[#, n] &


I want to be able to change the value of n from 1 to 3 with a step of 1,

However,

TreeForm[Flatten[structured, n]], {n, 0, 3}


doesn't work. What am I doing wrong?

• Shouldn't bifurcate use Length[list] rather than Length[list1]? Feb 22, 2019 at 21:04

I think first clean up structured. Then
Manipulate[TreeForm[Flatten[structured, n]], {n, Range[0,3]}]

will give the TreeForm for n in {0,1,2,3}. Just Range[3] for n in {1,2,3}. This is not a "slider" but discrete choices since n is an integer.
• For a slider, just use {n, 0, 3, 1} instead of {n, Range[0,3]}. Feb 22, 2019 at 19:15