$\newcommand{\abstraction}[2]{\lambda #1. #2}$ $\newcommand{\application}[2]{\left(#1 #2\right)}$ $\newcommand{\substitution}[3]{#1 \left[#2 := #3\right]}$ $\newcommand{\freevars}[1]{\operatorname{FV}\left(#1\right)}$ $\newcommand{\closedlambdaset}{\Lambda^{0}}$ $\newcommand{\lambdaexprswithfreevars}[1]{\closedlambdaset\left(#1\right)}$ $\newcommand{\subterm}[1]{\operatorname{Sub}\left(#1\right)}$ $\newcommand{\vars}[1]{\operatorname{Var}\left(#1\right)}$ $\newcommand{\context}[2]{{#1}\left[#2\right]}$ $\newcommand{\hole}{\ }$
Barendregt defines a binary relation $R$ on the set of lambda terms $\Lambda$ to be compatible if $$\begin{align} \left(M,M'\right) \in R \implies &\left(\application{Z}{M}, \application{Z}{M'} \right) \in R,\\ & \left( \application{M}{Z}, \application{M'}{Z} \right) \in R, \text{ and }\\ &\left( \abstraction{x}{M}, \abstraction{x}{M'} \right) \in R \end{align} $$ for all $M,M',Z \in \Lambda$. Call this Statement 1.
I'm understanding that this condition is required to somehow "preserve" the syntactic structure of a (potentially complicated) term being reduced under a notion of reduction in the system.
The author later comments that a relation $R \subseteq \Lambda^2$ is compatible if $$\left(M,M'\right) \in R \implies \left( \context{C}{M}, \context{C}{M'} \right) \in R$$ for all $M,M' \in \Lambda$ and all contexts $\context{C}{}$ with one hole. Call this Statement 2.
The proofs that follow in the book all use induction over the structure of contexts using Statement 2 instead of the former. Indeed, all other references I found online use Statement 2 (with some minor variations) as the definition for a relation to be compatible. So I'm trying to prove they are equivalent statements: given one statement as a definition, the other follows.
My rational is as follows for given Statement 2 as a definition, it follows that Statement 1 is true.
The same reference defines a context inductively by:
- $x$ is a context — I have seem some controversy about this one on other answers here, but this is how it is defined in the reference;
- $\context{}{}$ is a context;
- if $\context{C_1}{}$ and $\context{C_2}{}$ are contexts, then so is $\application{\context{C_1}{}}{\context{C_2}{}}$.
- if $\context{C_1}{}$ is a context, then so is $\abstraction{x}{\context{C_1}{}}$.
The contexts with one hole can only be (*)
- $\context{}{}$;
- $\application{Z}{\context{}{}}$ — coming from case 3 above and choosing $\context{C_1}{} \equiv Z$ and $\context{C_2}{} \equiv \context{}{}$.
- $\application{\context{}{}}{Z}$ — coming from case 3 above and choosing $\context{C_1}{} \equiv \context{}{}$ and $\context{C_2}{} \equiv Z$.;
- $\abstraction{x}{\context{}{}}$ — coming from case 4 above and choosing $\context{C_1}{} \equiv \context{}{}$.;
because otherwise the inductive nature of the context definition as given would create more than one hole. Also, the case $x$ has no holes.
Then, the three implications follow immediately from the substitution of cases 2, 3, and 4 above, together with $(M,M') \in R \implies (M,M') \in R$ from the first case which is (obviously?) true from the structure of the statement.
The converse would be in the lines of:
Given $\left(M,M'\right) \in R \implies \left(\application{Z}{M}, \application{Z}{M'} \right) \in R$ choose $\context{C}{} \equiv \application{Z}{\context{}{}}$ and it follows that $\left(M,M'\right) \in R \implies \left( \context{C}{M}, \context{C}{M'} \right) \in R$. Similarly for the other cases. Together they would cover all cases of contexts with one hole and thus the condition of statement 2.
It took me quite some time to perceive the importance of the restriction with one hole in Statement 1 (Barendregt's original definition).
Is this a correct way to prove the equivalence between the mentioned statements or I am missing something here?
What bothers me is that in (*) there are actually infinitely many contexts with one hole that can be generated from the rules (e.g. $\application{Z}{\application{A}{\context{}{}}}$ or $\abstraction{x}{\application{Z}{\context{}{}}}$).