Structural Induction removing specific character from word

226 Views Asked by At

Define, by structural induction, a function $f : A^* \to A^*$ that removes all occurrences of the letter $a$. For instance, we should have $f(abcbab) = bcbb$ and $f(bc) = bc$.

I came up with this:

$f(\lambda) = \lambda$ (empty word)

$f(xw) = xf(w)$ if $x$ is not $a$

$f(w)$, otherwise.

But I have no idea if this is sufficient and if its a structural induction.

Thanks in advance

2

There are 2 best solutions below

2
On

You have the right idea but I would make the removal of $a$ the explicit case:

$f(\lambda) = \lambda$

$f(aw) = f(w)$

$f(xw) = xf(w) \ otherwise$

0
On

Your $f$ is a monoid morphism from $A^*$ to itself. Therefore, denoting $1$ the neutral element of $A^*$ (aka the empty word), it suffices to set $f(1) = 1$, $f(a) = 1$, $f(b) = b$ if $b \not= a$ and $f(uc) = f(u)f(c)$ for all words $u$ and letter $c$.