+
    �°³jB<  ã            
       óÆ  € R t ^ RIt^ RIt. ROt]P
                  ! RRR7      RR l4       t]P
                  ! RRR7      RR l4       t]P
                  ! RRR7      RR l4       t]P                  P                  P                  R4      ]P
                  ! RRR7      RRR	^dRR/R
 l4       4       tRRR	^dRR/R lt]P                  P                  R4      ]P                  P                  R4      ]P
                  ! RR^//R7      R^ /R l4       4       4       t]P                  P                  P                  R4      ]P
                  ! RRR7      R^ RRR	^dRR/R l4       4       tR# )z3Provides explicit constructions of expander graphs.NT)ÚgraphsÚreturns_graphc                ól  € \         P                  ! ^ V\         P                  R7      pVP                  4       '       g   VP	                  4       '       g   Rp\         P
                  ! V4      h\        P                  ! \        V 4      ^R7       F�  w  rEV^V,          ,           V ,          V3V^V,          ^,           ,           V ,          V3WE^V,          ,           V ,          3WE^V,          ^,           ,           V ,          33 F  w  rgVP                  WE3Wg34       K  	  K’  	  RV  R2VP                  R&   V# )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.

©Údefaultú0`create_using` must be an undirected multigraph.)Úrepeatz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   &&      Ú^/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/generators/expanders.pyÚmargulis_gabber_galil_graphr   2   sù   € ô4 	�Š�q˜,´·±Ô>€AØ‡}�}‡‚˜aŸo™o×/Ò/Ø@ˆÜ×Ò˜sÓ#Ð#ä×!Ò!¤%¨£(°1×5‰ˆà�!�a•%�i˜1�_˜aÐ Ø�1�q•5˜1•9�o Õ" AÐ&Ø�Q˜•U•˜a•Ð Ø�a˜!•e˜a•i• AÕ%Ð&ó	
‰DˆAð �J‰J˜�v ˜vÖ&ó
ñ 6ð 5°Q°C°qÐ9€A‡G�GˆF�OØ€Hó    c                óÖ  € \         P                  ! ^ V\         P                  R7      pVP                  4       '       g   VP	                  4       '       g   Rp\         P
                  ! V4      h\        V 4       F[  pV^,
          V ,          pV^,           V ,          pV^ 8”  d   \        W@^,
          V 4      M^ pWVV3 F  pVP                  WH4       K  	  K]  	  RV  R2VP                  R&   V# )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]_ when viewed as a simple graph. The default return
type is a MultiGraph, which has 6-regular nodes due to the symmetric nature
of the edge additions. Use ``nx.Graph(nx.chordal_cycle_graph(p))`` to obtain
the 3-regular simple graph.

`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   zchordal_cycle_graph(r	   r
   )
r   r   r   r   r   r   r   Úpowr   r   )	Úpr   r   r   r   ÚleftÚrightÚchordr   s	   &&       r   Úchordal_cycle_graphr'   ]   sÂ   € ôT 	�Š�q˜,´·±Ô>€AØ‡}�}‡‚˜aŸo™o×/Ò/Ø@ˆÜ×Ò˜sÓ#Ð#ä�1ŽXˆØ�A•˜�{ˆØ�Q•˜!•ˆð %&¨¤E”�A˜1•u˜aÔ ¨qˆØ˜uÓ%ˆAØ�J‰J�qÖó &ñ ð  -¨Q¨C¨qÐ1€A‡G�GˆF�OØ€Hr    c                óÒ  € \         P                  ! ^ V\         P                  R7      pVP                  4       '       d   Rp\         P                  ! V4      h\        ^V 4       Uu0 uF)  qD^,          V ,          ^ 8w  g   K  V^,          V ,          kK+  	  pp\        V 4       F+  pV F"  pVP                  WDV,           V ,          4       K$  	  K-  	  RV  R2VP                  R&   V# u upi )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   z&`create_using` cannot be a multigraph.zpaley(r	   r
   )r   r   ÚDiGraphr   r   r   r   r   )r#   r   r   r   r   Ú
square_setÚx2s   &&     r   Úpaley_graphr,       sÀ   € ôX 	�Š�q˜,´·
±
Ô;€AØ‡�×ÒØ6ˆÜ×Ò˜sÓ#Ð#ô
 ',¨A¨q¤kÓE¡k ¸µd¸aµZÀ1±_”*�1�a•4˜1—*�*¡k€JÐEä�1ŽXˆÛˆBØ�J‰J�q˜r�6 Q�,Ö'ó ñ ð ˜q˜c �m€A‡G�GˆF�OØ€Hùò Fs   Á$C$Á?C$Úseedr   Ú	max_triesc               óì  € ^ RI pV ^8  d   \        P                  ! R4      hV^8¼  g   \        P                  ! R4      hV^,          ^ 8X  g   \        P                  ! R4      hV ^,
          V8¼  g%   \        P                  ! RV^,           RV  R24      h\        P                  ! W4      pV ^8  d   V# . p\	        4       p\        V^,          4       EF  p	Tp
\        V4      V	^,           V ,          8w  g   K&  V
^,          p
VP                  V ^,
          4      P                  4       pVP                  V ^,
          4       \        P                  P                  VRR	7       UUu0 uF  w  rÍWÍ3V9  g   K  WÜ3V9  g   K  WÍ3kK  	  ppp\        V4      V 8X  d#   VP                  V4       VP                  V4       V
^ 8X  g   Kë  R
p\        P                  ! V4      h	  VP                  V4       V# u uppi )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

Nzn must be a positive integerz$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 nodesT)Ú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.   r-   Únpr   ÚcyclesÚedgesÚiÚ
iterationsÚcycler   r   Ú	new_edgesr   s   &&$$$           r   Úmaybe_regular_expander_graphrC   Ý   sÌ  € ó~ àˆ1„uÜ×ÒÐ=Ó>Ð>à�ŒFÜ×ÒÐEÓFÐFà��E�QŒJÜ×ÒÐ/Ó0Ð0à��E�QŒJÜ×ÒØ,¨Q°!­V¨HÐ4MÈaÈSÐPVÐWó
ð 	
ô 	�Š�qÓ'€Aàˆ1„uØˆà€FÜ‹E€Eô �1˜•6�]ˆØˆ
ä�%‹j˜Q �U a�KÖ'Ø˜!�OˆJð ×$Ñ$ Q¨¥UÓ+×2Ñ2Ó4ˆEØ�L‰L˜˜Q�Ôô ŸH™H×-Ñ-¨e¸DÐ-ÔAôáA‘D�AØ�6 Ñ&ô à,-¨6¸Ñ+>ô �“ÙAð ñ ô �9‹~ Ô"Ø—‘˜eÔ$Ø—‘˜YÔ'à˜QŽØK�Ü×&Ò& sÓ+Ð+ñ/ ð2 ×Ñ�UÔà€Hùó#s   Å#G0Å4G0Å>G0c               óV   € ^ RI pVP                  R\        ^R7       \        WW#VR7      # )z�
.. deprecated:: 3.6
   `maybe_regular_expander` is a deprecated alias
   for `maybe_regular_expander_graph`.
   Use `maybe_regular_expander_graph` instead.
NzQmaybe_regular_expander is deprecated, use `maybe_regular_expander_graph` instead.)ÚcategoryÚ
stacklevel©r   r.   r-   )ÚwarningsÚwarnÚDeprecationWarningrC   )r   r;   r   r.   r-   rH   s   &&$$$ r   Úmaybe_regular_expanderrK   S  s9   € ó à‡M�Mð	6ä#Øð	 ô ô (Ø	˜<À4ôð r    ÚdirectedÚ
multigraphr   Úweight)Úpreserve_edge_attrsÚepsilonc               óô  € ^ RI p^ RIpV^ 8  d   \        P                  ! R4      h\        P                  ! V 4      '       g   R# \        P
                  P                  V P                  4      w  rE\        P                  ! V \        R7      pVP                  P                  P                  VR^RR7      p\        V4      p\        \        V4      ^VP!                  V^,
          4      ,          V,           8  4      # )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

Nzepsilon must be non negativeF)ÚdtypeÚLM)ÚwhichÚkÚreturn_eigenvectors)r1   Úscipyr   r   Ú
is_regularr7   Úarbitrary_elementÚdegreeÚadjacency_matrixÚfloatÚsparseÚlinalgÚeigshÚminÚboolÚabsÚsqrt)	r   rP   r<   ÚspÚ_r;   ÚAÚlamsÚlambda2s	   &$       r   Úis_regular_expanderri   g  s¼   € ób Ûà�„{Ü×ÒÐ=Ó>Ð>ä�=Š=˜×ÒÙä�8‰8×%Ñ% a§h¡hÓ/�D€Aä
×Ò˜A¤UÔ+€AØ�9‰9×Ñ×!Ñ! !¨4°1È%Ð!ÓP€Dô �$‹i€Gô ”�G“˜q 2§7¡7¨1¨q­5£>Õ1°GÕ;Ñ;Ó<Ð<r    c               ó¶   € \        WW4VR7      pTp\        WbR7      '       g7   V^,          p\        WW4VR7      pV^ 8X  g   K2  \        P                  ! R4      hV# )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

rG   )rP   )r   r;   r   r.   r-   z4Too many iterations in random_regular_expander_graph)rC   ri   r   r   )r   r;   rP   r   r.   r-   r   r@   s   &&$$$$  r   Úrandom_regular_expander_graphrk   ­  sh   € ôr 	%Ø	˜<À4ô	€Að €Jä! !×5Ó5Ø�a�ˆ
Ü(Ø <È4ô
ˆð ˜Ž?Ü×"Ò"ØFóð ð €Hr    )r   r'   r,   rK   rC   ri   rk   )N)Ú__doc__r   Únetworkxr   Ú__all__Ú_dispatchabler   r'   r,   r7   Ú
decoratorsÚnp_random_staterC   rK   Únot_implemented_forri   rk   © r    r   Ú<module>rt      sµ  ðÙ 9ã ã ò€ðV ×Ò˜¨TÔ2ó'ó 3ð'ðT ×Ò˜¨TÔ2ó?ó 3ð?ðD ×Ò˜¨TÔ2ó9ó 3ð9ðx ‡�×Ñ×$Ñ$ VÓ,Ø×Ò˜¨TÔ2ðq°tð qÀsð qÐQUó qó 3ó -ðqðh°ð Àð È4ô ð( ‡�×Ñ˜jÓ)Ø‡�×Ñ˜lÓ+Ø×Ò s¨X°q¨MÐ&:Ô;ð@= aó @=ó <ó ,ó *ð@=ðF ‡�×Ñ×$Ñ$ VÓ,Ø×Ò˜¨TÔ2ðGØðGØ%)ðGØ58ðGØ?CóGó 3ó -òGr    