# Path: slabbe/language.py
# class RegularLanguage(Language):
#     r"""
#     Regular language
# 
#     INPUT:
# 
#     - ``alphabet`` -- iterable of letters
#     - ``automaton`` -- finite state automaton
# 
#     EXAMPLES::
# 
#         sage: from slabbe.language import RegularLanguage
#         sage: alphabet = ['a', 'b']
#         sage: trans = [(0, 1, 'a'), (1, 2, 'b'), (2, 3, 'b'), (3, 4, 'a')]
#         sage: automaton = Automaton(trans, initial_states=[0], final_states=[4])
#         sage: RegularLanguage(alphabet, automaton)
#         Regular language over ['a', 'b']
#         defined by: Automaton with 5 states
#     """
#     def __init__(self, alphabet, automaton):
#         r"""
#         EXAMPLES::
# 
#             sage: from slabbe.language import RegularLanguage
#             sage: alphabet = ['a', 'b']
#             sage: trans = [(0, 1, 'a'), (1, 2, 'b'), (2, 3, 'b'), (3, 4, 'a')]
#             sage: automaton = Automaton(trans, initial_states=[0], final_states=[4])
#             sage: R = RegularLanguage(alphabet, automaton)
#         """
#         Language.__init__(self, alphabet)
#         self._automaton = automaton
# 
# 
#     def __repr__(self):
#         r"""
#         EXAMPLES::
# 
#             sage: from slabbe.language import RegularLanguage
#             sage: alphabet = ['a', 'b']
#             sage: trans = [(0, 1, 'a'), (1, 2, 'b'), (2, 3, 'b'), (3, 4, 'a')]
#             sage: automaton = Automaton(trans, initial_states=[0], final_states=[4])
#             sage: RegularLanguage(alphabet, automaton)
#             Regular language over ['a', 'b']
#             defined by: Automaton with 5 states
#         """
#         s = "Regular language over {}\ndefined by: {}"
#         return s.format(self._alphabet, self._automaton)
# 
#     def words_of_length_iterator(self, length):
#         r"""
#         Return an iterator over words of given length.
# 
#         INPUT:
# 
#         - ``length`` -- integer
# 
#         EXAMPLES::
# 
#             sage: from slabbe.language import RegularLanguage
#             sage: alphabet = ['a', 'b']
#             sage: trans = [(0, 1, 'a'), (1, 2, 'b'), (2, 3, 'b'), (3, 4, 'a')]
#             sage: automaton = Automaton(trans, initial_states=[0], final_states=[4])
#             sage: R = RegularLanguage(alphabet, automaton)
#             sage: [list(R.words_of_length_iterator(i)) for i in range(6)]
#             [[], [], [], [], [word: abba], []]
#         """
#         it = super(RegularLanguage, self).words_of_length_iterator(length)
#         return [a for a in it if self._automaton(a)]
# 
# Path: slabbe/matrices.py
# def projection_matrix(dim_from=3, dim_to=2):
#     r"""
#     Return a projection matrix from R^d to R^l.
# 
#     INPUT:
# 
#     - ``dim_from` -- integer (default: ``3``)
#     - ``dim_to` -- integer (default: ``2``)
# 
#     OUTPUT:
# 
#         matrix
# 
#     EXAMPLES::
# 
#         sage: from slabbe.matrices import projection_matrix
#         sage: projection_matrix(3,2)
#         [-0.866025403784439  0.866025403784439  0.000000000000000]
#         [-0.500000000000000 -0.500000000000000   1.00000000000000]
#         sage: projection_matrix(2,3)
#         [-0.577350269189626 -0.333333333333333]
#         [ 0.577350269189626 -0.333333333333333]
#         [ 0.000000000000000  0.666666666666667]
#     """
#     from math import sqrt
#     from sage.rings.real_mpfr import RR
#     sqrt3 = sqrt(3)
#     if dim_from == 3 and dim_to == 2:
#         return matrix(2,[-sqrt3,sqrt3,0,-1,-1,2],ring=RR)/2
#     elif dim_from == 2 and dim_to == 3:
#         return matrix(3,[-sqrt3,-1,sqrt3,-1,0,2],ring=RR)/3
#     elif dim_from == 4 and dim_to == 2:
#         return matrix(2,[-sqrt3,sqrt3,0,1,-1,-1,2,0],ring=RR)/2
#     elif dim_from == 4 and dim_to == 3:
#         sqrt2 = sqrt(2)
#         return matrix([(1,-1,0,0), 
#                        (0,0,1,-1),
#                        (-1/sqrt2,-1/sqrt2,1/sqrt2,1/sqrt2)],
#                        ring=RR)
#     else:
#         s = "for input dim_from={} and dim_to={}"
#         raise NotImplementedError(s.format(dim_from, dim_to))


import itertools
from sage.misc.cachefunc import cached_method
from sage.misc.misc_c import prod
from sage.matrix.constructor import matrix
from sage.combinat.finite_state_machine import Automaton
from .language import RegularLanguage
from .matrices import projection_matrix
        from sage.rings.finite_rings.integer_mod_ring import Integers
        from sage.plot.graphics import Graphics
        from sage.plot.polygon import polygon
        from sage.plot.text import text
        from slabbe import TikzPicture
          takes value True if n is 1.

        EXAMPLES::

            sage: from slabbe.markov_transformation import markov_transformations
            sage: T = markov_transformations.Selmer()
            sage: t = T.tikz_n_cylinders(1, labels=True, scale=4)
            sage: t
            \documentclass[tikz]{standalone}
            \usepackage{amsmath}
            \begin{document}
            \begin{tikzpicture}
            [scale=4]
            ...
            ... 56 lines not printed (2702 characters in total) ...
            ...
            \end{tikzpicture}
            \end{document}

        ::

            sage: from sage.misc.temporary_file import tmp_filename
            sage: filename = tmp_filename('temp','.pdf')
            sage: _ = t.pdf(filename)
        """
        if labels is None:
            labels = True if n == 1 else False
        lines = []
        lines.append(r"\begin{tikzpicture}")
        lines.append("[scale={}]".format(scale))

# Path: slabbe/language.py
# class RegularLanguage(Language):
#     r"""
#     Regular language
# 
#     INPUT:
# 
#     - ``alphabet`` -- iterable of letters
#     - ``automaton`` -- finite state automaton
# 
#     EXAMPLES::
# 
#         sage: from slabbe.language import RegularLanguage
#         sage: alphabet = ['a', 'b']
#         sage: trans = [(0, 1, 'a'), (1, 2, 'b'), (2, 3, 'b'), (3, 4, 'a')]
#         sage: automaton = Automaton(trans, initial_states=[0], final_states=[4])
#         sage: RegularLanguage(alphabet, automaton)
#         Regular language over ['a', 'b']
#         defined by: Automaton with 5 states
#     """
#     def __init__(self, alphabet, automaton):
#         r"""
#         EXAMPLES::
# 
#             sage: from slabbe.language import RegularLanguage
#             sage: alphabet = ['a', 'b']
#             sage: trans = [(0, 1, 'a'), (1, 2, 'b'), (2, 3, 'b'), (3, 4, 'a')]
#             sage: automaton = Automaton(trans, initial_states=[0], final_states=[4])
#             sage: R = RegularLanguage(alphabet, automaton)
#         """
#         Language.__init__(self, alphabet)
#         self._automaton = automaton
# 
# 
#     def __repr__(self):
#         r"""
#         EXAMPLES::
# 
#             sage: from slabbe.language import RegularLanguage
#             sage: alphabet = ['a', 'b']
#             sage: trans = [(0, 1, 'a'), (1, 2, 'b'), (2, 3, 'b'), (3, 4, 'a')]
#             sage: automaton = Automaton(trans, initial_states=[0], final_states=[4])
#             sage: RegularLanguage(alphabet, automaton)
#             Regular language over ['a', 'b']
#             defined by: Automaton with 5 states
#         """
#         s = "Regular language over {}\ndefined by: {}"
#         return s.format(self._alphabet, self._automaton)
# 
#     def words_of_length_iterator(self, length):
#         r"""
#         Return an iterator over words of given length.
# 
#         INPUT:
# 
#         - ``length`` -- integer
# 
#         EXAMPLES::
# 
#             sage: from slabbe.language import RegularLanguage
#             sage: alphabet = ['a', 'b']
#             sage: trans = [(0, 1, 'a'), (1, 2, 'b'), (2, 3, 'b'), (3, 4, 'a')]
#             sage: automaton = Automaton(trans, initial_states=[0], final_states=[4])
#             sage: R = RegularLanguage(alphabet, automaton)
#             sage: [list(R.words_of_length_iterator(i)) for i in range(6)]
#             [[], [], [], [], [word: abba], []]
#         """
#         it = super(RegularLanguage, self).words_of_length_iterator(length)
#         return [a for a in it if self._automaton(a)]
# 
# Path: slabbe/matrices.py
# def projection_matrix(dim_from=3, dim_to=2):
#     r"""
#     Return a projection matrix from R^d to R^l.
# 
#     INPUT:
# 
#     - ``dim_from` -- integer (default: ``3``)
#     - ``dim_to` -- integer (default: ``2``)
# 
#     OUTPUT:
# 
#         matrix
# 
#     EXAMPLES::
# 
#         sage: from slabbe.matrices import projection_matrix
#         sage: projection_matrix(3,2)
#         [-0.866025403784439  0.866025403784439  0.000000000000000]
#         [-0.500000000000000 -0.500000000000000   1.00000000000000]
#         sage: projection_matrix(2,3)
#         [-0.577350269189626 -0.333333333333333]
#         [ 0.577350269189626 -0.333333333333333]
#         [ 0.000000000000000  0.666666666666667]
#     """
#     from math import sqrt
#     from sage.rings.real_mpfr import RR
#     sqrt3 = sqrt(3)
#     if dim_from == 3 and dim_to == 2:
#         return matrix(2,[-sqrt3,sqrt3,0,-1,-1,2],ring=RR)/2
#     elif dim_from == 2 and dim_to == 3:
#         return matrix(3,[-sqrt3,-1,sqrt3,-1,0,2],ring=RR)/3
#     elif dim_from == 4 and dim_to == 2:
#         return matrix(2,[-sqrt3,sqrt3,0,1,-1,-1,2,0],ring=RR)/2
#     elif dim_from == 4 and dim_to == 3:
#         sqrt2 = sqrt(2)
#         return matrix([(1,-1,0,0), 
#                        (0,0,1,-1),
#                        (-1/sqrt2,-1/sqrt2,1/sqrt2,1/sqrt2)],
#                        ring=RR)
#     else:
#         s = "for input dim_from={} and dim_to={}"
#         raise NotImplementedError(s.format(dim_from, dim_to))


# Path: slabbe/markov_transformation.py
import itertools
from sage.misc.cachefunc import cached_method
from sage.misc.misc_c import prod
from sage.matrix.constructor import matrix
from sage.combinat.finite_state_machine import Automaton
from .language import RegularLanguage
from .matrices import projection_matrix
        from sage.rings.finite_rings.integer_mod_ring import Integers
        from sage.plot.graphics import Graphics
        from sage.plot.polygon import polygon
        from sage.plot.text import text
        from slabbe import TikzPicture

          takes value True if n is 1.

        EXAMPLES::

            sage: from slabbe.markov_transformation import markov_transformations
            sage: T = markov_transformations.Selmer()
            sage: t = T.tikz_n_cylinders(1, labels=True, scale=4)
            sage: t
            \documentclass[tikz]{standalone}
            \usepackage{amsmath}
            \begin{document}
            \begin{tikzpicture}
            [scale=4]
            ...
            ... 56 lines not printed (2702 characters in total) ...
            ...
            \end{tikzpicture}
            \end{document}

        ::

            sage: from sage.misc.temporary_file import tmp_filename
            sage: filename = tmp_filename('temp','.pdf')
            sage: _ = t.pdf(filename)
        """
        if labels is None:
            labels = True if n == 1 else False
        lines = []
        lines.append(r"\begin{tikzpicture}")
        lines.append("[scale={}]".format(scale))

        M3to2 = projection_matrix(3, 2)