RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn...

145
Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of Rewrite Systems 1

Transcript of RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn...

Page 1: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Automated Complexity Analysis of Rewrite Systems

Florian Frohn

RWTH Aachen University, Germany

December 11, 2018

Automated Complexity Analysis of Rewrite Systems 1

Page 2: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Automated Complexity Analysis of Rewrite Systems

Florian Frohn

RWTH Aachen University, Germany

December 11, 2018

Automated Complexity Analysis of Rewrite Systems 1

Page 3: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Automated Complexity Analysis of Rewrite Systems

Florian Frohn

RWTH Aachen University, Germany

December 11, 2018

Automated Complexity Analysis of Rewrite Systems 1

Page 4: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Complexity Analysis?

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

x loop iterations

5 operations per iteration

complexity 5 · x + 2

upper bound: 7 · x + 4, ...

lower bound: x + 1, ...

Goal: compute such bounds automatically

Automated Complexity Analysis of Rewrite Systems 2

Page 5: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Complexity Analysis?

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

x loop iterations

5 operations per iteration

complexity 5 · x + 2

upper bound: 7 · x + 4, ...

lower bound: x + 1, ...

Goal: compute such bounds automatically

Automated Complexity Analysis of Rewrite Systems 2

Page 6: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Complexity Analysis?

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

x loop iterations

5 operations per iteration

complexity 5 · x + 2

upper bound: 7 · x + 4, ...

lower bound: x + 1, ...

Goal: compute such bounds automatically

Automated Complexity Analysis of Rewrite Systems 2

Page 7: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Complexity Analysis?

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

x loop iterations

5 operations per iteration

complexity 5 · x + 2

upper bound: 7 · x + 4, ...

lower bound: x + 1, ...

Goal: compute such bounds automatically

Automated Complexity Analysis of Rewrite Systems 2

Page 8: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Complexity Analysis?

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

x loop iterations

5 operations per iteration

complexity 5 · x + 2

upper bound: 7 · x + 4, ...

lower bound: x + 1, ...

Goal: compute such bounds automatically

Automated Complexity Analysis of Rewrite Systems 2

Page 9: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Complexity Analysis?

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

x loop iterations

5 operations per iteration

complexity 5 · x + 2

upper bound: 7 · x + 4, ...

lower bound: x + 1, ...

Goal: compute such bounds automatically

Automated Complexity Analysis of Rewrite Systems 2

Page 10: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Complexity Analysis?

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

x loop iterations

5 operations per iteration

complexity 5 · x + 2

upper bound: 7 · x + 4, ...

lower bound: x + 1, ...

Goal: compute such bounds automatically

Automated Complexity Analysis of Rewrite Systems 2

Page 11: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)Program (Java, C, . . .)

AProVE

AProVE

SE-GraphSE-Graph

AProVEAProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 12: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)

Program (Java, C, . . .)

AProVE

AProVE

SE-GraphSE-Graph

AProVEAProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 13: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)

Program (Java, C, . . .)

AProVE

AProVE

SE-Graph

SE-Graph

AProVEAProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 14: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)

Program (Java, C, . . .)

AProVE

AProVE

SE-Graph

SE-Graph

AProVE

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 15: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)

Program (Java, C, . . .)

AProVE

AProVE

SE-Graph

SE-Graph

AProVE

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 16: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)

Program (Java, C, . . .)

AProVE

AProVE

SE-Graph

SE-Graph

AProVE

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 17: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)

Program (Java, C, . . .)

AProVE

AProVE

SE-Graph

SE-Graph

AProVE

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 18: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)

Program (Java, C, . . .)

AProVE

AProVE

SE-Graph

SE-Graph

AProVE

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 19: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Complexity Analysis with AProVE

Program (Java, C, . . .)

Program (Java, C, . . .)

AProVE

AProVE

SE-Graph

SE-Graph

AProVE

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

Automated Complexity Analysis of Rewrite Systems 3

Page 20: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 21: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 22: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 23: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 24: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 25: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 26: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 27: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 28: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 29: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 30: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 31: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 0

1 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 32: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)

2 y s(s(0)). . .

Automated Complexity Analysis of Rewrite Systems 4

Page 33: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 34: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What is Rewriting?

Rule-Based Representation of Programs

Example (Integer Transition System (ITS))

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Term Rewrite System (TRS))

length(cons(x, x′)) −→ s(length(x′))

length(nil) −→ 0

input: x, y ∈ Nz = 0while x > 0 do

x = x− 1z = z + y

endreturn z

0 y 01 y s(0)2 y s(s(0))

. . .

Automated Complexity Analysis of Rewrite Systems 4

Page 35: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Upper, Lower, Worst Case, Best Case, ...

input size

run

tim

e

Automated Complexity Analysis of Rewrite Systems 5

Page 36: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Upper, Lower, Worst Case, Best Case, ...

input size

run

tim

e

Automated Complexity Analysis of Rewrite Systems 5

Page 37: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Upper, Lower, Worst Case, Best Case, ...

input size

run

tim

e

Automated Complexity Analysis of Rewrite Systems 5

Page 38: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Upper, Lower, Worst Case, Best Case, ...

input size

run

tim

e

Automated Complexity Analysis of Rewrite Systems 5

Page 39: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Upper, Lower, Worst Case, Best Case, ...

input size

run

tim

e

Automated Complexity Analysis of Rewrite Systems 5

Page 40: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Outline

1 Introduction

2 Lower Bounds for ITSs

3 Lower Bounds for TRSs

4 Constant Upper Bounds for TRSs

Automated Complexity Analysis of Rewrite Systems 6

Page 41: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0)

[x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4]1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 42: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0)

[x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4]1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 43: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0]

|= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4]1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 44: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 0

5−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4]1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 45: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2)

[x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4]1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 46: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2]

|= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4]1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 47: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 0

5−→ while(0, 2, 4) [x/0, y/2, z/4]1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 48: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4)

[x/0, y/2, z/4]1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 49: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4]

1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 50: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4] 6|= x > 0

1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 51: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4] |= x = 0

1−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 52: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating ITSs

Example (ITS)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

Example (Evaluation)

while(2, 2, 0) [x/2, y/2, z/0] |= x > 05−→ while(1, 2, 2) [x/1, y/2, z/2] |= x > 05−→ while(0, 2, 4) [x/0, y/2, z/4] |= x = 01−→ return(4)

Automated Complexity Analysis of Rewrite Systems 7

Page 53: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 54: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 55: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 56: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 57: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 58: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 59: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 60: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterations

x2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 61: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 62: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 63: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Loop Acceleration

Example (Loop Acceleration)

while(x, y, z)5−→ while(x− 1, y, z + y) [x > 0]

y while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

5 · n: cost of n iterations

x− n: value of x after n iterations

z + y · n: value of z after n iterations

x: maximal number of loop iterationsx2 , x− 1, . . . would be fine, too

search for metering function

Example (Recurrence Equations)

x(n) = x(n−1) − 1

y(n) = y(n−1)

z(n) = z(n−1) + y(n−1)

Automated Complexity Analysis of Rewrite Systems 8

Page 64: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 65: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, z)5·n−−→ while(x− n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 66: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·n−−→ while(x− n, y, 0 + y · n) [x > 0 ∧ 0 < n ≤ x]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 67: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·n−−→ while(x− n, y, y · n) [x > 0 ∧ 0 < n ≤ x]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 68: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·n−−→ while(x− n, y, y · n) [x > 0 ∧ 0 < n ≤ x]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 69: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·x−−→ while(x− x, y, y · x) [x > 0 ∧ 0 < x ≤ x]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 70: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·x−−→ while(0, y, y · x) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 71: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·x−−→ while(0, y, y · x) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 72: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·x−−→ while(0, y, y · x) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 73: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·x−−→ while(0, y, y · x) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 74: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·x−−→ while(0, y, y · x) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 75: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Chaining

Example

init(x, y)1−→ while(x, y, 0) [x ≥ 0 ∧ y ≥ 0]

while(x, y, 0)5·x−−→ while(0, y, y · x) [x > 0]

while(x, y, z)1−→ return(z) [x = 0]

y init(x, y)5·x+2−−−→ return(y · x) [x > 0 ∧ y ≥ 0]

y whole program compressed into a single rule

y lower bound 5 · x + 2 for all x > 0, y ≥ 0

Works for arbitrary programs!

Automated Complexity Analysis of Rewrite Systems 9

Page 76: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for ITSs – Wrap-Up

first technique to infer worst case lower bounds for ITSs

key idea: loop acceleration

many other features, e.g.:

non-determinism

asymptotic bounds

recursive void functions

SMT encodings

. . .

LoAT

Bes

tU

pp

erB

oun

d

rc(n) Ω(1) Ω(n) Ω(n2) Ω(n3) Ω(n4) EXP ∞O(1) (132) – – – – – –O(n) 37 126 – – – – –O(n2) 8 14 35 – – – –O(n3) 2 – 2 1 – – –O(n4) 1 – – – 2 – –EXP – – – – – 5 –∞ 53 31 1 – – – 176

Automated Complexity Analysis of Rewrite Systems 10

Page 77: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for ITSs – Wrap-Up

first technique to infer worst case lower bounds for ITSs

key idea: loop acceleration

many other features, e.g.:

non-determinism

asymptotic bounds

recursive void functions

SMT encodings

. . .

LoAT

Bes

tU

pp

erB

oun

d

rc(n) Ω(1) Ω(n) Ω(n2) Ω(n3) Ω(n4) EXP ∞O(1) (132) – – – – – –O(n) 37 126 – – – – –O(n2) 8 14 35 – – – –O(n3) 2 – 2 1 – – –O(n4) 1 – – – 2 – –EXP – – – – – 5 –∞ 53 31 1 – – – 176

Automated Complexity Analysis of Rewrite Systems 10

Page 78: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for ITSs – Wrap-Up

first technique to infer worst case lower bounds for ITSs

key idea: loop acceleration

many other features, e.g.:

non-determinism

asymptotic bounds

recursive void functions

SMT encodings

. . .

LoAT

Bes

tU

pp

erB

oun

d

rc(n) Ω(1) Ω(n) Ω(n2) Ω(n3) Ω(n4) EXP ∞O(1) (132) – – – – – –O(n) 37 126 – – – – –O(n2) 8 14 35 – – – –O(n3) 2 – 2 1 – – –O(n4) 1 – – – 2 – –EXP – – – – – 5 –∞ 53 31 1 – – – 176

Automated Complexity Analysis of Rewrite Systems 10

Page 79: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for ITSs – Wrap-Up

first technique to infer worst case lower bounds for ITSs

key idea: loop acceleration

many other features, e.g.:

non-determinism

asymptotic bounds

recursive void functions

SMT encodings

. . .

LoAT

Bes

tU

pp

erB

oun

d

rc(n) Ω(1) Ω(n) Ω(n2) Ω(n3) Ω(n4) EXP ∞O(1) (132) – – – – – –O(n) 37 126 – – – – –O(n2) 8 14 35 – – – –O(n3) 2 – 2 1 – – –O(n4) 1 – – – 2 – –EXP – – – – – 5 –∞ 53 31 1 – – – 176

Automated Complexity Analysis of Rewrite Systems 10

Page 80: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for ITSs – Wrap-Up

first technique to infer worst case lower bounds for ITSs

key idea: loop acceleration

many other features, e.g.:

non-determinism

asymptotic bounds

recursive void functions

SMT encodings

. . .

LoAT

Bes

tU

pp

erB

oun

d

rc(n) Ω(1) Ω(n) Ω(n2) Ω(n3) Ω(n4) EXP ∞O(1) (132) – – – – – –O(n) 37 126 – – – – –O(n2) 8 14 35 – – – –O(n3) 2 – 2 1 – – –O(n4) 1 – – – 2 – –EXP – – – – – 5 –∞ 53 31 1 – – – 176

Automated Complexity Analysis of Rewrite Systems 10

Page 81: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for ITSs – Wrap-Up

first technique to infer worst case lower bounds for ITSs

key idea: loop acceleration

many other features, e.g.:

non-determinism

asymptotic bounds

recursive void functions

SMT encodings

. . .

LoAT

Bes

tU

pp

erB

oun

d

rc(n) Ω(1) Ω(n) Ω(n2) Ω(n3) Ω(n4) EXP ∞O(1) (132) – – – – – –O(n) 37 126 – – – – –O(n2) 8 14 35 – – – –O(n3) 2 – 2 1 – – –O(n4) 1 – – – 2 – –EXP – – – – – 5 –∞ 53 31 1 – – – 176

Automated Complexity Analysis of Rewrite Systems 10

Page 82: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for ITSs – Wrap-Up

first technique to infer worst case lower bounds for ITSs

key idea: loop acceleration

many other features, e.g.:

non-determinism

asymptotic bounds

recursive void functions

SMT encodings

. . .

LoAT

Bes

tU

pp

erB

oun

d

rc(n) Ω(1) Ω(n) Ω(n2) Ω(n3) Ω(n4) EXP ∞O(1) (132) – – – – – –O(n) 37 126 – – – – –O(n2) 8 14 35 – – – –O(n3) 2 – 2 1 – – –O(n4) 1 – – – 2 – –EXP – – – – – 5 –∞ 53 31 1 – – – 176

Automated Complexity Analysis of Rewrite Systems 10

Page 83: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Outline

1 Introduction

2 Lower Bounds for ITSs

3 Lower Bounds for TRSs

4 Constant Upper Bounds for TRSs

Automated Complexity Analysis of Rewrite Systems 11

Page 84: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Example (Evaluation)

inf(0)

[y/0]

−→ cons(0, inf(s(0))) [y/s(0)]

−→ cons(0, cons(s(0), inf(s(s(0))))) [y/s(s(0))]

−→ . . .

Automated Complexity Analysis of Rewrite Systems 12

Page 85: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Example (Evaluation)

inf(0)

[y/0]

−→ cons(0, inf(s(0))) [y/s(0)]

−→ cons(0, cons(s(0), inf(s(s(0))))) [y/s(s(0))]

−→ . . .

Automated Complexity Analysis of Rewrite Systems 12

Page 86: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Example (Evaluation)

inf(0) [y/0]

−→ cons(0, inf(s(0))) [y/s(0)]

−→ cons(0, cons(s(0), inf(s(s(0))))) [y/s(s(0))]

−→ . . .

Automated Complexity Analysis of Rewrite Systems 12

Page 87: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Example (Evaluation)

inf(0) [y/0]

−→ cons(0, inf(s(0)))

[y/s(0)]

−→ cons(0, cons(s(0), inf(s(s(0))))) [y/s(s(0))]

−→ . . .

Automated Complexity Analysis of Rewrite Systems 12

Page 88: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Example (Evaluation)

inf(0) [y/0]

−→ cons(0, inf(s(0))) [y/s(0)]

−→ cons(0, cons(s(0), inf(s(s(0))))) [y/s(s(0))]

−→ . . .

Automated Complexity Analysis of Rewrite Systems 12

Page 89: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Example (Evaluation)

inf(0) [y/0]

−→ cons(0, inf(s(0))) [y/s(0)]

−→ cons(0, cons(s(0), inf(s(s(0)))))

[y/s(s(0))]

−→ . . .

Automated Complexity Analysis of Rewrite Systems 12

Page 90: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Example (Evaluation)

inf(0) [y/0]

−→ cons(0, inf(s(0))) [y/s(0)]

−→ cons(0, cons(s(0), inf(s(s(0))))) [y/s(s(0))]

−→ . . .

Automated Complexity Analysis of Rewrite Systems 12

Page 91: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Example (Evaluation)

inf(0) [y/0]

−→ cons(0, inf(s(0))) [y/s(0)]

−→ cons(0, cons(s(0), inf(s(s(0))))) [y/s(s(0))]

−→ . . .

Automated Complexity Analysis of Rewrite Systems 12

Page 92: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Loop

=⇒ Non-Termination

Automated Complexity Analysis of Rewrite Systems 12

Page 93: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(y)))

Loop =⇒ Non-Termination

Automated Complexity Analysis of Rewrite Systems 12

Page 94: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Evaluating TRSs

Example (TRS)

inf(y) −→ cons(y,inf(s(0)))

Loop =⇒ Non-Termination

Automated Complexity Analysis of Rewrite Systems 12

Page 95: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(x′))

Decreasing Loop Loop

Automated Complexity Analysis of Rewrite Systems 13

Page 96: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(x′))

Decreasing Loop

Loop

Automated Complexity Analysis of Rewrite Systems 13

Page 97: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(x′))

Decreasing Loop Loop

Automated Complexity Analysis of Rewrite Systems 13

Page 98: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(x′))

Decreasing Loop =⇒ Linear Lower Bound Loop

Automated Complexity Analysis of Rewrite Systems 13

Page 99: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(nil))

Decreasing Loop 6=⇒ Linear Lower Bound Loop

Automated Complexity Analysis of Rewrite Systems 13

Page 100: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(x′))

Decreasing Loop =⇒ Linear Lower Bound Loop

Automated Complexity Analysis of Rewrite Systems 13

Page 101: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(x′))

y length(cons(x, x′), y) −→ length(x′, s(y))

Decreasing Loops Loops

Automated Complexity Analysis of Rewrite Systems 14

Page 102: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(x′))

y length(cons(x, x′), y) −→ length(x′, s(y))

Decreasing Loops Loops

Automated Complexity Analysis of Rewrite Systems 14

Page 103: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops

Example

length(cons(x, x′)) −→ s(length(x′))

y length(cons(x, x′), y) −→ length(x′, s(y))

Decreasing Loops Revised

Automated Complexity Analysis of Rewrite Systems 14

Page 104: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops – Results

Theorem

If a TRS has a decreasing loop, then its complexity is at least linear.

Theorem

If a TRS has several compatible decreasing loops, then its complexity is at least exponential.

Theorem

Linear lower bounds are not semi-decidable.

Lemma

Decreasing loops are incomplete.

Example (Compatible Decreasing Loops)

fib(s(s(x))) −→ plus(fib(s(x)), fib(x))

Automated Complexity Analysis of Rewrite Systems 15

Page 105: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops – Results

Theorem

If a TRS has a decreasing loop, then its complexity is at least linear.

Theorem

If a TRS has several compatible decreasing loops, then its complexity is at least exponential.

Theorem

Linear lower bounds are not semi-decidable.

Lemma

Decreasing loops are incomplete.

Example (Compatible Decreasing Loops)

fib(s(s(x))) −→ plus(fib(s(x)), fib(x))

Automated Complexity Analysis of Rewrite Systems 15

Page 106: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops – Results

Theorem

If a TRS has a decreasing loop, then its complexity is at least linear.

Theorem

If a TRS has several compatible decreasing loops, then its complexity is at least exponential.

Theorem

Linear lower bounds are not semi-decidable.

Lemma

Decreasing loops are incomplete.

Example (Compatible Decreasing Loops)

fib(s(s(x))) −→ plus(fib(s(x)), fib(x))

Automated Complexity Analysis of Rewrite Systems 15

Page 107: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops – Results

Theorem

If a TRS has a decreasing loop, then its complexity is at least linear.

Theorem

If a TRS has several compatible decreasing loops, then its complexity is at least exponential.

Theorem

Linear lower bounds are not semi-decidable.

Lemma

Decreasing loops are incomplete.

Example (Compatible Decreasing Loops)

fib(s(s(x))) −→ plus(fib(s(x)), fib(x))

Automated Complexity Analysis of Rewrite Systems 15

Page 108: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Decreasing Loops – Results

Theorem

If a TRS has a decreasing loop, then its complexity is at least linear.

Theorem

If a TRS has several compatible decreasing loops, then its complexity is at least exponential.

Theorem

Linear lower bounds are not semi-decidable.

Lemma

Decreasing loops are incomplete.

Example (Compatible Decreasing Loops)

fib(s(s(x))) −→ plus(fib(s(x)), fib(x))

Automated Complexity Analysis of Rewrite Systems 15

Page 109: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for TRSs – Wrap-Up

first technique to infer worst case lower bounds for TRSs

key idea: generalize loops

linear, exponential, infinite bounds

quadratic, cubic, . . .?

y “induction technique”

incomplete

AProVE

Ω(1) Ω(n) EXP ∞66 600 143 90

Automated Complexity Analysis of Rewrite Systems 16

Page 110: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for TRSs – Wrap-Up

first technique to infer worst case lower bounds for TRSs

key idea: generalize loops

linear, exponential, infinite bounds

quadratic, cubic, . . .?

y “induction technique”

incomplete

AProVE

Ω(1) Ω(n) EXP ∞66 600 143 90

Automated Complexity Analysis of Rewrite Systems 16

Page 111: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for TRSs – Wrap-Up

first technique to infer worst case lower bounds for TRSs

key idea: generalize loops

linear, exponential, infinite bounds

quadratic, cubic, . . .?

y “induction technique”

incomplete

AProVE

Ω(1) Ω(n) EXP ∞66 600 143 90

Automated Complexity Analysis of Rewrite Systems 16

Page 112: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for TRSs – Wrap-Up

first technique to infer worst case lower bounds for TRSs

key idea: generalize loops

linear, exponential, infinite bounds

quadratic, cubic, . . .?

y “induction technique”

incomplete

AProVE

Ω(1) Ω(n) EXP ∞66 600 143 90

Automated Complexity Analysis of Rewrite Systems 16

Page 113: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for TRSs – Wrap-Up

first technique to infer worst case lower bounds for TRSs

key idea: generalize loops

linear, exponential, infinite bounds

quadratic, cubic, . . .?

y “induction technique”

incomplete

AProVE

Ω(1) Ω(n) EXP ∞66 600 143 90

Automated Complexity Analysis of Rewrite Systems 16

Page 114: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for TRSs – Wrap-Up

first second technique to infer worst case lower bounds for TRSs

key idea: generalize loops

linear, exponential, infinite bounds

quadratic, cubic, . . .?

y “induction technique”

incomplete

AProVE

Ω(1) Ω(n) EXP ∞66 600 143 90

Automated Complexity Analysis of Rewrite Systems 16

Page 115: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for TRSs – Wrap-Up

first second technique to infer worst case lower bounds for TRSs

key idea: generalize loops

linear, exponential, infinite bounds

quadratic, cubic, . . .?

y “induction technique”

incomplete

AProVE

Ω(1) Ω(n) EXP ∞66 600 143 90

Automated Complexity Analysis of Rewrite Systems 16

Page 116: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Lower Bounds for TRSs – Wrap-Up

first second technique to infer worst case lower bounds for TRSs

key idea: generalize loops

linear, exponential, infinite bounds

quadratic, cubic, . . .?

y “induction technique”

incomplete

AProVE

Ω(1) Ω(n) EXP ∞66 600 143 90

Automated Complexity Analysis of Rewrite Systems 16

Page 117: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Outline

1 Introduction

2 Lower Bounds for ITSs

3 Lower Bounds for TRSs

4 Constant Upper Bounds for TRSs

Automated Complexity Analysis of Rewrite Systems 17

Page 118: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y)

[y/g(x)]

g(h(f(x))) [x/a]

g(h(g(h(a)))) [x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 119: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y)

[y/g(x)]

g(h(f(x))) [x/a]

g(h(g(h(a)))) [x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 120: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y)

[y/g(x)]

g(h(f(x))) [x/a]

g(h(g(h(a)))) [x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 121: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y) [y/g(x)]

g(h(f(x))) [x/a]

g(h(g(h(a)))) [x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 122: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y) [y/g(x)]

g(h(f(x)))

[x/a]

g(h(g(h(a)))) [x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 123: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y) [y/g(x)]

g(h(f(x))) [x/a]

g(h(g(h(a)))) [x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 124: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y) [y/g(x)]

g(h(f(x))) [x/a]

g(h(g(h(a))))

[x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 125: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y) [y/g(x)]

g(h(f(x))) [x/a]

g(h(g(h(a)))) [x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 126: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Narrowing

Example (from TPDB)

f(a) −→ g(h(a))

h(g(x)) −→ g(h(f(x)))

Definition (Narrowing)

Just like rewriting, but with unification instead of matching.

Example (Evaluation)

h(y) [y/g(x)]

g(h(f(x))) [x/a]

g(h(g(h(a)))) [x/h(a)]

g(g(h(f(h(a)))))

Automated Complexity Analysis of Rewrite Systems 18

Page 127: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Constant Upper Bounds

Theorem

The complexity of a TRS is constant iff narrowing terminates for all terms f(x1, . . . , xn).

Lemma

Constant complexity is semi-decidable.

Automated Complexity Analysis of Rewrite Systems 19

Page 128: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Constant Upper Bounds

Theorem

The complexity of a TRS is constant iff narrowing terminates for all terms f(x1, . . . , xn).

Lemma

Constant complexity is semi-decidable.

Automated Complexity Analysis of Rewrite Systems 19

Page 129: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Constant Upper Bounds – Wrap-Up

semi-decision procedure for constant bounds

key idea: use narrowing

y AProVE can (dis-)prove constant complexity in almost all cases

Evaluation (TPDB – 899 examples)

succeeds for all 57 TRSs with constant complexity

solves 6 examples that couldn’t be solved before

Automated Complexity Analysis of Rewrite Systems 20

Page 130: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Constant Upper Bounds – Wrap-Up

semi-decision procedure for constant bounds

key idea: use narrowing

y AProVE can (dis-)prove constant complexity in almost all cases

Evaluation (TPDB – 899 examples)

succeeds for all 57 TRSs with constant complexity

solves 6 examples that couldn’t be solved before

Automated Complexity Analysis of Rewrite Systems 20

Page 131: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Constant Upper Bounds – Wrap-Up

semi-decision procedure for constant bounds

key idea: use narrowing

y AProVE can (dis-)prove constant complexity in almost all cases

Evaluation (TPDB – 899 examples)

succeeds for all 57 TRSs with constant complexity

solves 6 examples that couldn’t be solved before

Automated Complexity Analysis of Rewrite Systems 20

Page 132: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Constant Upper Bounds – Wrap-Up

semi-decision procedure for constant bounds

key idea: use narrowing

y AProVE can (dis-)prove constant complexity in almost all cases

Evaluation (TPDB – 899 examples)

succeeds for all 57 TRSs with constant complexity

solves 6 examples that couldn’t be solved before

Automated Complexity Analysis of Rewrite Systems 20

Page 133: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Constant Upper Bounds – Wrap-Up

semi-decision procedure for constant bounds

key idea: use narrowing

y AProVE can (dis-)prove constant complexity in almost all cases

Evaluation (TPDB – 899 examples)

succeeds for all 57 TRSs with constant complexity

solves 6 examples that couldn’t be solved before

Automated Complexity Analysis of Rewrite Systems 20

Page 134: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What’s next?

Program (Java, C, . . .)

AProVE

SE-Graph

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

integers and data structures

floats, arrays, . . .

underapproximating program transformations

Automated Complexity Analysis of Rewrite Systems 21

Page 135: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What’s next?

Program (Java, C, . . .)

AProVE

SE-Graph

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

integers and data structures

floats, arrays, . . .

underapproximating program transformations

Automated Complexity Analysis of Rewrite Systems 21

Page 136: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What’s next?

Program (Java, C, . . .)

AProVE

SE-Graph

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

integers and data structures

floats, arrays, . . .

underapproximating program transformations

Automated Complexity Analysis of Rewrite Systems 21

Page 137: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What’s next?

Program (Java, C, . . .)

AProVE

SE-Graph

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

integers and data structures

floats, arrays, . . .

underapproximating program transformations

Automated Complexity Analysis of Rewrite Systems 21

Page 138: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What’s next?

Program (Java, C, . . .)

AProVE

SE-Graph

AProVE

Integer Transition SystemTerm Rewrite System

AProVECoFloCo

LoAT. . .

Upper Bound

Lower Bound

8

integers and data structures

floats, arrays, . . .

underapproximating program transformations

Automated Complexity Analysis of Rewrite Systems 21

Page 139: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What else?

’15 • Induction Technique for TRSs RTA

’16 • Lower Bounds for ITSs IJCAR

’17 • Decreasing Loops for TRSs JAR

’17 • LPAR

’17 • FroCoS

’17 • Upper Bounds for Java iFM

’18 • Constant Upper Bounds for TRSs IPL

Termination and Complexity Analysis for C

AProVE Tool Papers

IJCAR ’14, SEFM ’16, JAR ’17, JLAMP ’18

IJCAR ’14, JAR ’17

Automated Complexity Analysis of Rewrite Systems 22

Page 140: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What else?

’15 • Induction Technique for TRSs RTA

’16 • Lower Bounds for ITSs IJCAR

’17 • Decreasing Loops for TRSs JAR

’17 • LPAR

’17 • FroCoS

’17 • Upper Bounds for Java iFM

’18 • Constant Upper Bounds for TRSs IPL

Termination and Complexity Analysis for C

AProVE Tool Papers

IJCAR ’14, SEFM ’16, JAR ’17, JLAMP ’18

IJCAR ’14, JAR ’17

Automated Complexity Analysis of Rewrite Systems 22

Page 141: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What else?

’15 • Induction Technique for TRSs RTA

’16 • Lower Bounds for ITSs IJCAR

’17 • Decreasing Loops for TRSs JAR

’17 • LPAR

’17 • FroCoS

’17 • Upper Bounds for Java iFM

’18 • Constant Upper Bounds for TRSs IPL

Termination and Complexity Analysis for C

AProVE Tool Papers

IJCAR ’14, SEFM ’16, JAR ’17, JLAMP ’18

IJCAR ’14, JAR ’17

Automated Complexity Analysis of Rewrite Systems 22

Page 142: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What else?

’15 • Induction Technique for TRSs RTA

’16 • Lower Bounds for ITSs IJCAR

’17 • Decreasing Loops for TRSs JAR

’17 • LPAR

’17 • FroCoS

’17 • Upper Bounds for Java iFM

’18 • Constant Upper Bounds for TRSs IPL

Termination and Complexity Analysis for C

AProVE Tool Papers

IJCAR ’14, SEFM ’16, JAR ’17, JLAMP ’18

IJCAR ’14, JAR ’17

Automated Complexity Analysis of Rewrite Systems 22

Page 143: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

What else?

’15 • Induction Technique for TRSs RTA

’16 • Lower Bounds for ITSs IJCAR

’17 • Decreasing Loops for TRSs JAR

’17 • LPAR

’17 • FroCoS

’17 • Upper Bounds for Java iFM

’18 • Constant Upper Bounds for TRSs IPL

Termination and Complexity Analysis for C

AProVE Tool Papers

IJCAR ’14, SEFM ’16, JAR ’17, JLAMP ’18

IJCAR ’14, JAR ’17

Automated Complexity Analysis of Rewrite Systems 22

Thank you!

Page 144: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

AProVE at TermComp

points of AProVEpoints of best competitor

ITS 2016 2017 2018

w/ lower bounds 2.09 N/A 2.60

w/o lower bounds 0.66 N/A 0.92

TRS 2014 2015 2016 2017 2018

innermost 1.05 2.73 1.18 N/A 1.79

full – 2.94 1.23 N/A 1.70

Automated Complexity Analysis of Rewrite Systems 23

Page 145: RWTH Aachen University, Germany · Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of

Recurrence Solving

Example (Recurrence Solving)

y(v+1) = 1− y(v)

x(v+1) = x(v) + 1− 3y(v)

y(v) = 12 −

12(−1)v + (−1)vy

x(v) = 34 −

34(−1)v − 3

2y −12v + 3

2(−1)vy + x

Automated Complexity Analysis of Rewrite Systems 24