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

p(0) → 0
p(s(x)) → x
le(0, y) → true
le(s(x), 0) → false
le(s(x), s(y)) → le(x, y)
minus(x, y) → if(le(x, y), x, y)
if(true, x, y) → 0
if(false, x, y) → s(minus(p(x), 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^2).


The TRS R consists of the following rules:

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

p(0) → 0 [1]
p(s(x)) → x [1]
le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
minus(x, y) → if(le(x, y), x, y) [1]
if(true, x, y) → 0 [1]
if(false, x, y) → s(minus(p(x), y)) [1]

The TRS has the following type information:
p :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
le :: 0:s → 0:s → true:false
true :: true:false
false :: true:false
minus :: 0:s → 0:s → 0:s
if :: true:false → 0:s → 0:s → 0:s

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:

p(0) → 0 [1]
p(s(x)) → x [1]
le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
minus(x, y) → if(le(x, y), x, y) [1]
if(true, x, y) → 0 [1]
if(false, x, y) → s(minus(p(x), y)) [1]

The TRS has the following type information:
p :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s
le :: 0:s → 0:s → true:false
true :: true:false
false :: true:false
minus :: 0:s → 0:s → 0:s
if :: true:false → 0:s → 0:s → 0:s

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

(8) Obligation:

Complexity RNTS consisting of the following rules:

if(z, z', z'') -{ 1 }→ 0 :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
if(z, z', z'') -{ 1 }→ 1 + minus(p(x), y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
le(z, z') -{ 1 }→ le(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
le(z, z') -{ 1 }→ 1 :|: y >= 0, z = 0, z' = y
le(z, z') -{ 1 }→ 0 :|: x >= 0, z = 1 + x, z' = 0
minus(z, z') -{ 1 }→ if(le(x, y), x, y) :|: x >= 0, y >= 0, z = x, z' = y
p(z) -{ 1 }→ x :|: x >= 0, z = 1 + x
p(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, V2, V9),0,[p(V, Out)],[V >= 0]).
eq(start(V, V2, V9),0,[le(V, V2, Out)],[V >= 0,V2 >= 0]).
eq(start(V, V2, V9),0,[minus(V, V2, Out)],[V >= 0,V2 >= 0]).
eq(start(V, V2, V9),0,[if(V, V2, V9, Out)],[V >= 0,V2 >= 0,V9 >= 0]).
eq(p(V, Out),1,[],[Out = 0,V = 0]).
eq(p(V, Out),1,[],[Out = V1,V1 >= 0,V = 1 + V1]).
eq(le(V, V2, Out),1,[],[Out = 1,V3 >= 0,V = 0,V2 = V3]).
eq(le(V, V2, Out),1,[],[Out = 0,V4 >= 0,V = 1 + V4,V2 = 0]).
eq(le(V, V2, Out),1,[le(V5, V6, Ret)],[Out = Ret,V2 = 1 + V6,V5 >= 0,V6 >= 0,V = 1 + V5]).
eq(minus(V, V2, Out),1,[le(V7, V8, Ret0),if(Ret0, V7, V8, Ret1)],[Out = Ret1,V7 >= 0,V8 >= 0,V = V7,V2 = V8]).
eq(if(V, V2, V9, Out),1,[],[Out = 0,V2 = V10,V9 = V11,V = 1,V10 >= 0,V11 >= 0]).
eq(if(V, V2, V9, Out),1,[p(V12, Ret10),minus(Ret10, V13, Ret11)],[Out = 1 + Ret11,V2 = V12,V9 = V13,V12 >= 0,V13 >= 0,V = 0]).
input_output_vars(p(V,Out),[V],[Out]).
input_output_vars(le(V,V2,Out),[V,V2],[Out]).
input_output_vars(minus(V,V2,Out),[V,V2],[Out]).
input_output_vars(if(V,V2,V9,Out),[V,V2,V9],[Out]).

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

#### Computed strongly connected components
0. recursive : [le/3]
1. non_recursive : [p/2]
2. recursive : [if/4,minus/3]
3. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into le/3
1. SCC is partially evaluated into p/2
2. SCC is partially evaluated into minus/3
3. SCC is partially evaluated into start/3

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

### Specialization of cost equations le/3
* CE 13 is refined into CE [14]
* CE 12 is refined into CE [15]
* CE 11 is refined into CE [16]


### Cost equations --> "Loop" of le/3
* CEs [15] --> Loop 10
* CEs [16] --> Loop 11
* CEs [14] --> Loop 12

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

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


### Specialization of cost equations p/2
* CE 8 is refined into CE [17]
* CE 7 is refined into CE [18]


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

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

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


### Specialization of cost equations minus/3
* CE 10 is refined into CE [19,20]
* CE 9 is refined into CE [21,22]


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

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

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


### Specialization of cost equations start/3
* CE 3 is refined into CE [23]
* CE 2 is refined into CE [24,25,26,27,28]
* CE 4 is refined into CE [29,30]
* CE 5 is refined into CE [31,32,33,34]
* CE 6 is refined into CE [35,36,37,38]


### Cost equations --> "Loop" of start/3
* CEs [32,36] --> Loop 19
* CEs [23,30,33,34,37,38] --> Loop 20
* CEs [24,25,26,27,28,29,31,35] --> Loop 21

### Ranking functions of CR start(V,V2,V9)

#### Partial ranking functions of CR start(V,V2,V9)


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

#### Cost of chains of le(V,V2,Out):
* Chain [[12],11]: 1*it(12)+1
Such that:it(12) =< V

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

* Chain [[12],10]: 1*it(12)+1
Such that:it(12) =< V2

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

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

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


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

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


#### Cost of chains of minus(V,V2,Out):
* Chain [[16],18]: 4*it(16)+3
Such that:it(16) =< Out

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

* Chain [[15],17]: 4*it(15)+1*s(1)+1*s(4)+3
Such that:it(15) =< Out
aux(2) =< V-Out
s(1) =< aux(2)
s(4) =< it(15)*aux(2)

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

* Chain [18]: 3
with precondition: [V=0,Out=0,V2>=0]

* Chain [17]: 1*s(1)+3
Such that:s(1) =< V

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


#### Cost of chains of start(V,V2,V9):
* Chain [21]: 5*s(5)+4*s(7)+1*s(9)+1*s(10)+5
Such that:s(7) =< V2-V9
s(8) =< V9
aux(3) =< V2
s(5) =< aux(3)
s(9) =< s(8)
s(10) =< s(7)*s(8)

with precondition: [V=0]

* Chain [20]: 2*s(11)+2*s(12)+4*s(14)+1*s(17)+3
Such that:s(14) =< V-V2
aux(4) =< V
aux(5) =< V2
s(12) =< aux(4)
s(11) =< aux(5)
s(17) =< s(14)*aux(5)

with precondition: [V>=1]

* Chain [19]: 4*s(18)+3
Such that:s(18) =< V

with precondition: [V2=0,V>=1]


Closed-form bounds of start(V,V2,V9):
-------------------------------------
* Chain [21] with precondition: [V=0]
- Upper bound: nat(V2)*5+5+nat(V9)+nat(V2-V9)*nat(V9)+nat(V2-V9)*4
- Complexity: n^2
* Chain [20] with precondition: [V>=1]
- Upper bound: 2*V+3+nat(V2)*2+nat(V-V2)*nat(V2)+nat(V-V2)*4
- Complexity: n^2
* Chain [19] with precondition: [V2=0,V>=1]
- Upper bound: 4*V+3
- Complexity: n

### Maximum cost of start(V,V2,V9): max([2*V+max([2*V,nat(V-V2)*nat(V2)+nat(V2)*2+nat(V-V2)*4]),nat(V2)*5+2+nat(V9)+nat(V2-V9)*nat(V9)+nat(V2-V9)*4])+3
Asymptotic class: n^2
* Total analysis performed in 207 ms.

(10) BOUNDS(1, n^2)