complexity-range 0.0.5__tar.gz
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.
- complexity_range-0.0.5/CHANGELOG.md +11 -0
- complexity_range-0.0.5/LICENSE +21 -0
- complexity_range-0.0.5/MANIFEST.in +2 -0
- complexity_range-0.0.5/PKG-INFO +70 -0
- complexity_range-0.0.5/README.md +38 -0
- complexity_range-0.0.5/pyproject.toml +66 -0
- complexity_range-0.0.5/setup.cfg +4 -0
- complexity_range-0.0.5/src/complexity_range/__init__.py +10 -0
- complexity_range-0.0.5/src/complexity_range/core.py +209 -0
- complexity_range-0.0.5/src/complexity_range.egg-info/PKG-INFO +70 -0
- complexity_range-0.0.5/src/complexity_range.egg-info/SOURCES.txt +12 -0
- complexity_range-0.0.5/src/complexity_range.egg-info/dependency_links.txt +1 -0
- complexity_range-0.0.5/src/complexity_range.egg-info/requires.txt +5 -0
- complexity_range-0.0.5/src/complexity_range.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.5
|
|
4
|
+
|
|
5
|
+
First experimental release: `complexity_range`, a port of a development draft (0.2.1) of the Wolfram Language function ComplexityRange, with the option `complexity_function`.
|
|
6
|
+
|
|
7
|
+
### Differences from the ComplexityRange draft
|
|
8
|
+
|
|
9
|
+
- The complexity function is called once per distinct number generated, instead of once per generated number and again for sorting. For a function that always returns the same value on the same number, the results are the same.
|
|
10
|
+
- The complexities are sorted by numeric value. In the Wolfram Language `SortBy` sorts them in canonical order, which is the same for integer, rational and real values, but places every other exact value (like `Sqrt[2]`) after all the rational ones.
|
|
11
|
+
- An `x` that is not a finite real number raises a `TypeError`.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniele Gregori
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: complexity-range
|
|
3
|
+
Version: 0.0.5
|
|
4
|
+
Summary: Generate ranges of numbers bounded and sorted by complexity
|
|
5
|
+
Author-email: Daniele Gregori <dangregori@gmail.com>
|
|
6
|
+
Maintainer-email: Daniele Gregori <dangregori@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/Daniele-Gregori/PyPI-packages/tree/main/packages/complexity-range
|
|
9
|
+
Project-URL: Repository, https://github.com/Daniele-Gregori/PyPI-packages/tree/main/packages/complexity-range
|
|
10
|
+
Project-URL: Changelog, https://github.com/Daniele-Gregori/PyPI-packages/blob/main/packages/complexity-range/CHANGELOG.md
|
|
11
|
+
Project-URL: Issues, https://github.com/Daniele-Gregori/PyPI-packages/issues
|
|
12
|
+
Keywords: complexity,range,complexity-range,leaf-complexity,numbers,rational,algebraic,square-root,closed-form,symbolic,sympy,mathematics,wolfram
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: leaf-complexity>=0.7.0
|
|
28
|
+
Requires-Dist: sympy>=1.8
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# complexity-range
|
|
34
|
+
|
|
35
|
+
[](https://badge.fury.io/py/complexity-range)
|
|
36
|
+
[](https://opensource.org/licenses/MIT)
|
|
37
|
+
|
|
38
|
+
Generate ranges of numbers bounded and sorted by complexity.
|
|
39
|
+
|
|
40
|
+
`complexity_range(x)` combines the positive integers up to `x` with one elementary operation (negation, reciprocal, square root, sum, difference, product or quotient), keeps the results of complexity up to `x` and sorts them by complexity. The default measure of complexity is [`leaf-complexity`](https://pypi.org/project/leaf-complexity/) minus 1.
|
|
41
|
+
|
|
42
|
+
This is an experimental early release, ported from a draft of the Wolfram Language function `ComplexityRange` by the same author. The interface and the results may change.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install complexity-range
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from complexity_range import complexity_range
|
|
54
|
+
|
|
55
|
+
complexity_range(6)
|
|
56
|
+
# [0, -1, 1, -2, 2, -3, 3, -4, 1/2, 4, -5, 1/3, 5, -6, 1/4, 2/3, 3/2, 6]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The results are [SymPy](https://www.sympy.org) numbers. The option `complexity_function` sets another measure, for instance the absolute value:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
complexity_range(3, complexity_function=lambda e: abs(float(e)))
|
|
63
|
+
# [0, 1/3, 1/2, 2/3, -1, 1, sqrt(2), 3/2, sqrt(3), -2, 2, -3, 3]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Each scan over the integers stops at the first result of complexity above `x`, so a square root within the bound can be missing, like `2*sqrt(2)` in `complexity_range(10)`.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# complexity-range
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/complexity-range)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
Generate ranges of numbers bounded and sorted by complexity.
|
|
7
|
+
|
|
8
|
+
`complexity_range(x)` combines the positive integers up to `x` with one elementary operation (negation, reciprocal, square root, sum, difference, product or quotient), keeps the results of complexity up to `x` and sorts them by complexity. The default measure of complexity is [`leaf-complexity`](https://pypi.org/project/leaf-complexity/) minus 1.
|
|
9
|
+
|
|
10
|
+
This is an experimental early release, ported from a draft of the Wolfram Language function `ComplexityRange` by the same author. The interface and the results may change.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install complexity-range
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from complexity_range import complexity_range
|
|
22
|
+
|
|
23
|
+
complexity_range(6)
|
|
24
|
+
# [0, -1, 1, -2, 2, -3, 3, -4, 1/2, 4, -5, 1/3, 5, -6, 1/4, 2/3, 3/2, 6]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The results are [SymPy](https://www.sympy.org) numbers. The option `complexity_function` sets another measure, for instance the absolute value:
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
complexity_range(3, complexity_function=lambda e: abs(float(e)))
|
|
31
|
+
# [0, 1/3, 1/2, 2/3, -1, 1, sqrt(2), 3/2, sqrt(3), -2, 2, -3, 3]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Each scan over the integers stops at the first result of complexity above `x`, so a square root within the bound can be missing, like `2*sqrt(2)` in `complexity_range(10)`.
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "complexity-range"
|
|
7
|
+
version = "0.0.5"
|
|
8
|
+
description = "Generate ranges of numbers bounded and sorted by complexity"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Daniele Gregori", email = "dangregori@gmail.com" },
|
|
14
|
+
]
|
|
15
|
+
maintainers = [
|
|
16
|
+
{ name = "Daniele Gregori", email = "dangregori@gmail.com" },
|
|
17
|
+
]
|
|
18
|
+
keywords = [
|
|
19
|
+
"complexity",
|
|
20
|
+
"range",
|
|
21
|
+
"complexity-range",
|
|
22
|
+
"leaf-complexity",
|
|
23
|
+
"numbers",
|
|
24
|
+
"rational",
|
|
25
|
+
"algebraic",
|
|
26
|
+
"square-root",
|
|
27
|
+
"closed-form",
|
|
28
|
+
"symbolic",
|
|
29
|
+
"sympy",
|
|
30
|
+
"mathematics",
|
|
31
|
+
"wolfram",
|
|
32
|
+
]
|
|
33
|
+
classifiers = [
|
|
34
|
+
"Development Status :: 3 - Alpha",
|
|
35
|
+
"Intended Audience :: Science/Research",
|
|
36
|
+
"Intended Audience :: Education",
|
|
37
|
+
"Operating System :: OS Independent",
|
|
38
|
+
"Programming Language :: Python :: 3",
|
|
39
|
+
"Programming Language :: Python :: 3.9",
|
|
40
|
+
"Programming Language :: Python :: 3.10",
|
|
41
|
+
"Programming Language :: Python :: 3.11",
|
|
42
|
+
"Programming Language :: Python :: 3.12",
|
|
43
|
+
"Programming Language :: Python :: 3.13",
|
|
44
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
45
|
+
]
|
|
46
|
+
dependencies = [
|
|
47
|
+
"leaf-complexity>=0.7.0",
|
|
48
|
+
"sympy>=1.8",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[project.optional-dependencies]
|
|
52
|
+
dev = [
|
|
53
|
+
"pytest>=7.0",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[project.urls]
|
|
57
|
+
Homepage = "https://github.com/Daniele-Gregori/PyPI-packages/tree/main/packages/complexity-range"
|
|
58
|
+
Repository = "https://github.com/Daniele-Gregori/PyPI-packages/tree/main/packages/complexity-range"
|
|
59
|
+
Changelog = "https://github.com/Daniele-Gregori/PyPI-packages/blob/main/packages/complexity-range/CHANGELOG.md"
|
|
60
|
+
Issues = "https://github.com/Daniele-Gregori/PyPI-packages/issues"
|
|
61
|
+
|
|
62
|
+
[tool.setuptools.packages.find]
|
|
63
|
+
where = ["src"]
|
|
64
|
+
|
|
65
|
+
[tool.pytest.ini_options]
|
|
66
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core implementation of complexity_range.
|
|
3
|
+
|
|
4
|
+
A range is usually bounded by size. complexity_range(x) is bounded by
|
|
5
|
+
complexity instead: it combines the positive integers up to x with one
|
|
6
|
+
elementary operation (negation, reciprocal, square root, sum,
|
|
7
|
+
difference, product, quotient), keeps the results whose complexity
|
|
8
|
+
does not exceed x and returns them sorted by complexity.
|
|
9
|
+
|
|
10
|
+
This is a direct translation of a development draft (0.2.1) of the
|
|
11
|
+
Wolfram Language function ComplexityRange, by the same author. It
|
|
12
|
+
follows the draft loop by loop, including its stopping rule: each scan
|
|
13
|
+
over the integers stops, like Break[], at the first result whose
|
|
14
|
+
complexity exceeds x. Since an argument of higher complexity can give
|
|
15
|
+
a result of lower complexity (Sqrt[8] = 2 Sqrt[2] is simpler than
|
|
16
|
+
Sqrt[7]), a scan can stop before reaching a number that is within the
|
|
17
|
+
bound, which is then missing from the range.
|
|
18
|
+
|
|
19
|
+
Author: Daniele Gregori
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from fractions import Fraction
|
|
23
|
+
from math import floor
|
|
24
|
+
|
|
25
|
+
from sympy import Integer, Rational, S, sqrt
|
|
26
|
+
|
|
27
|
+
from leaf_complexity import leaf_complexity
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _leaf_complexity(expr):
|
|
31
|
+
"""The default complexity function.
|
|
32
|
+
|
|
33
|
+
WL: leafComplexity = -1 + ResourceFunction["LeafComplexity"][#] &
|
|
34
|
+
|
|
35
|
+
leaf_complexity starts its recursion from 1, so that subtracting 1
|
|
36
|
+
gives complexity 0 to the number 0 and |n| to any integer n.
|
|
37
|
+
"""
|
|
38
|
+
return leaf_complexity(expr) - 1
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# The heads act on Python integers and return SymPy numbers. As in the
|
|
42
|
+
# draft, the "plain" heads are scanned over the whole range, while for
|
|
43
|
+
# the "simp" heads (the square root and the quotient) the arguments
|
|
44
|
+
# whose result simplifies to an integer are left out.
|
|
45
|
+
|
|
46
|
+
# heads1 = {Minus[#] &, If[# =!= 0, Divide[1, #], 0] &, Sqrt[#] &}
|
|
47
|
+
|
|
48
|
+
def _minus(a):
|
|
49
|
+
return Integer(-a)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _reciprocal(a):
|
|
53
|
+
return Rational(1, a) if a != 0 else S.Zero
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _sqrt(a):
|
|
57
|
+
return sqrt(Integer(a))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# heads2 = {Plus[#, #2] &, Subtract[#, #2] &, Times[#, #2] &,
|
|
61
|
+
# If[#2 =!= 0, Divide[#, #2], Indeterminate] &}
|
|
62
|
+
|
|
63
|
+
def _plus(a, b):
|
|
64
|
+
return Integer(a + b)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _subtract(a, b):
|
|
68
|
+
return Integer(a - b)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _times(a, b):
|
|
72
|
+
return Integer(a * b)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _divide(a, b):
|
|
76
|
+
return Rational(a, b) if b != 0 else S.NaN
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# {headsPlain1, headsSimp1} = TakeDrop[heads1, 2]
|
|
80
|
+
# {headsPlain2, headsSimp2} = TakeDrop[heads2, 3]
|
|
81
|
+
_HEADS_PLAIN_1 = (_minus, _reciprocal)
|
|
82
|
+
_HEADS_PLAIN_2 = (_plus, _subtract, _times)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _range_length(x):
|
|
86
|
+
"""The length of Range[x]: the integers from 1 to Floor[x]."""
|
|
87
|
+
try:
|
|
88
|
+
return max(int(floor(x)), 0)
|
|
89
|
+
except (TypeError, ValueError, OverflowError):
|
|
90
|
+
raise TypeError(f"x must be a finite real number, got {x!r}") from None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _canonical_key(expr):
|
|
94
|
+
"""The Wolfram canonical order among the generated numbers.
|
|
95
|
+
|
|
96
|
+
SortBy breaks the ties of the complexity by canonical order:
|
|
97
|
+
rational numbers come first, by value, and then the square roots
|
|
98
|
+
k*sqrt(m), by radicand m and then by coefficient k.
|
|
99
|
+
"""
|
|
100
|
+
if expr.is_Rational:
|
|
101
|
+
return (0, Fraction(expr.p, expr.q), 0)
|
|
102
|
+
coefficient, root = expr.as_coeff_Mul()
|
|
103
|
+
return (1, int(root.base), int(coefficient))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def complexity_range(x, complexity_function=None):
|
|
107
|
+
"""
|
|
108
|
+
Generate the range of numbers of complexity up to x.
|
|
109
|
+
|
|
110
|
+
Direct translation of a development draft (0.2.1) of the Wolfram
|
|
111
|
+
Language function ComplexityRange. The positive integers from 1 to
|
|
112
|
+
x are combined with one elementary operation: negation, reciprocal,
|
|
113
|
+
square root, sum, difference, product or quotient. The results
|
|
114
|
+
whose complexity does not exceed x are collected without
|
|
115
|
+
duplicates and sorted by complexity.
|
|
116
|
+
|
|
117
|
+
With the default complexity function, leaf_complexity(e) - 1, an
|
|
118
|
+
integer n has complexity |n|, a fraction p/q in lowest terms
|
|
119
|
+
p + q + 1, a square root sqrt(n) n + 5 and k*sqrt(m) k + m + 6.
|
|
120
|
+
The range then consists of the integers from -x to x, the positive
|
|
121
|
+
fractions p/q with p + q + 1 <= x, and square roots.
|
|
122
|
+
|
|
123
|
+
Each scan over the integers stops at the first result whose
|
|
124
|
+
complexity exceeds x. An argument of higher complexity can give a
|
|
125
|
+
result of lower complexity, so a square root within the bound can
|
|
126
|
+
be missing: complexity_range(10) stops at sqrt(6), of complexity
|
|
127
|
+
11, before reaching sqrt(8) = 2*sqrt(2), of complexity 10.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
x : real number
|
|
132
|
+
The upper bound of the complexity. The integers combined are
|
|
133
|
+
those from 1 to floor(x), like Range[x], so that the result is
|
|
134
|
+
empty for x < 1.
|
|
135
|
+
complexity_function : callable, optional
|
|
136
|
+
The measure of complexity, like the option ComplexityFunction:
|
|
137
|
+
a function of a SymPy number returning a real number. It is
|
|
138
|
+
called once per distinct number generated. If None (default),
|
|
139
|
+
leaf_complexity(e) - 1.
|
|
140
|
+
|
|
141
|
+
Returns
|
|
142
|
+
-------
|
|
143
|
+
list of sympy numbers
|
|
144
|
+
The numbers of complexity up to x, sorted by complexity. Ties
|
|
145
|
+
are in the canonical order of the Wolfram Language: rational
|
|
146
|
+
numbers by value, and then square roots.
|
|
147
|
+
|
|
148
|
+
Examples
|
|
149
|
+
--------
|
|
150
|
+
>>> complexity_range(6)
|
|
151
|
+
[0, -1, 1, -2, 2, -3, 3, -4, 1/2, 4, -5, 1/3, 5, -6, 1/4, 2/3, 3/2, 6]
|
|
152
|
+
>>> complexity_range(8)[-12:]
|
|
153
|
+
[-7, 1/5, 7, sqrt(2), -8, 1/6, 2/5, 3/4, 4/3, 5/2, 8, sqrt(3)]
|
|
154
|
+
>>> complexity_range(2, complexity_function=lambda e: abs(float(e)))
|
|
155
|
+
[0, 1/2, -1, 1, sqrt(2), -2, 2]
|
|
156
|
+
"""
|
|
157
|
+
cf = _leaf_complexity if complexity_function is None else complexity_function
|
|
158
|
+
if not callable(cf):
|
|
159
|
+
raise TypeError(
|
|
160
|
+
f"complexity_function must be callable, got {complexity_function!r}")
|
|
161
|
+
|
|
162
|
+
rg = range(1, _range_length(x) + 1) # rg = Range[x]
|
|
163
|
+
|
|
164
|
+
# basic1, the DynamicArray of the numbers found, kept without
|
|
165
|
+
# duplicates (DeleteDuplicates) and with their complexity, which is
|
|
166
|
+
# computed only once per distinct number generated
|
|
167
|
+
basic = {}
|
|
168
|
+
measured = {}
|
|
169
|
+
|
|
170
|
+
def append(curr):
|
|
171
|
+
# If[cf[curr] <= x, basic1["Append", curr], Break[]]
|
|
172
|
+
try:
|
|
173
|
+
complexity = measured[curr]
|
|
174
|
+
except KeyError:
|
|
175
|
+
complexity = measured[curr] = cf(curr)
|
|
176
|
+
if complexity <= x:
|
|
177
|
+
basic[curr] = complexity
|
|
178
|
+
return True
|
|
179
|
+
return False
|
|
180
|
+
|
|
181
|
+
for h in _HEADS_PLAIN_1:
|
|
182
|
+
for a in rg:
|
|
183
|
+
if not append(h(a)):
|
|
184
|
+
break
|
|
185
|
+
|
|
186
|
+
for h in _HEADS_PLAIN_2:
|
|
187
|
+
for a in rg:
|
|
188
|
+
for b in rg:
|
|
189
|
+
if not append(h(a, b)):
|
|
190
|
+
break
|
|
191
|
+
|
|
192
|
+
# headsSimp1, the square root: srg = Intersection[rg, rg^2] are the
|
|
193
|
+
# perfect squares and nrg = Complement[rg, srg] the other integers
|
|
194
|
+
srg = {a * a for a in rg}
|
|
195
|
+
nrg = [a for a in rg if a not in srg]
|
|
196
|
+
for a in nrg:
|
|
197
|
+
if not append(_sqrt(a)):
|
|
198
|
+
break
|
|
199
|
+
|
|
200
|
+
# headsSimp2, the quotient: srg = Intersection[rg, rg rg[[i]]] are
|
|
201
|
+
# the multiples of the denominator b and nrg the other integers
|
|
202
|
+
for b in rg:
|
|
203
|
+
nrg = [a for a in rg if a % b != 0]
|
|
204
|
+
for a in nrg:
|
|
205
|
+
if not append(_divide(a, b)):
|
|
206
|
+
break
|
|
207
|
+
|
|
208
|
+
# SortBy[cf] @ DeleteDuplicates @ Normal[basic1]
|
|
209
|
+
return sorted(basic, key=lambda e: (basic[e], _canonical_key(e)))
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: complexity-range
|
|
3
|
+
Version: 0.0.5
|
|
4
|
+
Summary: Generate ranges of numbers bounded and sorted by complexity
|
|
5
|
+
Author-email: Daniele Gregori <dangregori@gmail.com>
|
|
6
|
+
Maintainer-email: Daniele Gregori <dangregori@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/Daniele-Gregori/PyPI-packages/tree/main/packages/complexity-range
|
|
9
|
+
Project-URL: Repository, https://github.com/Daniele-Gregori/PyPI-packages/tree/main/packages/complexity-range
|
|
10
|
+
Project-URL: Changelog, https://github.com/Daniele-Gregori/PyPI-packages/blob/main/packages/complexity-range/CHANGELOG.md
|
|
11
|
+
Project-URL: Issues, https://github.com/Daniele-Gregori/PyPI-packages/issues
|
|
12
|
+
Keywords: complexity,range,complexity-range,leaf-complexity,numbers,rational,algebraic,square-root,closed-form,symbolic,sympy,mathematics,wolfram
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: leaf-complexity>=0.7.0
|
|
28
|
+
Requires-Dist: sympy>=1.8
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# complexity-range
|
|
34
|
+
|
|
35
|
+
[](https://badge.fury.io/py/complexity-range)
|
|
36
|
+
[](https://opensource.org/licenses/MIT)
|
|
37
|
+
|
|
38
|
+
Generate ranges of numbers bounded and sorted by complexity.
|
|
39
|
+
|
|
40
|
+
`complexity_range(x)` combines the positive integers up to `x` with one elementary operation (negation, reciprocal, square root, sum, difference, product or quotient), keeps the results of complexity up to `x` and sorts them by complexity. The default measure of complexity is [`leaf-complexity`](https://pypi.org/project/leaf-complexity/) minus 1.
|
|
41
|
+
|
|
42
|
+
This is an experimental early release, ported from a draft of the Wolfram Language function `ComplexityRange` by the same author. The interface and the results may change.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install complexity-range
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from complexity_range import complexity_range
|
|
54
|
+
|
|
55
|
+
complexity_range(6)
|
|
56
|
+
# [0, -1, 1, -2, 2, -3, 3, -4, 1/2, 4, -5, 1/3, 5, -6, 1/4, 2/3, 3/2, 6]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The results are [SymPy](https://www.sympy.org) numbers. The option `complexity_function` sets another measure, for instance the absolute value:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
complexity_range(3, complexity_function=lambda e: abs(float(e)))
|
|
63
|
+
# [0, 1/3, 1/2, 2/3, -1, 1, sqrt(2), 3/2, sqrt(3), -2, 2, -3, 3]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Each scan over the integers stops at the first result of complexity above `x`, so a square root within the bound can be missing, like `2*sqrt(2)` in `complexity_range(10)`.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
CHANGELOG.md
|
|
2
|
+
LICENSE
|
|
3
|
+
MANIFEST.in
|
|
4
|
+
README.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
src/complexity_range/__init__.py
|
|
7
|
+
src/complexity_range/core.py
|
|
8
|
+
src/complexity_range.egg-info/PKG-INFO
|
|
9
|
+
src/complexity_range.egg-info/SOURCES.txt
|
|
10
|
+
src/complexity_range.egg-info/dependency_links.txt
|
|
11
|
+
src/complexity_range.egg-info/requires.txt
|
|
12
|
+
src/complexity_range.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
complexity_range
|