Skip to content

Commit 69fd49c

Browse files
committed
Working on tests for the examples in the paper.
1 parent 5d25d01 commit 69fd49c

File tree

3 files changed

+87
-25
lines changed

3 files changed

+87
-25
lines changed

scripts/test_quasinormal.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@
33

44
from thompson.word import Word
55

6-
print('importing example_4_25')
7-
from thompson.examples import example_4_25 as ex
8-
ex.dump_mapping()
9-
ex.dump_mapping(inverse=True)
6+
from thompson.examples import example_4_5 as aut
107

11-
basis = ex.quasinormal_basis()
12-
print(basis)
8+
9+
10+
aut.dump_mapping()
11+
12+
basis = aut.domain
13+
print('basis is', basis)
14+
15+
results = {
16+
Word("x a1 a1 a1", 2, 1) : "left semi-infinite",
17+
Word("x a1 a2", 2, 1) : "right semi-infinite",
18+
Word("x a1 a1 a2", 2, 1) : "complete infinite",
19+
Word("x a2", 2, 1) : "incomplete",
20+
}
21+
22+
for word, expected in results.items():
23+
otype = aut._orbit_type(word, basis)
24+
print(word, 'should have type', expected)
25+
print(otype)
26+
27+
28+
# basis = ex.quasinormal_basis()
29+
# print(basis)

thompson/automorphism.py

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def _reduce(domain, range):
127127
"""Contracts the domain generators whenever the corresponding contraction in range is possible. (This corresponds to reducing a tree pair diagram.)
128128
129129
>>> from thompson.examples import cyclic_order_six as cyclic
130+
>>> #This is given by 6 generators, but after reduction consists of 5:
130131
>>> for d, r in zip(cyclic.domain, cyclic.range):
131132
... print(d, '->', r)
132133
x1 a1 a1 -> x1 a1 a1
@@ -329,18 +330,22 @@ def dump_mapping(self, inverse=False, **kwargs):
329330

330331
#Operations on automorphisms
331332
def quasinormal_basis(self):
332-
r"""An implementation of Lemma 4.24.1. In [Hig]_ (section 9) Higman defines when an automorphism :math:`\phi` is in *quasinormal form* with respect to a given basis :math:`X`. We return the basis :math:`X` w.r.t which the current automorphism is in quasinormal form.
333+
r"""An implementation of Lemma 4.24.1. In [Hig]_ (section 9) Higman defines when an automorphism :math:`\phi` is in *quasinormal form* with respect to a given basis :math:`X`. We return the basis :math:`X` w.r.t which the current automorphism is in quasinormal form.
334+
335+
>>> from thompson.examples import *
336+
>>> example_4_5.quasinormal_basis()
337+
Generators(2, 1, ['x1 a1 a1', 'x1 a1 a2', 'x1 a2 a1', 'x1 a2 a2'])
333338
"""
334339
#TODO finish me and test me to high heaven.
335340
basis = self._minimal_expansion()
336-
print(basis)
341+
# print(basis)
337342
#expand basis until each no element's orbit has finite intersection with X<A>
338343
i = 0
339344
while i < len(basis):
340345
type = self._orbit_type(basis[i], basis)
341-
print("Orbit type:", type, '\n')
346+
# print("Orbit type:", type, '\n')
342347
if type is Orbit.incomplete:
343-
print('expand basis')
348+
# print('expand basis')
344349
basis.expand(i)
345350
else:
346351
i += 1
@@ -350,14 +355,16 @@ def _minimal_expansion(self):
350355
r"""Returns the minimal expansion :math:`X` of :math:`\boldsymbol{x}` such that every element of :math:`X` belongs to either *self.domain* or *self.range*. Put differently, this is the minimal expansion of :math:`\boldsymbol{x}` which does not contain any elements which are above :math:`Y \cup W`. See example 4.25.
351356
352357
>>> from thompson.examples import *
353-
>>> cyclic_order_six._minimal_expansion()
354-
Generators(2, 1, ['x1 a1 a1', 'x1 a1 a2 a1', 'x1 a1 a2 a2', 'x1 a2'])
358+
>>> example_4_5._minimal_expansion()
359+
Generators(2, 1, ['x1 a1 a1', 'x1 a1 a2', 'x1 a2 a1', 'x1 a2 a2'])
355360
>>> example_4_11._minimal_expansion()
356361
Generators(2, 1, ['x1 a1', 'x1 a2'])
357362
>>> example_4_12._minimal_expansion()
358363
Generators(2, 1, ['x1 a1', 'x1 a2'])
359364
>>> example_4_25._minimal_expansion()
360365
Generators(2, 1, ['x1 a1', 'x1 a2 a1', 'x1 a2 a2'])
366+
>>> cyclic_order_six._minimal_expansion()
367+
Generators(2, 1, ['x1 a1 a1', 'x1 a1 a2 a1', 'x1 a1 a2 a2', 'x1 a2'])
361368
"""
362369
#TODO arity 3 example, alphabet size > 1 example.
363370
basis = Generators.standard_basis(self.arity, self.alphabet_size)
@@ -373,19 +380,61 @@ def _minimal_expansion(self):
373380
def _orbit_type(self, y, basis):
374381
"""Returns the orbit type of *y* with respect to the given *basis*.
375382
376-
>>> from thompson.examples import example_4_25 as ex
377-
>>> basis = ex._minimal_expansion()
378-
>>> ex._orbit_type(Word("x a1", 2, 1), basis)
379-
<Orbit.right_semi_infinite: 3>
383+
>>> from thompson.examples import *
384+
>>> def f(word, aut, basis=None):
385+
... if basis is None:
386+
... basis = aut._minimal_expansion()
387+
... print(aut._orbit_type(word, basis))
388+
389+
>>> #Example 4.5.
390+
>>> for w in ["x", "x a1", "x a1 a1", "x a1 a1 a1", "x a1 a1 a2", "x a1 a2", "x a2", "x a1 a1 a1 a1 a2 a2 a1 a2 a1"]:
391+
... f(Word(w, 2, 1), example_4_5, example_4_5.domain)
392+
Orbit.incomplete
393+
Orbit.incomplete
394+
Orbit.left_semi_infinite
395+
Orbit.left_semi_infinite
396+
Orbit.complete_infinite
397+
Orbit.right_semi_infinite
398+
Orbit.incomplete
399+
Orbit.complete_infinite
400+
401+
>>> #Example 4.11
402+
>>> for w in ["x1 a1", "x1 a2"]:
403+
... f(Word(w, 2, 1), example_4_11)
404+
Orbit.left_semi_infinite
405+
Orbit.right_semi_infinite
406+
407+
>>> #Example 4.12
408+
>>> basis = example_4_12._minimal_expansion()
409+
>>> for w in basis:
410+
... print(w, ':', sep='', end=' ')
411+
... f(Word(w, 2, 1), example_4_12, basis)
412+
Orbit.incomplete
413+
Orbit.incomplete
414+
>>> basis.expand(0)
415+
>>> for w in basis:
416+
... print(w, ':', sep='', end=' ')
417+
... f(Word(w, 2, 1), example_4_12, basis)
418+
x1 a1 a1: Orbit.complete_infinite
419+
x1 a1 a2: Orbit.complete_infinite
420+
x1 a2: Orbit.incomplete
421+
>>> basis.expand(2)
422+
>>> for w in basis:
423+
... print(w, ':', sep='', end=' ')
424+
... f(Word(w, 2, 1), example_4_12, basis)
425+
x1 a1 a1: Orbit.complete_infinite
426+
x1 a1 a2: Orbit.complete_infinite
427+
x1 a2 a1: Orbit.complete_infinite
428+
x1 a2 a2: Orbit.complete_infinite
380429
"""
381430
#TODO. Tests from the examples
382-
print('Forward Orbit for', y)
431+
# print('Forward Orbit for', y)
383432
right_infinite = self._test_semi_infinite(y, basis, backward=False)
384433
if isinstance(right_infinite, Orbit):
385434
return right_infinite #periodic
386-
print('right_infinite:', right_infinite)
435+
# print('right_infinite:', right_infinite)
387436

388-
print('Backward orbit for', y)
437+
# print('Backward orbit for', y)
389438
left_infinite = self._test_semi_infinite(y, basis, backward=True)
390439
assert not isinstance(left_infinite, Orbit), "Orbit is not periodic going forward but is going backward."
391440

@@ -407,7 +456,7 @@ def _test_semi_infinite(self, y, basis, backward=False):
407456
while True:
408457
#Compute the image y\phi^i as y\phi^{i-1} \phi
409458
image = self.image(image, inverse=backward)
410-
print('power #', len(images), 'is', image)
459+
# print('power #', len(images), 'is', image)
411460
#1. Is this image in X<A>?
412461
if not basis.is_above(image): #not in X<A>
413462
return False #NOT semi_infinite in the given direction

thompson/examples.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,20 @@
77
"example_4_5", "example_4_11", "example_4_12", "example_4_25"]
88

99
#Example 4.5
10-
#TODO minimal expansion and orbit types
1110
domain = Generators(2, 1, ["x1 a1 a1 a1", "x1 a1 a1 a2", "x1 a1 a2", "x1 a2 a1", "x1 a2 a2"])
1211
range = Generators(2, 1, ["x1 a1 a1", "x1 a1 a2 a1", "x1 a1 a2 a2", "x1 a2 a2", "x1 a2 a1"])
1312
example_4_5 = Automorphism(2, 1, domain, range)
14-
#See example 4.7 for more details
15-
#See example 4.13 for SNF (QNF)?
1613
#See example e.18 for characteristics
1714

1815
#Example 4.11
19-
#TODO minimal expansion and orbit types
2016
#TODO. I think this is a special element of one of Thompson's groups.
2117
#I should put those examples in the automorphism module.
2218
domain = Generators(2, 1, ["x a1 a1", "x a1 a2", "x a2"])
2319
range = Generators(2, 1, ["x a1", "x a2 a1", "x a2 a2"])
2420
example_4_11 = Automorphism(2, 1, domain, range)
2521

2622
#Example 4.12
27-
#TODO minimal expansion and orbit types, semi-normal form
23+
#TODO minimal expansion and orbit types, semi-normal form (in progress)
2824
domain = Generators(2, 1, ["x a1 a1", "x a1 a2", "x a2"])
2925
range = Generators(2, 1, ["x a2 a2", "x a2 a1", "x a1"])
3026
example_4_12 = Automorphism(2, 1, domain, range)

0 commit comments

Comments
 (0)