Skip to main content

The Syracuse problem (aka Collatz conjecture) library

Project description

PyPI - Python Version GitHub release (latest by date) GitHub GitHub issues GitHub pull requests

Graph of the first 26 compressed Collatz sequences (Graph of the first 26 compressed Collatz sequences)

Syracuse

syracuse, The Syracuse problem (aka Collatz conjecture) library.

About the project

The syracuse library provides a way to generate Collatz sequences (either "normal" or compressed forms) and some functions to deal with.

The Collatz conjecture

The Collatz conjecture, also known as the "3n + 1 problem" or the "Syracuse problem", is an unsolved hypothesis in mathematics that concerns a sequence of operations applied to a positive integer. The conjecture states that no matter what the starting value of this integer is, the sequence will always eventually reach the value 1.

More specifically, the Collatz conjecture states that if one takes a positive integer n and applies the following function:

  • If n is even, divide it by 2.
  • If n is odd, multiply it by 3 and add 1.

Then, repeat the process with the resulting value, applying the function over and over again until the value of n eventually reaches 1.

For example, if one takes n = 6, the sequence for the Collatz conjecture would be: 6, 3, 10, 5, 16, 8, 4, 2, 1.

The Collatz conjecture asserts that this sequence will always eventually reach the value 1, no matter what positive integer n one starts with. Although the conjecture has been computationally tested for extremely large values, it remains unproven to this day.

The compressed form

(definition partially inspired by the relevant article on Wikipedia)

Since 3n+1 is even whenever n is odd, one may instead use the "compressed" form of the Collatz function:

  • if n is even, divide it by 2.
  • if n is odd, multiply it by 3, add 1 and divide the result by 2.

This definition yields smaller values for the stopping time and total stopping time without changing the overall dynamics of the process.

For example, consider the Collatz sequence for the number 17: 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1

The compressed form of this sequence would be: 17, 26, 13, 20, 10, 5, 8, 4, 2, 1

The compressed form of the Collatz sequence has been the subject of much research, as it provides insights into the behavior of the original sequence and can be used to search for cycles and other patterns. However, the Collatz conjecture itself remains unproven, and the compressed form of the sequence does not provide a proof or disproof of the conjecture.

Why the name "syracuse" ?

The Collatz conjecture is also known as the Syracuse problem because it was first introduced by Lothar Collatz in a 1950 paper, where he credited his colleague, mathematician Helmut Hasse, with calling it the Syracuse problem. The name "Syracuse" refers to the University of Syracuse, where Collatz was working at the time.

The name "Syracuse problem" has since become a common alternative to "Collatz conjecture", especially in French and Italian-speaking countries, where it is often referred to as the "problème de Syracuse" or "problema di Syracuse", respectively.

Regardless of the name used, the conjecture remains one of the most famous and challenging open problems in mathematics, and it continues to attract the attention of mathematicians and computer scientists around the world.

Getting started

Prerequisites

Of course, syracuse cannot run without Python ! More precisely, it requires at least the 3.11 version of our beloved language.

syracuse depends on the following packages. The installation of syracuse should install automatically those packages if they are missing on your system. If it fails, you can install them individually:

  • networkx: version 3.0.0 or above

     pip install networkx["default"]
    
  • matplotlib: version 3.6.0 or above

     pip install matplotlib
    
  • numpy: version 1.24.0 or above

     pip install numpy
    

Installation

Install from PyPi with:

pip install syracuse

As an alternative, you can download the *.whl file from the last release on the syracuse Github repository, and execute the following command (replace "X.Y.Z" by the right version number):

pip install syracuse-X.Y.Z-py3-none-any.whl

Usage

Please refer to the documentation.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement" or "bug", according to whether you want to share a proposal of a new function, or to record an anomaly.

Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. Check out LICENSE.md file for more information.

Acknowledgments

I would like greatfully to thank:

Graphviz authors for this impressive graph visualization software, especially for the creation of the useful DOT Langage.

The Matplotlib development team for providing a very powerful library "for creating static, animated, and interactive visualizations in Python".

NumPy community for this fundamental tool to be used as a priority if you want make serious scientific computations with Python.

MkDocs, mkdocstrings and Material for MkDocs for giving the ability to create in a very simple way an accessible documentation for either tiny or big projects.

Make a README, Sayan Mondal, Hillary Nyakundi and othneildrew for providing very interesting materials to write good README files (far better than I can write by myself !).

Choose an open source license for helping to choose the best suitable license for this project.

Semantic Versioning for providing clear specifications for versioning projects.

Real Python for contributing really increasing skills in Python for everyone, novices or veterans.

GitHub for hosting this project, and helping to share it.

Pypi for providing a very convenient way to share modules and package to the entire Python community.

And, of course, all the former, current and further contributors of this project !

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

syracuse-0.1.2.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

syracuse-0.1.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file syracuse-0.1.2.tar.gz.

File metadata

  • Download URL: syracuse-0.1.2.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.1 Windows/10

File hashes

Hashes for syracuse-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ccaa8ff69684f2161ab681777a5cbd5404c41e4e0e885c3821c159ead2c27a91
MD5 665e0019bbda4e16d8dae789e05cfc48
BLAKE2b-256 229ca23762a54eeda04e61585864df77e5387a782093750bab252cf0c8bfdc53

See more details on using hashes here.

File details

Details for the file syracuse-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: syracuse-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.1 Windows/10

File hashes

Hashes for syracuse-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 98e5e98654590eee98368f80a74f719b1417af524e09e6ec91d5aed03d507967
MD5 5259f8ab93bdaf988fd77094eb8b75a1
BLAKE2b-256 8ae706a540a1263cf8a6892d40f0028a4ee1a6cf10b73debbae1b1f5777d1f8d

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