boring-math.recursive-functions 1.0.0__tar.gz → 5.0.0__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.
Files changed (20) hide show
  1. boring_math_recursive_functions-5.0.0/PKG-INFO +47 -0
  2. boring_math_recursive_functions-5.0.0/README.md +23 -0
  3. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/pyproject.toml +50 -32
  4. boring_math_recursive_functions-5.0.0/src/boring_math/recursive_functions/__init__.py +59 -0
  5. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/src/boring_math/recursive_functions/ackermann.py +12 -12
  6. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/src/boring_math/recursive_functions/cli/__init__.py +12 -12
  7. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/src/boring_math/recursive_functions/cli/ackermann_cli.py +19 -11
  8. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/src/boring_math/recursive_functions/cli/fibonacci_cli.py +15 -6
  9. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/src/boring_math/recursive_functions/fibonacci.py +14 -13
  10. boring_math_recursive_functions-1.0.0/.gitignore +0 -7
  11. boring_math_recursive_functions-1.0.0/CHANGELOG.md +0 -41
  12. boring_math_recursive_functions-1.0.0/PKG-INFO +0 -56
  13. boring_math_recursive_functions-1.0.0/README.rst +0 -31
  14. boring_math_recursive_functions-1.0.0/src/boring_math/recursive_functions/__init__.py +0 -59
  15. boring_math_recursive_functions-1.0.0/tests/ackermann/test_ackermann_list.py +0 -50
  16. boring_math_recursive_functions-1.0.0/tests/fibonacci/test_fibonacci_float.py +0 -125
  17. boring_math_recursive_functions-1.0.0/tests/fibonacci/test_fibonacci_int.py +0 -87
  18. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/LICENSE +0 -0
  19. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/src/boring_math/recursive_functions/cli/py.typed +0 -0
  20. {boring_math_recursive_functions-1.0.0 → boring_math_recursive_functions-5.0.0}/src/boring_math/recursive_functions/py.typed +0 -0
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: boring-math-recursive-functions
3
+ Version: 5.0.0
4
+ Summary: Recursive functions package.
5
+ Keywords: ackermann,fibonacci,recursive,recursive functions
6
+ Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
7
+ Requires-Python: >=3.14
8
+ Description-Content-Type: text/markdown
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Framework :: Pytest
11
+ Classifier: Intended Audience :: Education
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Classifier: Typing :: Typed
17
+ License-File: LICENSE
18
+ Requires-Dist: pythonic-fp-iterables>=6.0.0,<7
19
+ Project-URL: Changelog, https://github.com/grscheller/boring-math-recursive-functions/blob/main/CHANGELOG.md
20
+ Project-URL: Documentation, https://grscheller.github.io/boring-math-recursive-functions
21
+ Project-URL: Homepage, https://grscheller.github.io/boring-math/
22
+ Project-URL: Source, https://github.com/grscheller/boring-math-recursive-functions
23
+
24
+ # Boring Math - Recursive Functions
25
+
26
+ Project is to explore different ways to efficiently implement recursion
27
+ in Python.
28
+
29
+ PyPI project
30
+ [boring-math-recursive-functions](https://pypi.org/project/boring-math-recursive-functions).
31
+ This pypi project is part of the
32
+ [boring math](https://grscheller.github.io/boring-math) projects.
33
+
34
+ ## Documentation
35
+
36
+ Documentation and other links for this project are hosted on
37
+ [GitHub Pages](https://grscheller.github.io/boring-math/projects/recursive_functions.html).
38
+
39
+ Functions defined using previously well defined values originating from
40
+ "base cases" are called "primitively recursive functions." Not all
41
+ computable functions are primitively recursive.
42
+
43
+ ## Copyright and License
44
+
45
+ Copyright (c) 2023-2026 Geoffrey R. Scheller. Licensed under the Apache
46
+ License, Version 2.0. See the LICENSE file for details.
47
+
@@ -0,0 +1,23 @@
1
+ # Boring Math - Recursive Functions
2
+
3
+ Project is to explore different ways to efficiently implement recursion
4
+ in Python.
5
+
6
+ PyPI project
7
+ [boring-math-recursive-functions](https://pypi.org/project/boring-math-recursive-functions).
8
+ This pypi project is part of the
9
+ [boring math](https://grscheller.github.io/boring-math) projects.
10
+
11
+ ## Documentation
12
+
13
+ Documentation and other links for this project are hosted on
14
+ [GitHub Pages](https://grscheller.github.io/boring-math/projects/recursive_functions.html).
15
+
16
+ Functions defined using previously well defined values originating from
17
+ "base cases" are called "primitively recursive functions." Not all
18
+ computable functions are primitively recursive.
19
+
20
+ ## Copyright and License
21
+
22
+ Copyright (c) 2023-2026 Geoffrey R. Scheller. Licensed under the Apache
23
+ License, Version 2.0. See the LICENSE file for details.
@@ -1,10 +1,16 @@
1
+ [build-system]
2
+ requires = ["flit_core>=3.12,<4"]
3
+ build-backend = "flit_core.buildapi"
4
+
1
5
  [project]
2
6
  name = "boring-math-recursive-functions"
3
- version = "1.0.0"
4
- readme = "README.rst"
5
- requires-python = ">=3.13"
6
- license = { file = "LICENSE" }
7
- authors = [{ name = "Geoffrey R. Scheller", email = "geoffrey@scheller.com" }]
7
+ version = "5.0.0"
8
+ description = "Recursive functions package."
9
+ readme = "README.md"
10
+ requires-python = ">=3.14" # floor: PEP 649/749 deferred annotations — class-level self-reference NameErrors on <3.14
11
+ authors = [
12
+ { name = "Geoffrey R. Scheller", email = "geoffrey@scheller.com" },
13
+ ]
8
14
  keywords = [
9
15
  "ackermann",
10
16
  "fibonacci",
@@ -17,67 +23,79 @@ classifiers = [
17
23
  "Intended Audience :: Education",
18
24
  "License :: OSI Approved :: Apache Software License",
19
25
  "Operating System :: OS Independent",
20
- "Programming Language :: Python :: 3.13",
26
+ "Programming Language :: Python :: 3.14",
27
+ "Programming Language :: Python :: 3.15",
21
28
  "Typing :: Typed",
22
29
  ]
23
30
  dependencies = [
24
- "pythonic-fp-iterables>=5.1.2",
31
+ "pythonic-fp-iterables>=6.0.0,<7",
25
32
  ]
26
- dynamic = ["description"]
27
-
28
- [project.urls]
29
- Changelog = "https://github.com/grscheller/boring-math-recursive-functions/blob/main/CHANGELOG.md"
30
- Documentation = "https://grscheller.github.io/boring-math/recursive-functions/development/build/html"
31
- Homepage = "https://grscheller.github.io/boring-math/homepage/build/html"
32
- Source = "https://github.com/grscheller/boring-math-recursive-functions"
33
33
 
34
34
  [project.scripts]
35
35
  ackermann_list = "boring_math.recursive_functions.cli.ackermann_cli:ackermann_list_cli"
36
36
  fibonacci = "boring_math.recursive_functions.cli.fibonacci_cli:fibonacci"
37
37
 
38
- [project.optional-dependencies]
38
+ [project.urls]
39
+ Changelog = "https://github.com/grscheller/boring-math-recursive-functions/blob/main/CHANGELOG.md"
40
+ Documentation = "https://grscheller.github.io/boring-math-recursive-functions"
41
+ Homepage = "https://grscheller.github.io/boring-math/"
42
+ Source = "https://github.com/grscheller/boring-math-recursive-functions"
43
+
44
+ [dependency-groups]
45
+ docs = [
46
+ "furo>=2025.12.19",
47
+ "sphinx>=9.1",
48
+ ]
39
49
  test = [
40
50
  "pytest>=8.4.1",
41
51
  ]
42
52
 
43
- [build-system]
44
- requires = ["flit_core>=3.12,<4"]
45
- build-backend = "flit_core.buildapi"
46
-
47
53
  [tool.flit.module]
48
54
  name = "boring_math.recursive_functions"
49
55
 
56
+ [tool.flit.sdist]
57
+ exclude = [
58
+ "docs/",
59
+ "tests/",
60
+ "**/.mypy_cache/",
61
+ "**/.ruff_cache/",
62
+ "**/.pytest_cache/",
63
+ "**/__pycache__/",
64
+ "**/.dmypy.json",
65
+ ]
66
+
50
67
  [tool.mypy]
51
- enable_incomplete_feature = "NewGenericSyntax"
52
68
  explicit_package_bases = true
53
- implicit_reexport = false
54
69
  local_partial_types = true
55
70
  namespace_packages = true
71
+ strict = true
56
72
  warn_redundant_casts = true
57
73
  warn_return_any = true
58
74
  warn_unused_configs = true
59
75
 
60
- [tool.pylsp-mypy]
61
- enabled = true
62
- live-mode = true
63
- dmypy = false
64
- strict = true
65
- report_progress = true
76
+ [[tool.mypy.overrides]]
77
+ module = ["tests.*"]
78
+ strict_equality = false
66
79
 
67
- [tool.pytest.ini_options]
68
- addopts = "-ra"
80
+ [tool.pytest]
81
+ addopts = ["-ra"]
69
82
  consider_namespace_packages = true
70
83
  testpaths = ["tests/"]
71
84
 
72
85
  [tool.ruff]
73
- target-version = "py313"
86
+ target-version = "py314"
87
+
88
+ [tool.ruff.lint]
89
+ ignore = ["RUF022", "E741"]
74
90
 
75
91
  [tool.ruff.lint.flake8-quotes]
76
92
  docstring-quotes = "double"
77
93
 
78
94
  [tool.ruff.lint.per-file-ignores]
79
- "tests/*" = ["C901"]
80
- "**/*.py" = ["E741"]
95
+ "tests/**/*.py" = [
96
+ "E731",
97
+ "C901",
98
+ ]
81
99
 
82
100
  [tool.ruff.format]
83
101
  quote-style = "single"
@@ -0,0 +1,59 @@
1
+ # Copyright 2016-2026 Geoffrey R. Scheller
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ Recursive Functions
17
+ -------------------
18
+
19
+ Project to explore efficient ways to implement recursive functions. This
20
+ project is more about exploring how to implement recursive functions
21
+ efficiently than exposing tools to do such.
22
+
23
+ .. admonition:: Ackermann's Function
24
+
25
+ Ackermann's function is an example of a function that is computable
26
+ but not primitively recursive. It quickly becomes computationally
27
+ intractable for relatively small values of m.
28
+
29
+ Ackermann function is defined recursively by
30
+
31
+ ``ackermann(0,n) = n+1`` for ``n >= 0``
32
+
33
+ ``ackermann(m,0) = ackermann(m-1,1)`` for ``m >= 0``
34
+
35
+ ``ackermann(m,n) = ackermann(m-1, ackermann(m,n-1))`` for ``m, n > 0``
36
+
37
+ .. admonition:: Fibonacci Sequences
38
+
39
+ The Fibonacci sequence is usually taught in grade school as the
40
+ first recursive function that is not either an arithmetic or geometric
41
+ progression.
42
+
43
+ The Fibonacci sequence is traditionally defined as
44
+
45
+ ``f₁ = 1``
46
+
47
+ ``f₂ = 1``
48
+
49
+ ``fₙ₊₂ = fₙ₊₁ + fₙ``
50
+
51
+ Actually, the Fibonacci sequence can be extended in both directions.
52
+
53
+ ``..., 13, -8, 5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 5, 6, 13, ...``
54
+
55
+ """
56
+
57
+ __author__ = 'Geoffrey R. Scheller'
58
+ __copyright__ = 'Copyright (c) 2016-2026 Geoffrey R. Scheller'
59
+ __license__ = 'Apache License 2.0'
@@ -13,28 +13,28 @@
13
13
  # limitations under the License.
14
14
 
15
15
  """
16
- Ackermann examples
17
- ==================
16
+ .. admonition:: Ackermann examples
18
17
 
19
- Example implementations for Ackermann's function.
18
+ Example implementations for Ackermann's function.
20
19
 
21
20
  """
22
21
  __all__ = ['ackermann_list']
23
22
 
24
23
 
25
24
  def ackermann_list(m: int, n: int) -> int:
26
- """Ackermann's Function.
25
+ """
26
+ .. admonition:: Ackermann's Function
27
27
 
28
- .. note::
28
+ :param m: First argument to Ackermann's function.
29
+ :param n: Second argument to Ackermann's function.
30
+ :returns: A very hard to calculate useless value.
29
31
 
30
- This implementation models the recursion with a Python list
31
- instead of Python's "call stack". It then evaluates the
32
- innermost ackermann function first. To naively use call stack
33
- recursion would result in the loss of stack safety.
32
+ .. note::
34
33
 
35
- :param m: First argument to Ackermann's function.
36
- :param n: Second argument to Ackermann's function.
37
- :returns: A very hard to calculate useless value.
34
+ This implementation models the recursion with a Python list
35
+ instead of Python's call stack. It then evaluates the
36
+ innermost ackermann function first. To naively use call
37
+ stack recursion would quickly result in a stack overflow.
38
38
 
39
39
  """
40
40
  acker = [m, n]
@@ -13,23 +13,23 @@
13
13
  # limitations under the License.
14
14
 
15
15
  """
16
- Entry points for automatically generated CLI scripts
17
- ----------------------------------------------------
16
+ .. admonition:: CGI script entry points
18
17
 
19
- The CGI package automatically generates Python scripts in an OS independent way
20
- using the packaging build backend. This is configured by the `[project.scripts]`
21
- section in the project's pyproject.toml file.
18
+ Automatically generate Python scripts in an OS independent way
19
+ using the packaging build's backend, *flit* in this case. This
20
+ is configured by the [project.scripts] section in the project's
21
+ pyproject.toml file.
22
22
 
23
- Example applications
24
- --------------------
23
+ **Example applications:**
25
24
 
26
- - Ackermann's function
25
+ .. admonition:: Ackermann's function
27
26
 
28
- - **ackermann_list:** Calculate values for a computable but not simple
29
- recursive function.
27
+ - **ackermann_list:** Calculate values for a computable
28
+ but not simple recursive function.
30
29
 
31
- - Fibonacci sequences
30
+ .. admonition:: Fibonacci sequences
32
31
 
33
- - **fibonacci:** Generate Fibonacci sequences both forward and backward.
32
+ - **fibonacci:** Generate Fibonacci sequences both forwards
33
+ and backwards.
34
34
 
35
35
  """
@@ -13,20 +13,21 @@
13
13
  # limitations under the License.
14
14
 
15
15
  """
16
- Programs to evaluate Ackermann's function.
16
+ .. admonition:: Programs to evaluate Ackermann's function.
17
17
 
18
- .. note::
18
+ .. note::
19
19
 
20
- The version of the Ackermann's function being used is defined recursively by
20
+ The version of the Ackermann's function being used is defined
21
+ recursively by
21
22
 
22
- - ``ackermann(0,n) = n+1 for n >= 0``
23
- - ``ackermann(m,0) = ackermann(m-1,1) for m >= 0``
24
- - ``ackermann(m,n) = ackermann(m-1, ackermann(m, n-1)) for m,n > 0``
23
+ - ``ackermann(0,n) = n+1 for n >= 0``
24
+ - ``ackermann(m,0) = ackermann(m-1,1) for m >= 0``
25
+ - ``ackermann(m,n) = ackermann(m-1, ackermann(m, n-1)) for m,n > 0``
25
26
 
26
- Ackermann's function is an example of a computable but not primitively
27
- recursive function.
27
+ Ackermann's function is an example of a computable but not primitively
28
+ recursive function.
28
29
 
29
- - **ackermann_list:** Computes Ackermann's function by simulating recursion with a list.
30
+ - **ackermann_list:** Computes Ackermann's function by simulating recursion with a list.
30
31
 
31
32
  """
32
33
 
@@ -37,9 +38,16 @@ from boring_math.recursive_functions.ackermann import ackermann_list
37
38
  def ackermann_list_cli() -> None:
38
39
  """Evaluate Ackermann's function simulating recursion with a Python list.
39
40
 
40
- Usage: ``ackermann_list m n``
41
+ .. admonition:: Usage
41
42
 
42
- Becomes numerically intractable after m=4 n=1.
43
+ .. code-block:: console
44
+
45
+ $ ackermann_list m n
46
+
47
+ .. note::
48
+
49
+ Ackermann's function becomes numerically intractable
50
+ after m=4 n=1.
43
51
 
44
52
  """
45
53
  args = sys.argv[1:]
@@ -13,10 +13,9 @@
13
13
  # limitations under the License.
14
14
 
15
15
  """
16
- Programs involving Fibonacci sequences. These are installed into the
17
- Python virtual environment.
16
+ .. admonition:: Programs involving Fibonacci sequences.
18
17
 
19
- - **fibonacci:** Prints generated Fibonacci sequences to stdout.
18
+ - **fibonacci:** Prints generated Fibonacci sequences to stdout.
20
19
 
21
20
  """
22
21
 
@@ -29,12 +28,22 @@ from pythonic_fp.iterables.drop_take import take
29
28
 
30
29
  def fibonacci() -> None:
31
30
  """
32
- Calculate Fibonacci sequences both forward ans backwards.
31
+ .. admonition:: Fibonacci
33
32
 
34
- Usage: ``fibonacci [-r] f1 f2 n``
33
+ Calculate Fibonacci sequences both forward ans backwards.
35
34
 
36
- - gets installed into the virtual environment
35
+ .. admonition:: Usage
37
36
 
37
+ .. code-block:: console
38
+
39
+ $ fibonacci [-r] f1 f2 n
40
+
41
+ where
42
+
43
+ - **f1**: first number in sequence
44
+ - **f2**: second number in sequence
45
+ - **n**: number of terms to output
46
+ - **-r** reverse direction of sequence
38
47
 
39
48
  """
40
49
  nargs = len(args := sys.argv[1:])
@@ -1,4 +1,4 @@
1
- # Copyright 2016-2025 Geoffrey R. Scheller
1
+ # Copyright 2016-2026 Geoffrey R. Scheller
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -13,10 +13,9 @@
13
13
  # limitations under the License.
14
14
 
15
15
  """
16
- Fibonacci examples
17
- ==================
16
+ .. admonition:: Fibonacci sequence
18
17
 
19
- Example implementations for Fibonacci functions.
18
+ Example implementation for Fibonacci sequences.
20
19
 
21
20
  """
22
21
 
@@ -45,20 +44,22 @@ def orderable_generator[T: OrderedRing](
45
44
  fib0: T, fib1: T, forward: bool = True
46
45
  ) -> Iterator[T]:
47
46
  """
48
- Generate a Fibonacci or reverse Fibonacci sequence.
47
+ .. admonition:: Generate a Fibonacci sequence
49
48
 
50
- - ``fib0=0, fib1=1`` generates
49
+ :param fib0: Zeroth numeric element of the sequence.
50
+ :param fib1: Next numeric element of the sequence.
51
+ :param forward: Generate sequence in forward or reverse order.
52
+ :yields: An iterator iterating over a Fibonacci sequence.
51
53
 
52
- - the sequence ``0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ...``
54
+ .. note::
53
55
 
54
- - ``fib0=5, fib1=3, forward = False`` generates
56
+ - ``fibonacci.orderable_generator(fib0=0, fib1=1)`` generates
55
57
 
56
- - the sequence ``5, 3, 2, 1, 1, 0, 1, -1, 2, -3, 5, -8, ...``
58
+ - the sequence ``0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ...``
57
59
 
58
- :param fib0: Zeroth numeric element of the sequence.
59
- :param fib1: Next numeric element of the sequence.
60
- :param reverse: Generate sequence in reverse order.
61
- :returns: An iterator iterating over a Fibonacci sequence.
60
+ - ``fibonacci.orderable_generator(fib0=5, fib1=3, forward = False)`` generates
61
+
62
+ - the sequence ``5, 3, 2, 1, 1, 0, 1, -1, 2, -3, 5, -8, ...``
62
63
 
63
64
  """
64
65
  if forward:
@@ -1,7 +0,0 @@
1
- # Minimal version - only add to when necessary
2
- **/__pycache__/
3
- dist/
4
- **/.dmypy.json
5
- **/.mypy_cache/
6
- **/.pytest_cache/
7
- **/.ruff_cache
@@ -1,41 +0,0 @@
1
- # CHANGELOG
2
-
3
- PyPI `boring-math.recursive-functions` project.
4
-
5
- ## Semantic Versioning
6
-
7
- Strict 3 digit semantic versioning.
8
-
9
- - **MAJOR** version incremented for incompatible API changes
10
- - **MINOR** version incremented for backward compatible added functionality
11
- - **PATCH** version incremented for backward compatible bug fixes
12
-
13
- See [Semantic Versioning 2.0.0](https://semver.org).
14
-
15
- ## Releases and other important milestones
16
-
17
- ### Version 1.0.0 - PyPI release date 2025-10-11
18
-
19
- Completely rewrote Fibonacci library and created cli implementation.
20
-
21
- Docs now use Sphinx.
22
-
23
- ### Version 0.8.1 - PyPI release date 2025-08-04
24
-
25
- Infrastructure updated, now similar to Pythonic FP projects.
26
-
27
- ### Version 0.7.1 - PyPI release date 2025-07-31
28
-
29
- New PyPI name is `boring-math-recursive-functions
30
-
31
- ### Version 0.6.1 - PyPI release date 2025-07-14
32
-
33
- First (correct) version to use boring-math.recursive-functions
34
-
35
- - fixed munged CHANGELOG and Documentation links.
36
-
37
- ### Version 0.5.0 - PyPI release date 2025-01-??
38
-
39
- - Part of the Boring Math projects
40
- - PyPI bm.recursive-functions
41
- - Migrated code from grscheller/boring-math repo
@@ -1,56 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: boring-math-recursive-functions
3
- Version: 1.0.0
4
- Summary: Recursive Functions Package
5
- Keywords: ackermann,fibonacci,recursive,recursive functions
6
- Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
7
- Requires-Python: >=3.13
8
- Description-Content-Type: text/x-rst
9
- Classifier: Development Status :: 3 - Alpha
10
- Classifier: Framework :: Pytest
11
- Classifier: Intended Audience :: Education
12
- Classifier: License :: OSI Approved :: Apache Software License
13
- Classifier: Operating System :: OS Independent
14
- Classifier: Programming Language :: Python :: 3.13
15
- Classifier: Typing :: Typed
16
- License-File: LICENSE
17
- Requires-Dist: pythonic-fp-iterables>=5.1.2
18
- Requires-Dist: pytest>=8.4.1 ; extra == "test"
19
- Project-URL: Changelog, https://github.com/grscheller/boring-math-recursive-functions/blob/main/CHANGELOG.md
20
- Project-URL: Documentation, https://grscheller.github.io/boring-math/recursive-functions/development/build/html
21
- Project-URL: Homepage, https://grscheller.github.io/boring-math/homepage/build/html
22
- Project-URL: Source, https://github.com/grscheller/boring-math-recursive-functions
23
- Provides-Extra: test
24
-
25
- Boring Math - Recursive Functions
26
- =================================
27
-
28
- PyPI project
29
- `boring-math-recursive-functions
30
- <https://pypi.org/project/boring-math-recursive-functions>`_.
31
-
32
- The purpose of this project is to explore different ways to efficiently
33
- implement recursion in Python.
34
-
35
- Computable recursive functions can be defined with previously defined or even
36
- not yet defined values. Functions defined using previously well defined values
37
- having "base cases" are called "primitively recursive functions." Not all
38
- computable functions are primitively recursive.
39
-
40
- This pypi project is part of the
41
- `boring math
42
- <https://grscheller.github.io/boring-math>`_ projects.
43
-
44
- Documentation
45
- -------------
46
-
47
- Documentation for this project is hosted on
48
- `GitHub Pages
49
- <https://grscheller.github.io/boring-math/recursive-functions/development/build/html>`_.
50
-
51
- Copyright and License
52
- ---------------------
53
-
54
- Copyright (c) 2023-2025 Geoffrey R. Scheller. Licensed under the Apache
55
- License, Version 2.0. See the LICENSE file for details.
56
-
@@ -1,31 +0,0 @@
1
- Boring Math - Recursive Functions
2
- =================================
3
-
4
- PyPI project
5
- `boring-math-recursive-functions
6
- <https://pypi.org/project/boring-math-recursive-functions>`_.
7
-
8
- The purpose of this project is to explore different ways to efficiently
9
- implement recursion in Python.
10
-
11
- Computable recursive functions can be defined with previously defined or even
12
- not yet defined values. Functions defined using previously well defined values
13
- having "base cases" are called "primitively recursive functions." Not all
14
- computable functions are primitively recursive.
15
-
16
- This pypi project is part of the
17
- `boring math
18
- <https://grscheller.github.io/boring-math>`_ projects.
19
-
20
- Documentation
21
- -------------
22
-
23
- Documentation for this project is hosted on
24
- `GitHub Pages
25
- <https://grscheller.github.io/boring-math/recursive-functions/development/build/html>`_.
26
-
27
- Copyright and License
28
- ---------------------
29
-
30
- Copyright (c) 2023-2025 Geoffrey R. Scheller. Licensed under the Apache
31
- License, Version 2.0. See the LICENSE file for details.
@@ -1,59 +0,0 @@
1
- # Copyright 2016-2025 Geoffrey R. Scheller
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- """
16
- Recursive Functions Package
17
- ===========================
18
-
19
- Package to explore efficient ways to implement recursive functions.
20
-
21
- Ackermann function
22
- ------------------
23
-
24
- Ackermann's function is an example of a function that is computable
25
- but not primitively recursive. It quickly becomes computationally
26
- intractable for relatively small values of m.
27
-
28
- Ackermann function is defined recursively by
29
-
30
- ``ackermann(0,n) = n+1`` for ``n >= 0``
31
-
32
- ``ackermann(m,0) = ackermann(m-1,1)`` for ``m >= 0``
33
-
34
- ``ackermann(m,n) = ackermann(m-1, ackermann(m,n-1))`` for ``m, n > 0``
35
-
36
- Fibonacci sequences
37
- -------------------
38
-
39
- The Fibonacci sequence is usually taught in grade school as the
40
- first recursive function that is not either an arithmetic or geometric
41
- progression.
42
-
43
- The Fibonacci sequence is traditionally defined as
44
-
45
- ``f₁ = 1``
46
-
47
- ``f₂ = 1``
48
-
49
- ``fₙ₊₂ = fₙ₊₁ + fₙ``
50
-
51
- Actually, the Fibonacci sequence can be extended in both directions.
52
-
53
- ``..., 13, -8, 5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 5, 6, 13, ...``
54
-
55
- """
56
-
57
- __author__ = 'Geoffrey R. Scheller'
58
- __copyright__ = 'Copyright (c) 2016-2025 Geoffrey R. Scheller'
59
- __license__ = 'Apache License 2.0'
@@ -1,50 +0,0 @@
1
- # Copyright 2023-2024 Geoffrey R. Scheller
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from boring_math.recursive_functions.ackermann import ackermann_list
16
-
17
- class Test_ackerman:
18
- def test_ack_list(self) -> None:
19
- assert ackermann_list(0, 0) == 1
20
- assert ackermann_list(0, 5) == 6
21
- assert ackermann_list(1, 0) == 2
22
- assert ackermann_list(1, 1) == 3
23
- assert ackermann_list(1, 2) == 4
24
- assert ackermann_list(1, 3) == 5
25
- assert ackermann_list(1, 4) == 6
26
- assert ackermann_list(1, 5) == 7
27
- assert ackermann_list(1, 6) == 8
28
- assert ackermann_list(1, 7) == 9
29
- assert ackermann_list(1, 8) == 10
30
- assert ackermann_list(1, 27) == 29 # inferring from patterns
31
- assert ackermann_list(2, 0) == 3
32
- assert ackermann_list(2, 1) == 5
33
- assert ackermann_list(2, 2) == 7
34
- assert ackermann_list(2, 3) == 9
35
- assert ackermann_list(2, 4) == 11
36
- assert ackermann_list(2, 5) == 13
37
- assert ackermann_list(2, 6) == 15
38
- assert ackermann_list(2, 13) == 29 # inferring from patterns
39
- assert ackermann_list(3, 0) == 5
40
- assert ackermann_list(3, 1) == 13
41
- assert ackermann_list(3, 2) == 29 # inferring from patterns
42
- assert ackermann_list(3, 3) == 61 # inferring from patterns
43
- assert ackermann_list(3, 4) == 125
44
- assert ackermann_list(3, 8) == 2045 # not hand computed
45
- assert ackermann_list(4, 0) == 13
46
- # assert ackermann(4, 1) == 65533 # not hand computed!
47
- assert ackermann_list(0, 21) == 22
48
- assert ackermann_list(4, 0) == ackermann_list(3, 1)
49
- assert ackermann_list(3, 7) == ackermann_list(2, ackermann_list(3, 6))
50
-
@@ -1,125 +0,0 @@
1
- # Copyright 2023-2024 Geoffrey R. Scheller
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from collections.abc import Iterator, Callable
16
- from math import sqrt
17
- from typing import cast
18
- from boring_math.recursive_functions.fibonacci import orderable_generator
19
-
20
- fib_gen = cast(
21
- Callable[[float, float], Iterator[float]],
22
- lambda n, m: orderable_generator(n, m, forward=True),
23
- )
24
-
25
- fib_rev_gen = cast(
26
- Callable[[float, float], Iterator[float]],
27
- lambda n, m: orderable_generator(n, m, forward=False),
28
- )
29
-
30
-
31
- class TestFibonacciFloat:
32
- def test_int(self) -> None:
33
- float_fibs: list[float] = []
34
- fibs = fib_gen(0.0, 1.0)
35
- fib = next(fibs)
36
- while fib < 60.0:
37
- float_fibs.append(fib)
38
- fib = next(fibs)
39
- assert float_fibs == [0.0, 1.0, 1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0, 34.0, 55.0]
40
-
41
- float_fibs = []
42
- fibs = fib_gen(0.25, 0.5)
43
- fib = next(fibs)
44
- while fib < 25.0:
45
- float_fibs.append(fib)
46
- fib = next(fibs)
47
- exact_float_fibs = [0.25, 0.5, 0.75, 1.25, 2.0, 3.25, 5.25, 8.5, 13.75, 22.25]
48
- for nn in range(10):
49
- assert abs(float_fibs[nn] - exact_float_fibs[nn]) < 0.000001
50
-
51
- float_fibs = []
52
- fibs = fib_rev_gen(8.5, 5.25)
53
- fib = next(fibs)
54
- while fib > 0.0000025:
55
- float_fibs.append(fib)
56
- fib = next(fibs)
57
- exact_float_fibs = [8.5, 5.25, 3.25, 2.0, 1.25, 0.75, 0.5, 0.25, 0.25]
58
- assert len(float_fibs) == 9
59
- for nn in range(9):
60
- assert abs(float_fibs[nn] - exact_float_fibs[nn]) < 0.000001
61
-
62
- class TestFibonacciRatio:
63
- def test_golden_ratio_1(self) -> None:
64
- phi = (1 + sqrt(5))/2
65
-
66
- fibs = fib_gen(1.0, 1.0)
67
-
68
- loops, ratio, fib_numerator = 0, -1.0, next(fibs)
69
- while loops < 100:
70
- loops += 1
71
- fib_denominator, fib_numerator = fib_numerator, next(fibs)
72
- ratio = fib_numerator / fib_denominator
73
- if abs(ratio - phi) < 0.0000025:
74
- break
75
-
76
- err = abs(ratio - phi)
77
- assert err < 0.0000025
78
-
79
- assert loops < 100
80
- assert loops < 50
81
- assert loops < 25
82
- assert loops < 20
83
-
84
- def test_golden_ratio_2(self) -> None:
85
- phi = (1 + sqrt(5))/2
86
-
87
- fibs = fib_gen(-182.413, 142.1215)
88
-
89
- loops, ratio, fib_numerator = 0, -1.0, next(fibs)
90
- while loops < 100:
91
- loops += 1
92
- fib_denominator, fib_numerator = fib_numerator, next(fibs)
93
- ratio = fib_numerator / fib_denominator
94
- if abs(ratio - phi) < 0.0000025:
95
- break
96
-
97
- err = abs(ratio - phi)
98
- assert err < 0.0000025
99
-
100
- assert loops < 100
101
- assert loops < 50
102
- assert loops < 25
103
- assert loops < 20
104
-
105
- def test_golden_ratio_3(self) -> None:
106
- phi = (1 + sqrt(5))/2
107
- neg_inv_phi = -1.0/phi
108
-
109
- fibs = fib_rev_gen(1.2015, 0.8203)
110
-
111
- loops, ratio, fib_denominator = 0, -1.0, next(fibs)
112
- while loops < 100:
113
- loops += 1
114
- fib_numerator, fib_denominator = fib_denominator, next(fibs)
115
- ratio = fib_numerator / fib_denominator
116
- if abs(ratio - neg_inv_phi) < 0.0000025:
117
- break
118
-
119
- err = abs(ratio - neg_inv_phi)
120
- assert err < 0.0000025
121
-
122
- assert loops < 100
123
- assert loops < 50
124
- assert loops < 25
125
- assert loops < 20
@@ -1,87 +0,0 @@
1
- # Copyright 2023-2024 Geoffrey R. Scheller
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from collections.abc import Callable, Iterator
16
- from typing import cast
17
- from boring_math.recursive_functions.fibonacci import orderable_generator
18
-
19
- fib_gen = cast(
20
- Callable[[int, int], Iterator[int]],
21
- lambda n, m: orderable_generator(n, m, forward=True),
22
- )
23
-
24
- fib_rev_gen = cast(
25
- Callable[[int, int], Iterator[int]],
26
- lambda n, m: orderable_generator(n, m, forward=False),
27
- )
28
-
29
-
30
- class Test_fibonacci_int:
31
- def test_int(self) -> None:
32
- int_fibs: list[int] = []
33
- fibs = fib_gen(0, 1)
34
- fib = next(fibs)
35
- while fib < 60:
36
- int_fibs.append(fib)
37
- fib = next(fibs)
38
- assert int_fibs == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
39
-
40
- int_fibs = []
41
- fib0 = 1
42
- fib1 = 1
43
- fibs = fib_gen(fib0, fib1)
44
- fib = next(fibs)
45
- while fib < 90:
46
- int_fibs.append(fib)
47
- fib = next(fibs)
48
- assert int_fibs == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
49
-
50
- int_fibs = []
51
- fib0 = 1
52
- fib1 = 1
53
- fibs = fib_rev_gen(fib0, fib1)
54
- for _ in range(11):
55
- fib = next(fibs)
56
- int_fibs.append(fib)
57
- assert int_fibs == [1, 1, 0, 1, -1, 2, -3, 5, -8, 13, -21]
58
-
59
- int_fibs = []
60
- fibs = fib_rev_gen(1, -1)
61
- for _ in range(10):
62
- fib = next(fibs)
63
- int_fibs.append(fib)
64
- assert int_fibs == [1, -1, 2, -3, 5, -8, 13, -21, 34, -55]
65
-
66
- int_fibs = []
67
- fibs = fib_gen(5, 3)
68
- for _ in range(9):
69
- fib = next(fibs)
70
- int_fibs.append(fib)
71
- assert int_fibs == [5, 3, 8, 11, 19, 30, 49, 79, 128]
72
-
73
- int_fibs = []
74
- fibs = fib_gen(-21, 13)
75
- fib = next(fibs)
76
- while fib < 15:
77
- int_fibs.append(fib)
78
- fib = next(fibs)
79
- assert int_fibs == [-21, 13, -8, 5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 5, 8, 13]
80
-
81
- int_fibs = []
82
- fibs = fib_gen(20, -14)
83
- fib = next(fibs)
84
- while fib > -35:
85
- int_fibs.append(fib)
86
- fib = next(fibs)
87
- assert int_fibs == [20, -14, 6, -8, -2, -10, -12, -22, -34]