2006-10-26から1日間の記事一覧

演算 () を実現する

VDM++ での演算 () に準拠するように、メソッド VDM_Map.__getitem__ を実現します。class VDM_Map: def __getitem__(m,d): """ m(d) ; map A to B * A -> B ; ; Map apply ; yields the information value whose key is d. d must ; be in the domain of m.…

演算 comp を実現する

VDM++ での演算 comp に準拠するように、メソッド VDM_Map.comp を実現します。class VDM_Map: def comp(m1,m2): """ m1 comp m2 ; map B to C * map A to B -> map A to C ; ; Map composition ; yields the the map that is created by composing m2 ; ele…

事例:演算 comp

VDM++ での演算 comp に準拠した事例(VDM_Map.comp)を紹介します。 m1 = VDM_Map({1:"alpha",2:"beta"}) m2 = VDM_Map({"A":1,"B":2}) print ">>> %s comp %s"%(m1,m2) X = m1.comp(m2) print X; assert X == VDM_Map({"A":"alpha","B":"beta"})2つの写像…

事例:演算 ()

VDM++ での演算 () に準拠した事例(演算子 [])を紹介します。 m = VDM_Map({"A":1,"B":2,"C":3}) d = "C" print ">>> %s(%s)"%(m,d) X = m[d] print X; assert X == 3写像 m において、指定したキー d に対応する値を得るには、演算子 [] を利用します。こ…

演算 ** を実現する

VDM++ での演算 ** に準拠するように、メソッド VDM_Map.__pow__ を実現します。class VDM_Map: def __pow__(m,n): """ m ** n ; (map A to A) * nat -> map A to A ; ; Map iteration ; yields the map where m is composed with itself ; n times. n=0 yie…

事例:演算 **

VDM++ での演算 ** に準拠した事例(演算子 **)を紹介します。 m = VDM_Map({1:2,2:3,3:4,4:1}) n = 2 print ">>> %s ** %s"%(m,n) X = m ** n print X; assert X == VDM_Map({1:3,2:4,3:1,4:2})同一写像を繰り返し適用した写像を得るには、演算子 ** を利…

写像の適用

VDM++ の map 型には、写像の適用を定義できます。VDM++ では、次のように表現します。 {'A' |-> 1, 'B' |-> 2, 'C' |-> 3}('C') = 3この写像にキー 'C' を適用した値は 3 になります。ただし、指定したキーは、定義域に含まれるものとします。 {1 |-> "alph…

VDM++《19》Map に対する演算(4)

Shall_we_Agile = Java.use(better, Python) # Swing by VDM++《記事一覧》 改訂♪2008/09/14《承前》