# Note that integer division by 2 is equivalent to one bit shift to the right (a >> 1)
a += a//2
a += a//2
</syntaxhighlight>
</syntaxhighlight>
Replacing <code>a = 3</code> with <code>a = 8</code> and swapping <code>b -= 1</code> for <code>b += 2</code> turns this program into an Antihydra simulator.
Replacing <code>a = 3</code> with <code>a = 8</code> and swapping <code>b -= 1</code> with <code>b += 2</code> turns this program into an Antihydra simulator.
==Properties==
==Properties==
The Hydra function can be rewritten as follows:
The Hydra function can be rewritten as follows:
Line 119:
Line 120:
== Visualizations ==
== 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):
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):
<gallery mode=packed heights="250">
<gallery mode="packed" heights="250">
File:HydraFunction-StartingValue2.png|Starting value 2. There are 492 even numbers and 508 odd numbers.
File:HydraFunction-StartingValue2.png|Starting value 2. There are 492 even numbers and 508 odd numbers.
File:HydraFunction-StartingValue5.png|Starting value 5. There are 497 even numbers and 503 odd numbers.
File:HydraFunction-StartingValue5.png|Starting value 5. There are 497 even numbers and 503 odd numbers.
Revision as of 13:17, 15 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 CryptidsHydra and Antihydra. Due to its simplicity, simulations for both of these Turing machines utilize this function instead of what can initially be proven.
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 function
The Hydra function's simple definition allows one to write computer programs that simulate Hydra and Antihydra. The following Python program is a straightforward Hydra simulator based on the Hydra function:
# 'a' and 'b' fulfill the same purpose as in the Hydra rules.a=3b=0# As long as Hydra has not halted, 'b' remains greater than -1.whileb!=-1:# If 'a' is even, decrement 'b', otherwise increase 'b' by 2.ifa%2==0:b-=1else:b+=2# This performs 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.
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):
Starting value 2. There are 492 even numbers and 508 odd numbers.
Starting value 5. There are 497 even numbers and 503 odd numbers.
Starting value 8. There are 499 even numbers and 501 odd numbers.
Starting value 11. There are 481 even numbers and 519 odd numbers.