Skip to content

Commit 7d03faa

Browse files
committed
Website build
1 parent 8c1caae commit 7d03faa

File tree

3 files changed

+175
-6
lines changed

3 files changed

+175
-6
lines changed

11_further_object-oriented_features.html

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,12 +721,102 @@ <h3><span class="section-number">11.5.2. </span>Support while revising<a class="
721721
</div>
722722
<div class="section" id="practice-questions">
723723
<h3><span class="section-number">11.5.3. </span>Practice questions<a class="headerlink" href="#practice-questions" title="Permalink to this headline"></a></h3>
724-
<p>Some specifically-designed practice questions will be released at about the end
725-
of term. In addition to this, there are a lot of very good exercises in
724+
<p>Some specifically-designed practice questions are presented below. In addition to this, there are a lot of very good exercises in
726725
chapters 7 and 9 of <a class="reference external" href="https://link.springer.com/book/10.1007%2F978-3-662-49887-3">Hans Petter Langtangen, A Primer on Scientific Programming
727726
with Python</a>.
728727
You can access that book by logging in with your Imperial credentials.</p>
729-
<p class="rubric">Footnotes</p>
728+
<p>The first two questions are in exam format.</p>
729+
<div class="proof proof-type-exercise" id="id9">
730+
731+
<div class="proof-title">
732+
<span class="proof-type">Exercise 11.3</span>
733+
734+
</div><div class="proof-content">
735+
<p>Obtain the <a class="reference external" href="https://classroom.github.com/a/HdgipMxw">practice problem from GitHub Classroom</a>. Follow the instructions in
736+
the README file that will be displayed on GitHub on your copy of the page.</p>
737+
<div class="admonition note">
738+
<p class="admonition-title">Note</p>
739+
<p>This exercise is fully set up as an exam question, including provisional
740+
points on the autotests. It should be doable in 30 minutes, though the
741+
level of programming is a little more basic than the exam questions.</p>
742+
</div>
743+
</div></div><div class="proof proof-type-exercise" id="id10">
744+
745+
<div class="proof-title">
746+
<span class="proof-type">Exercise 11.4</span>
747+
748+
</div><div class="proof-content">
749+
<p>Obtain the <a class="reference external" href="https://classroom.github.com/a/6usAsES4">practice problem from GitHub Classroom</a>. Follow the instructions in
750+
the README file that will be displayed on GitHub on your copy of the page.</p>
751+
<div class="admonition note">
752+
<p class="admonition-title">Note</p>
753+
<p>This exercise is at the level of an exam question, though longer. An
754+
actual exam question would be pruned back to be achievable in 30
755+
minutes. Here the complete exercise is presented because the main thing
756+
you need to do is practice programming, and cutting out material
757+
doesn’t help with that. Marks are not given as the question is the
758+
wrong length, so dividing 20 marks over the question would just be
759+
misleading</p>
760+
</div>
761+
</div></div><p>In addition to these exam-style questions, you can also usefully practice
762+
programming by going beyond the specification of the exercises in the course.
763+
The following exercises are just ideas for how to do that. They do not come
764+
with additional code or tests.</p>
765+
<div class="proof proof-type-exercise" id="id11">
766+
767+
<div class="proof-title">
768+
<span class="proof-type">Exercise 11.5</span>
769+
770+
</div><div class="proof-content">
771+
<p>Extend the <code class="xref py py-class docutils literal notranslate"><span class="pre">Polynomial</span></code> class from <a class="reference internal" href="3_objects.html#objects"><span class="std std-numref">Week 3</span></a> to
772+
support polynomial division. Polynomial division results in a quotient and
773+
a remainder, so you might choose to implement <a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#object.__floordiv__" title="(in Python v3.9)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__floordiv__()</span></code></a>
774+
to return the quotient and <a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#object.__mod__" title="(in Python v3.9)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__mod__()</span></code></a> to return the remainder,
775+
in a manner analogous to integer division. You might also implement
776+
<a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#object.__truediv__" title="(in Python v3.9)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__truediv__()</span></code></a> and have it return the quotient if the
777+
polynomial division is exact, but raise <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a> if there is a
778+
remainder.</p>
779+
<div class="admonition hint">
780+
<p class="admonition-title">Hint</p>
781+
<p>Don’t forget that repeating code is poor style, so you might need a
782+
helper method to implement the actual polynomial division.</p>
783+
</div>
784+
</div></div><div class="proof proof-type-exercise" id="id12">
785+
786+
<div class="proof-title">
787+
<span class="proof-type">Exercise 11.6</span>
788+
789+
</div><div class="proof-content">
790+
<p>Extend the <code class="xref py py-class docutils literal notranslate"><span class="pre">Deque</span></code> class from <a class="reference internal" href="5_abstract_data_types.html#abstract-data-types"><span class="std std-numref">Week 5</span></a> to automatically resize the ring buffer by a
791+
proportion of its length when it is full, and when it becomes too empty.
792+
You can check the behaviour of your implementation against
793+
<a class="reference external" href="https://docs.python.org/3/library/collections.html#collections.deque" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.deque</span></code></a>.</p>
794+
</div></div><div class="proof proof-type-exercise" id="id13">
795+
796+
<div class="proof-title">
797+
<span class="proof-type">Exercise 11.7</span>
798+
799+
</div><div class="proof-content">
800+
<p>For a real challenge, extend the groups implementation from <a class="reference internal" href="8_inheritance.html#inheritance"><span class="std std-numref">Week
801+
8</span></a> to support taking the quotient of two groups. What do the
802+
values and validation of a quotient group look like in code? You could
803+
implement <a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#object.__truediv__" title="(in Python v3.9)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__truediv__()</span></code></a> on <code class="xref py py-class docutils literal notranslate"><span class="pre">Group</span></code> to provide the user
804+
interface.</p>
805+
</div></div><div class="proof proof-type-exercise" id="id14">
806+
807+
<div class="proof-title">
808+
<span class="proof-type">Exercise 11.8</span>
809+
810+
</div><div class="proof-content">
811+
<p>Write additional single dispatch visitor functions to extend the
812+
capabilities of the symbolic algebra system you wrote in <a class="reference internal" href="10_trees_and_directed_acyclic_graphs.html#trees"><span class="std std-numref">Week 10</span></a>. You could, for example, write a visitor which performs
813+
cancellation of expressions involving 1 or 0. You could implement expansion
814+
of brackets according to distributive laws. Finally you could canonicalise
815+
commutative operators such as <code class="xref py py-obj docutils literal notranslate"><span class="pre">+</span></code> and <code class="xref py py-obj docutils literal notranslate"><span class="pre">*</span></code> so that, for example <code class="xref py py-obj docutils literal notranslate"><span class="pre">1</span> <span class="pre">+</span> <span class="pre">x</span></code> is
816+
mapped to <code class="xref py py-obj docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">1</span></code>. Doing this over multiple layers of the tree
817+
(transforming <code class="xref py py-obj docutils literal notranslate"><span class="pre">1</span> <span class="pre">+</span> <span class="pre">2*x</span> <span class="pre">+</span> <span class="pre">3*x**2</span></code> to <code class="xref py py-obj docutils literal notranslate"><span class="pre">3*x**2</span> <span class="pre">+</span> <span class="pre">2*x</span> <span class="pre">+</span> <span class="pre">1</span></code> is an additional
818+
challenge.</p>
819+
</div></div><p class="rubric">Footnotes</p>
730820
<dl class="footnote brackets">
731821
<dt class="label" id="python-in-python"><span class="brackets"><a class="fn-backref" href="#id3">1</a></span></dt>
732822
<dd><p>Most of the <a class="reference external" href="https://docs.python.org/3/library/index.html#library-index" title="(in Python v3.9)"><span class="xref std std-ref">Python Standard Library</span></a> is written

_sources/11_further_object-oriented_features.rst.txt

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,91 @@ people attend then I will also run a group Q & A session.
654654
Practice questions
655655
~~~~~~~~~~~~~~~~~~
656656

657-
Some specifically-designed practice questions will be released at about the end
658-
of term. In addition to this, there are a lot of very good exercises in
657+
Some specifically-designed practice questions are presented below. In addition to this, there are a lot of very good exercises in
659658
chapters 7 and 9 of `Hans Petter Langtangen, A Primer on Scientific Programming
660659
with Python <https://link.springer.com/book/10.1007%2F978-3-662-49887-3>`__.
661660
You can access that book by logging in with your Imperial credentials.
662661

662+
The first two questions are in exam format.
663+
664+
.. proof:exercise::
665+
666+
Obtain the `practice problem from GitHub Classroom
667+
<https://classroom.github.com/a/HdgipMxw>`__. Follow the instructions in
668+
the README file that will be displayed on GitHub on your copy of the page.
669+
670+
.. note::
671+
672+
This exercise is fully set up as an exam question, including provisional
673+
points on the autotests. It should be doable in 30 minutes, though the
674+
level of programming is a little more basic than the exam questions.
675+
676+
.. proof:exercise::
677+
678+
Obtain the `practice problem from GitHub Classroom
679+
<https://classroom.github.com/a/6usAsES4>`__. Follow the instructions in
680+
the README file that will be displayed on GitHub on your copy of the page.
681+
682+
.. note::
683+
684+
This exercise is at the level of an exam question, though longer. An
685+
actual exam question would be pruned back to be achievable in 30
686+
minutes. Here the complete exercise is presented because the main thing
687+
you need to do is practice programming, and cutting out material
688+
doesn't help with that. Marks are not given as the question is the
689+
wrong length, so dividing 20 marks over the question would just be
690+
misleading
691+
692+
In addition to these exam-style questions, you can also usefully practice
693+
programming by going beyond the specification of the exercises in the course.
694+
The following exercises are just ideas for how to do that. They do not come
695+
with additional code or tests.
696+
697+
.. proof:exercise::
698+
699+
Extend the :class:`Polynomial` class from :numref:`Week %s <objects>` to
700+
support polynomial division. Polynomial division results in a quotient and
701+
a remainder, so you might choose to implement :meth:`~object.__floordiv__`
702+
to return the quotient and :meth:`~object.__mod__` to return the remainder,
703+
in a manner analogous to integer division. You might also implement
704+
:meth:`~object.__truediv__` and have it return the quotient if the
705+
polynomial division is exact, but raise :class:`ValueError` if there is a
706+
remainder.
707+
708+
.. hint::
709+
710+
Don't forget that repeating code is poor style, so you might need a
711+
helper method to implement the actual polynomial division.
712+
713+
.. proof:exercise::
714+
715+
Extend the :class:`Deque` class from :numref:`Week %s
716+
<abstract_data_types>` to automatically resize the ring buffer by a
717+
proportion of its length when it is full, and when it becomes too empty.
718+
You can check the behaviour of your implementation against
719+
:class:`collections.deque`.
720+
721+
.. proof:exercise::
722+
723+
For a real challenge, extend the groups implementation from :numref:`Week
724+
%s <inheritance>` to support taking the quotient of two groups. What do the
725+
values and validation of a quotient group look like in code? You could
726+
implement :meth:`~object.__truediv__` on :class:`Group` to provide the user
727+
interface.
728+
729+
.. proof:exercise::
730+
731+
Write additional single dispatch visitor functions to extend the
732+
capabilities of the symbolic algebra system you wrote in :numref:`Week %s
733+
<trees>`. You could, for example, write a visitor which performs
734+
cancellation of expressions involving 1 or 0. You could implement expansion
735+
of brackets according to distributive laws. Finally you could canonicalise
736+
commutative operators such as `+` and `*` so that, for example `1 + x` is
737+
mapped to `x + 1`. Doing this over multiple layers of the tree
738+
(transforming `1 + 2*x + 3*x**2` to `3*x**2 + 2*x + 1` is an additional
739+
challenge.
740+
741+
663742
.. rubric:: Footnotes
664743

665744
.. [#python_in_python] Most of the :ref:`Python Standard Library <library-index>` is written

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)