\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\_2}
\rhead {\rm Page \thepage~of \pageref{LastPage}}
\lfoot{}\cfoot{}\rfoot{}
\pagestyle{fancy}
%---------------------------------------------------------
\begin{document}
\thispagestyle{empty}
\begin{description}
\BTitle{BalTransfer\_2}{23 Apr 2012}{03:56:06 PM}
\MACHINE{BalTransfer\_2}
\cmt{ introduce request and response mechanism bw atm and bank for balance transfer }
\REFINES{BalTransfer\_1}
\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{ reqTransfer }
		\Item{ transferOk }
		\Item{ transferFail }
		\Item{ cardInAtm }
		\Item{ respTransferOk }
		\Item{ respTransferFail }
		\Item{ srcAccBalAtm }
		\Item{ destAccBalAtm }
		\Item{ trAmount }
		\Item{ transOkAtm }
		\Item{ srcAcc }
		\Item{ destAcc }
		\Item{ trans }
	\end{description}
\INVARIANTS
	\begin{description}
		\nItemX{ inv1 }{ trans \in  \pow(ATM) }
		\nItemX{ inv3 }{ reqTransfer \in  \pow(trans) }
		\nItemX{ inv6 }{ respTransferOk \in  \pow(trans) }
		\nItemX{ inv7 }{ respTransferFail \in  \pow(trans) }
		\nItemX{ inv8 }{ trAmount \in  ATM \pfun  \nat_1 }
		\nItemX{ inv9 }{ srcAccBalAtm \in  ACCOUNT \pfun  \nat }
		\nItemX{ inv10 }{ destAccBalAtm \in  ACCOUNT \pfun  \nat }
		\nItemX{ inv11 }{ transOkAtm \in  ATM \pfun  BOOL }
		\nItemX{ inv12 }{ srcAcc \in  ATM \pfun  ACCOUNT }
		\nItemX{ inv13 }{ destAcc \in  ATM \pfun  ACCOUNT }
		\nItemX{ inv15 }{ transferOk \subseteq transferOkA }
		\nItemX{ inv16 }{ transferFail \subseteq transferFailA }
		\nItemX{ inv17 }{ \forall  c \qdot  c \in  ran(cardInAtm) \limp  c \in  validCard }
		\nItemX{ inv18 }{ partition(trans, reqTransfer, transferOk, transferFail, respTransferOk, respTransferFail) }
	\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{ act13 }{ reqTransfer :=  \emptyset  }
			\nItemX{ act14 }{ transferOk :=  \emptyset  }
			\nItemX{ act15 }{ transferFail :=  \emptyset  }
			\nItemX{ act16 }{ respTransferOk :=  \emptyset  }
			\nItemX{ act17 }{ respTransferFail :=  \emptyset  }
			\nItemX{ act18 }{ trAmount :=  \emptyset  }
			\nItemX{ act19 }{ srcAccBalAtm :=  \emptyset  }
			\nItemX{ act20 }{ destAccBalAtm :=  \emptyset  }
			\nItemX{ act21 }{ transOkAtm :=  \emptyset  }
			\nItemX{ act22 }{ srcAcc :=  \emptyset  }
			\nItemX{ act23 }{ destAcc :=  \emptyset  }
			\nItemX{ act24 }{ trans :=  \emptyset  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {ReqTransfer}
	\cmt{ event for ATM }
		\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{ grd8 }{ a \in  dom(cardInAtm) }
			\nItemX{ grd9 }{ c = cardInAtm(a) }
			\nItemX{ grd10 }{ a \notin  trans }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ reqTransfer :=   reqTransfer \bunion  \{ a\}  }
			\nItemX{ act2 }{ trAmount(a) :=  am }
			\nItemX{ act3 }{ srcAcc(a) :=  src\_ac }
			\nItemX{ act4 }{ destAcc(a) :=  dest\_ac }
			\nItemX{ act5 }{ trans :=  trans \bunion  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {TransferOK}
	\cmt{ event for Bank }
	\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{ grd17 }{ a \in  reqTransfer }
			\nItemX{ grd18 }{ \btrue   }
			\cmt{ a $\notin$  transferFail }
			\nItemX{ grd19 }{ \btrue   }
			\cmt{ a $\notin$  transferOk }
			\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 }{ reqTransfer :=  reqTransfer \setminus  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {RespTransferOk}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd2 }{ a \in  transferOk }
			\nItemX{ grd3 }{ a \notin  transferFail }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ respTransferOk :=   respTransferOk \bunion  \{ a\}  }
			\nItemX{ act2 }{ transferOk :=   transferOk \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{ grd17 }{ a \in  reqTransfer }
			\nItemX{ grd18 }{ a \notin  transferFail }
			\nItemX{ grd19 }{ a \notin  transferOk }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act2 }{ transferFail :=   transferFail \bunion  \{ a\}  }
			\nItemX{ act3 }{ reqTransfer :=  reqTransfer \setminus  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {RespTransferFail}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd2 }{ a \in  transferFail }
			\nItemX{ grd3 }{ a \notin  transferOk }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ respTransferFail :=   respTransferFail \bunion  \{ a\}  }
			\nItemX{ act2 }{ transferFail :=   transferFail \setminus  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {TransferOKAtm}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd8 }{ a \in  respTransferOk }
			\nItemX{ grd9 }{ a \notin  respTransferFail }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ transOkAtm(a) :=   TRUE }
			\nItemX{ act5 }{ respTransferOk :=  respTransferOk \setminus  \{ a\}  }
			\nItemX{ act6 }{ trans :=  trans \setminus  \{ a\}  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {TransferFailsAtm}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ grd8 }{ a \in  respTransferFail }
			\nItemX{ grd9 }{ a \notin  respTransferOk }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act1 }{ transOkAtm(a) :=   FALSE }
			\nItemX{ act5 }{ respTransferFail :=  respTransferFail \setminus  \{ a\}  }
			\nItemX{ act6 }{ trans :=  trans \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}
