Hydra function: Difference between revisions

From BusyBeaverWiki
Jump to navigation Jump to search
m (→‎Coding the Hydra and Antihydra problems using the Hydra function: Improve wording around condition counter and explain meaning of program halting status)
Line 96: Line 96:


Determining whether these programs halt or not (and if so, after how many loop iterations) would resolve these open problems.
Determining whether these programs halt or not (and if so, after how many loop iterations) would resolve these open problems.
problems.
==Properties==
==Properties==
The Hydra function can be rewritten as follows:
The Hydra function can be rewritten as follows:

Revision as of 10:46, 23 April 2025

A spiral-like figure that gives the first few terms of the Hydra sequences with initial values 2, 5, 8, 11, 14, and 17.

The Hydra function is a Collatz-like function defined as:

It is named as such because of its connection to the unsolved halting problems for the Cryptids Hydra and Antihydra. Due to its simplicity, simulations for both of these Turing machines utilize this function instead of what can initially be proven.

Relationship to Hydra and Antihydra problems

Using the Hydra function, we can obtain simplified rules for Hydra and Antihydra:

Hydra Antihydra
Let :
Let :
Proof

Recall the high-level rules for Hydra and Antihydra:

Hydra Antihydra
Let :
Let :

Already, both machines appear to be very similar. They have one parameter that increases exponentially with growth factor and another that takes a pseudo-random walk. Below, the exponentially increasing variables are described by integer sequences:

Hydra Antihydra

This will make demonstrating the transformation easier. Now we will define a new integer sequence based on the old one and discover the recursive rules for that sequence. This new sequence is and for Hydra and Antihydra respectively. We start by using instead and substituting for its recursive formula. By doing so, we get:

Hydra Antihydra

After that, we can substitute for its solution in terms of . What results is the following:

Hydra Antihydra

The statements amount to checking if is even or odd. After simplifying, we are done:

Hydra Antihydra

Now that we have demonstrated a strong similarity in the behaviour of both Turing machines, we can return to using the high-level rules. Doing that while considering the step counts yields the final result.

Under these rules, the halting problem for Hydra is about whether repeatedly applying the function , starting with , will eventually generate more even terms than twice the number of odd terms. Similarly, Antihydra halts if and only if repeatedly applying , starting with , will eventually generate more odd terms than twice the number of even terms.

Coding the Hydra and Antihydra problems using the Hydra function

Paired with the corresponding even/odd criterion as loop halting condition (implemented as a counter variable) and initial Hydra function value, the Hydra function definition can be used to write computer programs that simulate the abstracted behavior of the Hydra and Antihydra Turing machines. The following Python program is a Hydra simulator:

# 'a' and 'b' fulfill the same purpose as in the Hydra rules:
# The current hydra function value
a = 3
# The even/odd condition counter
b = 0
# As long as Hydra has not halted, 'b' remains greater than -1.
while b != -1:
    # If 'a' is even, decrement 'b', otherwise increase 'b' by 2.
    if a % 2 == 0:
        b -= 1
    else:
        b += 2
    # This performs one step of the Hydra function H(a) = a + floor(a/2).
    # Note that integer division by 2 is equivalent to one bit shift to the right (a >> 1)
    a += a//2

Replacing a = 3 with a = 8 and swapping b -= 1 with b += 2 turns this program into an Antihydra simulator.

Determining whether these programs halt or not (and if so, after how many loop iterations) would resolve these open problems.

Properties

The Hydra function can be rewritten as follows:

Now assume that for some positive integer and every odd integer , and , where is function iteration. Notice that we can write and , so if we apply to these numbers, we get and . Now, if we apply to these numbers times, we get and . Therefore, by mathematical induction we have proved the following formulas:
This optimization can be directly applied to the high-level rules for Hydra and Antihydra, producing this result:

Hydra Antihydra
Let :

where and .

Let :

where and .

Visualizations

The four images below depict the first 1000 values of four Hydra sequences with different initial values. Each row of pixels shows a number in binary on the right and its parity on the left (blue for even, red for odd):