(0) Obligation:

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


The TRS R consists of the following rules:

half(0) → 0
half(s(0)) → 0
half(s(s(x))) → s(half(x))
lastbit(0) → 0
lastbit(s(0)) → s(0)
lastbit(s(s(x))) → lastbit(x)
zero(0) → true
zero(s(x)) → false
conv(x) → conviter(x, cons(0, nil))
conviter(x, l) → if(zero(x), x, l)
if(true, x, l) → l
if(false, x, l) → conviter(half(x), cons(lastbit(x), l))

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^1).


The TRS R consists of the following rules:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
lastbit(0) → 0 [1]
lastbit(s(0)) → s(0) [1]
lastbit(s(s(x))) → lastbit(x) [1]
zero(0) → true [1]
zero(s(x)) → false [1]
conv(x) → conviter(x, cons(0, nil)) [1]
conviter(x, l) → if(zero(x), x, l) [1]
if(true, x, l) → l [1]
if(false, x, l) → conviter(half(x), cons(lastbit(x), l)) [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:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
lastbit(0) → 0 [1]
lastbit(s(0)) → s(0) [1]
lastbit(s(s(x))) → lastbit(x) [1]
zero(0) → true [1]
zero(s(x)) → false [1]
conv(x) → conviter(x, cons(0, nil)) [1]
conviter(x, l) → if(zero(x), x, l) [1]
if(true, x, l) → l [1]
if(false, x, l) → conviter(half(x), cons(lastbit(x), l)) [1]

The TRS has the following type information:
half :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
lastbit :: 0:s → 0:s
zero :: 0:s → true:false
true :: true:false
false :: true:false
conv :: 0:s → nil:cons
conviter :: 0:s → nil:cons → nil:cons
cons :: 0:s → nil:cons → nil:cons
nil :: nil:cons
if :: true:false → 0:s → 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:

half(0) → 0 [1]
half(s(0)) → 0 [1]
half(s(s(x))) → s(half(x)) [1]
lastbit(0) → 0 [1]
lastbit(s(0)) → s(0) [1]
lastbit(s(s(x))) → lastbit(x) [1]
zero(0) → true [1]
zero(s(x)) → false [1]
conv(x) → conviter(x, cons(0, nil)) [1]
conviter(x, l) → if(zero(x), x, l) [1]
if(true, x, l) → l [1]
if(false, x, l) → conviter(half(x), cons(lastbit(x), l)) [1]

The TRS has the following type information:
half :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
lastbit :: 0:s → 0:s
zero :: 0:s → true:false
true :: true:false
false :: true:false
conv :: 0:s → nil:cons
conviter :: 0:s → nil:cons → nil:cons
cons :: 0:s → nil:cons → nil:cons
nil :: nil:cons
if :: true:false → 0:s → 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:

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

(8) Obligation:

Complexity RNTS consisting of the following rules:

conv(z) -{ 1 }→ conviter(x, 1 + 0 + 0) :|: x >= 0, z = x
conviter(z, z') -{ 1 }→ if(zero(x), x, l) :|: z' = l, x >= 0, l >= 0, z = x
half(z) -{ 1 }→ 0 :|: z = 0
half(z) -{ 1 }→ 0 :|: z = 1 + 0
half(z) -{ 1 }→ 1 + half(x) :|: x >= 0, z = 1 + (1 + x)
if(z, z', z'') -{ 1 }→ l :|: z' = x, z = 1, x >= 0, l >= 0, z'' = l
if(z, z', z'') -{ 1 }→ conviter(half(x), 1 + lastbit(x) + l) :|: z' = x, x >= 0, l >= 0, z = 0, z'' = l
lastbit(z) -{ 1 }→ lastbit(x) :|: x >= 0, z = 1 + (1 + x)
lastbit(z) -{ 1 }→ 0 :|: z = 0
lastbit(z) -{ 1 }→ 1 + 0 :|: z = 1 + 0
zero(z) -{ 1 }→ 1 :|: z = 0
zero(z) -{ 1 }→ 0 :|: x >= 0, z = 1 + x

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, V5, V8),0,[half(V, Out)],[V >= 0]).
eq(start(V, V5, V8),0,[lastbit(V, Out)],[V >= 0]).
eq(start(V, V5, V8),0,[zero(V, Out)],[V >= 0]).
eq(start(V, V5, V8),0,[conv(V, Out)],[V >= 0]).
eq(start(V, V5, V8),0,[conviter(V, V5, Out)],[V >= 0,V5 >= 0]).
eq(start(V, V5, V8),0,[if(V, V5, V8, Out)],[V >= 0,V5 >= 0,V8 >= 0]).
eq(half(V, Out),1,[],[Out = 0,V = 0]).
eq(half(V, Out),1,[],[Out = 0,V = 1]).
eq(half(V, Out),1,[half(V1, Ret1)],[Out = 1 + Ret1,V1 >= 0,V = 2 + V1]).
eq(lastbit(V, Out),1,[],[Out = 0,V = 0]).
eq(lastbit(V, Out),1,[],[Out = 1,V = 1]).
eq(lastbit(V, Out),1,[lastbit(V2, Ret)],[Out = Ret,V2 >= 0,V = 2 + V2]).
eq(zero(V, Out),1,[],[Out = 1,V = 0]).
eq(zero(V, Out),1,[],[Out = 0,V3 >= 0,V = 1 + V3]).
eq(conv(V, Out),1,[conviter(V4, 1 + 0 + 0, Ret2)],[Out = Ret2,V4 >= 0,V = V4]).
eq(conviter(V, V5, Out),1,[zero(V6, Ret0),if(Ret0, V6, V7, Ret3)],[Out = Ret3,V5 = V7,V6 >= 0,V7 >= 0,V = V6]).
eq(if(V, V5, V8, Out),1,[],[Out = V9,V5 = V10,V = 1,V10 >= 0,V9 >= 0,V8 = V9]).
eq(if(V, V5, V8, Out),1,[half(V11, Ret01),lastbit(V11, Ret101),conviter(Ret01, 1 + Ret101 + V12, Ret4)],[Out = Ret4,V5 = V11,V11 >= 0,V12 >= 0,V = 0,V8 = V12]).
input_output_vars(half(V,Out),[V],[Out]).
input_output_vars(lastbit(V,Out),[V],[Out]).
input_output_vars(zero(V,Out),[V],[Out]).
input_output_vars(conv(V,Out),[V],[Out]).
input_output_vars(conviter(V,V5,Out),[V,V5],[Out]).
input_output_vars(if(V,V5,V8,Out),[V,V5,V8],[Out]).

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

#### Computed strongly connected components
0. recursive : [half/2]
1. recursive : [lastbit/2]
2. non_recursive : [zero/2]
3. recursive : [conviter/3,if/4]
4. non_recursive : [conv/2]
5. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into half/2
1. SCC is partially evaluated into lastbit/2
2. SCC is partially evaluated into zero/2
3. SCC is partially evaluated into conviter/3
4. SCC is completely evaluated into other SCCs
5. SCC is partially evaluated into start/3

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

### Specialization of cost equations half/2
* CE 11 is refined into CE [19]
* CE 10 is refined into CE [20]
* CE 9 is refined into CE [21]


### Cost equations --> "Loop" of half/2
* CEs [20] --> Loop 13
* CEs [21] --> Loop 14
* CEs [19] --> Loop 15

### Ranking functions of CR half(V,Out)
* RF of phase [15]: [V-1]

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


### Specialization of cost equations lastbit/2
* CE 14 is refined into CE [22]
* CE 13 is refined into CE [23]
* CE 12 is refined into CE [24]


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

### Ranking functions of CR lastbit(V,Out)
* RF of phase [18]: [V-1]

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


### Specialization of cost equations zero/2
* CE 18 is refined into CE [25]
* CE 17 is refined into CE [26]


### Cost equations --> "Loop" of zero/2
* CEs [25] --> Loop 19
* CEs [26] --> Loop 20

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

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


### Specialization of cost equations conviter/3
* CE 16 is refined into CE [27]
* CE 15 is refined into CE [28,29,30,31,32]


### Cost equations --> "Loop" of conviter/3
* CEs [31] --> Loop 21
* CEs [32] --> Loop 22
* CEs [29] --> Loop 23
* CEs [30] --> Loop 24
* CEs [28] --> Loop 25
* CEs [27] --> Loop 26

### Ranking functions of CR conviter(V,V5,Out)
* RF of phase [21,22,23,24]: [V-1,2*V+V5-3]

#### Partial ranking functions of CR conviter(V,V5,Out)
* Partial RF of phase [21,22,23,24]:
- RF of loop [21:1,22:1]:
V/2-1
- RF of loop [23:1]:
V-1
- RF of loop [24:1]:
2/3*V-5/3


### Specialization of cost equations start/3
* CE 3 is refined into CE [33]
* CE 2 is refined into CE [34,35,36,37,38,39,40,41,42]
* CE 4 is refined into CE [43,44,45,46]
* CE 5 is refined into CE [47,48,49,50]
* CE 6 is refined into CE [51,52]
* CE 7 is refined into CE [53,54,55]
* CE 8 is refined into CE [56,57,58]


### Cost equations --> "Loop" of start/3
* CEs [33,44,45,46,48,49,50,52,54,55,57,58] --> Loop 27
* CEs [34,35,36,37,38,39,40,41,42,43,47,51,53,56] --> Loop 28

### Ranking functions of CR start(V,V5,V8)

#### Partial ranking functions of CR start(V,V5,V8)


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

#### Cost of chains of half(V,Out):
* Chain [[15],14]: 1*it(15)+1
Such that:it(15) =< 2*Out

with precondition: [V=2*Out,V>=2]

* Chain [[15],13]: 1*it(15)+1
Such that:it(15) =< 2*Out

with precondition: [V=2*Out+1,V>=3]

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

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


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

with precondition: [Out=0,V>=2]

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

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

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

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


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

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


#### Cost of chains of conviter(V,V5,Out):
* Chain [[21,22,23,24],25,26]: 5*it(21)+5*it(22)+5*it(23)+5*it(24)+2*s(17)+2*s(18)+4*s(21)+8
Such that:aux(6) =< 2*V+V5
aux(7) =< 2*V+V5-Out
aux(10) =< 3*V
aux(9) =< 3*V+6
aux(12) =< 4*V
aux(11) =< 4*V+8
it(24) =< 2/3*V
aux(15) =< V
aux(16) =< 2*V
aux(17) =< V/2
it(21) =< aux(15)
it(22) =< aux(15)
it(23) =< aux(15)
it(24) =< aux(15)
it(24) =< aux(16)
it(21) =< aux(6)
it(22) =< aux(6)
it(23) =< aux(6)
it(24) =< aux(6)
it(21) =< aux(7)
it(22) =< aux(7)
it(23) =< aux(7)
it(24) =< aux(7)
it(22) =< aux(9)
it(23) =< aux(9)
it(24) =< aux(9)
s(18) =< aux(9)
it(22) =< aux(10)
it(23) =< aux(10)
it(24) =< aux(10)
s(18) =< aux(10)
it(22) =< aux(11)
it(23) =< aux(11)
it(24) =< aux(11)
s(17) =< aux(11)
it(22) =< aux(12)
it(23) =< aux(12)
it(24) =< aux(12)
s(17) =< aux(12)
it(21) =< aux(17)
it(22) =< aux(17)
s(21) =< aux(16)

with precondition: [V5>=0,Out>=V5+3,V+2*V5+6>=2*Out,V+V5+1>=Out]

* Chain [26]: 3
with precondition: [V=0,V5=Out,V5>=0]

* Chain [25,26]: 8
with precondition: [V=1,Out=V5+2,Out>=2]


#### Cost of chains of start(V,V5,V8):
* Chain [28]: 4*s(25)+24*s(27)+5*s(35)+10*s(39)+5*s(40)+5*s(41)+4*s(42)+4*s(43)+5*s(53)+5*s(57)+5*s(58)+5*s(59)+2*s(64)+5*s(73)+5*s(77)+5*s(78)+5*s(79)+4*s(80)+4*s(81)+5*s(93)+5*s(98)+5*s(99)+11
Such that:s(67) =< V5+V8
s(47) =< V5+V8+2
aux(23) =< 2
aux(24) =< 3
aux(25) =< V5
aux(26) =< V5+V8+1
aux(27) =< 2*V5
aux(28) =< 2*V5+6
aux(29) =< 2*V5+8
aux(30) =< V5/2
aux(31) =< V5/3
aux(32) =< V5/4
aux(33) =< 3/2*V5
aux(34) =< 3/2*V5+6
aux(35) =< 3/2*V5+9/2
s(25) =< aux(23)
s(64) =< aux(24)
s(35) =< aux(31)
s(53) =< aux(31)
s(73) =< aux(31)
s(93) =< aux(31)
s(27) =< aux(25)
s(77) =< aux(30)
s(78) =< aux(30)
s(79) =< aux(30)
s(73) =< aux(30)
s(73) =< aux(25)
s(77) =< s(67)
s(78) =< s(67)
s(79) =< s(67)
s(73) =< s(67)
s(77) =< aux(25)
s(78) =< aux(25)
s(79) =< aux(25)
s(78) =< aux(35)
s(79) =< aux(35)
s(73) =< aux(35)
s(80) =< aux(35)
s(78) =< aux(33)
s(79) =< aux(33)
s(73) =< aux(33)
s(80) =< aux(33)
s(78) =< aux(28)
s(79) =< aux(28)
s(73) =< aux(28)
s(81) =< aux(28)
s(78) =< aux(27)
s(79) =< aux(27)
s(73) =< aux(27)
s(81) =< aux(27)
s(77) =< aux(32)
s(78) =< aux(32)
s(39) =< aux(30)
s(40) =< aux(30)
s(41) =< aux(30)
s(35) =< aux(30)
s(35) =< aux(25)
s(39) =< aux(26)
s(40) =< aux(26)
s(41) =< aux(26)
s(35) =< aux(26)
s(39) =< aux(25)
s(40) =< aux(25)
s(41) =< aux(25)
s(40) =< aux(34)
s(41) =< aux(34)
s(35) =< aux(34)
s(42) =< aux(34)
s(40) =< aux(33)
s(41) =< aux(33)
s(35) =< aux(33)
s(42) =< aux(33)
s(40) =< aux(29)
s(41) =< aux(29)
s(35) =< aux(29)
s(43) =< aux(29)
s(40) =< aux(27)
s(41) =< aux(27)
s(35) =< aux(27)
s(43) =< aux(27)
s(39) =< aux(32)
s(40) =< aux(32)
s(98) =< aux(30)
s(99) =< aux(30)
s(93) =< aux(30)
s(93) =< aux(25)
s(98) =< aux(26)
s(99) =< aux(26)
s(93) =< aux(26)
s(98) =< aux(25)
s(99) =< aux(25)
s(98) =< aux(35)
s(99) =< aux(35)
s(93) =< aux(35)
s(98) =< aux(33)
s(99) =< aux(33)
s(93) =< aux(33)
s(98) =< aux(28)
s(99) =< aux(28)
s(93) =< aux(28)
s(98) =< aux(27)
s(99) =< aux(27)
s(93) =< aux(27)
s(98) =< aux(32)
s(57) =< aux(30)
s(58) =< aux(30)
s(59) =< aux(30)
s(53) =< aux(30)
s(53) =< aux(25)
s(57) =< s(47)
s(58) =< s(47)
s(59) =< s(47)
s(53) =< s(47)
s(57) =< aux(25)
s(58) =< aux(25)
s(59) =< aux(25)
s(58) =< aux(34)
s(59) =< aux(34)
s(53) =< aux(34)
s(58) =< aux(33)
s(59) =< aux(33)
s(53) =< aux(33)
s(58) =< aux(29)
s(59) =< aux(29)
s(53) =< aux(29)
s(58) =< aux(27)
s(59) =< aux(27)
s(53) =< aux(27)
s(57) =< aux(32)
s(58) =< aux(32)

with precondition: [V=0]

* Chain [27]: 4*s(103)+5*s(113)+5*s(117)+5*s(118)+5*s(119)+4*s(120)+4*s(121)+8*s(122)+5*s(129)+5*s(133)+5*s(134)+5*s(135)+9
Such that:s(107) =< 2*V+1
s(123) =< 2*V+V5
aux(38) =< V
aux(39) =< 2*V
aux(40) =< 3*V
aux(41) =< 3*V+6
aux(42) =< 4*V
aux(43) =< 4*V+8
aux(44) =< V/2
aux(45) =< 2/3*V
s(103) =< aux(38)
s(113) =< aux(45)
s(129) =< aux(45)
s(117) =< aux(38)
s(118) =< aux(38)
s(119) =< aux(38)
s(113) =< aux(38)
s(113) =< aux(39)
s(117) =< s(107)
s(118) =< s(107)
s(119) =< s(107)
s(113) =< s(107)
s(117) =< aux(39)
s(118) =< aux(39)
s(119) =< aux(39)
s(118) =< aux(41)
s(119) =< aux(41)
s(113) =< aux(41)
s(120) =< aux(41)
s(118) =< aux(40)
s(119) =< aux(40)
s(113) =< aux(40)
s(120) =< aux(40)
s(118) =< aux(43)
s(119) =< aux(43)
s(113) =< aux(43)
s(121) =< aux(43)
s(118) =< aux(42)
s(119) =< aux(42)
s(113) =< aux(42)
s(121) =< aux(42)
s(117) =< aux(44)
s(118) =< aux(44)
s(122) =< aux(39)
s(133) =< aux(38)
s(134) =< aux(38)
s(135) =< aux(38)
s(129) =< aux(38)
s(129) =< aux(39)
s(133) =< s(123)
s(134) =< s(123)
s(135) =< s(123)
s(129) =< s(123)
s(133) =< aux(39)
s(134) =< aux(39)
s(135) =< aux(39)
s(134) =< aux(41)
s(135) =< aux(41)
s(129) =< aux(41)
s(134) =< aux(40)
s(135) =< aux(40)
s(129) =< aux(40)
s(134) =< aux(43)
s(135) =< aux(43)
s(129) =< aux(43)
s(134) =< aux(42)
s(135) =< aux(42)
s(129) =< aux(42)
s(133) =< aux(44)
s(134) =< aux(44)

with precondition: [V>=1]


Closed-form bounds of start(V,V5,V8):
-------------------------------------
* Chain [28] with precondition: [V=0]
- Upper bound: nat(V5)*24+25+nat(2*V5+6)*4+nat(2*V5+8)*4+nat(3/2*V5+6)*4+nat(3/2*V5+9/2)*4+nat(V5/2)*60+nat(V5/3)*20
- Complexity: n
* Chain [27] with precondition: [V>=1]
- Upper bound: 254/3*V+65
- Complexity: n

### Maximum cost of start(V,V5,V8): max([254/3*V+56,nat(V5)*24+16+nat(2*V5+6)*4+nat(2*V5+8)*4+nat(3/2*V5+6)*4+nat(3/2*V5+9/2)*4+nat(V5/2)*60+nat(V5/3)*20])+9
Asymptotic class: n
* Total analysis performed in 566 ms.

(10) BOUNDS(1, n^1)