Below are definitions TLA+ operators that convert a set of integers into a sorted sequence. You can take the first N elements of SortedSeqFromSet(Range(f)) to retrieve the N smallest values of the function f. Evaluation of these operators still requires quadratic time, and although you could write a Quicksort operator in TLA+, if you really care about efficiency you should probably consider overriding the definition of SortedSeqFromSet(_) by a Java method. Best, Stephan RECURSIVE InsertSorted(_,_,_), SortedSeqFromSet(_) InsertSorted(x, seq, i) == \* insert element in a sorted sequence of integers, starting from index i IF i > Len(seq) THEN seq \o << x >> ELSE IF x <= seq[i] THEN SubSeq(seq, 1, i-1) \o << x >> \o SubSeq(seq, i, Len(seq)) ELSE InsertSorted(x, seq, i+1) SortedSeqFromSet(S) == \* convert a set of integers into a sorted sequence IF S = {} THEN << >> ELSE LET x == CHOOSE x \in S : TRUE rest == SortedSeqFromSet(S \ {x}) IN InsertSorted(x, rest, 1)
You received this message because you are subscribed to the Google Groups "tlaplus" group. To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+unsubscribe@xxxxxxxxxxxxxxxx. To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/826397D5-5C3D-42AF-A560-B019523B5411%40gmail.com. |