Hydra: Difference between revisions

From BusyBeaverWiki
Jump to navigation Jump to search
No edit summary
(Combined introduction with link to bbch)
 
(13 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{machine|1RB3RB---3LA1RA_2LA3RA4LB0LB0LA}}{{unsolved|Does Hydra run forever?}}{{TM|1RB3RB---3LA1RA_2LA3RA4LB0LB0LA|undecided}}
{{machine|1RB3RB---3LA1RA_2LA3RA4LB0LB0LA}}{{unsolved|Does Hydra run forever?}}
'''Hydra''' is a [[BB(2,5)]] [[Cryptid]]. It simulates computing the terms of the sequence
{{TM|1RB3RB---3LA1RA_2LA3RA4LB0LB0LA|undecided}}, called '''Hydra''', is a [[BB(2,5)]] [[Cryptid]]. Its high-level rules were first reported [https://discord.com/channels/960643023006490684/1084047886494470185/1231110668288135208 on Discord] by Daniel Yuan on 20 April 2024, who also gave Hydra said name. Later on, a 6-state, 2-symbol [[Turing machine]] was discovered and named [[Antihydra]] for having similar behaviour to Hydra, making the study of this machine important to the study of that one.
<math display="block>H_{n+1}=\bigg\lfloor\frac{3}{2}H_n\bigg\rfloor,H_0=3,</math>
 
halting if and only if there exists a point in the sequence where the number of even terms up to that point exceeds twice the number of odd terms.
Hydra is known to not generate Sturmian words<ref>Dubickas A. On Integer Sequences Generated by Linear Maps. ''Glasgow Mathematical Journal''. 2009; 51(2): 243-252. doi:[https://doi.org/10.1017/S0017089508004655 10.1017/S0017089508004655]</ref> (Corollary 4).
<div style="width: fit-content; text-align: center; margin-left: auto; margin-right: auto;">
{|class="wikitable" style="margin-left: auto; margin-right: auto;"
! !!0!!1!!2!!3!!4
|-
!A
|1RB
|3RB
| ---
|3LA
|1RA
|-
!B
|2LA
|3RA
|4LB
|0LB
|0LA
|}
The transition table of Hydra.</div>
== Analysis ==
== Analysis ==
===Rules===
Let <math>C(a,b):=0^\infty\;\textrm{<A}\;2\;0^a\;3^b\;2\;0^\infty</math>. Then,<ref>S. Ligocki, "[https://www.sligocki.com/2024/05/10/bb-2-5-is-hard.html BB(2, 5) is Hard (Hydra)] (2024). Accessed 22 July 2024.</ref>
Let <math>C(a,b):=0^\infty\;\textrm{<A}\;2\;0^a\;3^b\;2\;0^\infty</math>. Then<ref>S. Ligocki, "[https://www.sligocki.com/2024/05/10/bb-2-5-is-hard.html BB(2, 5) is Hard (Hydra)] (2024). Accessed 22 July 2024.</ref>,
<math display="block">\begin{array}{|lll|}\hline
<math display="block">\begin{array}{|lll|}\hline
C(2a,0)&\xrightarrow{6a^2+20a+4}&0^\infty\;3^{3a+1}\;1\;\textrm{A>}\;2\;0^\infty,\\
C(2a,0)&\xrightarrow{6a^2+20a+4}&0^\infty\;3^{3a+1}\;1\;\textrm{A>}\;2\;0^\infty,\\
Line 11: Line 29:
C(2a+1,b)&\xrightarrow{4b+6a^2+23a+26}&C(3a+3,b+2).\\\hline
C(2a+1,b)&\xrightarrow{4b+6a^2+23a+26}&C(3a+3,b+2).\\\hline
\end{array}</math>
\end{array}</math>
By scaling and translating these rules we acquire the [[Hydra function]] that relates it to [[Antihydra]]<ref>S. Ligocki, "[https://www.sligocki.com/2024/07/06/bb-6-2-is-hard.html BB(6) is Hard (Antihydra)]" (2024). Accessed 22 July 2024.</ref>.
<div class="toccolours mw-collapsible mw-collapsed">'''Proof'''<div class="mw-collapsible-content">
===Proof===
Consider the partial configuration <math>P(m,n):=0^\infty\;3^m\;\textrm{A>}\;02\;0^n</math>. After 14 steps this configuration becomes  
Consider the partial configuration <math>P(m,n):=0^\infty\;3^m\;\textrm{A>}\;02\;0^n</math>. After 14 steps this configuration becomes  
<math>0^\infty\;3^{m+3}\;\textrm{<A}\;2\;0^{n-2}</math>. We note the following shift rule:
<math>0^\infty\;3^{m+3}\;\textrm{<A}\;2\;0^{n-2}</math>. We note the following shift rule:
Line 22: Line 39:
With <math>C(a,b)</math> we have <math>P(0,a)</math>. As a result, we can apply this rule <math display="inline">\big\lfloor\frac{1}{2}a\big\rfloor</math> times, which creates two possible scenarios:
With <math>C(a,b)</math> we have <math>P(0,a)</math>. As a result, we can apply this rule <math display="inline">\big\lfloor\frac{1}{2}a\big\rfloor</math> times, which creates two possible scenarios:
#If <math>a\equiv0\ (\operatorname{mod}2)</math>, then in <math>\sum_{i=0}^{(a/2)-1}(4\times 3i+26)=\textstyle\frac{3}{2}a^2+10a</math> steps we arrive at <math display="inline">P\Big(\frac{3}{2}a,0\Big)</math>. The matching complete configuration is <math>0^\infty\;3^{(3/2)a}\;\textrm{A>}\;02\;3^b\;2\;0^\infty</math>, which in four steps becomes <math>0^\infty\;3^{(3/2)a+1}\;1\;\textrm{A>}\;3^b\;2\;0^\infty.</math> If <math>b=0</math> then we have reached the undefined <code>A2</code> transition in <math display="inline">\frac{3}{2}a^2+10a+4</math> steps total. Otherwise, continuing for three steps gives us <math>0^\infty\;3^{(3/2)+2}\;\textrm{<B}\;0\;3^{b-1}\;2\;0^\infty</math>. Another shift rule is required here:<math display="block">\begin{array}{|c|}\hline3^s\;\textrm{<B}\xrightarrow{s}\textrm{<B}\;0^s\\\hline\end{array}</math>This means the configuration becomes <math>0^\infty\;\textrm{<B}\;0^{(3/2)a+3}\;3^{b-1}\;2\;0^\infty</math> in <math display="inline">\frac{3}{2}a+2</math> steps, and <math>0^\infty\;\textrm{<A}\;2\;0^{(3/2)a+3}\;3^{b-1}\;2\;0^\infty</math>, equal to <math display="inline">C\Big(\frac{3}{2}a+3,b-1\Big)</math>, one step later. This gives a total of <math display="inline">\frac{3}{2}a^2+\frac{23}{2}a+10</math> steps.
#If <math>a\equiv0\ (\operatorname{mod}2)</math>, then in <math>\sum_{i=0}^{(a/2)-1}(4\times 3i+26)=\textstyle\frac{3}{2}a^2+10a</math> steps we arrive at <math display="inline">P\Big(\frac{3}{2}a,0\Big)</math>. The matching complete configuration is <math>0^\infty\;3^{(3/2)a}\;\textrm{A>}\;02\;3^b\;2\;0^\infty</math>, which in four steps becomes <math>0^\infty\;3^{(3/2)a+1}\;1\;\textrm{A>}\;3^b\;2\;0^\infty.</math> If <math>b=0</math> then we have reached the undefined <code>A2</code> transition in <math display="inline">\frac{3}{2}a^2+10a+4</math> steps total. Otherwise, continuing for three steps gives us <math>0^\infty\;3^{(3/2)+2}\;\textrm{<B}\;0\;3^{b-1}\;2\;0^\infty</math>. Another shift rule is required here:<math display="block">\begin{array}{|c|}\hline3^s\;\textrm{<B}\xrightarrow{s}\textrm{<B}\;0^s\\\hline\end{array}</math>This means the configuration becomes <math>0^\infty\;\textrm{<B}\;0^{(3/2)a+3}\;3^{b-1}\;2\;0^\infty</math> in <math display="inline">\frac{3}{2}a+2</math> steps, and <math>0^\infty\;\textrm{<A}\;2\;0^{(3/2)a+3}\;3^{b-1}\;2\;0^\infty</math>, equal to <math display="inline">C\Big(\frac{3}{2}a+3,b-1\Big)</math>, one step later. This gives a total of <math display="inline">\frac{3}{2}a^2+\frac{23}{2}a+10</math> steps.
#If <math>a\equiv1\ (\operatorname{mod}2)</math>, then in <math display="inline">\frac{3}{2}a^2+7a-\frac{17}{2}</math> steps we arrive at <math display="inline">P\Big(\frac{3a-3}{2},1\Big)</math>. The matching complete configuration is <math>0^\infty\;3^{(3a-3)/2}\;\textrm{A>}\;020\;3^b\;2\;0^\infty</math>, which in four steps becomes <math>0^\infty\;3^{(3a-1)/2}\;1\;\textrm{A>}\;0\;3^b\;2\;0^\infty</math>, and then <math>0^\infty\;3^{(3a-1)/2}\;1\;3^b\;\textrm{A>}\;02\;0^\infty</math> in <math>3b</math> steps. After 14 steps, we see the configuration <math>0^\infty\;3^{(3a-1)/2}\;1\;3^{b+3}\;\textrm{<A}\;2\;0^\infty</math>, which turns into <math>0^\infty\;3^{(3a-1)/2}\;1\;\textrm{<A}\;3^{b+3}\;2\;0^\infty</math> in <math>b+3</math> steps. In two steps we get <math>0^\infty\;3^{(3a+1)/2}\;\textrm{<B}\;0\;3^{b+2}\;2\;0^\infty</math>, followed by <math>0^\infty\;\textrm{<B}\;0^{(3a+3)/2}\;3^{b+2}\;2\;0^\infty</math> after another <math display="inline">\frac{3a+1}{2}</math> steps. We conclude with <math>0^\infty\;\textrm{<A}\;2\;0^{(3a+3)/2}\;3^{b+2}\;2\;0^\infty</math>, equal to <math display="inline">C\Big(\frac{3a+3}{2},b+2\Big)</math>, one step later. This gives a total of <math display="inline">4b+\frac{3}{2}a^2+\frac{17}{2}a+16</math> steps.
#If <math>a\equiv1\ (\operatorname{mod}2)</math>, then in <math display="inline">\frac{3}{2}a^2+7a-\frac{17}{2}</math> steps we arrive at <math display="inline">P\Big(\frac{3a-3}{2},1\Big)</math>. The matching complete configuration is <math>0^\infty\;3^{(3a-3)/2}\;\textrm{A>}\;020\;3^b\;2\;0^\infty</math>, which in four steps becomes <math>0^\infty\;3^{(3a-1)/2}\;1\;\textrm{A>}\;0\;3^b\;2\;0^\infty</math>, and then <math>0^\infty\;3^{(3a-1)/2}\;1\;3^b\;\textrm{A>}\;02\;0^\infty</math> in <math>3b</math> steps. After 14 steps, we see the configuration <math>0^\infty\;3^{(3a-1)/2}\;1\;3^{b+3}\;\textrm{<A}\;2\;0^\infty</math>, which turns into <math>0^\infty\;3^{(3a-1)/2}\;1\;\textrm{<A}\;3^{b+3}\;2\;0^\infty</math> in <math>b+3</math> steps. In two steps we get <math>0^\infty\;3^{(3a+1)/2}\;\textrm{<B}\;0\;3^{b+2}\;2\;0^\infty</math>, followed by <math>0^\infty\;\textrm{<B}\;0^{(3a+3)/2}\;3^{b+2}\;2\;0^\infty</math> after <math display="inline">\frac{3a+1}{2}</math> more steps. We conclude with <math>0^\infty\;\textrm{<A}\;2\;0^{(3a+3)/2}\;3^{b+2}\;2\;0^\infty</math>, equal to <math display="inline">C\Big(\frac{3a+3}{2},b+2\Big)</math>, one step later. This gives a total of <math display="inline">4b+\frac{3}{2}a^2+\frac{17}{2}a+16</math> steps.
The information above can be summarized as
The information above can be summarized as
<math display="block">C(a,b)\rightarrow\begin{cases}0^\infty\;3^{(3/2)a+1}\;1\;\textrm{A>}\;2\;0^\infty&\text{if }a\equiv0\pmod{2}\text{ and }b=0,\\C\Big(\frac{3}{2}a+3,b-1\Big)&\text{if }a\equiv0\pmod{2}\text{ and }b>0,\\C\Big(\frac{3a+3}{2},b+2\Big)&\text{if }a\equiv1\pmod2.\end{cases}</math>
<math display="block">C(a,b)\rightarrow\begin{cases}0^\infty\;3^{(3/2)a+1}\;1\;\textrm{A>}\;2\;0^\infty&\text{if }a\equiv0\pmod{2}\text{ and }b=0,\\C\Big(\frac{3}{2}a+3,b-1\Big)&\text{if }a\equiv0\pmod{2}\text{ and }b>0,\\C\Big(\frac{3a+3}{2},b+2\Big)&\text{if }a\equiv1\pmod2.\end{cases}</math>
Substituting <math>a\leftarrow 2a</math> for the first two cases and <math>a\leftarrow 2a+1</math> for the third yields the final result.
Substituting <math>a\leftarrow 2a</math> for the first two cases and <math>a\leftarrow 2a+1</math> for the third yields the final result.
</div></div>
In effect, the halting problem for Hydra is about whether repeatedly applying the function <math display="inline">f(n)=3\big\lfloor\frac{n}{2}\big\rfloor+3</math> will at some point produce more even values of <math>n</math> than twice the number of odd values.
An alternative version of these rules exists that makes the connection to Antihydra more apparent by using the function <math display="inline">H(n)=\Big\lfloor\frac{3}{2}n\Big\rfloor</math>, or the [[Hydra function]].<ref>S. Ligocki, "[https://www.sligocki.com/2024/07/06/bb-6-2-is-hard.html BB(6) is Hard (Antihydra)]" (2024). Accessed 22 July 2024.</ref>
== Trajectory ==
== Trajectory ==
It takes 20 steps to reach the configuration <math>C(3,0)</math>, and from there, the [[Collatz-like]] rules are repeatedly applied. Here are the first few iterations:
It takes 20 steps to reach the configuration <math>C(3,0)</math>, and from there, the [[Collatz-like]] rules are repeatedly applied. Simulating Hydra has shown that after 4000000 rule steps, we have <math>b=2005373</math>. Here are the first few:
[[File:Hydra 0-572.gif|right|thumb|Animation of the blank tape becoming <math>C(21,0)</math> in 572 steps (''[https://wiki.bbchallenge.org/w/images/2/2f/Hydra_0-572.gif click to view]'').]]
<math display="block">\begin{array}{|c|}\hline C(3,0)\xrightarrow{55}C(6,2)\xrightarrow{133}C(12,1)\xrightarrow{364}C(21,0)\xrightarrow{856}C(33,2)\xrightarrow{1938}C(51,4)\xrightarrow{4367}C(78,6)\rightarrow\cdots\\\hline\end{array}</math>
<math display="block">\begin{array}{|c|}\hline C(3,0)\xrightarrow{55}C(6,2)\xrightarrow{133}C(12,1)\xrightarrow{364}C(21,0)\xrightarrow{856}C(33,2)\xrightarrow{1938}C(51,4)\rightarrow\cdots\\\hline\end{array}</math>
The heuristic argument that suggests Antihydra is a [[probviously]] non-halting machine can be applied here. This means that if <math>b</math> is to be thought of as moving randomly, then the probability of Hydra halting is <math display="inline">{\Big(\frac{\sqrt{5}-1}{2}\Big)}^{2005374}\approx 4.168\times 10^{-419099}</math>.
After 60 million rule steps, there are 29995836 even values of <math>a</math> and 30004165 odd values, giving a very high <math>b</math> value. However, this does not sufficiently prove that Hydra does not halt.
 
===A heuristic nonhalting argument===
== Code ==
The trajectory of <math>b</math> values can be approximated by a random walk, where the walker can only move in step sizes +2 or -1 with equal probability, starting at position 0. The expected position of the walker after <math>k</math> steps is <math display="inline">\frac{1}{2}k</math>, and it can be shown that the probability of the walker reaching position -1 from position <math>n</math> is <math display="inline">{\Big(\frac{\sqrt{5}-1}{2}\Big)}^{n+1}</math>.
 
<div class="toccolours mw-collapsible mw-collapsed">'''Proof'''<div class="mw-collapsible-content">
Fast Hydra/[[Antihydra]] simulation code by Greg Kuperberg (who said it could be made faster using FLINT):<syntaxhighlight lang="python2" line="1">
Let <math>P(n)</math> denote the probability of the random walker reaching position 0 from position <math>n</math>. If the walker reaches position 0, it will do so either by first moving +2 with probability <math display="inline">\frac{1}{2}</math> or first moving -1 with probability <math display="inline">\frac{1}{2}</math>. Therefore, the recurrence relation is
# Python script to demonstrate almost linear time hydra simulation
<math display="block">\textstyle P(n)=\frac{1}{2}P(n+2)+\frac{1}{2}P(n-1)\text{ for }n\ge1.</math>
# using fast multiplication.
Bringing all terms with <math>P</math> to the left side of the equation and then substituting <math>n\leftarrow n+1</math> gives
# by Greg Kuperberg
<math display="block">\textstyle P(n+1)-\frac{1}{2}P(n+3)-\frac{1}{2}P(n)=0.</math>
 
This equation has the form <math>\sum_{i=0}^k a_iP(n+i)=0</math>, which can be solved using the zeroes of the characteristic polynomial <math>f(z)=\sum_{i=0}^k a_iz^i</math>. In this instance we get <math display="inline">f(z)=-\frac{1}{2}+z-\frac{1}{2}z^3</math>, whose zeroes are given by
import time
<math display="block">\textstyle z_0=\frac{\sqrt{5}-1}{2},\qquad\qquad z_1=1,\qquad\qquad z_2=-\frac{1+\sqrt{5}}{2}.</math>
from gmpy2 import mpz,bit_mask
For each real root <math>z_i</math> with multiplicity 1, its fundamental solution is <math>c_i{\left(z_i\right)}^n</math>, and combining these fundamental solutions produces the general solution. Therefore,
 
<math display="block">\textstyle P(n)=c_0{\left(\frac{\sqrt{5}-1}{2}\right)}^n+c_1+c_2{\left(-\frac{1+\sqrt{5}}{2}\right)}^n</math>
# Straight computation of t steps of hydra
The boundary condition <math>\lim_{n\to\infty} P(n)=0</math> means <math>c_2=0</math> (since <math display="inline">\left\vert-\frac{1+\sqrt{5}}{2}\right\vert > 1</math>) and <math>c_1=0</math>, and the boundary condition <math>P(0)=1</math> requires that <math>c_0=1</math>.
def simple(n,t):
    for s in range(t): n += n>>1
    return n
 
# Accelerated computation of 2**e steps of hydra
def hydra(n,e):
    if e < 9: return simple(n,1<<e)
    t = 1<<(e-1)
    (p3t,m) = (mpz(3)**t,bit_mask(t))
    n = p3t*(n>>t) + hydra(n&m,e-1)
    return p3t*(n>>t) + hydra(n&m,e-1)
 
def elapsed():
    (last,elapsed.mark) = (elapsed.mark,time.process_time())
    return elapsed.mark-last
elapsed.mark = 0
 
(n,e) = (mpz(3),25)
 
elapsed()
print('hydra:  steps=%d hash=%016x time=%.6fs'
    % (1<<e,hash(hydra(n,e)),elapsed()))
 
# Quadratic time algorithm for comparison
# print('simple: steps=%d hash=%016x time=%.6fs'
#    % (1<<e,hash(simple(n,1<<e)),elapsed()))
</syntaxhighlight>
 
 


Finally, we note that reaching position -1 from position <math>n</math>, the required condition for halting, is the same as reaching position 0 from position <math>n+1</math>, so we must increment <math>n</math>.
</div></div>
For these reasons, Hydra is considered to be a [[probviously]] nonhalting machine.
==References==
==References==
[[Category:Cryptids]]
[[Category:Cryptids]]

Latest revision as of 21:25, 10 August 2025

Unsolved problem:
Does Hydra run forever?

1RB3RB---3LA1RA_2LA3RA4LB0LB0LA (bbch), called Hydra, is a BB(2,5) Cryptid. Its high-level rules were first reported on Discord by Daniel Yuan on 20 April 2024, who also gave Hydra said name. Later on, a 6-state, 2-symbol Turing machine was discovered and named Antihydra for having similar behaviour to Hydra, making the study of this machine important to the study of that one.

Hydra is known to not generate Sturmian words[1] (Corollary 4).

0 1 2 3 4
A 1RB 3RB --- 3LA 1RA
B 2LA 3RA 4LB 0LB 0LA
The transition table of Hydra.

Analysis

Let . Then,[2]

Proof

Consider the partial configuration . After 14 steps this configuration becomes . We note the following shift rule:

Using this shift rule, we get in steps. From here, we can observe that turns into in three steps if . By repeating this process, we acquire this transition rule:
With this rule, it takes steps to reach the configuration , which is the same configuration as . To summarize:
With we have . As a result, we can apply this rule times, which creates two possible scenarios:

  1. If , then in steps we arrive at . The matching complete configuration is , which in four steps becomes If then we have reached the undefined A2 transition in steps total. Otherwise, continuing for three steps gives us . Another shift rule is required here:
    This means the configuration becomes in steps, and , equal to , one step later. This gives a total of steps.
  2. If , then in steps we arrive at . The matching complete configuration is , which in four steps becomes , and then in steps. After 14 steps, we see the configuration , which turns into in steps. In two steps we get , followed by after more steps. We conclude with , equal to , one step later. This gives a total of steps.

The information above can be summarized as

Substituting for the first two cases and for the third yields the final result.

In effect, the halting problem for Hydra is about whether repeatedly applying the function will at some point produce more even values of than twice the number of odd values.

An alternative version of these rules exists that makes the connection to Antihydra more apparent by using the function , or the Hydra function.[3]

Trajectory

It takes 20 steps to reach the configuration , and from there, the Collatz-like rules are repeatedly applied. Simulating Hydra has shown that after 4000000 rule steps, we have . Here are the first few:

The heuristic argument that suggests Antihydra is a probviously non-halting machine can be applied here. This means that if is to be thought of as moving randomly, then the probability of Hydra halting is .

Code

Fast Hydra/Antihydra simulation code by Greg Kuperberg (who said it could be made faster using FLINT):

# Python script to demonstrate almost linear time hydra simulation
# using fast multiplication. 
# by Greg Kuperberg

import time
from gmpy2 import mpz,bit_mask

# Straight computation of t steps of hydra
def simple(n,t):
    for s in range(t): n += n>>1
    return n

# Accelerated computation of 2**e steps of hydra
def hydra(n,e):
    if e < 9: return simple(n,1<<e)
    t = 1<<(e-1)
    (p3t,m) = (mpz(3)**t,bit_mask(t))
    n = p3t*(n>>t) + hydra(n&m,e-1)
    return p3t*(n>>t) + hydra(n&m,e-1)

def elapsed():
    (last,elapsed.mark) = (elapsed.mark,time.process_time())
    return elapsed.mark-last
elapsed.mark = 0

(n,e) = (mpz(3),25)

elapsed()
print('hydra:  steps=%d hash=%016x time=%.6fs'
    % (1<<e,hash(hydra(n,e)),elapsed()))

# Quadratic time algorithm for comparison
# print('simple: steps=%d hash=%016x time=%.6fs'
#     % (1<<e,hash(simple(n,1<<e)),elapsed()))


References

  1. Dubickas A. On Integer Sequences Generated by Linear Maps. Glasgow Mathematical Journal. 2009; 51(2): 243-252. doi:10.1017/S0017089508004655
  2. S. Ligocki, "BB(2, 5) is Hard (Hydra) (2024). Accessed 22 July 2024.
  3. S. Ligocki, "BB(6) is Hard (Antihydra)" (2024). Accessed 22 July 2024.