\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 mBank\_T}
\rhead {\rm Page \thepage~of \pageref{LastPage}}
\lfoot{}\cfoot{}\rfoot{}
\pagestyle{fancy}
%---------------------------------------------------------
\begin{document}
\thispagestyle{empty}
\begin{description}
\BTitle{mBank\_T}{25 Jun 2012}{04:14:47 PM}
\MACHINE{mBank\_T}
\SEES{Context\_mBank\_T}
\VARIABLES
	\begin{description}
		\Item{ bal }
		\Item{ cardAcct }
		\Item{ transferOk }
		\Item{ transferFail }
		\Item{ trAmountB }
		\Item{ cardInAtmB }
		\Item{ srcAccB }
		\Item{ destAccB }
		\Item{ recvReqTransfer }
	\end{description}
\INVARIANTS
	\begin{description}
		\nItemX{ typing\_srcAccB }{ srcAccB \in  \pow(ATM \cprod  ACCOUNT) }
		\nItemX{ typing\_recvReqTransfer }{ recvReqTransfer \in  \pow(ATM) }
		\nItemX{ typing\_bal }{ bal \in  \pow(ACCOUNT \cprod  \intg ) }
		\nItemX{ typing\_transferOk }{ transferOk \in  \pow(ATM) }
		\nItemX{ typing\_cardInAtmB }{ cardInAtmB \in  \pow(ATM \cprod  CARD) }
		\nItemX{ typing\_transferFail }{ transferFail \in  \pow(ATM) }
		\nItemX{ typing\_destAccB }{ destAccB \in  \pow(ATM \cprod  ACCOUNT) }
		\nItemX{ typing\_trAmountB }{ trAmountB \in  \pow(ATM \cprod  \intg ) }
		\nItemX{ typing\_cardAcct }{ cardAcct \in  \pow(CARD \cprod  ACCOUNT) }
		\nItemX{ BalTransfer\_0\_IntegralATM\_0\_inv1 }{ bal \in  ACCOUNT \pfun  \nat }
		\nItemX{ BalTransfer\_0\_IntegralATM\_0\_inv2 }{ cardAcct \in  CARD \pfun  ACCOUNT }
		\nItemX{ BalTransfer\_4\_inv23 }{ srcAccB \in  ATM \pfun  ACCOUNT }
		\nItemX{ BalTransfer\_4\_inv24 }{ destAccB \in  ATM \pfun  ACCOUNT }
		\nItemX{ BalTransfer\_4\_inv5 }{ cardInAtmB \in  ATM \pfun  CARD }
		\nItemX{ BalTransfer\_4\_inv6 }{ trAmountB \in  ATM \pfun  \nat_1 }
	\end{description}
\EVENTS
	\INITIALISATION
		\begin{description}
		\BeginAct
			\begin{description}
			\nItemX{ act1 }{ bal :=  \emptyset  }
			\nItemX{ act2 }{ cardAcct :=  \emptyset  }
			\nItemX{ act14 }{ transferOk :=  \emptyset  }
			\nItemX{ act15 }{ transferFail :=  \emptyset  }
			\nItemX{ act28 }{ recvReqTransfer :=   \emptyset  }
			\nItemX{ act31 }{ cardInAtmB :=  \emptyset  }
			\nItemX{ act32 }{ trAmountB :=  \emptyset  }
			\nItemX{ act42 }{ srcAccB:=  \emptyset  }
			\nItemX{ act43 }{ destAccB  :=  \emptyset  }
			\end{description}
		\EndAct
		\end{description}
	\EVT {RecvReqTransfer}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\ItemX{ am }
			\ItemX{ c }
			\ItemX{ src\_ac }
			\ItemX{ dest\_ac }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ typing\_c }{ c \in  CARD }
			\nItemX{ typing\_am }{ am \in  \intg  }
			\nItemX{ typing\_src\_ac }{ src\_ac \in  ACCOUNT }
			\nItemX{ typing\_a }{ a \in  ATM }
			\nItemX{ typing\_dest\_ac }{ dest\_ac \in  ACCOUNT }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act4 }{ recvReqTransfer :=  recvReqTransfer \bunion  \{ 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}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ src\_ac }
			\ItemX{ dest\_ac }
			\ItemX{ am }
			\ItemX{ c }
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ typing\_c }{ c \in  CARD }
			\nItemX{ typing\_am }{ am \in  \intg  }
			\nItemX{ typing\_a }{ a \in  ATM }
			\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 <  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}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ typing\_a }{ a \in  ATM }
			\nItemX{ grd2 }{ a \in  transferOk }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act2 }{ transferOk :=   transferOk \setminus  \{ 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 {TransferFails}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ src\_ac }
			\ItemX{ dest\_ac }
			\ItemX{ am }
			\ItemX{ c }
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ typing\_c }{ c \in  CARD }
			\nItemX{ typing\_am }{ am \in  \intg  }
			\nItemX{ typing\_a }{ a \in  ATM }
			\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}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ a }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ typing\_a }{ a \in  ATM }
			\nItemX{ grd2 }{ a \in  transferFail }
			\end{description}
		\ThenAct
			\begin{description}
			\nItemX{ act2 }{ transferFail :=   transferFail \setminus  \{ 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 {Deposit}
		\begin{description}
		\AnyPrm
			\begin{description}
			\ItemX{ acc }
			\ItemX{ am }
			\ItemX{ c }
			\end{description}
		\WhereGrd
			\begin{description}
			\nItemX{ typing\_c }{ c \in  CARD }
			\nItemX{ typing\_am }{ am \in  \intg  }
			\nItemX{ grd1 }{ acc \in  ACCOUNT }
			\nItemX{ grd2 }{ acc \in  dom(bal) }
			\nItemX{ grd3 }{ am \in  \nat_1 }
			\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}
