Article SCPQSORT, MML version 4.99.1005
:: SCPQSORT:funcreg 1
registration
let a1, a2 be finite programmed initial shiftable Element of sproduct the Object-Kind of SCMPDS;
let a3 be Int_position;
let a4 be integer set;
cluster if>0(a3,a4,a1,a2) -> finite programmed initial shiftable;
end;
:: SCPQSORT:th 1
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2 being finite programmed initial shiftable No-StopCode Element of sproduct the Object-Kind of SCMPDS
for b3 being finite programmed initial shiftable Element of sproduct the Object-Kind of SCMPDS
for b4, b5 being Int_position
for b6 being integer set
st 0 < b1 . DataLoc(b1 . b4,b6) &
b2 is_closed_on b1 &
b2 is_halting_on b1
holds (IExec(if>0(b4,b6,b2,b3),b1)) . b5 = (IExec(b2,b1)) . b5;
:: SCPQSORT:th 2
theorem
for b1, b2 being Element of product the Object-Kind of SCMPDS
for b3 being finite programmed initial shiftable No-StopCode Element of sproduct the Object-Kind of SCMPDS
for b4 being Int_position
for b5 being integer set
for b6 being Element of NAT
st 0 < card b3 &
b3 is_closed_on b1 &
b3 is_halting_on b1 &
0 < b1 . DataLoc(b1 . b4,b5) &
b6 = (LifeSpan (b1 +* Initialized stop b3)) + 2 &
b2 = Computation(b1 +* Initialized stop while>0(b4,b5,b3),b6)
holds b2 | SCM-Data-Loc = (IExec(b3,b1)) | SCM-Data-Loc &
b2 +* Initialized stop while>0(b4,b5,b3) = b2;
:: SCPQSORT:th 3
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2 being finite programmed initial Element of sproduct the Object-Kind of SCMPDS
st for b3 being Element of product the Object-Kind of SCMPDS
st b3 | SCM-Data-Loc = b1 | SCM-Data-Loc
holds b2 is_halting_on b3
holds b2 is_closed_on b1;
:: SCPQSORT:th 4
theorem
for b1, b2, b3, b4 being Element of the Instructions of SCMPDS holds
card (((b1 ';' b2) ';' b3) ';' b4) = 4;
:: SCPQSORT:th 5
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2 being finite programmed initial shiftable No-StopCode Element of sproduct the Object-Kind of SCMPDS
for b3, b4, b5 being Int_position
for b6, b7 being integer set
st 0 < card b2 &
b7 + (b1 . DataLoc(b1 . b3,b6)) <= b1 . b4 &
(for b8 being Element of product the Object-Kind of SCMPDS
st b7 + (b8 . DataLoc(b1 . b3,b6)) <= b8 . b4 &
b8 . b5 = b1 . b5 &
b8 . b3 = b1 . b3 &
0 < b8 . DataLoc(b1 . b3,b6)
holds (IExec(b2,b8)) . b3 = b8 . b3 &
b2 is_closed_on b8 &
b2 is_halting_on b8 &
(IExec(b2,b8)) . DataLoc(b1 . b3,b6) < b8 . DataLoc(b1 . b3,b6) &
b7 + ((IExec(b2,b8)) . DataLoc(b1 . b3,b6)) <= (IExec(b2,b8)) . b4 &
(IExec(b2,b8)) . b5 = b8 . b5)
holds while>0(b3,b6,b2) is_closed_on b1 &
while>0(b3,b6,b2) is_halting_on b1 &
(b1 . DataLoc(b1 . b3,b6) <= 0 or IExec(while>0(b3,b6,b2),b1) = IExec(while>0(b3,b6,b2),IExec(b2,b1)));
:: SCPQSORT:th 6
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2 being finite programmed initial shiftable No-StopCode Element of sproduct the Object-Kind of SCMPDS
for b3, b4, b5 being Int_position
for b6, b7 being integer set
st 0 < card b2 &
b7 <= b1 . b4 &
(for b8 being Element of product the Object-Kind of SCMPDS
st b7 <= b8 . b4 &
b8 . b5 = b1 . b5 &
b8 . b3 = b1 . b3 &
0 < b8 . DataLoc(b1 . b3,b6)
holds (IExec(b2,b8)) . b3 = b8 . b3 &
b2 is_closed_on b8 &
b2 is_halting_on b8 &
(IExec(b2,b8)) . DataLoc(b1 . b3,b6) < b8 . DataLoc(b1 . b3,b6) &
b7 <= (IExec(b2,b8)) . b4 &
(IExec(b2,b8)) . b5 = b8 . b5)
holds while>0(b3,b6,b2) is_closed_on b1 &
while>0(b3,b6,b2) is_halting_on b1 &
(b1 . DataLoc(b1 . b3,b6) <= 0 or IExec(while>0(b3,b6,b2),b1) = IExec(while>0(b3,b6,b2),IExec(b2,b1)));
:: SCPQSORT:th 7
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2 being finite programmed initial shiftable No-StopCode Element of sproduct the Object-Kind of SCMPDS
for b3, b4, b5, b6, b7 being Int_position
for b8, b9, b10 being integer set
st 0 < card b2 &
b1 . b7 = ((b1 . b6) - b9) + (b1 . b4) &
b10 <= (b1 . b6) - b9 &
(for b11 being Element of product the Object-Kind of SCMPDS
st b11 . b7 = ((b11 . b6) - b9) + (b11 . b4) &
b10 <= (b11 . b6) - b9 &
b11 . b5 = b1 . b5 &
b11 . b3 = b1 . b3 &
0 < b11 . DataLoc(b1 . b3,b8)
holds (IExec(b2,b11)) . b3 = b11 . b3 &
b2 is_closed_on b11 &
b2 is_halting_on b11 &
(IExec(b2,b11)) . DataLoc(b1 . b3,b8) < b11 . DataLoc(b1 . b3,b8) &
(IExec(b2,b11)) . b7 = (((IExec(b2,b11)) . b6) - b9) + ((IExec(b2,b11)) . b4) &
b10 <= ((IExec(b2,b11)) . b6) - b9 &
(IExec(b2,b11)) . b5 = b11 . b5)
holds while>0(b3,b8,b2) is_closed_on b1 &
while>0(b3,b8,b2) is_halting_on b1 &
(b1 . DataLoc(b1 . b3,b8) <= 0 or IExec(while>0(b3,b8,b2),b1) = IExec(while>0(b3,b8,b2),IExec(b2,b1)));
:: SCPQSORT:th 8
theorem
for b1 being FinSequence of INT
for b2, b3, b4, b5 being Element of NAT
st b2 <= b4 &
b4 <= b5 &
b3 = b4 - 1 &
b1 is_non_decreasing_on b2,b3 &
b1 is_non_decreasing_on b4 + 1,b5 &
(for b6 being Element of NAT
st b2 <= b6 & b6 < b4
holds b1 . b6 <= b1 . b4) &
(for b6 being Element of NAT
st b4 < b6 & b6 <= b5
holds b1 . b4 <= b1 . b6)
holds b1 is_non_decreasing_on b2,b5;
:: SCPQSORT:th 9
theorem
for b1, b2 being Relation-like Function-like FinSequence-like set
for b3 being set
st b3 in dom b2 & b1,b2 are_fiberwise_equipotent
holds ex b4 being set st
b4 in dom b2 & b1 . b3 = b2 . b4;
:: SCPQSORT:th 10
theorem
for b1, b2, b3 being Relation-like Function-like FinSequence-like set holds
b1,b2 are_fiberwise_equipotent
iff
b3 ^ b1,b3 ^ b2 are_fiberwise_equipotent;
:: SCPQSORT:th 11
theorem
for b1, b2 being Relation-like Function-like FinSequence-like set
for b3, b4, b5 being Element of NAT
st b1,b2 are_fiberwise_equipotent &
b3 <= b4 &
b4 <= len b1 &
(for b6 being Element of NAT
st 1 <= b6 & b6 <= b3
holds b1 . b6 = b2 . b6) &
(for b6 being Element of NAT
st b4 < b6 & b6 <= len b1
holds b1 . b6 = b2 . b6) &
b3 < b5 &
b5 <= b4
holds ex b6 being Element of NAT st
b3 < b6 & b6 <= b4 & b1 . b5 = b2 . b6;
:: SCPQSORT:funcnot 1 => SCPQSORT:func 1
definition
func Partition -> finite programmed initial Element of sproduct the Object-Kind of SCMPDS equals
((((((((GBP,5):=(GBP,4)) ';' SubFrom(GBP,5,GBP,2)) ';' ((GBP,3):=(GBP,2))) ';' AddTo(GBP,3,1)) ';' while>0(GBP,5,((while>0(GBP,5,(((((GBP,7):=(GBP,5)) ';' AddTo(GBP,5,- 1)) ';' ((GBP,6):=(intpos 4,0))) ';' SubFrom(GBP,6,intpos 2,0)) ';' if>0(GBP,6,(AddTo(GBP,4,- 1)) ';' AddTo(GBP,7,- 1),Load ((GBP,5):= 0)))) ';' while>0(GBP,7,(((((GBP,5):=(GBP,7)) ';' AddTo(GBP,7,- 1)) ';' ((GBP,6):=(intpos 2,0))) ';' SubFrom(GBP,6,intpos 3,0)) ';' if>0(GBP,6,(AddTo(GBP,3,1)) ';' AddTo(GBP,5,- 1),Load ((GBP,7):= 0)))) ';' if>0(GBP,5,((((((GBP,6):=(intpos 4,0)) ';' ((intpos 4,0):=(intpos 3,0))) ';' ((intpos 3,0):=(GBP,6))) ';' AddTo(GBP,5,- 2)) ';' AddTo(GBP,3,1)) ';' AddTo(GBP,4,- 1)))) ';' ((GBP,6):=(intpos 4,0))) ';' ((intpos 4,0):=(intpos 2,0))) ';' ((intpos 2,0):=(GBP,6));
end;
:: SCPQSORT:def 1
theorem
Partition = ((((((((GBP,5):=(GBP,4)) ';' SubFrom(GBP,5,GBP,2)) ';' ((GBP,3):=(GBP,2))) ';' AddTo(GBP,3,1)) ';' while>0(GBP,5,((while>0(GBP,5,(((((GBP,7):=(GBP,5)) ';' AddTo(GBP,5,- 1)) ';' ((GBP,6):=(intpos 4,0))) ';' SubFrom(GBP,6,intpos 2,0)) ';' if>0(GBP,6,(AddTo(GBP,4,- 1)) ';' AddTo(GBP,7,- 1),Load ((GBP,5):= 0)))) ';' while>0(GBP,7,(((((GBP,5):=(GBP,7)) ';' AddTo(GBP,7,- 1)) ';' ((GBP,6):=(intpos 2,0))) ';' SubFrom(GBP,6,intpos 3,0)) ';' if>0(GBP,6,(AddTo(GBP,3,1)) ';' AddTo(GBP,5,- 1),Load ((GBP,7):= 0)))) ';' if>0(GBP,5,((((((GBP,6):=(intpos 4,0)) ';' ((intpos 4,0):=(intpos 3,0))) ';' ((intpos 3,0):=(GBP,6))) ';' AddTo(GBP,5,- 2)) ';' AddTo(GBP,3,1)) ';' AddTo(GBP,4,- 1)))) ';' ((GBP,6):=(intpos 4,0))) ';' ((intpos 4,0):=(intpos 2,0))) ';' ((intpos 2,0):=(GBP,6));
:: SCPQSORT:funcnot 2 => SCPQSORT:func 2
definition
let a1, a2 be Element of NAT;
func QuickSort(A1,A2) -> finite programmed initial Element of sproduct the Object-Kind of SCMPDS equals
((((GBP := 0) ';' (SBP := 1)) ';' ((SBP,a2 + a1):= (a2 + 1))) ';' ((SBP,(a2 + a1) + 1):= (a2 + a1))) ';' while>0(GBP,1,(((GBP,2):=(SBP,(a2 + a1) + 1)) ';' SubFrom(GBP,2,SBP,a2 + a1)) ';' if>0(GBP,2,((((GBP,2):=(SBP,a2 + a1)) ';' ((GBP,4):=(SBP,(a2 + a1) + 1))) ';' Partition) ';' (((((((SBP,(a2 + a1) + 3):=(SBP,(a2 + a1) + 1)) ';' ((SBP,(a2 + a1) + 1):=(GBP,4))) ';' ((SBP,(a2 + a1) + 2):=(GBP,4))) ';' AddTo(SBP,(a2 + a1) + 1,- 1)) ';' AddTo(SBP,(a2 + a1) + 2,1)) ';' AddTo(GBP,1,2)),Load AddTo(GBP,1,- 2)));
end;
:: SCPQSORT:def 2
theorem
for b1, b2 being Element of NAT holds
QuickSort(b1,b2) = ((((GBP := 0) ';' (SBP := 1)) ';' ((SBP,b2 + b1):= (b2 + 1))) ';' ((SBP,(b2 + b1) + 1):= (b2 + b1))) ';' while>0(GBP,1,(((GBP,2):=(SBP,(b2 + b1) + 1)) ';' SubFrom(GBP,2,SBP,b2 + b1)) ';' if>0(GBP,2,((((GBP,2):=(SBP,b2 + b1)) ';' ((GBP,4):=(SBP,(b2 + b1) + 1))) ';' Partition) ';' (((((((SBP,(b2 + b1) + 3):=(SBP,(b2 + b1) + 1)) ';' ((SBP,(b2 + b1) + 1):=(GBP,4))) ';' ((SBP,(b2 + b1) + 2):=(GBP,4))) ';' AddTo(SBP,(b2 + b1) + 1,- 1)) ';' AddTo(SBP,(b2 + b1) + 2,1)) ';' AddTo(GBP,1,2)),Load AddTo(GBP,1,- 2)));
:: SCPQSORT:th 12
theorem
card Partition = 38;
:: SCPQSORT:th 13
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2, b3 being Element of NAT
st b1 . GBP = 0 &
0 < (b1 . intpos 4) - (b1 . intpos 2) &
b1 . intpos 2 = b2 &
b3 + 1 <= b2 &
7 <= b3
holds Partition is_closed_on b1 & Partition is_halting_on b1;
:: SCPQSORT:th 14
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2, b3, b4 being Element of NAT
for b5, b6 being FinSequence of INT
st b1 . GBP = 0 &
0 < (b1 . intpos 4) - (b1 . intpos 2) &
b1 . intpos 2 = b2 &
b3 + 1 <= b2 &
b1 . intpos 4 <= b3 + b4 &
7 <= b3 &
b5 is_FinSequence_on b1,b3 &
len b5 = b4 &
b6 is_FinSequence_on IExec(Partition,b1),b3 &
len b6 = b4
holds (IExec(Partition,b1)) . GBP = 0 &
(IExec(Partition,b1)) . intpos 1 = b1 . intpos 1 &
b5,b6 are_fiberwise_equipotent &
(ex b7 being Element of NAT st
b7 = (IExec(Partition,b1)) . intpos 4 &
b2 <= b7 &
b7 <= b1 . intpos 4 &
(for b8 being Element of NAT
st b2 <= b8 & b8 < b7
holds (IExec(Partition,b1)) . intpos b8 <= (IExec(Partition,b1)) . intpos b7) &
(for b8 being Element of NAT
st b7 < b8 & b8 <= b1 . intpos 4
holds (IExec(Partition,b1)) . intpos b7 <= (IExec(Partition,b1)) . intpos b8) &
(for b8 being Element of NAT
st b3 + 1 <= b8 &
(b1 . intpos 2 <= b8 implies b1 . intpos 4 < b8)
holds (IExec(Partition,b1)) . intpos b8 = b1 . intpos b8));
:: SCPQSORT:th 15
theorem
Partition is No-StopCode & Partition is shiftable;
:: SCPQSORT:th 16
theorem
for b1, b2 being Element of NAT holds
card QuickSort(b1,b2) = 57;
:: SCPQSORT:th 17
theorem
for b1, b2 being Element of NAT
st 7 <= b1
holds QuickSort(b2,b1) is parahalting;
:: SCPQSORT:th 18
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2, b3 being Element of NAT
st 7 <= b2
holds ex b4, b5 being FinSequence of INT st
len b4 = b3 & b4 is_FinSequence_on b1,b2 & len b5 = b3 & b5 is_FinSequence_on IExec(QuickSort(b3,b2),b1),b2 & b4,b5 are_fiberwise_equipotent & b5 is_non_decreasing_on 1,b3;