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

��c���@s�ddlZddlmZddlmZmZmZddlmZddl	m
Zddlm
Z
ddlmZddlZddlmZd	d
�Zdd�Zd
d�Zdd�Zedd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Z d#d$�Z!d%d&�Z"d'd(�Z#d+d)d*�Z$dS),�N)�ceil)�
partitions�permutations�multiset_partitions)�Graph)�Compositions)�OrderedPartitions)�cached_function)�	SignaturecsF�fdd�tt�jdd���D��t�fdd��jdd�D�ddd�S)	Ncs&i|]}�j|dd�D]
}||�qqS)F��copy)�legs)�.0�vnum�i��gr��</home/user/Introduction lectures/admcycles/diffstrata/bic.py�
<dictcomp>s�zSageGraph.<locals>.<dictcomp>Frcs g|]\}}�|�|f�qSrr)r�a�b)�legdicrr�
<listcomp>!s�zSageGraph.<locals>.<listcomp>T)�loops�
multiedges)�range�lenr
r�edgesrr)rrr�	SageGraphs�
��rc
s�td�td�t��}||}g}�fdd�t|�D�}td|d�D]|}t|||�D]j}t|��d���drX�fdd	��dD�}�fd
d	��dD�}	|t|||	|�7}|t||	||�7}qXqH|S)z�
    Generate BICs for stratum with signature orders of genus g.

    DO NOT USE!!! USE bic_alt instead!!!

    Args:
        g (int): genus
        orders (tuple): signature tuple

    Returns:
        list: list of BICs
    z9WARNING! This is not the normal BIC generation algorithm!z'Only use if you know what you're doing!csi|]}|d�|�qS��r�rr��ordersrrr7�zbics.<locals>.<dictcomp>r!Trcs g|]}�d|dkr|�qS)r!rr�r�v��checkrrr?r%zbics.<locals>.<listcomp>cs g|]}�d|dkr|�qSr rr&r(rrr@r%)�printrr�new_list_stratar�is_bipartite�
bics_on_bipgr)
�gr$�n�bound�result�	orderdict�er�vert1�vert2r)r)r$r�bics%s
r6c	s�g}dd�}t|jdd��}|���t|jdd�����dd�|jdd�D��dd�t|�D�}|D]}d	||<qf�fd
d�|jdd�D��g}	t|�D]8�|	�d|���dt	�fdd�|�
��D���q�g}
|D]��g}t|	�t���t����D]\����fd
d�tt����D�}|�����fdd�tt����D��|�|��q|
|g7}
q�tj
|
�D]j}
|�g|
�R�}tjjj|jdd�|jdd�|jdd�||dd�}|�d��rz|�d��rz|�|��qz|S)NcWsttj�dd�|D���S)Ncss|]}|��VqdS�N)�items)r�dctrrr�	<genexpr>Ms�z2bics_on_bipgr.<locals>.dicunion.<locals>.<genexpr>)�dict�	itertools�chain�
from_iterable)�dictsrrr�dicunionLs�zbics_on_bipgr.<locals>.dicunionFrcSsi|]\}}||�qSrr)r�e0�e1rrrrSr%z!bics_on_bipgr.<locals>.<dictcomp>cSsg|]}d�qS�rrr"rrrrUr%z!bics_on_bipgr.<locals>.<listcomp>�����csg|]}�fdd�|D��qS)csg|]}|�vr|�qSrr�r�l��	halfedgesrrrYr%z,bics_on_bipgr.<locals>.<listcomp>.<listcomp>r)r�llrGrrrYs��csg|]}�|�qSrrrE)r2rrr_s�cs"i|]}��|�|d�qSr rr")�helist�partr'rrrir%cs(i|] }���|�|d�qSr rr")�halfedgeinversrKrLr'rrrkr%T��quiet)r�generarHr;r�updaterr
�append�sum�
list_markingsrr<�product�	admcycles�
diffstrata�
levelgraph�
LevelGraph�is_legal�checkadmissible)rZvertupZvertdownr2r1r@�numvert�levelsr�degsZweightpartsZvweightpartZvdic�parts�
poleordersZ	CandGraphr)rMrHrKr2rLr'rr-FsX


� �&""�����r-cCs&dd�tj�t|�||�d|D�S)NcSsg|]}|d�qSrCr)r�lisrrrrr%z#new_list_strata.<locals>.<listcomp>r)rV�degeneration_graph�int)r.r/�rrrrr+~s
��r+c*s�t�t�rt���dd�t�j�D�}�j}dd�t�j�D�}�j}dd�t�j�D�}t|�}�j}dd�t�j�D���j	}�j
dkr�|dkr�|}	d}
ddg}q�|d}	d}
dg}n2�j
d	kr�|}	d}
|dkr�ddgndg}ntd
���j
d	ko��jdk}g}
t
d||d�D�]�}t�t|d	�t|ggg��D�]h}dD�]Z}|dk�sdt||�|k�rB||}|d|}n�qB|dk�r�t||�}n
t||�}|D�]��t
|	d�D�]�}t
|
||d�D�]�}|||}t||�D�]��t����fd
d�t
|�D���s�q�t�t|d	�t|ggg��D�]X}|D�]J}||}|d|}�j
dk�r||dk�r|t|�dk�r|�q:t||�D�]�������fdd�t
|�D�}t�fdd�|D���sƐq��j
dk�r�t�fdd�|D��}t|�}nN�j
d	k�r8tdd�|D��}t�fdd�|D��|}t|�|}ntd
��tt|d	�j
�|�}t
d||d�D�]�
�
||d�
t���fdd�t
|�D���j
d�
�j
d	|d	|k�rʐqlt|�
�D�]��t|�
�D�]��t���
��fdd�t
�
�D���s�q�t|�
�D�]T������fdd�t
�
�D�} t�
�fdd�| D���s^�qt|�
|�
�j
|�D�]�\�}!t| |!�j
�D�]܉	t��	��s��q��D],}"|"D] }#d�j
|!|#|!|#�
<�q��q����t|t���D�]z�����	�
fdd�t
�
�D������
fdd�t
|�D�}$t�fdd�t|$�D���rL�q�|$�
fdd�t
|d|�
d�D�t�|!�dg�
dg|f}%�j
dk�r�tjj j!|%�}&n$�j
d	k�r�tjj"j#|%�}&ntd
��|&j$dd��rZ�j
dk�r|&j%dd��rX|
�&|&�nT�j
d	k�rP�jdk�r*|&j'dd��sD�jd k�rX|&j(dd��rX|
�&|&�ntd
��n
t)d!|&��q�q��qt�q�q�qԐql�q��q:�q0�q�q̐q��q��qB�q8�qg}'t*�}(|
D]$})|)|(v�r�|'�&|)�|(�+|)��q�|'S)"ap	
    Construct all non-horizontal divisors in the stratum sig.

    More precisely, each BIC is LevelGraph with two levels numbered 0, -1
    and marked points 1,...,n where the i-th point corresponds to the element
    i-1 of the signature.

    Note that this is the method called by GeneralisedStratum.gen_bic.

    Args:
        sig (Signature): Signature of the stratum.

    Returns:
        list: list of 2-level non-horizontal LevelGraphs.

    EXAMPLES::

        sage: from admcycles.diffstrata import *
        sage: assert comp_list(bic_alt(Signature((1,1))),        [LevelGraph([1, 0],[[3, 4], [1, 2, 5, 6]],[(3, 5), (4, 6)],{1: 1, 2: 1, 3: 0, 4: 0, 5: -2, 6: -2},[0, -1],True),        LevelGraph([1, 1, 0],[[4], [3], [1, 2, 5, 6]],[(3, 5), (4, 6)],{1: 1, 2: 1, 3: 0, 4: 0, 5: -2, 6: -2},[0, 0, -1],True),        LevelGraph([1, 1],[[3], [1, 2, 4]],[(3, 4)],{1: 1, 2: 1, 3: 0, 4: -2},[0, -1],True),        LevelGraph([2, 0],[[3], [1, 2, 4]],[(3, 4)],{1: 1, 2: 1, 3: 2, 4: -4},[0, -1],True)])

        sage: assert comp_list(bic_alt(Signature((2,))),        [LevelGraph([1, 1],[[2], [1, 3]],[(2, 3)],{1: 2, 2: 0, 3: -2},[0, -1],True),        LevelGraph([1, 0],[[2, 3], [1, 4, 5]],[(2, 4), (3, 5)],{1: 2, 2: 0, 3: 0, 4: -2, 5: -2},[0, -1],True)])

        sage: assert comp_list(bic_alt(Signature((4,))),        [LevelGraph([1, 1, 0],[[2, 4], [3], [1, 5, 6, 7]],[(2, 5), (3, 6), (4, 7)],{1: 4, 2: 0, 3: 0, 4: 0, 5: -2, 6: -2, 7: -2},[0, 0, -1],True),        LevelGraph([1, 1, 1],[[3], [2], [1, 4, 5]],[(2, 4), (3, 5)],{1: 4, 2: 0, 3: 0, 4: -2, 5: -2},[0, 0, -1],True),        LevelGraph([2, 0],[[2, 3], [1, 4, 5]],[(2, 4), (3, 5)],{1: 4, 2: 2, 3: 0, 4: -4, 5: -2},[0, -1],True),        LevelGraph([2, 0],[[2, 3], [1, 4, 5]],[(2, 4), (3, 5)],{1: 4, 2: 1, 3: 1, 4: -3, 5: -3},[0, -1],True),        LevelGraph([1, 0],[[2, 3, 4], [1, 5, 6, 7]],[(2, 5), (3, 6), (4, 7)],{1: 4, 2: 0, 3: 0, 4: 0, 5: -2, 6: -2, 7: -2},[0, -1],True),        LevelGraph([1, 2],[[2], [1, 3]],[(2, 3)],{1: 4, 2: 0, 3: -2},[0, -1],True),        LevelGraph([2, 1],[[2], [1, 3]],[(2, 3)],{1: 4, 2: 2, 3: -4},[0, -1],True),        LevelGraph([1, 1],[[2, 3], [1, 4, 5]],[(2, 4), (3, 5)],{1: 4, 2: 0, 3: 0, 4: -2, 5: -2},[0, -1],True)])

        sage: len(bic_alt(Signature((1,1,1,1)))) # long time (2 seconds)
        102

        sage: len(bic_alt(Signature((2,2,0,-2))))
        61

        sage: len(bic_alt((2,2,0,-2)))
        61
    cSs g|]\}}|dkr|d�qS�rr!r�rrrrrrr�r%z!bic_alt_noiso.<locals>.<listcomp>cSs g|]\}}|dkr|d�qSrerrfrrrr�r%cSs g|]\}}|dkr|d�qSrerrfrrrr�r%cSsi|]\}}|d|�qSr r)rr�ordrrrr�r%z!bic_alt_noiso.<locals>.<dictcomp>r!rrJzNot implemented for k>2�gsrec3sD|]<}t�fdd��|D���j�|d�jdkVqdS)c3s|]}�|VqdSr7r�r�bzr#rrr:r%�*bic_alt_noiso.<locals>.<genexpr>.<genexpr>rJr!N�rS�k�r�c)�distr_bot_g�distr_bot_zerosr$�sigrrr:s�
���z bic_alt_noiso.<locals>.<genexpr>csXg|]P}t�fdd��|D��t�fdd��|D���jd�|d�qS)c3s|]}�|VqdSr7r�r�tzr#rrr:r%�+bic_alt_noiso.<locals>.<listcomp>.<genexpr>c3s|]}�|VqdSr7r�r�tpr#rrr:r%rJrlrn)rp�distr_bot_polesrqr$rrrrrs���c3s|]}|�jdkVqdS�r!N�rm�r�s�rrrrr:s�c3s|]}�|VqdSr7r�r�pr#rrr:%scSs4g|],}|ddkr|dnt|d�d�qS)�rr!)rcr{rrrr-r%c3s|]}�|VqdSr7rr~r#rrr:.sc3sB|]:}t�fdd��|D��t�fdd��|D��VqdS)c3s|]}�|VqdSr7rrir#rrr:?r%rkc3s|]}�|VqdSr7r)r�bpr#rrr:@r%N)rSrn)rxrqr$rrr:?s��c3sL|]D}t�fdd��|D��d�j��jd�|dkVqdS)c3s|]}�|VqdSr7rrvr#rrr:Kr%rkr!rJNrlrn)�distr_top_g�distr_top_poles�num_of_edgesr$rrrrr:Ks����csXg|]P}t�fdd��|D��t�fdd��|D���jd�|d�qS)c3s|]}�|VqdSr7rrvr#rrr:Vr%ruc3s|]}�|VqdSr7rrsr#rrr:Wr%rJrlrn)r�r��distr_top_zerosr$rrrrrVs������c3s |]}|d�j�kVqdSryrzr{)r�rrrrr:]s�����cs:g|]2}�|�|�|�fdd��|D��qS)csg|]}|��qSrrrE�r�rrr}r%z,bic_alt_noiso.<locals>.<listcomp>.<listcomp>rrn)�distr_mpr�r��half_edges_topr�rrrzs���cs0g|](}�|�|�|��|�qSrrrn)rxrqr��half_edges_bot�top_comp_lenrrrs�
��c3s*|]"\}}�|dkrt|�dkVqdS)rr�N�r)rro�ls)rPrrr:�scsg|]}||�f�qSrrrEr�rrr�r%rDTrNrzNot admissible(!): ),�
isinstance�tupler
�	enumeraterr�zrrr.r/rm�
ValueErrorZdifftyperr<r=r�iter�_distribute_fully�_distribute_points�_distribute_part_ordered�allrS�minrc�_place_legs_on_bot�_place_legs_on_top�is_connected�any�_merge_dictsrVrWrXrYZquadraticlevelgraphZQuadraticLevelGraphr[rZrRZis_legal_global_squareZis_legal_primitiver*�set�add)*rr�zerosr��polesr�
marked_points�mpr.r/Z	g_bot_maxZ	g_top_min�pole_ind�	only_even�foundZbot_comp_lenr_rZbottom_zerosZ	top_zerosZbot_zero_genZtotal_g_botZtotal_g_topZ
total_g_graphZ
pole_parts�ipZbottom_polesZ	top_polesZ
spaces_botZmax_total_pole_order_topZ
max_poles_topZmax_poles_from_edgesZ
max_g0_topZ
spaces_topZ	orders_herorFr
Zlg_data�LGZ	found_newZ	found_set�xr)rprxrqr�r�r�r�rPr�r�r�r$rrr�r�
bic_alt_noiso�s�1



�


��
�
�
�
�

���
��
�
��������
����
�
�
�
��
��
����
����
������������
����H

r�cCstt|��S)aB
    The BICs of the stratum sig up to isomorphism of LevelGraphs.

    This should not be used directly, use a GeneralisedStratum or Stratum
    instead to obtain EmbeddedLevelGraphs and the correct isomorphism classes.

    Args:
        sig (tuple): signature tuple

    Returns:
        list: list of LevelGraphs.
    )�isom_repr�r}rrr�bic_alt�s
r�cCs|��}|�|�|Sr7)rrQ)r��yr�rrrr��s
r�c
#s�g�g�������fdd���|��D]f}i}|d}tt|��D]>}tt||��D](}	|||	||<||||	<|d7}qZqF||fVq*dS)Ncs�|dkr$��dd�t��D��dS�s,dS���}t��}�rpdd�t|dt�dd�||d�D�}nt|�d||d���}|r�|D]&}��|��|t|�����q���|�dS)	NrcSsg|]}dd�|D��qS)cSsg|]
}|�qSrr)rrrrrr�r%�@_place_legs_on_bot.<locals>.split.<locals>.<listcomp>.<listcomp>rrnrrrr�r%z5_place_legs_on_bot.<locals>.split.<locals>.<listcomp>cSsg|]}dd�|D��qS)cSsg|]}|d�qS)rJrrnrrrr�r%r�r)r�posrrrr�s�rJr!g@)�min_part�
max_length)rR�reversed�popr�	sage_partr�list)r/�current�remaining_comp�
possibilities�possibility��distrrm�legal_splitsr��space�splitrrr��s("��


z!_place_legs_on_bot.<locals>.splitr!)rr)
r�Z
num_of_points�startrmr��distZ	order_dicrrorrr�rr��s r�csVg�dd��D��dd�tt���dd�d��D�}������fdd���|��S)	NcSsg|]}g�qSrr)r�_rrrrr%z&_place_legs_on_top.<locals>.<listcomp>cSsg|]\}}|�qSrr)rrFr�rrrrr%cSs|dS)Nr!r)�orrr�<lambda>r%z$_place_legs_on_top.<locals>.<lambda>)�keycs|s6t��r2tdd��D��r2��dd��D��dStdd��D��}�dkrTdn tdd���fd	d�|D�D��}|t|�kr�dS|��}d
��|}tt���D]V}�|||kr��||8<�|�|��|��||7<�|��q�|�|�dS)Ncss|]}|dkVqdS�rNrr{rrrr:r%z5_place_legs_on_top.<locals>.splits.<locals>.<genexpr>cSsg|]}t|��qSr)r�rnrrrrr%z6_place_legs_on_top.<locals>.splits.<locals>.<listcomp>cSsg|]}|s|�qSrr)r�hitrrrr#r%r!rcss|]}|dkr|VqdSr�r)rr�rrrr:$scsg|]}d��|�qS)r�rrE)rm�
orders_botrrr%r%r�)r�rRrrSr�r)�keysr�Zremaining_pole_orderr�Z
current_orderr�r�rmr�r�r��splitsrrr�s(�z"_place_legs_on_top.<locals>.splits)r��sortedr8)r�r�rmZordered_keysrr�rr�s�r�ccs,t||�D]}t|�D]}t|�Vqq
dSr7)rrr�)�pointsr/rLZpermuted_pointsrrrr�9sr�ccs0t�d|�D]}||}|||}|VqdSr7)r<�repeat)r�rr/r�rdrrr�
_b_ary_genCsr�ccsbt|�}t||�D]H}dd�t|�D�}tt|||��D]\}}||�||�q:|VqdS)NcSsg|]}g�qSrr)r�jrrrrQr%z&_distribute_points.<locals>.<listcomp>)rrr�r�rR)r�r/rFr�
point_listr��drrrr�Ksr�ccsh||kr|}nd}t||d�D]D}g}|��D]}||g||7}q.||t|�dg7}|VqdS)N)�mr)rr�r)r.r/�maxi�	part_dictrLrmrrrr�Xsr�cs2g}|D]$�t�fdd�|D��r|���q|S)z\
    Return a list of representatives of isomorphism classes of L.

    TODO: optimise!
    c3s|]}��|�VqdSr7��
is_isomorphic�r�h�r.rrr:tr%zisom_rep.<locals>.<genexpr>)r�rR)�LZ	dist_listrr�rr�ls
r�cs$�fdd��D��fdd��D�fS)zz
    Compare two lists of LevelGraphs (up to isomorphism).

    Returns a tuple: (list L without H, list H without L)
    cs&g|]�t�fdd��D��s��qS)c3s|]}��|�VqdSr7r�r�r�rrr:r%�'comp_list.<locals>.<listcomp>.<genexpr>�r��r)�Hr�rrr%zcomp_list.<locals>.<listcomp>cs&g|]�t�fdd��D��s��qS)c3s|]}��|�VqdSr7r�r�r�rrr:�r%r�r�r�)r�r�rr�r%r)r�r�r)r�r�r�	comp_listys�r�csDd�fdd�	�g}g}�||||�t|�t|�koBt|�t|�kS)a�
    Check if graph given by the two sets of half edges is connected.
    We do this by depth-first search.
    Note that we assume that both ends of each edge have the same number,
    i.e. each edge is of the form (j,j).

    EXAMPLES::

        sage: from admcycles.diffstrata.bic import is_connected
        sage: is_connected([[1],[2]],[[1,2]])
        True
        sage: is_connected([[1],[2]],[[2],[1]])
        False
    rcsV|�|�||D]:}t|�D],\}}||vr||vrF�|||||�qqq||fSr7)rRr�)Z
current_edgesZother_edgesZseen_currentZ
seen_otherZcurrent_vertr3rr��_connected_comprrr��s
�z%is_connected.<locals>._connected_comp)rr�)r�Zhalf_edges_bottomZseen_topZseen_bottomrr�rr��s���r�cCsL|durgd�}|D]2}t|�}td|jtt|j|j�t|��f�qdS)a�
    Compare output of bics and bic_alt.

    EXAMPLES::

        sage: from admcycles.diffstrata import *
        sage: test_bic_algs()  # long time (45 seconds)  # skip, not really needed + long # doctest: +SKIP
        (1, 1): ([], [])
        (1, 1, 0, 0, -2): ([], [])
        (2, 0, -2): ([], [])
        (1, 0, 0, 1): ([], [])
        (1, -2, 2, 1): ([], [])
        (2, 2): ([], [])

        sage: test_bic_algs([(0,0),(2,1,1)])  # long time (50 seconds)  # doctest: +SKIP
        (0, 0): ([], [])
        (2, 1, 1): ([], [])

        sage: test_bic_algs([(1,0,-1),(2,),(4,),(1,-1)])
        WARNING! This is not the normal BIC generation algorithm!
        Only use if you know what you're doing!
        (1, 0, -1): ([], [])
        WARNING! This is not the normal BIC generation algorithm!
        Only use if you know what you're doing!
        (2,): ([], [])
        WARNING! This is not the normal BIC generation algorithm!
        Only use if you know what you're doing!
        (4,): ([], [])
        WARNING! This is not the normal BIC generation algorithm!
        Only use if you know what you're doing!
        (1, -1): ([], [])
    N))r!r!)r!r!rrr�)rJrr�)r!rrr!)r!r�rJr!)rJrJz%r: %r)r
r*rrr�r6r.r�)�sig_listrrZSigrrr�
test_bic_algs�s"!�����r�)N)%r<�mathr�sympy.utilities.iterablesrrr�sage.graphs.graphr�sage.combinat.compositionrr��sage.combinat.partitionr�sage.misc.cachefuncr	�admcycles.diffstrata.levelgraphrV�admcycles.diffstrata.sigr
rr6r-r+r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>s8!8
29-



!