Chapter 10: Processes of Perception and Analysis

Section 5: Data Compression

Recursive subdivision [encoding]

In one dimension, encoding can be done using

Subdivide[a_] := Flatten[If[Length[a] 2, a, If[Apply[SameQ, a], {1,First[a]}, {0, Map[Subdivide, Partition[a, Length[a]/2]]}]]]

In n dimensions, it can be done using

Subdivide[a_, n_] := With[{s = Table[1, {n}]}, Flatten[If[Dimensions[a] 2s, a, If[Apply[SameQ, Flatten[a]], {1, First[Flatten[a]]}, {0, Map[Subdivide[#, n] &, Partition[a, 1/2Length[a] s], {n}]}]]]]

Image Source Notebooks:

From Stephen Wolfram: A New Kind of Science [citation]