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

��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)Az�
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
    NcCsH|rt|�|_n4|r4ttt|�dddg|�|_nttddd�|_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__EszGraph.__repr__cCspdd�td|j���D�}td|j���D]<}td|j���D]&}||d|j||fd7<q>q*t|�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,)
        cSsg|]}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]�}d|j|dfd}td|j���D],}||j||fd|j||fd7}q>td|j|df��d�D]}|||j|df|7}q�|d;}|||d>7}q|S)Nrr�)r*rr+r,�degree)r�ansr'Zlocal_parityr/rrr�
target_parityZs* zGraph.target_paritycCs|j|dS)z4
        Return the degree of vertex ``i``.
        r)r0�rr'rrrr2gszGraph.degreecCs|j��dS�Nr)rr+r"rrr�num_verticesmszGraph.num_verticescCs|j��dSr6)rr,r"rrr�	num_edgespszGraph.num_edgescCs|j��|j��dSr6)rr,r+r"rrr�h1sszGraph.h1cCs(|j�td|j����|_||jd<dS)Nr)rr)r�stackr
r,)r�grrr�
add_vertexvszGraph.add_vertexrcCsd|j�t|j��d��|_||jd<|dkrB|j|dfd7<|dkr`|j|dfd7<dS)Nr)rrrr)r�augmentr
r+)r�i1�i2�markingrrr�add_edgezs
zGraph.add_edgecCs(|jd|��|j|dd��|_dSr6)rr:r5rrr�
del_vertex�szGraph.del_vertexcCs^||��kr&|jdd�d|�f|_n4|jdd�d|�f�|jdd�|dd�f�|_dS)Nrr)r8rr=r5rrr�del_edge�szGraph.del_edgecCsN|j�td|j��||��|_|�|j��d|j��d�|�|�dS)Nr1r)rr:r
r,rAr+rB)rr'�row1�row2rrr�split_vertex�s
 �zGraph.split_vertexcCs�|��}|��}g}g}dg}d}td|j���D]T}	|jd|	fdkr||jd|	fdkrb|d7}|�|jd|	f|�q2|�d�q2td|j���D]H}	t|j||	fd�D],}
|jd|	fdkr�|�|	�q�|�|	�q�q�||}|�|�t|��t|��D]}
|�dd��qt|���D]}
|�	|j|
ddf��q(|d}td|j���D�]H}	|jd|	fdk�rlt
||	�}
t|���D]�}
|j||
||
dfdk�r�|j|
d|	f|j||
||
df<n�|j|
d|	fdk�r�|j||
||
dfd}|j|
d|	fd}dt||�tt
||�td|j||
||
df<�q�n<t|���D]&}
|j|
d|	f|j||
|f<�qx|d7}�q`dS)Nrrrr1)r7r8r*rr,�appendrBrrAr<r�maxr�min)rr'�G�nv�neZhedge_list_onesZhedge_list_othersZ
unsym_colsZmark_nr�kr/Z
hedge_list�col�mark�a�brrr�replace_vertex_with_graph�sR
 *�� $zGraph.replace_vertex_with_graphcs��j���j���}��fdd�td��D��_td|�D�]2���fdd�td��D�}t|�dkr��jd�fdkr��j|ddd��jd�f�j|d�ff�n*�j|ddd��j|d�f�q<�j|ddd|dd��j|d�f�j|d�ff��j|ddd|dd��j|d�f�j|d�ff�q<td��D�]b}dd��j|ddD��j|dd<tt�j|dd��D]L��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]R}|dk�s^||d||ddk�rj�j	�g��j	d
�||d��q2dS)Nc	s2g|]*}�j|dfggdd�td��D�g�qS)rcSsg|]}g�qSrr�r&r/rrrr(�sz6Graph.compute_invariant.<locals>.<listcomp>.<listcomp>r)rr*r%)�nrrrrr(�s��z+Graph.compute_invariant.<locals>.<listcomp>rcs"g|]}�j|�fdkr|�qSr$�rr%)rMrrrr(�s�rr1�cSsg|]}t|�r|�qSr)r)r&�termrrrr(�s�csg|]}|�j|dg�qS�r)�	invariantr%r"rrr(�s�cSs|dSr6r)�xrrr�<lambda>�r)z)Graph.compute_invariant.<locals>.<lambda>)�keyr)
rr+r,r*rYrrG�sortr-�vertex_groupings)r�nc�Lr'Zvertex_invariantsr)rMrTrr�compute_invariant�sl�
���,2�2�*����$$$ 
�
(

�zGraph.compute_invariantcCsLt|j���D]8}t|j���D]$}t|j||fd�|j||f<q qdS)Nr)r*rr+r,r)rr'r/rrr�purify�szGraph.purifycsv�jd�fdkrtd�dS��fdd�td�j���D�}t|�dkr��j|ddfd7<����|d�d�|�d�}n����|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 markingcs"g|]}�j|�fdkr|�qSr$rU)r&�row�r'rrrr(�s�z"Graph.contract.<locals>.<listcomp>rr)r�printr*r+rrCr<rB)rr'�vlist�elist�Srrdr�contract�s.
�


*� �zGraph.contract)NN)r)�__name__�
__module__�__qualname__�__doc__rr#rr0r4r2r7r8r9r<rArBrCrFrRrarbrirrrrrs( 
	


,,rc
Cs�|j|jkrdS|j}|j}|j}|j}|��}|��}tjdd�|D��D�]�}dg|d}	tt|��D]>}
tt||
��D](}||
||
||	||
|d<q�qld}td|�D�]}
|	|
d}
td|
�D]�}|	|d}g}td|�D]B}||
|fdkr�|||fdkr�|�	||
|f|||fg�q�|�
�g}td|�D]H}||
|fdk�rN|||fdk�rN|�	||
|f|||fg��qN|�
�||kr�d}�q�q�|dur��q�q�|rLdSqLdS)z:
    Return whether ``G1`` and ``G2`` are isomorphic.
    Fcss |]}t�tt|���VqdSr ��	itertools�permutationsr*r�r&�grouprrr�	<genexpr>r)z#graph_isomorphic.<locals>.<genexpr>rrT�rYrr^r+r,ro�productr*rrGr])�G1�G2�M1�M2�group1�group2rTr_�
sigma_data�sigmar'r/�good�ii�jj�L1rM�L2rrr�graph_isomorphicsH(  $"r�FcCst|j|j|�Sr )�count_automorphismsrr^)rJ�
vertex_orbitsrrr�graph_count_automorphisms2sr�c
s�������}}t��}|r"g}tjdd�|D��D�]�}dd�t|d�D�}tt|��D]>}	tt||	��D](}
||	||	|
|||	|
d<qrq^d}td|�D�]}	||	d}td|	�D]�}
||
d}
g}td|�D]B��|	�fdkr�|
�fdkr�|��|	�f�|
�fg�q�|�	�g}td|�D]H��|�fdk�r@�|
�fdk�r@|��|�f�|
�fg��q@|�	�||kr�d}�q�q�|s��q�q�|r6|d7}|r6|�|�q6|�rjg}g�t��|dk�rft
�fd	d�td|�D��}	g}|D]<}||	d|v�r|�||	d���||	d��q|�	�|�|��q�|Std|�D�]D}	td|�D]F��|	�fdd
k�r��|	�fd�|	�fd
k�r�|d
9}�q�g}td|�D]Z��|	�fdk�r�t��fdd�td|�D��dk�r�|��d�f�|	�fg��q�|t|�9}td|	�D]j}
g}td|�D]H��|	�fdk�r^�|
�fdk�r^|��|	�f�|
�fg��q^|t|�9}�qL�qt|S)z`
    INPUT:

    M: adjacency matrix
    grouping: list of lists
    vertex_orbits: boolean
    css |]}t�tt|���VqdSr rnrqrrrrsBr)z&count_automorphisms.<locals>.<genexpr>cSsg|]}d�qSr$rr%rrrr(Cr)z'count_automorphisms.<locals>.<listcomp>rTrFc3s|]}|�vr|VqdSr r)r&r)�
vertices_usedrrrsdr)r1c3s"|]}�|�fdkrdVqdS)rrNrrS)rrMrrrsur))
r+r,r�zerororur*rrGr]�next�sumr)r�groupingr�rTr_�count�	isom_listr|r}r'r/r~rr�r�r�Z
orbit_list�orbitr`r)rrMr�rr�6s~(  $"8$"$"r�c
sN|j|jkrgS|j�|j�|j}|j}�������}g}tjdd�|D��D�]�}dg�d�tt|��D]>}tt||��D](}	|||||	�|||	d<q�qpd}
td��D�]}�|d}td|�D]�}	�|	d}g}
td|�D]B}�||fdkr��|	|fdkr�|
�	�||f�|	|fg�q�|
�
�g}td|�D]H}�||fdk�rR�||fdk�rR|�	�||f�||fg��qR|�
�|
|kr�d}
�q�q�|
s��q�q�|
rP��fdd�td|�D�}���fd	d�td|�D�}g}g}g}td|�D]�}	|	|v�r|�	g�|�	g�td|�D]`}||d||	dk�rv|d
�	|�|�	|�||d||	dk�r@|d
�	|��q@�qtjdd�|D��D]�}dd�t|d�D�}tt|��D]B}tt||��D]*}	|||||	||||	d<�q��q�|�	�|g�|�r�|S�q�qP|S)
z@
    Return the list of isomorphisms from ``G1`` to ``G2``.
    css |]}t�tt|���VqdSr rnrqrrrrs�r)z*graph_list_isomorphisms.<locals>.<genexpr>rrTFcs$g|]���fdd�t��D��qS)csg|]}�|�f�qSrrr%)rxr/rrr(�r)�6graph_list_isomorphisms.<locals>.<listcomp>.<listcomp>�r*�r&)rxrT�r/rr(�r)z+graph_list_isomorphisms.<locals>.<listcomp>cs6g|].��d�fg���fdd�td��D��qS)rcs g|]}��|d�f�qSrXrr%)ryr/r}rrr(�r)r�rr�r�)ryrTr}r�rr(�s�rcss |]}t�tt|���VqdSr rn)r&Z
edge_grouprrrrs�r)cSsg|]}d�qSr$rr%rrrr(�r)rt)rvrwZonly_onerzr{r_r�r|r'r/r~rr�r�rMr�Zcols1Zcols2Zedge_group1Zedge_group2Zused1Zedge_sigma_dataZ
edge_sigmar)rxryrTr}r�graph_list_isomorphisms�s�(  $"�



��r�cs�|d}|tkrtd}dd�t|�D�}t|�D�]�}||D�]�}td|��d�D�]l}t|j|���dt��}|dkr�qXdd�tt���D��dd��D��krX�ddkr�|tkr�qX�dt��dk�rd�dt��|dk�rd��fd	d�tt���D�}t	|j�}	|	�
|�|�|}
|
tk�r:t}
|
tk�rV�ddk�rVt}
||
�|	��d
d7<tdt���D]@}�|�|k�r�q�d�|<�|dd7<�q�q�qXq@q2t|�D]}t
||�||<�q�|S)z^
    Return the list of degenerations of the graphs in ``G_list`` up to
    isomorphisms.
    rcSsg|]}g�qSrrr%rrrr(�r)zdegenerate.<locals>.<listcomp>r�cSsg|]}d�qSr$rrSrrrr(�r)cSsg|]}d|�qS)r1r)r&rZrrrr(�r)r1csg|]}�|�|�qSrrrS�rcrDrrr(�r)r)rr
r*r7�listrr�rrrrFrrG�remove_isomorphic)�G_list�moduli_type�mod_size�
G_list_new�
which_typerJr'�mrE�G_copy�new_typer/rr�r�
degenerate�sD0


"r�cs�|d}|tkrtd}dd�t|�D�}t|�D�]z}||D�]j�dd�t|�D�}�j���j��}}g}	g}
td|�D]V�td|�D]F}�j�|fdkr�|	��|g�q��j�|fdkr�|
��|g�q�q�|d�t|	�}t|
�}
��fdd�t|�D�}t|�||
�D�]f�|}|tk�r��d��}t|�D]*�||	�dd���7<�qBt|
�D].�||
�dd��|�7<�qvt||�D]:}t��D]*�|�||�k�r�|d}�q��q��q�||k�r��qg}t��D]�|�t	�����qt��|�D]8�|���fd	d�tt
��td�d��D���q.tj
|�}|D�]}t�j�}t��D]4�|�D]$}|j�ddft|7<�q��q�t��|�D]T�|j|	��d|	��df|�dt|�dtd7<�q�t|
�D]<�|j|
�d|
�df���|t7<�q0||�|��qv�qt|�D]}||t||�7<�q�q@q2|S)
z6
    Add decorations to the graphs in ``G_list``.
    rcSsg|]}g�qSrrr%rrrr(�r)zdecorate.<locals>.<listcomp>cSsg|]}g�qSrrr%rrrr(�r)r1cs$g|]���fdd�t��D��qS)cs4g|],}t�j|ddfd��|d����qS)rr)rrr2r%)rJ�mod_typerrr(	s�z'decorate.<locals>.<listcomp>.<listcomp>r�r�)rJrP)r�rr(	s��Nrcsg|]}��||g�qSrrrS)r'�vecrrr(r))rr
r*rr+r,rGrrrr	rrorurrr�)r��rr�r�r�r�ZG_decorTr_Ztwo_listZone_listr/rQ�c�dimsr�Z	test_dimsr�ZS_listrh�vec2r�r)rJrPr'r�r�decorate�s��
(,
*�


&�"�

��
 r�cCs�g}i}d}|D]p}|��|j|vr0g||j<d}||jD]}t|||�r>d}qZq>|r|�|�||j�|�|d7}q|S)zY
    Return a list of isomorphism class representatives of the graphs in ``G_list``.
    rTFr)rarYr�rG)r�r��inv_dictr�rvr~r'rrrr�2s"



r�rcCstt||||��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_strataIsr�cCstt||||��S)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_sr�cCst||||�|S)z(
    Return the ``num``-th stratum.
    )r���numr;r�r�r�rrr�single_stratumusr�cCst||||�|S)z-
    Return the ``num``-th pure stratum.
    �r�r�rrr�single_pure_stratum|sr�cCstt|||||��Sr )r�r�r�rrr�autom_count�sr�cCstt|||||��Sr )r�r�r�rrr�pure_strata_autom_count�sr�cs�t|�|||�}t|j�}|��|��t||��t��}t||�}t|�}	g}
g}|��}|��}
t	|�D]���|vrn|
�
���|D]`����fdd�t	|�D����fdd�t	|
�D�g}t	|�D]}�||kr�|�
|�q�q�q�qn|	|
gS)Ncs(g|] }��d�d|d�qS�rrr�r&rM�r;r'Z	pure_autsrrr(�s�z'automorphism_cosets.<locals>.<listcomp>cs(g|] }��d�d|d�qSrXrr�r�rrr(�r))r�rrrbrar�rr7r8r*rG)r�r;r�r�r�rJZpureGZnum_pureZimpure_autsZ
num_impureZchosen_autsZ	used_auts�v�er}rrr�r�automorphism_cosets�s4


��

r�cs�i}���fdd�t|d�D�}t�|���}t|�D]�\}}t|j�}	|	��|	��t��}
d}tt||
��D](}|	j||
|jkrv|
|f}
d}q�qv|s�Jd��|
|vr�g||
<||
�|�q8|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]}
    csg|]}t�|����qSrr��r&�r0�r;r�r�rrr(�s�z unpurify_map.<locals>.<listcomp>rFTzfailed purification)	r*r��	enumeraterrrbr8rrG)r;r�r�r��unpurify�pure_strataZ
impure_stratar'ZstratirJr��foundr/ZG_keyrr�r�unpurify_map�s(
�
r�c
Cs�|d}|tkrtd}dd�t|�D�}t|d�D�]2}|dkrR|tkrR�ql||kr`�qlt||d�D]�}|dkr�|tkr�q6t�}|�||�t|�D]}	|�dd�q�|D]}	|�dd|	�q�dd�t|�D�}
|dk�r|dk�r|g|
t<n
|g|
t<n
|g|
t<t|�D]}	t	|
|�}
�qt
|
||||�}
t|�D]}|||
|7<�qLqpq6g}t|�D]}|||7}�qx|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]]
    rcSsg|]}g�qSrrr%rrrr(�r)zall_strata.<locals>.<listcomp>rcSsg|]}g�qSrrr%rrrr(�r))rr
r*rrr<rArrr�r�)
r;r�r�r�r��big_list�loops�edgesrJrM�GGGr'�
combined_listrrrr��sB


r�cCs�dd�t|d�D�}t|d�D�]2}|dkr>|tkr>�qX||krL�qXt||||d�D]�}|dkrz|tkrzq"t�}|�||�t|�D]}|�dd�q�|D]}|�dd|�q�|��dd�t|d�D�}	|dk�r|dkr�|g|	t<n
|g|	t<n
|g|	t<t|�D]}t	|	|�}	�qt|d�D]}
||
|	|
7<�q8qbq"g}t|d�D]}
|||
7}�qh|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]]
    cSsg|]}g�qSrrr%rrrr(r)z#all_pure_strata.<locals>.<listcomp>rrcSsg|]}g�qSrrr%rrrr(-r))
r*rr
rr<rArarrr�)r;r�r�r�r�r�r�rJrMr�r'r�rrrr�s<

r�cCsXi}t||||�}tt|��D]4}||j|vr>g|||j<|||j�|�q|Sr )r�r*rrYrG)r;r�r�r�r�r`r'rrr�strata_invariant_lookup?sr�c	Cs||��t||||�}t||||�}||j}t|�dkrB|dS|D]}t|||�rF|SqFtd�|||||���dS)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={}
{}N)rar�r�rYrr��
ValueError�format)	rJr;r�r�r�r`�LLrZr'rrr�num_of_stratumJs


�r�cCsPt||ttd|d��|�}t|�D]&\}}td|�t|j�td�q$dS)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�rer)r;r��nr�r`r'�Lirrr�list_stratahs

r�cs@i}���fdd�t|d�D�}t|d�D�]
}tt||��D�]�}|||��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]B}t
||||
d
�}|�rH|�||f�|�|d��q��qH|�||f�|||	<q�tjdd�t|�D��D�]x�td
d��D��||k�r�q�t�fdd�t|�D��}��fdd�t|�D�}t�fdd�t|�D��}||k�r<�q�||}||}|d|dg}|d|dg}|d|dk�r�|��|��||f||d|dg|}n||f||d|dg|}t|�}||v�r�g||<||�|�|d|dk�r�||�|dd�|d|d|d|dg��q�qDq.|S)Ncsg|]}t�|����qSrr�r�r�rrr(�s�z%contraction_table.<locals>.<listcomp>rcs"g|]}�jd|fdkr|�qSr$rUrS)rJrrr(�r)cSsg|]}ddg�qSr�rr%rrrr(�r)c3s|]}�|dkr|VqdS�rNrr%)�edge_subsetrrrs�s�z$contraction_table.<locals>.<genexpr>csg|]}�|�qSrrr%)rhrrr(�r)cSsg|]
}|g�qSrrr%rrrr(�r)TrcSsg|]}gd��qS))rrr1rr%rrrr(�r)css|]}|dkrdVqdS)rNrr%rrrrs�r)c3s|]}�|dkr|VqdSr�rr%��edge_assignmentrrrs�s�cs g|]}�|dkr�|�qSrXrr%)rhr�rrr(�s�c3s|]}�|dkr|VqdS)r1Nrr%r�rrrs�s�r1rV�r�)r*rrr,rorur-�reverser+r�rrirar�rGr�)r;r�r�r��contraction_dictr�r�rZcontractionsr\�Arfrg�Gcopyr'�rnewZcontraction_resultr`�key1�B�key2Z	contract1Z	contract2�dict_keyZ
dict_entryr)rJrhr�r�r;r�r�r�contraction_table�s�
��

�

�
��

����
&�r�)F)F)F)3rmrro�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>sX l,

L
G)@=8
%