§
    bŠtjP;  ã                   ó²  — d Z ddlZddlZg d¢Z ej        dd¬¦  «        dd„¦   «         Z ej        dd¬¦  «        dd„¦   «         Z ej        dd¬¦  «        dd„¦   «         Zej	        j
                             d	¦  «         ej        dd¬¦  «        dd
ddœd„¦   «         ¦   «         Zdd
ddœd„Zej	                             d¦  «        ej	                             d¦  «         ej        dddii¬¦  «        ddœd„¦   «         ¦   «         ¦   «         Zej	        j
                             d	¦  «         ej        dd¬¦  «        ddd
ddœd„¦   «         ¦   «         ZdS )z3Provides explicit constructions of expander graphs.é    N)Úmargulis_gabber_galil_graphÚchordal_cycle_graphÚpaley_graphÚmaybe_regular_expanderÚmaybe_regular_expander_graphÚis_regular_expanderÚrandom_regular_expander_graphT)ÚgraphsÚreturns_graphc                 óâ  — t          j        d|t           j        ¬¦  «        }|                     ¦   «         s|                     ¦   «         sd}t          j        |¦  «        ‚t          j        t          | ¦  «        d¬¦  «        D ]]\  }}|d|z  z   | z  |f|d|z  dz   z   | z  |f||d|z  z   | z  f||d|z  dz   z   | z  ffD ]\  }}| 	                    ||f||f¦  «         Œ Œ^d| › d�|j
        d	<   |S )
aÐ  Returns the Margulis-Gabber-Galil undirected MultiGraph on `n^2` nodes.

    The undirected MultiGraph is regular with degree `8`. Nodes are integer
    pairs. The second-largest eigenvalue of the adjacency matrix of the graph
    is at most `5 \sqrt{2}`, regardless of `n`.

    Parameters
    ----------
    n : int
        Determines the number of nodes in the graph: `n^2`.
    create_using : NetworkX graph constructor, optional (default MultiGraph)
       Graph type to create. If graph instance, then cleared before populated.

    Returns
    -------
    G : graph
        The constructed undirected multigraph.

    Raises
    ------
    NetworkXError
        If the graph is directed or not a multigraph.

    r   ©Údefaultú0`create_using` must be an undirected multigraph.é   )Úrepeaté   zmargulis_gabber_galil_graph(ú)Úname)ÚnxÚempty_graphÚ
MultiGraphÚis_directedÚis_multigraphÚNetworkXErrorÚ	itertoolsÚproductÚrangeÚadd_edgeÚgraph)ÚnÚcreate_usingÚGÚmsgÚxÚyÚuÚvs           ú[/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/generators/expanders.pyr   r   2   s.  € õ4 	Œ�q˜,µ´Ð>Ñ>Ô>€AØ‡}‚}�„ð $˜aŸošoÑ/Ô/ð $Ø@ˆÝÔ˜sÑ#Ô#Ð#åÔ!¥%¨¡(¤(°1Ð5Ñ5Ô5ð 'ð '‰ˆˆ1à�!�a‘%‰i˜1‰_˜aÐ Ø�1�q‘5˜1‘9‰o Ñ" AÐ&Ø��Q˜‘U‘˜a‘Ð Ø��a˜!‘e˜a‘i‘ AÑ%Ð&ð	
ð 	'ð 	'‰DˆAˆqð �JŠJ˜˜1�v  1˜vÑ&Ô&Ð&Ð&ð	'ð :°QÐ9Ð9Ð9€A„GˆF�OØ€Hó    c                 ó˜  — t          j        d|t           j        ¬¦  «        }|                     ¦   «         s|                     ¦   «         sd}t          j        |¦  «        ‚t          | ¦  «        D ]L}|dz
  | z  }|dz   | z  }|dk    rt          || dz
  | ¦  «        nd}|||fD ]}|                     ||¦  «         ŒŒMd| › d�|j	        d<   |S )	u  Returns the chordal cycle graph on `p` nodes.

    The returned graph is a cycle graph on `p` nodes with chords joining each
    vertex `x` to its inverse modulo `p`. This graph is a (mildly explicit)
    3-regular expander [1]_.

    `p` *must* be a prime number.

    Parameters
    ----------
    p : a prime number

        The number of vertices in the graph. This also indicates where the
        chordal edges in the cycle will be created.

    create_using : NetworkX graph constructor, optional (default=nx.Graph)
       Graph type to create. If graph instance, then cleared before populated.

    Returns
    -------
    G : graph
        The constructed undirected multigraph.

    Raises
    ------
    NetworkXError

        If `create_using` indicates directed or not a multigraph.

    References
    ----------

    .. [1] Theorem 4.4.2 in A. Lubotzky. "Discrete groups, expanding graphs and
           invariant measures", volume 125 of Progress in Mathematics.
           BirkhÃ¤user Verlag, Basel, 1994.

    r   r   r   r   r   zchordal_cycle_graph(r   r   )
r   r   r   r   r   r   r   Úpowr   r   )	Úpr!   r"   r#   r$   ÚleftÚrightÚchordr%   s	            r(   r   r   ]   sô   € õN 	Œ�q˜,µ´Ð>Ñ>Ô>€AØ‡}‚}�„ð $˜aŸošoÑ/Ô/ð $Ø@ˆÝÔ˜sÑ#Ô#Ð#å�1‰XŒXð ð ˆØ�A‘˜‰{ˆØ�Q‘˜!‘ˆð %&¨¢E E•�A�q˜1‘u˜aÑ Ô Ð ¨qˆØ˜˜uÐ%ð 	ð 	ˆAØ�JŠJ�q˜!ÑÔÐÐð	à1¨QÐ1Ð1Ð1€A„GˆF�OØ€Hr)   c                 óX  ‡ — t          j        d|t           j        ¬¦  «        }|                     ¦   «         rd}t          j        |¦  «        ‚ˆ fd„t          d‰ ¦  «        D ¦   «         }t          ‰ ¦  «        D ]#}|D ]}|                     |||z   ‰ z  ¦  «         ŒŒ$d‰ › d�|j        d<   |S )	a-  Returns the Paley $\frac{(p-1)}{2}$ -regular graph on $p$ nodes.

    The returned graph is a graph on $\mathbb{Z}/p\mathbb{Z}$ with edges between $x$ and $y$
    if and only if $x-y$ is a nonzero square in $\mathbb{Z}/p\mathbb{Z}$.

    If $p \equiv 1  \pmod 4$, $-1$ is a square in
    $\mathbb{Z}/p\mathbb{Z}$ and therefore $x-y$ is a square if and
    only if $y-x$ is also a square, i.e the edges in the Paley graph are symmetric.

    If $p \equiv 3 \pmod 4$, $-1$ is not a square in $\mathbb{Z}/p\mathbb{Z}$
    and therefore either $x-y$ or $y-x$ is a square in $\mathbb{Z}/p\mathbb{Z}$ but not both.

    Note that a more general definition of Paley graphs extends this construction
    to graphs over $q=p^n$ vertices, by using the finite field $F_q$ instead of
    $\mathbb{Z}/p\mathbb{Z}$.
    This construction requires to compute squares in general finite fields and is
    not what is implemented here (i.e `paley_graph(25)` does not return the true
    Paley graph associated with $5^2$).

    Parameters
    ----------
    p : int, an odd prime number.

    create_using : NetworkX graph constructor, optional (default=nx.Graph)
       Graph type to create. If graph instance, then cleared before populated.

    Returns
    -------
    G : graph
        The constructed directed graph.

    Raises
    ------
    NetworkXError
        If the graph is a multigraph.

    References
    ----------
    Chapter 13 in B. Bollobas, Random Graphs. Second edition.
    Cambridge Studies in Advanced Mathematics, 73.
    Cambridge University Press, Cambridge (2001).
    r   r   z&`create_using` cannot be a multigraph.c                 ó8   •— h | ]}|d z  ‰z  dk    ¯|d z  ‰z  ’ŒS )r   r   © )Ú.0r$   r,   s     €r(   ú	<setcomp>zpaley_graph.<locals>.<setcomp>Ñ   s.   ø€ ÐEÐEÐE °a¸±d¸a±ZÀ1²_°_�1�a‘4˜1‘*°_°_°_r)   r   zpaley(r   r   )r   r   ÚDiGraphr   r   r   r   r   )r,   r!   r"   r#   Ú
square_setr$   Úx2s   `      r(   r   r   �   sÊ   ø€ õX 	Œ�q˜,µ´
Ð;Ñ;Ô;€AØ‡‚ÑÔð $Ø6ˆÝÔ˜sÑ#Ô#Ð#ð
 FÐEÐEÐE¥e¨A¨q¡k¤kÐEÑEÔE€Jå�1‰XŒXð (ð (ˆØð 	(ð 	(ˆBØ�JŠJ�q˜1˜r™6 Q™,Ñ'Ô'Ð'Ð'ð	(à#˜q�m�m�m€A„GˆF�OØ€Hr)   Úseedéd   ©r!   Ú	max_triesr8   c                ó´  ‡— ddl }| dk     rt          j        d¦  «        ‚|dk    st          j        d¦  «        ‚|dz  dk    st          j        d¦  «        ‚| dz
  |k    st          j        d|dz  › d	| › d
�¦  «        ‚t          j        | |¦  «        }| dk     r|S g }t	          ¦   «         Št          |dz  ¦  «        D �]}|}	t          ‰¦  «        |dz   | z  k    ræ|	dz  }	|                     | dz
  ¦  «                             ¦   «         }
|
 	                    | dz
  ¦  «         ˆfd„t          j
                             |
d¬¦  «        D ¦   «         }t          |¦  «        | k    r*| 	                    |
¦  «         ‰                     |¦  «         |	dk    rd}t          j        |¦  «        ‚t          ‰¦  «        |dz   | z  k    °æ�Œ|                     ‰¦  «         |S )a±  Utility for creating a random regular expander.

    Returns a random $d$-regular graph on $n$ nodes which is an expander
    graph with very good probability.

    Parameters
    ----------
    n : int
      The number of nodes.
    d : int
      The degree of each node.
    create_using : Graph Instance or Constructor
      Indicator of type of graph to return.
      If a Graph-type instance, then clear and use it.
      If a constructor, call it to create an empty graph.
      Use the Graph constructor by default.
    max_tries : int. (default: 100)
      The number of allowed loops when generating each independent cycle
    seed : (default: None)
      Seed used to set random number generation state. See :ref`Randomness<randomness>`.

    Notes
    -----
    The nodes are numbered from $0$ to $n - 1$.

    The graph is generated by taking $d / 2$ random independent cycles.

    Joel Friedman proved that in this model the resulting
    graph is an expander with probability
    $1 - O(n^{-\tau})$ where $\tau = \lceil (\sqrt{d - 1}) / 2 \rceil - 1$. [1]_

    Examples
    --------
    >>> G = nx.maybe_regular_expander_graph(n=200, d=6, seed=8020)

    Returns
    -------
    G : graph
        The constructed undirected graph.

    Raises
    ------
    NetworkXError
        If $d % 2 != 0$ as the degree must be even.
        If $n - 1$ is less than $ 2d $ as the graph is complete at most.
        If max_tries is reached

    See Also
    --------
    is_regular_expander
    random_regular_expander_graph

    References
    ----------
    .. [1] Joel Friedman,
       A Proof of Alon's Second Eigenvalue Conjecture and Related Problems, 2004
       https://arxiv.org/abs/cs/0405020

    r   Nr   zn must be a positive integerr   z$d must be greater than or equal to 2zd must be evenzNeed n-1>= d to have room for z independent cycles with z nodesc                 ó6   •— h | ]\  }}||f‰v¯||f‰v¯||f’ŒS r2   r2   )r3   r&   r'   Úedgess      €r(   r4   z/maybe_regular_expander_graph.<locals>.<setcomp><  sH   ø€ ð ð ð á�A�qØ�q�6 Ð&Ð&¨A¨q¨6¸Ð+>Ð+>ð �A�à+>Ð+>Ð+>r)   T)Úcyclicz3Too many iterations in maybe_regular_expander_graph)Únumpyr   r   r   Úsetr   ÚlenÚpermutationÚtolistÚappendÚutilsÚpairwiseÚupdateÚadd_edges_from)r    Údr!   r;   r8   Únpr"   ÚcyclesÚiÚ
iterationsÚcycleÚ	new_edgesr#   r>   s                @r(   r   r   Ú   s  ø€ ð~ ÐÐÐàˆ1‚u€uÝÔÐ=Ñ>Ô>Ð>à�ŠFˆFÝÔÐEÑFÔFÐFà�‰E�QŠJˆJÝÔÐ/Ñ0Ô0Ð0à�‰E�QŠJˆJÝÔØW¨Q°!©VÐWÐWÈaÐWÐWÐWñ
ô 
ð 	
õ 	Œ�q˜,Ñ'Ô'€Aàˆ1‚u€uØˆà€FÝ‰EŒE€Eõ �1˜‘6‰]Œ]ð ,ñ ,ˆØˆ
å�%‰jŒj˜Q ™U a™KÒ'Ð'Ø˜!‰OˆJð ×$Ò$ Q¨¡UÑ+Ô+×2Ò2Ñ4Ô4ˆEØ�LŠL˜˜Q™ÑÔÐðð ð ð åœH×-Ò-¨e¸DÐ-ÑAÔAðñ ô ˆIõ �9‰~Œ~ Ò"Ð"Ø—’˜eÑ$Ô$Ð$Ø—’˜YÑ'Ô'Ð'à˜QŠˆØK�ÝÔ& sÑ+Ô+Ð+õ) �%‰jŒj˜Q ™U a™KÒ'Ð'ùð, ×Ò�UÑÔÐà€Hr)   c                ól   — ddl }|                     dt          d¬¦  «         t          | ||||¬¦  «        S )z±
    .. deprecated:: 3.6
       `maybe_regular_expander` is a deprecated alias
       for `maybe_regular_expander_graph`.
       Use `maybe_regular_expander_graph` instead.
    r   NzQmaybe_regular_expander is deprecated, use `maybe_regular_expander_graph` instead.r   )ÚcategoryÚ
stacklevelr:   )ÚwarningsÚwarnÚDeprecationWarningr   )r    rJ   r!   r;   r8   rT   s         r(   r   r   P  sW   € ð €O€O€Oà‡M‚Mð	6å#Øð	 ñ ô ð õ (Ø	ˆ1˜<°9À4ðñ ô ð r)   ÚdirectedÚ
multigraphr"   Úweightr   )Úpreserve_edge_attrs©Úepsilonc                óÒ  — ddl }ddl}|dk     rt          j        d¦  «        ‚t          j        | ¦  «        sdS t          j                             | j        ¦  «        \  }}t          j        | t          ¬¦  «        }|j
        j                             |ddd¬¦  «        }t          |¦  «        }t          t          |¦  «        d|                     |d	z
  ¦  «        z  |z   k     ¦  «        S )
a%  Determines whether the graph G is a regular expander. [1]_

    An expander graph is a sparse graph with strong connectivity properties.

    More precisely, this helper checks whether the graph is a
    regular $(n, d, \lambda)$-expander with $\lambda$ close to
    the Alon-Boppana bound and given by
    $\lambda = 2 \sqrt{d - 1} + \epsilon$. [2]_

    In the case where $\epsilon = 0$ then if the graph successfully passes the test
    it is a Ramanujan graph. [3]_

    A Ramanujan graph has spectral gap almost as large as possible, which makes them
    excellent expanders.

    Parameters
    ----------
    G : NetworkX graph
    epsilon : int, float, default=0

    Returns
    -------
    bool
        Whether the given graph is a regular $(n, d, \lambda)$-expander
        where $\lambda = 2 \sqrt{d - 1} + \epsilon$.

    Examples
    --------
    >>> G = nx.random_regular_expander_graph(20, 4)
    >>> nx.is_regular_expander(G)
    True

    See Also
    --------
    maybe_regular_expander_graph
    random_regular_expander_graph

    References
    ----------
    .. [1] Expander graph, https://en.wikipedia.org/wiki/Expander_graph
    .. [2] Alon-Boppana bound, https://en.wikipedia.org/wiki/Alon%E2%80%93Boppana_bound
    .. [3] Ramanujan graphs, https://en.wikipedia.org/wiki/Ramanujan_graph

    r   Nzepsilon must be non negativeF)ÚdtypeÚLMr   )ÚwhichÚkÚreturn_eigenvectorsr   )r@   Úscipyr   r   Ú
is_regularrF   Úarbitrary_elementÚdegreeÚadjacency_matrixÚfloatÚsparseÚlinalgÚeigshÚminÚboolÚabsÚsqrt)	r"   r\   rK   ÚspÚ_rJ   ÚAÚlamsÚlambda2s	            r(   r   r   d  sà   € ðb ÐÐÐØÐÐÐà�‚{€{ÝÔÐ=Ñ>Ô>Ð>åŒ=˜ÑÔð ØˆuåŒ8×%Ò% a¤hÑ/Ô/�D€A€qå
Ô˜A¥UÐ+Ñ+Ô+€AØŒ9Ô×!Ò! !¨4°1È%Ð!ÑPÔP€Dõ �$‰iŒi€Gõ •�G‘”˜q 2§7¢7¨1¨q©5¡>¤>Ñ1°GÑ;Ò;Ñ<Ô<Ð<r)   )r\   r!   r;   r8   c                óÜ   — t          | ||||¬¦  «        }|}t          ||¬¦  «        sD|dz  }t          | ||||¬¦  «        }|dk    rt          j        d¦  «        ‚t          ||¬¦  «        ¯D|S )a*  Returns a random regular expander graph on $n$ nodes with degree $d$.

    An expander graph is a sparse graph with strong connectivity properties. [1]_

    More precisely the returned graph is a $(n, d, \lambda)$-expander with
    $\lambda = 2 \sqrt{d - 1} + \epsilon$, close to the Alon-Boppana bound. [2]_

    In the case where $\epsilon = 0$ it returns a Ramanujan graph.
    A Ramanujan graph has spectral gap almost as large as possible,
    which makes them excellent expanders. [3]_

    Parameters
    ----------
    n : int
      The number of nodes.
    d : int
      The degree of each node.
    epsilon : int, float, default=0
    max_tries : int, (default: 100)
      The number of allowed loops,
      also used in the `maybe_regular_expander_graph` utility
    seed : (default: None)
      Seed used to set random number generation state. See :ref`Randomness<randomness>`.

    Raises
    ------
    NetworkXError
        If max_tries is reached

    Examples
    --------
    >>> G = nx.random_regular_expander_graph(20, 4)
    >>> nx.is_regular_expander(G)
    True

    Notes
    -----
    This loops over `maybe_regular_expander_graph` and can be slow when
    $n$ is too big or $\epsilon$ too small.

    See Also
    --------
    maybe_regular_expander_graph
    is_regular_expander

    References
    ----------
    .. [1] Expander graph, https://en.wikipedia.org/wiki/Expander_graph
    .. [2] Alon-Boppana bound, https://en.wikipedia.org/wiki/Alon%E2%80%93Boppana_bound
    .. [3] Ramanujan graphs, https://en.wikipedia.org/wiki/Ramanujan_graph

    r:   r[   r   )r    rJ   r!   r;   r8   r   z4Too many iterations in random_regular_expander_graph)r   r   r   r   )r    rJ   r\   r!   r;   r8   r"   rN   s           r(   r	   r	   ª  s©   € õr 	%Ø	ˆ1˜<°9À4ð	ñ 	ô 	€Að €Jå! !¨WÐ5Ñ5Ô5ð 	Ø�a‰ˆ
Ý(Ø�1 <¸9È4ð
ñ 
ô 
ˆð ˜Š?ˆ?ÝÔ"ØFñô ð õ " !¨WÐ5Ñ5Ô5ð 	ð €Hr)   )N)Ú__doc__r   Únetworkxr   Ú__all__Ú_dispatchabler   r   r   rF   Ú
decoratorsÚnp_random_stater   r   Únot_implemented_forr   r	   r2   r)   r(   ú<module>r}      sE  ðØ 9Ð 9à Ð Ð Ð à Ð Ð Ð ðð ð €ðV €Ô˜¨TÐ2Ñ2Ô2ð'ð 'ð 'ñ 3Ô2ð'ðT €Ô˜¨TÐ2Ñ2Ô2ð<ð <ð <ñ 3Ô2ð<ð~ €Ô˜¨TÐ2Ñ2Ô2ð9ð 9ð 9ñ 3Ô2ð9ðx „Ô×$Ò$ VÑ,Ô,Ø€Ô˜¨TÐ2Ñ2Ô2Ø7;ÀsÐQUð qð qð qð qñ 3Ô2ñ -Ô,ðqðh 26ÀÈ4ð ð ð ð ð ð( „×Ò˜jÑ)Ô)Ø„×Ò˜lÑ+Ô+Ø€Ô s¨X°q¨MÐ&:Ð;Ñ;Ô;Ø&'ð @=ð @=ð @=ð @=ñ <Ô;ñ ,Ô+ñ *Ô)ð@=ðF „Ô×$Ò$ VÑ,Ô,Ø€Ô˜¨TÐ2Ñ2Ô2à T°S¸tðGð Gð Gð Gñ 3Ô2ñ -Ô,ðGð Gð Gr)   