1 General presentation
You will design and implement a program that will
check whether some numbers, stored in a le, represent a particular coding of a frieze, and
{ either display the period of the pattern of the frieze and the transformations that keep it
invariant, based on a result that classi es friezes into 7 groups of symmetries,
{ or output some Latex code in a le, from which a pictorial representation of the frieze can be
produced.
The representation of a frieze is based on a coding with numbers in the range 0 . . .15, each such number
n being associated with a particular point p such that
if the rightmost digit of the representation of n in base 2 is equal to 1 then p is to be connected to
its northern neighbour:
if the second rightmost digit of the representation of n in base 2 is equal to 1 then p is to be
connected to its north-eastern neighbour:
if the third rightmost digit of the representation of n in base 2 is equal to 1 then p is to be connected
to its eastern neighbour:
if the fourth rightmost digit of the representation of n in base 2 is equal to 1 then p is to be
connected to its south-eastern neighbour:
2 Examples
2.1 First example
The le frieze_1.txt has the following contents.
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 0
0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0
0 0 0 0 4 4 1 5 4 4 4 4 8 0 0 0 0 0 0 4 4 1 5 4 4 4 4 8 0 0 0
0 0 0 2 0 0 5 1 0 0 0 0 0 8 0 0 0 0 2 0 0 5 1 0 0 0 0 0 8 0 0
0 0 2 0 0 0 0 0 0 0 0 0 0 0 8 0 0 2 0 0 0 0 0 0 0 0 0 0 0 8 0
0 6 4 4 4 4 4 4 4 4 4 4 4 4 4 0 6 4 4 4 4 4 4 4 4 4 4 4 4 4 0
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 4 4 4 12 4 4 4 1 1 0 0 0 0 0 0 4 4 4 12 4 4 4 1
1 1 0 4 4 0 0 0 1 2 0 0 8 1 0 1 1 0 4 4 0 0 0 1 2 0 0 8 1 0 1
1 1 0 5 5 1 0 0 3 0 0 0 0 1 0 1 1 0 5 5 1 0 0 3 0 0 0 0 1 0 1
1 1 0 5 5 1 0 0 5 4 4 4 4 1 0 1 1 0 5 5 1 0 0 5 4 4 4 4 1 0 1
1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1
1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1
1 5 4 5 4 5 4 4 4 4 4 4 4 4 4 1 5 4 5 4 5 4 4 4 4 4 4 4 4 4 1
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 0
Here is a possible interaction:
$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
...
>>> from frieze import *
>>> frieze = Frieze(’frieze_1.txt’)
>>> frieze.analyse()
Pattern is a frieze of period 15 that is invariant under translation only.
>>> frieze.display()
The e ect of executing frieze.display() is to produce a le named frieze_1.tex that can be given
as argument to pdflatex to produce a le named frieze_1.pdf that views as follows.
2
2.2 Second example
The le frieze_2.txt has the following contents.
4 4 4 4 4 4 4 4 4 4 12 4 4 4 4 4 4 4 4 4 4 4 12 4 4 4 4 4 4 4 4 4 4 4 12 4 4 4 4 4 4 4 4 4 4 4 12 4 0
0 0 0 4 8 0 0 0 3 1 1 1 0 0 0 4 8 0 0 0 3 1 1 1 0 0 0 4 8 0 0 0 3 1 1 1 0 0 0 4 8 0 0 0 3 1 1 1 0
0 0 2 0 0 0 0 0 0 1 1 0 0 0 2 0 0 0 0 0 0 1 1 0 0 0 2 0 0 0 0 0 0 1 1 0 0 0 2 0 0 0 0 0 0 1 1 0 0
1 0 9 0 0 1 0 1 0 1 1 0 1 0 9 0 0 1 0 1 0 1 1 0 1 0 9 0 0 1 0 1 0 1 1 0 1 0 9 0 0 1 0 1 0 1 1 0 1
4 0 0 4 2 0 4 4 8 1 1 4 4 0 0 4 2 0 4 4 8 1 1 4 4 0 0 4 2 0 4 4 8 1 1 4 4 0 0 4 2 0 4 4 8 1 1 4 0
8 1 0 0 0 0 1 0 0 1 3 0 8 1 0 0 0 0 1 0 0 1 3 0 8 1 0 0 0 0 1 0 0 1 3 0 8 1 0 0 0 0 1 0 0 1 3 0 0
1 1 0 4 0 0 3 1 0 0 0 0 1 1 0 4 0 0 3 1 0 0 0 0 1 1 0 4 0 0 3 1 0 0 0 0 1 1 0 4 0 0 3 1 0 0 0 0 1
1 0 0 5 1 0 0 1 0 4 0 0 1 0 0 5 1 0 0 1 0 4 0 0 1 0 0 5 1 0 0 1 0 4 0 0 1 0 0 5 1 0 0 1 0 4 0 0 1
1 4 4 0 4 4 8 1 0 1 1 0 1 4 4 0 4 4 8 1 0 1 1 0 1 4 4 0 4 4 8 1 0 1 1 0 1 4 4 0 4 4 8 1 0 1 1 0 1
3 0 8 1 1 0 0 1 0 1 1 0 3 0 8 1 1 0 0 1 0 1 1 0 3 0 8 1 1 0 0 1 0 1 1 0 3 0 8 1 1 0 0 1 0 1 1 0 1
0 0 1 1 3 1 0 0 4 1 5 0 0 0 1 1 3 1 0 0 4 1 5 0 0 0 1 1 3 1 0 0 4 1 5 0 0 0 1 1 3 1 0 0 4 1 5 0 0
0 0 1 0 8 1 0 0 1 0 0 1 0 0 1 0 8 1 0 0 1 0 0 1 0 0 1 0 8 1 0 0 1 0 0 1 0 0 1 0 8 1 0 0 1 0 0 1 0
4 4 7 5 5 5 4 4 5 4 4 5 4 4 7 5 5 5 4 4 5 4 4 5 4 4 7 5 5 5 4 4 5 4 4 5 4 4 7 5 5 5 4 4 5 4 4 5 0
Here is a possible interaction:
$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
...
>>> from frieze import *
>>> frieze = Frieze(’frieze_2.txt’)
>>> frieze.analyse()
Pattern is a frieze of period 12 that is invariant under translation
and vertical reflection only.
>>> frieze.display()
The e ect of executing frieze.display() is to produce a le named frieze_2.tex that can be given
as argument to pdflatex to produce a le named frieze_2.pdf that views as follows.
3
2.3 Third example
The le frieze_3.txt has the following contents.
12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 12 4 12 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 9 5 8 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0
2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 2 4 2 0
1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 6 4 6 0
Here is a possible interaction:
$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
...
>>> from frieze import *
>>> frieze = Frieze(’frieze_3.txt’)
>>> frieze.analyse()
Pattern is a frieze of period 3 that is invariant under translation
and horizontal reflection only.
>>> frieze.display()
The e ect of executing frieze.display() is to produce a le named frieze_3.tex that can be given
as argument to pdflatex to produce a le named frieze_3.pdf that views as follows.
4
2.4 Four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...
>>> from frieze import *
>>> frieze = Frieze(’frieze_4.txt’)
>>> frieze.analyse()
Pattern is a frieze of period 6 that is invariant under translation
and glided horizontal reflection only.
>>> frieze.display()
The e ect of executing frieze.display() is to produce a le named frieze_4.tex that can be given
as argument to pdflatex to produce a le named frieze_4.pdf that views as follows.
5
2.5 Fifth example
The le frieze_5.txt has the following contents.
4 4 4 4 4 4 12 4 4 4 4 4 4 4 12 4 4 4 4 4 4 4 12 4 4 4 4 4 4 4 12 4 4 4 4 4 4 4 12 4 4 4 4 4 4 4 12 4 0
0 4 1 0 0 2 0 8 0 4 1 0 0 2 0 8 0 4 1 0 0 2 0 8 0 4 1 0 0 2 0 8 0 4 1 0 0 2 0 8 0 4 1 0 0 2 0 8 0
10 0 0 0 2 0 0 0 10 0 0 0 2 0 0 0 10 0 0 0 2 0 0 0 10 0 0 0 2 0 0 0 10 0 0 0 2 0 0 0 10 0 0 0 2 0 0 0 0
0 8 0 2 0 0 4 2 0 8 0 2 0 0 4 2 0 8 0 2 0 0 4 2 0 8 0 2 0 0 4 2 0 8 0 2 0 0 4 2 0 8 0 2 0 0 4 2 0
4 4 6 4 4 4 5 4 4 4 6 4 4 4 5 4 4 4 6 4 4 4 5 4 4 4 6 4 4 4 5 4 4 4 6 4 4 4 5 4 4 4 6 4 4 4 5 4 0
Here is a possible interaction:
$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
...
>>> from frieze import *
>>> frieze = Frieze(’frieze_5.txt’)
>>> frieze.analyse()
Pattern is a frieze of period 8 that is invariant under translation
and rotation only.
>>> frieze.display()
The e ect of executing frieze.display() is to produce a le named frieze_5.tex that can be given
as argument to pdflatex to produce a le named frieze_5.pdf that views as follows.
6
2.6 Sixth example
The le frieze_6.txt has the following contents.
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 0
4 0 4 4 4 0 4 4 4 0 4 4 4 0 4 4 4 0 4 4 4 0 4 4 4 0 4 4 4 0 4 4 4 0 4 4 4 0 4 4 0
0 1 1 4 0 1 1 4 0 1 1 4 0 1 1 4 0 1 1 4 0 1 1 4 0 1 1 4 0 1 1 4 0 1 1 4 0 1 1 4 0
1 5 1 1 1 5 1 1 1 5 1 1 1 5 1 1 1 5 1 1 1 5 1 1 1 5 1 1 1 5 1 1 1 5 1 1 1 5 1 1 1
5 4 4 1 5 4 4 1 5 4 4 1 5 4 4 1 5 4 4 1 5 4 4 1 5 4 4 1 5 4 4 1 5 4 4 1 5 4 4 1 1
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 0
Here is a possible interaction:
$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
...
>>> from frieze import *
>>> frieze = Frieze(’frieze_6.txt’)
>>> frieze.analyse()
Pattern is a frieze of period 4 that is invariant under translation,
glided horizontal and vertical reflections, and rotation only.
>>> frieze.display()
The e ect of executing frieze.display() is to produce a le named frieze_6.tex that can be given
as argument to pdflatex to produce a le named frieze_6.pdf that views as follows.
7
2.7 Seventh example
The le frieze_7.txt has the following contents.
4 4 12 4 4 4 12 4 4 4 12 4 4 4 12 4 4 4 12 4 4 4 12 4 0
0 2 0 8 0 2 0 8 0 2 0 8 0 2 0 8 0 2 0 8 0 2 0 8 0
10 0 8 0 10 0 8 0 10 0 8 0 10 0 8 0 10 0 8 0 10 0 8 0 0
0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0
10 0 2 0 10 0 2 0 10 0 2 0 10 0 2 0 10 0 2 0 10 0 2 0 0
0 8 0 2 0 8 0 2 0 8 0 2 0 8 0 2 0 8 0 2 0 8 0 2 0
4 4 6 4 4 4 6 4 4 4 6 4 4 4 6 4 4 4 6 4 4 4 6 4 0
Here is a possible interaction:
$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
...
>>> from frieze import *
>>> frieze = Frieze(’frieze_7.txt’)
>>> frieze.analyse()
Pattern is a frieze of period 4 that is invariant under translation,
horizontal and vertical reflections, and rotation only.
>>> frieze.display()
The e ect of executing frieze.display() is to produce a le named frieze_7.tex that can be given
as argument to pdflatex to produce a le named frieze_7.pdf that views as follows.
8
3 Detailed description
3.1 Input
The input is expected to consist of height + 1 lines of length + 1 numbers in f0;:::;15g, where length
is at least equal to 4 and at most equal to 50 and height is at least equal to 2 and at most equal to 16,
with possibly lines consisting of spaces only that will be ignored and with possibly spaces anywhere on
the lines with digits. The xth digit n of the yth line, with 0 x length and 0 y height,
is to be associated with a point situated x? 0:2 cm to the right and y? 0.2 cm below an origin,
is to be connected to the point 0.2 cm above if the rightmost digit of n is 1,
is to be connected to the point 0.2 cm above and 0.2 cm to the right if the second rightmost digit
of n is 1,
is to be connected to the point 0.2 cm to the right if the third rightmost digit of n is 1, and
is to be connected to the point 0.2 cm to the right and 0.2 cm below if the fourth rightmost digit
of n is 1.
To qualify as a frieze, the input is further constrained to t in a rectangle of length length? 0:2 cm and
of height heigth? 0:2 cm, with horizontal lines of length length at the top and at the bottom, identical
vertical borders at both ends, no crossing segments connecting pairs of neighbours inside the rectangle,
and a pattern of integral period at least equal to 2 that is fully repeated at least twice in the horizontal
dimension.
3.2 Output
Consider executing from the Python prompt the statement from frieze import * followed by the
statement frieze = Frieze(some_filename). In case some_filename does not exit in the working
directory, then Python will raise a FileNotFoundError exception, that does not need to be caught.
Assume that some_filename does exit (in the working directory). If the input is incorrect in that it
does not contain only numbers in f0;:::;15g besides spaces, or in that it contains either two few or too
many lines of numbers, or in that some line of numbers contains too many or two few numbers, or in
that two of its lines of numbers do not contain the same number of numbers, then the e ect of executing
frieze = Frieze(some_filename) should be to generate a FriezeError exception that reads
Traceback (most recent call last):
...
frieze.FriezeError: Incorrect input.
If the previous conditions hold but the further conditions spelled out above for the input to qualify as a
frieze do not hold, then the e ect of executing frieze = Frieze(some_filename) should be to generate
a FriezeError exception that reads
9
Traceback (most recent call last):
...
frieze.FriezeError: Input does not represent a frieze.
If the input is correct and represents a frieze, then executing frieze = Frieze(some_filename) followed
by frieze.analyse() should have the e ect of outputting one or two lines that read
Pattern is a frieze of period N that is invariant under translation only.
or
Pattern is a frieze of period N that is invariant under translation
and vertical reflection only.
or
Pattern is a frieze of period N that is invariant under translation
and horizontal reflection only.
or
Pattern is a frieze of period N that is invariant under translation
and glided horizontal reflection only.
or
Pattern is a frieze of period N that is invariant under translation
and rotation only.
or
Pattern is a frieze of period N that is invariant under translation,
glided horizontal and vertical reflections, and rotation only.
or
Pattern is a frieze of period N that is invariant under translation,
horizontal and vertical reflections, and rotation only.
with N an appropriate integer at least equal to 2.
These 7 possible outputs are based on a mathematical result on the classi cation of friezes that lists
all possible complete lists of symmetries that leave a frieze invariant under an isometry (that is, a
transformation that does not alter the distance between any two points). These possible lists involve 5
symmetries.
10
Translation by period; of course, any frieze is invariant under this symmetry.
Vertical re ection about some vertical line; that line does not necessarily delimit the pattern nor
does it necessarily go through its middle (these conditions are actually equivalent).
Horizontal re ection about the line that goes through the middle of the frieze.
Glided horizontal re ection, that is, horizontal re ection about the line that goes through the
middle of the frieze and translation by half the period of the resulting lower half of the frieze.
Rotation around some point situated on the horizontal line that goes through the middle of the
frieze; this is equivalent to horizontal refection combined with vertical re ection.
Pay attention to the expected format, including spaces.
If the input is correct and represents a frieze, then executing frieze = Frieze(some_filename) followed
by frieze.display() should have the e ect of producing a le named some_filename.tex that can be
given as argument to pdflatex to generate a le named some_filename.pdf. The provided examples
will show you what some_filename.tex should contain. Segments are drawn in purple with a single
draw command for each longest segment,
starting with the vertical segments, from the topmost leftmost one to the bottommost rightmost
one with the leftmost ones rst,
followed by the segments that go from north west to south east, from the topmost leftmost one to
the bottommost rightmost one with the topmost ones rst,
followed by the segments that go from west to east, from the topmost leftmost one to the bottom-
most rightmost one with the topmost ones rst,
followed by the segments that go from the south west to the north east, from the topmost leftmost
one to the bottommost rightmost one with the topmost ones rst.
Pay attention to the expected format, including spaces and blank lines. Lines that start with % are
comments; there are 4 such lines, that have to be present even when there is no item to be displayed of
the kind described by the comment. The output of your program redirected to a le will be compared
with the expected output saved in a le (of a di erent name of course) using the diff command. For
your program to pass the associated test, diff should silently exit, which requires that the contents of
both les be absolutely identical, character for character, including spaces and blank lines. Check your
program on the provided examples using the associated .tex les, renaming them as they have the names
of the les expected to be generated by your program.
4 Assessment and submission
4.1 Submission
Your program will be stored in a le which has to be named frieze.py. Your code can be submitted
more than once on Ed; the last version and only the last version will be run, tested and marked. Your
assignment is due by May 27, 11:59pm.
4.2 Assessment
The automarking script. will let each both assessed methods of your program run for 30 seconds. Still
you should not take advantage of this and strive for a solution that gives an immediate output.
Late assignments will be penalised: the mark for a late submission will be the minimum of the awarded
mark and 10 minus the number of full and partial days that have elapsed from the due date.
4.3 Reminder on plagiarism policy
You are permitted, indeed encouraged, to discuss ways to solve the assignment with other people. Such
discussions must be in terms of algorithms, not code. But you must implement the solution on your
own. Submissions are routinely scanned for similarities that occur when students copy and modify other
people’s work, or work very closely together on a single implementation. Severe penalties apply.