quadint 0.0.8__cp313-cp313-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 9c46a97409a639359bbf__mypyc.cp313-win32.pyd +0 -0
- quadint/__init__.cp313-win32.pyd +0 -0
- quadint/complex.cp313-win32.pyd +0 -0
- quadint/eisenstein.cp313-win32.pyd +0 -0
- quadint/quad.cp313-win32.pyd +0 -0
- quadint-0.0.8.dist-info/METADATA +144 -0
- quadint-0.0.8.dist-info/RECORD +14 -0
- quadint-0.0.8.dist-info/WHEEL +5 -0
- quadint-0.0.8.dist-info/licenses/LICENSE +19 -0
- quadint-0.0.8.dist-info/top_level.txt +3 -0
- quadint-stubs/__init__.pyi +0 -0
- quadint-stubs/complex.pyi +8 -0
- quadint-stubs/eisenstein.pyi +8 -0
- quadint-stubs/quad.pyi +46 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quadint
|
|
3
|
+
Version: 0.0.8
|
|
4
|
+
Summary: A quadint class, for using quadratic integers.
|
|
5
|
+
Author-email: Ryan Heard <ryanwheard@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/rheard/quadint
|
|
8
|
+
Keywords: complex,math,eisenstein
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# quadint
|
|
25
|
+
|
|
26
|
+
Fast, integer-backed algebraic number types for **exact** arithmetic in imaginary quadratic integer rings.
|
|
27
|
+
|
|
28
|
+
- **`complexint`**: a Gaussian integer type that mirrors Python’s `complex`, but stores **`int`** components (no floating-point drift).
|
|
29
|
+
- **`QuadInt` / `QuadraticRing`**: a general quadratic-integer implementation for elements of the form
|
|
30
|
+
$(a + b\sqrt{D}) / \mathrm{den}$ with $den ∈ {1,2}$.
|
|
31
|
+
- **`eisensteinint`**: Eisenstein integers in the ω-basis (`a + bω`, where `ω = (-1 + √-3)/2`).
|
|
32
|
+
|
|
33
|
+
Designed for discrete math, number theory tooling, and high-throughput exact computations (this project is built to compile cleanly with **mypyc**).
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python -m pip install quadint
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quickstart (recommended): `complexint`
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from quadint import complexint
|
|
49
|
+
|
|
50
|
+
a = complexint(1, 2)
|
|
51
|
+
b = complexint(3, 6)
|
|
52
|
+
|
|
53
|
+
c = a * b
|
|
54
|
+
print(c) # "(-9+12j)" (exact, integer-backed)
|
|
55
|
+
print(c.real) # -9
|
|
56
|
+
print(c.imag) # 12
|
|
57
|
+
print(type(c.real)) # <class 'int'>
|
|
58
|
+
|
|
59
|
+
print(abs(a)) # 1^2 + 2^2 = 5 (norm)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`complexint` is ideal when you want something that *feels like* `complex`, but with infinite-precision integer components.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Quadratic integers: `make_quadint`
|
|
67
|
+
|
|
68
|
+
Create a ring instance for a chosen discriminant parameter `D`, then construct values in that ring:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from quadint import make_quadint
|
|
72
|
+
|
|
73
|
+
Q2 = make_quadint(-2) # Z[√-2]
|
|
74
|
+
|
|
75
|
+
x = Q2(1, 2) # (1 + 2*sqrt(-2))
|
|
76
|
+
y = Q2(3, 6)
|
|
77
|
+
|
|
78
|
+
print(x * y) # "(-21+12*sqrt(-2))"
|
|
79
|
+
print(abs(x)) # norm: 1^2 - (-2)*2^2 = 9
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Common operations include `+`, `-`, `*`, `**` (non-negative powers), `conjugate()`, and `abs()` (the norm).
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Eisenstein integers: `eisensteinint`
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from quadint import eisensteinint
|
|
90
|
+
|
|
91
|
+
z = eisensteinint(2, 3) # 2 + 3ω
|
|
92
|
+
w = eisensteinint(1, -1) # 1 - ω
|
|
93
|
+
|
|
94
|
+
print(z)
|
|
95
|
+
print(z * w) # exact product in Z[ω]
|
|
96
|
+
print(abs(z)) # norm (integer)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Use `real` and `omega` to access the ω-basis components.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Division & interoperability notes
|
|
104
|
+
|
|
105
|
+
* This package is primarily intended for **exact, discrete** arithmetic (`+`, `-`, `*`, `**`, conjugation, norms).
|
|
106
|
+
* Some division helpers exist (e.g. `divmod`, `//`, `%`) for **imaginary** quadratic rings, using a nearest-lattice approach; it may be `NotImplemented` for `D ≥ 0`, and behavior depends on the ring being Euclidean enough for your use case.
|
|
107
|
+
* **Floats and Python `complex` are accepted in some operations but are converted via `int(...)`, which truncates toward zero. If you care about rationals, avoid mixing in `float`.
|
|
108
|
+
|
|
109
|
+
Example of truncation behavior:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from quadint import complexint
|
|
113
|
+
|
|
114
|
+
a = complexint(3, 6)
|
|
115
|
+
|
|
116
|
+
print(a / 3) # "(1+2j)"
|
|
117
|
+
print(a / 3.5) # "(1+2j)" (3.5 -> 3 by int(...) conversion)
|
|
118
|
+
|
|
119
|
+
print(a + 1) # "(4+6j)"
|
|
120
|
+
print(a + 1.5) # "(4+6j)" (1.5 -> 1)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Minimal API overview
|
|
126
|
+
|
|
127
|
+
### Constructors
|
|
128
|
+
|
|
129
|
+
* `complexint(a: int = 0, b: int = 0)`
|
|
130
|
+
* `eisensteinint(a: int = 0, b: int = 0)` where `a + bω`
|
|
131
|
+
* `make_quadint(D: int) -> QuadraticRing`
|
|
132
|
+
|
|
133
|
+
### Ring instance (`QuadraticRing`)
|
|
134
|
+
|
|
135
|
+
* `Q(a: int = 0, b: int = 0) -> QuadInt` (constructs using the ring’s internal basis)
|
|
136
|
+
* `Q.from_ab(a: int, b: int) -> QuadInt` (construct with user coords, respecting `den`)
|
|
137
|
+
* `Q.from_obj(x) -> QuadInt` (embed `int`/`float`, and `complex` only when `D == -1`)
|
|
138
|
+
|
|
139
|
+
### Value type (`QuadInt`)
|
|
140
|
+
|
|
141
|
+
* `x.conjugate()`
|
|
142
|
+
* `abs(x)` (norm)
|
|
143
|
+
* `divmod(x, y)`, `x // y`, `x % y` (where supported)
|
|
144
|
+
* Iteration/indexing over the stored coefficients: `list(x)`, `x[0]`, `x[1]`
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
9c46a97409a639359bbf__mypyc.cp313-win32.pyd,sha256=6Gf-zhe0rn6kQW91hYvm8A9YMAHjY_rlU8uncwGwAI0,95232
|
|
2
|
+
quadint/__init__.cp313-win32.pyd,sha256=7Bhti46HqHCLmrrksB5wXNPCJ_QGzR7TxtGt6tEHSOU,9216
|
|
3
|
+
quadint/complex.cp313-win32.pyd,sha256=x0MMlEIuli3NcjKFmaBqeqBG67y74die6yxzgPKRv5I,9216
|
|
4
|
+
quadint/eisenstein.cp313-win32.pyd,sha256=4hHg_0MvQecM45_5yK22h2jwkurv5ssH9SCGl-NcGAo,9216
|
|
5
|
+
quadint/quad.cp313-win32.pyd,sha256=k4m1FeeG5DH2kJUulEXHb6UPRl14a5Mxbel8LUV1Xa8,9216
|
|
6
|
+
quadint-0.0.8.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
7
|
+
quadint-stubs/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
quadint-stubs/complex.pyi,sha256=WtDMsc_dlLgIK1LxdiRjrSMvhPu6ZXxWPiGB8E92PCA,284
|
|
9
|
+
quadint-stubs/eisenstein.pyi,sha256=jyCDCy4aFpYpIV6f1WZhdvaUpIPK-7IcxY1ZePzuwbc,266
|
|
10
|
+
quadint-stubs/quad.pyi,sha256=zIqLhbEAcYrFJV2mln_-lNo3XrJv0tczLOKf1cYbXUM,1901
|
|
11
|
+
quadint-0.0.8.dist-info/METADATA,sha256=fASNoNW7TIznKTCER6kk-VHnwqhLJKz-3W1mkscRDtk,4542
|
|
12
|
+
quadint-0.0.8.dist-info/WHEEL,sha256=0ABLuJ37exXk5N_efmYNs2NU9NK1K2Qlod_6bYkofEA,97
|
|
13
|
+
quadint-0.0.8.dist-info/top_level.txt,sha256=3uozn88TjoQFTKJWsN_qpidOqiCMI-Vk5jp1XkGRW78,50
|
|
14
|
+
quadint-0.0.8.dist-info/RECORD,,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from quadint.quad import OP_TYPES as OP_TYPES, QuadInt as QuadInt, QuadraticRing as QuadraticRing
|
|
2
|
+
|
|
3
|
+
class complexint(QuadInt):
|
|
4
|
+
def __init__(self, a: int = 0, b: int = 0) -> None: ...
|
|
5
|
+
@property
|
|
6
|
+
def real(self) -> int: ...
|
|
7
|
+
@property
|
|
8
|
+
def imag(self) -> int: ...
|
quadint-stubs/quad.pyi
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from typing import Iterator
|
|
3
|
+
|
|
4
|
+
OTHER_OP_TYPES = complex | int | float
|
|
5
|
+
OP_TYPES: Incomplete
|
|
6
|
+
|
|
7
|
+
class QuadraticRing:
|
|
8
|
+
D: int
|
|
9
|
+
den: int
|
|
10
|
+
def __init__(self, D: int) -> None: ...
|
|
11
|
+
def __call__(self, a: int = 0, b: int = 0) -> QuadInt: ...
|
|
12
|
+
def from_obj(self, n: OP_TYPES) -> QuadInt: ...
|
|
13
|
+
def from_ab(self, a: int, b: int) -> QuadInt: ...
|
|
14
|
+
|
|
15
|
+
class QuadInt:
|
|
16
|
+
ring: QuadraticRing
|
|
17
|
+
a: int
|
|
18
|
+
b: int
|
|
19
|
+
def __init__(self, ring: QuadraticRing, a: int = 0, b: int = 0) -> None: ...
|
|
20
|
+
def assert_same_ring(self, other: QuadInt): ...
|
|
21
|
+
def conjugate(self) -> QuadInt: ...
|
|
22
|
+
def __add__(self, other: OP_TYPES) -> QuadInt: ...
|
|
23
|
+
def __radd__(self, other: OTHER_OP_TYPES) -> QuadInt: ...
|
|
24
|
+
def __sub__(self, other: OP_TYPES) -> QuadInt: ...
|
|
25
|
+
def __rsub__(self, other: OTHER_OP_TYPES) -> QuadInt: ...
|
|
26
|
+
def __neg__(self) -> QuadInt: ...
|
|
27
|
+
def __pos__(self) -> QuadInt: ...
|
|
28
|
+
def __mul__(self, other: OP_TYPES) -> QuadInt: ...
|
|
29
|
+
def __rmul__(self, other: OTHER_OP_TYPES) -> QuadInt: ...
|
|
30
|
+
def __pow__(self, exp: float) -> QuadInt: ...
|
|
31
|
+
def __divmod__(self, other: OP_TYPES) -> tuple['QuadInt', 'QuadInt']: ...
|
|
32
|
+
def __truediv__(self, other: OP_TYPES) -> QuadInt: ...
|
|
33
|
+
def __rtruediv__(self, other: OTHER_OP_TYPES) -> QuadInt: ...
|
|
34
|
+
def __floordiv__(self, other: OP_TYPES) -> QuadInt: ...
|
|
35
|
+
def __rfloordiv__(self, other: OTHER_OP_TYPES) -> QuadInt: ...
|
|
36
|
+
def __mod__(self, other: QuadInt) -> QuadInt: ...
|
|
37
|
+
def __abs__(self) -> int: ...
|
|
38
|
+
def __bool__(self) -> bool: ...
|
|
39
|
+
def __iter__(self) -> Iterator[int]: ...
|
|
40
|
+
def __len__(self) -> int: ...
|
|
41
|
+
def __getitem__(self, idx: int) -> int: ...
|
|
42
|
+
def __eq__(self, other: object) -> bool: ...
|
|
43
|
+
def __ne__(self, other: object) -> bool: ...
|
|
44
|
+
def __hash__(self) -> int: ...
|
|
45
|
+
|
|
46
|
+
def make_quadint(D: int) -> QuadraticRing: ...
|