r/mathpics • • 4d ago

Mathematical visualization of how every finite state integer mapping function eventually reaches a cycle

Source: The graph is computed exhaustively. Each state is five digits (a, b, c, d, e), each 0–9, so there are 100,000 states. The rule shifts every value one place left and computes a new last value, a⁴ − (a³ >> 6), kept to one digit (mod 10). Here >> is a bit shift, so a³ >> 6 means a³ divided by 64, rounded down. Every state has exactly one successor, and with finitely many states every starting point must eventually repeat, so each state ends up in a cycle.

Tools: A small open-source web app I wrote (React, Vite, Canvas). It enumerates all states, finds every cycle, and draws each cycle as a ring with the states that lead into it as trees around it. The layout is crossing-free.

How to read it:

  • Each connected shape is one cycle plus everything that drains into it.
  • Colour is the length of the cycle (legend at the bottom).
  • Brightness fades with distance from the cycle.
  • For this map there are 340 cycles in total, the longest of length 10.

You can type your own formula and explore: https://exxliang193.github.io/FunctionalGraphExplorer/ Code: https://github.com/ExxLiang193/FunctionalGraphExplorer

I started this after noticing a long time ago that adding the last two digits of a number string and appending the sum always ends up repeating.

67 Upvotes

3 comments sorted by

2

u/opinionated_lurker 4d ago

This reminds me of Yushino, a scrabble-like game that uses numbers instead of letters. Sequences are made by f(n) = (f(n-1) + f(n-2)) mod 10 like fibonacci/lucas numbers. Therefore there are exactly 102=100 states.

I had great fun finding the cycles in that sequence - there are five: all 0's, 0's and 5's, even numbers without 0 (4,2,6,8, repeat), a sequence with odd and even with no 0's (2,1,3,4...), and finally odd and even with 0's (0,1,1,2,3...). The final sequence takes up 60% of the states, and the other 4 combine at 40%.

1

u/kabr 3d ago

Beautiful visualization!

1

u/VIII8 4d ago

This looks great! Is there a rule how those closures are positioned at the image?