You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+63-21Lines changed: 63 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,23 +28,31 @@ The library allows users to work with congruence classes (including finite field
28
28
29
29
Installation and Usage
30
30
----------------------
31
-
This library is available as a `package on PyPI <https://pypi.org/project/modulo>`__::
31
+
This library is available as a `package on PyPI <https://pypi.org/project/modulo>`__:
32
+
33
+
.. code-block:: bash
32
34
33
35
python -m pip install modulo
34
36
35
-
The library can be imported in the usual way::
37
+
The library can be imported in the usual way:
38
+
39
+
.. code-block:: python
36
40
37
41
from modulo import modulo
38
42
39
43
Examples
40
44
^^^^^^^^
41
-
This library makes it possible to work with `congruence classes <https://en.wikipedia.org/wiki/Congruence_relation>`__ (and sets of congruence classes such as finite fields) as objects. A congruence class is defined using a representative integer and a modulus::
45
+
This library makes it possible to work with `congruence classes <https://en.wikipedia.org/wiki/Congruence_relation>`__ (and sets of congruence classes such as finite fields) as objects. A congruence class is defined using a representative integer and a modulus:
46
+
47
+
.. code-block:: python
42
48
43
49
>>>from modulo import modulo
44
50
>>> modulo(3, 7)
45
51
modulo(3, 7)
46
52
47
-
Built-in operators can be used to perform modular addition, modular subtraction, and modular negation of congruence classes::
53
+
Built-in operators can be used to perform modular addition, modular subtraction, and modular negation of congruence classes:
54
+
55
+
.. code-block:: python
48
56
49
57
>>> modulo(3, 7) + modulo(5, 7)
50
58
modulo(1, 7)
@@ -53,7 +61,9 @@ Built-in operators can be used to perform modular addition, modular subtraction,
53
61
>>>-modulo(5, 7)
54
62
modulo(2, 7)
55
63
56
-
Modular multiplication, division, inversion, and exponentiation are also supported (when they are defined)::
64
+
Modular multiplication, division, inversion, and exponentiation are also supported (when they are defined):
65
+
66
+
.. code-block:: python
57
67
58
68
>>> modulo(3, 7) * modulo(5, 7)
59
69
modulo(1, 7)
@@ -64,14 +74,18 @@ Modular multiplication, division, inversion, and exponentiation are also support
64
74
>>> modulo(5, 7) ** (-1)
65
75
modulo(3, 7)
66
76
67
-
Individual congruence classes can be compared with one another according to their least nonnegative residues (and, thus, can also be sorted)::
77
+
Individual congruence classes can be compared with one another according to their least nonnegative residues (and, thus, can also be sorted):
A set of congruence classes such as a finite field can also be defined. The built-in length function |len|_ and the membership operator are supported::
100
+
A set of congruence classes such as a finite field can also be defined. The built-in length function |len|_ and the membership operator are supported:
101
+
102
+
.. code-block:: python
87
103
88
104
>>>len(modulo(7))
89
105
7
@@ -93,15 +109,19 @@ A set of congruence classes such as a finite field can also be defined. The buil
The built-in |int|_ function can be used to retrieve the least nonnegative residue of a congruence class and the built-in |len|_ function can be used to retrieve the modulus of a congruence class or set of congruence classes (this is the recommended approach)::
112
+
The built-in |int|_ function can be used to retrieve the least nonnegative residue of a congruence class and the built-in |len|_ function can be used to retrieve the modulus of a congruence class or set of congruence classes (this is the recommended approach):
113
+
114
+
.. code-block:: python
97
115
98
116
>>> c = modulo(3, 7)
99
117
>>>int(c)
100
118
3
101
119
>>>len(c)
102
120
7
103
121
104
-
Congruence classes and sets of congruence classes are also hashable (making it possible to use them as dictionary keys and as set members) and iterable::
122
+
Congruence classes and sets of congruence classes are also hashable (making it possible to use them as dictionary keys and as set members) and iterable:
123
+
124
+
.. code-block:: python
105
125
106
126
>>>len({mod(0, 3), mod(1, 3), mod(2, 3)})
107
127
3
@@ -111,14 +131,18 @@ Congruence classes and sets of congruence classes are also hashable (making it p
111
131
>>>list(islice(mod(3, 7), 5))
112
132
[3, 10, 17, 24, 31]
113
133
114
-
The `Chinese remainder theorem <https://en.wikipedia.org/wiki/Chinese_remainder_theorem>`__ can be applied to construct the intersection of two congruence classes as a congruence class (when it is possible to do so)::
134
+
The `Chinese remainder theorem <https://en.wikipedia.org/wiki/Chinese_remainder_theorem>`__ can be applied to construct the intersection of two congruence classes as a congruence class (when it is possible to do so):
135
+
136
+
.. code-block:: python
115
137
116
138
>>> mod(23, 100) & mod(31, 49)
117
139
modulo(423, 4900)
118
140
>>> mod(2, 10) & mod(4, 20) isNone
119
141
True
120
142
121
-
Some familiar forms of notation for referring to congruence classes (and sets thereof) are also supported::
143
+
Some familiar forms of notation for referring to congruence classes (and sets thereof) are also supported:
144
+
145
+
.. code-block:: python
122
146
123
147
>>> Z/(23*Z)
124
148
modulo(23)
@@ -129,30 +153,40 @@ Some familiar forms of notation for referring to congruence classes (and sets th
129
153
130
154
Development
131
155
-----------
132
-
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__::
156
+
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:
157
+
158
+
.. code-block:: bash
133
159
134
160
python -m pip install .[docs,lint]
135
161
136
162
Documentation
137
163
^^^^^^^^^^^^^
138
-
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__::
164
+
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:
165
+
166
+
.. code-block:: bash
139
167
140
168
python -m pip install .[docs]
141
169
cd docs
142
170
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html
143
171
144
172
Testing and Conventions
145
173
^^^^^^^^^^^^^^^^^^^^^^^
146
-
All unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details)::
174
+
All unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details):
175
+
176
+
.. code-block:: bash
147
177
148
178
python -m pip install .[test]
149
179
python -m pytest
150
180
151
-
Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__::
181
+
Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:
182
+
183
+
.. code-block:: bash
152
184
153
185
python src/modulo/modulo.py -v
154
186
155
-
Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__::
187
+
Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:
188
+
189
+
.. code-block:: bash
156
190
157
191
python -m pip install .[lint]
158
192
python -m pylint src/modulo
@@ -167,20 +201,28 @@ Beginning with version 0.2.0, the version number format for this library and the
167
201
168
202
Publishing
169
203
^^^^^^^^^^
170
-
This library can be published as a `package on PyPI <https://pypi.org/project/modulo>`__ by a package maintainer. First, install the dependencies required for packaging and publishing::
204
+
This library can be published as a `package on PyPI <https://pypi.org/project/modulo>`__ by a package maintainer. First, install the dependencies required for packaging and publishing:
205
+
206
+
.. code-block:: bash
171
207
172
208
python -m pip install .[publish]
173
209
174
-
Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number)::
210
+
Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number):
211
+
212
+
.. code-block:: bash
175
213
176
214
git tag ?.?.?
177
215
git push origin ?.?.?
178
216
179
-
Remove any old build/distribution files. Then, package the source into a distribution archive::
217
+
Remove any old build/distribution files. Then, package the source into a distribution archive:
218
+
219
+
.. code-block:: bash
180
220
181
221
rm -rf build dist src/*.egg-info
182
222
python -m build --sdist --wheel .
183
223
184
-
Finally, upload the package distribution archive to `PyPI <https://pypi.org>`__::
224
+
Finally, upload the package distribution archive to `PyPI <https://pypi.org>`__:
0 commit comments