Domanda

Il seguente algoritmo è supposto per confrontare due stringhe $S_1$ e $S_2$ ("/\" per la stringa vuota):

X = S1   
Y = S2

E = true   
// (1) S1 = S2 <=> X = Y and E = true
while X != /\ and Y != /\ and E == true          
  if head(X) == head(Y)           
    X = tail(X)
    Y = tail(Y)
  else
    E = false
// (2) S1 = S2 <=> X = /\ and Y = /\ and E = true
if !(X == /\ and Y == /\)    
  E = false 
  // (3) S1 != S2 and E = false
else // an empty else; just for inserting an assertion (i.e., 3' below) here
  // (3') S1 = S2 <=> E = true
// (4) S1 = S2 <=> E = true
return E

Ci sono cinque invarianti:

(1).$S_1 = S_2 \iff X = Y \in terra E = true$

(2).$S_1 = S_2 \iff X = \Lambda \in terra Y = \Lambda \in terra E = true$

(3).$S_1 eq S_2 erra E = false$

(3').$S_1 = S_2 \iff E = true$

(4).$S_1 = S_2 \iff E = true$

Sono in grado di capire queste invarianti e come essi sono derivati da quelli precedenti in modo intuitivo e così informale.Per esempio, possiamo derivare la (3') dalla (2) come segue:

Al punto (2), sappiamo che $S_1$ uguale a $S_2$ se e solo se $X = \Lambda \in terra Y = \Lambda \in terra E = true$.Al punto (3), si è ulteriormente sappiamo che $X = \Lambda \in terra Y = \Lambda$.Quindi, a questo punto, dobbiamo solo verificare se $E = true$ decidere se $S_1 = S_2$ detiene.

Tuttavia, il ragionamento di cui sopra non può essere giustificato con le convenzionali regole di inferenza della logica proposizionale che ci sarebbe

$$S_1 = S_2 \iff (X = \Lambda \in terra Y = \Lambda \in terra E = true) \land (X = \Lambda \in terra Y = \Lambda),$$ che è di $S_1 = S_2 \iff X = \Lambda \in terra Y = \Lambda \in terra E = true.$


Problema: Quali sono le regole di inferenza per la derivazione da (2) a (3')?

Related Post: Lo sviluppo di invarianti per confrontare due stringhe


Edit: Come sottolineato da @chi in commento, dovrebbe essere $$\big(S_1 = S_2 \iff (X = \Lambda \in terra Y = \Lambda \in terra E = true)\big) \land (X = \Lambda \in terra Y = \Lambda),$$ il che implica (3') $S_1 = S_2 \iff E = true$ come, la risposta di @kne mostra.

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a cs.stackexchange
scroll top