0
$\begingroup$

I am going over some excercises from the excellent Models of Computation book-thing and I have difficulties formulating a proposition to prove.

We have a definition of substring available, which using an array-indexed notation for strings and goes as follows:

$$ w[i..j] := \epsilon\ if\ j

And from it we also have the notion of prefix, which is defined as any substring of the form: $$w[1..j]$$

We are then asked to prove that for any string s of length n, there exist exactly n + 1 prefixes. I have problems formulating the proposition. My idea so far would be to create a definition to enumerate all prefixes of an arbitrary string of length w and use the size of the aforementioned set to formulate the following:

$$ \forall s \in string, |enumPrefixes(s)| = |s| + 1 $$

However I am not sure if I can add a new definition and also it feels like there should be a simpler way.

  • 0
    Maybe by induction... Is $\epsilon$ a substring of any string $s$ ? if so, a string $s$ of lenght $1$ (i.e. $|s|=1$) must have two prefixes : $\epsilon$ and $s[1..1]=s$ itself.2017-02-10
  • 0
    @MauroALLEGRANZA sure, the induction here is quite straightforward, but is it ok for me to have an additional definition that creates a set of all prefixes? - funnily enough, could I introduce a definition to compute the number of prefixes directly (0 if empty, fix f (head . tail) = 1 + f tail if non empty) and then somehow correlate my definition to the notion of prefixes provided by the author? I am not sure how to use the array notation to express that I want: w[1..|w|] U w[1..|w| - 1] U .. U epsilon.2017-02-10
  • 0
    I've just realized I said 0 if empty, it's of course 1 if empty.2017-02-10

0 Answers 0