Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 1 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.6%) to scientific vocabulary
Keywords
Repository
p-Adic numbers and finite fields in Python
Basic Info
- Host: GitHub
- Owner: GDeLaurentis
- License: gpl-3.0
- Language: Python
- Default Branch: main
- Homepage: https://gdelaurentis.github.io/pyadic/
- Size: 5.23 MB
Statistics
- Stars: 20
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 7
Topics
Metadata Files
README.md
pyAdic
The pyadic library is Python 3 package that provides number types for finite fields $\mathbb{F}p$ (ModP) and $p$-adic numbers $\mathbb{Q}p$ (PAdic). The goal is to mimic the flexible behavior of built-in types, such as int, float and complex. Thus, one can mix-and-match the different number types, as long as the operations are consistent. In particular, ModP and PAdic are compatible with fractions.Fraction.
In addition to arithmetic operations, the pyadic library also provides the following functions:
rationaliseto perform rationalization ($\mathbb{F}p\rightarrow \mathbb{Q}$ and $\mathbb{Q}p \rightarrow \mathbb{Q}$);finite_field_sqrtandpadic_sqrtto compute square roots (which may involveFieldExtension);padic_logto compute the $p$-adic logarithm.- polynomial and rational function interpolation, see
interpolation.pymodule.
A shout-out to galois for a very nice tool. It is recommented for vectorized finite field operations, unless type compatibility is an issue. For scalar operation this repo is recommended. See performance comparison below.
Installation
The package is available on the Python Package Index
console
pip install pyadic
Alternativelty, it can be installed by cloning the repo
console
git clone https://github.com/GDeLaurentis/pyadic.git path/to/repo
pip install -e path/to/repo
Requirements
pip will automatically install the required packages, which are
numpy, sympy
Additionally, pytest is needed for testing.
Testing
Extensive tests are implemented with pytest
console
pytest --cov pyadic/ --cov-report html tests/ --verbose
Quick Start
```python In [1]: from pyadic import PAdic, ModP In [2]: from fractions import Fraction as Q
7/13 as a 12-digit 2147483647-adic number
In [3]: PAdic(Q(7, 13), 2147483647, 12)
Out [3]: 1817101548 + 8259552482147483647 + 11563373482147483647^2 + 3303820992147483647^3 + 13215283982147483647^4 + 9911462982147483647^5 + 18171015472147483647^6 + 8259552482147483647^7 + 11563373482147483647^8 + 3303820992147483647^9 + 13215283982147483647^10 + 991146298*2147483647^11 + O(2147483647^12)
7/13 in F_2147483647
In [4]: ModP(Q(7, 13), 2147483647) Out [4]: 1817101548 % 2147483647
Mapping back to rational numbers
In [5]: from pyadic.finite_field import rationalise In [6]: rationalise(ModP(Q(7, 13), 2147483647)) Out [6]: Fraction(7, 13) In [7]: rationalise(PAdic(Q(7, 13), 2147483647, 12)) Out [7]: Fraction(7, 13) ```
Perfomance comparison with galois for finite fields
Scalar instantiation and operations are faster in pyadic ```python import numpy from galois import GF from pyadic import ModP from random import randint
GFp = GF(2 ** 31 - 1) x = randint(0, 2 ** 31 - 1)
%timeit GFp(x) 2.84 µs ± 63.5 ns
%timeit ModP(x, 2 ** 31 - 1) 297 ns ± 0.876 ns
%timeit GFp(x) ** 2 30.1 µs ± 20.6 µs
%timeit ModP(x, 2 ** 31 - 1) ** 2 2.23 µs ± 91.8 ns ```
while galois is faster for vectorized operations (the bigger the array the bigger the gain) ```python %timeit numpy.array([randint(0, 2 ** 31 - 1) for i in range(100)]).view(GFp) ** 2 65.6 µs ± 1.86 µs
%timeit numpy.array([ModP(randint(0, 2 ** 31 - 1), 2 ** 31 - 1) for i in range(100)]) ** 2 351 µs ± 9.28 µs ```
However, galois requires everything to be appropriately typed, while pyadic performs type-casting on-the-fly ```python numpy.array([randint(0, 2 ** 31 - 1) for i in range(100)]).view(GFp) / 2 TypeError
numpy.array([ModP(randint(0, 2 ** 31 - 1), 2 ** 31 - 1) for i in range(100)]) / 2 array([...], dtype=object) ```
Citation
If you found this library useful, please consider citing it
bibtex
@inproceedings{DeLaurentis:2023qhd,
author = "De Laurentis, Giuseppe",
title = "{Lips: $p$-adic and singular phase space}",
booktitle = "{21th International Workshop on Advanced Computing and Analysis Techniques in Physics Research}: {AI meets Reality}",
eprint = "2305.14075",
archivePrefix = "arXiv",
primaryClass = "hep-th",
reportNumber = "PSI-PR-23-14",
month = "5",
year = "2023"
}
Owner
- Name: Giuseppe DeLaurentis
- Login: GDeLaurentis
- Kind: user
- Location: Villigen, CH
- Company: Paul Scherrer Institut (PSI)
- Website: https://gdelaurentis.github.io/
- Repositories: 4
- Profile: https://github.com/GDeLaurentis
Citation (CITATION.bib)
@inproceedings{DeLaurentis:2023qhd,
author = "De Laurentis, Giuseppe",
title = "{Lips: $p$-adic and singular phase space}",
booktitle = "{21th International Workshop on Advanced Computing and Analysis Techniques in Physics Research}: {AI meets Reality}",
eprint = "2305.14075",
archivePrefix = "arXiv",
primaryClass = "hep-th",
reportNumber = "PSI-PR-23-14",
month = "5",
year = "2023"
}
GitHub Events
Total
- Release event: 2
- Watch event: 6
- Push event: 30
- Create event: 2
Last Year
- Release event: 2
- Watch event: 6
- Push event: 30
- Create event: 2
Issues and Pull Requests
Last synced: 7 months ago
All Time
- Total issues: 4
- Total pull requests: 0
- Average time to close issues: 5 days
- Average time to close pull requests: N/A
- Total issue authors: 3
- Total pull request authors: 0
- Average comments per issue: 1.5
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- timsherwood (2)
- funfwo (1)
- BMDragon (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 694 last-month
- Total dependent packages: 1
- Total dependent repositories: 1
- Total versions: 9
- Total maintainers: 1
pypi.org: pyadic
p-Adic numbers and finite fields in Python
- Homepage: https://github.com/GDeLaurentis/pyadic
- Documentation: https://gdelaurentis.github.io/pyadic/
- License: GNU General Public License v3.0
-
Latest release: 0.2.4
published 10 months ago
Rankings
Maintainers (1)
Dependencies
- numpy *
- sympy *
- actions/checkout v2 composite
- actions/setup-python v2 composite
- stefanzweifel/git-auto-commit-action v4 composite