“Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited....

21
“Shapes” Revisited Stuart Smith [email protected] Introduction At APL93 Gérard Langlet gave a presentation entitled “Building the APL Atlas of Natural Shapes” [1]. The presentation featured his “SHAPES” program which, with just a handful of inputs, is able to produce a seemingly endless series of images of shapes found in flowers and other plants, crystals, microscopic molecular and biological structures, and in works of visual art. Looking through the conference proceedings, anyone who wanted to try the program out for themselves would find the function definition shown in figure 1. Had the name not already been taken by a firm that specializes in travel to strange and exotic locations, this bit of APL code could easily have been named “Atlas Obscura.” Figure 1. Langlet’s definition of the SHAPES function [1, p.134] There have been discussions of ways to implement this program in a contemporary APL [2] and there has been at least one attempt to implement it in J.[3] Part of the difficulty is figuring out exactly what is essential in the definition and what isn’t. Langlet’s discussion of the function is long and somewhat hard to follow; nonetheless, one should read [1] to gain a full

Transcript of “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited....

Page 1: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

“Shapes” RevisitedStuart Smith

[email protected]

IntroductionAt APL93 Gérard Langlet gave a presentation entitled “Building the APL Atlas of Natural Shapes” [1]. The presentation featured his “SHAPES” program which, with just a handful of inputs, is able to produce a seemingly endless series of images of shapes found in flowers and other plants, crystals, microscopic molecular and biological structures, and in works of visual art. Looking through the conference proceedings, anyone who wanted to try the program out for themselves would find the function definition shown in figure 1. Had the name not already been taken by a firm that specializes in travel to strange and exotic locations, this bit of APL code could easily have been named “Atlas Obscura.”

Figure 1. Langlet’s definition of the SHAPES function [1, p.134]

There have been discussions of ways to implement this program in a contemporary APL [2] and there has been at least one attempt to implement it in J.[3] Part of the difficulty is figuring out exactly what is essential in the definition and what isn’t. Langlet’s discussion of the function is long and somewhat hard to follow; nonetheless, one should read [1] to gain a full understanding of the theory underlying SHAPES. The present paper gives a complete, up-to-date version of SHAPES that retains all the essential features of the original1. One difference between Langlet’s SHAPES and the version presented here should be noted: shapes is strictly dyadic—there is no monadic form. Most of the code is generic APL; however, the display function, colordisp, is implementation-dependent (Dyalog).

The Gallery2 section below contains images of the nine examples listed in [1, p. 142] together with the arguments to shapes required to create them. Langlet did not include these images in

1 www.cs.uml.edu/~stu/SHAPES.dws2 A more extensive collection of SHAPES images can be found at www.cs.uml.edu/~stu/Gallery/

Page 2: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

his paper. Instead, he presented several other pictures that are equally illustrative of the capabilities of SHAPE.

The shapes functionshapes takes the following arguments:

S is a one- or two-element integer vector. If S has only one element, it determines the order of rotational symmetry of the image (≥3). If S has a second element, it specifies which Langlet transform is to be applied to the contour bit-string, B: 1=Cognitive transform, ¯1=Helical transform. This provides a way to vary a shape while holding both the order of rotational symmetry and the number of iterations of rewriting applied to the contour bit-string constant.

N is a one- or two-element integer vector. If N has only one element, it determines the number of times the rewriting rule is applied to B. The rule is that on each iteration, each 0 in B is replaced by 0 1 0 1 and each 1 is replaced by 1 1 0 1. Thus the length of B quadruples on each iteration. To avoid WS FULL the number of iterations specified by N must generally be small (≤6), especially if the order of symmetry is large. If N has a second element, it determines the number of times B is integrated with ≠\B. This provides another way to vary a shape while holding both the order of rotational symmetry and the number of iterations of rewriting constant.

There are also two global variables that affect the geometry of the shape:

irregularity is set to 0 by default (no irregularity). If it is set to 1, departures from perfect symmetry will be introduced into the shape being created. The specific departures are determined by the value(s) assigned to deltaG.

deltaG can be set to any numeric or Boolean vector. The effect deltaG has on the shape being created is unpredictable. Its purpose is to provide still another way to vary a shape while holding while holding both rotational symmetry and the number of iterations of rewriting constant. Langlet characterizes this aspect of shapes somewhat dismissively as “ad hoc.” [1, p. 137]

Both variables can be reset to their default values with the init function.

The subfunctions required by shapes are given in the Appendix. www.cs.uml.edu/~stu/SHAPES.dws contains the definitions of all of the functions mentioned here.

The display function, colordisp, offers user-selectable line, fill, and background colors. To set a color, assign RGB (0-255) values to line, fill, or background. The default color combination is Black and White on a WhiteSmoke background. 36 named colors are defined as variables in the workspace. A custom color can be created simply by assigning RGB values to the appropriate variable. For example, create a custom fill color:

fill←17 199 32In addition, the workspace contains 92 palettes that have predefined combinations of line, fill, and background colors. Enter paletten to select a palette (n =0-91).

Page 3: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

S shapes N;B;D;I;transform;reps;K;L;M;i;T; IO⎕ B←, IO←0⎕ D←0.5 T←2 4⍴0 1 0 1 1 1 0 1 :For i :In ⍳1↑N B←,T[B;] :EndFor I←⌈D×⍴B B←I↑B ⍝ transform←0 :If 2=⍴,S transform←¯1↑S S←¯1↓S :If transform=1 B←COG B :ElseIf transform=¯1 B←HEL B :Else ←'nonexistent transform'⎕ →0 :EndIf :EndIf ⍝ I←S,⍴K←M←2 2⍴M, 1 ¯1×M←2 1○○2÷S⌽ M←I⍴M I←0 T←K :For i :In ⍳S-1 M[I←I+1;;]←T←T+.×K :EndFor reps←0 1↑1↓N⌷ :If reps>0 B←(bvi reps)B⍣ :EndIf K←S×⍴B K←K×1+I←≠/K⍴B K← 2,⌊K+D←÷2⌽ M←K⍴M[;;0] I←1+2↑⌊S×D T←S|¯1+¯1 +\I[K[0]⍴B]⌽

Page 4: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

K←⍴T←M[T;] :If irregularity T←T×K⍴2/1,deltaG+GOLD×deltaG∧.=0 :EndIf T←+ T⍀ T←D+T×I←255 K←⍴T←⌊T T←T-K⍴⌊ T⌿ K←I÷⌈/T←,T T←⌊D+T×K T←REDUTN T colordisp T

Demonstration workspacesPerhaps the best way to learn about the capabilities of shapes is to download the demonstration workspaces (www.cs.uml.edu/~stu/xper14.DWS and www.cs.uml.edu/~stu/lxper14.DWS ). The GUI starts automatically. Just plug values into the edit fields and click on “GO.” For more details, run the README function in the workspace.

DiscussionBuilding the APL Atlas of Natural Shapes brings to mind D’Arcy Thompson’s influential 1917 work, On Growth and Form [4]. Both Langlet and Thompson were concerned with how things come to have the shapes they have. For Thompson, the shape of an organism is determined by the forces at work in its growth. For Langlet, it is simple bit-level computational processes that determine shape.3 A critical difference between Thompson and Langlet is that Thompson recognized that his book was descriptive and did not propose experimental hypotheses. Langlet, on the other hand, seems to claim in his many publications that he has identified the actual physical mechanisms by which something acquires the shape it has. The status of this claim is examined in another paper. [6]

The cornerstone principle of Langlet’s mathematical-logical system is that computations must not lose information. The reasons for this are discussed in [7]. One consequence of this requirement is that his system does not permit the use of floating-point arithmetic: rounding, truncation, smoothing, averaging, etc. are all forbidden because they lose information. It may come as a surprise then to find M←2 1○○2÷S and GOLD (i.e., R←0.5×1+5*0.5) in the definition of shapes. The use of a trigonometric function is easy to justify. APL and most other programming languages support only rectangular arrays. This is a limitation that would severely restrict the range of natural shapes that could be represented if it were required that the coordinates of every data point in a computed shape correspond exactly to one specific bit position in a rectangular bitmap. M is a rotation matrix that allows conversion from the implicit coordinate system of the shape being created to the rectangular world of arrays and graphic display hardware. In a sense, then, the computation involving M is not actually “inside” Langlet’s system at all. It is merely an interface to the world outside his “topological universe.”

3 This view is shared by Stephen Wolfram, whose magisterial A New Kind of Science [5] elaborates on it in encyclopedic detail. Langlet knew Wolfram’s earlier work well and cited it often. For his part, Wolfram appears to have been completely unaware of Langlet’s work.

Page 5: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

The presence of the computation involving GOLD is harder to justify. Langlet says he included it to introduce “irregularity” into the computation of shapes. As mentioned above, he considered this feature “ad hoc,” but in fact it addresses a true shortcoming of his system: the system’s own operations cannot themselves generate randomness. It must rather be transferred into the system from outside. Langlet wanted his system to be able to mimic the chaotic behavior observed in many natural processes, but the key operation of his system, ≠\, generates only apparent randomness. As Langlet himself shows in [7], when the result of an application of ≠\ to a Boolean vector is repeatedly made the input to the next, eventually the original vector reappears, that is, the process is periodic. Thus, in SHAPES the loop containing B←≠\B can be executed only ¯1+⍴B times before the sequence of results begins to repeat. Moreover, as is shown in [6] the result at any step in this process can be computed directly from the initial conditions.4 This means that any randomness observed in this process is already contained in the initial conditions and not generated intrinsically by the process itself. It might be a rewarding exercise to see if some process within the Langletian framework could provide a source of randomness. One possibility is a variant of the simple cellular automaton described in [5]. This possibility is explored in another paper. [8]

One might characterize the overall effect of a sequence of shapes images as “extreme Spirograph.™” 5 This is not to belittle Langlet’s program, which, though it is quite short, is nonetheless capable of creating pictures that go far beyond the familiar roulette curves that can be produced with the simple stator-and-rotor mechanism of Spirograph. Every now and then SHAPES generates a fantastic picture reminiscent of Surrealist art. This is no small achievement. Another source of SHAPES-like images is Aguasonics Acoustics [9], whose striking color visualizations of animal sounds are both useful research tools and works of art.

4 Langlet acknowledges this [1, p. 140]: “This expression [B←≠\B] is just for demonstration; otherwise, optimal algorithms can give you the 1000th ID directly, without computing the 999 first ones.” An optimal algorithm gives the exact same result as the brute force method, just faster. There is no gain in randomness.5 An online replica, “inspirograph,” can be found at http://nathanfriend.io/inspirograph/. See also the spirograph homepage, http://www.originalspirograph.com/

Page 6: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Gallery

Figure 1. Nice flowers. 9 shapes 5 89

Figure 22. Von Koch’s snowflake. 6 shapes 5

Page 7: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Figure 3. Pentagonal snowflake. 5 shapes 6

Figure 4. Celtic ladies. 5 shapes 5 22

Page 8: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Figure 5. Strange runner. 5 1 shapes 6 11

Figure 6. Chestnut crown. 15 ¯1 shapes 6 732

Page 9: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Figure 7. Fly crown. 30 shapes 5 21

Figure 8. Handsome pilot fish. 32 shapes 5 71

Page 10: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Figure 9. Apple of the eye. 104 1 shapes 4 31

Page 11: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

References[1] Gérard Langlet. Building the APL Atlas of Natural Shapes. APL ’93 Proceedings of the International Conference on APL. New York, NY: ACM (1993).

[2] SHAPESWE.WS - from which APL dialect? (Langlet's APL Atlas of Natural Shapes). https://groups.google.com/forum/#!topic/comp.lang.apl/w0HIW0zVrQE

[3] Langlet’s Atlas of Natural Shapes. http://computer-programming-forum.com/9-apl/7f3fb389c538cbe7.htm.

[4] D’Arcy W. Thompson. On Growth and Form; Abridged edition. Cambridge, UK: Cambridge University Press (1992)

[5] Stephen Wolfram. A New Kind of Science. Champaign, IL: Wolfram Media (2002)

[6] Stuart Smith. In Search of the World Formula. www.cs.uml.edu/~stu/

[7] Gérard   Langlet . Towards the Ultimate APL-TOE. ACM SIGAPL Quote Quad, 23(1) (July 1992)

[8] Stuart Smith. SHAPES. www.cs.uml.edu/~stu/SHAPES.DWS

[9] Aquasonics Acoustics. Beautiful Visualizations of Animal Sounds. http://laughingsquid.com/aguasonic-acoustics-beautiful-visualizations-of-animal-sounds/

Page 12: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Appendix

Helical transform of boolean vector S, whose length is a power of 2

z←HEL S :If (⍴S)=1 z←S :Else z←(HEL lhalf S),HEL(lhalf S)≠rhalf S :EndIf

Cognitive transform of boolean vector S, whose length is a power of 2

z←COG S :If (⍴S)=1 z←S :Else z←(COG(rhalf S)≠lhalf S),COG rhalf S :EndIf

Auxiliary functions required by the transforms lhalf←{((⍴y)÷2)↑⍵}

rhalf←{((⍴y)÷2)↓⍵}

R←GOLD R←0.5×1+5*0.5

y←bvi x y←≠\x

z←REDUTN T :If ∧/(lhalf T)=rhalf T z←REDUTN lhalf T :Else z←T :EndIf

Page 13: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

colordisp T; IO;rt;x;y⎕ IO←0⎕ rt←⍴T x←0.135×(rt⍴1 0)/T y←0.25×(rt⍴0 1)/T :If ((1↑x)=¯1↑x)∨(1↑y)=¯1↑y x←x,1↑x y←y,1↑y :EndIf x←x+10 y←y+10 'F' WC'Form' params⎕ F.BCol←background 'F.L1' WC'Poly'(y x)(line)('FillCol'fill)('BCol'fill)('FStyle' 0)⎕⍝ x←85+24×x-31 y←70+13×y-12 'bt' WC'bitmap'('size' 1000 1000)('coord' 'pixel')('cbits'(1000 ⎕1000⍴(256⊥background))) bt.BCol←background 'bt.L1' WC'Poly'('points'(y x))(line)('FillCol'fill)('BCol'fill)('FStyle' 0)⎕ filename←'C:\Users\Stuart Smith\Desktop\image.bmp' 'bt' WS'file'filename⎕ 2 NQ'bt' 'filewrite'⎕

Page 14: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Alternate Gallery if color is available

Fig. 1 Nice flowers

Fig. 2. Von Koch snowflake

Page 15: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Fig. 3. Pentagonal snowflake

Fig. 4. Celtic ladies

Page 16: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Fig. 5. Strange runner

Fig. 6. Chestnut crown

Page 17: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Fig. 7. Fly crown

Fig. 8. Handsome pilot fish

Page 18: “Shapes” Revisited - cs.uml.edustu/Topologic Universe.docx  · Web view“Shapes” Revisited. Stuart Smith. stuart.smith3@comcast.net. Introduction. At APL93 Gérard Langlet

Fig. 9. Apple of the eye