This project explores the Collatz conjecture by working backward from the number 1. It generates a tree-like "mind map" of all the numbers that lead to 1, revealing the branching structure of the reversed sequences.
The standard Collatz conjecture starts with a positive integer n and repeatedly applies two rules:
- If
nis even, the next term isn / 2. - If
nis odd, the next term is3n + 1.
This project does the reverse:
- If a number
mis even, its predecessor could bem / 2(since(m/2) * 2 = m). - If a number
mcan be expressed as3n + 1, its predecessor could ben = (m - 1) / 3.
By starting at 1 and applying these reverse rules, we can generate a tree of all numbers that eventually lead to 1.
-
collatz_mindmap.py: This is the primary data generation script. It builds the reverse Collatz tree starting from1up to a specified depth. It produces a JSON file that represents this tree structure. -
visualize_mindmap.py: This script takes the JSON data generated by the first script and uses the Graphviz library to create a visually appealing PNG image of the mind map. -
main.py: The original script for analyzing Collatz sequences, likely used to generate the initial data in theadvanced_analysisandgraphsdirectories. -
collatz_mindmap.json: An intermediate data file containing the mind map structure in a hierarchical format. This file is read byvisualize_mindmap.py. -
graphs/collatz_mindmap_visualization.png: The final output image of the mind map.
Before running the scripts, you need to have the following installed:
-
Python 3: Download Python
-
Graphviz Software: This is a separate program required for rendering the graph.
- Download: https://graphviz.org/download/
- Important: During installation, ensure you add Graphviz to your system's PATH environment variable. The installer usually provides a checkbox for this.
-
Python
graphvizLibrary: Install this using pip after installing the Graphviz software.pip install graphviz
Follow these steps to generate and view the mind map:
Run the collatz_mindmap.py script. This will create the collatz_mindmap.json file.
python collatz_mindmap.pyNext, run the visualize_mindmap.py script. This reads the JSON file and creates the PNG image.
python visualize_mindmap.pyThe final image will be saved as graphs/collatz_mindmap_visualization.png.
To generate a larger or smaller mind map, you can change the search depth.
- Open the
collatz_mindmap.pyfile in a text editor. - Find the line
MAX_DEPTH = 8near the end of the file. - Change the number
8to a higher value (e.g.,10,12) for a larger tree, or a lower value for a smaller one. - Save the file.
- Re-run both scripts as described in the "How to Use" section to see your changes.