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

le(0, y) → true
le(s(x), 0) → false
le(s(x), s(y)) → le(x, y)
minus(x, x) → 0
minus(x, 0) → x
minus(0, x) → 0
minus(s(x), s(y)) → minus(x, y)
isZero(0) → true
isZero(s(x)) → false
mod(x, y) → if_mod(isZero(y), le(y, x), x, y, minus(x, y))
if_mod(true, b, x, y, z) → divByZeroError
if_mod(false, false, x, y, z) → x
if_mod(false, true, x, y, z) → mod(z, 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:

le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
minus(x, x) → 0 [1]
minus(x, 0) → x [1]
minus(0, x) → 0 [1]
minus(s(x), s(y)) → minus(x, y) [1]
isZero(0) → true [1]
isZero(s(x)) → false [1]
mod(x, y) → if_mod(isZero(y), le(y, x), x, y, minus(x, y)) [1]
if_mod(true, b, x, y, z) → divByZeroError [1]
if_mod(false, false, x, y, z) → x [1]
if_mod(false, true, x, y, z) → mod(z, y) [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:

le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
minus(x, x) → 0 [1]
minus(x, 0) → x [1]
minus(0, x) → 0 [1]
minus(s(x), s(y)) → minus(x, y) [1]
isZero(0) → true [1]
isZero(s(x)) → false [1]
mod(x, y) → if_mod(isZero(y), le(y, x), x, y, minus(x, y)) [1]
if_mod(true, b, x, y, z) → divByZeroError [1]
if_mod(false, false, x, y, z) → x [1]
if_mod(false, true, x, y, z) → mod(z, y) [1]

The TRS has the following type information:
le :: 0:s:divByZeroError → 0:s:divByZeroError → true:false
0 :: 0:s:divByZeroError
true :: true:false
s :: 0:s:divByZeroError → 0:s:divByZeroError
false :: true:false
minus :: 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError
isZero :: 0:s:divByZeroError → true:false
mod :: 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError
if_mod :: true:false → true:false → 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError
divByZeroError :: 0:s:divByZeroError

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:

le(v0, v1) → null_le [0]
minus(v0, v1) → null_minus [0]
isZero(v0) → null_isZero [0]
if_mod(v0, v1, v2, v3, v4) → null_if_mod [0]

And the following fresh constants:

null_le, null_minus, null_isZero, null_if_mod

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

le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
minus(x, x) → 0 [1]
minus(x, 0) → x [1]
minus(0, x) → 0 [1]
minus(s(x), s(y)) → minus(x, y) [1]
isZero(0) → true [1]
isZero(s(x)) → false [1]
mod(x, y) → if_mod(isZero(y), le(y, x), x, y, minus(x, y)) [1]
if_mod(true, b, x, y, z) → divByZeroError [1]
if_mod(false, false, x, y, z) → x [1]
if_mod(false, true, x, y, z) → mod(z, y) [1]
le(v0, v1) → null_le [0]
minus(v0, v1) → null_minus [0]
isZero(v0) → null_isZero [0]
if_mod(v0, v1, v2, v3, v4) → null_if_mod [0]

The TRS has the following type information:
le :: 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod → true:false:null_le:null_isZero
0 :: 0:s:divByZeroError:null_minus:null_if_mod
true :: true:false:null_le:null_isZero
s :: 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod
false :: true:false:null_le:null_isZero
minus :: 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod
isZero :: 0:s:divByZeroError:null_minus:null_if_mod → true:false:null_le:null_isZero
mod :: 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod
if_mod :: true:false:null_le:null_isZero → true:false:null_le:null_isZero → 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod → 0:s:divByZeroError:null_minus:null_if_mod
divByZeroError :: 0:s:divByZeroError:null_minus:null_if_mod
null_le :: true:false:null_le:null_isZero
null_minus :: 0:s:divByZeroError:null_minus:null_if_mod
null_isZero :: true:false:null_le:null_isZero
null_if_mod :: 0:s:divByZeroError:null_minus:null_if_mod

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 => 2
false => 1
divByZeroError => 1
null_le => 0
null_minus => 0
null_isZero => 0
null_if_mod => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

if_mod(z', z'', z1, z2, z3) -{ 1 }→ x :|: z2 = y, z >= 0, z3 = z, x >= 0, y >= 0, z' = 1, z'' = 1, z1 = x
if_mod(z', z'', z1, z2, z3) -{ 1 }→ mod(z, y) :|: z2 = y, z >= 0, z3 = z, x >= 0, y >= 0, z' = 1, z'' = 2, z1 = x
if_mod(z', z'', z1, z2, z3) -{ 1 }→ 1 :|: b >= 0, z2 = y, z >= 0, z'' = b, z' = 2, z3 = z, x >= 0, y >= 0, z1 = x
if_mod(z', z'', z1, z2, z3) -{ 0 }→ 0 :|: z2 = v3, v0 >= 0, v4 >= 0, z1 = v2, v1 >= 0, z'' = v1, z3 = v4, v2 >= 0, v3 >= 0, z' = v0
isZero(z') -{ 1 }→ 2 :|: z' = 0
isZero(z') -{ 1 }→ 1 :|: z' = 1 + x, x >= 0
isZero(z') -{ 0 }→ 0 :|: v0 >= 0, z' = v0
le(z', z'') -{ 1 }→ le(x, y) :|: z' = 1 + x, x >= 0, y >= 0, z'' = 1 + y
le(z', z'') -{ 1 }→ 2 :|: z'' = y, y >= 0, z' = 0
le(z', z'') -{ 1 }→ 1 :|: z'' = 0, z' = 1 + x, x >= 0
le(z', z'') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z'' = v1, z' = v0
minus(z', z'') -{ 1 }→ x :|: z'' = 0, z' = x, x >= 0
minus(z', z'') -{ 1 }→ minus(x, y) :|: z' = 1 + x, x >= 0, y >= 0, z'' = 1 + y
minus(z', z'') -{ 1 }→ 0 :|: z' = x, x >= 0, z'' = x
minus(z', z'') -{ 1 }→ 0 :|: x >= 0, z'' = x, z' = 0
minus(z', z'') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z'' = v1, z' = v0
mod(z', z'') -{ 1 }→ if_mod(isZero(y), le(y, x), x, y, minus(x, y)) :|: z' = x, z'' = y, x >= 0, y >= 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, V1, V14, V15, V16),0,[le(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V14, V15, V16),0,[minus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V14, V15, V16),0,[isZero(V, Out)],[V >= 0]).
eq(start(V, V1, V14, V15, V16),0,[mod(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V14, V15, V16),0,[fun(V, V1, V14, V15, V16, Out)],[V >= 0,V1 >= 0,V14 >= 0,V15 >= 0,V16 >= 0]).
eq(le(V, V1, Out),1,[],[Out = 2,V1 = V2,V2 >= 0,V = 0]).
eq(le(V, V1, Out),1,[],[Out = 1,V1 = 0,V = 1 + V3,V3 >= 0]).
eq(le(V, V1, Out),1,[le(V4, V5, Ret)],[Out = Ret,V = 1 + V4,V4 >= 0,V5 >= 0,V1 = 1 + V5]).
eq(minus(V, V1, Out),1,[],[Out = 0,V = V6,V6 >= 0,V1 = V6]).
eq(minus(V, V1, Out),1,[],[Out = V7,V1 = 0,V = V7,V7 >= 0]).
eq(minus(V, V1, Out),1,[],[Out = 0,V8 >= 0,V1 = V8,V = 0]).
eq(minus(V, V1, Out),1,[minus(V9, V10, Ret1)],[Out = Ret1,V = 1 + V9,V9 >= 0,V10 >= 0,V1 = 1 + V10]).
eq(isZero(V, Out),1,[],[Out = 2,V = 0]).
eq(isZero(V, Out),1,[],[Out = 1,V = 1 + V11,V11 >= 0]).
eq(mod(V, V1, Out),1,[isZero(V12, Ret0),le(V12, V13, Ret11),minus(V13, V12, Ret4),fun(Ret0, Ret11, V13, V12, Ret4, Ret2)],[Out = Ret2,V = V13,V1 = V12,V13 >= 0,V12 >= 0]).
eq(fun(V, V1, V14, V15, V16, Out),1,[],[Out = 1,V17 >= 0,V15 = V18,V19 >= 0,V1 = V17,V = 2,V16 = V19,V20 >= 0,V18 >= 0,V14 = V20]).
eq(fun(V, V1, V14, V15, V16, Out),1,[],[Out = V21,V15 = V22,V23 >= 0,V16 = V23,V21 >= 0,V22 >= 0,V = 1,V1 = 1,V14 = V21]).
eq(fun(V, V1, V14, V15, V16, Out),1,[mod(V24, V25, Ret3)],[Out = Ret3,V15 = V25,V24 >= 0,V16 = V24,V26 >= 0,V25 >= 0,V = 1,V1 = 2,V14 = V26]).
eq(le(V, V1, Out),0,[],[Out = 0,V27 >= 0,V28 >= 0,V1 = V28,V = V27]).
eq(minus(V, V1, Out),0,[],[Out = 0,V29 >= 0,V30 >= 0,V1 = V30,V = V29]).
eq(isZero(V, Out),0,[],[Out = 0,V31 >= 0,V = V31]).
eq(fun(V, V1, V14, V15, V16, Out),0,[],[Out = 0,V15 = V32,V33 >= 0,V34 >= 0,V14 = V35,V36 >= 0,V1 = V36,V16 = V34,V35 >= 0,V32 >= 0,V = V33]).
input_output_vars(le(V,V1,Out),[V,V1],[Out]).
input_output_vars(minus(V,V1,Out),[V,V1],[Out]).
input_output_vars(isZero(V,Out),[V],[Out]).
input_output_vars(mod(V,V1,Out),[V,V1],[Out]).
input_output_vars(fun(V,V1,V14,V15,V16,Out),[V,V1,V14,V15,V16],[Out]).

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

#### Computed strongly connected components
0. non_recursive : [isZero/2]
1. recursive : [le/3]
2. recursive : [minus/3]
3. recursive : [fun/6, (mod)/3]
4. non_recursive : [start/5]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into isZero/2
1. SCC is partially evaluated into le/3
2. SCC is partially evaluated into minus/3
3. SCC is partially evaluated into (mod)/3
4. SCC is partially evaluated into start/5

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

### Specialization of cost equations isZero/2
* CE 24 is refined into CE [26]
* CE 25 is refined into CE [27]
* CE 23 is refined into CE [28]


### Cost equations --> "Loop" of isZero/2
* CEs [26] --> Loop 19
* CEs [27] --> Loop 20
* CEs [28] --> Loop 21

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

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


### Specialization of cost equations le/3
* CE 17 is refined into CE [29]
* CE 15 is refined into CE [30]
* CE 14 is refined into CE [31]
* CE 16 is refined into CE [32]


### Cost equations --> "Loop" of le/3
* CEs [32] --> Loop 22
* CEs [29] --> Loop 23
* CEs [30] --> Loop 24
* CEs [31] --> Loop 25

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

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


### Specialization of cost equations minus/3
* CE 18 is refined into CE [33]
* CE 19 is refined into CE [34]
* CE 20 is refined into CE [35]
* CE 22 is refined into CE [36]
* CE 21 is refined into CE [37]


### Cost equations --> "Loop" of minus/3
* CEs [37] --> Loop 26
* CEs [33] --> Loop 27
* CEs [34] --> Loop 28
* CEs [35,36] --> Loop 29

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

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


### Specialization of cost equations (mod)/3
* CE 12 is refined into CE [38,39]
* CE 13 is refined into CE [40,41,42,43]
* CE 10 is refined into CE [44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62]
* CE 11 is refined into CE [63,64]


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

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

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


### Specialization of cost equations start/5
* CE 5 is refined into CE [65]
* CE 3 is refined into CE [66,67,68,69]
* CE 2 is refined into CE [70]
* CE 4 is refined into CE [71]
* CE 6 is refined into CE [72,73,74,75,76]
* CE 7 is refined into CE [77,78,79]
* CE 8 is refined into CE [80,81,82]
* CE 9 is refined into CE [83,84,85,86]


### Cost equations --> "Loop" of start/5
* CEs [73,77,84] --> Loop 36
* CEs [65] --> Loop 37
* CEs [66,67,68,69] --> Loop 38
* CEs [71] --> Loop 39
* CEs [70,72,74,75,76,78,79,80,81,82,83,85,86] --> Loop 40

### Ranking functions of CR start(V,V1,V14,V15,V16)

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


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

#### Cost of chains of isZero(V,Out):
* Chain [21]: 1
with precondition: [V=0,Out=2]

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

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


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

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

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

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

* Chain [[22],23]: 1*it(22)+0
Such that:it(22) =< V1

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

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

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

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


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

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

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

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

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

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

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

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

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


#### Cost of chains of mod(V,V1,Out):
* Chain [[30],35]: 19*it(30)+17*s(5)+5
Such that:aux(10) =< V1
aux(14) =< V
it(30) =< aux(14)
s(5) =< aux(10)

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

* Chain [[30],32]: 5*it(30)+2*s(40)+2*s(42)+1*s(44)+5
Such that:aux(12) =< V
it(30) =< V-V1+1
aux(13) =< V-Out
s(44) =< V1
aux(15) =< Out
s(42) =< aux(15)
it(30) =< aux(12)
s(41) =< aux(12)
it(30) =< aux(13)
s(41) =< aux(13)
s(40) =< s(41)

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

* Chain [[30],31,35]: 8*it(30)+19*s(5)+10
Such that:aux(17) =< V1
aux(18) =< V
it(30) =< aux(18)
s(5) =< aux(17)

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

* Chain [35]: 17*s(5)+12*s(8)+5
Such that:aux(9) =< V
aux(10) =< V1
s(8) =< aux(9)
s(5) =< aux(10)

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

* Chain [34]: 6*s(48)+4
Such that:aux(20) =< V
s(48) =< aux(20)

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

* Chain [33]: 4*s(57)+5
Such that:aux(22) =< V
s(57) =< aux(22)

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

* Chain [32]: 2*s(42)+1*s(44)+5
Such that:s(44) =< V1
aux(15) =< V
s(42) =< aux(15)

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

* Chain [31,35]: 19*s(5)+1*s(46)+10
Such that:s(46) =< V
aux(17) =< V1
s(5) =< aux(17)

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


#### Cost of chains of start(V,V1,V14,V15,V16):
* Chain [40]: 78*s(80)+54*s(82)+5*s(94)+10
Such that:s(94) =< V-V1+1
aux(26) =< V
aux(27) =< V1
s(82) =< aux(26)
s(80) =< aux(27)
s(94) =< aux(26)

with precondition: [V>=0]

* Chain [39]: 1
with precondition: [V=1,V1=1,V14>=0,V15>=0,V16>=0]

* Chain [38]: 56*s(103)+74*s(104)+5*s(111)+11
Such that:s(111) =< -V15+V16+1
aux(29) =< V15
aux(30) =< V16
s(104) =< aux(29)
s(103) =< aux(30)
s(111) =< aux(30)

with precondition: [V=1,V1=2,V14>=0,V15>=0,V16>=0]

* Chain [37]: 1
with precondition: [V=2,V1>=0,V14>=0,V15>=0,V16>=0]

* Chain [36]: 4*s(119)+5
Such that:s(118) =< V
s(119) =< s(118)

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


Closed-form bounds of start(V,V1,V14,V15,V16):
-------------------------------------
* Chain [40] with precondition: [V>=0]
- Upper bound: 54*V+10+nat(V1)*78+nat(V-V1+1)*5
- Complexity: n
* Chain [39] with precondition: [V=1,V1=1,V14>=0,V15>=0,V16>=0]
- Upper bound: 1
- Complexity: constant
* Chain [38] with precondition: [V=1,V1=2,V14>=0,V15>=0,V16>=0]
- Upper bound: 74*V15+56*V16+11+nat(-V15+V16+1)*5
- Complexity: n
* Chain [37] with precondition: [V=2,V1>=0,V14>=0,V15>=0,V16>=0]
- Upper bound: 1
- Complexity: constant
* Chain [36] with precondition: [V1=0,V>=0]
- Upper bound: 4*V+5
- Complexity: n

### Maximum cost of start(V,V1,V14,V15,V16): max([nat(V15)*74+10+nat(V16)*56+nat(-V15+V16+1)*5,50*V+5+nat(V1)*78+nat(V-V1+1)*5+ (4*V+4)])+1
Asymptotic class: n
* Total analysis performed in 517 ms.

(10) BOUNDS(1, n^1)