\documentclass[10pt,a4paper]{report}
\usepackage[top=3cm, bottom=2.5cm, left=3cm, right=2.5cm] {geometry}
\usepackage {bsymb,b2latex}
\usepackage{fancyhdr,lastpage,color}
\lhead{\rm An Event-B Specification of BalTransfer\_4}
\rhead {\rm Page \thepage~of \pageref{LastPage}}
\lfoot{}\cfoot{}\rfoot{}
\pagestyle{fancy}
%---------------------------------------------------------
\begin{document}
\thispagestyle{empty}
\begin{description}
\BTitle{BalTransfer\_4}{30 Aug 2012}{08:17:20 PM}
\MACHINE{BalTransfer\_4}
\cmt{ introduced MW between ATM and Bank }
\REFINES{BalTransfer\_3}
\SEES{BalTransfer\_CO1}
\VARIABLES
	\begin{description}
		\Item{ bal }
		\bcmt{ Shared variable, DO NOT REFINE }
		\Item{ validCard }
		\bcmt{ Shared variable, DO NOT REFINE }
		\Item{ cardAcct }
		\bcmt{ Shared variable, DO NOT REFINE }
		\Item{ cardInAtm }
		\Item{ transferOk }
		\Item{ transferFail }
		\Item{ trAmount }
		\Item{ transOkAtm }
		\Item{ srcAcc }
		\Item{ destAcc }
		\Item{ sendReqTransfer }
		\Item{ recvReqTransfer }
		\Item{ sendRespTransferOk }
		\Item{ recvRespTransferOk }
		\Item{ sendRespTransferFail }
		\Item{ recvRespTransferFail }
		\Item{ trAmountM }
		\Item{ trans }
		\Item{ trAmountB }
		\Item{ srcAccM }
		\Item{ destAccM }
		\Item{ srcAccB }
		\Item{ destAccB }
		\Item{ cardInAtmM }
		\Item{ cardInAtmB }
	\end{description}
\INVARIANTS
	\begin{description}
		\nItemX{ inv2 }{ cardInAtmM \in  ATM \pfun  CARD }
		\cmt{ sendReqTransfer $:=$  sendReqTransfer $\bunion$  $\{$ a$\}$  }
		\nItemX{ inv3 }{ trAmountM \in  ATM \pfun  \nat_1 }
		\nItemX{ inv21 }{ srcAccM \in  ATM \pfun  ACCOUNT }
		\nItemX{ inv22 }{ destAccM \in  ATM \pfun  ACCOUNT }
		\nItemX{ inv23 }{ srcAccB \in  ATM \pfun  ACCOUNT }
		\nItemX{ inv24 }{ destAccB \in  ATM \pfun  ACCOUNT }
		\nItemX{ inv5 }{ cardInAtmB \in  ATM \pfun  CARD }
		\nItemX{ inv6 }{ trAmountB \in  ATM \pfun  \nat_1 }
		\nItemX{ inv12 }{ \forall a \qdot  a \in  dom(trAmountM) \limp   a \in  dom(trAmount) \land  trAmountM(a) = trAmount(a) }
		\nItemX{ inv13 }{ \forall a \qdot  a \in  recvReqTransfer \land  a \in  dom(trAmountB) \limp  a \in  dom(trAmountM) \land  trAmountB(a) = trAmountM(a)  }
		\nItemX{ inv25 }{ \forall a \qdot  a \in  dom(srcAccM) \limp   a \in  dom(srcAcc) \land  srcAccM(a) = srcAcc(a) }
		\nItemX{ inv17 }{ \forall a \qdot  a \in  recvReqTransfer \land  a \in  dom(srcAccB) \limp   a \in  dom(srcAccM) \land  srcAccB(a) = srcAccM(a) }
		\nItemX{ inv26 }{ \forall a \qdot  a \in  dom(destAccM) \limp   a \in  dom(destAcc) \land  destAccM(a) = destAcc(a) }
		\nItemX{ inv18 }{ \forall a \qdot  a \in  recvReqTransfer \land  a \in  dom(destAccB) \limp   a \in  dom(destAccM) \land  destAccB(a) = destAccM(a) }
		\nItemX{ inv27 }{ \forall a \qdot  a \in  dom(cardInAtmM) \limp  a \in  dom(cardInAtm) \land  cardInAtmM(a) = cardInAtm(a) }
		\nItemX{ inv28 }{ \forall a \qdot  a \in  recvReqTransfer \land  a \in  dom(cardInAtmB) \limp  a \in  dom(cardInAtm) \land  cardInAtmB(a) = cardInAtm(a) }
		\nItemX{ inv29 }{ \forall a\qdot a\in dom(cardInAtmB)\limp a\in dom(cardInAtm) }
	\end{description}
\EVENTS
	\INITIALISATION
		\\\textit{extended}
		\begin{description}
		\BeginAct
			\begin{description}
			\nItem{ act1 }{ bal :=  \emptyset  }
			\nItem{ act2 }{ cardAcct :=  \emptyset  }
			\nItem{ act4 }{ validCard :=  \emptyset  }
			\nItem{ act7 }{ cardInAtm :=  \emptyset  }
			\nItem{ act14 }{ transferOk :=  \emptyset  }
			\nItem{ act15 }{ transferFail :=  \emptyset  }
			\nItem{ act18 }{ trAmount :=  \emptyset  }
			\nItem{ act21 }{ transOkAtm :=  \emptyset  }
			\nItem{ act22 }{ srcAcc :=  \emptyset  }
			\nItem{ act23 }{ destAcc :=  \emptyset  }
			\nItem{ act30 }{ trans :=  \emptyset  }
			\nItem{ act27 }{ sendReqTransfer :=   \emptyset  }
			\nItem{ act28 }{ recvReqTransfer :=   \emptyset  }
			\nItem{ act29 }{ sendRespTransferOk :=   \emptyset  }
			\nItem{ act24 }{ recvRespTransferOk :=   \emptyset  }
			\nItem{ act25 }{ sendRespTransferFail :=   \emptyset  }
			\nItem{ act26 }{ recvRespTransferFail :=   \emptyset  }
			\nItemX{ act36 }{ cardInAtmM :=  \emptyset  }
			\nItemX{ act38 }{ trAmountM :=  \emptyset  }
			\nItemX{ act31 }{ cardInAtmB :=  \emptyset  }
			\nItemX{ act32 }{ trAmountB :=  \emptyset  }
			\nItemX{ act40 }{ srcAccM :=  \emptyset  }
			\nItemX{ act41 }{ destAccM:=  \emptyset  }
			\nItemX{ act42 }{ srcAccB:=  \emptyset  }
			\nItemX{ act43 }{ destAccB  :=  \emptyset  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {SendReqTransfer}
	\REF {SendReqTransfer}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ c }
			\ItemX{ src\_ac }
			\ItemX{ dest\_ac }
			\ItemX{ am }
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd1 }{ src\_ac \in  ACCOUNT }
			\nItemX{ grd2 }{ dest\_ac \in  ACCOUNT }
			\nItemX{ grd3 }{ am \in  \nat_1 }
			\nItemX{ grd5 }{ src\_ac \neq  dest\_ac }
			\nItemX{ grd4 }{ c \in  validCard }
			\nItemX{ grd7 }{ a \mapsto  c \in  cardInAtm }
			\nItemX{ grd8 }{ a \in  ATM }
			\nItemX{ grd11 }{ a \notin  trans }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ sendReqTransfer :=  sendReqTransfer \bunion  \{ a\}  }
			\nItemX{ act2 }{ trAmount(a) :=  am }
			\nItemX{ act3 }{ srcAcc(a) :=  src\_ac }
			\nItemX{ act4 }{ destAcc(a) :=  dest\_ac }
			\nItemX{ act6 }{ trAmountM(a) :=  am }
			\nItemX{ act7 }{ srcAccM(a) :=  src\_ac }
			\nItemX{ act8 }{ destAccM(a) :=  dest\_ac }
			\nItemX{ act10 }{ cardInAtmM(a) :=  c }
			\nItemX{ act11 }{ trans :=  trans \bunion  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {RecvReqTransfer}
	\REF {RecvReqTransfer}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\ItemX{ am }
			\ItemX{ c }
			\ItemX{ src\_ac }
			\ItemX{ dest\_ac }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd1 }{ a \in  sendReqTransfer }
			\nItemX{ grd2 }{ a \in  dom(trAmountM) }
			\nItemX{ grd3 }{ am = trAmountM(a) }
			\nItemX{ grd5 }{ a \mapsto  c \in  cardInAtmM }
			\nItemX{ grd8 }{ a \in  dom(srcAccM) }
			\nItemX{ grd9 }{ a \in  dom(destAccM) }
			\nItemX{ grd6 }{ srcAccM(a) = src\_ac }
			\nItemX{ grd7 }{ destAccM(a) = dest\_ac }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act4 }{ recvReqTransfer :=  recvReqTransfer \bunion  \{ a\}  }
			\nItemX{ act5 }{ sendReqTransfer :=  sendReqTransfer \setminus  \{ a\}  }
			\nItemX{ act6 }{ trAmountB(a) :=  am }
			\nItemX{ act8 }{ cardInAtmB(a) :=  c }
			\nItemX{ act9 }{ srcAccB(a) :=  src\_ac }
			\nItemX{ act10 }{ destAccB(a) :=  dest\_ac }
			\end{description}
		\EndAct
		\end{description}
	\EVT {TransferOK}
	\REF {TransferOK}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ src\_ac }
			\ItemX{ dest\_ac }
			\ItemX{ am }
			\ItemX{ c }
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd1 }{ src\_ac \in  ACCOUNT }
			\nItemX{ grd2 }{ dest\_ac \in  ACCOUNT }
			\nItemX{ grd4 }{ c \mapsto  src\_ac \in  cardAcct }
			\nItemX{ grd5 }{ am \in  \nat_1 }
			\nItemX{ grd6 }{ src\_ac \in  dom(bal) }
			\nItemX{ grd7 }{ dest\_ac \in  dom(bal) }
			\nItemX{ grd8 }{ src\_ac \neq  dest\_ac }
			\nItemX{ grd9 }{ am \leq  bal(src\_ac) }
			\nItemX{ grd11 }{ a \in  dom(cardInAtmB) }
			\nItemX{ grd12 }{ c = cardInAtmB(a) }
			\nItemX{ grd13 }{ a \in  dom(trAmountB) }
			\nItemX{ grd20 }{ a \in  dom(srcAccB) }
			\nItemX{ grd21 }{ a \in  dom(destAccB) }
			\nItemX{ grd14 }{ src\_ac = srcAccB(a) }
			\nItemX{ grd15 }{ dest\_ac = destAccB(a) }
			\nItemX{ grd16 }{ am = trAmountB(a) }
			\nItemX{ grd24 }{ a \in  recvReqTransfer }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ bal :=   bal \ovl  \{ dest\_ac \mapsto  (bal(dest\_ac) + am), src\_ac \mapsto (bal(src\_ac) -  am)\}  }
			\nItemX{ act5 }{ transferOk :=  transferOk \bunion  \{ a\}  }
			\nItemX{ act6 }{ recvReqTransfer :=  recvReqTransfer \setminus  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {SendRespTransferOk}
	\REF {SendRespTransferOk}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd2 }{ a \in  transferOk }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act2 }{ transferOk :=   transferOk \setminus  \{ a\}  }
			\nItemX{ act3 }{ sendRespTransferOk :=   sendRespTransferOk \bunion  \{ a\}  }
			\nItemX{ act9 }{ trAmountB :=  \{ a\}  \domsub  trAmountB }
			\nItemX{ act11 }{ cardInAtmB :=  \{ a\}  \domsub  cardInAtmB }
			\nItemX{ act12 }{ srcAccB :=   \{ a\}  \domsub  srcAccB }
			\nItemX{ act13 }{ destAccB :=   \{ a\}  \domsub  destAccB }
			\end{description}
		\EndAct
		\end{description}
	\EVT {RecvRespTransferOk}
	\REF {RecvRespTransferOk}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd1 }{ a \in  sendRespTransferOk }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ recvRespTransferOk :=   recvRespTransferOk \bunion  \{ a\}  }
			\nItemX{ act2 }{ sendRespTransferOk :=   sendRespTransferOk \setminus  \{ a\}  }
			\nItemX{ act9 }{ trAmountM :=  \{ a\}  \domsub  trAmountM }
			\nItemX{ act11 }{ cardInAtmM :=  \{ a\}  \domsub  cardInAtmM }
			\nItemX{ act12 }{ srcAccM :=   \{ a\}  \domsub  srcAccM }
			\nItemX{ act13 }{ destAccM :=   \{ a\}  \domsub  destAccM }
			\end{description}
		\EndAct
		\end{description}
	\EVT {TransferFails}
	\REF {TransferFails}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ src\_ac }
			\ItemX{ dest\_ac }
			\ItemX{ am }
			\ItemX{ c }
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd1 }{ src\_ac \in  ACCOUNT }
			\nItemX{ grd2 }{ dest\_ac \in  ACCOUNT }
			\nItemX{ grd5 }{ am \in  \nat_1 }
			\nItemX{ grd6 }{ src\_ac \in  dom(bal) }
			\nItemX{ grd7 }{ dest\_ac \in  dom(bal) }
			\nItemX{ grd8 }{ src\_ac \neq  dest\_ac }
			\nItemX{ grd9 }{ am >  bal(src\_ac) \lor   c \mapsto  src\_ac \notin  cardAcct }
			\nItemX{ grd11 }{ a \in  dom(cardInAtmB) }
			\nItemX{ grd12 }{ c = cardInAtmB(a) }
			\nItemX{ grd13 }{ a \in  dom(trAmountB) }
			\nItemX{ grd21 }{ a \in  dom(destAccB) }
			\nItemX{ grd20 }{ a \in  dom(srcAccB) }
			\nItemX{ grd14 }{ src\_ac = srcAccB(a) }
			\nItemX{ grd15 }{ dest\_ac = destAccB(a) }
			\nItemX{ grd16 }{ am = trAmountB(a) }
			\nItemX{ grd22 }{ a \in  recvReqTransfer }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act2 }{ transferFail :=   transferFail \bunion  \{ a\}  }
			\nItemX{ act3 }{ recvReqTransfer :=  recvReqTransfer \setminus  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {SendRespTransferFail}
	\REF {SendRespTransferFail}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd2 }{ a \in  transferFail }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act2 }{ transferFail :=   transferFail \setminus  \{ a\}  }
			\nItemX{ act3 }{ sendRespTransferFail :=   sendRespTransferFail \bunion  \{ a\}  }
			\nItemX{ act9 }{ trAmountB :=  \{ a\}  \domsub  trAmountB }
			\nItemX{ act11 }{ cardInAtmB :=  \{ a\}  \domsub  cardInAtmB }
			\nItemX{ act12 }{ srcAccB :=   \{ a\}  \domsub  srcAccB }
			\nItemX{ act13 }{ destAccB :=   \{ a\}  \domsub  destAccB }
			\end{description}
		\EndAct
		\end{description}
	\EVT {RecvRespTransferFail}
	\REF {RecvRespTransferFail}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd1 }{ a \in  sendRespTransferFail }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ recvRespTransferFail :=   recvRespTransferFail \bunion  \{ a\}  }
			\nItemX{ act2 }{ sendRespTransferFail :=   sendRespTransferFail \setminus  \{ a\}  }
			\nItemX{ act9 }{ trAmountM :=  \{ a\}  \domsub  trAmountM }
			\nItemX{ act11 }{ cardInAtmM :=  \{ a\}  \domsub  cardInAtmM }
			\nItemX{ act12 }{ srcAccM :=   \{ a\}  \domsub  srcAccM }
			\nItemX{ act13 }{ destAccM :=   \{ a\}  \domsub  destAccM }
			\end{description}
		\EndAct
		\end{description}
	\EVT {TransferOKAtm}
	\REF {TransferOKAtm}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd11 }{ a \in  recvRespTransferOk }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ transOkAtm(a) :=   TRUE }
			\nItemX{ act7 }{ trans :=  trans \setminus  \{ a\}  }
			\nItemX{ act6 }{ recvRespTransferOk :=  recvRespTransferOk \setminus  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {TransferFailsAtm}
	\REF {TransferFailsAtm}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd11 }{ a \in  recvRespTransferFail }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ transOkAtm(a) :=   FALSE }
			\nItemX{ act7 }{ trans :=  trans \setminus  \{ a\}  }
			\nItemX{ act6 }{ recvRespTransferFail :=  recvRespTransferFail \setminus  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {Deposit}
	\cmt{ External event, DO NOT REFINE }
	\EXTD {Deposit}
		\begin{description}
		\AnyPrm
			\begin{description}
			\Item{ acc }
			\Item{ am }
			\Item{ c }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItem{ grd1 }{ acc \in  ACCOUNT }
			\nItem{ grd2 }{ acc \in  dom(bal) }
			\nItem{ grd3 }{ am \in  \nat_1 }
			\nItem{ grd4 }{ c \in  validCard }
			\nItem{ grd5 }{ c \mapsto  acc \in  cardAcct }
			\end{description}
		\ThenAct
			\begin{description}
			\nItem{ act1 }{ bal(acc) :=  bal(acc) + am }
			\end{description}
		\EndAct
		\end{description}
\END
\end{description}
\end{document}
