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

��cRr�@sVddlmZddlmZddlZddlZddlZdiiifdd�ZGdd�de�Z	dS)�)�
SageObject)�flattenNc
 
s��dus�dur
dSt�tjjj�r�j�t�tjjj�r �j�t�tjjj�r+�j��dur8�jj�jj}
n�jj�jj�jj}
�j���	�fdd�t	�	�D���fdd��jj
D�}�durhd�i�n�j�����	fdd�t	��D��|�fdd��jj
D�7}�j��}���	fd	d�t	|�D��|�fd
d��jj
D�7}dd�t	�	�|�D�}
g}g}i}i}�dur�g}ng}g}g}d}d}�durވ||��f�||��ff}n�|if�|	if�|iff}|D]�\�}}i�t
t�jj��D]/\}}||d}|�|<�jj|||<|d7}z|�j|||<Wq�t�y,Yq�w||7}|�fd
d��jjD�7}|�fdd��jjD�7}�du�r`|�t��fdd�|D���q��u�r�|�t��fdd�|��D���|�t��fdd�|��D���q��u�r�|�t��fdd�|��D���|�t��fdd�|��D���q��u�s�J�|�t��fdd�|��D���|�t��fdd�|��D���q�du�r�t|�dk�s�J�|tt|��7}n/t|�dk�s�J�t|�dk�sJ�t|�dk�sJ�|tt|��tt|��tt|��7}tjj�|
||||�}tjj�||||
�}|���s>td��|S)an
    Clutch EmbeddedLevelGraphs top and bottom to get a new EmbeddedLevelGraph.

    If middle is specified, we do a "double clutching" top - middle - bottom to
    give a graph in X.

    .. NOTE::

        * this cannot be split into two steps, as the intermediate graph is
          not a graph in X!
        * We include the possibility to clutch points in the top component *past*
          the middle to the bottom component (long edges!)

    This is the inverse procedure to EmbeddedLevelGraph.split() and
    GeneralisedStratum.doublesplit().

    Note that if top or bottom is None, we return None.

    INPUT:

    X (GeneralisedStratum): Stratum that the clutched graph will live in

    top (EmbeddedLevelGraph): Top component to be clutched

    bottom (EmbeddedLevelGraph): Bottom component to be clutched

    middle (EmbeddedLevelGraph, optional, defaults to None): Middle component to
    be clutched.

    clutch_dict (dict): The dictionary giving the clutching information,
    (i.e. the edges that will be inserted).
    In the case of a "simple clutch", i.e. top to bottom with no middle,
    a dictionary:

    * point on top stratum -> point on bottom stratum
      In the case of a middle graph, i.e. a "double clutching":
    * point on top stratum -> point on middle stratum.
      In this case, we also need clutch_dict_lower for the other clutching
      and clutch_dict_long for the long edges.

    clutch_dict_lower (dict, optional): In the case of a "double clutching", the
    info for the "lower" clutching, i.e. a dictionary
    point on middle stratum -> point on bottom stratum

    clutch_dict_long (dict, optional): In the case of a "double clutching", the
    info for the "long edges", i.e. a dictionary
    point on top stratum -> point on bottom stratum

    emb_dict_top (dict): dictionary giving the embedding of the resulting
    EmbeddedLevelGraph, i.e. points on top stratum -> point on
    enveloping stratum.

    emb_dict_bot (dict): dictionary giving the embedding of the resulting
    EmbeddedLevelGraph, i.e. points on bottom stratum -> point on
    enveloping stratum.

    emb_dict_mid (dict, optional): dictionary giving the embedding of the
    resulting EmbeddedLevelGraph, i.e. points on middle stratum -> point on
    enveloping stratum.

    OUTPUT:

    EmbeddedLevelGraph: Clutched LevelGraph together with embedding.

    Returns:
        tuple: EmbeddedLevelGraph: as above

    EXAMPLES::

        sage: from admcycles.diffstrata import *
        sage: X=GeneralisedStratum([Signature((1,1))])
        sage: assert clutch(**X.bics[1].split()).is_isomorphic(X.bics[1])
        sage: assert all(clutch(**B.split()).is_isomorphic(B) for B in X.bics)

        The same works for 3-level graphs and doublesplit:

        sage: X=GeneralisedStratum([Signature((1,1))])
        sage: assert all(X.lookup_graph(*ep).is_isomorphic(clutch(**X.doublesplit(ep))) for ep in X.enhanced_profiles_of_length(2))
        sage: X=GeneralisedStratum([Signature((2,2,-2))])
        sage: assert all(X.lookup_graph(*ep).is_isomorphic(clutch(**X.doublesplit(ep))) for ep in X.enhanced_profiles_of_length(2))  # long time (4 seconds)
    Ncsi|]
}�j�|�|�qS���LG�internal_level_number��.0�l)�topr�G/home/user/Introduction lectures/admcycles/diffstrata/stratatautring.py�
<dictcomp>�s���zclutch.<locals>.<dictcomp>c�g|]}�|�qSrrr)�top_level_dictrr�
<listcomp>��zclutch.<locals>.<listcomp>rcs i|]}�j�|�|��qSrrr)�middle�
top_levelsrrr
�s�crrrr)�mid_level_dictrrr�rcs$i|]}�j�|�|���qSrrr)�bottom�
mid_levelsrrrr
�s
�����crrrr)�bot_level_dictrrr�rcSsi|]}||�qSrrrrrrr
�s�csg|]}�fdd�|D��qS)crrrr��leg_dictrrr�rz%clutch.<locals>.<listcomp>.<listcomp>r)r	�comprrrr�scs$g|]}�|d�|df�qS)rrr)r	�errrr�s$c3��|]
}��j|VqdS�N��dmp_inv�r	�p��emb_grrr�	<genexpr>s�zclutch.<locals>.<genexpr>c3rrrr!r#rrr%!��
�c3rrrr!r#rrr%$r&c3rrrr!r#rrr%(r&c3rrrr!r#rrr%+r&c3rrrr!r#rrr%0r&c3rrrr!r#rrr%3r&��/Illegal clutch, this should not happen anymore!)�
isinstance�	admcycles�
diffstrata�generalisedstratum�LevelStratum�	smooth_LGr�genera�numberoflevels�range�levels�keys�values�	enumerater�legs�
poleorders�dmp�KeyError�edges�append�tuple�len�list�zip�
levelgraph�
LevelGraph�embeddedlevelgraph�EmbeddedLevelGraph�is_legal�RuntimeError) �Xrr�clutch_dict�emb_dict_top�emb_dict_botr�clutch_dict_lower�clutch_dict_long�emb_dict_midZ	newgeneraZ	newlevelsZ
bot_levelsZ
newdlevelsZnewlegsZnewedgesZ
newpoleordersZnewdmpZclutch_edgesZclutch_edges_tmZclutch_edges_mbZclutch_edges_tbZleg_number_shiftr6Z	comp_dataZemb_dictZ
clutch_points�ir
Znewlegnumberr�ELGr)
rrr$rrrrrrrr�clutch+s�\
�
�

�
�
�	��	�
�

��

��
��

�
�
��
rOc@sdeZdZdZdd�Zdd�Zdd�Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�GenDegenerationGrapha�
    The degeneration graph of the Generalised Stratum X.

    A degeneration graph of a (generalised) stratum is built recursively.
    For that we need to know:

    * The BICs inside X
    * For each BIC its top and bottom component (generalised strata)
    * For each BIC the clutching map of these components
    * For each top and bottom component of each BIC an embedding of their
      respective BICs into BIC(X)

    This allows us to translate products of BICs on X into clutchings of
    products of BICs on top and bottom components and gives a recursive
    procedure to compute the LevelGraph(s) for any product of BICs in X.

    INPUT:

    X (GeneralisedStratum): The GeneralisedStratum we give the degeneration
    graph of.
    cs�|�_t�jj��_dd�t�j�D��_dd�t�j�D��_i�_dd�t�j�D��_dd�t�j�D��_	i�_
�fdd�t�j�D��_�fdd�t�j�D��_g�_
t��_d�_dS)NcS�g|]}d�qSrr�r	�_rrrrk�z1GenDegenerationGraph.__init__.<locals>.<listcomp>cSrQrrrRrrrrmrTcSrQrrrRrrrrprTcSrQrrrRrrrrrrTc�g|]	}tt�j���qSr�r>r1�nrR��selfrrry��crUrrVrRrXrrr{rZ)rFr=�bicsrWr1�_top_to_bic�_bot_to_bic�_middle_to_bic�_top_to_bic_inv�_bot_to_bic_inv�_middle_to_bic_inv�_unused_bics_top�_unused_bics_bot�
_triple_prods�set�_triple_prod_set�_triple_prod_set_list)rYrFrrXr�__init__hs2
�
�
�
�
�
�
zGenDegenerationGraph.__init__cCs
d|jS)NzGenDegenerationGraph(X=%r))rFrXrrr�__repr__�s
zGenDegenerationGraph.__repr__cCs|j�|�|j�|�dSr)rdr;rf�add)rY�trrr�_append_triple_prod�sz(GenDegenerationGraph._append_triple_prodcCs@|jdurt|j�D]}|�|�|�|�q
t|j�|_|jS)z�
        A list of profiles of the 3-level graphs in X.

        Note that this is generated on first call.

        Returns:
            list: list of tuples of length two of indices of X.bics.
        N)rgr1rW�
top_to_bic�
bot_to_bicr>rf)rYrMrrr�triple_prods�s


z!GenDegenerationGraph.triple_prodsc	
Cs|j|dur�|jj|}i}t|jj�D]g\}}t|j||j|j|j|j	�}|dur/t
d��|�d�}|j|D]8}||kr@q9|�
|jj|�rq|||<|�||f�|j|duroz
|j|�|�Wn	tynYnwnq9t
d|||jf��q|��|j|<|j|S)a�
        A dictionary indices of BICs of X.bic[i].top -> indices of X.bics.

        Note that this is created once and then reused.

        Args:
            i (int): Index of X.bics

        Raises:
            RuntimeError: Raised if the squish of the clutching of a degeneration of
                the top component with X.bic[i].bot is not found in X.bics.

        Returns:
            dict: Dictionary mapping BICs of X.bic[i].top to indices of X.bics.
        Nr(rz3delta(1) of %s, %s, not found in list of BICs of %s)r\rFr[r5rrO�botrG�emb_top�emb_botrE�deltarb�
is_isomorphicrlr]rc�remove�
ValueError�copy)	rYrM�Brm�jZBt�G�squished_bic�im_jrrrrm��D��
��
���
zGenDegenerationGraph.top_to_bicc	
Cs|j|dur�|jj|}i}t|jj�D]g\}}t|j|j||j|j|j	�}|dur/t
d��|�d�}|j|D]8}||kr@q9|�
|jj|�rq|||<|�||f�|j|duroz
|j|�|�Wn	tynYnwnq9t
d|||jf��q|��|j|<|j|S)a�
        A dictionary indices of BICs of X.bic[i].bot -> indices of X.bics.

        Note that this is created once and then reused.

        Args:
            i (int): Index of X.bics

        Raises:
            RuntimeError: Raised if the squish of the clutching of a degeneration of
                the bottom component with X.bic[i].top is not found in X.bics.

        Returns:
            dict: Dictionary mapping BICs of X.bic[i].bot to indices of X.bics.
        Nr(r'z3delta(2) of %s, %s, not found in list of BICs of %s)r]rFr[r5rprOrrGrqrrrErsrcrtrlr\rbrurvrw)	rYrMrxrnryZBbrzr{r|rrrrn�r}zGenDegenerationGraph.bot_to_bicc
Csr||jvr�|\}}t|�dkrtd|f��i}|j�|�}|d}t�}t|�|d����}|�|d���D]}	|	|vrD|�	|	�q9t
|j�D]b\}}
|
|d<td
i|��}|�
d��|jj|d�siJ�|�
d��|jj|d�syJ�|�
d�}|D]}	|�|jj|	�r�||vr�td|||jf��|	||<q�||vr�td|||jf��qJ|��|j|<|j|S)aM
        A dictionary for each 3-level graph mapping (indices of) BICs of the middle level
        to (indices of) BICs of the enveloping stratum.

        Raises a RuntimeError if

        * either enh_profile is not a 3-level graph
        * or if a degeneration of the middle level is isomorphic
          (after squishing) to more than one BIC of X.
        * or if no isomorphic BIC of X is found.

        INPUT:

        enh_profile (tuple): Enhanced profile of a 3-level graph.

        OUTPUT:

        dictionary: indices of bics of the middle level -> indices of X.bics
        r'z2Only 3-level graphs have a well-defined middle! %rrrr�z:BIC %r of %r seems to be isomorphic to several BICs of %r!z%BIC %r of %r not found in BICs of %r!Nr)r^r=rErF�doublesplitrermr4rnrjr5r[rOrsrtrw)
rY�enh_profiler"rMZ
mid_to_bic�clutching_info�L�
candidatesZtop_deg�brx�HZXBrrr�
middle_to_bicsT
��
�  

���
���
z"GenDegenerationGraph.middle_to_bicc	C�x|j|dur7i|j|<|�|�}|��D]!\}}z|j||�|�Wqty6|g|j||<Yqw|j|S)a�
        Inverse of top_to_bic.

        More Precisely: A dictionary assigning indices of X.bics a list of indices of
        X.top.bics. Note that this can be more than one (if the intersection is not
        irreducible).

        Note also that not all indices of X.bics are keys (but if not, they should be
        keys of bot_to_bic_inv)!

        Args:
            i (int): index of X.bics

        Returns:
            dict: index of X.bics -> list of indices of X.top.bics.
        N)r_rm�itemsr;r9�rYrM�dryr|rrr�top_to_bic_invM�

�
z#GenDegenerationGraph.top_to_bic_invc	Cr�)a�
        Inverse of :meth:`bot_to_bic`.

        More Precisely: A dictionary assigning indices of X.bics a list of indices of
        X.bot.bics. Note that this can be more than one (if the intersection is not
        irreducible).

        Note also that not all indices of X.bics are keys (but if not, they should be
        keys of top_to_bic_inv)!

        Args:
            i (int): index of X.bics

        Returns:
            dict: index of X.bics -> list of indices of X.bot.bics.
        N)r`rnr�r;r9r�rrr�bot_to_bic_invhr�z#GenDegenerationGraph.bot_to_bic_invc	Cst||jvr5i|j|<|�|�}|��D]!\}}z|j||�|�Wqty4|g|j||<Yqw|j|S)a�
        Inverse of middle_to_bic.

        More Precisely: A dictionary assigning indices of X.bics a list of indices of
        {middle level of enh_profile}.bics.
        Note that this can be more than one (if the intersection is not
        irreducible).

        INPUT:

        enh_profile (tuple): enhanced profile of a 3-level graph.

        OUTPUT:

        index of X.bics -> list of indices of {middle level of enh_profile}.bics.
        )rar�r�r;r9)rYr�r�ryr|rrr�middle_to_bic_inv�s


�
z&GenDegenerationGraph.middle_to_bic_invN)�__name__�
__module__�__qualname__�__doc__rhrirl�propertyrormrnr�r�r�r�rrrrrPRs
66ArP)
�sage.structure.sage_objectr�sage.misc.flattenr�'admcycles.diffstrata.generalisedstratumr*�admcycles.diffstrata.levelgraph�'admcycles.diffstrata.embeddedlevelgraphrOrPrrrr�<module>s+
�)