Answer
- **(a)** The string `()(()` is **not** in \(P\).
- **(b)** The string `(()()))(()` is also **not** in \(P\).
Neither \(\texttt{()(()}\) nor \(\texttt{(()()))(()}\) can be derived using the given formation rules for \(P\). In particular,
1. \(\texttt{()(()}\) has an *odd* number of parentheses, while all members of \(P\) must have an even number.
2. \(\texttt{(()()))(()}\) has even length but fails the well-formedness check (its balance goes negative at some point).
Hence, **both** strings are excluded from \(P\).
Work Step by Step
Below is a sketch of a **structural induction** proof (sometimes also called an **inductive proof on the formation rules**) that shows why neither string can be generated by the given rules.
---
## Definition Recap (Example 5.9.4)
The set \(P\) of “legal” (well-formed) parenthesis configurations is defined by:
1. **Base Case:** \(\texttt{()}\in P.\)
2. **Rule 1 (Wrapping):** If \(E\in P\), then \(\texttt{(}E\texttt{)} \in P.\)
3. **Rule 2 (Concatenation):** If \(E\in P\) and \(F\in P\), then the concatenation \(EF \in P.\)
4. **Restriction:** No other parenthesis configurations are in \(P\) except those generated by the above rules.
---
## Part (a): \(\texttt{()(()}\)
1. **Count of Parentheses:**
The string \(\texttt{()(()}\) has 5 characters total:
\[
\texttt{()(()} = \texttt{( ) ( ( )}.
\]
That is 3 left parentheses and 2 right parentheses.
2. **All Strings in \(P\) Have Even Length:**
By structural induction on the formation rules, one can show that **any** string in \(P\) has an *even* number of parentheses:
- **Base:** \(\texttt{()}\) has length \(2\) (even).
- **Rule 1:** If \(E\) has an even number of parentheses, then \(\texttt{(}E\texttt{)}\) adds exactly 2 more parentheses, giving an even total.
- **Rule 2:** If \(E\) and \(F\) each have an even number of parentheses, then their concatenation \(EF\) has even \(+\) even = even parentheses.
Since \(\texttt{()(()}\) has length \(5\) (which is *odd*), it cannot be in \(P\).
Hence,
\[
\boxed{\texttt{()(()} \notin P.}
\]
---
## Part (b): \(\texttt{(()()))(()}\)
Now consider the string
\[
\texttt{(()()))(()},
\]
which has 10 parentheses in total. Merely having an even number of parentheses does *not* guarantee membership in \(P\). We need to check whether it can be built by the formation rules.
### Approach 1: Prefix-Balance (Negative Partial Sums)
A well-known necessary (and sufficient) property of any well-formed parentheses string is:
> **No prefix of the string ever has more right parentheses than left parentheses.**
Equivalently, if we scan from left to right, counting `(` as +1 and `)` as −1, the “running total” (or balance) should never go negative, and it should end at 0.
Let us track the balance of \(\texttt{(()()))(()}\) by positions:
1. `(`: balance = 1
2. `(`: balance = 2
3. `)`: balance = 1
4. `(`: balance = 2
5. `)`: balance = 1
6. `)`: balance = 0
7. `)`: balance = −1 ← **goes negative here**
8. `(`: balance = 0
9. `(`: balance = 1
10. `)`: balance = 0
At position 7, the balance becomes −1, which violates the well-formedness condition. Hence the string is *not* in \(P\).
### Approach 2: Attempting to Derive It by the Rules
Suppose for contradiction that \(\texttt{(()()))(()}\in P\). By the formation rules, there are two ways a string can be in \(P\):
1. **Rule 1 Form \((E)\):** The entire string would start with `(` and end with the matching `)` that brings the balance back to zero *for the first time*. Scanning from the start, the balance first returns to zero at position 6. That means if the string were of the form \((E)\), it would be
\[
\underbrace{\texttt{( } E \texttt{ )}}_{\text{positions 1..6}} \quad \text{plus leftover characters}.
\]
The substring from positions 2..5 is \(\texttt{()()}\), which is indeed in \(P\). So positions 1..6 form \(\texttt{(()())}\), a valid piece in \(P\). **But** the entire string has 10 characters, so there are 4 leftover characters (positions 7..10), meaning the whole string is not purely of the form \((E)\).
2. **Rule 2 Form \(EF\):** Then the string must split as a concatenation \(E F\) with \(E,F \in P\). For that to happen, there must be some position \(k\) such that:
- The substring from 1..\(k\) is in \(P\).
- The substring from \(k+1\)..10 is in \(P\).
The natural place to split is where the “balance” first returns to zero when reading left to right. That happens at position 6, giving:
\[
E = \texttt{(()())}, \quad F = \texttt{)(()}.
\]
We already noted \(E = \texttt{(()())}\) is indeed in \(P\). But \(F = \texttt{)(()}\) starts with `)`, which cannot be in \(P\) (its prefix balance is negative immediately). No other split aligns with a zero balance *without* going negative in between. Thus there is no valid way to write the entire string as \(EF\) with \(E,F\in P\).
Both arguments show \(\texttt{(()()))(()}\) fails to be in \(P\). Therefore,
\[
\boxed{\texttt{(()()))(()} \notin P.}
\]