example_code package¶
Submodules¶
example_code.addable module¶
example_code.euclid module¶
example_code.expression_tools module¶
- example_code.expression_tools.evaluate(expr, *o, **kwargs)[source]¶
- example_code.expression_tools.evaluate(expr: Number, *o, **kwargs)
- example_code.expression_tools.evaluate(expr: Symbol, *o, symbol_map, **kwargs)
- example_code.expression_tools.evaluate(expr: Add, *o, **kwargs)
- example_code.expression_tools.evaluate(expr: Sub, *o, **kwargs)
- example_code.expression_tools.evaluate(expr: Mul, *o, **kwargs)
- example_code.expression_tools.evaluate(expr: Div, *o, **kwargs)
- example_code.expression_tools.evaluate(expr: Pow, *o, **kwargs)
Evaluate an expression node.
- Parameters:
expr (Expression) – The expression node to be evaluated.
*o (numbers.Number) – The results of evaluating the operands of expr.
**kwargs – Any keyword arguments required to evaluate specific types of expression.
symbol_map (dict) –
A dictionary mapping Symbol names to numerical values, for example:
{‘x’: 1}
- example_code.expression_tools.postvisitor(expr, fn, **kwargs)[source]¶
Visit an Expression in postorder applying a function to every node.
- Parameters:
expr (Expression) – The expression to be visited.
fn (
function(node, *o, **kwargs)
) – A function to be applied at each node. The function should take the node to be visited as its first argument, and the results of visiting its operands as any further positional arguments. Any additional information that the visitor requires can be passed in as keyword arguments.**kwargs – Any additional keyword arguments to be passed to fn.
example_code.graphs module¶
A simple tree implementation with basic pre- and post-visitors.
- class example_code.graphs.TreeNode(value, *children)[source]¶
Bases:
object
A basic tree implementation.
A tree is simply a collection of connected TreeNodes.
- Parameters:
value – An arbitrary value associated with this node.
children – The TreeNodes which are the children of this node.
- example_code.graphs.postvisitor(tree, fn)[source]¶
Traverse tree in postorder applying a function to every node.
- example_code.graphs.previsitor(tree, fn, fn_parent=None)[source]¶
Traverse tree in preorder applying a function to every node.
- Parameters:
tree (TreeNode) – The tree to be visited.
fn (function(node, fn_parent)) – A function to be applied at each node. The function should take the node to be visited as its first argument, and the result of visiting its parent as the second.
example_code.groups module¶
A module implementing the basic functionality of mathematical groups.
This version of the module uses inheritance.
- class example_code.groups.CyclicGroup(n)[source]¶
Bases:
Group
A cyclic group represented by integer addition modulo n.
- operation(a, b)[source]¶
Perform the group operation on two values.
The group operation is addition modulo n.
- symbol = 'C'¶
- class example_code.groups.Element(group, value)[source]¶
Bases:
object
An element of the specified group.
- Parameters:
group (Group) – The group of which this is an element.
value – The value of this entity. Valid values depend on the group.
- class example_code.groups.GeneralLinearGroup(n)[source]¶
Bases:
Group
The general linear group represented by n x n matrices.
- operation(a, b)[source]¶
Perform the group operation on two values.
The group operation is matrix multiplication.
- symbol = 'G'¶
- class example_code.groups.Group(n)[source]¶
Bases:
object
A base class containing methods common to many groups.
Each subclass represents a family of parametrised groups.
- Parameters:
n (int) – The primary group parameter, such as order or degree. The precise meaning of n changes from subclass to subclass.
example_code.groups_abc module¶
A module implementing the basic functionality of mathematical groups.
This version of the module uses inheritance and defines the base class as an
abc.ABC
.
- class example_code.groups_abc.CyclicGroup(n)[source]¶
Bases:
Group
A cyclic group represented by integer addition modulo n.
- operation(a, b)[source]¶
Perform the group operation on two values.
The group operation is addition modulo n.
- symbol = 'C'¶
- class example_code.groups_abc.Element(group, value)[source]¶
Bases:
object
An element of the specified group.
- Parameters:
group (Group) – The group of which this is an element.
value – The value of this entity. Valid values depend on the group.
- class example_code.groups_abc.GeneralLinearGroup(n)[source]¶
Bases:
Group
The general linear group represented by n x n matrices.
- operation(a, b)[source]¶
Perform the group operation on two values.
The group operation is matrix multiplication.
- symbol = 'G'¶
- class example_code.groups_abc.Group(n)[source]¶
Bases:
ABC
A base class containing methods common to many groups.
Each subclass represents a family of parametrised groups.
- Parameters:
n (int) – The primary group parameter, such as order or degree. The precise meaning of n changes from subclass to subclass.
- abstract property symbol¶
Represent the group name as a character.
example_code.groups_basic module¶
A module implementing the basic functionality of mathematical groups.
- class example_code.groups_basic.CyclicGroup(order)[source]¶
Bases:
object
A cyclic group represented by addition modulo group order.
example_code.hello module¶
example_code.linked_list module¶
example_code.polynomial module¶
example_code.shapes module¶
A module containing some very simple shape classes to illustrate the use of
super()
.
example_code.simple_classes module¶
A very elementary set of classes and objects for one of the week 3 quiz questions.
- example_code.simple_classes.g()¶