(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

length(nil) → 0
length(cons(x, l)) → s(length(l))
lt(x, 0) → false
lt(0, s(y)) → true
lt(s(x), s(y)) → lt(x, y)
head(cons(x, l)) → x
head(nil) → undefined
tail(nil) → nil
tail(cons(x, l)) → l
reverse(l) → rev(0, l, nil, l)
rev(x, l, accu, orig) → if(lt(x, length(orig)), x, l, accu, orig)
if(true, x, l, accu, orig) → rev(s(x), tail(l), cons(head(l), accu), orig)
if(false, x, l, accu, orig) → accu

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

length(nil) → 0 [1]
length(cons(x, l)) → s(length(l)) [1]
lt(x, 0) → false [1]
lt(0, s(y)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]
head(cons(x, l)) → x [1]
head(nil) → undefined [1]
tail(nil) → nil [1]
tail(cons(x, l)) → l [1]
reverse(l) → rev(0, l, nil, l) [1]
rev(x, l, accu, orig) → if(lt(x, length(orig)), x, l, accu, orig) [1]
if(true, x, l, accu, orig) → rev(s(x), tail(l), cons(head(l), accu), orig) [1]
if(false, x, l, accu, orig) → accu [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

length(nil) → 0 [1]
length(cons(x, l)) → s(length(l)) [1]
lt(x, 0) → false [1]
lt(0, s(y)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]
head(cons(x, l)) → x [1]
head(nil) → undefined [1]
tail(nil) → nil [1]
tail(cons(x, l)) → l [1]
reverse(l) → rev(0, l, nil, l) [1]
rev(x, l, accu, orig) → if(lt(x, length(orig)), x, l, accu, orig) [1]
if(true, x, l, accu, orig) → rev(s(x), tail(l), cons(head(l), accu), orig) [1]
if(false, x, l, accu, orig) → accu [1]

The TRS has the following type information:
length :: nil:cons → 0:s
nil :: nil:cons
0 :: 0:s
cons :: undefined → nil:cons → nil:cons
s :: 0:s → 0:s
lt :: 0:s → 0:s → false:true
false :: false:true
true :: false:true
head :: nil:cons → undefined
undefined :: undefined
tail :: nil:cons → nil:cons
reverse :: nil:cons → nil:cons
rev :: 0:s → nil:cons → nil:cons → nil:cons → nil:cons
if :: false:true → 0:s → nil:cons → nil:cons → nil:cons → nil:cons

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

length(nil) → 0 [1]
length(cons(x, l)) → s(length(l)) [1]
lt(x, 0) → false [1]
lt(0, s(y)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]
head(cons(x, l)) → x [1]
head(nil) → undefined [1]
tail(nil) → nil [1]
tail(cons(x, l)) → l [1]
reverse(l) → rev(0, l, nil, l) [1]
rev(x, l, accu, orig) → if(lt(x, length(orig)), x, l, accu, orig) [1]
if(true, x, l, accu, orig) → rev(s(x), tail(l), cons(head(l), accu), orig) [1]
if(false, x, l, accu, orig) → accu [1]

The TRS has the following type information:
length :: nil:cons → 0:s
nil :: nil:cons
0 :: 0:s
cons :: undefined → nil:cons → nil:cons
s :: 0:s → 0:s
lt :: 0:s → 0:s → false:true
false :: false:true
true :: false:true
head :: nil:cons → undefined
undefined :: undefined
tail :: nil:cons → nil:cons
reverse :: nil:cons → nil:cons
rev :: 0:s → nil:cons → nil:cons → nil:cons → nil:cons
if :: false:true → 0:s → nil:cons → nil:cons → nil:cons → nil:cons

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

nil => 0
0 => 0
false => 0
true => 1
undefined => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

head(z) -{ 1 }→ x :|: x >= 0, l >= 0, z = 1 + x + l
head(z) -{ 1 }→ 0 :|: z = 0
if(z, z', z'', z1, z2) -{ 1 }→ accu :|: z2 = orig, z' = x, z1 = accu, orig >= 0, x >= 0, l >= 0, z = 0, accu >= 0, z'' = l
if(z, z', z'', z1, z2) -{ 1 }→ rev(1 + x, tail(l), 1 + head(l) + accu, orig) :|: z2 = orig, z' = x, z1 = accu, z = 1, orig >= 0, x >= 0, l >= 0, accu >= 0, z'' = l
length(z) -{ 1 }→ 0 :|: z = 0
length(z) -{ 1 }→ 1 + length(l) :|: x >= 0, l >= 0, z = 1 + x + l
lt(z, z') -{ 1 }→ lt(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
lt(z, z') -{ 1 }→ 1 :|: z' = 1 + y, y >= 0, z = 0
lt(z, z') -{ 1 }→ 0 :|: x >= 0, z = x, z' = 0
rev(z, z', z'', z1) -{ 1 }→ if(lt(x, length(orig)), x, l, accu, orig) :|: z' = l, orig >= 0, x >= 0, l >= 0, z'' = accu, z = x, accu >= 0, z1 = orig
reverse(z) -{ 1 }→ rev(0, l, 0, l) :|: z = l, l >= 0
tail(z) -{ 1 }→ l :|: x >= 0, l >= 0, z = 1 + x + l
tail(z) -{ 1 }→ 0 :|: z = 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V3, V13, V14, V19),0,[length(V, Out)],[V >= 0]).
eq(start(V, V3, V13, V14, V19),0,[lt(V, V3, Out)],[V >= 0,V3 >= 0]).
eq(start(V, V3, V13, V14, V19),0,[head(V, Out)],[V >= 0]).
eq(start(V, V3, V13, V14, V19),0,[tail(V, Out)],[V >= 0]).
eq(start(V, V3, V13, V14, V19),0,[reverse(V, Out)],[V >= 0]).
eq(start(V, V3, V13, V14, V19),0,[rev(V, V3, V13, V14, Out)],[V >= 0,V3 >= 0,V13 >= 0,V14 >= 0]).
eq(start(V, V3, V13, V14, V19),0,[if(V, V3, V13, V14, V19, Out)],[V >= 0,V3 >= 0,V13 >= 0,V14 >= 0,V19 >= 0]).
eq(length(V, Out),1,[],[Out = 0,V = 0]).
eq(length(V, Out),1,[length(V1, Ret1)],[Out = 1 + Ret1,V2 >= 0,V1 >= 0,V = 1 + V1 + V2]).
eq(lt(V, V3, Out),1,[],[Out = 0,V4 >= 0,V = V4,V3 = 0]).
eq(lt(V, V3, Out),1,[],[Out = 1,V3 = 1 + V5,V5 >= 0,V = 0]).
eq(lt(V, V3, Out),1,[lt(V6, V7, Ret)],[Out = Ret,V3 = 1 + V7,V6 >= 0,V7 >= 0,V = 1 + V6]).
eq(head(V, Out),1,[],[Out = V8,V8 >= 0,V9 >= 0,V = 1 + V8 + V9]).
eq(head(V, Out),1,[],[Out = 0,V = 0]).
eq(tail(V, Out),1,[],[Out = 0,V = 0]).
eq(tail(V, Out),1,[],[Out = V10,V11 >= 0,V10 >= 0,V = 1 + V10 + V11]).
eq(reverse(V, Out),1,[rev(0, V12, 0, V12, Ret2)],[Out = Ret2,V = V12,V12 >= 0]).
eq(rev(V, V3, V13, V14, Out),1,[length(V16, Ret01),lt(V15, Ret01, Ret0),if(Ret0, V15, V17, V18, V16, Ret3)],[Out = Ret3,V3 = V17,V16 >= 0,V15 >= 0,V17 >= 0,V13 = V18,V = V15,V18 >= 0,V14 = V16]).
eq(if(V, V3, V13, V14, V19, Out),1,[tail(V21, Ret11),head(V21, Ret201),rev(1 + V20, Ret11, 1 + Ret201 + V22, V23, Ret4)],[Out = Ret4,V19 = V23,V3 = V20,V14 = V22,V = 1,V23 >= 0,V20 >= 0,V21 >= 0,V22 >= 0,V13 = V21]).
eq(if(V, V3, V13, V14, V19, Out),1,[],[Out = V24,V19 = V25,V3 = V26,V14 = V24,V25 >= 0,V26 >= 0,V27 >= 0,V = 0,V24 >= 0,V13 = V27]).
input_output_vars(length(V,Out),[V],[Out]).
input_output_vars(lt(V,V3,Out),[V,V3],[Out]).
input_output_vars(head(V,Out),[V],[Out]).
input_output_vars(tail(V,Out),[V],[Out]).
input_output_vars(reverse(V,Out),[V],[Out]).
input_output_vars(rev(V,V3,V13,V14,Out),[V,V3,V13,V14],[Out]).
input_output_vars(if(V,V3,V13,V14,V19,Out),[V,V3,V13,V14,V19],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. non_recursive : [head/2]
1. recursive : [length/2]
2. recursive : [lt/3]
3. non_recursive : [tail/2]
4. recursive : [if/6,rev/5]
5. non_recursive : [reverse/2]
6. non_recursive : [start/5]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into head/2
1. SCC is partially evaluated into length/2
2. SCC is partially evaluated into lt/3
3. SCC is partially evaluated into tail/2
4. SCC is partially evaluated into rev/5
5. SCC is completely evaluated into other SCCs
6. SCC is partially evaluated into start/5

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations head/2
* CE 12 is refined into CE [21]
* CE 13 is refined into CE [22]


### Cost equations --> "Loop" of head/2
* CEs [21] --> Loop 14
* CEs [22] --> Loop 15

### Ranking functions of CR head(V,Out)

#### Partial ranking functions of CR head(V,Out)


### Specialization of cost equations length/2
* CE 17 is refined into CE [23]
* CE 16 is refined into CE [24]


### Cost equations --> "Loop" of length/2
* CEs [24] --> Loop 16
* CEs [23] --> Loop 17

### Ranking functions of CR length(V,Out)
* RF of phase [17]: [V]

#### Partial ranking functions of CR length(V,Out)
* Partial RF of phase [17]:
- RF of loop [17:1]:
V


### Specialization of cost equations lt/3
* CE 20 is refined into CE [25]
* CE 18 is refined into CE [26]
* CE 19 is refined into CE [27]


### Cost equations --> "Loop" of lt/3
* CEs [26] --> Loop 18
* CEs [27] --> Loop 19
* CEs [25] --> Loop 20

### Ranking functions of CR lt(V,V3,Out)
* RF of phase [20]: [V,V3]

#### Partial ranking functions of CR lt(V,V3,Out)
* Partial RF of phase [20]:
- RF of loop [20:1]:
V
V3


### Specialization of cost equations tail/2
* CE 11 is refined into CE [28]
* CE 10 is refined into CE [29]


### Cost equations --> "Loop" of tail/2
* CEs [28] --> Loop 21
* CEs [29] --> Loop 22

### Ranking functions of CR tail(V,Out)

#### Partial ranking functions of CR tail(V,Out)


### Specialization of cost equations rev/5
* CE 15 is refined into CE [30,31,32,33]
* CE 14 is refined into CE [34,35]


### Cost equations --> "Loop" of rev/5
* CEs [35] --> Loop 23
* CEs [34] --> Loop 24
* CEs [33] --> Loop 25
* CEs [32] --> Loop 26
* CEs [31] --> Loop 27
* CEs [30] --> Loop 28

### Ranking functions of CR rev(V,V3,V13,V14,Out)
* RF of phase [25]: [-V+V14,V3]
* RF of phase [26]: [-V+V14]

#### Partial ranking functions of CR rev(V,V3,V13,V14,Out)
* Partial RF of phase [25]:
- RF of loop [25:1]:
-V+V14
V3
* Partial RF of phase [26]:
- RF of loop [26:1]:
-V+V14


### Specialization of cost equations start/5
* CE 3 is refined into CE [36,37,38,39,40,41,42]
* CE 2 is refined into CE [43]
* CE 4 is refined into CE [44,45]
* CE 5 is refined into CE [46,47,48,49]
* CE 6 is refined into CE [50,51]
* CE 7 is refined into CE [52,53]
* CE 8 is refined into CE [54,55,56,57]
* CE 9 is refined into CE [58,59,60,61,62,63,64,65,66]


### Cost equations --> "Loop" of start/5
* CEs [64] --> Loop 29
* CEs [47,63] --> Loop 30
* CEs [39,41,42] --> Loop 31
* CEs [40] --> Loop 32
* CEs [36,38] --> Loop 33
* CEs [37,45,48,49,51,53,54,55,56,65,66] --> Loop 34
* CEs [43,44,46,50,52,57,58,59,60,61,62] --> Loop 35

### Ranking functions of CR start(V,V3,V13,V14,V19)

#### Partial ranking functions of CR start(V,V3,V13,V14,V19)


Computing Bounds
=====================================

#### Cost of chains of head(V,Out):
* Chain [15]: 1
with precondition: [V=0,Out=0]

* Chain [14]: 1
with precondition: [Out>=0,V>=Out+1]


#### Cost of chains of length(V,Out):
* Chain [[17],16]: 1*it(17)+1
Such that:it(17) =< V

with precondition: [Out>=1,V>=Out]

* Chain [16]: 1
with precondition: [V=0,Out=0]


#### Cost of chains of lt(V,V3,Out):
* Chain [[20],19]: 1*it(20)+1
Such that:it(20) =< V

with precondition: [Out=1,V>=1,V3>=V+1]

* Chain [[20],18]: 1*it(20)+1
Such that:it(20) =< V3

with precondition: [Out=0,V3>=1,V>=V3]

* Chain [19]: 1
with precondition: [V=0,Out=1,V3>=1]

* Chain [18]: 1
with precondition: [V3=0,Out=0,V>=0]


#### Cost of chains of tail(V,Out):
* Chain [22]: 1
with precondition: [V=0,Out=0]

* Chain [21]: 1
with precondition: [Out>=0,V>=Out+1]


#### Cost of chains of rev(V,V3,V13,V14,Out):
* Chain [[26],23]: 6*it(26)+2*s(1)+2*s(7)+4
Such that:it(26) =< -V13+Out
aux(5) =< V14
s(1) =< aux(5)
s(7) =< it(26)*aux(5)

with precondition: [V3=0,V>=1,V13>=0,Out>=V13+1,V13+V14>=Out+V]

* Chain [[25],[26],23]: 12*it(25)+2*s(1)+4*s(7)+4
Such that:aux(9) =< -V+V14
aux(10) =< V14
it(25) =< aux(9)
s(1) =< aux(10)
s(7) =< it(25)*aux(10)

with precondition: [V>=1,V3>=1,V13>=0,V14>=V+2,Out>=V13+2]

* Chain [[25],23]: 6*it(25)+2*s(1)+2*s(13)+4
Such that:it(25) =< -V+V14
aux(11) =< V14
s(1) =< aux(11)
s(13) =< it(25)*aux(11)

with precondition: [V>=1,V3>=1,V13>=0,V14>=V+1,Out>=V13+1]

* Chain [28,[26],23]: 6*it(26)+3*s(1)+2*s(7)+10
Such that:it(26) =< -V13+Out
aux(12) =< V14
s(1) =< aux(12)
s(7) =< it(26)*aux(12)

with precondition: [V=0,V3=0,V13>=0,Out>=V13+2,V13+V14>=Out]

* Chain [28,23]: 3*s(1)+10
Such that:aux(13) =< V14
s(1) =< aux(13)

with precondition: [V=0,V3=0,Out=V13+1,V14>=1,Out>=1]

* Chain [27,[26],23]: 9*it(26)+2*s(7)+10
Such that:aux(14) =< V14
it(26) =< aux(14)
s(7) =< it(26)*aux(14)

with precondition: [V=0,V3>=1,V13>=0,V14>=2,Out>=V13+2,V3+V13+V14>=Out+1]

* Chain [27,[25],[26],23]: 15*it(25)+4*s(7)+10
Such that:aux(15) =< V14
it(25) =< aux(15)
s(7) =< it(25)*aux(15)

with precondition: [V=0,V3>=2,V13>=0,V14>=3,Out>=V13+3]

* Chain [27,[25],23]: 9*it(25)+2*s(13)+10
Such that:aux(16) =< V14
it(25) =< aux(16)
s(13) =< it(25)*aux(16)

with precondition: [V=0,V3>=2,V13>=0,V14>=2,Out>=V13+2]

* Chain [27,23]: 3*s(1)+10
Such that:aux(17) =< V14
s(1) =< aux(17)

with precondition: [V=0,V13>=0,V14>=1,Out>=V13+1,V3+V13>=Out]

* Chain [24]: 4
with precondition: [V14=0,V13=Out,V>=0,V3>=0,V13>=0]

* Chain [23]: 2*s(1)+4
Such that:aux(1) =< V14
s(1) =< aux(1)

with precondition: [V13=Out,V>=1,V3>=0,V13>=0,V14>=1]


#### Cost of chains of start(V,V3,V13,V14,V19):
* Chain [35]: 48*s(33)+10*s(37)+10
Such that:aux(22) =< V14
s(33) =< aux(22)
s(37) =< s(33)*aux(22)

with precondition: [V=0]

* Chain [34]: 38*s(46)+1*s(47)+8*s(51)+6*s(58)+18*s(61)+6*s(63)+11
Such that:s(59) =< -V+V14
s(47) =< V3
aux(23) =< V
aux(24) =< V14
s(46) =< aux(23)
s(61) =< s(59)
s(58) =< aux(24)
s(63) =< s(61)*aux(24)
s(51) =< s(46)*aux(23)

with precondition: [V>=1]

* Chain [33]: 6*s(64)+4*s(66)+2*s(67)+7
Such that:s(64) =< -V3+V19
aux(25) =< V19
s(66) =< aux(25)
s(67) =< s(64)*aux(25)

with precondition: [V=1,V13=0,V3>=0,V14>=0,V19>=1]

* Chain [32]: 7
with precondition: [V=1,V19=0,V3>=0,V13>=1,V14>=0]

* Chain [31]: 24*s(70)+8*s(72)+8*s(73)+7
Such that:aux(26) =< -V3+V19
aux(27) =< V19
s(70) =< aux(26)
s(72) =< aux(27)
s(73) =< s(70)*aux(27)

with precondition: [V=1,V3>=0,V13>=1,V14>=0,V19>=1]

* Chain [30]: 6*s(81)+2*s(83)+2*s(84)+4
Such that:s(81) =< -V+V14
s(82) =< V14
s(83) =< s(82)
s(84) =< s(81)*s(82)

with precondition: [V3=0,V>=0]

* Chain [29]: 4
with precondition: [V14=0,V>=0,V3>=0,V13>=0]


Closed-form bounds of start(V,V3,V13,V14,V19):
-------------------------------------
* Chain [35] with precondition: [V=0]
- Upper bound: nat(V14)*48+10+nat(V14)*10*nat(V14)
- Complexity: n^2
* Chain [34] with precondition: [V>=1]
- Upper bound: 38*V+11+8*V*V+nat(V3)+nat(V14)*6+nat(V14)*6*nat(-V+V14)+nat(-V+V14)*18
- Complexity: n^2
* Chain [33] with precondition: [V=1,V13=0,V3>=0,V14>=0,V19>=1]
- Upper bound: 4*V19+7+2*V19*nat(-V3+V19)+nat(-V3+V19)*6
- Complexity: n^2
* Chain [32] with precondition: [V=1,V19=0,V3>=0,V13>=1,V14>=0]
- Upper bound: 7
- Complexity: constant
* Chain [31] with precondition: [V=1,V3>=0,V13>=1,V14>=0,V19>=1]
- Upper bound: 8*V19+7+8*V19*nat(-V3+V19)+nat(-V3+V19)*24
- Complexity: n^2
* Chain [30] with precondition: [V3=0,V>=0]
- Upper bound: nat(V14)*2+4+nat(V14)*2*nat(-V+V14)+nat(-V+V14)*6
- Complexity: n^2
* Chain [29] with precondition: [V14=0,V>=0,V3>=0,V13>=0]
- Upper bound: 4
- Complexity: constant

### Maximum cost of start(V,V3,V13,V14,V19): max([nat(V14)*2+max([nat(V14)*2*nat(-V+V14)+nat(-V+V14)*6,nat(V14)*4+6+max([nat(V14)*10*nat(V14)+nat(V14)*42,38*V+1+8*V*V+nat(V3)+nat(V14)*6*nat(-V+V14)+nat(-V+V14)*18])]),nat(V19)*6*nat(-V3+V19)+nat(V19)*4+nat(-V3+V19)*18+ (nat(V19)*2*nat(-V3+V19)+nat(V19)*4+nat(-V3+V19)*6)+3])+4
Asymptotic class: n^2
* Total analysis performed in 567 ms.

(10) BOUNDS(1, n^2)