Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
181 views
unlisted
ubuntu2004
o

��c��@s�dZddlmZddlZddlmZddlmZddlmZm	Z	ddl
mZmZddl
mZdd	lmZd
dlmZd
dlmZmZmZmZmZmZee	d
d
dd�Ze��ZGdd�d�Zdd�Zd>dd�Zd>dd�Z d>dd�Z!efdd�Z"efdd�Z#dd �Z$d!efd"d#�Z%d!efd$d%�Z&d!efd&d'�Z'd!efd(d)�Z(ed!efd*d+��Z)ed!efd,d-��Z*ed!efd.d/��Z+ed!efd0d1��Z,ed!efd2d3��Z-ed!efd4d5��Z.ed!efd6d7��Z/ed!efd8d9��Z0defd:d;�Z1ed!efd<d=��Z2dS)?z�
Generators of tautological ring

Each generator is called a stratum and is encoded in a class class:`Graph`. A
stratum is called *pure* if it has neither kappa nor psi marking (ie a stable
graph with no decoration).
�)�copyN)�cached_function)�lazy_attribute)�PolynomialRing�ZZ)�IntegerVectors�
Partitions)�floor)�matrix�)�aut)�	MODULI_SM�	MODULI_RT�	MODULI_CT�	MODULI_ST�MODULI_SMALL�dim_form�lex)�X)�order�namesc@s�eZdZdZd&dd�Zdd�Zedd��Zed	d
��Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
d'dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdS)(�Grapha�
    A decorated graph representing a tautological class.

    The graph is encoded as a matrix where

    - each row after the first one corresponds to a vertex
    - each column after the first one corresponds to an edge or leg
    - the first column gives the genera of the vertices
    - the first row gives the markings on the legs
    - the other cells are
      - 0 if the vertex and edge/leg are not incident
      - 1 if the vertex and edge/leg are incident once
      - 2 if the edge is a loop at the vertex
    - entries with polynomials in X describe kappa/psi decorations:
    - in the first column, each X^n term corresponds to a kappa_n at that
      vertex
    - in other locations, each X term corresponds to a psi at that half-edge
    - at loops, 2 + aX + bX^2 corresponds to having psi^a on one side of the
      loop and psi^b on the other

    EXAMPLES::

        sage: from admcycles.DR.graph import Graph, X
        sage: gr = Graph(matrix(2, 3, [-1, 1, 2, 1, X + 1, 1]))
        sage: gr
        [   -1     1     2]
        [    1 X + 1     1]
        sage: gr.num_vertices()
        1
        sage: gr.num_edges()
        2
    NcCsL|r	t|�|_dS|rttt|�dddg|�|_dSttddd�|_dS)Nr�����)r�Mr
�R�len)�selfrZ
genus_list�r�6/home/user/Introduction lectures/admcycles/DR/graph.py�__init__<s

�zGraph.__init__cCs
t|j�S�N)�reprr�rrrr�__repr__Es
zGraph.__repr__cCspdd�td|j���D�}td|j���D]}td|j���D]}||d|j||fd7<qqt|�S)z�
        Return the tuple of degrees of vertices.

        EXAMPLES::

            sage: from admcycles.DR.graph import Graph, X
            sage: gr = Graph(matrix(2, 3, [-1, 1, 2, 1, X + 1, 1]))
            sage: gr.degree_vec
            (2,)
        cS�g|]}d�qS�rr��.0�irrr�
<listcomp>T�z$Graph.degree_vec.<locals>.<listcomp>rr)�ranger�nrows�ncols�tuple)r�resr(�jrrr�
degree_vecHs$�zGraph.degree_veccCs�d}td|j���D]V}d|j|dfd}td|j���D]}||j||fd|j||fd7}qtd|j|df��d�D]}|||j|df|7}qD|d;}|||d>7}q
|S)Nrr�)r+rr,r-�degree)r�ansr(Zlocal_parityr0rrr�
target_parityZs* zGraph.target_paritycCs|j|dS)z4
        Return the degree of vertex ``i``.
        r)r1�rr(rrrr3gszGraph.degreecC�|j��dS�Nr)rr,r"rrr�num_verticesm�zGraph.num_verticescCr7r8)rr-r"rrr�	num_edgespr:zGraph.num_edgescCs|j��|j��dSr8)rr-r,r"rrr�h1sszGraph.h1cCs(|j�td|j����|_||jd<dS)Nr)rr)r�stackr
r-)r�grrr�
add_vertexvszGraph.add_vertexrcCsh|j�t|j��d��|_||jd<|dkr!|j|dfd7<|dkr2|j|dfd7<dSdS)Nr)rrrr)r�augmentr
r,)r�i1�i2�markingrrr�add_edgezs
�zGraph.add_edgecCs(|jd|��|j|dd��|_dSr8)rr=r6rrr�
del_vertex�s(zGraph.del_vertexcCs`||��kr|jdd�d|�f|_dS|jdd�d|�f�|jdd�|dd�f�|_dS)Nrr)r;rr@r6rrr�del_edge�s8zGraph.del_edgecCsN|j�td|j��||��|_|�|j��d|j��d�|�|�dS)Nr2r)rr=r
r-rDr,rE)rr(�row1�row2rrr�split_vertex�s
 �zGraph.split_vertexcCs�|��}|��}g}g}dg}d}td|j���D]*}	|jd|	fdkr>|jd|	fdkr1|d7}|�|jd|	f|�q|�d�qtd|j���D]$}	t|j||	fd�D]}
|jd|	fdkrj|�|	�qY|�|	�qYqL||}|�|�t|��t|��D]}
|�dd�q�t|���D]}
|�	|j|
ddf�q�|d}td|j���D]�}	|jd|	fdk�r1t
||	�}
t|���D]i}
|j||
||
dfdkr�|j|
d|	f|j||
||
df<q�|j|
d|	fdk�r/|j||
||
dfd}|j|
d|	fd}dt||�tt
||�td|j||
||
df<q�q�t|���D]}
|j|
d|	f|j||
|f<�q7|d7}q�dS)Nrrrr2)r9r;r+rr-�appendrErrDr?r�maxr�min)rr(�G�nv�neZhedge_list_onesZhedge_list_othersZ
unsym_colsZmark_nr�kr0Z
hedge_list�col�mark�a�brrr�replace_vertex_with_graph�sZ�
*����	$
�zGraph.replace_vertex_with_graphcs��j���j���}��fdd�td��D��_td|�D]����fdd�td��D�}t|�dkro�jd�fdkrY�j|ddd��jd�f�j|d�ff�q�j|ddd��j|d�f�q�j|ddd|dd��j|d�f�j|d�ff��j|ddd|dd��j|d�f�j|d�ff�qtd��D]�}dd��j|ddD��j|dd<tt�j|dd��D]%��j|dd���t�j|dd���j|dd�<q�j|dd��t�j|dd��j|dd<�j|dd��t�j|dd��j|dd<�j|dd��t�j|dd��j|dd<t�j|d��j|d<q��fd	d�td��D�}�j��t�j��_|jd
d�d�g�_	t�d�D])}|dk�s�||d||ddk�r��j	�g��j	d
�||d��q�dS)Nc	s2g|]}�j|dfggdd�td��D�g�qS)rcS�g|]}g�qSrr�r'r0rrrr)�s�z6Graph.compute_invariant.<locals>.<listcomp>.<listcomp>r)rr+r&)�nrrrrr)�s
��z+Graph.compute_invariant.<locals>.<listcomp>rc�"g|]
}�j|�fdkr|�qSr%�rr&)rPrrrr)��
�rr2�cSsg|]}t|�r|�qSr)r)r'�termrrrr)�s
�csg|]}|�j|dg�qS�r)�	invariantr&r"rrr)�s�cSs|dSr8r)�xrrr�<lambda>�sz)Graph.compute_invariant.<locals>.<lambda>)�keyr)
rr,r-r+r_rrJ�sortr.�vertex_groupings)r�nc�Lr(Zvertex_invariantsr)rPrXrr�compute_invariant�sl�
��&,2�2�*����$$$
�
(

��zGraph.compute_invariantcCsLt|j���D]}t|j���D]}t|j||fd�|j||f<qqdS)Nr)r+rr,r-r)rr(r0rrr�purify�s
"��zGraph.purifycs|�jd�fdkrtd�dS��fdd�td�j���D�}t|�dkrI�j|ddfd7<����|d�d�|�d�}||fS����|d�d�|�d�}��d��jd�j|d7<�jd�j|d7<��|d���|d�|d|dd�||d|dd�||dd�||dd||ddg}||fS)Nrz ERROR: cannot contract a markingcrYr%rZ)r'�row�r(rrrr)�r[z"Graph.contract.<locals>.<listcomp>rr)r�printr+r,rrFr?rE)rr(�vlist�elist�Srrjr�contract�s0
�

�
*� �zGraph.contract)NNr%)�__name__�
__module__�__qualname__�__doc__rr#rr1r5r3r9r;r<r?rDrErFrIrUrgrhrorrrrrs*
 	


,,rc
Cs�|j|jkrdS|j}|j}|j}|j}|��}|��}tjdd�|D��D]�}dg|d}	tt|��D]}
tt||
��D]}||
||
||	||
|d<q?q5d}td|�D]~}
|	|
d}
td|
�D]j}|	|d}g}td|�D]!}||
|fdkr�|||fdkr�|�	||
|f|||fg�qx|�
�g}td|�D]!}||
|fdkr�|||fdkr�|�	||
|f|||fg�q�|�
�||kr�d}nqi|dur�nq\|r�dSq&dS)z:
    Return whether ``G1`` and ``G2`` are isomorphic.
    Fcs�"�|]}t�tt|���VqdSr ��	itertools�permutationsr+r�r'�grouprrr�	<genexpr>�� z#graph_isomorphic.<locals>.<genexpr>rrT�r_rrdr,r-rv�productr+rrJrc)�G1�G2�M1�M2�group1�group2rXre�
sigma_data�sigmar(r0�good�ii�jj�L1rP�L2rrr�graph_isomorphicsT&� � ����r�FcCst|j|j|�Sr )�count_automorphismsrrd)rM�
vertex_orbitsrrr�graph_count_automorphisms2sr�c
s�������}}t��}|rg}tjdd�|D��D]�}dd�t|d�D�}tt|��D]}	tt||	��D]}
||	||	|
|||	|
d<q8q.d}td|�D]|}	||	d}td|	�D]j}
||
d}
g}td|�D]!��|	�fdkr��|
�fdkr�|��|	�f�|
�fg�qq|�	�g}td|�D]!��|�fdkr��|
�fdkr�|��|�f�|
�fg�q�|�	�||kr�d}nqb|s�nqU|r�|d7}|r�|�|�q|�r4g}g�t��|dk�r2t
�fd	d�td|�D��}	g}|D]}||	d|v�r|�||	d���||	d��q|�	�|�|�t��|dks�|Std|�D]�}	td|�D]#��|	�fdd
k�rb�|	�fd�|	�fd
k�rb|d
9}�q@g}td|�D]-��|	�fdk�r�t��fdd�td|�D��dk�r�|��d�f�|	�fg��qk|t|�9}td|	�D]5}
g}td|�D]$��|	�fdk�rЈ|
�fdk�r�|��|	�f�|
�fg��q�|t|�9}�q��q9|S)z`
    INPUT:

    M: adjacency matrix
    grouping: list of lists
    vertex_orbits: boolean
    csrtr rurxrrrrzBr{z&count_automorphisms.<locals>.<genexpr>cSr$r%rr&rrrr)Cr*z'count_automorphisms.<locals>.<listcomp>rTrFc3s�|]	}|�vr|VqdSr r)r'r�)�
vertices_usedrrrzd��r2c3s$�|]
}�|�fdkrdVqdS)rrNrrW)rrPrrrzus�")
r,r-r�zerorvr}r+rrJrc�next�sumr)r�groupingr�rXre�count�	isom_listr�r�r(r0r�r�r�r�r�Z
orbit_list�orbitrfr)rrPr�rr�6s�&� � ���
��
�	8�$�$��r�c
sD|j|jkrgS|j�|j�|j}|j}�������}g}tjdd�|D��D�]v}dg�d�tt|��D]}tt||��D]}	|||||	�|||	d<qBq8d}
td��D]|}�|d}td|�D]j}	�|	d}g}
td|�D]!}�||fdkr��|	|fdkr�|
�	�||f�|	|fg�q{|
�
�g}td|�D]!}�||fdkrɈ||fdkr�|�	�||f�||fg�q�|�
�|
|kr�d}
nql|
s�nq_|
�r���fdd�td|�D�}���fd	d�td|�D�}g}g}g}td|�D]H}	|	|v�rL|�	g�|�	g�td|�D]0}||d||	dk�r6|d
�	|�|�	|�||d||	dk�rJ|d
�	|��q�qtjdd�|D��D]F}dd�t|d�D�}tt|��D]!}tt||��D]}	|||||	||||	d<�qu�qk|�	�|g�|�r�|S�qXq(|S)
z@
    Return the list of isomorphisms from ``G1`` to ``G2``.
    csrtr rurxrrrrz�r{z*graph_list_isomorphisms.<locals>.<genexpr>rrTFc�$g|]���fdd�t��D��qS)csg|]}�|�f�qSrrr&)r�r0rrr)�s�6graph_list_isomorphisms.<locals>.<listcomp>.<listcomp>�r+�r')r�rX�r0rr)�s$z+graph_list_isomorphisms.<locals>.<listcomp>cs6g|]��d�fg���fdd�td��D��qS)rcs g|]}��|d�f�qSr^rr&)r�r0r�rrr)�s r�rr�r�)r�rXr�r�rr)�s.�rcsrtr ru)r'Z
edge_grouprrrrz�r{cSr$r%rr&rrrr)�r*r|)r~rZonly_oner�r�rer�r�r(r0r�r�r�r�rPr�Zcols1Zcols2Zedge_group1Zedge_group2Zused1Zedge_sigma_dataZ
edge_sigmar)r�r�rXr�r�graph_list_isomorphisms�s�&� � ����



������r�cs�|d}|tkrtd}dd�t|�D�}t|�D]�}||D]�}td|��d�D]�}t|j|���dt��}|dkr@q*dd�tt���D��dd��D��kr�ddkr_|tkr_n��dt��dkr��dt��|dkr���fd	d�tt���D�}t	|j�}	|	�
|�|�|}
|
tkr�t}
|
tkr��ddkr�t}
||
�|	��d
d7<tdt���D]}�|�|kr�nd�|<�|dd7<q�dd��D��ksTq*qqt|�D]
}t
||�||<q�|S)z^
    Return the list of degenerations of the graphs in ``G_list`` up to
    isomorphisms.
    rcSrVrrr&rrrr)�r*zdegenerate.<locals>.<listcomp>r�cSr$r%rrWrrrr)�r*cSsg|]}d|�qS)r2r)r'r`rrrr)��r2csg|]
}�|�|�qSrrrW�rirGrrr)��r)rr
r+r9�listrr�rrrrIrrJ�remove_isomorphic)�G_list�moduli_type�mod_size�
G_list_new�
which_typerMr(�mrH�G_copy�new_typer0rr�r�
degenerate�sL,

����r�cs�|d}|tkrtd}dd�t|�D�}t|�D�]�}||D�]��dd�t|�D�}�j���j��}}g}	g}
td|�D]+�td|�D]#}�j�|fdkrZ|	��|g�qG�j�|fdkrj|
��|g�qGq@|d�t|	�}t|
�}
��fdd�t|�D�}t|�||
�D�]'�|}|tkr�d��}t|�D]�||	�dd���7<q�t|
�D]�||
�dd��|�7<q�t||�D]}t��D]�|�||�kr�|d}nq�q�||kr�q�g}t��D]�|�t	����q�t��|�D]�|���fd	d�tt
��td�d��D���q
tj
|�}|D]�}t�j�}t��D]�|�D]}|j�ddft|7<�qB�q<t��|�D]*�|j|	��d|	��df|�dt|�dtd7<�q^t|
�D]�|j|
�d|
�df���|t7<�q�||�|��q1q�t|�D]}||t||�7<�q�q q|S)
z6
    Add decorations to the graphs in ``G_list``.
    rcSrVrrr&rrrr)�r*zdecorate.<locals>.<listcomp>cSrVrrr&rrrr)�r*r2cr�)cs4g|]}t�j|ddfd��|d����qS)rr)rrr3r&)rM�mod_typerrr)	s,�z'decorate.<locals>.<listcomp>.<listcomp>r�r�)rMrS)r�rr)	s
�
�Nrcsg|]
}��||g�qSrrrW)r(�vecrrr)r�)rr
r+rr,r-rJrrrr	rrvr}rrr�)r��rr�r�r�r�ZG_decorXreZtwo_listZone_listr0rT�c�dimsr�Z	test_dimsr�ZS_listrn�vec2r�r)rMrSr(r�r�decorate�s����&*��*�

"��"
�
�
����4r�cCs�g}i}d}|D]8}|��|j|vrg||j<d}||jD]
}t|||�r,d}nq|r@|�|�||j�|�|d7}q|S)zY
    Return a list of isomorphism class representatives of the graphs in ``G_list``.
    rTFr)rgr_r�rJ)r�r��inv_dictr�r~r�r(rrrr�2s&

�
�r�rcC�tt||||��S)a�
    Return the number of strata in given genus, rank, markings and moduli type.

    EXAMPLES::

        sage: from admcycles.DR.moduli import MODULI_SM, MODULI_CT, MODULI_RT, MODULI_ST
        sage: from admcycles.DR.graph import num_strata
        sage: for r in range(4):
        ....:     print('r={}: {} {} {} {}'.format(r,
        ....:           num_strata(2, r, (1, 1), MODULI_SM),
        ....:           num_strata(2, r, (1, 1), MODULI_RT),
        ....:           num_strata(2, r, (1, 1), MODULI_CT),
        ....:           num_strata(2, r, (1, 1), MODULI_ST)))
        r=0: 1 1 1 1
        r=1: 2 3 5 6
        r=2: 0 7 16 28
        r=3: 0 0 38 113
    )r�
all_strata�r>r��markingsr�rrr�
num_strataI�r�cCr�)a�
    Return the number of pure strata in given genus, rank, markings and moduli type.

    EXAMPLES::

        sage: from admcycles.DR.moduli import MODULI_SM, MODULI_CT, MODULI_RT, MODULI_ST
        sage: from admcycles.DR.graph import num_pure_strata
        sage: for r in range(4):
        ....:     print('r={}: {} {} {} {}'.format(r,
        ....:           num_pure_strata(2, r, (1, 1), MODULI_SM),
        ....:           num_pure_strata(2, r, (1, 1), MODULI_RT),
        ....:           num_pure_strata(2, r, (1, 1), MODULI_CT),
        ....:           num_pure_strata(2, r, (1, 1), MODULI_ST)))
        r=0: 1 1 1 1
        r=1: 0 1 3 4
        r=2: 0 0 3 10
        r=3: 0 0 2 19
    )r�all_pure_stratar�rrr�num_pure_strata_r�r�cC�t||||�|S)z(
    Return the ``num``-th stratum.
    )r���numr>r�r�r�rrr�single_stratumu�r�cCr�)z-
    Return the ``num``-th pure stratum.
    �r�r�rrr�single_pure_stratum|r�r�cC�tt|||||��Sr )r�r�r�rrr�autom_count��r�cCr�r )r�r�r�rrr�pure_strata_autom_count�r�r�cs�t|�|||�}t|j�}|��|��t||��t��}t||�}t|�}	g}
g}|��}|��}
t	|�D]@��|vrw|
�
���|D]0����fdd�t	|�D����fdd�t	|
�D�g}t	|�D]}�||kru|�
|�nqfqFq7|	|
gS)Ncs(g|]}��d�d|d�qS�rrr�r'rP�r>r(Z	pure_autsrrr)�s �z'automorphism_cosets.<locals>.<listcomp>cs(g|]}��d�d|d�qSr^rr�r�rrr)�s()r�rrrhrgr�rr9r;r+rJ)r�r>r�r�r�rMZpureGZnum_pureZimpure_autsZ
num_impureZchosen_autsZ	used_auts�v�er�r�rr�r�automorphism_cosets�s8


��
��r�cs�i}���fdd�t|d�D�}t�|���}t|�D]I\}}t|j�}	|	��|	��t��}
d}tt||
��D]}|	j||
|jkrO|
|f}
d}nq;|sVJd��|
|vr^g||
<||
�|�q|S)a
    Return a dictionary which maps pure strata to list of strata.

    EXAMPLES::

        sage: from admcycles.DR.graph import unpurify_map
        sage: unpurify_map(2, 2)
        {(0, 0): [0, 1], (1, 0): [2, 3], (1, 1): [4, 5], (2, 0): [6], (2, 1): [7]}
    c�g|]	}t�|����qSrr��r'�r0�r>r�r�rrr)���z unpurify_map.<locals>.<listcomp>rFTzfailed purification)	r+r��	enumeraterrrhr;rrJ)r>r�r�r��unpurify�pure_strataZ
impure_stratar(ZstratirMr��foundr0ZG_keyrr�r�unpurify_map�s*
�
�r�c
Cs�|d}|tkrtd}dd�t|�D�}t|d�D]�}|dkr'|tkr'n�||kr-n�t||d�D]x}|dkrA|tkrAnmt�}|�||�t|�D]}	|�dd�qO|D]	}	|�dd|	�qZdd�t|�D�}
|dkr�|dkr{|g|
t<n|g|
t<n|g|
t<t|�D]}	t	|
|�}
q�t
|
||||�}
t|�D]}|||
|7<q�q5qg}t|�D]}|||7}q�|S)a:
    Return the lists of strata with given genus, degree, markings and moduli.

    EXAMPLES::

        sage: from admcycles.DR.graph import all_strata
        sage: all_strata(2, 1, (1, 1))
        [[   -1     1     1]
         [X + 2     1     1],
         [   -1     1     1]
         [    2 X + 1     1],
         [-1  1  1  0]
         [ 0  1  1  1]
         [ 2  0  0  1],
         [-1  1  1  0]
         [ 1  0  0  1]
         [ 1  1  1  1],
         [-1  1  1  0]
         [ 1  0  1  1]
         [ 1  1  0  1],
         [-1  0  1  1]
         [ 1  2  1  1]]
    rcSrVrrr&rrrr)�r*zall_strata.<locals>.<listcomp>rcSrVrrr&rrrr)�r*)rr
r+rrr?rDrrr�r�)
r>r�r�r�r��big_list�loops�edgesrMrP�GGGr(�
combined_listrrrr��sF
��r�cCsrdd�t|d�D�}t|d�D]�}|dkr|tkrn�||kr#n�t||||d�D]v}|dkr:|tkr:nkt�}|�||�t|�D]}|�dd�qH|D]	}|�dd|�qS|��dd�t|d�D�}	|dkr�|dkrz|g|	t<n|g|	t<n|g|	t<t|�D]}t	|	|�}	q�t|d�D]}
||
|	|
7<q�q.qg}t|d�D]}
|||
7}q�|S)a<
    Return the lists of pure strata with given genus, degree, markings and moduli.

    EXAMPLES::

        sage: from admcycles.DR.graph import all_pure_strata
        sage: from admcycles.DR.moduli import MODULI_CT
        sage: all_pure_strata(2, 0, (1, 1))
        [[-1  1  1]
         [ 2  1  1]]
        sage: all_pure_strata(2, 1, (1, 1), MODULI_CT)
        [[-1  1  1  0]
         [ 0  1  1  1]
         [ 2  0  0  1],
         [-1  1  1  0]
         [ 1  0  0  1]
         [ 1  1  1  1],
         [-1  1  1  0]
         [ 1  0  1  1]
         [ 1  1  0  1]]
    cSrVrrr&rrrr)r*z#all_pure_strata.<locals>.<listcomp>rrcSrVrrr&rrrr)-r*)
r+rr
rr?rDrgrrr�)r>r�r�r�r�r�r�rMrPr�r(r�rrrr�s@
��r�cCsXi}t||||�}tt|��D]}||j|vrg|||j<|||j�|�q|Sr )r�r+rr_rJ)r>r�r�r�r�rfr(rrr�strata_invariant_lookup?sr�c	Csx|��t||||�}t||||�}||j}t|�dkr!|dS|D]
}t|||�r0|Sq#td�|||||���)a�
    Return the index of the graph ``G`` in the list of all strata with given
    genus, rank, markings and moduli type.

    This is the inverse of :func:`single_stratum`.

    EXAMPLES::

        sage: from admcycles.DR.graph import Graph, X, R, num_of_stratum
        sage: G = Graph(matrix(R, 2, 3, [-1, 1, 2, X+1, 1, 1]))
        sage: num_of_stratum(G, 1, 1, (1, 2))
        0
    rrz;wrong Graph with g={}, r={}, markings={}, moduli_type={}
{})rgr�r�r_rr��
ValueError�format)	rMr>r�r�r�rf�LLr`r(rrr�num_of_stratumJs
�
�r�cCsPt||ttd|d��|�}t|�D]\}}td|�t|j�td�qdS)a�
    Displays the list of all strata.

    EXAMPLES::

        sage: from admcycles.DR.graph import list_strata
        sage: list_strata(1,1,2)
        generator 0
        [   -1     1     2]
        [X + 1     1     1]
        ------------------------------
        generator 1
        [   -1     1     2]
        [    1 X + 1     1]
        ------------------------------
        generator 2
        [   -1     1     2]
        [    1     1 X + 1]
        ------------------------------
        generator 3
        [-1  1  2  0]
        [ 0  1  1  1]
        [ 1  0  0  1]
        ------------------------------
        generator 4
        [-1  0  1  2]
        [ 0  2  1  1]
        ------------------------------
    rzgenerator %sz------------------------------N)r�r.r+r�rkr)r>r��nr�rfr(�Lirrr�list_stratahs

�r�cs,i}���fdd�t|d�D�}t|d�D�]{}tt||��D�]o}|||��fdd�td�j���D��i}tjdd�t|�D��D]��t�fdd�t|�D��}	�fdd�|	D�}
|
��d	d�td�j���D�}t	td�j����}t
�j�}
|
D]}|
�|||�\}}q�|
��|t|
�}g}tt||��D]}t
||||
d
�}|r�|�||f�|�|d�nq�|�||f�|||	<qHtjdd�t|�D��D]��td
d��D��||kr�q�t�fdd�t|�D��}��fdd�t|�D�}t�fdd�t|�D��}||k�rq�||}||}|d|dg}|d|dg}|d|dk�rM|��|��||f||d|dg|}n||f||d|dg|}t|�}||v�rhg||<||�|�|d|dk�r�||�|dd�|d|d|d|dg�q�q"q|S)Ncr�rr�r�r�rrr)�r�z%contraction_table.<locals>.<listcomp>rcs"g|]
}�jd|fdkr|�qSr%rZrW)rMrrr)�s"cSsg|]}ddg�qSr�rr&rrrr)�r�c3� �|]}�|dkr|VqdS�rNrr&)�edge_subsetrrrz���
�z$contraction_table.<locals>.<genexpr>csg|]}�|�qSrrr&)rnrrr)�r�cSsg|]}|g�qSrrr&rrrr)�sTrcSsg|]}gd��qS))rrr2rr&rrrr)�r�css�|]	}|dkrdVqdS)rNrr&rrrrz�r�c3r�r�rr&��edge_assignmentrrrz�r�cs g|]}�|dkr�|�qSr^rr&)rnr�rrr)�s�c3r�)r2Nrr&r�rrrz�r�r2r\�r�)r+rrr-rvr}r.�reverser,r�rrorgr�rJr�)r>r�r�r��contraction_dictr�r�r�Zcontractionsrb�ArlrmZGcopyr(�rnewZcontraction_resultrf�key1�B�key2Z	contract1Z	contract2�dict_keyZ
dict_entryr)rMrnr�r�r>r�r�r�contraction_table�s�
�
�
��

��
�
����
&����9r�)F)3rsrrv�sage.misc.cachefuncr�sage.misc.lazy_attributer�sage.rings.allrr�sage.combinat.allrr�sage.functions.otherr	�sage.matrix.constructorr
�utilsr�modulir
rrrrrr�genrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>sZ l
,

LG)@=8
%