Skip to content

Commit bbf7dc4

Browse files
committed
docs: further fixes in docstrings and Sphinx docs
1 parent 21a2ac7 commit bbf7dc4

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

docs/sources/rational-points.rst

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,17 @@ Internally, the rational components of a :py:class:`~continuedfractions.rational
7070
>>> P.y
7171
ContinuedFraction(4, 5)
7272
>>> P.coordinates
73-
Dim2RationalCoordinates(ContinuedFraction(3, 5), ContinuedFraction(4, 5))
73+
Dim2RationalCoordinates(3/5, 4/5)
7474
75-
Note that :py:attr:`~continuedfractions.rational_points.RationalPoint.coordinates` property returns a :py:class:`~continuedfractions.rational_points.RationalPoint.Dim2RationalCoordinates` object, which is a simple :py:class:`tuple`-based wrapper for 2D rational coordinates.
75+
Note that the :py:attr:`~continuedfractions.rational_points.RationalPoint.coordinates` property returns a :py:class:`~continuedfractions.rational_points.Dim2RationalCoordinates` object, which is a simple :py:class:`tuple`-based wrapper for 2D rational coordinates, which can also be used to access the rational point coordinates:
76+
77+
.. code:: python
78+
79+
>>> P = RP(F(3, 5), F(4, 5))
80+
>>> P.coordinates.x
81+
ContinuedFraction(3, 5)
82+
>>> P.coordinates.y
83+
ContinuedFraction(4, 5)
7684
7785
As :py:class:`~continuedfractions.rational_points.RationalPoint` objects are also instances of :py:class:`tuple`, they support almost all of the common :py:class:`tuple`-compatible operations including indexing, sorting, iteration, unpacking:
7886

@@ -282,20 +290,25 @@ Some examples are given below:
282290
>>> RP(F(1, 2), F(2, 3)).homogeneous_coordinates
283291
(3, 4, 6)
284292
285-
Note that the examples involving ``RP(F(3, 5), F(4, 5))`` and ``RP(F(5, 13), F(12, 13))`` yield the primitive Pythagorean triples :math:`(3, 4, 5)` and :math:`(5, 12, 13)` respectively because the underlying rational points :math:`\left(\frac{3}{5},\frac{4}{5}\right)` and :math:`\left(\frac{5}{13},\frac{12}{13}\right)` fall on the unit circle :math:`x^2 + y^2 = 1` and have numerators which are coprime. The example with ``RP(F(6, 10), F(8, 10))`` yields the non-primitive Pythagorean triple :math:`(6, 8, 10)` which happens to be a scalar multiple :math:`2\cdot(3, 4, 5)` of :math:`(3, 4, 5)`, but both are homogeneous coordinates for the same rational point :math:`\left(\frac{3}{5},\frac{4}{5}\right)`.
293+
.. note::
286294
287-
Also note that :py:attr:`~continuedfractions.rational_points.RationalPoint.homogeneous_coordinates` returns a :py:class:`~continuedfractions.rational_points.Dim3RationalCoordinates` object, which is a simple and scalable :py:class:`tuple`-based wrapper for 3D rational coordinates. This means that homogeneous coordinates can be scaled and re-scaled at will:
295+
The term "minimal" above refers to the fact that the integer coordinates returned by :py:attr:`~continuedfractions.rational_points.RationalPoint.homogeneous_coordinates` are (setwise) coprime and are the smallest possible (in magnitude), by construction, with respect to the coordinates of the original rational point, as will be described below.
288296
289-
.. code:: python
297+
The examples involving ``RP(F(3, 5), F(4, 5))`` and ``RP(F(5, 13), F(12, 13))`` yield the primitive Pythagorean triples :math:`(3, 4, 5)` and :math:`(5, 12, 13)` respectively because the underlying rational points :math:`\left(\frac{3}{5},\frac{4}{5}\right)` and :math:`\left(\frac{5}{13},\frac{12}{13}\right)` fall on the unit circle :math:`x^2 + y^2 = 1` and have numerators which are coprime. The example with ``RP(F(6, 10), F(8, 10))`` yields the non-primitive Pythagorean triple :math:`(6, 8, 10)` which happens to be a scalar multiple :math:`2\cdot(3, 4, 5)` of :math:`(3, 4, 5)`, but both are homogeneous coordinates for the same rational point :math:`\left(\frac{3}{5},\frac{4}{5}\right)`.
298+
299+
Note that :py:attr:`~continuedfractions.rational_points.RationalPoint.homogeneous_coordinates` returns a :py:class:`~continuedfractions.rational_points.Dim3RationalCoordinates` object, which is a simple :py:class:`tuple`-based wrapper for 3D rational coordinates which are accesible via the object, and the coordinates can be scaled and re-scaled any number of times:
290300
291-
>>> RP(1, 2).homogeneous_coordinates
292-
Dim3RationalCoordinates(1, 2, 1)
293-
>>> RP(1, 2).homogeneous_coordinates.scale(F(-1, 2))
294-
Dim3RationalCoordinates(-1/2, -1, -1/2)
295-
>>> RP(1, 2).homogeneous_coordinates.scale(F(-1, 2)).scale(-2)
296-
Dim3RationalCoordinates(1, 2, 1)
301+
.. code:: python
297302
298-
The term "minimal" above refers to the fact that the integer coordinates returned by :py:attr:`~continuedfractions.rational_points.RationalPoint.homogeneous_coordinates` are (setwise) coprime and are the smallest possible (in magnitude), by construction, with respect to the coordinates of the original rational point, as described below.
303+
>>> P = RP(F(3, 5), F(4, 5))
304+
>>> P.homogeneous_coordinates
305+
Dim3RationalCoordinates(3, 4, 5)
306+
>>> P.homogeneous_coordinates.x, P.homogeneous_coordinates.y, P.homogeneous_coordinates.z
307+
(3, 4, 5)
308+
>>> P.homogeneous_coordinates.scale(2)
309+
Dim3RationalCoordinates(6, 8, 10)
310+
>>> P.homogeneous_coordinates.scale(2).scale(F(1, 2))
311+
Dim3RationalCoordinates(3, 4, 5)
299312
300313
Users can refer to textbooks for more details on homogeneous coordinates and projective spaces, but, with respect to rational points in the plane, the basic idea is that they can be identified with certain "points" of :math:`\mathbb{P}^2(\mathbb{Q})` which happen to be equivalence classes of type :math:`\left[\frac{a}{c}: \frac{b}{d}: 1\right]` (for :math:`\frac{a}{c}, \frac{b}{d} \in \mathbb{Q}`) under :math:`\sim` (the scalar multiple equivalence relation described above): the mapping :math:`\left(\frac{a}{c},\frac{b}{d}\right) \longmapsto \left[\frac{a}{c},\frac{b}{d},1\right]` is a bijection from :math:`\mathbb{Q}^2` into :math:`\mathbb{P}^2(\mathbb{Q})`, and allows rational points to be studied in a 3D setting.
301314
@@ -320,10 +333,10 @@ Some examples are given below:
320333
321334
.. code:: python
322335
323-
>>> RP(F(0, 0)).projective_height
336+
>>> RP(0, 0).projective_height
324337
1
325338
>>> RP(2, F(1, 2)).projective_height
326-
6
339+
4
327340
>>> RP(F(3, 5), F(4, 5)).projective_height
328341
5
329342
>>> RP(F(-3, 5), F(4, 5)).projective_height
@@ -339,7 +352,7 @@ Some examples are given below:
339352
340353
.. code:: python
341354
342-
>>> RP(F(0, 0)).log_projective_height
355+
>>> RP(0, 0).log_projective_height
343356
Decimal('0')
344357
>>> RP(2, F(1, 2)).log_projective_height
345358
Decimal('1.3862943611198905724535279659903608262538909912109375')

src/continuedfractions/rational_points.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class RationalTuple(tuple):
3030
The class serves as a generic base for other custom rational-valued tuple
3131
types defined in this library:
3232
33-
* `~continuedfractions.rational_points.Dim2RationalCoordinates`
34-
* `~continuedfractions.rational_points.Dim3RationalCoordinates`
35-
* `~continuedfractions.rational_points.RationalPoint`
33+
* :py:class:`~continuedfractions.rational_points.Dim2RationalCoordinates`
34+
* :py:class:`~continuedfractions.rational_points.Dim3RationalCoordinates`
35+
* :py:class:`~continuedfractions.rational_points.RationalPoint`
3636
3737
It does not contain any mathematical structure. That is left to the other
3838
custom types listed above.
@@ -44,7 +44,7 @@ class RationalTuple(tuple):
4444
>>> RationalTuple(F(1, 2), CF(3, 4))
4545
RationalTuple(1/2, 3/4)
4646
"""
47-
def __new__(cls, *args: Any) -> RationalTuple:
47+
def __new__(cls, *args: numbers.Rational) -> RationalTuple:
4848
"""Constructor.
4949
"""
5050
if args is None or any(not isinstance(arg, numbers.Rational) for arg in args):
@@ -101,7 +101,7 @@ class Dim2RationalCoordinates(RationalTuple):
101101
>>> c.y
102102
Fraction(3, 4)
103103
"""
104-
def __new__(cls, *args: Any) -> Dim2RationalCoordinates:
104+
def __new__(cls, *args: numbers.Rational) -> Dim2RationalCoordinates:
105105
"""Constructor.
106106
"""
107107
self = super().__new__(cls, *args)
@@ -173,7 +173,7 @@ class Dim3RationalCoordinates(RationalTuple):
173173
>>> c.z
174174
ContinuedFraction(4, 5)
175175
"""
176-
def __new__(cls, *args: Any) -> Dim2RationalCoordinates:
176+
def __new__(cls, *args: numbers.Rational) -> Dim3RationalCoordinates:
177177
"""Constructor.
178178
"""
179179
self = super().__new__(cls, *args)
@@ -807,7 +807,7 @@ def __neg__(self) -> RationalPoint:
807807
"""
808808
return self.__class__(-self.x, -self.y)
809809

810-
def __mul__(self, other: Any) -> RationalPoint:
810+
def __mul__(self, other: Any) -> None:
811811
"""Does not support component-wise right-multiplication by a scalar to respect notational convention.
812812
"""
813813
raise NotImplementedError(

0 commit comments

Comments
 (0)