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

��c�@s\ddlmZddlmZddlZddlZdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�)�defaultdict)�flattenNcCstjjjt|tjjj��S)N)�	admcycles�
diffstrata�embeddedlevelgraph�EmbeddedLevelGraph�unite_embedded_k_graphs�
levelgraph�
LevelGraph)�gen_LGs�r�B/home/user/Introduction lectures/admcycles/diffstrata/auxiliary.py�unite_embedded_graphss��rc
sHg}g}g}i}g}i}i}d}	|dd}
|D]v}|\}}
}�||
kr*td|��||
j7}|�fdd�|
jD�7}i�d}tt|
j��D]+\}}|	|d}|�|<|
j|||<z||||<Wn	tylYnw|d7}qF|	|7}	|�fdd�|
jD�7}|�fdd�|
jD�7}qdd	�|D�}||||||�}||||fS)
a
    Create a (disconnected) EmbeddedLevelGraph from a tuple of tuples that generate EmbeddedLevelGraphs.

    (The name is slightly misleading, but of course it does not make sense to actually unite two complete
    EmbeddedLevelGraphs, as the checks would (and do!) throw errors otherwise! Therefore, this essentially
    takes the data of a LevelGraph embedded into each connected componenent of a GeneralisedStratum and
    returns an EmbeddedLevelGraph on the product.)

    This should be used on (products) of BICs in generalised strata.

    INPUT:

    gen_LGs: tuple
    A tuple of tuples that generate EmbeddedLevelGraphs.
    More precisely, each tuple is of the form:

    * X (GeneralisedStratum): Enveloping stratum (should be the same for all tuples!)
    * LG (LevelGraph): Underlying LevelGraph
    * dmp (dict): (partial) dictionary of marked points
    * dlevels (dict): (partial) dictionary of levels

    clsELG: class of the graph to return, either EmbeddedLevelGraph or EmbeddedQuadraticLevelGraph

    clsLG: class of the underlying levelgraph, either LevelGraph or QuadraticLevelGraph

    OUTPUT:

    The (disconnected) LevelGraph obtained from the input with the legs
    renumbered (continuously, starting with 1), and the levels numbered
    according to the embedding.
    rz*Can't unite graphs on different Strata! %rc�g|]}�|�qSrr��.0�l)�dlevelsrr
�
<listcomp>L�z+unite_embedded_k_graphs.<locals>.<listcomp>�csg|]}�fdd�|D��qS)crrrr��leg_dictrr
r`rz6unite_embedded_k_graphs.<locals>.<listcomp>.<listcomp>r)r�comprrr
r`scs$g|]}�|d�|df�qS)rrr)r�errr
rbs$cSsi|]}||�qSrrrrrr
�
<dictcomp>dsz+unite_embedded_k_graphs.<locals>.<dictcomp>)	�RuntimeError�genera�levels�	enumerater�legs�
poleorders�KeyError�edges)rZclsLG�	newgenera�	newlevels�newlegs�
newpoleorders�newedges�newdmp�
newdlevelsZmax_leg_numberZoldX�emb_g�X�LG�dmpr �ir�newlegnumber�newLGr)rrr
rsJ �
�

�rcCsHg}i}ttt|�dd�d��D]\}\}}|�|�|||<q||fS)aY
    Sort a list and provide a dictionary relating old and new indices.

    If x had index i in l, then x has index sorted_dict[i] in the sorted l.

    Args:
        l (list): List to be sorted.

    Returns:
        tuple: A tuple consisting of:
            list: The sorted list l.
            dict: A dictionary old index -> new index.
    cS�|dS�Nrr)�wrrr
�<lambda>{�z sort_with_dict.<locals>.<lambda>��key)r�sorted�append)r�sorted_listZsorted_dictr/�j�vrrr
�sort_with_dictks$

r>cCsD|d}t|d�}t|�D]\}}||vr|Sqtd||f��)a`
    Get the (relative) level number of the level squished in ep.

    This is the index of the corresponding BIC in the profile.

    Args:
        deg_ep (tuple): enhanced profile
        ep (tuple): enhanced profile

    Raises:
        RuntimeError: raised if deg_ep is not a degeneration of ep

    Returns:
        int: relative level number
    rz%r is not a degeneration of %r!)�setrr)Zdeg_ep�epZdeg_p�pr/�brrr
�get_squished_level�s�rCcCs4|durd}ntt|����}|t|d�|dfS)a�
    The hash of an AdditiveGenerator, built from the psis and the enhanced profile.

    The hash-tuple is (leg-tuple,profile,index), where profile is
    changed to a tuple and leg-tuple is a nested tuple consisting of
    tuples (leg,exponent) (or None).

    Args:
        leg_dict (dict): dictioary for psi powers (leg -> exponent)
        enh_profile (tuple): enhanced profile

    Returns:
        tuple: nested tuple
    Nrrr)�tupler9�items)r�enh_profileZleg_hashrrr
�hash_AG�srGcCsLi}g}tt�}ttt|�dd�d��D],\}\}}|d}|d}	|�|�|	|vr@||vs1J�||	}
|
||<||�|
�qi}d}t|�t|�ksOJ�|t|�kr�||}tt||��D]\}
}
|||
|ksoJ�|
|||
d<qa|t|�kr�|||kr�|d7}|t|�kr�|||ks�|t|�ksUt|�tt|����fS)a�
    The hash of a psi monomial on a connected stratum without residue conditions.

    This is used for caching the values computed using admcycles (using
    GeneralisedStratum.adm_evaluate)

    The signature is sorted, the psis are renumbered accordingly and also
    sorted (with the aim of computing as few duplicates as possible).

    Args:
        sig (tuple): signature tuple
        psis (dict): psi dictionary

    Returns:
        tuple: nested tuple
    cSr2r3r)�krrr
r5�r6zadm_key.<locals>.<lambda>r7rr)r�listrr9r:�lenrDrE)�sig�psisZsorted_psisZ
sorted_sigZpsi_by_order�new_iZold_i�orderZ	psi_new_iZ	psi_old_iZpsi_expZordered_sorted_psisr/r<rrr
�adm_key�s8�
���rO)
�collectionsr�sage.misc.flattenr�admcycles.diffstrata.levelgraphr�'admcycles.diffstrata.embeddedlevelgraphrrr>rCrGrOrrrr
�<module>s	T