0 CpxTRS
↳1 TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID), 1 ms)
↳2 CpxWeightedTrs
↳3 TypeInferenceProof (BOTH BOUNDS(ID, ID), 0 ms)
↳4 CpxTypedWeightedTrs
↳5 CompletionProof (UPPER BOUND(ID), 0 ms)
↳6 CpxTypedWeightedCompleteTrs
↳7 CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID), 0 ms)
↳8 CpxRNTS
↳9 CompleteCoflocoProof (⇔, 302 ms)
↳10 BOUNDS(1, n^2)
sub(0, 0) → 0
sub(s(x), 0) → s(x)
sub(0, s(x)) → 0
sub(s(x), s(y)) → sub(x, y)
zero(nil) → zero2(0, nil)
zero(cons(x, xs)) → zero2(sub(x, x), cons(x, xs))
zero2(0, nil) → nil
zero2(0, cons(x, xs)) → cons(sub(x, x), zero(xs))
zero2(s(y), nil) → zero(nil)
zero2(s(y), cons(x, xs)) → zero(cons(x, xs))
sub(0, 0) → 0 [1]
sub(s(x), 0) → s(x) [1]
sub(0, s(x)) → 0 [1]
sub(s(x), s(y)) → sub(x, y) [1]
zero(nil) → zero2(0, nil) [1]
zero(cons(x, xs)) → zero2(sub(x, x), cons(x, xs)) [1]
zero2(0, nil) → nil [1]
zero2(0, cons(x, xs)) → cons(sub(x, x), zero(xs)) [1]
zero2(s(y), nil) → zero(nil) [1]
zero2(s(y), cons(x, xs)) → zero(cons(x, xs)) [1]
sub(0, 0) → 0 [1]
sub(s(x), 0) → s(x) [1]
sub(0, s(x)) → 0 [1]
sub(s(x), s(y)) → sub(x, y) [1]
zero(nil) → zero2(0, nil) [1]
zero(cons(x, xs)) → zero2(sub(x, x), cons(x, xs)) [1]
zero2(0, nil) → nil [1]
zero2(0, cons(x, xs)) → cons(sub(x, x), zero(xs)) [1]
zero2(s(y), nil) → zero(nil) [1]
zero2(s(y), cons(x, xs)) → zero(cons(x, xs)) [1]
sub :: 0:s → 0:s → 0:s 0 :: 0:s s :: 0:s → 0:s zero :: nil:cons → nil:cons nil :: nil:cons zero2 :: 0:s → nil:cons → nil:cons cons :: 0:s → nil:cons → nil:cons |
Runtime Complexity Weighted TRS with Types. The TRS R consists of the following rules:
The TRS has the following type information:
Rewrite Strategy: INNERMOST |
0 => 0
nil => 0
sub(z, z') -{ 1 }→ sub(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
sub(z, z') -{ 1 }→ 0 :|: z = 0, z' = 0
sub(z, z') -{ 1 }→ 0 :|: z' = 1 + x, x >= 0, z = 0
sub(z, z') -{ 1 }→ 1 + x :|: x >= 0, z = 1 + x, z' = 0
zero(z) -{ 1 }→ zero2(sub(x, x), 1 + x + xs) :|: z = 1 + x + xs, xs >= 0, x >= 0
zero(z) -{ 1 }→ zero2(0, 0) :|: z = 0
zero2(z, z') -{ 1 }→ zero(0) :|: y >= 0, z = 1 + y, z' = 0
zero2(z, z') -{ 1 }→ zero(1 + x + xs) :|: xs >= 0, z' = 1 + x + xs, y >= 0, x >= 0, z = 1 + y
zero2(z, z') -{ 1 }→ 0 :|: z = 0, z' = 0
zero2(z, z') -{ 1 }→ 1 + sub(x, x) + zero(xs) :|: xs >= 0, z' = 1 + x + xs, x >= 0, z = 0
eq(start(V, V1),0,[sub(V, V1, Out)],[V >= 0,V1 >= 0]). eq(start(V, V1),0,[zero(V, Out)],[V >= 0]). eq(start(V, V1),0,[zero2(V, V1, Out)],[V >= 0,V1 >= 0]). eq(sub(V, V1, Out),1,[],[Out = 0,V = 0,V1 = 0]). eq(sub(V, V1, Out),1,[],[Out = 1 + V2,V2 >= 0,V = 1 + V2,V1 = 0]). eq(sub(V, V1, Out),1,[],[Out = 0,V1 = 1 + V3,V3 >= 0,V = 0]). eq(sub(V, V1, Out),1,[sub(V4, V5, Ret)],[Out = Ret,V1 = 1 + V5,V4 >= 0,V5 >= 0,V = 1 + V4]). eq(zero(V, Out),1,[zero2(0, 0, Ret1)],[Out = Ret1,V = 0]). eq(zero(V, Out),1,[sub(V6, V6, Ret0),zero2(Ret0, 1 + V6 + V7, Ret2)],[Out = Ret2,V = 1 + V6 + V7,V7 >= 0,V6 >= 0]). eq(zero2(V, V1, Out),1,[],[Out = 0,V = 0,V1 = 0]). eq(zero2(V, V1, Out),1,[sub(V8, V8, Ret01),zero(V9, Ret11)],[Out = 1 + Ret01 + Ret11,V9 >= 0,V1 = 1 + V8 + V9,V8 >= 0,V = 0]). eq(zero2(V, V1, Out),1,[zero(0, Ret3)],[Out = Ret3,V10 >= 0,V = 1 + V10,V1 = 0]). eq(zero2(V, V1, Out),1,[zero(1 + V11 + V12, Ret4)],[Out = Ret4,V12 >= 0,V1 = 1 + V11 + V12,V13 >= 0,V11 >= 0,V = 1 + V13]). input_output_vars(sub(V,V1,Out),[V,V1],[Out]). input_output_vars(zero(V,Out),[V],[Out]). input_output_vars(zero2(V,V1,Out),[V,V1],[Out]). |
CoFloCo proof output:
Preprocessing Cost Relations
=====================================
#### Computed strongly connected components
0. recursive : [sub/3]
1. recursive : [zero/2,zero2/3]
2. non_recursive : [start/2]
#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into sub/3
1. SCC is partially evaluated into zero/2
2. SCC is partially evaluated into start/2
Control-Flow Refinement of Cost Relations
=====================================
### Specialization of cost equations sub/3
* CE 14 is refined into CE [15]
* CE 12 is refined into CE [16]
* CE 13 is refined into CE [17]
* CE 11 is refined into CE [18]
### Cost equations --> "Loop" of sub/3
* CEs [16] --> Loop 11
* CEs [17] --> Loop 12
* CEs [18] --> Loop 13
* CEs [15] --> Loop 14
### Ranking functions of CR sub(V,V1,Out)
* RF of phase [14]: [V,V1]
#### Partial ranking functions of CR sub(V,V1,Out)
* Partial RF of phase [14]:
- RF of loop [14:1]:
V
V1
### Specialization of cost equations zero/2
* CE 10 is refined into CE [19]
* CE 9 is refined into CE [20,21,22,23]
* CE 8 is discarded (unfeasible)
### Cost equations --> "Loop" of zero/2
* CEs [21,23] --> Loop 15
* CEs [20,22] --> Loop 16
* CEs [19] --> Loop 17
### Ranking functions of CR zero(V,Out)
* RF of phase [15,16]: [V]
#### Partial ranking functions of CR zero(V,Out)
* Partial RF of phase [15,16]:
- RF of loop [15:1]:
V-1
- RF of loop [16:1]:
V
### Specialization of cost equations start/2
* CE 3 is refined into CE [24]
* CE 4 is refined into CE [25,26,27,28]
* CE 2 is refined into CE [29]
* CE 5 is refined into CE [30]
* CE 6 is refined into CE [31,32,33,34,35,36]
* CE 7 is refined into CE [37,38]
### Cost equations --> "Loop" of start/2
* CEs [34] --> Loop 18
* CEs [24,29,33,35,36,38] --> Loop 19
* CEs [25,26,27,28,30,31,32,37] --> Loop 20
### Ranking functions of CR start(V,V1)
#### Partial ranking functions of CR start(V,V1)
Computing Bounds
=====================================
#### Cost of chains of sub(V,V1,Out):
* Chain [[14],13]: 1*it(14)+1
Such that:it(14) =< V
with precondition: [Out=0,V=V1,V>=1]
* Chain [[14],12]: 1*it(14)+1
Such that:it(14) =< V
with precondition: [Out=0,V>=1,V1>=V+1]
* Chain [[14],11]: 1*it(14)+1
Such that:it(14) =< V1
with precondition: [V=Out+V1,V1>=1,V>=V1+1]
* Chain [13]: 1
with precondition: [V=0,V1=0,Out=0]
* Chain [12]: 1
with precondition: [V=0,Out=0,V1>=1]
* Chain [11]: 1
with precondition: [V1=0,V=Out,V>=1]
#### Cost of chains of zero(V,Out):
* Chain [[15,16],17]: 10*it(15)+1*s(10)+1*s(12)+2
Such that:aux(6) =< V
it(15) =< aux(6)
aux(3) =< aux(6)-1
s(10) =< it(15)*aux(6)
s(12) =< it(15)*aux(3)
with precondition: [Out>=1,V>=Out]
* Chain [17]: 2
with precondition: [V=0,Out=0]
#### Cost of chains of start(V,V1):
* Chain [20]: 22*s(14)+2*s(16)+2*s(17)+4
Such that:aux(8) =< V1
s(14) =< aux(8)
s(15) =< aux(8)-1
s(16) =< s(14)*aux(8)
s(17) =< s(14)*s(15)
with precondition: [V=0]
* Chain [19]: 11*s(26)+1*s(28)+1*s(29)+11*s(30)+1*s(35)+1*s(36)+3
Such that:aux(9) =< V
aux(10) =< V1
s(30) =< aux(9)
s(26) =< aux(10)
s(34) =< aux(9)-1
s(35) =< s(30)*aux(9)
s(36) =< s(30)*s(34)
s(27) =< aux(10)-1
s(28) =< s(26)*aux(10)
s(29) =< s(26)*s(27)
with precondition: [V>=1]
* Chain [18]: 1*s(37)+1
Such that:s(37) =< V1
with precondition: [V=V1,V>=1]
Closed-form bounds of start(V,V1):
-------------------------------------
* Chain [20] with precondition: [V=0]
- Upper bound: nat(V1)*22+4+nat(V1)*2*nat(V1)+nat(nat(V1)+ -1)*2*nat(V1)
- Complexity: n^2
* Chain [19] with precondition: [V>=1]
- Upper bound: 11*V+3+V*V+nat(V1)*11+nat(V1)*nat(V1)+ (V-1)*V+nat(nat(V1)+ -1)*nat(V1)
- Complexity: n^2
* Chain [18] with precondition: [V=V1,V>=1]
- Upper bound: V1+1
- Complexity: n
### Maximum cost of start(V,V1): nat(V1)*10+2+nat(V1)*nat(V1)+nat(nat(V1)+ -1)*nat(V1)+max([11*V+V*V+nat(V-1)*V,nat(V1)*11+1+nat(V1)*nat(V1)+nat(nat(V1)+ -1)*nat(V1)])+ (nat(V1)+1)
Asymptotic class: n^2
* Total analysis performed in 221 ms.