(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:

first(0, X) → nil
first(s(X), cons(Y, Z)) → cons(Y, n__first(X, activate(Z)))
from(X) → cons(X, n__from(n__s(X)))
first(X1, X2) → n__first(X1, X2)
from(X) → n__from(X)
s(X) → n__s(X)
activate(n__first(X1, X2)) → first(activate(X1), activate(X2))
activate(n__from(X)) → from(activate(X))
activate(n__s(X)) → s(activate(X))
activate(X) → X

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:

first(0, X) → nil [1]
first(s(X), cons(Y, Z)) → cons(Y, n__first(X, activate(Z))) [1]
from(X) → cons(X, n__from(n__s(X))) [1]
first(X1, X2) → n__first(X1, X2) [1]
from(X) → n__from(X) [1]
s(X) → n__s(X) [1]
activate(n__first(X1, X2)) → first(activate(X1), activate(X2)) [1]
activate(n__from(X)) → from(activate(X)) [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(X) → X [1]

Rewrite Strategy: INNERMOST

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

Removed the following rules with non-basic left-hand side, as they cannot be used in innermost rewriting:

first(s(X), cons(Y, Z)) → cons(Y, n__first(X, activate(Z))) [1]

Due to the following rules that have to be used instead:

s(X) → n__s(X) [1]

(4) 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:

first(0, X) → nil [1]
from(X) → cons(X, n__from(n__s(X))) [1]
first(X1, X2) → n__first(X1, X2) [1]
from(X) → n__from(X) [1]
s(X) → n__s(X) [1]
activate(n__first(X1, X2)) → first(activate(X1), activate(X2)) [1]
activate(n__from(X)) → from(activate(X)) [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(X) → X [1]

Rewrite Strategy: INNERMOST

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

Infered types.

(6) Obligation:

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

first(0, X) → nil [1]
from(X) → cons(X, n__from(n__s(X))) [1]
first(X1, X2) → n__first(X1, X2) [1]
from(X) → n__from(X) [1]
s(X) → n__s(X) [1]
activate(n__first(X1, X2)) → first(activate(X1), activate(X2)) [1]
activate(n__from(X)) → from(activate(X)) [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(X) → X [1]

The TRS has the following type information:
first :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
0 :: 0:nil:n__s:n__from:cons:n__first
nil :: 0:nil:n__s:n__from:cons:n__first
from :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
cons :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
n__from :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
n__s :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
n__first :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
s :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
activate :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first

Rewrite Strategy: INNERMOST

(7) 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

(8) 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:

first(0, X) → nil [1]
from(X) → cons(X, n__from(n__s(X))) [1]
first(X1, X2) → n__first(X1, X2) [1]
from(X) → n__from(X) [1]
s(X) → n__s(X) [1]
activate(n__first(X1, X2)) → first(activate(X1), activate(X2)) [1]
activate(n__from(X)) → from(activate(X)) [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(X) → X [1]

The TRS has the following type information:
first :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
0 :: 0:nil:n__s:n__from:cons:n__first
nil :: 0:nil:n__s:n__from:cons:n__first
from :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
cons :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
n__from :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
n__s :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
n__first :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
s :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first
activate :: 0:nil:n__s:n__from:cons:n__first → 0:nil:n__s:n__from:cons:n__first

Rewrite Strategy: INNERMOST

(9) 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
nil => 1

(10) Obligation:

Complexity RNTS consisting of the following rules:

activate(z) -{ 1 }→ X :|: X >= 0, z = X
activate(z) -{ 1 }→ s(activate(X)) :|: z = 1 + X, X >= 0
activate(z) -{ 1 }→ from(activate(X)) :|: z = 1 + X, X >= 0
activate(z) -{ 1 }→ first(activate(X1), activate(X2)) :|: X1 >= 0, X2 >= 0, z = 1 + X1 + X2
first(z, z') -{ 1 }→ 1 :|: z' = X, X >= 0, z = 0
first(z, z') -{ 1 }→ 1 + X1 + X2 :|: X1 >= 0, X2 >= 0, z = X1, z' = X2
from(z) -{ 1 }→ 1 + X :|: X >= 0, z = X
from(z) -{ 1 }→ 1 + X + (1 + (1 + X)) :|: X >= 0, z = X
s(z) -{ 1 }→ 1 + X :|: X >= 0, z = X

Only complete derivations are relevant for the runtime complexity.

(11) CompleteCoflocoProof (EQUIVALENT transformation)

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

eq(start(V, V1),0,[first(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1),0,[from(V, Out)],[V >= 0]).
eq(start(V, V1),0,[s(V, Out)],[V >= 0]).
eq(start(V, V1),0,[activate(V, Out)],[V >= 0]).
eq(first(V, V1, Out),1,[],[Out = 1,V1 = X3,X3 >= 0,V = 0]).
eq(from(V, Out),1,[],[Out = 3 + 2*X4,X4 >= 0,V = X4]).
eq(first(V, V1, Out),1,[],[Out = 1 + X11 + X21,X11 >= 0,X21 >= 0,V = X11,V1 = X21]).
eq(from(V, Out),1,[],[Out = 1 + X5,X5 >= 0,V = X5]).
eq(s(V, Out),1,[],[Out = 1 + X6,X6 >= 0,V = X6]).
eq(activate(V, Out),1,[activate(X12, Ret0),activate(X22, Ret1),first(Ret0, Ret1, Ret)],[Out = Ret,X12 >= 0,X22 >= 0,V = 1 + X12 + X22]).
eq(activate(V, Out),1,[activate(X7, Ret01),from(Ret01, Ret2)],[Out = Ret2,V = 1 + X7,X7 >= 0]).
eq(activate(V, Out),1,[activate(X8, Ret02),s(Ret02, Ret3)],[Out = Ret3,V = 1 + X8,X8 >= 0]).
eq(activate(V, Out),1,[],[Out = X9,X9 >= 0,V = X9]).
input_output_vars(first(V,V1,Out),[V,V1],[Out]).
input_output_vars(from(V,Out),[V],[Out]).
input_output_vars(s(V,Out),[V],[Out]).
input_output_vars(activate(V,Out),[V],[Out]).

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

#### Computed strongly connected components
0. non_recursive : [first/3]
1. non_recursive : [from/2]
2. non_recursive : [s/2]
3. recursive [non_tail,multiple] : [activate/2]
4. non_recursive : [start/2]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into first/3
1. SCC is partially evaluated into from/2
2. SCC is completely evaluated into other SCCs
3. SCC is partially evaluated into activate/2
4. SCC is partially evaluated into start/2

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

### Specialization of cost equations first/3
* CE 7 is refined into CE [14]
* CE 6 is refined into CE [15]


### Cost equations --> "Loop" of first/3
* CEs [14] --> Loop 9
* CEs [15] --> Loop 10

### Ranking functions of CR first(V,V1,Out)

#### Partial ranking functions of CR first(V,V1,Out)


### Specialization of cost equations from/2
* CE 8 is refined into CE [16]
* CE 9 is refined into CE [17]


### Cost equations --> "Loop" of from/2
* CEs [16] --> Loop 11
* CEs [17] --> Loop 12

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

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


### Specialization of cost equations activate/2
* CE 13 is refined into CE [18]
* CE 11 is refined into CE [19,20]
* CE 12 is refined into CE [21]
* CE 10 is refined into CE [22,23]


### Cost equations --> "Loop" of activate/2
* CEs [23] --> Loop 13
* CEs [22] --> Loop 14
* CEs [19,21] --> Loop 15
* CEs [20] --> Loop 16
* CEs [18] --> Loop 17

### Ranking functions of CR activate(V,Out)
* RF of phase [13,14,15,16]: [V]

#### Partial ranking functions of CR activate(V,Out)
* Partial RF of phase [13,14,15,16]:
- RF of loop [13:1,13:2,14:1,14:2,15:1,16:1]:
V


### Specialization of cost equations start/2
* CE 2 is refined into CE [24,25]
* CE 3 is refined into CE [26,27]
* CE 4 is refined into CE [28]
* CE 5 is refined into CE [29,30]


### Cost equations --> "Loop" of start/2
* CEs [24,25,26,27,28,29,30] --> Loop 18

### Ranking functions of CR start(V,V1)

#### Partial ranking functions of CR start(V,V1)


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

#### Cost of chains of first(V,V1,Out):
* Chain [10]: 1
with precondition: [V=0,Out=1,V1>=0]

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


#### Cost of chains of from(V,Out):
* Chain [12]: 1
with precondition: [V+1=Out,V>=0]

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


#### Cost of chains of activate(V,Out):
* Chain [17]: 1
with precondition: [V=Out,V>=0]

* Chain [multiple([13,14,15,16],[[17]])]: 8*it(13)+1*it([17])+0
Such that:it([17]) =< V+1
aux(1) =< V
it(13) =< aux(1)

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


#### Cost of chains of start(V,V1):
* Chain [18]: 1*s(1)+8*s(3)+1
Such that:s(2) =< V
s(1) =< V+1
s(3) =< s(2)

with precondition: [V>=0]


Closed-form bounds of start(V,V1):
-------------------------------------
* Chain [18] with precondition: [V>=0]
- Upper bound: 9*V+2
- Complexity: n

### Maximum cost of start(V,V1): 9*V+2
Asymptotic class: n
* Total analysis performed in 143 ms.

(12) BOUNDS(1, n^1)