Algorithm Search⌘K

Proofs: Antimirov partial derivatives

These are the human proofs of Antimirov partial derivatives, at full length.

The partial derivative automaton accepts L(r) and has at most k + 1 states full

This proof shows: correctness, termination.

Throughout, expressions are compared as terms (trees), ν\nu and S⊙tS \odot t are as on the main page, and ∂ax\partial_a x is the set computed by lines L9 to L13. For a set SS of expressions write L(S)=⋃z∈SL(z)L(S) = \bigcup_{z \in S} L(z), and let #x\#x be the number of symbol occurrences in xx.

Lemma 1. ν(x)\nu(x) is true if and only if ε∈L(x)\varepsilon \in L(x).

Proof. By induction on xx: ε∉L(∅)\varepsilon \notin L(\emptyset) and ε∉L(b)\varepsilon \notin L(b); ε∈L(ε)\varepsilon \in L(\varepsilon) and ε∈L(s∗)\varepsilon \in L(s^*); ε∈L(s)∪L(t)\varepsilon \in L(s) \cup L(t) iff it is in one of them; and ε∈L(s)L(t)\varepsilon \in L(s) L(t) iff it is in both, since uv=εuv = \varepsilon forces u=v=εu = v = \varepsilon. □\square

Lemma 2. L(S⊙t)=L(S) L(t)L(S \odot t) = L(S)\, L(t).

Proof. If t=∅t = \emptyset, both sides are empty. If t=εt = \varepsilon, both sides are L(S)L(S). Otherwise each z∈Sz \in S contributes L(zt)=L(z)L(t)L(zt) = L(z) L(t), or L(t)=L(ε)L(t)L(t) = L(\varepsilon) L(t) when z=εz = \varepsilon, and the union over zz is L(S)L(t)L(S) L(t). □\square

Lemma 3. For every expression xx and symbol aa, L(∂ax)=a−1L(x)L(\partial_a x) = a^{-1} L(x), where a−1L={v:av∈L}a^{-1}L = \{v : av \in L\}.

Proof. By induction on xx. For ∅\emptyset and ε\varepsilon, no word of L(x)L(x) starts with aa, and line L9 returns ∅\emptyset. For a symbol bb, a−1{b}a^{-1}\{b\} is {ε}\{\varepsilon\} if b=ab = a and empty otherwise, as at line L10. For s∣ts \mid t, a−1a^{-1} distributes over union (line L11). For stst: av∈L(s)L(t)av \in L(s) L(t) iff either av=(au)v′av = (au) v' with au∈L(s)au \in L(s) and v′∈L(t)v' \in L(t), so v∈(a−1L(s))L(t)v \in (a^{-1}L(s)) L(t), or ε∈L(s)\varepsilon \in L(s) and av∈L(t)av \in L(t). By the induction hypothesis, Lemma 1 and Lemma 2, this is L(∂as⊙t)∪L(∂at)L(\partial_a s \odot t) \cup L(\partial_a t) when ν(s)\nu(s) holds and L(∂as⊙t)L(\partial_a s \odot t) otherwise, as at line L12. For s∗s^*: av∈L(s∗)av \in L(s^*) iff av=u1u2⋯ujav = u_1 u_2 \cdots u_j with all ui∈L(s)u_i \in L(s); dropping the empty factors, the first factor is aua u with au∈L(s)au \in L(s) and the rest is in L(s∗)L(s^*). So a−1L(s∗)=(a−1L(s))L(s∗)a^{-1}L(s^*) = (a^{-1}L(s)) L(s^*), which is L(∂as⊙s∗)L(\partial_a s \odot s^*) by Lemma 2, as at line L13. □\square

For a word uu, ∂εx={x}\partial_\varepsilon x = \{x\} and ∂uax=⋃y∈∂ux∂ay\partial_{ua} x = \bigcup_{y \in \partial_u x} \partial_a y. By induction on uu and Lemma 3, L(∂ux)=u−1L(x)L(\partial_u x) = u^{-1} L(x), since (ua)−1L=a−1(u−1L)(ua)^{-1} L = a^{-1}(u^{-1} L) and a−1a^{-1} distributes over union.

Definition. π(∅)=π(ε)=∅\pi(\emptyset) = \pi(\varepsilon) = \emptyset, π(b)={ε}\pi(b) = \{\varepsilon\}, π(s∣t)=π(s)∪π(t)\pi(s \mid t) = \pi(s) \cup \pi(t), π(st)=(π(s)⊙t)∪π(t)\pi(st) = (\pi(s) \odot t) \cup \pi(t) and π(s∗)=π(s)⊙s∗\pi(s^*) = \pi(s) \odot s^*.

Lemma 4. ∣π(x)∣≤#x|\pi(x)| \le \#x.

Proof. By induction, using ∣S⊙t∣≤∣S∣|S \odot t| \le |S|, which holds because ⊙\odot maps each member of SS to at most one term: ∣π(st)∣≤∣π(s)∣+∣π(t)∣≤#s+#t|\pi(st)| \le |\pi(s)| + |\pi(t)| \le \#s + \#t, and the other cases are similar. □\square

Lemma 5. For every expression xx and symbol aa: (i) ∂ax⊆π(x)\partial_a x \subseteq \pi(x), and (ii) ∂ay⊆π(x)\partial_a y \subseteq \pi(x) for every y∈π(x)y \in \pi(x).

Proof. By induction on xx. Note that S⊆S′S \subseteq S' implies S⊙t⊆S′⊙tS \odot t \subseteq S' \odot t.

  • x=∅x = \emptyset or ε\varepsilon: ∂ax=π(x)=∅\partial_a x = \pi(x) = \emptyset.
  • x=bx = b: ∂ab⊆{ε}=π(b)\partial_a b \subseteq \{\varepsilon\} = \pi(b), and the only y∈π(b)y \in \pi(b) is ε\varepsilon, with ∂aε=∅\partial_a \varepsilon = \emptyset.
  • x=s∣tx = s \mid t: both parts follow from the induction hypothesis for ss and tt, since π(x)\pi(x) is the union of π(s)\pi(s) and π(t)\pi(t).
  • x=stx = st: (i) ∂ax\partial_a x is ∂as⊙t\partial_a s \odot t, possibly with ∂at\partial_a t, which are subsets of π(s)⊙t\pi(s) \odot t and π(t)\pi(t) by (i) for ss and tt. (ii) If y∈π(t)y \in \pi(t), use (ii) for tt. Otherwise y∈π(s)⊙ty \in \pi(s) \odot t, so t≠∅t \ne \emptyset and yy comes from some z∈π(s)z \in \pi(s). If t=εt = \varepsilon, then y=zy = z and ∂ay⊆π(s)=π(s)⊙t\partial_a y \subseteq \pi(s) = \pi(s) \odot t by (ii) for ss. If z=εz = \varepsilon, then y=ty = t and ∂at⊆π(t)\partial_a t \subseteq \pi(t) by (i) for tt. Otherwise yy is the term ztzt, and ∂ay\partial_a y is ∂az⊙t\partial_a z \odot t, possibly with ∂at\partial_a t; by (ii) for ss, ∂az⊆π(s)\partial_a z \subseteq \pi(s), and by (i) for tt, ∂at⊆π(t)\partial_a t \subseteq \pi(t).
  • x=s∗x = s^*: (i) ∂ax=∂as⊙s∗⊆π(s)⊙s∗\partial_a x = \partial_a s \odot s^* \subseteq \pi(s) \odot s^*. (ii) yy comes from some z∈π(s)z \in \pi(s), and s∗s^* is neither ∅\emptyset nor ε\varepsilon. If z=εz = \varepsilon, then y=s∗y = s^* and (i) applies. Otherwise yy is the term zs∗z s^*, and ∂ay\partial_a y is ∂az⊙s∗\partial_a z \odot s^*, possibly with ∂a(s∗)=∂as⊙s∗\partial_a(s^*) = \partial_a s \odot s^*; both are subsets of π(s)⊙s∗\pi(s) \odot s^* by (ii) and (i) for ss. □\square

Lemma 6. Every set QQ built by lines L1 to L7 satisfies Q⊆{r}∪π(r)Q \subseteq \{r\} \cup \pi(r), so ∣Q∣≤k+1|Q| \le k + 1.

Proof. Line L1 starts with {r}\{r\}. A term yy is added at line L7 only when y∈∂axy \in \partial_a x for some x∈Qx \in Q, and by Lemma 5, ∂ar⊆π(r)\partial_a r \subseteq \pi(r) and ∂ax⊆π(r)\partial_a x \subseteq \pi(r) for x∈π(r)x \in \pi(r). The size bound is Lemma 4. □\square

Termination. Each pass of the loop at lines L2 to L7 pops one term, and a term is pushed only when it is added to QQ, at most once. By Lemma 6, at most k+1k + 1 terms are ever pushed, so the loop runs at most k+1k + 1 times. Each call PARTIAL(x,a)(x, a) ends: it processes the finitely many nodes below xx, each once per symbol because of the memo. The loop at lines L16 to L17 runs nn times.

Lemma 7. After line L8, for every x∈Qx \in Q and symbol aa, the moves of TT from xx on aa lead exactly to ∂ax\partial_a x; for a symbol cc that does not occur in rr, ∂cx=∅\partial_c x = \emptyset.

Proof. Every x∈Qx \in Q is pushed once and popped once, and when it is popped, lines L4 to L6 add the moves (x,a,y)(x, a, y) for all y∈∂axy \in \partial_a x and all symbols aa of rr. A term x∈Qx \in Q is rr or a member of π(r)\pi(r), whose symbols all occur in rr; by Lemma 3, L(∂cx)=c−1L(x)=∅L(\partial_c x) = c^{-1} L(x) = \emptyset, and by line L10, a term without the symbol cc has ∂cx=∅\partial_c x = \emptyset. □\square

Theorem. PD-MATCH(r,w)(r, w) returns true if and only if w∈L(r)w \in L(r).

Proof. By Lemma 7 and induction on ii, the set SS after ii rounds of line L17 is ∂a1⋯air\partial_{a_1 \cdots a_i} r. If line L17 returns false, SS is empty, so L(∂a1⋯air)=(a1⋯ai)−1L(r)L(\partial_{a_1 \cdots a_i} r) = (a_1 \cdots a_i)^{-1} L(r) is empty and no word that starts with a1⋯aia_1 \cdots a_i is in L(r)L(r), in particular not ww. Otherwise, line L18 returns whether some x∈∂wrx \in \partial_w r has ν(x)\nu(x), which by Lemma 1 holds iff ε∈L(∂wr)=w−1L(r)\varepsilon \in L(\partial_w r) = w^{-1} L(r), that is, iff w∈L(r)w \in L(r). ■\blacksquare

Back to Antimirov partial derivatives