Git Product home page Git Product logo

python-hyperoperators's Introduction

Hyperoperators

Build Status Coverage Status PyPI version

hyperop is a small library for representing really, really, ridiculously large numbers in pure python. It does so using hyperoperations.

  • Hyperoperation 0, H0 is the successor function, H0(None, 4) = 5
  • H1 is addition, H1(2,4) = 2 + (1+1+1+1) = 6
  • H2 is multiplication (repeated addition), H2(2,4) = 2+2+2+2 = 8
  • H3 is exponentiation (repeated multiplication), H3(2,4) = 2*2*2*2 = 16
  • H4 is tetration (repeated exponentiation) H4(2,4) = 2^(2^(2^(2))) = 65536
  • ...
  • Hyperoperation n is repeated Hyperoperation (n-1)

Fundamentally, hyperop works recursively by applying a fold-right operation:

H[n](x,y) = reduce(lambda x,y: H[n-1](y,x), [a,]*b)

Installation

pip install hyperop

To install the latest version use:

pip install git+https://github.com/thoppe/python-hyperoperators

Examples

from hyperop import hyperop

H1 = hyperop(1)
print(H1(2,3), H1(3,2), H1(5,4))
# >> 5, 5, 9

H3 = hyperop(3)
print(H3(2,3), H3(3,2), H3(5,4))
# >> 8, 9, 625

from math import log
H = hyperop(4)
print(H(2,5))
>>> 200352993040684646497....45587895905719156736

print(log(log(log(log(H(2,5),2.0),2.0),2.0),2.0) == 2)
>>> True  

Approximate infinite tetration. Show that sqrt(2)^sqrt(2)^... where the tower continues an infinite amount of times is 2.

H4 = hyperop(4)
print(H4(2**0.5, 200))
# >> 2.0

Calculate the incomprehensibly large, but finite Graham's number:

def GrahamsNumber():
    # This may take awhile...
    g = 4
    for n in range(1,64+1):
        g = hyperop(g+2)(3,3)
    return g

Plot the phase angle on the complex plane over tetrating four times H4(z,4)

from hyperop import hyperop
import mpmath

H = hyperop(4)
f = lambda z: H(z,4)
mpmath.cplot(f, verbose=True, points=100000)

Complex tetration plot

Bounded hyperoperators

Sometimes, especially in the case of small complex numbers, you only care about numbers that stay bounded during the calculation. That is, you'd only like to keep the result for some bound z such that H[n](a,b) <= z. The class bounded_hyperop does just that:

from hyperop import bounded_hyperop
Hb = bounded_hyperop(4, bound=1000)
print(Hb(2,3), Hb(2,4))
# >> 16 inf

Caveats

Higher order hyperoperations (from tetration and above) are not associative, thus tetration H4(2,4) = 2^(2^(2^(2))) = 65536 is not H4(2,4) != 2^(2*2*2) = 256.

Since tetration is not defined for non-integral heights, the second argument of tetration and both arguments of pentation and above are restricted to non-negative integer values.

Talks & Press

python weekly

Hyperop was featured in issue #231 of Python Weekly!

This library was first presented at DC's Hack && Tell (Feb. 2016). Talk link.

License

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

python-hyperoperators's People

Contributors

anandjeyahar avatar redjard avatar thoppe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-hyperoperators's Issues

Modulo Feature

Hello It Possible To Add Modulo Parametter, For Avoid A Large Number Impossible To Calculate

And Do Not Use a ** b % c For Modulo Please Use pow(a,b,c) For Avoid Impossible Number.

Newa Our Master.

Add bounded operators

Trying to map out the complex plane for H4(z,5) fails as an exact calculation is being attempted. Create a bounded class that returns infinity if it gets too large.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.