Skip to content

Commit

Permalink
Merge pull request #35 from Mathics3/edges-as-operators
Browse files Browse the repository at this point in the history
Redo DirectedEdge and UndirectedEdge as operators
  • Loading branch information
rocky authored Nov 25, 2024
2 parents 5a07c1b + f482ed8 commit 57522db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
python -m pip install --upgrade pip
python -m pip install pytest
# Can comment out when next Mathics core and Mathics-scanner are released
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full]
python -m pip install -e .
# (cd src/mathics3 && bash ./admin-tools/make-op-tables.sh)
(cd src/mathics3 && bash ./admin-tools/make-op-tables.sh)
- name: install pymathics graph
run: |
make develop
Expand Down
30 changes: 17 additions & 13 deletions pymathics/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from inspect import isgenerator
from typing import Callable, Optional, Union

from mathics.builtin.no_meaning import (
DirectedEdge as GenericDirectedEdge,
UndirectedEdge as GenericUndirectedEdge,
)
from mathics.core.attributes import A_PROTECTED, A_READ_PROTECTED
from mathics.core.builtin import AtomBuiltin, Builtin
from mathics.core.atoms import Atom, Integer, Integer0, Integer1, Integer2, String
from mathics.core.convert.expression import ListExpression, from_python, to_mathics_list
Expand Down Expand Up @@ -893,8 +898,8 @@ def neighbors(v):
return self._retrieve(graph, what, neighbors, expression, evaluation)


class DirectedEdge(Builtin):
"""
class DirectedEdge(GenericDirectedEdge):
r"""
Edge of a <url>
:Directed graph:
https://en.wikipedia.org/wiki/Directed_graph</url> (<url>
Expand All @@ -908,9 +913,15 @@ class DirectedEdge(Builtin):
<dt>'DirectedEdge[$u$, $v$]'
<dd>create a directed edge from $u$ to $v$.
</dl>
>> DirectedEdge[x, y, z]
= x → y → z
>> a \[DirectedEdge] b
= a → b
"""

summary_text = "make a directed graph edge"
attributes = A_PROTECTED | A_READ_PROTECTED


class EdgeConnectivity(_NetworkXBuiltin):
Expand Down Expand Up @@ -1494,7 +1505,7 @@ def _items(self, graph):
return graph.vertices


class UndirectedEdge(Builtin):
class UndirectedEdge(GenericUndirectedEdge):
"""
<url>
:WMA link:
Expand All @@ -1506,17 +1517,10 @@ class UndirectedEdge(Builtin):
</dl>
>> a <-> b
= UndirectedEdge[a, b]
>> (a <-> b) <-> c
= UndirectedEdge[UndirectedEdge[a, b], c]
>> a <-> (b <-> c)
= UndirectedEdge[a, UndirectedEdge[b, c]]
= ...
"""

summary_text = "undirected graph edge"
pass
attributes = A_PROTECTED | A_READ_PROTECTED


# class EdgeAdd(_NetworkXBuiltin):
Expand Down
6 changes: 4 additions & 2 deletions pymathics/graph/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class RandomTree(_NetworkXBuiltin):
"""
<url>:NetworkX:
https://networkx.org/documentation/networkx-2.8.8/reference\
/generated/networkx.generators.trees.random_tree.html</url>, <url>
/generated/networkx.generators.trees.random_labeled_tree.html</url>, <url>
:WMA:
https://reference.wolfram.com/language/ref/RandomTree.html</url>
Expand Down Expand Up @@ -610,7 +610,9 @@ def eval(
return

args = (py_n,)
g = graph_helper(nx.random_tree, options, False, "tree", evaluation, 0, *args)
g = graph_helper(
nx.random_labeled_tree, options, False, "tree", evaluation, 0, *args
)
if not g:
return None
g.G.n = n
Expand Down

0 comments on commit 57522db

Please sign in to comment.