Sumは列sの要素の合計を返す。
\begin{vdm_al} staticpublic Sum[@T] : seqof @T -> @T
Sum(s) == Foldl[@T, @T](Plus[@T])(0)(s) pre
is_(s, seqofint) or is_(s, seqofnat) or is_(s, seqofnat1) or
is_(s, seqofreal) or is_(s, seqofrat);
\end{vdm_al}
Prodは列sの全要素の積を返す。
\begin{vdm_al} staticpublic Prod[@T] : seqof @T -> @T
Prod(s) == Foldl[@T, @T](Product[@T])(1)(s) pre
is_(s, seqofint) or is_(s, seqofnat) or is_(s, seqofnat1) or
is_(s, seqofreal) or is_(s, seqofrat);
\end{vdm_al}
Plusは加算を行う。
\begin{vdm_al} staticpublic Plus[@T] : @T -> @T -> @T
Plus(a)(b) == if is_real(a) and is_real(b) then a + b elseundefined;
\end{vdm_al}
Productは積算を行う。
\begin{vdm_al} staticpublic Product[@T] : @T -> @T -> @T
Product(a)(b) == if is_real(a) and is_real(b) then a * b elseundefined;
\end{vdm_al}
Averageは列sの要素の平均を求める。
\begin{vdm_al} staticpublic Average[@T]: seqof @T -> [real]
Average(s) == if s = [] thennilelse AverageAux[@T](0)(0)(s) post if s = [] then RESULT = nil elselet sum = Sum[@T](s) in RESULT = if is_real(sum) then sum / len s elseundefined;
static AverageAux[@T] : @T -> @T -> seqof @T -> real
AverageAux(total)(numOfElem)(s) == if is_(s,seqofreal) and is_real(total) and is_real(numOfElem) then cases s :
[x] ^ xs -> AverageAux[@T](total + x)(numOfElem + 1)(xs),
[] -> total / numOfElem end elseundefined;
\end{vdm_al}
IsAscendingは、演算子<で与えられた全順序で、列sの要素が昇順であるか否かを返す。
\begin{vdm_al} staticpublic IsAscending [@T]: seqof @T -> bool
IsAscending(s) ==
IsAscendingInTotalOrder[@T](lambda x : @T, y : @T & if is_real(x) and is_real(y) then x < y elseundefined)(s);
\end{vdm_al}
IsDescendingは、演算子<で与えられた全順序で、列sの要素が降順であるか否かを返す。
\begin{vdm_al} staticpublic IsDescending[@T]: seqof @T -> bool
IsDescending(s) ==
IsDescendingInTotalOrder[@T](lambda x : @T, y : @T & if is_real(x) and is_real(y) then x < y elseundefined)(s);
\end{vdm_al}
AscendingSortは、演算子<で与えられた順序で、列sの要素を昇順にソートする。
\begin{vdm_al} staticpublic AscendingSort[@T] : seqof @T -> seqof @T
AscendingSort(s) == Sort[@T](lambda x : @T, y : @T & if is_real(x) and is_real(y) then x < y elseundefined)(s) post
IsAscending[@T](RESULT);
\end{vdm_al}
DescendingSortは、演算子>で与えられた順序で、列sの要素を昇順にソートする。
演算子<から見れば降順。
\begin{vdm_al} staticpublic DescendingSort[@T] : seqof @T -> seqof @T
DescendingSort(s) == Sort[@T](lambda x : @T, y : @T & if is_real(x) and is_real(y) then x > y elseundefined)(s) post
IsDescending[@T](RESULT);
\end{vdm_al}
IsDupは、列s中に同じ要素があるか否かを返す。
\begin{vdm_al} staticpublic IsDup[@T] : seqof @T -> bool
IsDup(s) == notcardelems s = len s post if s = [] then RESULT = false else RESULT = notforall i, j insetinds s & s(i) <> s(j) <=> i <> j ;
\end{vdm_al}
Indexは、指定された要素eが列sの何番目にあるかを返す。最初の要素の位置を返す。
\begin{vdm_al} staticpublic Index[@T]: @T -> seqof @T -> int
Index(e)(s) == let i = 0 in
IndexAux[@T](e)(s)(i);
staticpublic IndexAux[@T] : @T -> seqof @T -> int -> int
IndexAux(e)(s)(i) == cases s:
[] -> 0,
[x]^xs -> if x = e then
i + 1 else
IndexAux[@T](e)(xs)(i+1) end;
\end{vdm_al}
¤ 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.0.14Bemerkung:
(vorverarbeitet)
¤
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.