unlisted
ubuntu2004o
��c� � @ s& d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z ddl
mZ ddlm
Z
dd lmZ dd
lmZ ddlmZ ddlmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+ G dd� de�Z,dd� Z-ddd�Z.dS )z
Stable graphs
� N��defaultdict)�prod)�
SageObject)�Permutations)�Subsets)�ZZ)�
FreeModule)�floor)�Graph)�Integer)� factorial)�SymmetricGroup)� polygon2d)�text)�bezier_path)�line)�circle� )�deprecated_function_alias)� MODULI_ST� MODULI_TL� MODULI_CT� MODULI_RT� MODULI_SMc @ sh e Zd ZdZg d�Zd�dd�Zdd� Zd d
� Zdd� Zd�d
d�Z dd� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd � Zd�d!d"�Zd�d#d$�Zd�d%d&�Zd'd(� Zd�d*d+�Zd�d,d-�Zd.d/� Zd0d1� Zd2d3� Zd4d5� Zd6d7� Zd�d8d9�Zd�d:d;�Zd<d=� Z d�d>d?�Z!e Z"d@dA� Z#dBdC� Z$d�dDdE�Z%dFdG� Z&d�dHdI�Z'dJdK� Z(dLdM� Z)dNdO� Z*d�dPdQ�Z+dRdS� Z,dTdU� Z-dVdW� Z.dXdY� Z/dZd[� Z0d\d]� Z1d�d^d_�Z2d`da� Z3d�dbdc�Z4ddde� Z5dfdg� Z6d�dhdi�Z7i i i fdjdk�Z8dldm� Z9d�dndo�Z:dpdq� Z;d�drds�Z<dtdu� Z=d�dvdw�Z>e?dxe>�Z@dydz� ZAd{d|� ZBd�d~d�ZCd�d�� ZDd�d�� ZEd�d�� ZFd�d�� ZGd�d�d��ZHd�d�� ZId)S )��StableGrapha
Stable graph.
A stable graph is a graph (with allowed loops and multiple edges) that
has "genus" and "marking" decorations at its vertices. It is represented
as a list of genera of its vertices, a list of legs at each vertex and a
list of pairs of legs forming edges.
The markings (the legs that are not part of edges) are allowed to have
repetitions.
EXAMPLES:
We create a stable graph with two vertices of genera 3,5 joined by an edge
with a self-loop at the genus 3 vertex::
sage: from admcycles import StableGraph
sage: StableGraph([3,5], [[1,3,5],[2]], [(1,2),(3,5)])
[3, 5] [[1, 3, 5], [2]] [(1, 2), (3, 5)]
The markings can have repetitions::
sage: StableGraph([1,0], [[1,2], [3,2]], [(1,3)])
[1, 0] [[1, 2], [3, 2]] [(1, 3)]
It is also possible to create graphs which are not necessarily stable::
sage: StableGraph([1,0], [[1], [2,3]], [(1,2)])
[1, 0] [[1], [2, 3]] [(1, 2)]
sage: StableGraph([0], [[1]], [])
[0] [[1]] []
If the input is invalid a ``ValueError`` is raised::
sage: StableGraph([0, 0], [[1], [2], [3]], [])
Traceback (most recent call last):
...
ValueError: genera and legs must have the same length
sage: StableGraph([0, 'hello'], [[1], [2]], [(1,2)])
Traceback (most recent call last):
...
ValueError: genera must be a list of non-negative integers
sage: StableGraph([0, 0], [[1,2], [3]], [(3,4)])
Traceback (most recent call last):
...
ValueError: the edge (3, 4) uses invalid legs
sage: StableGraph([0, 0], [[2,3], [2]], [(2,3)])
Traceback (most recent call last):
...
ValueError: the edge (2, 3) uses invalid legs
)�_genera�_legs�_edges�_maxleg�_mutable�_graph_cache�_canonical_label_cache�_hashFTc C sl |r�t |t�rt |t�rt |t�std��t|�t|�kr!td��tdd� |D ��s.td��tt�}t|�D ])\}}t |t�sCtd��|D ]} t | tt f�rR| dkrVtd��|| d 7 <