No.2398 Breaking the Hydra
タグ : / 解いたユーザー数 5
作問者 : 👑
testestest
Problem Statement
We recursively define when a string consisting only of the $2$ kinds of characters ( and ) is a hydra, as follows:
- The empty string is a hydra.
- For any hydras $h_0$ and $h_1$, the string obtained by concatenating $h_0$ and $h_1$ in this order is a hydra.
- For any hydra $h$, the string obtained by concatenating
(, $h$, and)in this order is a hydra.
Below is an explanation for those unfamiliar with recursive definitions of sets and the like. (Click to expand)
Let $X$ be a set. For example, $X$ may be the set of strings consisting only of specific characters. What we explain here is the phrasing peculiar to mathematics used when recursively defining subsets of $X$ and the like.
For example, using an element $c$ of $X$, non-negative integers $n_0,m_0,n_1,m_1$, and maps $F_0 \colon X^{n_0} \times X^{m_0} \to X$ and $F_1 \colon X^{n_1} \times X^{m_1} \to X$, one may write as follows:
We recursively define a subset $A$ of $X$ as follows:
- $c \in A$.
- For any $(a,t) \in A^{n_0} \times X^{m_0}$, we have $F_0(a,t) \in A$.
- For any $(a,t) \in A^{n_1} \times X^{m_1}$, we have $F_1(a,t) \in A$.
This is merely an example. We used $3$ conditions here, but in general there need not be exactly $3$, and relations may be used instead of maps. The general formulation of recursive definitions[1] 6.1.1 Definition is quite abstract, so here we consider only the examples needed to solve this problem.
The important point is that this definition does not merely mean that $A$ is an arbitrary subset of $X$ satisfying all $3$ conditions; rather, it stands for the following definition:[1] See 6.1.2 Definition and the paragraph immediately after it
We define the subset $A$ of $X$ as the intersection of all subsets $B$ of $X$ satisfying all of the following $3$ conditions:
- $c \in B$.
- For any $(a,t) \in B^{n_0} \times X^{m_0}$, we have $F_0(a,t) \in B$.
- For any $(a,t) \in B^{n_1} \times X^{m_1}$, we have $F_1(a,t) \in B$.
Taking $B = X$ does satisfy the $3$ conditions above, so the set of all $B$ satisfying the conditions is non-empty and the intersection is well-defined. It then follows that $A$ is the smallest among the $B$ satisfying the $3$ conditions.
Note in this way that, by convention, a recursive definition of a subset is not a mere list of conditions but also implies minimality. However, this convention applies only to recursive definitions. An ordinary definition of course does not imply minimality, and in the first place, self-reference like that of a recursive definition, when used in an ordinary definition, usually results in circular reasoning and makes the definition break down.
Now, since a $1$-ary relation on $X$ is equivalent to a subset of $X$, the same rule applies to recursive definitions of $1$-ary relations on $X$. Specifically, suppose we write a recursive definition of the $1$-ary relation "is a good term" as follows:
We recursively define when an element of $X$ is a good term as follows:
- $c$ is a good term.
- For any $(a,t) \in X^{n_0} \times X^{m_0}$, if every component of $a$ is a good term, then $F_0(a,t)$ is also a good term.
- For any $(a,t) \in X^{n_1} \times X^{m_1}$, if every component of $a$ is a good term, then $F_1(a,t)$ is also a good term.
This does not mean that the predicate "is a good term" denotes an arbitrary $1$-ary relation satisfying the $3$ conditions. The above definition is equivalent to the following definition:
We define an element $x$ of $X$ to be a good term if $x \in B$ holds for every subset $B$ of $X$ satisfying all of the following $3$ conditions:
- $c \in B$.
- For any $(a,t) \in B^{n_0} \times X^{m_0}$, we have $F_0(a,t) \in B$.
- For any $(a,t) \in B^{n_1} \times X^{m_1}$, we have $F_1(a,t) \in B$.
Based on the above, the recursive definition of a hydra in this problem is equivalent to the following definition:
We define a string $h$ consisting only of the $2$ kinds of characters
(and)to be a hydra if, for any set $B$ consisting only of strings consisting only of(and), $h \in B$ holds whenever $B$ satisfies all of the following $3$ conditions:
- The empty string is an element of $B$.
- For any elements $h_0$ and $h_1$ of $B$, the string obtained by concatenating $h_0$ and $h_1$ in this order is an element of $B$.
- For any element $h$ of $B$, the string obtained by concatenating
(, $h$, and)in this order is an element of $B$.
This phrasing is considerably more complicated than the original one. To avoid such complicated phrasing, mathematics defines and adopts the concise phrasing introduced here.
Such phrasing is actually adopted, for example, in the references listed below:
- the recursive definitions of the $1$-ary relations "be an $\mathcal{L}$-term" and "be an $\mathcal{L}$-formula" in [1], etc.
- the recursive definitions of the set $T$ and the $1$-ary relation "be a principal term" in [2], etc.
- the recursive definitions of the sets $B(\alpha,\beta)$ and $\textrm{K}_{\kappa}(\gamma)$ in [3], etc.
and so on.
References
- W. Pohlers, "Proof Theory - The first step into impredicativity", Springer, 2010.
- W. Buchholz, "A New System of Proof-Theoretic Ordinal Functions", Annals of Pure and Applied Logic 32 (1986), pp. 195--207.
- M. Rathjen, "Ordinal Notations Based on a Weakly Mahlo Cardinal", Archive for Mathematical Logic 29 (1990), pp. 249--263.
The hydra that is the empty string is called a dead hydra, and a hydra that is not the empty string is called a living hydra.
For a living hydra $h$ and a positive integer $n$, we recursively define the hydra $h[n]$ as follows:
- If there exists a hydra $h'$ such that $h$ is the string obtained by concatenating $h'$ and
()in this order, then $h[n]$ is $h'$. - Suppose there exist a hydra $h_0$ and a living hydra $h_1$ such that $h$ is the string obtained by concatenating $h_0$,
(, $h_1$, and)in this order. - Suppose there exists a hydra $h_1'$ such that $h_1$ is the string obtained by concatenating $h_1'$ and
()in this order. - If $n = 1$, then $h[n]$ is the string obtained by concatenating $h_0$,
(, $h_1'$, and)in this order. - If $n > 1$, then $h[n]$ is the string obtained by concatenating $h[n-1]$,
(, $h_1'$, and)in this order. - Otherwise, $h[n]$ is the string obtained by concatenating $h_0$,
(, $h_1[n]$, and)in this order.
Calculation example (click to expand):
For example, when $h$ is (((())()())), $h[n]$ for $n = 1,2,3,4,5,6,7,8,9,10$ is as follows:
$h[1] =$ (((())())) $h[2] =$ (((())())((())())) $h[3] =$ (((())())((())())((())())) $h[4] =$ (((())())((())())((())())((())())) $h[5] =$ (((())())((())())((())())((())())((())())) $h[6] =$ (((())())((())())((())())((())())((())())((())())) $h[7] =$ (((())())((())())((())())((())())((())())((())())((())())) $h[8] =$ (((())())((())())((())())((())())((())())((())())((())())((())())) $h[9] =$ (((())())((())())((())())((())())((())())((())())((())())((())())((())())) $h[10] =$ (((())())((())())((())())((())())((())())((())())((())())((())())((())())((())()))
Hydra Daisuki bot is a bot that loves hydras.
Hydra Daisuki bot Daisuki bot is a bot that loves Hydra Daisuki bot. Of course, the two are distinct entities.
For a living hydra $h_0$, we define the hydra game with initial value $h_0$, whose two players are Hydra Daisuki bot and Hydra Daisuki bot Daisuki bot, as follows:
- First, set the value of the variable $h$, which represents a hydra, to $h_0$.
- Next, starting with Hydra Daisuki bot, the two players alternately perform the following operation until the value of $h$ becomes a dead hydra:
- Choose $1$ positive integer $n$ and replace the value of $h$ with the value of $h[n]$.
When this game ends after a finite number of operations, the player who performed the last operation wins.
A living hydra $H$ is given as input.
In the hydra game with initial value $H$, when the two choose optimal moves so as to aim for their own victory and avoid the opponent's victory, determine whether the outcome is decided within a finite number of operations and, if it is decided, which one wins.
Background
The hydra game introduced here is a slight modification of the single-player Kirby-Paris hydra game[1], made into a game with two players.
The specific changes are the following $3$ points:
- Here it is formulated with strings consisting only of parentheses, whereas the original is formulated with finite rooted trees.
- Here $n$ can be freely chosen in each operation, whereas in the original $n$ cannot be chosen and the turn number is used.
- Here the part of the hydra that changes cannot be chosen, whereas in the original one can choose any leaf and change that part.
Point $1$ is a change of convenience that simplifies the rigorous description of the operation and the input; it can be translated into a finite rooted tree by taking the syntax tree of the parentheses and adding a root.
Input
The input is given from Standard Input in the following format:
$H$
The hydra $H$ is given on $1$ line.
Constraints
The input satisfies the following constraints:
- $H$ is a living hydra whose length as a string is at most $10^5$
- $H$ can appear as a value of $h$ in the hydra game whose initial value is the living hydra obtained by concatenating $5 \times 10^4$ copies of
(and $5 \times 10^4$ copies of)in this order
Output
In the hydra game with initial value $H$, when the two choose optimal moves so as to aim for their own victory and avoid the opponent's victory, print
-
-1if the outcome is not decided within a finite number of operations -
0if Hydra Daisuki bot, who moves first, wins -
1if Hydra Daisuki bot Daisuki bot, who moves second, wins
.
Print a newline at the end.
Sample
Sample 1
Input
()
Output
0
First, the value of $h$ is initialized to ().
Next, if Hydra Daisuki bot chooses $n = 1$, the value of $h$ is replaced with the value of $h[1]$, which is a dead hydra.
Therefore, Hydra Daisuki bot has a winning strategy.
Sample 2
Input
()()
Output
1
First, the value of $h$ is initialized to ()().
Next, Hydra Daisuki bot chooses a positive integer $n$ and the value of $h$ is replaced with the value of $h[n]$, which is the living hydra () regardless of the choice of $n$.
Then, if Hydra Daisuki bot Daisuki bot chooses $n=1$, the value of $h$ is replaced with the value of $h[1]$, which is a dead hydra.
Therefore, Hydra Daisuki bot Daisuki bot has a winning strategy.
Sample 3
Input
(())
Output
0
First, the value of $h$ is initialized to (()).
Next, if Hydra Daisuki bot chooses $n = 2$, the value of $h$ is replaced with the value of $h[2]$, which is the living hydra ()().
Then, when Hydra Daisuki bot Daisuki bot chooses a positive integer $n$, the value of $h$ is replaced with the value of $h[n]$, which is the living hydra () regardless of the choice of $n$.
Finally, if Hydra Daisuki bot chooses $n = 1$, the value of $h$ is replaced with the value of $h[1]$, which is a dead hydra.
Therefore, Hydra Daisuki bot has a winning strategy.
Source
- L. Kirby and J. Paris, "Accessible Independence Results for Peano Arithmetic", Bull. London Math. Soc. 14 (1982), pp. 285--193.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。