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

��c%C�@sZdZddlZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZdd	l
mZdd
lmZddlmZddlmZd
dlmZd>dd�Zdd�Zdd�Zd?dd�Zd?dd�Zdd�Zdd�Zdd�Zd?d d!�Zd?d"d#�Z d$d%�Z!d&d'�Z"d(d)�Z#d?d*d+�Z$d,d-�Z%d.d/�Z&d0d1�Z'd@d2d3�Z(d4d5�Z)d6d7�Z*d8d9�Z+d:d;�Z,d<d=�Z-dS)Az
Double ramification cycle
�N)�copy)�IntegerVectors��bernoulli_polynomial)�	factorial)�exp)�QQ)�PowerSeriesRing��list_strata)�StableGraph��DR_cycle�)�TautologicalRingFc
 s&|dur|durd�d�n|}|dur*��fdd�td�d�d�D�}|dur2dd�}�dur:dd	���
durBd
d��
�durJdd
��g}
|D�]�\��|t�����
�
dkr`qNg}���}�fdd�t|�D��dd��D�}
���}�fdd�t|�D���fdd�t|�D������
�fdd�t|�D�������
�
�fdd�|D������
fdd����D���fdd����D���fdd��D���fdd����D�}|��fdd����D��|dur�t�
d�}n	|t����g}|D]�}t|||
d�D]���fdd�t|�D�}tj|�D]։g�i�	t|�D]���	��d��	���fdd�t
�����D���q'��fdd��D�}�	�fdd��D�}|D]}|�|||9<�q\���D]]\}}��|\}}t||�}|�|�||f�
||�	|||�	|d�|��|��	|9<��|\}}t||�}|�||��|��	|9<�qp|D]}|���qЈ�|�}|��|���s�||���9}|�	|��q�q
�q|	d k�r|
�	t|��qN|
|7}
qN|	�r|
St|
�S)!a�Returns the (possibly mixed-degree) tautological class obtained by summing over graphs gamma,
    inserting vertex-, leg- and edgeterms.

    INPUT:

    - ``decgraphs`` -- list or generator; entries of decgraphs are pairs (gamma,dec) of a StableGraph
      gamma and some additional combinatorial structure dec associated to gamma

    - ``globalfact`` -- function; globalfact(gamma,dec) gets handed the parameters gamma,dec as arguments and gives out a number that is multiplied with the corresponding term in the graph sum; default is 1

    - ``vertterm`` -- function; ``vertterm(gv,nv,maxdeg, **kwargs)`` takes arguments local genus gv and number of legs nv
      and maxdeg gets handed the parameters gamma,dec,v as optional keyworded arguments and gives out a
      tautological class on Mbar_{gv,nv}; the class is assumed to be of degree at most maxdeg,
      if deg is given, the class is exactly of degree deg

    - ``legterm`` -- function; ``legterm(gv,nv,i,maxdeg, **kwargs)`` similar to vertterm, except input is
      gv,nv,i,maxdeg where i is number of marking on Mbar_{gv,nv} associated to leg
      gamma, dec and origleg (number of leg in outer graph) given as keyworded arguments

    - ``edgeterm`` -- function; edgeterm(maxdeg,**kwargs) takes keyworded arguments gamma,dec,e,maxdeg
      it gives a generating series s in x0,x1 such that the insertion at edge
      e=(h0,h1) is given by s(psi_h0, psi_h1)

    - ``termsout`` -- parameter; if termsout=False, return sum of all terms
      if termsout = 'coarse', return tuple of terms, one for each pair (gamma,dec)
      if termsout = 'fine', return tuple of terms, one for each pair (gamma,dec) and each distribution
      of cohomological degrees to vertices and half-edges
    N�cs&g|]}t��|�D]}|df�q
qS�Nr
)�.0Zednum�gr)�g�n��7/home/user/Introduction lectures/admcycles/graph_sum.py�
<listcomp>8s

��zgraph_sum.<locals>.<listcomp>rcSsdS�Nrr��a�brrr�
globalfact;szgraph_sum.<locals>.globalfactc[�t||���Sr�r�fundamental_class)�gv�nv�maxdeg�kwargsrrr�vertterm>�zgraph_sum.<locals>.verttermc[rrr )r"r#�ir$r%rrr�legtermAr'zgraph_sum.<locals>.legtermc[sttd|dd�}|��S�N�x0,x1r��default_prec)r	r�one)r$r%�Srrr�edgetermDszgraph_sum.<locals>.edgetermrcs$g|]}��|�t��|��f�qSr)�genera�len�legs�rr(��gammarrrRs$cSs g|]\}}d|d|�qS)rr)rrrrrrrS� cs"i|]
}��|�D]}||�q	qSr)r3)r�v�lr5rr�
<dictcomp>U�"zgraph_sum.<locals>.<dictcomp>cs.i|]}t��|��D]	\}}||d�qqS�r)�	enumerater3)rr8�jr9r5rrr:Vs.cs2i|]}|��|d�|d���|d��qS)rr)r6�decr8r�rr8)r?r6�gnvect�restdegr&rrr:Zs2cs@i|]}|���|d��|d�|���|d��qS)rr)r6r?�origlegrr4)r?r6rA�indexdicr)rB�vertdicrrr:[s
&�
�c	si|]}|����|d��qS))r6r?�er�rrF)r?r0r6rBrrr:]�cs*i|]\}}||f�||f�����qSr)�parent�gens�r�h0�h1��etermsrrr:^s*csi|]	}|�|���qSr)�coefficientsrGrNrrr:_�cs"i|]
\}}|�||fd�qS�rrrK��varlistrrr:`r;cs"i|]
\}}|�||fd�qSr<rrKrSrrr:ar;)�outercs(g|]}t�|t��|��d��qSr<)rr2r3r@)�degdistr6rrrks(cs"i|]
\}}|��|d�qSr<r)rr(r9)�choicer8rrr:qr;csg|]}�|��|��qSr��degree_partr@)�vdims�vtermsrrrsrHcs i|]}|�|��|��qSrrXr4)�ldims�ltermsrrr:tr7Zcoarse)�ranger2�edges�numvert�
list_markings�updater�	itertools�product�appendr=r3r�get�psi�simplify�boundary_pushforward�is_empty�sum) rr�	decgraphsrr&r)r0r$�degZtermsoutZtermlistZgammadectermlistr`Zdimvect�markingsZvarxZrdlis�rdegZvertchoicesZ	effvtermsZ	effltermsr(rLrMZgv0Znv0�R0Zgv1Znv1�R1�t�tempresr)rWr?rVr0rOrr6rArDr\r)r]rrBr8rTrZrEr&r[r�	graph_sums�(�(
&���
*
	

���
'
rtcCs|�d�|�d�kS�Nr�)�vertex)rrrr�DR11_tree_test�srxcs�fdd�td|d�D�S)NcsJg|]!}tt|�|d��D]}tdd||�D]}t|�r|�qqqS)rrrv)r^�minrrx)rrrFr�r$rrr�s
"��zDR11_trees.<locals>.<listcomp>r)r^)rr$rrzr�
DR11_trees�sr{c
s|durd|dd}g}t||�D]g}t|���d}tdd�|jD���g}t||dd�D]@}t|j�t|�}t|j�dd�t	�d�|d�D�}t|j
��fdd�t	�d�|d�D�}	|�t|||	��q0|d	d�|D�7}qt
|d
d��|S)NrrvcSsg|]	}t|dg��qSrR)�max�rr>rrrr�rQzDR11_graphs.<locals>.<listcomp>r)�min_partcSsg|]}|g�qSrrr}rrrr��csg|]
}|�d|f�qS)rvrr}��maxlegrrr�scSsg|]}|df�qSrr)r�gamrrrr�scSs|d�|d�S)Nr)�
is_isomorphicrrrr�<lambda>�rzDR11_graphs.<locals>.<lambda>)r{r2rar|r3rrr1�listr^r_rer�
removedups)
rr$�resultrrZgrlistZgdistr1r3r_rr�r�DR11_graphs�s*.r�csl�durdd��t��}t��}t|dd�D]�t���fdd�t�d|�D��r3����|d8}qdS)a6
    Remove duplicates in a list ``li`` according to a comparison function.

    This works inplace and modifies ``li``.

    EXAMPLES::

        sage: from admcycles.graph_sum import removedups
        sage: L = [4,6,3,2,4,99,1,3,2]
        sage: removedups(L)
        sage: L
        [6, 4, 99, 1, 3, 2]
    NcSs||kSrrrrrr�comp�szremovedups.<locals>.comp�����c3s"�|]}����|�VqdSrrr}�r�r(�lirr�	<genexpr>�s� zremovedups.<locals>.<genexpr>r)r2r^�any�pop)r�r�rZcurrnrr�rr��s$
��r�cCstd�|��Sr)r�automorphism_number)r6r?rrr�divbyaut�sr�csdt||��|dkr#|d}|d}���}d|j|vr!||S|St�fdd�t|d�D��S)Nrr6r8rc�g|]}d|��|��qS�r���lambdaclassr}��Rrrr�rHzDR11_vterm.<locals>.<listcomp>�rr!r3rkr^�r"r#r$r%r6r8�frr�r�
DR11_vterm�s

r�cKs6ttd|dd�}|��\}}dd||||Sr*�r	rrJ)r$r%r/�x0�x1rrr�
DR11_eterm�sr�cK�2|dur|}t|dft||d�ttt|d�|��S�Nrvrz)rlrr&r0rm)rtr�r�r�r��rrm�kwdsrrr�DR11_sum��&r�ccsD�t||�D]\}}dd�|jD�}tj|�D]}||fVqqdS)zg
    Decorate the graphs of DR11_graphs(g) with a choice of half-edge
    at each non-root vertex.
    cSsg|]}d|vr|�qSr<rr@rrrr�z"DR11_decgraphs.<locals>.<listcomp>N)r�r3rcrd)rr$Zgr0�_�LrWrrr�DR11_decgraphss���r�cCs |j�d�}t|d�|��S)Nrr)r1�countrr�)r6r?Z	zerovertsrrr�divbyaut_newsr�csbt||��|dkr"|d}|d}���}d|j|vr d|S|St�fdd�t|d�D��S)Nrr6r8rr�cr�r�r�r}r�rrrrHz"DR11_vterm_new.<locals>.<listcomp>r�r�rr�r�DR11_vterm_news
r�c	Ks`ttd|dd�}|��\}}|d}|d}d}|D]
}||vr%|d7}qdd|||S)Nr+rr,rFr?rr�)	r$r%r/r�r�rFr?�exr(rrr�DR11_eterm_new"s�r�cKr�r�)rtr�r�r�r�r�rrr�DR11_sum_new0r�r�cCst|�}|�|�|S)z�
    Computes the union of dictionaries d1, d2.

    EXAMPLES::

        sage: from admcycles.graph_sum import dicunion
        sage: d1 = {1:2, 3:4}; d2 = {1:2, 4:5};
        sage: dicunion(d1, d2)
        {1: 2, 3: 4, 4: 5}
    )rrb)�d1�d2�d3rrr�dicunion9s
r�c	#s��t��}�fdd�t|�D�}td|d|d�D]Z}t|||�D]Q}|���tj�fdd��D��D]>�t|��fdd�tt���D��������fdd�tt���D��t���fd	d
�t	|�
�|���D��rt|�fVq6q$qdS)a�
    Returns a generator of pairs (Gamma, w) of pairs of stable graphs Gamma in genus g
    and admissible k-weightings w mod r on Gamma for the weight vector Avector.

    EXAMPLES::

        sage: from admcycles.graph_sum import GammaWlist
        sage: list(GammaWlist(0, (4,-1,-2,-3), 1, 2))
        [([0] [[1, 2, 3, 4]] [], {1: 4, 2: -1, 3: -2, 4: -3}),
         ([0, 0] [[1, 2, 5], [3, 4, 6]] [(5, 6)],
          {1: 4, 2: -1, 3: -2, 4: -3, 5: 0, 6: 0}),
         ([0, 0] [[1, 3, 5], [2, 4, 6]] [(5, 6)],
          {1: 4, 2: -1, 3: -2, 4: -3, 5: 1, 6: 1}),
         ([0, 0] [[1, 4, 5], [2, 3, 6]] [(5, 6)],
          {1: 4, 2: -1, 3: -2, 4: -3, 5: 0, 6: 0})]
    csi|]	}|d�|�qSr<rr4)�Avectorrrr:[rQzGammaWlist.<locals>.<dictcomp>rrcsg|]}tt����qSr)r�r^�r�h��rrrr_r�zGammaWlist.<locals>.<listcomp>csi|]}�|d�|�qSrRrr4)r_�wrrr:`rHcs&i|]}�|d��|��qSr<rr4)r_r�r�rrr:as&c3sJ�|] \}}�d|dt|�t�fdd�|D���dkVqdS)rvc3s�|]}�|VqdSrrr�)�dicrrr�bs�z'GammaWlist.<locals>.<genexpr>.<genexpr>rN)r2rk)rr"Zhev)r��kr�rrr�bs�HzGammaWlist.<locals>.<genexpr>N)r2r^rr_rcrdr�rb�all�zipr1r3)rr�r�r�rZstdicrFr6r)r�r�r_r�r�r�r�
GammaWlistIs�"$(
����r�c���fdd�}|S)Ncs0|��|��d}�d�d||��Sru)�	num_edges�	num_vertsr�)r6r�rM�rr�rr�GFgszChiodo_GF.<locals>.GFr)rr�r�rr�r�	Chiodo_GFfsr�cCsNddlm}|dd�|dur#|durt||�}nt|�}||���S|��S)aF
    Given a tautological class x on Mbar_{g,n} of degree at least 1, returns
    the exponential exp(x) = 1 + x + 1/2*x^2 + ... of x.

    EXAMPLES::

        sage: from admcycles.graph_sum import expclass
        sage: from admcycles import TautologicalRing
        sage: R = TautologicalRing(1, 2)
        sage: expclass(R.psi(1))
        doctest:...: DeprecationWarning: expclass is deprecated. Please use the exp method of TautologicalClass instead
        See https://gitlab.com/modulispaces/admcycles/-/merge_requests/109 for details.
        Graph :      [1] [[1, 2]] []
        Polynomial : 1 + psi_1 + 1/2*psi_1^2

    TESTS::

        sage: from admcycles import TautologicalRing
        sage: R = TautologicalRing(0, 3)
        sage: expclass(R.zero(), 0, 3)
        Graph :      [0] [[1, 2, 3]] []
        Polynomial : 1
    r)�deprecation�mzNexpclass is deprecated. Please use the exp method of TautologicalClass insteadN)�
supersededr�rr)�xrrr�r�rrr�expclassms
r�cr�)NcsHt||��t���fdd�tdd|d|d�D��}�|���S)Nc3sD�|]}d|dt��|d�||d��|�VqdS�r�rN)r�kappa�r�m)r�r�r�rrr��s�<�z.Chiodo_vterm.<locals>.vterm.<locals>.<genexpr>rr�rrkr^r)r"r#r$r%�expo�r�r�r�r�vterm�s


�zChiodo_vterm.<locals>.vtermr)r�r�r�rr�r�Chiodo_vterm�sr�c��fdd�}|S)Ncs`t||��|d}|d}||�t����fdd�tdd|d|d�D��}�|���S)Nr?rCc3sH�|]}d|dt��|d�||d����|VqdSr�)rrgr�)r��air(r�rrr��s� ���z2Chiodo_legterm.<locals>.legterm.<locals>.<genexpr>rrr�)r"r#r(r$r%r?rCr�r�)r�r�r(rr)�s
�zChiodo_legterm.<locals>.legtermr)r�r)rr�r�Chiodo_legterm�sr�cr�)Ncst|d}|d}||d�ttd|dd�}|��\��t����fdd�td	|d
�D��}d	t|���S)Nr?rFrr+�r,c3sL�|]!}d|dt��|d�||d�|�|VqdSr�rr�)r��whr�r�rrr��s� ���z1Chiodo_edgeterm.<locals>.eterm.<locals>.<genexpr>rr)r	rrJrkr^r)r$r%r?rFr/r�r�)r�r�r�r�eterm�s�zChiodo_edgeterm.<locals>.etermr)r�r�rr�r�Chiodo_edgeterm�s
r�c
	CsPt|�}t||||�}t||�}t||�}t|�}t|�}	t|||||||	d�S)a
    Computes the mixed-degree class epsilon_* c(-R^* pi_* L) from [JPPZ17]_, Corollary 4.

    This agrees with the corresponding sum of DR_cycles with chiodo_coeff=True, weighted by appropriate powers of r.

    EXAMPLES::

        sage: from admcycles.graph_sum import Chiodo, Chiodo_alt
        sage: g=1; A=(0,0); k=2; r=2;
        sage: (Chiodo_alt(g, A, k, r)-Chiodo(g, r, k, A, 1)).simplify()
        0
        sage: g=1; A=(1,1); k=4; r=3;
        sage: (Chiodo_alt(g, A, k, r)-Chiodo(g, r, k, A, 1)).simplify()
        0
    )rlrr&r)r0)r2r�r�r�r�r�rt)
rr�r�r�rZGWlistr�r�Zltermr�rrr�
Chiodo_alt�s

r�cs:t��}t�����fdd�td�d|d�D��S)Nc
3sD�|]}�d�d|d�|t��|�d�d�VqdS)rvrT)�chiodo_coeff�r_coeffNr
)r�d��Arr�r�r�rrr��s�BzChiodo.<locals>.<genexpr>rr)r2rkr^)rr�r�r�r�rrr�r�Chiodo�s2r�)NNNNNNNFr)NN).�__doc__rcr�sage.combinat.integer_vectorr�sage.combinat.combinatr�sage.arith.allr�sage.functions.logr�sage.rings.allr�sage.rings.power_series_ringr	Zadmcycles.admcyclesrZadmcycles.stable_graphrZ#admcycles.double_ramification_cycler�tautological_ringrrtrxr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>sJ





	
#