Skip to main content

Recursive Functions Package

Project description

Boring Math Library - Recursive functions

The purpose of this project is to explore different ways to efficiently implement recursive functions in Python.

Repos and Documentation

Repositories

Detailed documentation

Overview

This project is part of the Boring Math boring-math namespace project.

Recursive functions

Computable recursive functions can be defined with previously defined or not yet defined values. Functions defined using previously defined values having "base cases" are called "primitively recursive functions." Not all computable functions are primitively recursive.

Ackermann's Function

  • Function ackermann_list(m: int, n: int) -> int
    • is a total computable function that is not primitive recursive
    • becomes numerically intractable after m=4
    • see CLI section below for a mathematical definition

Fibonacci Sequences

  • Function fibonacci(f0: int=0, f1: int=1) -> Iterator[int]

    • returns a Fibonacci sequence iterator where
      • f(0) = f0 and f(1) = f1
      • f(n) = f(n-1) + f(n-2)
    • yield defaults to 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
  • Function rev_fibonacci(f0: int=0, f1: int=1) -> Iterator[int]

    • returns a Reverse Fibonacci sequence iterator where
      • rf(0) = f0 and rf(1) = f1
      • rf(n) = rf(n-1) - rf(n-2)
        • rf(0) = fib(-1) = 1
        • rf(1) = fib(-2) = -1
        • rf(2) = fib(-3) = 2
        • rf(3) = fib(-4) = -3
        • rf(4) = fib(-5) = 5
    • yield defaults to 1, -1, 2, -3, 5, -8, 13, -21, ...

CLI Applications

Implemented in an OS and package build tool independent way via the project.scripts section of pyproject.toml.

Ackermann CLI programs

Ackermann, a student of Hilbert, discovered early examples of totally computable functions that are not primitively recursive.

A fairly standard definition of the Ackermann function is recursively defined for m,n >= 0 by

    ackermann(0,n) = n+1
    ackermann(m,0) = ackermann(m-1,1)
    ackermann(m,n) = ackermann(m-1, ackermann(m, n-1))

CLI program ackermann_list

  • Given two non-negative integers, evaluates Ackermann's function
  • Implements the recursion via a Python array
  • Usage: ackerman_list m n

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boring_math_recursive_functions-0.7.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boring_math_recursive_functions-0.7.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file boring_math_recursive_functions-0.7.1.tar.gz.

File metadata

File hashes

Hashes for boring_math_recursive_functions-0.7.1.tar.gz
Algorithm Hash digest
SHA256 85733652317d1876b17409feec1b177e72535cbe1ed55549193fcc1ecfe23b9c
MD5 671c7722a81abebdd4e1e4b4c2f93210
BLAKE2b-256 814d7b64922155319f0dbd05321ccc3d1b75f93277abbe2f3488833b48eba318

See more details on using hashes here.

File details

Details for the file boring_math_recursive_functions-0.7.1-py3-none-any.whl.

File metadata

File hashes

Hashes for boring_math_recursive_functions-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7158dba8f7803e1edc07a366e5b920beb095e6e974e74729409113104956297
MD5 2fc4b214fc4c2d22542e0a7052409910
BLAKE2b-256 a4544435bfa1b7f15ff05a575bc8bd0b85720d236ac43623f0140c4dbf77c87e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page