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

��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]5}t|��d���dra�fdd	��dD�}�fd
d	��dD�}	|t|||	|�7}|t||	||�7}q,q$|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?� 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"
��r7c	s�g}dd�}t|jdd��}|���t|jdd�����dd�|jdd�D��dd�t|�D�}|D]}d	||<q3�fd
d�|jdd�D��g}	t|�D]�|	�d|���dt	�fdd�|�
��D���qMg}
|D]H�g}t|	�t���t����D]-����fd
d�tt����D�}|�����fdd�tt����D��|�|�q�|
|g7}
qntj
|
�D]2}
|�g|
�R�}tjjj|jdd�|jdd�|jdd�||dd�}|�d�r�|�d�r�|�|�q�|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�e1rrrrSsz!bics_on_bipgr.<locals>.<dictcomp>cSsg|]}d�qS�rrr"rrrrU�z!bics_on_bipgr.<locals>.<listcomp>�����csg|]}�fdd�|D��qS)csg|]}|�vr|�qSrr�r�l��	halfedgesrrrY�z,bics_on_bipgr.<locals>.<listcomp>.<listcomp>r)r�llrIrrrYs��csg|]}�|�qSrrrG)r3rrr_s�cs"i|]
}��|�|d�qSr rr")�helist�partr'rrris"cs(i|]}���|�|d�qSr rr")�halfedgeinversrNrOr'rrrks(T��quiet)r�generarJr<r�updaterr
�append�sum�
list_markingsrr=�product�	admcycles�
diffstrata�
levelgraph�
LevelGraph�is_legal�checkadmissible)rZvertupZvertdownr3r2rA�numvert�levelsr�degsZweightpartsZvweightpartZvdic�parts�
poleordersZ	CandGraphr)rPrJrNr3rOr'rr.FsZ


� �&""�����
�r.cCs&dd�tj�t|�||�d|D�S)NcSsg|]}|d�qSrDr)r�lisrrrr�z#new_list_strata.<locals>.<listcomp>r)rY�degeneration_graph�int)r/r0�rrrrr,~s
��r,c*s�t�t�r	t���dd�t�j�D�}�j}dd�t�j�D�}�j}dd�t�j�D�}t|�}�j}dd�t�j�D���j	}�j
dkr]|dkrS|}	d}
ddg}n#|d}	d}
dg}n�j
d	krr|}	d}
|dkrnddgndg}ntd
���j
d	ko�jdk}g}
t
d||d�D�]�}t�t|d	�t|ggg��D�]�}dD�]�}|dks�t||�|kr�||}|d|}nq�|dkr�t||�}nt||�}|D�]t�t
|	d�D�]j}t
|
||d�D�]]}|||}t||�D�]N�t����fd
d�t
|�D���sq�t�t|d	�t|ggg��D�]*}|D�]#}||}|d|}�j
dk�r9|dk�r9t|�dk�r9�qt||�D�]�������fdd�t
|�D�}t�fdd�|D���s^�q>�j
dk�rtt�fdd�|D��}t|�}n'�j
d	k�r�tdd�|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��q�t|�
�D�]P�t|�
�D�]F�t���
��fdd�t
�
�D���s�q�t|�
�D�](������fdd�t
�
�D�} t�
�fdd�| D���s*�q	t|�
|�
�j
|�D]�\�}!t| |!�j
�D]�	t��	��sJ�q@�D]}"|"D]}#d�j
|!|#|!|#�
<�qP�qL���t|t���D]������	�
fdd�t
�
�D������
fdd�t
|�D�}$t�fdd�t|$�D���r��qn�|$�
fdd�t
|d|�
d�D�t�|!�dg�
dg|f}%�j
dk�r�tjj j!|%�}&n�j
d	k�r�tjj"j#|%�}&ntd
��|&j$dd��r&�j
dk�r�|&j%dd��r�|
�&|&��qn�j
d	k�r"�jdk�r|&j'dd��s�jd k�r |&j(dd��r |
�&|&��qntd
��t)d!|&��qn�q@�q5�q	�q�q�q��q>�q�qq�q�q�q�q�q�q�g}'t*�}(|
D]})|)|(v�r^|'�&|)�|(�+|)��qM|'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�qSrirrjrrrr�r*cSs g|]\}}|dkr|d�qSrirrjrrrr�r*cSsi|]	\}}|d|�qSr r)rr�ordrrrr�r%z!bic_alt_noiso.<locals>.<dictcomp>r!rrMzNot implemented for k>2�gsric3sF�|]}t�fdd��|D���j�|d�jdkVqdS)c3��|]}�|VqdSr8r�r�bzr#rrr;���*bic_alt_noiso.<locals>.<genexpr>.<genexpr>rMr!N�rV�k�r�c)�distr_bot_g�distr_bot_zerosr$�sigrrr;s��
���z bic_alt_noiso.<locals>.<genexpr>csXg|](}t�fdd��|D��t�fdd��|D���jd�|d�qS)c3rmr8r�r�tzr#rrr;rp�+bic_alt_noiso.<locals>.<listcomp>.<genexpr>c3rmr8r�r�tpr#rrr;rprMrrrt)rv�distr_bot_polesrwr$rxrrrs���c3s �|]}|�jdkVqdS�r!N�rs�r�s�rxrrr;s��c3rmr8r�r�pr#rrr;%��
�cSs4g|]}|ddkr|dnt|d�d�qS)�rr!)rgr�rrrr-s4c3rmr8rr�r#rrr;.r�c3sD�|]}t�fdd��|D��t�fdd��|D��VqdS)c3rmr8rrnr#rrr;?rprqc3rmr8r)r�bpr#rrr;@rpN)rVrt)r~rwr$rrr;?s���c3sN�|]"}t�fdd��|D��d�j��jd�|dkVqdS)c3rmr8rr|r#rrr;Krprqr!rMNrrrt)�distr_top_g�distr_top_poles�num_of_edgesr$rxrrr;Ks�����csXg|](}t�fdd��|D��t�fdd��|D���jd�|d�qS)c3rmr8rr|r#rrr;Vrpr{c3rmr8rryr#rrr;WrprMrrrt)r�r��distr_top_zerosr$rxrrrVs������c3s"�|]}|d�j�kVqdSrr�r�)r�rxrrr;]s�
������cs:g|]}�|�|�|�fdd��|D��qS)csg|]}|��qSrrrG�r�rrr}rez,bic_alt_noiso.<locals>.<listcomp>.<listcomp>rrt)�distr_mpr�r��half_edges_topr�rrrzs���cs0g|]}�|�|�|��|�qSrrrt)r~rwr��half_edges_bot�top_comp_lenrrrs�
��c3s,�|]\}}�|dkrt|�dkVqdS)rr�N�r)rru�ls)rSrrr;�s��

�csg|]}||�f�qSrrrGr�rrr�rKrFTrQr�zNot admissible(!): ),�
isinstance�tupler
�	enumeraterx�zr�rr/r0rs�
ValueErrorZdifftyperr=r>r�iter�_distribute_fully�_distribute_points�_distribute_part_ordered�allrV�minrg�_place_legs_on_bot�_place_legs_on_top�is_connected�any�_merge_dictsrYrZr[r\ZquadraticlevelgraphZQuadraticLevelGraphr^r]rUZis_legal_global_squareZis_legal_primitiver+�set�add)*rx�zerosr��polesr��
marked_points�mpr/r0Z	g_bot_maxZ	g_top_min�pole_ind�	only_even�foundZbot_comp_lenrbrZ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_herurHr
Zlg_data�LGZ	found_newZ	found_set�xr)rvr~rwr�r�r�r�rSr�r�r�r$rxr�r�
bic_alt_noiso�s�
1



�
��

�
�
�
�
��
��
��
�������
����
�
�
�
��
�����������
��������������
���������������������L


�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|��}|�|�|Sr8)rrT)r��yr�rrrr��s
r�c
#s��g�g�������fdd���|��D]3}i}|d}tt|��D]}tt||��D]}	|||	||<||||	<|d7}q.q$||fVqdS)Ncs�|dkr��dd�t��D��dS�sdS���}t��}�r8dd�t|dt�dd�||d�D�}nt|�d||d���}|r^|D]}��|��|t|�����qJ��|�dS)	NrcS�g|]	}dd�|D��qS)cSsg|]}|�qSrr)rrrrrr�s�@_place_legs_on_bot.<locals>.split.<locals>.<listcomp>.<listcomp>rrtrrrr�r%z5_place_legs_on_bot.<locals>.split.<locals>.<listcomp>cSr�)cSsg|]}|d�qS)rMrrtrrrr�rer�r)r�posrrrr�s�rMr!g@)�min_part�
max_length)rU�reversed�popr�	sage_partr�list)r0�current�remaining_comp�
possibilitiesZpossibility��distrrs�legal_splitsr��space�splitrrr��s,"���

z!_place_legs_on_bot.<locals>.splitr!)rr)
r�Z
num_of_points�startrsr��distZ	order_dicr�rurrr�rr��s � 
��r�csVg�dd��D��dd�tt���dd�d��D�}������fdd���|��S)	NcS�g|]}g�qSrr)r�_rrrrrEz&_place_legs_on_top.<locals>.<listcomp>cSsg|]\}}|�qSrr)rrHr�rrrrrecSs|dS)Nr!r)�orrr�<lambda>sz$_place_legs_on_top.<locals>.<lambda>)�keycs|st��rtdd��D��r��dd��D��dStdd��D��}�dkr*dntdd���fd	d�|D�D��}|t|�krCdS|��}d
��|}tt���D]+}�|||kr��||8<�|�|��|��||7<�|��qU|�|�dS)Ncss�|]}|dkVqdS�rNrr�rrrr;rpz5_place_legs_on_top.<locals>.splits.<locals>.<genexpr>cSsg|]}t|��qSr)r�rtrrrrrez6_place_legs_on_top.<locals>.splits.<locals>.<listcomp>cSsg|]}|s|�qSrr)r�hitrrrr#rer!rcss�|]	}|dkr|VqdSr�r)rr�rrrr;$s��
�csg|]
}d��|�qS)r�rrG)rs�
orders_botrrr%sr�)r�rUrrVr�r)�keysr�Zremaining_pole_orderr�Z
current_orderr�r�rsr�r�r��splitsrrr�s*��z"_place_legs_on_top.<locals>.splits)r��sortedr9)r�r�rsZordered_keysrr�rr�s�r�ccs.�t||�D]}t|�D]}t|�VqqdSr8)rrr�)�pointsr0rOZpermuted_pointsrrrr�9s���r�ccs2�t�d|�D]}||}|||}|VqdSr8)r=�repeat)r�rr0r�rhrrr�
_b_ary_genCs��r�ccsd�t|�}t||�D]$}dd�t|�D�}tt|||��D]
\}}||�||�q|VqdS)NcSr�rr)r�jrrrrQrEz&_distribute_points.<locals>.<listcomp>)rrr�r�rU)r�r0rHr�
point_listr��drrrr�Ks��r�ccsj�||kr|}nd}t||d�D]"}g}|��D]}||g||7}q||t|�dg7}|VqdS)N)�mr)rr�r)r/r0�maxi�	part_dictrOrsrrrr�Xs��r�cs2g}|D]�t�fdd�|D��r|���q|S)z\
    Return a list of representatives of isomorphism classes of L.

    TODO: optimise!
    c3s�|]	}��|�VqdSr8��
is_isomorphic�r�h�r/rrr;ts�zisom_rep.<locals>.<genexpr>)r�rU)�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)
    c�&g|]�t�fdd��D��s��qS)c3��|]}��|�VqdSr8r�r�r�rrr;���'comp_list.<locals>.<listcomp>.<genexpr>�r��r)�Hr�rr�&zcomp_list.<locals>.<listcomp>cr�)c3r�r8r�r�r�rrr;�r�r�r�r�)r�r�rr�r�r)r�r�r)r�r�r�	comp_listys�r�csF	d�fdd�	�g}g}�||||�t|�t|�ko"t|�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%||vr#�|||||�nqq	||fSr8)rUr�)Z
current_edgesZother_edgesZseen_currentZ
seen_otherZcurrent_vertr4rr��_connected_comprrr��s
���z%is_connected.<locals>._connected_compNrDr�)r�Zhalf_edges_bottomZseen_topZseen_bottomrr�rr��s���r�cCsL|durgd�}|D]}t|�}td|jtt|j|j�t|��f�q
dS)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�)rMrr�)r!rrr!)r!r�rMr!)rMrMz%r: %r)r
r+rxr�r7r/r�)�sig_listrxZSigrrr�
test_bic_algs�s$!������r�r8)%r=�mathr�sympy.utilities.iterablesrrr�sage.graphs.graphr�sage.combinat.compositionrr��sage.combinat.partitionr�sage.misc.cachefuncr	�admcycles.diffstrata.levelgraphrY�admcycles.diffstrata.sigr
rr7r.r,r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>s:!8
29-



!