You are on page 1of 6

Flexagons and Prolog

Logic Programming - Course Project


Zinovi Rabinovich Alexander Pyasik
nomad@cs.huji.ac.il alexpy@cs.huji.ac.il
Hebrew University of Jerusalem, Israel
Department of Computer Sciences
September 13, 1999

Abstract 2 Folding and Flexing


Here we present limited case of exagons 2.1 Folding
(hexa-hexa- exagons), exigation (pinch- exing)
and their prolog implementation with Tcl/Tk in- Folding a hexahexa exagon is a matter of ba-

terface. sic drawing tools and cutting skills. We shall begin


from strip of paper formed by 18 21 equilateral tri-
angles (the half is for gluing) as shown at Fig.1.
1 Introduction Pay attention to the Greek letters and on rst
and last triangle, they will help you to place the
Math student A. H. Stone pre- paper strip correctly during the folding. Now, fold
the strip to form spiral gure, as shown on Fig.2:
Year 1939.
pared a scienti c report. Problem: American end
English paper standards di er. So he had to tear fold strip to match 2b/3b, 4b/5b, 6b/7b... Fold
o strip of paper from each and every sheet he used spiral to match 4a/7a (Fig.3) and 10a/13a (Fig.4).
to t it into folder. Drifting into his thoughts, he Now left only to fold 18a to the backward (notice
began folding current paper strip and after a while that and on triangles 1 and 18 now match)
produced a exible hexagon. He found that it had and glue 'G' half-triangle to the triangle signed 1.
six di erent faces. And it is not trivial to ' ex'
(fold in certain way) this hexagon gure to expose
all of them.
2.2 Pinch-Flexing
So called 'Flexagon Committee' was formed, Flexing is a transformation made upon a
rst: when B. Tuckerman, R. P. Feynman and exagon, so that visible face is changed to dif-
J.W. Tuckey joined Stone in developing and re- ferent one. Pinch- exing is simplest after obvi-
searching the exagons. Di erent types where ous rotation ' exing'. Take one of the corners of
found, classi ed and faces counted. As men- hexa exagon in your right hand and make radial
tioned, our work build around hexa-hexa- exagon: edge of that corner fold upward. At the same time
exible hexagonal gure, showing six di erent pinch radial edge of the opposite corner downward.
faces, built from straight strip of paper - original Join all radial edges, that where folded down-
exagon invented by Stone. wards, together. The resulting gure should open
There were several works generalizing exiga- like ower bud, revealing new exagon face. This
tion: those who generalized exing [11], those who process is called pinch- ex. Notice that pinch- ex
generalized process of faces revealing [12, 8], those might not be possible for certain ( exagon state -
who generalized paper strips and exagons them- corner) pairs, which makes it only more interest-
selves [12, 15, 2]. ing to nd all existing exagon faces. It was

1
2 Flexagons and Prolog

α α
2a 4a 6a 8a 10a 12a 14a 16a 18a
1a 3a 5a 7a 9a 11a 13a 15a 17a β G
β

β β G
1b 3b 5b 7b 9b 11b 13b 15b 17b
α 2b 4b 6b 8b 10b 12b 14b 15b 18b
α

Fig. 1: Basic strip for hexahexa exagon, fore- and backside


β α
1a 5a 9a 13a 17a
2a 6a 10a 14a 18a
β α

Fig. 2: First folding stage - spiral


α
G
18a
β β
1a
17a
2a α
2a 14a
β α
11a 15a
5a 18b 5a 11a
8a 12a 16a 8a

Fig. 3: Continuing to double spiral Fig. 4: Double spiral is complete

shown by Tuckerman that certain sequence (so will be noted by list of numbers - id's of triangles
called Tuckerman's traversal) of pinch- ex and ro- that form it: from front to the back. For example
tations will lead to revealing of all possible faces initial state of the exagon we've made in 2.1 can
of hexahexa exagon. It also led to developing of be written as:
hexa exagrams[8] - graph-like notation for trans- (2,3-5,4,7,6-8,9-11,10,13,12-14,15-17,16,1,18)
actions between di erent exagon states. Knowl-
edge of Tuckerman's traversal was really handy
when we tested our implementation of exing for-
mula (see 3.2 and 4.1) 17a
2a 14a
3 Mathematical basis
11a
3.1 Flexagon state notion 5a
8a
Notion for exagon state that we describe
here is taken from papers by McLean [11] and Oak-
ley,Wisner [12] and slightly modi ed to note com- Fig. 5: Initial face of hexahexa exagon
plete colored exagon state. Let's call triangu-
lar regions that form the hexagon pats. Each pat This notation is used by McLean [11] and dif-
is a set of triangles that form original paper strip. fers slightly from that of Oakley,Wisner [12]. On
Let's number pats from p1 to p6. And right down our behalf, we changed it little bit more, and
each one of them separated by the dash. Each pat each triangle is written as list : (closest to front
Logic Programming - Course project 3

side,triangle id,far side). Like ((a 2 b) (b 3 a) : : :) nd p5 can be optimized using fact that D(a1 ) =
Thus we can tell what side of triangle we see and D(a3 ) = D(a5 ) and D(b1 ) = D(b3 ) = D(b5 )
it's color. Necessity of such notation will be clear should exist.
the moment we'll present transformation formu-
las. 3.3 Simple Example
3.2 Flex vs. Formula Let's begin from the initial state of the
exagon built in 2.1:
We'll now build a transformation formula (2,3-5,4,7,6-8,9-11,10,13,12-14,15-17,16,1,18)
from state to state that will:
Formula requires splitting pats p2; p3 and p5.
 Be consistent with physical parameters of the only way to do that is to split them into single
constructed exagon triangles:
 Will represent transformation identical to a1 = ae1 = 2, b1 = be1 = 3
pinch- ex a3 = ae3 = 8, b3 = be3 = 9
a5 = ae5 = 14, b5 = be5 = 15
After simple observations of exagon behavior un-
der pinch- ex, one can easily notice the follow- So using formula we should obtain the following
ing1: Let  denote addition modulo 6, and face face:
(p1 ? p2 ? p3 ? p4 ? p5 ? p6 ) is legal i : (2-3,6,7,4,5-8-9,12,13,10,11-14-15,18,1,16,17)
 p is a pat for each i
i If you will check this face due conditions of 3.2,
you will see that newly obtained face is legal. If
 p ? p 1 is a permutation of six2 consecutive
i i you will perform pinch- ex on physical exagon
numbers using corner of pats p1 ; p6 as base (one that goes
 P D(p ) = 18, where D(p ) is number of tri-
6 up), you will see that new face is corresponding to
i=1
i i description obtained via pinch- ex formula.
angles in pat p
3.4 Complex Example
i

Now we can de ne function for pinch- ex:


Let's start once again from initial state:
P inch(State) =
P inch(ae1be1 ? p2 ? ae3be3 ? p4 ? ae5be5 ? p6 ) =
(2,3-5,4,7,6-8,9-11,10,13,12-14,15-17,16,1,18)
(a1 ? be1pe2 ? a3 ? be3pe4 ? a5 ? be5pe6 ) (1)
But this time, before pinch- ex, let's rotate the
exagon clockwise to shift p2 to be p3:
Where pe denotes reversing of pat p. Since re- (17,16,1,18-2,3-5,4,7,6-8,9-11,10,13,12-14,15)
versing involves change in visibility of triangle's Now we have more options to divide pats. Let's
sides that form a pat, additional notion required try the following:
if we wish to trace color of visible exagon face.
From this need derives notation change described a1 = ae1 = 17, be1 = 16; 1; 18
in 3.1. We also can see that applying the formula a3 = ae3 = 5, be3 = 4; 7; 6
demands that p1; p3 and p5 will not be singleton a5 = ae5 = 11, be5 = 10; 13; 12
pats. It is also clear that such situation can be The formula will give the following face:
resolved by rotating the exagon for one pat. (17-16,1,18,3,2-5-4,7,6,9,8-11-10,13,12,15,14)
Notice that pinch- exing has symmetry prop-
erty, thus search for appropriate breaking of p1 ; p3 But now we should check it using constrains of
3.2. Simple observation of p2 ? p3 will show that
1 Conditions and formula itself, as well as 'easiness' re-
mark, are taken from article by T. Bruce McLean[11]
the face is not legal: 16,1,18,3,2 and 5 are not
2 Condition that was actually used is one for more gen- sequential.
eral exing, that includes V-Flex[11]: . . .permutation of Similar thing will happen if we will split p1 ; p2
3k. .. and p3 in 3/1 proportion. Yet, the combination:
4 Flexagons and Prolog

e e
a1 = 16; 17, a1 = 17; 16, b1 = 1; 18 Legality conditions described in 3.2 can be eas-
e e
a3 = 4; 5, a3 = 5; 4, b3 = 7; 6 ily reached through standard prolog functions such
e e
a5 = 10; 11, a5 = 11; 10, b5 = 13; 12 as permutation and sort. The only problem might
will lead to legal face: occur from the fact that triangles 1 and 18 should
be consecutive, but that is solved by shifting num-
(16,17-1,18,3,2-4,5-7,6,9,8-10,11-13,12,15,14) bers to 0-17 range and using addition modulo 18
in consequency check.
Initial state representation is provided hard-
3.5 Notes on exing coded
It is important to note that triangles forming
the exagon have much more complex trajectory 4.2 Visualization
then just ipping over and changing order. They
also turn around center of exagon and, what is Thanks to great power of prolog, visualiza-
more important, around their own center in cer- tion became the hard part, instead of exing it-
tain non trivial way. One consequence is that each self. Graphical representation required 3D opera-
face that we described is rather a class of exagon tion over object dynamic in time.
faces. Although it is possible to extent exagon Standing alone animation in Tcl/Tk is easy.
state notion to capture, in addition to all, relative The problem is interference between animation
position of the triangle corners, we preferred not running and user actions over graphical interface
to, so that resulting puzzle (see 4.3) will be easier at the same time. It was solved by centralizing
to solve. animation process. As for 3D, we had to limit an-
imation to 2D space, to avoid overcomplicated and
computationally expensive calculations.
4 Virtual Flexing Physically exed, hexa exagon undergoes rota-
tion unnoticed, when pinch- ex is performed. Nor-
4.1 Prolog Flexing mal form of pinch- ex formula does not create this
deceptive rotation, so we had to force it by ad-
One can easily observe that mathematical ditional programming. Which also created more
transformations described for exing look like clas- complex animation.
sical logic programming problem. Beside legality Finally exagon is presented as set of six
checking of exagon face, exing itself described smoothed triangles and their outlines, which form
as symbolic formula (1) in 3.2 - native language hexagonal gure, disharmonized to simulate 3D
of logic programming. Practically what left is to appearance. Under request of an animation, tri-
translate this formula to prolog syntax [14]. We angles begin to shrink by three opposite corners
use modi cation of di erence lists idea to trans- of the hexagon, so after a while exagon looks
late exagon state notion. like three lines, after that and change of color,
State = [P1 ? : : : ? P6 ]. triangles grow back revealing new exagon face.
P = [S1 ; S2; : : :], P is a Pat.
i i To simulate and visualize physical spin deception,
i i
S = [c1 ; j; c2], j triangle's id forming the pat.
i j j while shrinking/growing, exagon turns one pat
j
on, which makes exing seems more natural.
c1 denotes color of closest to front side of Sji
j

cj2 - color of the farthest.


4.3 Puzzling Flexagon
The rest of formula implementation is purely It would be wonderful if we could build full
technical issue of operating with list: append, re- virtual reality models. Unfortunately, at this mo-
verse supply needed functionality. The only ad- ment of time, it is grey-area. Yet, virtual exagon
ditional check that need to be made is that, lists we've built and virtually we'll ex it. For that user
break to non-empty parts, which will also ensure interface was developed and built.
essential condition for pats P1; P3 and P5 to be Since exagon represents a game for naive ob-
non-singletons. server. We used game-like representation for ex-
Logic Programming - Course project 5

4.5 Running and Thinking


The following is step-by-step instructions list
to run Virtual Flexagon
Rotate  SICStus[14] prolog was used for creating this
CounterClock application. So rst you have to obtain SIC-
Stus prolog or one compliant.
 Application also requires Tcl/Tk v.8.0 or later
PinchFlex (pay attention to possible incompatibility be-
Rotate tween Tcl/Tk versions)
ClockWise
 Run prolog and load ' ex.prolog' program le
 Evaluate 'virtualFlexagon' predicate.
Tcl/Tk window as described in 4.3 will open
Fig. 6: Flex Option Sensors
 Enjoy !
ing. User is presented a exagon and 'simple' tar- You can obtain source of the exagon simulator:
get: to discover all possible faces. Colors are listed  From
and marked when unseen before face exposed. http://www.cs.huji.ac.il/nomad/
Arrows mark basic possibilities. Concentric or
arrow marks base corner for pinch ex. Two ar- http://www.cs.huji.ac.il/alexpy/
rows, directed along perimeter of exagon at both
sides of pinch ex marking arrow, sign two direc-  e-mail by request
tions for rotating exagon. Pressing left mouse to nomad@cs.huji.ac.il
button over one of them will cause appropriate or
action over displayed exagon. Similarly to that, to alexpy@cs.huji.ac.il
exists binding between actions and cursor arrows Package contains:
on the keyboard: left-right arrow keys mark rota-
tion, down/up arrow key marks pinch- ex.  Prolog implementation of pich- ex formula -
Standard menus supplied as well: Game, Ani- ' ex.prolog'
mation and Help menus. 'Game' menu includes
options like 'Exit' and 'New game', while 'Help'  Tcl/Tk interface to the implementation -
menu is standard one for it's type: 'About' is ' ex.tcl'
the single options implemented at this time, for  This le - 'project.ps'
project time and size limitation. User also is given
an option to change animationparameters via 'An-  Image 'about.gif' used by the interface
imation' menu. This menu is also limited - anima-
tion speed is only available parameter to change.
5 Possible Extensions
As was mentioned in 3.5, exagon face is
4.4 Known Bugs much more complex then visualization was built
for. Yet, created code is easily extensible to cap-
Single bug noticed is that exit while animat- ture all needed changes. For example each tri-
ing causes prolog to crash. But, since it happens angles side, instead of being colored entirely into
under exit from programm and there is certain in- one color, can be colored into three di erent colors
dication that it might be bug in Tcl/Tk library of so that corners will be easily identi ed by viewer.
prolog, we consider it extremely minor bug. This will make resulting puzzle harder: to nd
6 Flexagons and Prolog

all faces, when face de ned by combination and References


relative placement of colors due to the center of
exagon. [1] K. R. Apt. From Logic Programming to Pro-
Number of exagons produced by prolog part log. Prentice-Hall, 1997.
can be extended, as well - simple addition of [2] P. B. Chapman. Square exagons. Math.
parameter to function, which produces initial Gaz., 45:192{194, 1961.
exagon state, and exagons with 15, 12 and even
48 sides can be created for joy of public, for the [3] J. Crampin. On note 2449. Math. Gazette,
exing formula is general whatever number of faces 41:55{56, 1957.
there is, and same generality has the prolog imple-
mentation. This way multiple levels of puzzling [4] M. Gardner. Mathematical games: About
can be created in exagon Tcl/Tk simulator. tetra exagons and tetra exigation. Sci.
Amer., 198:122{126, May 1958.
[5] M. Gardner. The Scienti c American Book
of Mathematical Puzzles & Diversions, chap-
ter 1, HexaFlexagons. New York: Simon and
Schuster, 1959.
[6] M. Gardner. The Second Scienti c Ameri-
can Book of Mathematical Puzzles & Diver-
sions: A New Selection., chapter 2, pages 24{
31. New York: Simon and Schuster, 1961.
[7] Martin Gardner. Mathematical Puzzles and
Diversions. Penguin Books, or Chicago Press,
1965.
[8] Margaret Joseph. Hexahexa exagrams.
Mathematics Teacher, 44:247{248, 1951.
[9] David King. A bit of exagon theory. pub-
lished via WWW, February 1999. drk-
ing@enterprise.net.
[10] F. G. Maunsell. The exagon and the hex-
a exagon. Math. Gazette, 38:213{214, 1954.
[11] T.Bruce McLean. V- exing the hexahex-
a exagon. Amer. Math. Monthly, 86(6):457{
466, 1979.
[12] C. O. Oakley and R. J. Wisner. Flexagons.
Amer. Math. Monthly, 64:143{154, 1957.
[13] L. Sterling and E. Shapiro. The Art Of Pro-
log. MIT Press, 1986, 1994.
[14] Swedish Institute of Computer Science. SIC-
Stus Prolog 3.7, October 1998.
[15] R. F. Wheeler. The exagon family. Math.
Gazette, 42:1{6, 1958.

You might also like