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

-(x, 0) → x
-(0, s(y)) → 0
-(s(x), s(y)) → -(x, y)
lt(x, 0) → false
lt(0, s(y)) → true
lt(s(x), s(y)) → lt(x, y)
if(true, x, y) → x
if(false, x, y) → y
div(x, 0) → 0
div(0, y) → 0
div(s(x), s(y)) → if(lt(x, y), 0, s(div(-(x, y), s(y))))

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:

-(x, 0) → x [1]
-(0, s(y)) → 0 [1]
-(s(x), s(y)) → -(x, y) [1]
lt(x, 0) → false [1]
lt(0, s(y)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]
if(true, x, y) → x [1]
if(false, x, y) → y [1]
div(x, 0) → 0 [1]
div(0, y) → 0 [1]
div(s(x), s(y)) → if(lt(x, y), 0, s(div(-(x, y), s(y)))) [1]

Rewrite Strategy: INNERMOST

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

Renamed defined symbols to avoid conflicts with arithmetic symbols:

- => minus

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

minus(x, 0) → x [1]
minus(0, s(y)) → 0 [1]
minus(s(x), s(y)) → minus(x, y) [1]
lt(x, 0) → false [1]
lt(0, s(y)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]
if(true, x, y) → x [1]
if(false, x, y) → y [1]
div(x, 0) → 0 [1]
div(0, y) → 0 [1]
div(s(x), s(y)) → if(lt(x, y), 0, s(div(minus(x, y), s(y)))) [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:

minus(x, 0) → x [1]
minus(0, s(y)) → 0 [1]
minus(s(x), s(y)) → minus(x, y) [1]
lt(x, 0) → false [1]
lt(0, s(y)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]
if(true, x, y) → x [1]
if(false, x, y) → y [1]
div(x, 0) → 0 [1]
div(0, y) → 0 [1]
div(s(x), s(y)) → if(lt(x, y), 0, s(div(minus(x, y), s(y)))) [1]

The TRS has the following type information:
minus :: 0:s → 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
lt :: 0:s → 0:s → false:true
false :: false:true
true :: false:true
if :: false:true → 0:s → 0:s → 0:s
div :: 0:s → 0:s → 0:s

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:

minus(x, 0) → x [1]
minus(0, s(y)) → 0 [1]
minus(s(x), s(y)) → minus(x, y) [1]
lt(x, 0) → false [1]
lt(0, s(y)) → true [1]
lt(s(x), s(y)) → lt(x, y) [1]
if(true, x, y) → x [1]
if(false, x, y) → y [1]
div(x, 0) → 0 [1]
div(0, y) → 0 [1]
div(s(x), s(y)) → if(lt(x, y), 0, s(div(minus(x, y), s(y)))) [1]

The TRS has the following type information:
minus :: 0:s → 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
lt :: 0:s → 0:s → false:true
false :: false:true
true :: false:true
if :: false:true → 0:s → 0:s → 0:s
div :: 0:s → 0:s → 0:s

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
false => 0
true => 1

(10) Obligation:

Complexity RNTS consisting of the following rules:

div(z, z') -{ 1 }→ if(lt(x, y), 0, 1 + div(minus(x, y), 1 + y)) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
div(z, z') -{ 1 }→ 0 :|: x >= 0, z = x, z' = 0
div(z, z') -{ 1 }→ 0 :|: y >= 0, z = 0, z' = y
if(z, z', z'') -{ 1 }→ x :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
if(z, z', z'') -{ 1 }→ y :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
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
minus(z, z') -{ 1 }→ x :|: x >= 0, z = x, z' = 0
minus(z, z') -{ 1 }→ minus(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
minus(z, z') -{ 1 }→ 0 :|: z' = 1 + y, y >= 0, z = 0

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, V10),0,[minus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V10),0,[lt(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V10),0,[if(V, V1, V10, Out)],[V >= 0,V1 >= 0,V10 >= 0]).
eq(start(V, V1, V10),0,[div(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(minus(V, V1, Out),1,[],[Out = V2,V2 >= 0,V = V2,V1 = 0]).
eq(minus(V, V1, Out),1,[],[Out = 0,V1 = 1 + V3,V3 >= 0,V = 0]).
eq(minus(V, V1, Out),1,[minus(V4, V5, Ret)],[Out = Ret,V1 = 1 + V5,V4 >= 0,V5 >= 0,V = 1 + V4]).
eq(lt(V, V1, Out),1,[],[Out = 0,V6 >= 0,V = V6,V1 = 0]).
eq(lt(V, V1, Out),1,[],[Out = 1,V1 = 1 + V7,V7 >= 0,V = 0]).
eq(lt(V, V1, Out),1,[lt(V8, V9, Ret1)],[Out = Ret1,V1 = 1 + V9,V8 >= 0,V9 >= 0,V = 1 + V8]).
eq(if(V, V1, V10, Out),1,[],[Out = V11,V1 = V11,V10 = V12,V = 1,V11 >= 0,V12 >= 0]).
eq(if(V, V1, V10, Out),1,[],[Out = V13,V1 = V14,V10 = V13,V14 >= 0,V13 >= 0,V = 0]).
eq(div(V, V1, Out),1,[],[Out = 0,V15 >= 0,V = V15,V1 = 0]).
eq(div(V, V1, Out),1,[],[Out = 0,V16 >= 0,V = 0,V1 = V16]).
eq(div(V, V1, Out),1,[lt(V17, V18, Ret0),minus(V17, V18, Ret210),div(Ret210, 1 + V18, Ret21),if(Ret0, 0, 1 + Ret21, Ret2)],[Out = Ret2,V1 = 1 + V18,V17 >= 0,V18 >= 0,V = 1 + V17]).
input_output_vars(minus(V,V1,Out),[V,V1],[Out]).
input_output_vars(lt(V,V1,Out),[V,V1],[Out]).
input_output_vars(if(V,V1,V10,Out),[V,V1,V10],[Out]).
input_output_vars(div(V,V1,Out),[V,V1],[Out]).

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

#### Computed strongly connected components
0. non_recursive : [if/4]
1. recursive : [lt/3]
2. recursive : [minus/3]
3. recursive [non_tail] : [ (div)/3]
4. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into if/4
1. SCC is partially evaluated into lt/3
2. SCC is partially evaluated into minus/3
3. SCC is partially evaluated into (div)/3
4. SCC is partially evaluated into start/3

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

### Specialization of cost equations if/4
* CE 12 is refined into CE [17]
* CE 13 is refined into CE [18]


### Cost equations --> "Loop" of if/4
* CEs [17] --> Loop 13
* CEs [18] --> Loop 14

### Ranking functions of CR if(V,V1,V10,Out)

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


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


### Cost equations --> "Loop" of lt/3
* CEs [20] --> Loop 15
* CEs [21] --> Loop 16
* CEs [19] --> Loop 17

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

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


### Specialization of cost equations minus/3
* CE 8 is refined into CE [22]
* CE 6 is refined into CE [23]
* CE 7 is refined into CE [24]


### Cost equations --> "Loop" of minus/3
* CEs [23] --> Loop 18
* CEs [24] --> Loop 19
* CEs [22] --> Loop 20

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

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


### Specialization of cost equations (div)/3
* CE 16 is refined into CE [25,26,27,28]
* CE 14 is refined into CE [29]
* CE 15 is refined into CE [30]


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

### Ranking functions of CR div(V,V1,Out)
* RF of phase [23]: [V-1,V-V1+1]
* RF of phase [25]: [V]

#### Partial ranking functions of CR div(V,V1,Out)
* Partial RF of phase [23]:
- RF of loop [23:1]:
V-1
V-V1+1
* Partial RF of phase [25]:
- RF of loop [25:1]:
V


### Specialization of cost equations start/3
* CE 2 is refined into CE [31,32,33,34]
* CE 3 is refined into CE [35,36,37,38]
* CE 4 is refined into CE [39,40]
* CE 5 is refined into CE [41,42,43,44,45,46]


### Cost equations --> "Loop" of start/3
* CEs [34,37,44,46] --> Loop 27
* CEs [32,36,43] --> Loop 28
* CEs [33,38,42,45] --> Loop 29
* CEs [40] --> Loop 30
* CEs [31,35,39,41] --> Loop 31

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

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


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

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

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


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

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

* Chain [[17],15]: 1*it(17)+1
Such that:it(17) =< V1

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

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

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


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

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

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

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

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

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


#### Cost of chains of div(V,V1,Out):
* Chain [[25],22]: 4*it(25)+1
Such that:it(25) =< Out

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

* Chain [[23],26,22]: 4*it(23)+2*s(5)+5
Such that:it(23) =< V-V1+1
aux(4) =< V
it(23) =< aux(4)
s(5) =< aux(4)

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

* Chain [[23],24,22]: 4*it(23)+4*s(5)+5
Such that:it(23) =< V-V1+1
aux(6) =< V
s(5) =< aux(6)
it(23) =< aux(6)

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

* Chain [[23],22]: 4*it(23)+2*s(5)+1
Such that:it(23) =< V-V1+1
aux(7) =< V
it(23) =< aux(7)
s(5) =< aux(7)

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

* Chain [26,22]: 5
with precondition: [V=1,Out=0,V1>=2]

* Chain [24,22]: 2*s(7)+5
Such that:aux(5) =< V
s(7) =< aux(5)

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

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

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


#### Cost of chains of start(V,V1,V10):
* Chain [31]: 1
with precondition: [V=0,V1>=0]

* Chain [30]: 1
with precondition: [V=1,V1>=0,V10>=0]

* Chain [29]: 4*s(18)+5
Such that:aux(10) =< V
s(18) =< aux(10)

with precondition: [V>=1,V1>=V+1]

* Chain [28]: 1
with precondition: [V1=0,V>=0]

* Chain [27]: 2*s(22)+12*s(24)+12*s(27)+5
Such that:s(26) =< V-V1+1
aux(11) =< V
aux(12) =< V1
s(24) =< aux(11)
s(22) =< aux(12)
s(27) =< s(26)
s(27) =< aux(11)

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


Closed-form bounds of start(V,V1,V10):
-------------------------------------
* Chain [31] with precondition: [V=0,V1>=0]
- Upper bound: 1
- Complexity: constant
* Chain [30] with precondition: [V=1,V1>=0,V10>=0]
- Upper bound: 1
- Complexity: constant
* Chain [29] with precondition: [V>=1,V1>=V+1]
- Upper bound: 4*V+5
- Complexity: n
* Chain [28] with precondition: [V1=0,V>=0]
- Upper bound: 1
- Complexity: constant
* Chain [27] with precondition: [V1>=1,V>=V1]
- Upper bound: 24*V-10*V1+17
- Complexity: n

### Maximum cost of start(V,V1,V10): 8*V+2*V1+nat(V-V1+1)*12+ (4*V+4)+1
Asymptotic class: n
* Total analysis performed in 325 ms.

(12) BOUNDS(1, n^1)