0 CpxTRS
↳1 TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID), 0 ms)
↳2 CpxWeightedTrs
↳3 TypeInferenceProof (BOTH BOUNDS(ID, ID), 0 ms)
↳4 CpxTypedWeightedTrs
↳5 CompletionProof (UPPER BOUND(ID), 0 ms)
↳6 CpxTypedWeightedCompleteTrs
↳7 CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID), 0 ms)
↳8 CpxRNTS
↳9 CompleteCoflocoProof (⇔, 944 ms)
↳10 BOUNDS(1, n^2)
gt(s(x), 0) → true
gt(0, y) → false
gt(s(x), s(y)) → gt(x, y)
divides(x, y) → div(x, y, y)
div(0, 0, z) → true
div(0, s(x), z) → false
div(s(x), 0, s(z)) → div(s(x), s(z), s(z))
div(s(x), s(y), z) → div(x, y, z)
prime(x) → test(x, s(s(0)))
test(x, y) → if1(gt(x, y), x, y)
if1(true, x, y) → if2(divides(x, y), x, y)
if1(false, x, y) → true
if2(true, x, y) → false
if2(false, x, y) → test(x, s(y))
gt(s(x), 0) → true [1]
gt(0, y) → false [1]
gt(s(x), s(y)) → gt(x, y) [1]
divides(x, y) → div(x, y, y) [1]
div(0, 0, z) → true [1]
div(0, s(x), z) → false [1]
div(s(x), 0, s(z)) → div(s(x), s(z), s(z)) [1]
div(s(x), s(y), z) → div(x, y, z) [1]
prime(x) → test(x, s(s(0))) [1]
test(x, y) → if1(gt(x, y), x, y) [1]
if1(true, x, y) → if2(divides(x, y), x, y) [1]
if1(false, x, y) → true [1]
if2(true, x, y) → false [1]
if2(false, x, y) → test(x, s(y)) [1]
gt(s(x), 0) → true [1]
gt(0, y) → false [1]
gt(s(x), s(y)) → gt(x, y) [1]
divides(x, y) → div(x, y, y) [1]
div(0, 0, z) → true [1]
div(0, s(x), z) → false [1]
div(s(x), 0, s(z)) → div(s(x), s(z), s(z)) [1]
div(s(x), s(y), z) → div(x, y, z) [1]
prime(x) → test(x, s(s(0))) [1]
test(x, y) → if1(gt(x, y), x, y) [1]
if1(true, x, y) → if2(divides(x, y), x, y) [1]
if1(false, x, y) → true [1]
if2(true, x, y) → false [1]
if2(false, x, y) → test(x, s(y)) [1]
gt :: s:0 → s:0 → true:false s :: s:0 → s:0 0 :: s:0 true :: true:false false :: true:false divides :: s:0 → s:0 → true:false div :: s:0 → s:0 → s:0 → true:false prime :: s:0 → true:false test :: s:0 → s:0 → true:false if1 :: true:false → s:0 → s:0 → true:false if2 :: true:false → s:0 → s:0 → true:false |
div(v0, v1, v2) → null_div [0]
if1(v0, v1, v2) → null_if1 [0]
if2(v0, v1, v2) → null_if2 [0]
null_div, null_if1, null_if2
Runtime Complexity Weighted TRS with Types. The TRS R consists of the following rules:
The TRS has the following type information:
Rewrite Strategy: INNERMOST |
0 => 0
true => 2
false => 1
null_div => 0
null_if1 => 0
null_if2 => 0
div(z', z'', z1) -{ 1 }→ div(x, y, z) :|: z' = 1 + x, z1 = z, z >= 0, x >= 0, y >= 0, z'' = 1 + y
div(z', z'', z1) -{ 1 }→ div(1 + x, 1 + z, 1 + z) :|: z'' = 0, z' = 1 + x, z >= 0, x >= 0, z1 = 1 + z
div(z', z'', z1) -{ 1 }→ 2 :|: z'' = 0, z1 = z, z >= 0, z' = 0
div(z', z'', z1) -{ 1 }→ 1 :|: z1 = z, z >= 0, x >= 0, z'' = 1 + x, z' = 0
div(z', z'', z1) -{ 0 }→ 0 :|: v0 >= 0, z1 = v2, v1 >= 0, z'' = v1, v2 >= 0, z' = v0
divides(z', z'') -{ 1 }→ div(x, y, y) :|: z' = x, z'' = y, x >= 0, y >= 0
gt(z', z'') -{ 1 }→ gt(x, y) :|: z' = 1 + x, x >= 0, y >= 0, z'' = 1 + y
gt(z', z'') -{ 1 }→ 2 :|: z'' = 0, z' = 1 + x, x >= 0
gt(z', z'') -{ 1 }→ 1 :|: z'' = y, y >= 0, z' = 0
if1(z', z'', z1) -{ 1 }→ if2(divides(x, y), x, y) :|: z1 = y, z' = 2, x >= 0, y >= 0, z'' = x
if1(z', z'', z1) -{ 1 }→ 2 :|: z1 = y, x >= 0, y >= 0, z'' = x, z' = 1
if1(z', z'', z1) -{ 0 }→ 0 :|: v0 >= 0, z1 = v2, v1 >= 0, z'' = v1, v2 >= 0, z' = v0
if2(z', z'', z1) -{ 1 }→ test(x, 1 + y) :|: z1 = y, x >= 0, y >= 0, z'' = x, z' = 1
if2(z', z'', z1) -{ 1 }→ 1 :|: z1 = y, z' = 2, x >= 0, y >= 0, z'' = x
if2(z', z'', z1) -{ 0 }→ 0 :|: v0 >= 0, z1 = v2, v1 >= 0, z'' = v1, v2 >= 0, z' = v0
prime(z') -{ 1 }→ test(x, 1 + (1 + 0)) :|: z' = x, x >= 0
test(z', z'') -{ 1 }→ if1(gt(x, y), x, y) :|: z' = x, z'' = y, x >= 0, y >= 0
eq(start(V, V1, V8),0,[gt(V, V1, Out)],[V >= 0,V1 >= 0]). eq(start(V, V1, V8),0,[divides(V, V1, Out)],[V >= 0,V1 >= 0]). eq(start(V, V1, V8),0,[div(V, V1, V8, Out)],[V >= 0,V1 >= 0,V8 >= 0]). eq(start(V, V1, V8),0,[prime(V, Out)],[V >= 0]). eq(start(V, V1, V8),0,[test(V, V1, Out)],[V >= 0,V1 >= 0]). eq(start(V, V1, V8),0,[if1(V, V1, V8, Out)],[V >= 0,V1 >= 0,V8 >= 0]). eq(start(V, V1, V8),0,[if2(V, V1, V8, Out)],[V >= 0,V1 >= 0,V8 >= 0]). eq(gt(V, V1, Out),1,[],[Out = 2,V1 = 0,V = 1 + V2,V2 >= 0]). eq(gt(V, V1, Out),1,[],[Out = 1,V1 = V3,V3 >= 0,V = 0]). eq(gt(V, V1, Out),1,[gt(V4, V5, Ret)],[Out = Ret,V = 1 + V4,V4 >= 0,V5 >= 0,V1 = 1 + V5]). eq(divides(V, V1, Out),1,[div(V6, V7, V7, Ret1)],[Out = Ret1,V = V6,V1 = V7,V6 >= 0,V7 >= 0]). eq(div(V, V1, V8, Out),1,[],[Out = 2,V1 = 0,V8 = V9,V9 >= 0,V = 0]). eq(div(V, V1, V8, Out),1,[],[Out = 1,V8 = V10,V10 >= 0,V11 >= 0,V1 = 1 + V11,V = 0]). eq(div(V, V1, V8, Out),1,[div(1 + V12, 1 + V13, 1 + V13, Ret2)],[Out = Ret2,V1 = 0,V = 1 + V12,V13 >= 0,V12 >= 0,V8 = 1 + V13]). eq(div(V, V1, V8, Out),1,[div(V14, V15, V16, Ret3)],[Out = Ret3,V = 1 + V14,V8 = V16,V16 >= 0,V14 >= 0,V15 >= 0,V1 = 1 + V15]). eq(prime(V, Out),1,[test(V17, 1 + (1 + 0), Ret4)],[Out = Ret4,V = V17,V17 >= 0]). eq(test(V, V1, Out),1,[gt(V18, V19, Ret0),if1(Ret0, V18, V19, Ret5)],[Out = Ret5,V = V18,V1 = V19,V18 >= 0,V19 >= 0]). eq(if1(V, V1, V8, Out),1,[divides(V20, V21, Ret01),if2(Ret01, V20, V21, Ret6)],[Out = Ret6,V8 = V21,V = 2,V20 >= 0,V21 >= 0,V1 = V20]). eq(if1(V, V1, V8, Out),1,[],[Out = 2,V8 = V22,V23 >= 0,V22 >= 0,V1 = V23,V = 1]). eq(if2(V, V1, V8, Out),1,[],[Out = 1,V8 = V24,V = 2,V25 >= 0,V24 >= 0,V1 = V25]). eq(if2(V, V1, V8, Out),1,[test(V26, 1 + V27, Ret7)],[Out = Ret7,V8 = V27,V26 >= 0,V27 >= 0,V1 = V26,V = 1]). eq(div(V, V1, V8, Out),0,[],[Out = 0,V28 >= 0,V8 = V29,V30 >= 0,V1 = V30,V29 >= 0,V = V28]). eq(if1(V, V1, V8, Out),0,[],[Out = 0,V31 >= 0,V8 = V32,V33 >= 0,V1 = V33,V32 >= 0,V = V31]). eq(if2(V, V1, V8, Out),0,[],[Out = 0,V34 >= 0,V8 = V35,V36 >= 0,V1 = V36,V35 >= 0,V = V34]). input_output_vars(gt(V,V1,Out),[V,V1],[Out]). input_output_vars(divides(V,V1,Out),[V,V1],[Out]). input_output_vars(div(V,V1,V8,Out),[V,V1,V8],[Out]). input_output_vars(prime(V,Out),[V],[Out]). input_output_vars(test(V,V1,Out),[V,V1],[Out]). input_output_vars(if1(V,V1,V8,Out),[V,V1,V8],[Out]). input_output_vars(if2(V,V1,V8,Out),[V,V1,V8],[Out]). |
CoFloCo proof output:
Preprocessing Cost Relations
=====================================
#### Computed strongly connected components
0. recursive : [ (div)/4]
1. non_recursive : [divides/3]
2. recursive : [gt/3]
3. recursive : [if1/4,if2/4,test/3]
4. non_recursive : [prime/2]
5. non_recursive : [start/3]
#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into (div)/4
1. SCC is completely evaluated into other SCCs
2. SCC is partially evaluated into gt/3
3. SCC is partially evaluated into test/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 (div)/4
* CE 18 is refined into CE [27]
* CE 15 is refined into CE [28]
* CE 14 is refined into CE [29]
* CE 17 is refined into CE [30]
* CE 16 is refined into CE [31]
### Cost equations --> "Loop" of (div)/4
* CEs [30] --> Loop 15
* CEs [31] --> Loop 16
* CEs [27] --> Loop 17
* CEs [28] --> Loop 18
* CEs [29] --> Loop 19
### Ranking functions of CR div(V,V1,V8,Out)
#### Partial ranking functions of CR div(V,V1,V8,Out)
* Partial RF of phase [15,16]:
- RF of loop [15:1]:
V
V1 depends on loops [16:1]
- RF of loop [16:1]:
-V1+1 depends on loops [15:1]
### Specialization of cost equations gt/3
* CE 26 is refined into CE [32]
* CE 24 is refined into CE [33]
* CE 25 is refined into CE [34]
### Cost equations --> "Loop" of gt/3
* CEs [33] --> Loop 20
* CEs [34] --> Loop 21
* CEs [32] --> Loop 22
### Ranking functions of CR gt(V,V1,Out)
* RF of phase [22]: [V,V1]
#### Partial ranking functions of CR gt(V,V1,Out)
* Partial RF of phase [22]:
- RF of loop [22:1]:
V
V1
### Specialization of cost equations test/3
* CE 23 is refined into CE [35,36]
* CE 21 is refined into CE [37]
* CE 19 is refined into CE [38,39,40,41]
* CE 22 is refined into CE [42,43,44,45]
* CE 20 is refined into CE [46]
### Cost equations --> "Loop" of test/3
* CEs [46] --> Loop 23
* CEs [36] --> Loop 24
* CEs [37] --> Loop 25
* CEs [39,40,41,45] --> Loop 26
* CEs [44] --> Loop 27
* CEs [38,43] --> Loop 28
* CEs [35] --> Loop 29
* CEs [42] --> Loop 30
### Ranking functions of CR test(V,V1,Out)
* RF of phase [23]: [V-V1]
#### Partial ranking functions of CR test(V,V1,Out)
* Partial RF of phase [23]:
- RF of loop [23:1]:
V-V1
### Specialization of cost equations start/3
* CE 2 is refined into CE [47,48,49,50,51]
* CE 4 is refined into CE [52,53,54,55,56,57,58]
* CE 6 is refined into CE [59,60]
* CE 7 is refined into CE [61]
* CE 3 is refined into CE [62]
* CE 5 is refined into CE [63,64,65,66,67,68,69]
* CE 8 is refined into CE [70]
* CE 9 is refined into CE [71,72,73,74]
* CE 10 is refined into CE [75,76,77,78,79]
* CE 11 is refined into CE [80,81,82,83,84]
* CE 12 is refined into CE [85,86,87,88,89,90,91]
* CE 13 is refined into CE [92,93,94,95,96,97,98,99]
### Cost equations --> "Loop" of start/3
* CEs [88,89,91] --> Loop 31
* CEs [48,52,53,72,94] --> Loop 32
* CEs [47,49,50,51,54,55,56,57,58,59,60,61,62,73,74,77,78,79,82,83,84,95,96,97,98,99] --> Loop 33
* CEs [63,64,65,66,67,68,69,70,87,90] --> Loop 34
* CEs [71,75,76,80,81,85,86,92,93] --> Loop 35
### Ranking functions of CR start(V,V1,V8)
#### Partial ranking functions of CR start(V,V1,V8)
Computing Bounds
=====================================
#### Cost of chains of div(V,V1,V8,Out):
* Chain [[15,16],19]: 1*it(15)+1*it(16)+1
Such that:it(15) =< V
aux(6) =< -V1
aux(5) =< -V1+1
it(16) =< it(15)+aux(6)
it(16) =< it(15)+aux(5)
with precondition: [Out=2,V>=1,V1>=0,V8>=0,V>=V1,V1+V8>=1]
* Chain [[15,16],18]: 1*it(15)+1*it(16)+1
Such that:it(15) =< V
aux(5) =< -V1+1
it(16) =< it(15)+aux(5)
with precondition: [Out=1,V>=1,V1>=0,V8>=0,V1+V8>=1]
* Chain [[15,16],17]: 1*it(15)+1*it(16)+0
Such that:it(15) =< V
aux(5) =< -V1+1
it(16) =< it(15)+aux(5)
with precondition: [Out=0,V>=1,V1>=0,V8>=0,V1+V8>=1]
* Chain [19]: 1
with precondition: [V=0,V1=0,Out=2,V8>=0]
* Chain [18]: 1
with precondition: [V=0,Out=1,V1>=1,V8>=0]
* Chain [17]: 0
with precondition: [Out=0,V>=0,V1>=0,V8>=0]
#### Cost of chains of gt(V,V1,Out):
* Chain [[22],21]: 1*it(22)+1
Such that:it(22) =< V
with precondition: [Out=1,V>=1,V1>=V]
* Chain [[22],20]: 1*it(22)+1
Such that:it(22) =< V1
with precondition: [Out=2,V1>=1,V>=V1+1]
* Chain [21]: 1
with precondition: [V=0,Out=1,V1>=0]
* Chain [20]: 1
with precondition: [V1=0,Out=2,V>=1]
#### Cost of chains of test(V,V1,Out):
* Chain [[23],27]: 6*it(23)+1*s(4)+2*s(13)+1*s(15)+2
Such that:s(16) =< -V1+1
aux(14) =< V
aux(15) =< V-V1
s(4) =< aux(14)
it(23) =< aux(15)
s(16) =< aux(15)
s(13) =< it(23)*aux(14)
s(15) =< s(13)+s(16)
with precondition: [Out=0,V1>=1,V>=V1+1]
* Chain [[23],26]: 6*it(23)+2*s(13)+1*s(15)+7*s(17)+3*s(20)+5
Such that:s(16) =< -V1+1
aux(19) =< V
aux(20) =< V-V1
aux(21) =< -V1
it(23) =< aux(20)
s(16) =< aux(20)
s(17) =< aux(19)
s(20) =< s(17)+aux(21)
s(13) =< it(23)*aux(19)
s(15) =< s(13)+s(16)
with precondition: [Out=0,V1>=1,V>=V1+2]
* Chain [[23],25]: 6*it(23)+2*s(13)+1*s(15)+2*s(31)+1*s(35)+6
Such that:s(16) =< -V1+1
aux(22) =< V
aux(23) =< V-V1
aux(24) =< -V1
s(31) =< aux(22)
it(23) =< aux(23)
s(16) =< aux(23)
s(35) =< s(31)+aux(24)
s(13) =< it(23)*aux(22)
s(15) =< s(13)+s(16)
with precondition: [Out=1,V1>=1,V>=V1+2]
* Chain [[23],24]: 6*it(23)+2*s(13)+1*s(15)+1*s(36)+3
Such that:s(16) =< -V1+1
aux(25) =< V
aux(26) =< V-V1
s(36) =< aux(25)
it(23) =< aux(26)
s(16) =< aux(26)
s(13) =< it(23)*aux(25)
s(15) =< s(13)+s(16)
with precondition: [Out=2,V1>=1,V>=V1+1]
* Chain [30]: 2
with precondition: [V=0,Out=0,V1>=0]
* Chain [29]: 3
with precondition: [V=0,Out=2,V1>=0]
* Chain [28]: 1*s(37)+1*s(39)+4
Such that:s(38) =< 1
s(37) =< V
s(39) =< s(37)+s(38)
with precondition: [V1=0,Out=0,V>=1]
* Chain [27]: 1*s(4)+2
Such that:s(4) =< V
with precondition: [Out=0,V>=1,V1>=V]
* Chain [26]: 4*s(17)+3*s(18)+2*s(20)+1*s(29)+5
Such that:s(27) =< -V1
aux(16) =< V
aux(17) =< -V1+1
aux(18) =< V1
s(18) =< aux(16)
s(17) =< aux(18)
s(20) =< s(18)+aux(17)
s(29) =< s(18)+s(27)
s(29) =< s(18)+aux(17)
with precondition: [Out=0,V1>=1,V>=V1+1]
* Chain [25]: 1*s(31)+1*s(32)+1*s(35)+6
Such that:s(32) =< V
s(33) =< -V1
s(34) =< -V1+1
s(31) =< V1
s(35) =< s(32)+s(33)
s(35) =< s(32)+s(34)
with precondition: [Out=1,V1>=1,V>=V1+1]
* Chain [24]: 1*s(36)+3
Such that:s(36) =< V
with precondition: [Out=2,V>=1,V1>=V]
#### Cost of chains of start(V,V1,V8):
* Chain [35]: 4
with precondition: [V=0]
* Chain [34]: 17*s(78)+5*s(86)+8*s(87)+24*s(89)+8*s(91)+4*s(92)+2*s(113)+7
Such that:aux(36) =< V
aux(37) =< V1
aux(38) =< V1-V8
aux(39) =< -V8
aux(40) =< V8+1
s(113) =< aux(36)
s(78) =< aux(37)
s(84) =< aux(39)
s(86) =< aux(40)
s(87) =< s(78)+aux(39)
s(89) =< aux(38)
s(84) =< aux(38)
s(91) =< s(89)*aux(37)
s(92) =< s(91)+s(84)
with precondition: [2>=V,V>=1]
* Chain [33]: 32*s(115)+7*s(117)+2*s(124)+5*s(139)+8*s(140)+24*s(142)+8*s(144)+4*s(145)+24*s(179)+6*s(183)+4*s(190)+24*s(212)+4*s(213)+8*s(214)+4*s(215)+10
Such that:aux(48) =< V
aux(49) =< V-V1
aux(50) =< -V1
aux(51) =< -V1+1
aux(52) =< V1
aux(53) =< V1-V8
aux(54) =< -V8
aux(55) =< -V8+1
aux(56) =< V8+1
s(179) =< aux(48)
s(207) =< aux(51)
s(115) =< aux(52)
s(137) =< aux(54)
s(139) =< aux(56)
s(183) =< s(179)+aux(51)
s(190) =< s(179)+aux(50)
s(190) =< s(179)+aux(51)
s(212) =< aux(49)
s(207) =< aux(49)
s(213) =< s(179)+aux(50)
s(214) =< s(212)*aux(48)
s(215) =< s(214)+s(207)
s(117) =< s(115)+aux(55)
s(124) =< s(115)+aux(54)
s(124) =< s(115)+aux(55)
s(140) =< s(115)+aux(54)
s(142) =< aux(53)
s(137) =< aux(53)
s(144) =< s(142)*aux(52)
s(145) =< s(144)+s(137)
with precondition: [V>=0,V1>=0]
* Chain [32]: 1*s(237)+1*s(238)+7
Such that:s(236) =< 1
s(237) =< V
s(238) =< s(237)+s(236)
with precondition: [V1=0,V>=1]
* Chain [31]: 39*s(245)+5*s(246)+8*s(247)+8*s(251)+4*s(252)+7
Such that:aux(62) =< 2
aux(63) =< V
s(246) =< aux(62)
s(245) =< aux(63)
s(247) =< s(245)
s(251) =< s(245)*aux(63)
s(252) =< s(251)
with precondition: [V>=3]
Closed-form bounds of start(V,V1,V8):
-------------------------------------
* Chain [35] with precondition: [V=0]
- Upper bound: 4
- Complexity: constant
* Chain [34] with precondition: [2>=V,V>=1]
- Upper bound: 2*V+7+nat(V1)*25+nat(V1)*12*nat(V1-V8)+nat(-V8)*12+nat(V8+1)*5+nat(V1-V8)*24
- Complexity: n^2
* Chain [33] with precondition: [V>=0,V1>=0]
- Upper bound: 38*V+10+12*V*nat(V-V1)+49*V1+12*V1*nat(V1-V8)+nat(-V8)*14+nat(V8+1)*5+nat(-V1+1)*10+nat(-V8+1)*7+nat(V-V1)*24+nat(V1-V8)*24
- Complexity: n^2
* Chain [32] with precondition: [V1=0,V>=1]
- Upper bound: 2*V+8
- Complexity: n
* Chain [31] with precondition: [V>=3]
- Upper bound: 47*V+17+12*V*V
- Complexity: n^2
### Maximum cost of start(V,V1,V8): 2*V+3+max([max([1,nat(V1)*12*nat(V1-V8)+nat(V1)*25+nat(-V8)*12+nat(V8+1)*5+nat(V1-V8)*24]),36*V+3+max([9*V+7+12*V*V,12*V*nat(V-V1)+nat(V1)*49+nat(V1)*12*nat(V1-V8)+nat(-V8)*14+nat(V8+1)*5+nat(-V1+1)*10+nat(-V8+1)*7+nat(V-V1)*24+nat(V1-V8)*24])])+4
Asymptotic class: n^2
* Total analysis performed in 751 ms.