• Keine Ergebnisse gefunden

Constant Runtime Complexity of Term Rewriting is Semi-Decidable

N/A
N/A
Protected

Academic year: 2021

Aktie "Constant Runtime Complexity of Term Rewriting is Semi-Decidable"

Copied!
12
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Constant Runtime Complexity of Term Rewriting is Semi-Decidable

J¨urgen Giesl

LuFG Informatik 2, RWTH Aachen University, Germany

joint work with Florian Frohn

(2)

Runtime Complexity

Example TRS

R

f (d)

c(g(d)) g(c(x))

c(g(f(x)))

Rewrite Sequence

g(c(d))

R

c(g(f(d)))

R

c(g(c(g(d))))

R

c(c(g(f(g(d)))))

Defined Symbols:

roots of lhs f, g

Constructors:

other function symbols c, d

Basic Term:

defined symbol only at the root

f(x), g(c(x)), g(c(d))

Runtime Complexity rc

R(n)

length of longest

−→R

-sequence starting with basic term t where

|t| ≤

n

Example: rc

R(3)≥3

since

|

g(c(d))

|= 3

(3)

Runtime Complexity

Contribution:

Constant runtime complexity is semi-decidable

R

has constant runtime complexity

rc

R

(n)

∈ O(1)

⇔ ∃m∈N

. all

R

-evaluations of basic terms take at most m steps

Motivation

Complexity Analysis: bounds on program’s resource usage Constant Bounds: detect bugs

Runtime Complexity rc

R(n)

length of longest

−→R

-sequence starting with basic term t where

|t| ≤

n

Example: rc

R(3)≥3

since

|

g(c(d))

|= 3

(4)

Constructor-Based Narrowing

Example TRS

R

f (d)

c(g(d)) g(c(x))

c(g(f(x)))

Constructor-Based Narrowing Sequence

g(x)

(c0)

{x/c(x0)}

ε c(g(f(x0))) {x1.10/d} c(g(c(g(d)))) 1 c(c(g(f(g(d)))))

)

Narrowing sequencet0 σ1 · · · σn tn isconstructor basedift0σ1· · ·σn is basic.

Constructor-basedR-narrowing terminates:

g(x), g(c(x)), g(c(d)) 3 steps g(c(t))for other termst 1 step g(t)for other termst 0 steps

f(x), f(d) 1 step

f(t)for other termst 0 steps

Goal: Show termination of cb narrowing by inspecting finitely many start terms

Main Theorem

Rhas constant runtime complexity iff constructor-basedR-narrowing terminates

(5)

Constructor-Based Narrowing

Example TRS

R

f (d)

c(g(d)) g(c(x))

c(g(f(x)))

Constructor-Based Narrowing Sequence

g(x)

(c0)

{x/c(x0)}

ε c(g(f(x0))) {x1.10/d} c(g(c(g(d)))) 1 c(c(g(f(g(d)))))

)

Narrowing sequencet0 σ1 · · · σn tn isconstructor basedift0σ1· · ·σn is basic.

Forg(c(x))→c(g(x)), cb narrowing would not terminate:

g(x) {x/c(x0)} c(g(x0)) {x0/c(x00)} c(c(g(x00))) · · ·

)

Goal: Show termination of cb narrowing by inspecting finitely many start terms

Main Theorem

Rhas constant runtime complexity iff constructor-basedR-narrowing terminates

(6)

Constructor-Based Narrowing

Example TRS

R

f (d)

c(g(d)) g(c(x))

c(g(f(x)))

Constructor-Based Narrowing Sequence

g(x)

(c0)

{x/c(x0)}

ε c(g(f(x0))) {x1.10/d} c(g(c(g(d)))) 1 c(c(g(f(g(d)))))

)

g(c(x0)) ε c(g(f(x0))) {x1.10/d} c(g(c(g(d)))) 1 c(c(g(f(g(d))))) g(c(d)) ε c(g(f(d))) 1.1 c(g(c(g(d)))) 1 c(c(g(f(g(d)))))

Def: s0

σ1

π1 · · · σnπn sn is more generalthan t0

θ1

π1 · · · πθnn tn if

Def:

there is a substitution η with s0 σ1σ2· · ·σn η = t0 θ1θ2· · ·θn

s1 σ2· · ·σn η = t1 θ2· · ·θn

. . .

sn η = tn

Goal: Show termination of cb narrowing by inspecting finitely many start terms

Narrowing Lemma

For everyf(. . .) ntthere is a more general sequence f(x1, . . . , xk) ns.

(7)

Main Theorem

Main Theorem

Rhas constant runtime complexity iff constructor-basedR-narrowing terminates

Proof of “⇐”

Assume thatRdoes not have constant runtime complexity

⇒ f(q~1) −→n1 t1, f(q~2) −→n2 t2, . . . withn1< n2<· · ·

⇒ f(q~1) n1 t1, f(q~2) n2 t2, . . .

⇒ f(x1, . . . , xk) σ1n1 s1, f(x1, . . . , xk) σ2n2 s2, . . . by Narrowing Lemma

⇒ cb narrowing tree with rootf(x1, . . . , xk) has infinitely many nodes

is finitely branching (as Ris finite)

has infinite path (by K¨onig’s Lemma), i.e., infinite cb narrowing sequence

Narrowing Lemma

For everyf(. . .) ntthere is a more general sequence f(x1, . . . , xk) ns.

(8)

Main Theorem

Main Theorem

Rhas constant runtime complexity iff constructor-basedR-narrowing terminates

Proof of “⇒”

Assume that there is an infinite sequencet0

σ1

t1

σ2

· · ·

⇒ t0σ1· · ·σm+1 −→m+1 tm+1 for allm∈N

⇒ ∀m. there is an→R-evaluation of a basic term with more thanmsteps

⇔ Rdoes not have constant runtime complexity

Narrowing Lemma

For everyf(. . .) ntthere is a more general sequence f(x1, . . . , xk) ns.

(9)

Semi-Decision Procedure for Constant Runtime Complexity

Example TRS

R

f (d)

c(g(d)) g(c(x))

c(g(f(x)))

CB Narrowing Trees

f(x) {x/d} c(g(d))

f(x)

g(x) {x/c(x0)} c(g(f(x0))) {x0/d} c(g(c(g(d))))

(

c(c(g(f(g(d)))))

Semi-Decision Procedure

For all defined symbols f, build cb narrowing tree for f(x

1

, . . . , x

k

).

If constructing the trees terminates, then return “constant runtime”.

(10)

Undecidability of Constant Runtime Complexity

Theorem

Constant runtime complexity of TRSs is semi-decidable, but not decidable.

Proof

Turing machine

M

is immortal

rewriting

infinite

basic terms with

RM

does not terminate

narrowing basic terms f(x

1

, . . . , x

k

) with

RM

does not terminate

⇔ RM

does not have constant runtime complexity

(Im)mortality undecidable

constant runtime complexity undecidable

(11)

Experiments

Theorem

Constant runtime complexity of TRSs is semi-decidable, but not decidable.

Implementation and integration of semi-decision procedure inAProVE

Full rewriting (959examples from the TPDB, 60 s per example) 57TRSs with constant runtime

57TRSs detected by semi-decision procedure, 1.8 s avg. on successes 51TRSs detected byTcTorAProVEwithout semi-decision procedure

Innermost rewriting (1022examples from the TPDB, 60 s per example) 59TRSs with constant runtime

58TRSs detected by semi-decision procedure, 1.4 s avg. on successes 1TRS withrelativerules not detected by semi-decision procedure 55TRSs detected byTcTorAProVEwithout semi-decision procedure

(12)

Constant Runtime Complexity of TRSs is Semi-Decidable

R

has constant runtime complexity

⇔ ∃m∈N

. all

R

-evaluations of basic terms take at most m steps

Main Theorem

Rhas constant runtime complexity iff

constructor-basedR-narrowing of all termsf(x1, . . . , xk)terminates

Semi-Decision Procedure (implemented in AProVE)

For all defined symbols f, build cb narrowing tree for f(x

1

, . . . , x

k

).

If constructing the trees terminates, then return “constant runtime”.

Theorem

Constant runtime complexity of TRSs is semi-decidable, but not decidable.

Referenzen

ÄHNLICHE DOKUMENTE

14 To avoid the need for considering infinitely many rules in the reduction pair processor and in order to handle ITRSs where defined symbols like + oc- cur on non-increasing

Now we show the soundness theorem: to prove termination of all queries Q where π(Q) is a finite ground atom, it suffices to show termination of all those terms p in (~t) for the TRS R

In particular, there are numerous term rewriting systems where a direct termination proof with simplication orderings is not possible, but in combination with our technique,

u t Hence, in the quot example the constraints (22) and (23) are in fact sucient for innermost termination. A suitable quasi-ordering satisfying these weakened constraints can easily

By using (quasi-)simplication orderings in combination with dependency pairs, it is possible to prove termination of non-simply terminating systems automatically.. It is nat- ural

u t Hence, independent of the technique used to check the absence of innite innermost chains, narrowing dependency pairs can never destroy the success of the innermost

In case you prove termination, explicitly state which order you used (including precedence and status if appropriate) and which checks you have to perform for the termination proof

2. Astronauts have placed mirrors on the Moon, and hence it is possible to measure the distance to the Moon by sending a laser beam to the Moon: the mirrors reflect the light and