Differences between revisions 13 and 14
 ⇤ ← Revision 13 as of 2006-12-06 07:39:37 → Size: 2104 Editor: RogerHui Comment: ← Revision 14 as of 2008-12-08 10:45:28 → ⇥ Size: 2091 Editor: anonymous Comment: converted to 1.6 markup Deletions are marked like this. Additions are marked like this. Line 73: Line 73: attachment:plot-BiG.png {{attachment:plot-BiG.png}} Line 75: Line 75: Comparatively, binary [:Essays/Base_Spectrum: base spectra] of` G `and` B `look like this: Comparatively, binary [[Essays/Base Spectrum| base spectra]] of` G `and` B `look like this: Line 80: Line 80: attachment:viewmat-G-B.png {{attachment:viewmat-G-B.png}} Line 83: Line 83: [[BR]] <
> Line 86: Line 86: [http://mathworld.wolfram.com/GrayCode.html MathWorld] [[MathWorld:GrayCode|MathWorld]] Line 88: Line 88: [[BR]] <
>

Gray code encodes integers as boolean lists so that code words for adjacent numbers differ by 1 bit. For example, the 4-bit encodings of 7 and 8 are:

```0 1 0 0
1 1 0 0```

The 2^n Gray codes of length n can be computed as follows:

```   G=: 3 : '(0&,. , 1&,.@|.)^:y i.1 0'

G&.> 2 3 4
┌───┬─────┬───────┐
│0 0│0 0 0│0 0 0 0│
│0 1│0 0 1│0 0 0 1│
│1 1│0 1 1│0 0 1 1│
│1 0│0 1 0│0 0 1 0│
│   │1 1 0│0 1 1 0│
│   │1 1 1│0 1 1 1│
│   │1 0 1│0 1 0 1│
│   │1 0 0│0 1 0 0│
│   │     │1 1 0 0│
│   │     │1 1 0 1│
│   │     │1 1 1 1│
│   │     │1 1 1 0│
│   │     │1 0 1 0│
│   │     │1 0 1 1│
│   │     │1 0 0 1│
│   │     │1 0 0 0│
└───┴─────┴───────┘```

Gray codes and the binary representations are closely related: The binary representations of n bits can be computed similarly, and one can be transformed into the other readily:

```   B=: 3 : '(0&,. , 1&,.)^:y i.1 0'

(B ; G) 3
┌─────┬─────┐
│0 0 0│0 0 0│
│0 0 1│0 0 1│
│0 1 0│0 1 1│
│0 1 1│0 1 0│
│1 0 0│1 1 0│
│1 0 1│1 1 1│
│1 1 0│1 0 1│
│1 1 1│1 0 0│
└─────┴─────┘

(B 3) -: ~:/\"1 G 3
1
(G 3) -: ~:/\^:_1"1 B 3
1```

can also be expressed as #:@i.@(2&^)

```   (B -: #:@i.@(2&^)) 8
1```

and G are related in self-similar manner:

`'dot;title B i. G'plot (B i. G) 10`

Comparatively, binary base spectra of G and B look like this:

```   viewmat (|:G 8);'G 8'
viewmat (|:B 8);'B 8'```