\subsection{Sequence}
\subsubsection{Responsibility}
I am a Sequence.
\subsubsection{Abstract}
I define functionsnotin Sequence type operand.
\subsubsection{note} By historical reason, there are functional style functionsand non functional style functions. Functions which name starts capital letters is functional style. If there are same name functions, the lower-case letter`s function is the old function.
Many offunctions are from functional programming language libraries.
static SumAux[@T] : seqof @T -> @T -> @T
SumAux(s)(sum) == if is_(s,seqofreal) and is_real(sum) then if s = [] then
sum else
SumAux[@T](tl s)(sum + hd s) elseundefined; --measure length_measure;
static ProductAux[@T] : seqof @T -> @T -> @T
ProductAux(s)(p) == if is_(s,seqofreal) and is_real(p) then cases s :
[h] ^ tail -> ProductAux[@T](tail)(p * h),
[] -> p end elseundefined; --measure length_measure;
staticpublic GetAverage[@T]: seqof @T -> [real]
GetAverage(s) == if s = [] thennilelse GetAverageAux[@T](s)(0)(len s);
static GetAverageAux[@T] : seqof @T -> @T -> @T -> real
GetAverageAux(s)(sum)(numberOfElem) == if is_(s,seqofreal) and is_real(sum) and is_real(numberOfElem) then cases s :
[h] ^ tail -> GetAverageAux[@T](tail)(sum + h)(numberOfElem),
[] -> sum / numberOfElem end elseundefined; --measure length_measure;
staticpublic isAscendingTotalOrder [@T]:
(@T * @T -> bool) -> seqof @T -> bool
isAscendingTotalOrder (decideOrderFunc)(s) == forall i,j insetinds s & i < j => decideOrderFunc(s(i),s(j)) or s(i) = s(j);
staticpublic isDescendingTotalOrder [@T]:
(@T * @T -> bool) -> seqof @T -> bool
isDescendingTotalOrder (decideOrderFunc)(s) == forall i,j insetinds s & i < j => decideOrderFunc(s(j),s(i)) or s(i) = s(j);
staticpublic isAscendingOrder [@T]: seqof @T -> bool
isAscendingOrder(s) ==
isAscendingTotalOrder [@T](lambda x : @T, y : @T & if is_real(x) and is_real(y) then x < y elseundefined)(s);
staticpublic isDescendingOrder[@T]: seqof @T -> bool
isDescendingOrder(s) ==
isDescendingTotalOrder [@T](lambda x : @T, y : @T & if is_real(x) and is_real(y) then x < y elseundefined)(s);
staticpublic ascendingOrderSort[@T] : seqof @T -> seqof @T
ascendingOrderSort(s) == sort[@T](lambda x : @T, y : @T & if is_real(x) and is_real(y) then x < y elseundefined)(s);
staticpublic descendingOrderSort[@T] : seqof @T -> seqof @T
descendingOrderSort(s) == sort[@T](lambda x : @T, y : @T & if is_real(x) and is_real(y) then x > y elseundefined)(s);
staticpublic Index[@T]: @T -> seqof @T -> int
Index(e)(s) == let i = 0 in IndexAux[@T](e)(s)(i);
static IndexAux[@T]: @T -> seqof @T -> int -> int
IndexAux(e)(s)(indx) == cases s:
[] -> 0,
[x]^xs -> if x = e then
indx + 1 else
IndexAux[@T](e)(xs)(indx+1) end;
staticpublic IndexAll2[@T] : @T -> seqof @T -> setofint
IndexAll2(e)(s) == {i | i insetinds s & s(i) = e};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.