• Aucun résultat trouvé

First-Order Rewriting

N/A
N/A
Protected

Academic year: 2022

Partager "First-Order Rewriting"

Copied!
34
0
0

Texte intégral

(1)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

First-Order Rewriting

(2)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Rewriting System

Arewriting ruleis a pair of termsl7→rsuch thatlis not a variable andVar(r)⊆Var(l). Arewriting systemis a set of rewriting rules.

Given a rewriting systemR, therewriting relation→R is generated by the following rules:

l7→r∈ R θ(l)→R θ(r)

s→R t u[s]pR u[t]p

The notation→+Ris used for the transitive closure of→R and→Rfor the reflexive-transitive closure of→R.

RemarkThis definition implies that ift→R u, then there is a rewriting rulel7→r∈ R, a substitutionσ, a termv, and a positionp∈Pos(v)such thatt=v[σ(l)]pandu=v[σ(r)]p.

(3)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Example

Rewriting system for Peano arithmetic:

0+y → y

s(x)+y → s(x+y)

0∗y → 0

s(x)∗y → (x∗y)+y Reduction sequence:

2∗3=s(s(0))∗s(s(s(0))) → [s(0)∗s(s(s(0)))]+s(s(s(0))) → [[0∗s(s(s(0)))]+s(s(s(0)))]+s(s(s(0))) → [0+s(s(s(0)))]+s(s(s(0))) →

s(s(s(0)))+s(s(s(0))) →

s(s(s(0))+s(s(s(0)))) →

s(s(s(0)+s(s(s(0))))) →

s(s(s(0+s(s(s(0)))))) →

s(s(s(s(s(s(0))))))=6

(4)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence

(5)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Motivations

Confluence is an undecidable property.

(6)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Decision procedures

Sound methods Terminating methods

(7)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Some techniques to show confluence

Confluence by strong confluence Confluence by diamond property Confluence by equivalence Confluence by commutation Confluence by interpretation Confluence by critical pairs Confluence by orthogonality Confluence by decreasing diagrams

(8)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence by strong confluence

Recall thatRisstrongly confluent (SC)iff

s →R t

R∗R

u →=R v

Example

R=









f(x,x) 7→ g(x) f(x,y) 7→ g(y) g(x) 7→ f(x,a) We only check one-step diagrams.

(9)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Theorem

IfRisstrongly confluent, thenRisconfluent.

Proof.

Lets→ntands→mu. We reason by induction onhn,miusing the lexicographic order.

Ifn=0orm=0, then the property is trivial.

Ifn>0andm>0, we haves→1t0n−1tands→1u0m−1u.

By using the hypothesis we havet0vetu0=v. We thus consideru0=vand u0m−1u, we remark thath1/0,m−1i<lexhn,mi, and thus by the i.h. there isv0 such thatv→v0etu→v0.

Now, we considert0n−1tandt0v→v0, we remark thathn−1,ki<lexhn,mifor anyk, and thus by the i.h.tandv0are joinable, and this close the whole diagram.

(10)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence by diamond property

Recall thatRhas thediamond property (DP)iff

s →R t

RR

u →R v

This is a particular case of strongly confluence.

Corollary

IfRhas thediamond property, thenRisconfluent.

(11)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence by equivalence

Theorem

LetRandStwo rewrite systems such that→R⊆→S⊆→RandSisstrongly confluent.

ThenRisconfluent.

Proof.

If→R⊆→S⊆→R, then→R=→S.

IfSis strongly confluent, thenSis confluent.

If→R=→S, thenRis confluent iffSis confluent.

(12)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

(Famous) Example: confluence of β

Show that(λx.t)u7→βt{x\u}is confluent.

Define a relationas follows:

xx

tt0 λx.tλx.t0

tt0anduu0 t ut0u0

tt0anduu0 (λx.t)ut0{x\u0}

LetR=βand letS=. Now,

1 Show thatβ ⊆ ⊆ β.

2 Show thatis strongly confluent.

3 Conclude thatβis confluent (on all the terms).

(13)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence by commutation [Hindley-Rosen]

Two systemsRandSare said tocommuteiff

s →R t

∗S∗S

u →R v Two systemsRandSare said tostrongly commuteiff

s →R t

S∗S

u →=R v

(14)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Strong Commutation

Theorem

IfRandSstrongly commute, then theycommute.

Proof.

Lets→nRtands→mSu. We reason by induction onhn,miusing the lexicographic order.

Ifn=0orm=0, then the property is trivial.

Ifn>0andm>0, thens→1Rt0n−1R t.s→1Su0m−1S u. By the hypothesisu0=Rvandt0Sv.

Now, we consideru0=Rvandu0mS1u, we remark thath0/1,m−1i<lexhn,mi, so by the i.h.u→Rv0andv→Sv0.

Similarly,t0n−1R tandt0Sv0, we remark thathn−1,ki<lexhn,mifor anyk, and then the diagram closes by the i.h.

(15)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Theorem

IfRandSare bothconfluentandcommute, thenR∪Sisconfluent.

Proof.

Lets→R∪Stands→R∪Su. We decompose both sequences ass→RS. . .→RSt ands→RS. . .→RSu.

Intuitively, the steps withRare closed by confluence ofR, and the steps withSare closed by confluence ofS. The other ones by commutation.

Formally,

We show→R∪S⊆→RS⊆→R∪S

We remark that→RSis strongly confluent.

We apply confluence by equivalence.

(16)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

(Famous) Example: confluence of βη

Example

(λx.t)u 7→β t{x\u}

λx.t x 7→η t Ifx<fv(t)

LetR=βandS=η. Now,

Show thatβis confluent (done).

Show thatηis confluent.

Show thatβandηstrongly commute.

Conclude thatβ∪ηis confluent.

(17)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence by interpretation

Theorem

LetRandSbe two relations s.t.Ris confluent and terminating. If there is a relationT on the set ofR-normal forms s.t.

1T ⊆ →R∪Sand

2 a→S bimpliesR(a)→T R(b)

3 T is confluent ThenR∪Sis confluent.

Proof.

Lets→R∪Stands→R∪Su.

SinceRis confluent and terminating we can computeR-normal formss→RR(s), t→RR(t), andu→RR(u).

We can then simulate the first two→R∪S-sequences byR(s)→T R(t)andR(s)→T R(u) using point 2.

We can close this divergence byR(t)→T vandR(u)→T vusing point 3.

We obtainR(t)→R∪SvandR(u)→R∪Svusing point 1.

We thus conclude sincet→RR(t)→R∪Svandu→RR(u)→R∪Sv.

(18)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

(Famous) Example: confluence of λx

(λx.t)u 7→B t[x/u]

(t u)[x/v] 7→x (t[x/v]u[x/v])

(λy.t)[x/v] 7→x λy.t[x/v] ifx,y&y<fv(v)

y[x/v] 7→x y ifx,y

x[x/v] 7→x v LetR=xandS=BandT =β, Now,

Show thatxis confluent and terminating.

Show thatβ⊆(x∪B).

Show thata→B bimpliesx(a)→βx(b). Sinceβis confluentλx=x∪Bis confluent.

(19)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence by critical pairs

Lemma

(Newmann)LetRbe aSNsystem. ThenRislocally confluentiffRisconfluent.

Proof.

(By Huet) By well-founded induction ons∈S N.

s → t0 t

↓ ↓

u0 v i.h. sincet0<s ↓

i.h. sinceu0<s ↓

u → p → p0

(20)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Important remark

The following (infinite) system on natural numbers:

R=













2.n 7→ 2.n+1

2.n 7→ a

2.m+1 7→ 2.m+2

2.m+1 7→ b

islocally confluentbut notconfluent:a←0→b In fact it is not SN

0→ 1→ 2→ 3→ . . .

(21)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Towards local confluence: critical pairs

Acritical pairbetween twovariable disjoint rulesl7→randg7→dofR(not necessarily distinct rules) is a pairhσ(r), σ(l)[σ(d)]pis.t.

1 p∈Pos(l)andl|pis not a variable.

2 σis a principal unifier ofl|pandg.

3 Ifl7→randg7→dare the same rule, thenp,Λ.

Observe that

σ(r)←σ(l) =σ(l)[σ(l)|p]p

=σ(l)[σ(l|p)]p

=σ(l)[σ(g)]p→ σ(l)[σ(d)]p

(22)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Example

R=









f(g(x),g(y),a) 7→r1 j(x,x,a)

g(b) 7→r2 b

h(b) 7→r3 b

The critical pairs are in red:

j(b,b,a)r1← f(g(b),g(y),a)→r2 f(b,g(y),a) (r1,r2,pos=1) j(x,x,a)r1← f(g(x),g(b),a)→r2 f(g(x),b,a) (r1,r2,pos=2)

Putting the information in a table:

r1 r2 r3

r1 X positions=1,2 X

r2 X X

r3 X

(23)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Example

R=









f(f(x)) 7→r1 g(x) f(b) 7→r2 c

b 7→r3 a

The critical pairs are in red:

g(f(x)) r1← f(f(f(x))) →r1 f(g(x)) (r1,r1,pos=1) g(b) r1← f(f(b)) →r2 f(c) (r1,r2,pos=1) c r2← f(b) →r3 f(a) (r2,r3,pos=1)

Putting the information in a table:

r1 r2 r3

r1 positions=1 positions=1 X

r2 X positions=1

r3 X

(24)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Local confluence by critical pairs

Theorem

LetRbe a rewrite system. ThenRis locally confluent iff every critical pair ofRis joinable.

Proof.

Theonly ifimplication is trivial.

For theifimplication, let us take any case of the form

v←t→ u Three cases are possible:

Disjoint reductions:

f(b,h(b),a) ← f(g(b),h(b),a) → f(g(b),b,a) f(b,h(b),a) → f(b,b,a) ← f(g(b),b,a)

Not disjoint and not critical:

j(h(b),h(b),a) ← f(g(h(b)),g(b),a) → f(g(b),g(b),a)

↓ ↓

j(b,h(b),a) → j(b,b,a)

Not disjoint and critical: we close the diagram by the hypothesis.

(25)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Decidable case of confluence

Theorem

LetRbe afiniteandSNrewrite system. Then confluence ofRis decidable.

Proof.

The algorithm:

1 Generate all the critical pairs.

2 For each critical pairhu,vi, if there issomenormal formbuofuandsomenormal formbvofvsuch thatbu,bv, thenfail.

3 Otherwise (no fail for some critical pair),succeed.

Remark that

If the algorithm fails, then there is a critical pair which is not joinable, soRis not confluent by the previous theorem.

If the algorithm succeeds, then every critical pair is joinable, so thatRis locally confluent by the previous theorem. To obtain confluence, apply Newmann’s Lemma.

(26)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Orthogonal Systems

A system isorthogonaliff it isleft linear(no duplication of variables on the left of rules) andhas no critical pairs.

Example

0+y 7→ y

s(x)+y 7→ s(x+y)

0∗y 7→ 0

s(x)∗y 7→ (x∗y)+y

(27)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence by orthogonality

Theorem

IfRis orthogonal, then it is confluent.

Proof.

We define a notion ofparallel reductionassociated toRfor first-order terms:

sRs (R) l7→r∈ Randσa subst.

σ(l)Rσ(r) (S) s1Rt1. . . .snRtn

f(s1, . . . ,sn)R f(t1, . . . ,tn) (C) Example:

ForR={f(x,y)7→h(y,y),a7→b}, we have f(f(a,c),a,f(a,c))R f(h(c,c),b,f(b,c))

Now use theconfluence by equivalencetechnique:

1 Observe that→RR ⊆ →R.

2 Show thatRhas the diamond property.

3 Conclude that→R is confluent.

Obs: from now on, we simply writeinsted ofRisRis clear from the context.

(28)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

The relation has the diamond property

Defineσδfor two substitutions iffdom(σ)=dom(δ)andσxδxfor everyx∈dom(σ).

Lemma (A)

Ifσδ, thenσtδtfor every termt.

Proof.

By induction ont.

(29)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Lemma (B)

LetRbe an orthogonal rewriting system. Letσbe a substitution. Letsbe a strict subterm ofl, wherel7→r∈ R. Ifσst, then there isδs.t.t=δsandσδ.

The proof is by induction ons.

Ifs=x, then defineδx=tandδy=σyfory,x.

Ifs= f(s1, . . . ,sn), we distinguish three cases according to the definition ofσst. Ifσstholds by(R), thent=σsand thus we simply letδ:=σ.

Ifσstholds by(S), then there is some ruleg7→d∈ Rand some substitutionτsuch thatσs=τgandt=τd. We can assumel7→randg7→ddo not share variables and thus(σ∪τ)s=σs=τg=(σ∪τ)g. Thenσ∪τunifiess(a strict subterm ofl) andg, thus contradictingabsence of critical pairs, and thusorthogonalityofR.

Ifσstholds by(C), thent=f(t1, . . . ,tn)andσsiti. Sincel(and thuss) arelinear, we can writeσasSσi, where eachσiisσrestricted to the variables ofsi. We then haveσisitiandsiis a strict subterm ofl. The i.h. givestiisiandσiδi. We take δ:=Sδi. It is easy to checkσδandt=δs.

(30)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Theorem

LetRbe an orthogonal system andits associated parallel reduction relation. The reduction relationhas the diamond property.

Proof.

Suposett1andtt2. We reason by cases.

If one of them uses(R), then we trivially close the diagram.

If both use(S), thent=σl,t1=σr,t=δgandt2=δdforl7→randg7→dinR. If the two rules are the same, thenσ=δand we trivially close the diagram.

Otherwise, we can assume that the rules do not share variables so

that(δ∪σ)l=σl=t=δg=(σ∪δ)g,i.e.(δ∪σ)unifieslandg, which contradicts absence of critical pairs, and thusorthogonalityofR.

If both use(C), the property trivially holds by the i.h.

Suppose one uses(C)and the other one uses(S). We have

t=f(v1, . . . ,vn) f(u1, . . . ,un)=t1whereviuiandt=σlσr=t2for some rulel7→r∈ Rand some substitutionσ. The left-hand sidelis necessarily of the form f(l1, . . . ,ln)so thatt=f(v1, . . . ,vn)=f(σl1, . . . , σln)andσliui. Butlis linearso that we can writeσ=Sn

1σiwhereσiliui. Each termliis a strict subterm oflso that byLemma (B)there are substitutionsδisuch thatuiiliand σiδi. We letδ:=Sn

1δi. Thent1=f(δ1l1, . . . , δnln)=δland alsoσδ. We can now close the diagram witht3=δras follows

t1=δlδr=t3holds using the(S)rule.

t2=σrδr=t3holds byLemma (A)using the fact thatσδ.

(31)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Important remark (I)

Left linearity alone is not sufficient for confluence.

Example

a 7→ b b 7→ a c 7→ a

a 7→ c b 7→ d c 7→ e

Two not joinable terms:

e ←a→ d

(32)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Important remark (II)

Absence of critical pairs is not sufficient for confluence.

Example

f(x,x) 7→ a f(x,g(x)) 7→ b

c 7→ g(c)

Two not joinable terms:

b ← f(c,c)→a

(33)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Relaxing orthogonality

por(t,x) 7→ t por(x,t) 7→ t This system is not orthogonal but the critical pair is trivial.

A systemRisparallel closediff for every critical pairhu,viofRwe havevu.

Theorem

IfRis left-linear and parallel closed then it is confluent.

(34)

Delia KESNER IRIF, CNRS et Universit ´e Paris [email protected] www.irif.fr/˜kesner

Confluence by decreasing diagrams

Vincent van Oostrom (1994) Idea: every reduction step islabelled

wheret→gS umeanst→s ufor somes<S,i.e.∃i∈ Ssuch thats<i. As a consequence,t→

glumeans that every step fromttouis labelled with somes0<l, andt→g{l,m}umeans that every step fromttouis labelled with somes0<max(l,m)(ifl andmare comparable).

Références

Documents relatifs

C’est la valeur absolue triviale

Confluence of graph transformation systems was first studied by Plump, who defined the notion of graph critical pairs and proved their completeness, but also showed that

Van Oostrom’s confluence theorems are abstract, their application to particular rewrite systems is non-trivial, and, indeed, no result prior to ours could show the

Son maximum se produira généralement 3 à 4 jours avant le maximum de la crue de la Loire, mais si on envisage comme pour les crues de type océanique la possibilité d'une nouvelle

Plus au sud encore (ZAC 2), sur l’an- cien site du Marché d’Intérêt National en cours de démolition, un quartier mix- te sera réalisé avec 2 500 logements neufs, des sièges

If a Thue system is known to be terminating, then local confluence – and hence confluence – holds if, and only if, each critical pair is convergent [15] (actually this is a more

Ces deux auteurs montrent comment r´ealiser les deux ´etapes (transformation de jauge pour se ramener au cas constant et d´etermination d’un syst`eme fondamental de solutions dans

« l’Europe centrale » est différente avant et après 1989 et ses rôles dans la logique discursive changent avec le temps. La mémoire collective politique agit donc d’une