\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\_3}
\rhead {\rm Page \thepage~of \pageref{LastPage}}
\lfoot{}\cfoot{}\rfoot{}
\pagestyle{fancy}
%---------------------------------------------------------
\begin{document}
\thispagestyle{empty}
\begin{description}
\BTitle{BalTransfer\_3}{23 Apr 2012}{03:56:06 PM}
\MACHINE{BalTransfer\_3}
\cmt{ refined the request and response mechanism for balance transfer }
\REFINES{BalTransfer\_2}
\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{ trans }
		\Item{ sendReqTransfer }
		\Item{ recvReqTransfer }
		\Item{ sendRespTransferOk }
		\Item{ recvRespTransferOk }
		\Item{ sendRespTransferFail }
		\Item{ recvRespTransferFail }
	\end{description}
\INVARIANTS
	\begin{description}
		\nItemX{ inv1 }{ sendReqTransfer \in  \pow(reqTransfer) }
		\nItemX{ inv2 }{ recvReqTransfer \in  \pow(reqTransfer) }
		\nItemX{ inv3 }{ sendRespTransferOk \in  \pow(respTransferOk) }
		\nItemX{ inv4 }{ recvRespTransferOk \in  \pow(respTransferOk) }
		\nItemX{ inv5 }{ sendRespTransferFail \in  \pow(respTransferFail) }
		\nItemX{ inv6 }{ recvRespTransferFail \in  \pow(respTransferFail) }
		\nItemX{ inv7 }{ partition(reqTransfer, sendReqTransfer, recvReqTransfer) }
		\cmt{ reqTransfer = sentReqTransfer $\bunion$  recvReqTransfer }
		\nItemX{ inv8 }{ partition(respTransferOk, sendRespTransferOk, recvRespTransferOk) }
		\nItemX{ inv9 }{ partition(respTransferFail, sendRespTransferFail, recvRespTransferFail) }
	\end{description}
\EVENTS
	\INITIALISATION
		\begin{description}
		\BeginAct
			\begin{description}
			\nItemX{ act1 }{ bal :=  \emptyset  }
			\nItemX{ act2 }{ cardAcct :=  \emptyset  }
			\nItemX{ act4 }{ validCard :=  \emptyset  }
			\nItemX{ act7 }{ cardInAtm :=  \emptyset  }
			\nItemX{ act14 }{ transferOk :=  \emptyset  }
			\nItemX{ act15 }{ transferFail :=  \emptyset  }
			\nItemX{ act18 }{ trAmount :=  \emptyset  }
			\nItemX{ act21 }{ transOkAtm :=  \emptyset  }
			\nItemX{ act22 }{ srcAcc :=  \emptyset  }
			\nItemX{ act23 }{ destAcc :=  \emptyset  }
			\nItemX{ act30 }{ trans :=  \emptyset  }
			\nItemX{ act27 }{ sendReqTransfer :=   \emptyset  }
			\nItemX{ act28 }{ recvReqTransfer :=   \emptyset  }
			\nItemX{ act29 }{ sendRespTransferOk :=   \emptyset  }
			\nItemX{ act24 }{ recvRespTransferOk :=   \emptyset  }
			\nItemX{ act25 }{ sendRespTransferFail :=   \emptyset  }
			\nItemX{ act26 }{ recvRespTransferFail :=   \emptyset  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {SendReqTransfer}
	\REF {ReqTransfer}
		\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 }{ c \in  validCard }
			\nItemX{ grd5 }{ am \in  \nat_1 }
			\nItemX{ grd6 }{ src\_ac \neq  dest\_ac }
			\nItemX{ grd7 }{ a \in  ATM }
			\nItemX{ grd8 }{ a \in  dom(cardInAtm) }
			\nItemX{ grd9 }{ c = cardInAtm(a) }
			\nItemX{ grd11 }{ a \notin  trans }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act2 }{ trAmount(a) :=  am }
			\nItemX{ act3 }{ srcAcc(a) :=  src\_ac }
			\nItemX{ act4 }{ destAcc(a) :=  dest\_ac }
			\nItemX{ act5 }{ trans :=  trans \bunion  \{ a\}  }
			\nItemX{ act6 }{ sendReqTransfer :=  sendReqTransfer \bunion  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {RecvReqTransfer}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd9 }{ a \in  sendReqTransfer }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act4 }{ recvReqTransfer :=  recvReqTransfer \bunion  \{ a\}  }
			\nItemX{ act5 }{ sendReqTransfer :=  sendReqTransfer \setminus  \{ a\}  }
			\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(cardInAtm) }
			\nItemX{ grd12 }{ c = cardInAtm(a) }
			\nItemX{ grd13 }{ a \in  dom(trAmount) }
			\nItemX{ grd20 }{ a \in  dom(srcAcc) }
			\nItemX{ grd21 }{ a \in  dom(destAcc) }
			\nItemX{ grd14 }{ src\_ac = srcAcc(a) }
			\nItemX{ grd15 }{ dest\_ac = destAcc(a) }
			\nItemX{ grd16 }{ am = trAmount(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 {RespTransferOk}
		\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\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {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\}  }
			\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(cardInAtm) }
			\nItemX{ grd12 }{ c = cardInAtm(a) }
			\nItemX{ grd13 }{ a \in  dom(trAmount) }
			\nItemX{ grd21 }{ a \in  dom(destAcc) }
			\nItemX{ grd20 }{ a \in  dom(srcAcc) }
			\nItemX{ grd14 }{ src\_ac = srcAcc(a) }
			\nItemX{ grd15 }{ dest\_ac = destAcc(a) }
			\nItemX{ grd16 }{ am = trAmount(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 {RespTransferFail}
		\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\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {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\}  }
			\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 }
	\REF {Deposit}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ acc }
			\ItemX{ am }
			\ItemX{ c }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd1 }{ acc \in  ACCOUNT }
			\nItemX{ grd2 }{ acc \in  dom(bal) }
			\nItemX{ grd3 }{ am \in  \nat_1 }
			\nItemX{ grd4 }{ c \in  validCard }
			\nItemX{ grd5 }{ c \mapsto  acc \in  cardAcct }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ bal(acc) :=  bal(acc) + am }
			\end{description}
		\EndAct
		\end{description}
\END
\end{description}
\end{document}
