Git Product home page Git Product logo

collatzlibrary's Introduction

A Collatz Library

In the 30s of the last century, German mathematician Lothar Collatz came up with the following problem:

Take a natural number n.

If n is even, divide it by 2: n_new = n / 2.

If n is odd, multiply it by 3 and add 1: n_new = 3 x n + 1.

repeat with result n = n_new.

Repeating this algorithm leads to a sequence (the Collatz sequence).

Example:

  7 is odd      => 7 * 3 + 1 = 22

  22 is even    => 22 / 2 = 11

  11 is odd     => 11 * 3 + 1 = 34

  34 is even    => 34 / 2 = 17

  17 is odd     => 17 * 3 + 1 = 52

  52 is even    => 52 / 2 = 26

  26 is even    => 26 / 2 = 13

  13 is odd     => 13 * 3 + 1 = 40

  40 is even    => 40 / 2 = 20

  20 is even    => 20 / 2 = 10

  10 is even    => 10 / 2 = 5

  5 is odd      => 5 * 3 + 1 = 16

  16 is odd     => 16 / 2 = 8

  8 is even     => 8 / 2 = 4

  4 is even     => 4 / 2 = 2

  2 is even     => 2 / 2 = 1

  1 is odd      => 3 * 1 + 1 = 4 

We end up in a loop (4, 2, 1)

Collatz assumed that this behavior is the same for all natural numbers. And indeed, all numbers up to pow(2,68) seem to support this assumption.

Unfortunately, nobody was able to prove or disprove this assumption so far. It might even be the case that we can never prove the assumption. According to Turing and Gödel there must be some problems that fall into this category.

Since I am fascinated by the Collatz assumption, I built my own Python library to study Collatz sequenzes from different angles using different views. I am providing this library for sharing my enthusiasm with others.

I added a demo to the library so that it can also be executed as a standalone program. In addition, the demo illustrates how the library might be used.

collatzlibrary's People

Contributors

ms1963 avatar

Watchers

 avatar

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.