Algorithms for Extended Alpha-Equivalence and Complexity Manfred - - PowerPoint PPT Presentation

algorithms for extended alpha equivalence and complexity
SMART_READER_LITE
LIVE PREVIEW

Algorithms for Extended Alpha-Equivalence and Complexity Manfred - - PowerPoint PPT Presentation

Algorithms for Extended Alpha-Equivalence and Complexity Manfred Schmidt-Schau, Conrad Rau, David Sabel Goethe-University, Frankfurt, Germany RTA 2013, Eindhoven, The Netherlands 1 Motivation GI-Completeness GC Applications -Calculus


slide-1
SLIDE 1

1

Algorithms for Extended Alpha-Equivalence and Complexity

Manfred Schmidt-Schauß, Conrad Rau, David Sabel Goethe-University, Frankfurt, Germany RTA 2013, Eindhoven, The Netherlands

slide-2
SLIDE 2

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Motivation

Reasoning, deduction, rewriting, program transformation . . . requires to identify expressions Functional core languages have (recursive) bindings, e.g.

letrec map = λf, xs.case xs of {[] -> []; (y : ys) -> (f y) : (map f ys)}; square = λx.x ∗ x; myList = [1, 2, 3] in map square myList

These bindings are sets, i.e. they are commutable Identify expressions upto extended α-equivalence: α-renaming and commutation of bindings

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 2/21

slide-3
SLIDE 3

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Questions

What is the complexity of deciding extended α-equivalence? Is there a difference for languages with non-recursive let? Find efficient algorithms for special cases. Complexity of extended α-equivalence in process calculi?

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 3/21

slide-4
SLIDE 4

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Extended α-Equivalence for let-languages

Abstract language CH with recursive let, where c ∈ Σ si ∈ LCH ::= x | c(s1, . . . , sar(c)) | λx.s | letrec x1 = s1; . . . ; xn = sn in s Extended α-Equivalence ≃α,CH in CH: s ≃α,CH t iff s

α∨comm,∗

← − − − − − → t where s α − → t is α-renaming C[letrec . . . ; xi = si; . . . , xj = sj; . . . in s]

comm

− − − − → C[letrec . . . ; xj = sj; . . . ; xi = si; . . . in s] CHNR: Variant of CH with non-recursive let instead of letrec

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 4/21

slide-5
SLIDE 5

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Graph Isomorphism

Graph Isomorphism Undirected graphs G1 = (V1, E1) and G2 = (V2, E2) are isomorphic iff there exists a bijection φ : V1 → V2 such that (v, w) ∈ E1 ⇐ ⇒ (φ(v), φ(w)) ∈ E2 Graph Isomorphism Problem (GI) Graph-isomorphism (GI) is the following problem: Given two finite (unlabelled, undirected) graphs G1 = (V1, E1) and G2 = (V2, E2), are G1 and G2 isomorphic? P ⊆ GI ⊆ NP GI is neither known to be in P nor NP-hard A lot of other isomorphism problems on labelled / directed graphs are GI-complete (see e.g. Booth & Colboum’ 79)

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 5/21

slide-6
SLIDE 6

Motivation GI-Completeness GC Applications π-Calculus Conclusion

GI-Hardness of Extended α-Equivalence

Theorem Deciding ≃α,CH is GI-hard. Proof: Polytime reduction of the Digraph-Isomorphism-Problem: Digraph G = (V , E) is encoded as: enc(G) = letrec EnvV , EnvE in x such that EnvV =

vi∈V {vi = a} where a ∈ Σ

EnvE =

(vi,vj)∈E{xi,j = c(vi, vj)} where c ∈ Σ

Verify: G1, G2 are isomorphic ⇐ ⇒ enc(G1) ≃α,CH enc(G2)

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 6/21

slide-7
SLIDE 7

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec u1 = a; u2 = a; u3 = a; x1,3 = c(u1, u3); x3,2 = c(u3, u2); x2,2 = c(u2, u2); x2,1 = c(u2, u1); x1,2 = c(u1, u2); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-8
SLIDE 8

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec u3 = a; u1 = a; u2 = a; x3,2 = c(u3, u2); x2,2 = c(u2, u2); x2,1 = c(u2, u1); x1,2 = c(u1, u2); x1,3 = c(u1, u3); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-9
SLIDE 9

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec u3 = a; u1 = a; u2 = a; x1,3 = c(u3, u2); x3,3 = c(u2, u2); x3,2 = c(u2, u1); x2,3 = c(u1, u2); x2,1 = c(u1, u3); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-10
SLIDE 10

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec u3 = a; u1 = a; u2 = a; x1,3 = c(u3, u2); x3,3 = c(u2, u2); x3,2 = c(u2, u1); x2,3 = c(u1, u2); x2,1 = c(u1, u3); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-11
SLIDE 11

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec u3 = a; v2 = a; u2 = a; x1,3 = c(u3, u2); x3,3 = c(u2, u2); x3,2 = c(u2, v2); x2,3 = c(v2, u2); x2,1 = c(v2, u3); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-12
SLIDE 12

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec u3 = a; v2 = a; u2 = a; x1,3 = c(u3, u2); x3,3 = c(u2, u2); x3,2 = c(u2, v2); x2,3 = c(v2, u2); x2,1 = c(v2, u3); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-13
SLIDE 13

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec u3 = a; v2 = a; v3 = a; x1,3 = c(u3, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, u3); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-14
SLIDE 14

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec u3 = a; v2 = a; v3 = a; x1,3 = c(u3, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, u3); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-15
SLIDE 15

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1); in x

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-16
SLIDE 16

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Example

v1 u3 v2 u1 u2 v3 letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1) in x letrec v1 = a; v2 = a; v3 = a; x1,3 = c(v1, v3); x3,3 = c(v3, v3); x3,2 = c(v3, v2); x2,3 = c(v2, v3); x2,1 = c(v2, v1); in x Isomorphism: { u1 → v2 , u2 → v3 , u3 → v1 }

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 7/21

slide-17
SLIDE 17

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Easy Variations / Consequences

Deciding ≃α,CH is still GI-hard if expressions are restricted to one-level letrecs (since our encoding uses a one-level letrec) Non-recursive let: Deciding ≃α,CHNR is GI-hard: Use enc(G) = let EnvV in (let EnvE in x) Hardness also holds for empty signature Σ:

replace a by a free variable xa, replace c(vi, vj) by let y = vi in vj

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 8/21

slide-18
SLIDE 18

Motivation GI-Completeness GC Applications π-Calculus Conclusion

GI-Completeness of Extended α-Equivalence

We use labelled digraph isomorphism Encode CH-expressions s into a labelled digraph G(s), example:

s = letrec x = y ; y = z in x

letrec

G(s) =

letvar letvar z var var in bind bind Full encoding is given in the paper Verify: G(s1), G(s2) are isomorphic iff s1 ≃α,CH s2 Theorem Deciding ≃α,CH is GI-complete.

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 9/21

slide-19
SLIDE 19

Motivation GI-Completeness GC Applications π-Calculus Conclusion

GI-Completeness of Extended α-Equivalence

We use labelled digraph isomorphism Encode CH-expressions s into a labelled digraph G(s), example:

s = letrec x = y ; y = z in x

letrec

G(s) =

letvar letvar z var var in bind bind Full encoding is given in the paper Verify: G(s1), G(s2) are isomorphic iff s1 ≃α,CH s2 Theorem Deciding ≃α,CH is GI-complete.

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 9/21

slide-20
SLIDE 20

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Special Case: Removing Garbage

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 10/21

slide-21
SLIDE 21

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Garbage Collection

Garbage collection (gc): removing unused bindings letrec x1 = s1; . . . ; xn = sn in t

gc

− − → t

if FV (t) ∩ {x1, . . . , xn} = ∅

letrec x1 = s1; . . . ; xn = sn; y1 = t1; . . . ; ym = tm in tm+1

gc

− − → letrec y1 = t1; . . . ; ym = tm in tm+1

if m+1

i=1 FV (ti) ∩ {x1, . . . , xn} = ∅

Expression s is garbage-free if it is in (gc)-normal form Lemma For every CH-expression, its (gc)-normal form can be computed in time O(n log n)

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 11/21

slide-22
SLIDE 22

Motivation GI-Completeness GC Applications π-Calculus Conclusion

The Garbage-Free Case

Theorem If s1, s2 are garbage free then s1 ≃α,CH s2 can be decided in O(n log n) where n = |s1| + |s2|. Informal argument: Since the s1, s2 are garbage free they can be uniquely traversed:

(letrec Env in s)∗ → (letrec Env in s∗) letrec . . . x = s . . . C[x∗] → letrec . . . x = s∗ . . . C[x]

(if x = s was not visited already)

. . .

This traversal can be used to fix an order of the bindings

letrec x1 = s1; . . . ; xn = sn in t → lrin(xπ(1) = sπ(1), . . . , xπ(n) = sπ(n), t)

Now usual algorithms for deciding α-equivalence of terms can be used (see e.g. Calv`

es & Fern´ andez ’10)

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 12/21

slide-23
SLIDE 23

Motivation GI-Completeness GC Applications π-Calculus Conclusion

The Garbage-Free Case (2)

Formal proof in the paper (sketch): Compute G(si), i = 1, 2 OO(·) removes all var-edges from G(si) resulting in OO(G(si))

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 13/21

slide-24
SLIDE 24

Motivation GI-Completeness GC Applications π-Calculus Conclusion

The Garbage-Free Case (2)

Formal proof in the paper (sketch): Compute G(si), i = 1, 2 OO(·) removes all var-edges from G(si) resulting in OO(G(si)) Since si are garbage-free, the graphs OO(G(si)) are rooted outgoing-ordered labelled digraphs (OOLDGs) Isomorphism of rooted OOLDGs can be decided in O(n log n) G(s1) and G(s2) are isom. iff OO(G(s1)) and OO(G(s2)) are isom. OOLDG: Labelled digraph s.t. v w1 w2 l1 l2 = ⇒ l1 = l2 Rooted OOLDG: weakly-connected exists root v: every other node is reachable from v

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 13/21

slide-25
SLIDE 25

Motivation GI-Completeness GC Applications π-Calculus Conclusion

The Garbage-Free Case (2)

Formal proof in the paper (sketch): Compute G(si), i = 1, 2 OO(·) removes all var-edges from G(si) resulting in OO(G(si)) Since si are garbage-free, the graphs OO(G(si)) are rooted outgoing-ordered labelled digraphs (OOLDGs) Isomorphism of rooted OOLDGs can be decided in O(n log n) G(s1) and G(s2) are isom. iff OO(G(s1)) and OO(G(s2)) are isom. OOLDG: Labelled digraph s.t. v w1 w2 l1 l2 = ⇒ l1 = l2 Rooted OOLDG: weakly-connected exists root v: every other node is reachable from v

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 13/21

slide-26
SLIDE 26

Motivation GI-Completeness GC Applications π-Calculus Conclusion

OOLDGs vs. OLDGs

v w1 w2 u1 u2 l1 l2 l3 l4 Outgoing ordered LDG (OOLDG): l1 = l2, but l3 = l4 or l3 = l1 allowed Ordered LDG (OLDG): {l1, l2, l3, l4} required to be pairwise distinct Remark: OOLDG-Isomorphism is GI-complete (proof in the paper) OLDG-Isomorphism is in P (Jian & Bunke, 99)

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 14/21

slide-27
SLIDE 27

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Alpha-Equivalence Including Garbage Collection

Further consequences: Extended α-Equivalence up to Garbage-Collection CH-expressions s, t are alpha-equivalent up to garbage-collection written as s ≃α,gc,CH t, iff the (gc)-normal forms s′ and t′ of s and t are alpha-equivalent. Theorem s1 ≃α,gc,CH s2 can be decided in O(n log n) where n = |s1| + |s2|.

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 15/21

slide-28
SLIDE 28

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Applications

Extended α-equivalence is GI-complete in several letrec-calculi (Ariola’95, Ariola & Blom’97,. . . ) extended and non-deterministic letrec-calculi

(Moran, Sands & Carlsson ’03, S. & Schmidt-Schauß’08,. . . )

fragment of Haskell: Recursive functions, data constructors, letrec-expressions Remark: The result does not hold for let-calculi with non-recursive, single-binding let-expressions (e.g. Maraist, Odersky & Wadler ’98)

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 16/21

slide-29
SLIDE 29

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Structural Congruence in the π-Calculus

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 17/21

slide-30
SLIDE 30

Motivation GI-Completeness GC Applications π-Calculus Conclusion

The π-calculus

Syntax: P ::= π.P | (P1 | P2) | ! P | 0 | νx.P π ::= x(y) | xy where x, y ∈ N Milner’s structural congruence ≡: The least congruence satisfying the equations P ≡ Q, if P and Q are α-equivalent P1 | (P2 | P3) ≡ (P1 | P2) | P3 P1 | P2 ≡ P2 | P1 P | 0 ≡ P νz.νw.P ≡ νw.νz.P νz.0 ≡ νz.(P1 | P2) ≡ P1 | νz.P2, if z ∈ fn(P1) ! P ≡ P | ! P Open Question: Is ≡ decidable?

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 18/21

slide-31
SLIDE 31

Motivation GI-Completeness GC Applications π-Calculus Conclusion

π-Calculus: Specific Cases and Results (1)

Lemma (see also (Khomenko & Meyer ’09)) Structural congruence ≡ is GI-hard even without replication. Alternative proof: Polytime reduction of Digraph-Isomorphism: Encode digraph G = (V, E) with V = {v1, . . . , vn}, E = {e1, . . . , em} as ϕ(G) := νv1, . . . , vn.(ϕ(v1) | . . . | ϕ(vn) | ϕ(e1) | . . . | ϕ(em)) where for vi ∈ V : ϕ(vi) = via.0 for ei = (vj, vk) ∈ E: ϕ(ei) = vj(vk).0 Then ϕ(G1) ≡ ϕ(G2) ⇐ ⇒ G1, G2 are isomorphic.

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 19/21

slide-32
SLIDE 32

Motivation GI-Completeness GC Applications π-Calculus Conclusion

π-Calculus: Specific Cases and Results (2)

Fragment with replication but without binders s, si ∈ PIR := C | (s1 | s2) | ! s

(C represents constants)

Structural congruence ≡PIR is the least congruence satisfying (s1 | s2) ≡PIR (s2 | s1) (s1 | (s2 | s3)) ≡PIR ((s1 | s2) | s3) ! s ≡PIR s | ! s

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 20/21

slide-33
SLIDE 33

Motivation GI-Completeness GC Applications π-Calculus Conclusion

π-Calculus: Specific Cases and Results (2)

Fragment with replication but without binders s, si ∈ PIR := C | (s1 | s2) | ! s

(C represents constants)

Structural congruence ≡PIR is the least congruence satisfying (s1 | s2) ≡PIR (s2 | s1) (s1 | (s2 | s3)) ≡PIR ((s1 | s2) | s3) ! s ≡PIR s | ! s Theorem Deciding s1 ≡PIR s2 is EXPSPACE-complete Proof: In EXPSPACE was shown by Engelfriet & Gelsema’ 07. Hardness: Reduction of the word problem over commutative semigroups Remark: Structural congruence in the full π-calculus with replication is thus EXPSPACE-hard, however decidability is still open.

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 20/21

slide-34
SLIDE 34

Motivation GI-Completeness GC Applications π-Calculus Conclusion

Conclusion

Extended α-equivalence in let- / letrec-calculi is GI-complete Complexity arises from garbage bindings (unless GI = P) Including garbage-collection in the equivalence makes the decision problem efficiently solvable. π-calculus with replication: Deciding structural congruence is a very hard problem

  • D. Sabel

Algorithms for Extended Alpha-Equivalence and Complexity 21/21