Automated Complexity Analysis of Rewrite Systems
Florian Frohn
RWTH Aachen University, Germany
December 11, 2018
Automated Complexity Analysis of Rewrite Systems 1
Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH - - PowerPoint PPT Presentation
Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen University, Germany December 11, 2018 Automated Complexity Analysis of Rewrite Systems 1 Automated Complexity Analysis of Rewrite Systems Florian Frohn RWTH Aachen
Florian Frohn
RWTH Aachen University, Germany
December 11, 2018
Automated Complexity Analysis of Rewrite Systems 1
Florian Frohn
RWTH Aachen University, Germany
December 11, 2018
Automated Complexity Analysis of Rewrite Systems 1
Florian Frohn
RWTH Aachen University, Germany
December 11, 2018
Automated Complexity Analysis of Rewrite Systems 1
input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 2
input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z x loop iterations
Automated Complexity Analysis of Rewrite Systems 2
input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z x loop iterations 5 operations per iteration
Automated Complexity Analysis of Rewrite Systems 2
input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z x loop iterations 5 operations per iteration complexity 5 · x + 2
Automated Complexity Analysis of Rewrite Systems 2
input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z x loop iterations 5 operations per iteration complexity 5 · x + 2 upper bound: 7 · x + 4, ...
Automated Complexity Analysis of Rewrite Systems 2
input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z x loop iterations 5 operations per iteration complexity 5 · x + 2 upper bound: 7 · x + 4, ... lower bound: x + 1, ...
Automated Complexity Analysis of Rewrite Systems 2
input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return 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
AProVE
Automated Complexity Analysis of Rewrite Systems 3
Program (Java, C, . . .) AProVE
Automated Complexity Analysis of Rewrite Systems 3
Program (Java, C, . . .) AProVE SE-Graph
Automated Complexity Analysis of Rewrite Systems 3
Program (Java, C, . . .) AProVE SE-Graph AProVE
Automated Complexity Analysis of Rewrite Systems 3
Program (Java, C, . . .) AProVE SE-Graph AProVE Integer Transition System Term Rewrite System
Automated Complexity Analysis of Rewrite Systems 3
Program (Java, C, . . .) AProVE SE-Graph AProVE Integer Transition System Term Rewrite System AProVE CoFloCo LoAT . . .
Automated Complexity Analysis of Rewrite Systems 3
Program (Java, C, . . .) AProVE SE-Graph AProVE Integer Transition System Term Rewrite System AProVE CoFloCo LoAT . . . Upper Bound
Automated Complexity Analysis of Rewrite Systems 3
Program (Java, C, . . .) AProVE SE-Graph AProVE Integer Transition System Term Rewrite System AProVE CoFloCo LoAT . . . Upper Bound Lower Bound
Automated Complexity Analysis of Rewrite Systems 3
Program (Java, C, . . .) AProVE SE-Graph AProVE Integer Transition System Term Rewrite System AProVE CoFloCo LoAT . . . AProVE CoFloCo LoAT . . . Upper Bound Lower Bound
Automated Complexity Analysis of Rewrite Systems 3
Rule-Based Representation of Programs
Automated Complexity Analysis of Rewrite Systems 4
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]
Automated Complexity Analysis of Rewrite Systems 4
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] input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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] input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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] input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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] input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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] input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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] input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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] input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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] input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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) − → input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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) − → input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
4
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) − → input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
Automated Complexity Analysis of Rewrite Systems 4
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) − → input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
2
Automated Complexity Analysis of Rewrite Systems 4
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) − → input: x, y ∈ N z = 0 while x > 0 do x = x − 1 z = z + y end return z
2
. . .
Automated Complexity Analysis of Rewrite Systems 4
input size runtime
Automated Complexity Analysis of Rewrite Systems 5
input size runtime
Automated Complexity Analysis of Rewrite Systems 5
input size runtime
Automated Complexity Analysis of Rewrite Systems 5
input size runtime
Automated Complexity Analysis of Rewrite Systems 5
input size runtime
Automated Complexity Analysis of Rewrite Systems 5
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
Example (ITS) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0] while(x, y, z)
1
− → return(z) [x = 0]
Automated Complexity Analysis of Rewrite Systems 7
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)
Automated Complexity Analysis of Rewrite Systems 7
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]
Automated Complexity Analysis of Rewrite Systems 7
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
Automated Complexity Analysis of Rewrite Systems 7
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)
Automated Complexity Analysis of Rewrite Systems 7
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]
Automated Complexity Analysis of Rewrite Systems 7
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 > 0
Automated Complexity Analysis of Rewrite Systems 7
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 > 0
5
− → while(0, 2, 4)
Automated Complexity Analysis of Rewrite Systems 7
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 > 0
5
− → while(0, 2, 4) [x/0, y/2, z/4]
Automated Complexity Analysis of Rewrite Systems 7
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 > 0
5
− → while(0, 2, 4) [x/0, y/2, z/4] | = x > 0
Automated Complexity Analysis of Rewrite Systems 7
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 > 0
5
− → while(0, 2, 4) [x/0, y/2, z/4] | = x = 0
Automated Complexity Analysis of Rewrite Systems 7
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 > 0
5
− → while(0, 2, 4) [x/0, y/2, z/4] | = x = 0
1
− → return(4)
Automated Complexity Analysis of Rewrite Systems 7
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
Automated Complexity Analysis of Rewrite Systems 8
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
5·n
− − → while(x − n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x]
Automated Complexity Analysis of Rewrite Systems 8
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
5·n
− − → while(x − n, y, z + y · n) [x > 0 ∧ 0 < n ≤ x] 5 · n: cost of n iterations
Automated Complexity Analysis of Rewrite Systems 8
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
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
Automated Complexity Analysis of Rewrite Systems 8
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
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
Automated Complexity Analysis of Rewrite Systems 8
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
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 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
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
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 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
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
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 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
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
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
x 2, x − 1, . . . would be fine, too
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
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
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
x 2, 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
Example (Loop Acceleration) while(x, y, z)
5
− → while(x − 1, y, z + y) [x > 0]
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
x 2, 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
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]
Automated Complexity Analysis of Rewrite Systems 9
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]
Automated Complexity Analysis of Rewrite Systems 9
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]
Automated Complexity Analysis of Rewrite Systems 9
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]
Automated Complexity Analysis of Rewrite Systems 9
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]
Automated Complexity Analysis of Rewrite Systems 9
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]
Automated Complexity Analysis of Rewrite Systems 9
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]
Automated Complexity Analysis of Rewrite Systems 9
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]
5·x+2
− − − → return(y · x) [x > 0 ∧ y ≥ 0]
Automated Complexity Analysis of Rewrite Systems 9
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]
5·x+2
− − − → return(y · x) [x > 0 ∧ y ≥ 0]
Automated Complexity Analysis of Rewrite Systems 9
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]
5·x+2
− − − → return(y · x) [x > 0 ∧ y ≥ 0] whole program compressed into a single rule
Automated Complexity Analysis of Rewrite Systems 9
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]
5·x+2
− − − → return(y · x) [x > 0 ∧ y ≥ 0] whole program compressed into a single rule lower bound 5 · x + 2 for all x > 0, y ≥ 0
Automated Complexity Analysis of Rewrite Systems 9
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]
5·x+2
− − − → return(y · x) [x > 0 ∧ y ≥ 0] whole program compressed into a single rule lower bound 5 · x + 2 for all x > 0, y ≥ 0 Works for arbitrary programs!
Automated Complexity Analysis of Rewrite Systems 9
first technique to infer worst case lower bounds for ITSs
Automated Complexity Analysis of Rewrite Systems 10
first technique to infer worst case lower bounds for ITSs key idea: loop acceleration
Automated Complexity Analysis of Rewrite Systems 10
first technique to infer worst case lower bounds for ITSs key idea: loop acceleration many other features, e.g.:
Automated Complexity Analysis of Rewrite Systems 10
first technique to infer worst case lower bounds for ITSs key idea: loop acceleration many other features, e.g.:
non-determinism
Automated Complexity Analysis of Rewrite Systems 10
first technique to infer worst case lower bounds for ITSs key idea: loop acceleration many other features, e.g.:
non-determinism asymptotic bounds
Automated Complexity Analysis of Rewrite Systems 10
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 . . .
Automated Complexity Analysis of Rewrite Systems 10
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 Best Upper Bound 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
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
Example (TRS) inf(y) − → cons(y,inf(s(y)))
Automated Complexity Analysis of Rewrite Systems 12
Example (TRS) inf(y) − → cons(y,inf(s(y))) Example (Evaluation) inf(0)
Automated Complexity Analysis of Rewrite Systems 12
Example (TRS) inf(y) − → cons(y,inf(s(y))) Example (Evaluation) inf(0) [y/0]
Automated Complexity Analysis of Rewrite Systems 12
Example (TRS) inf(y) − → cons(y,inf(s(y))) Example (Evaluation) inf(0) [y/0] − → cons(0, inf(s(0)))
Automated Complexity Analysis of Rewrite Systems 12
Example (TRS) inf(y) − → cons(y,inf(s(y))) Example (Evaluation) inf(0) [y/0] − → cons(0, inf(s(0))) [y/s(0)]
Automated Complexity Analysis of Rewrite Systems 12
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)))))
Automated Complexity Analysis of Rewrite Systems 12
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
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
Example (TRS) inf(y) − → cons(y,inf(s(y))) Loop
Automated Complexity Analysis of Rewrite Systems 12
Example (TRS) inf(y) − → cons(y,inf(s(y))) Loop = ⇒ Non-Termination
Automated Complexity Analysis of Rewrite Systems 12
Example (TRS) inf(y) − → cons(y,inf(s(0))) Loop = ⇒ Non-Termination
Automated Complexity Analysis of Rewrite Systems 12
Example length(cons(x, x′)) − → s(length(x′))
Automated Complexity Analysis of Rewrite Systems 13
Example length(cons(x, x′)) − → s(length(x′)) Loop
Automated Complexity Analysis of Rewrite Systems 13
Example length(cons(x, x′)) − → s(length(x′)) Decreasing Loop Loop
Automated Complexity Analysis of Rewrite Systems 13
Example length(cons(x, x′)) − → s(length(x′)) Decreasing Loop = ⇒ Linear Lower Bound Loop
Automated Complexity Analysis of Rewrite Systems 13
Example length(cons(x, x′)) − → s(length(nil)) Decreasing Loop
⇒ Linear Lower Bound Loop
Automated Complexity Analysis of Rewrite Systems 13
Example length(cons(x, x′)) − → s(length(x′)) Decreasing Loop = ⇒ Linear Lower Bound Loop
Automated Complexity Analysis of Rewrite Systems 13
Example length(cons(x, x′)) − → s(length(x′))
− → length(x′, s(y))
Automated Complexity Analysis of Rewrite Systems 14
Example length(cons(x, x′)) − → s(length(x′))
− → length(x′, s(y)) Decreasing Loops Loops
Automated Complexity Analysis of Rewrite Systems 14
Example length(cons(x, x′)) − → s(length(x′))
− → length(x′, s(y)) Decreasing Loops Revised
Automated Complexity Analysis of Rewrite Systems 14
Theorem If a TRS has a decreasing loop, then its complexity is at least linear.
Automated Complexity Analysis of Rewrite Systems 15
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.
Automated Complexity Analysis of Rewrite Systems 15
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. Example (Compatible Decreasing Loops) fib(s(s(x))) − → plus(fib(s(x)), fib(x))
Automated Complexity Analysis of Rewrite Systems 15
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. Example (Compatible Decreasing Loops) fib(s(s(x))) − → plus(fib(s(x)), fib(x))
Automated Complexity Analysis of Rewrite Systems 15
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
first technique to infer worst case lower bounds for TRSs
Automated Complexity Analysis of Rewrite Systems 16
first technique to infer worst case lower bounds for TRSs key idea: generalize loops
Automated Complexity Analysis of Rewrite Systems 16
first technique to infer worst case lower bounds for TRSs key idea: generalize loops linear, exponential, infinite bounds
Automated Complexity Analysis of Rewrite Systems 16
first technique to infer worst case lower bounds for TRSs key idea: generalize loops linear, exponential, infinite bounds
quadratic, cubic, . . .?
Automated Complexity Analysis of Rewrite Systems 16
first technique to infer worst case lower bounds for TRSs key idea: generalize loops linear, exponential, infinite bounds
quadratic, cubic, . . .? “induction technique”
Automated Complexity Analysis of Rewrite Systems 16
first second technique to infer worst case lower bounds for TRSs key idea: generalize loops linear, exponential, infinite bounds
quadratic, cubic, . . .? “induction technique”
Automated Complexity Analysis of Rewrite Systems 16
first second technique to infer worst case lower bounds for TRSs key idea: generalize loops linear, exponential, infinite bounds
quadratic, cubic, . . .? “induction technique”
incomplete
Automated Complexity Analysis of Rewrite Systems 16
first second technique to infer worst case lower bounds for TRSs key idea: generalize loops linear, exponential, infinite bounds
quadratic, cubic, . . .? “induction technique”
incomplete AProVE Ω(1) Ω(n) EXP ∞ 66 600 143 90
Automated Complexity Analysis of Rewrite Systems 16
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
Example (from TPDB) f(a) − → g(h(a)) h(g(x)) − → g(h(f(x)))
Automated Complexity Analysis of Rewrite Systems 18
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.
Automated Complexity Analysis of Rewrite Systems 18
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)
Automated Complexity Analysis of Rewrite Systems 18
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)]
Automated Complexity Analysis of Rewrite Systems 18
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)]
Automated Complexity Analysis of Rewrite Systems 18
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)]
[x/a]
Automated Complexity Analysis of Rewrite Systems 18
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)]
[x/a]
Automated Complexity Analysis of Rewrite Systems 18
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)]
[x/a]
[x/h(a)]
Automated Complexity Analysis of Rewrite Systems 18
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)]
[x/a]
[x/h(a)]
Automated Complexity Analysis of Rewrite Systems 18
Theorem The complexity of a TRS is constant iff narrowing terminates for all terms f(x1, . . . , xn).
Automated Complexity Analysis of Rewrite Systems 19
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
semi-decision procedure for constant bounds
Automated Complexity Analysis of Rewrite Systems 20
semi-decision procedure for constant bounds key idea: use narrowing
Automated Complexity Analysis of Rewrite Systems 20
semi-decision procedure for constant bounds key idea: use narrowing AProVE can (dis-)prove constant complexity in almost all cases
Automated Complexity Analysis of Rewrite Systems 20
semi-decision procedure for constant bounds key idea: use narrowing AProVE can (dis-)prove constant complexity in almost all cases Evaluation (TPDB – 899 examples) succeeds for all 57 TRSs with constant complexity
Automated Complexity Analysis of Rewrite Systems 20
semi-decision procedure for constant bounds key idea: use narrowing 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
integers and data structures
Automated Complexity Analysis of Rewrite Systems 21
integers and data structures floats, arrays, . . .
Automated Complexity Analysis of Rewrite Systems 21
integers and data structures floats, arrays, . . . underapproximating program transformations
Automated Complexity Analysis of Rewrite Systems 21
Program (Java, C, . . .) AProVE SE-Graph AProVE Integer Transition System Term Rewrite System AProVE CoFloCo LoAT . . . Upper Bound Lower Bound
integers and data structures floats, arrays, . . . underapproximating program transformations
Automated Complexity Analysis of Rewrite Systems 21
Program (Java, C, . . .) AProVE SE-Graph AProVE Integer Transition System Term Rewrite System AProVE CoFloCo LoAT . . . Upper Bound Lower Bound
integers and data structures floats, arrays, . . . underapproximating program transformations
Automated Complexity Analysis of Rewrite Systems 21
’15 • Induction Technique for TRSs RTA ’16 • Lower Bounds for ITSs IJCAR ’17 • Decreasing Loops for TRSs JAR ’17 • Upper Bounds for TRSs (full rewriting) LPAR ’17 • Upper Bounds for TRSs (innermost rewriting) FroCoS ’17 • Upper Bounds for Java iFM ’18 • Constant Upper Bounds for TRSs IPL
Automated Complexity Analysis of Rewrite Systems 22
’15 • Induction Technique for TRSs RTA ’16 • Lower Bounds for ITSs IJCAR ’17 • Decreasing Loops for TRSs JAR ’17 • Upper Bounds for TRSs (full rewriting) LPAR ’17 • Upper Bounds for TRSs (innermost rewriting) FroCoS ’17 • Upper Bounds for Java iFM ’18 • Constant Upper Bounds for TRSs IPL
Automated Complexity Analysis of Rewrite Systems 22
’15 • Induction Technique for TRSs RTA ’16 • Lower Bounds for ITSs IJCAR ’17 • Decreasing Loops for TRSs JAR ’17 • Upper Bounds for TRSs (full rewriting) LPAR ’17 • Upper Bounds for TRSs (innermost rewriting) FroCoS ’17 • Upper Bounds for Java iFM ’18 • Constant Upper Bounds for TRSs IPL
Automated Complexity Analysis of Rewrite Systems 22
’15 • Induction Technique for TRSs RTA ’16 • Lower Bounds for ITSs IJCAR ’17 • Decreasing Loops for TRSs JAR ’17 • Upper Bounds for TRSs (full rewriting) LPAR ’17 • Upper Bounds for TRSs (innermost rewriting) 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
’15 • Induction Technique for TRSs RTA ’16 • Lower Bounds for ITSs IJCAR ’17 • Decreasing Loops for TRSs JAR ’17 • Upper Bounds for TRSs (full rewriting) LPAR ’17 • Upper Bounds for TRSs (innermost rewriting) 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
points of AProVE points 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
Example (Recurrence Solving) y(v+1) = 1 − y(v) x(v+1) = x(v) + 1 − 3y(v) y(v) =
1 2 − 1 2(−1)v + (−1)vy
x(v) =
3 4 − 3 4(−1)v − 3 2y − 1 2v + 3 2(−1)vy + x
Automated Complexity Analysis of Rewrite Systems 24