Skip to content

Commit d153e2c

Browse files
committed
Sort out Tree module ...
This might be temporay though based on WMA docs
1 parent 286c9ff commit d153e2c

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

pymathics/graph/eval/tree.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from mathics.core.symbols import SymbolConstant, SymbolFalse, SymbolTrue
2+
3+
import networkx as nx
4+
from pymathics.graph.base import Graph
5+
6+
7+
def eval_TreeGraphQ(g: Graph) -> SymbolConstant:
8+
"""
9+
Returns SymbolTrue if g is a (networkx) tree and SymbolFalse
10+
otherwise.
11+
"""
12+
if not isinstance(g, Graph):
13+
return SymbolFalse
14+
return SymbolTrue if nx.is_tree(g.G) else SymbolFalse

pymathics/graph/tree.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
"""
2+
Trees
3+
"""
14
import networkx as nx
25
from mathics.core.atoms import Atom
36
from mathics.core.evaluation import Evaluation
4-
from mathics.core.symbols import SymbolConstant, SymbolFalse, SymbolTrue
7+
from mathics.core.symbols import SymbolConstant
58

69
from pymathics.graph.base import (
710
DEFAULT_GRAPH_OPTIONS,
8-
Graph,
911
_graph_from_list,
1012
_NetworkXBuiltin,
1113
)
14+
from pymathics.graph.eval.tree import eval_TreeGraphQ
1215

1316
DEFAULT_TREE_OPTIONS = {
1417
**DEFAULT_GRAPH_OPTIONS,
@@ -18,16 +21,6 @@
1821
from mathics.builtin.base import AtomBuiltin
1922

2023

21-
def eval_TreeGraphQ(g: Graph) -> SymbolConstant:
22-
"""
23-
Returns SymbolTrue if g is a (networkx) tree and SymbolFalse
24-
otherwise.
25-
"""
26-
if not isinstance(g, Graph):
27-
return SymbolFalse
28-
return SymbolTrue if nx.is_tree(g.G) else SymbolFalse
29-
30-
3124
# FIXME: do we need to have TreeGraphAtom and TreeGraph?
3225
# Can't these be combined into one?
3326
class TreeGraphAtom(AtomBuiltin):

0 commit comments

Comments
 (0)