66
77from pymathics .graph .tree import DEFAULT_TREE_OPTIONS
88
9- from mathics .core .expression import Integer , String
9+ from mathics .core .expression import Expression , Integer , String
1010from typing import Callable , Optional
1111
1212# TODO: Can this code can be DRY'd more?
@@ -215,6 +215,21 @@ def apply_multipartite(self, n, evaluation, options):
215215 )
216216
217217
218+ class CycleGraph (_NetworkXBuiltin ):
219+ """<dl>
220+ <dt>'CycleGraph[$n$]'
221+ <dd>Returns the cycle graph with $n$ vertices $C_n$.
222+ </dl>
223+
224+ >> CycleGraph[3, PlotLabel -> "C_i"]
225+ = -Graph-
226+ """
227+
228+ def apply (self , n , expression , evaluation , options ):
229+ "%(name)s[n_Integer, OptionsPattern[%(name)s]]"
230+ return hkn_harary_apply (self , Integer (2 ), n , expression , evaluation , options )
231+
232+
218233class FullRAryTree (_NetworkXBuiltin ):
219234 """<dl>
220235 <dt>'FullRAryTree[$r$, $n$]'
@@ -292,11 +307,33 @@ def apply(self, n, expression, evaluation, options):
292307 g .n = n
293308 return g
294309
310+ def hkn_harary_apply (self , k , n , expression , evaluation , options ):
311+ py_k = k .get_int_value ()
312+
313+ if py_k < 0 :
314+ evaluation .message (self .get_name (), "ilsmp" , expression )
315+ return
316+
317+ py_n = n .get_int_value ()
318+ if py_n < 0 :
319+ evaluation .message (self .get_name (), "ilsmp2" , expression )
320+ return
321+
322+ from pymathics .graph .harary import hkn_harary_graph
323+
324+ args = (py_k , py_n )
325+ g = graph_helper (hkn_harary_graph , options , False , "circular" , None , * args )
326+ if not g :
327+ return None
328+ g .k = py_k
329+ g .n = py_n
330+ return g
331+
295332
296333class HknHararyGraph (_NetworkXBuiltin ):
297334 """<dl>
298- <dt>'HmnHararyGraph[$k$, $n$]'
299- <dd>Returns the Harary graph with given node connectivity and node number.
335+ <dt>'HmnHararyGraph[$k$, $n$]'
336+ <dd>Returns the Harary graph with given node connectivity and node number.
300337
301338 This second generator gives the Harary graph that minimizes the
302339 number of edges in the graph with given node connectivity and
@@ -317,26 +354,7 @@ class HknHararyGraph(_NetworkXBuiltin):
317354
318355 def apply (self , k , n , expression , evaluation , options ):
319356 "%(name)s[k_Integer, n_Integer, OptionsPattern[%(name)s]]"
320- py_k = k .get_int_value ()
321-
322- if py_k < 0 :
323- evaluation .message (self .get_name (), "ilsmp" , expression )
324- return
325-
326- py_n = n .get_int_value ()
327- if py_n < 0 :
328- evaluation .message (self .get_name (), "ilsmp2" , expression )
329- return
330-
331- from pymathics .graph .harary import hkn_harary_graph
332-
333- args = (py_k , py_n )
334- g = graph_helper (hkn_harary_graph , options , False , "circular" , None , * args )
335- if not g :
336- return None
337- g .k = py_k
338- g .n = py_n
339- return g
357+ return hkn_harary_apply (self , k , n , expression , evaluation , options )
340358
341359
342360class HmnHararyGraph (_NetworkXBuiltin ):
0 commit comments