Skip to content

Commit f0aeee6

Browse files
committed
Some trivial fixes.
1 parent 26ccb8e commit f0aeee6

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

doc/source/10_trees_and_directed_acyclic_graphs.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ huge range of interconnected networks. :numref:`graph` illustrates a simple exam
5757

5858
.. proof:definition:: Directed graph
5959
60-
A *directed graph* is a graph in which the edges have a direction associated
61-
with them. In other words each edge point *from* one node (the *source*)
60+
A *directed graph* is a graph in which the pair of nodes forming each edge
61+
is ordered. In other words each edge points *from* one node (the *source*)
6262
and *to* another (the *target*).
6363

6464
:numref:`digraph` shows a directed graph with similar topology to the previous example.
@@ -1000,7 +1000,7 @@ with a keyword argument in a manner analogous to `tree_map` in
10001000
:numref:`tree_evaluate`.
10011001

10021002
The differentiation of operators is achieved by an applying the chain rule. For
1003-
an binary operator :math:`\odot`, with operands :math:`o_0` and :math:`o_1`, the
1003+
a binary operator :math:`\odot`, with operands :math:`o_0` and :math:`o_1`, the
10041004
chain rule is given by:
10051005

10061006
.. math::
@@ -1085,7 +1085,9 @@ Glossary
10851085
Exercises
10861086
---------
10871087

1088-
Obtain the :doc:`skeleton code for these exercises from GitHub classroom <not_released>`.
1088+
Obtain the :doc:`skeleton code for these exercises from GitHub classroom
1089+
<not_released>`. You should also update your clone of the course repository to
1090+
ensure you have the latest version of the :mod:`example_code` package.
10891091

10901092
.. _ex_expr:
10911093

@@ -1114,6 +1116,11 @@ Obtain the :doc:`skeleton code for these exercises from GitHub classroom <not_re
11141116
expression provided with respect to a symbol whose name is passed as the
11151117
string :term:`keyword argument <argument>` `var`.
11161118

1119+
As a simplification, the tests will assume that `var` does not appear in an
1120+
exponent. As an extension, you could consider that case too, but you'd
1121+
probably need to extend your symbolic language to include the natural
1122+
logarithm as a symbolic function.
1123+
11171124
.. rubric:: Footnotes
11181125

11191126
.. [#tree_def] This definition of a tree matches computer science usage and is

doc/webgit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 17c8388afd23a150fa49b3f125b7788bd008a1ad
1+
Subproject commit 581fce18c880a3fb8eda49f8187363e32ace268a

example_code/graphs.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1+
"""A simple tree implementation with basic pre- and post-visitors."""
2+
3+
14
class TreeNode:
2-
'''A basic tree implementation.
5+
"""A basic tree implementation.
6+
7+
Observe that a tree is simply a collection of connected TreeNodes.
8+
9+
Parameters
10+
----------
11+
value:
12+
An arbitrary value associated with this node.
13+
children:
14+
The TreeNodes which are the children of this node.
15+
"""
316

4-
Observe that a tree is simply a collection of connected TreeNodes.'''
517
def __init__(self, value, *children):
6-
'''
7-
Parameters
8-
----------
9-
value:
10-
An arbitrary value associated with this node.
11-
children:
12-
The TreeNodes which are the children of this node.
13-
'''
1418
self.value = value
1519
self.children = tuple(children)
1620

1721
def __repr__(self):
18-
return f"{self.__class__.__name__}{(self.value,) + self.children}"
22+
"""Return the canonical string representation."""
23+
return f"{type(self).__name__}{(self.value,) + self.children}"
1924

2025
def __str__(self):
26+
"""Serialise the tree recursively as parent -> (children)."""
2127
childstring = ", ".join(map(str, self.children))
2228
return f"{self.value!s} -> ({childstring})"
2329

2430

2531
def previsitor(tree, fn, fn_parent=None):
26-
'''Traverse tree in preorder applying a function to every node.
32+
"""Traverse tree in preorder applying a function to every node.
2733
2834
Parameters
2935
----------
@@ -33,16 +39,15 @@ def previsitor(tree, fn, fn_parent=None):
3339
A function to be applied at each node. The function should take the
3440
node to be visited as its first argument, and the result of visiting
3541
its parent as the second.
36-
'''
37-
42+
"""
3843
fn_out = fn(tree, fn_parent)
3944

4045
for child in tree.children:
4146
previsitor(child, fn, fn_out)
4247

4348

4449
def postvisitor(expr, fn, **kwargs):
45-
'''Traverse an Expression in postorder applying a function to every node.
50+
"""Traverse an Expression in postorder applying a function to every node.
4651
4752
Parameters
4853
----------
@@ -56,8 +61,7 @@ def postvisitor(expr, fn, **kwargs):
5661
arguments.
5762
**kwargs:
5863
Any additional keyword arguments to be passed to fn.
59-
'''
60-
64+
"""
6165
return fn(expr,
6266
*(postvisitor(c, fn, **kwargs) for c in expr.operands),
6367
**kwargs)

0 commit comments

Comments
 (0)