Index: doc/theses/jiada_liang_MMath/CFAenum.tex
===================================================================
--- doc/theses/jiada_liang_MMath/CFAenum.tex	(revision 0c51c8b42a007627bcf2537dfce73151c5a015ef)
+++ doc/theses/jiada_liang_MMath/CFAenum.tex	(revision 63d5b9c813497aa370ec41bc6b32ec92e82c0831)
@@ -236,60 +236,26 @@
 However, the position of the underlying representation is the order of the enumerator in the new enumeration.
 \begin{cfa}
-enum() E1 { A };
-enum() E2 { B, C };
+enum() E1 { B };							
+enum() E2 { C, D };							
 enum() E3 { inline E1, inline E2, D };
-\end{cfa}
-Here, @A@ has position 0 in @E1@ and @E3@.
-@B@ has position 0 in @E2@ and 1 in @E3@.
-@C@ has position 1 in @E2@ and position 2 in @E3@.
-@D@ has position 3 in @E3@.
-
-A subtype enumeration can be casted, or implicitly converted into its supertype, with a @safe@ cost.
+enum() E4 { A, inline E3, E };
+\end{cfa}
+In the example above, @B@ has the position 0 in @E1@ and @E3@, but it at the position 0 in @E4@ as taking the 0 there.
+@C@ is at the position 0 in E2, 1 in E3 and 2 in E4. @D@ is at the position 1 in E2, 2 in E3 and 3 in E4. 
+
+A subtype enumeration can be casted, or implicitly converted into its supertype, with a @safe@ cost. Such conversion is an @enumeration conversion@. 
 \begin{cfa}
 enum E2 e2 = C;
-posn( e2 );			$\C[1.75in]{// 1}$
+posn( e2 );			$\C[1.75in]{// 0}$
 enum E3 e3 = e2;
-posn( e2 );			$\C{// 2}$
+posn( e2 );			$\C{// 1}$
 void foo( E3 e );
 foo( e2 );
-posn( (E3)e2 );		$\C{// 2}$
+posn( (E3)e2 );		$\C{// 1}$
 E3 e31 = B;
-posn( e31 );		$\C{// 1}\CRT$
+posn( e31 );		$\C{// 0}\CRT$
 \end{cfa}
 The last expression is unambiguous.
 While both @E2.B@ and @E3.B@ are valid candidate, @E2.B@ has an associated safe cost and \CFA selects the zero cost candidate @E3.B@.
-Hence, as discussed in \VRef{s:OpaqueEnum}, \CFA chooses position as a representation of the \CFA enum.
-Therefore, conversion involves both a change of type and possibly position.
-
-When converting a subtype to a supertype, its position can only be a larger value.
-The difference between the position in the subtype and in the supertype is its \newterm{offset}.
-\VRef[Figure]{s:OffsetSubtypeSuperType} show the algorithm to determine the offset for an subtype enumerator to its super type.
-\PAB{You need to explain the algorithm.}
-
-\begin{figure}
-\begin{cfa}
-struct Enumerator;
-struct CFAEnum {
-	vector<variant<CFAEnum, Enumerator>> members;
-};
-pair<bool, int> calculateEnumOffset( CFAEnum dst, Enumerator e ) {
-	int offset = 0;
-	for ( auto v: dst.members ) {
-		if ( v.holds_alternative<Enumerator>() ) {
-			auto m = v.get<Enumerator>();
-			if ( m == e ) return make_pair( true, 0 );
-			offset++;
-		} else {
-			auto p = calculateEnumOffset( v, e );
-			if ( p.first ) return make_pair( true, offset + p.second );
-			offset += p.second;
-		}
-	}
-	return make_pair( false, offset );
-}
-\end{cfa}
-\caption{Compute Offset from Subtype Enumerator to Super Type}
-\label{s:OffsetSubtypeSuperType}
-\end{figure}
 
 For the given function prototypes, the following calls are valid.
@@ -313,4 +279,53 @@
 Note, the validity of calls is the same for call-by-reference as for call-by-value, and @const@ restrictions are the same as for other types.
 
+\subsection{Offset Calculation}
+As discussed in \VRef{s:OpaqueEnum}, \CFA chooses position as a representation of a \CFA enumeration variable.
+Because enumerators has different @position@ between subtype and supertype, \CFA might need to manipulate the representation whenever a cast or 
+implicit conversion involves two \CFA enums. \CFA determine how a position is going to change with an @offset calculation@ function, reflects to 
+enumerator as an arithmetic expression. Casting an enumeration of subtype to a supertype, the position can be unchanged or increase. The change 
+of position is an @offset@.  
+
+\begin{figure}
+\begin{cfa}
+struct Enumerator;
+struct CFAEnum { vector<variant<CFAEnum, Enumerator>> members; string name; };
+inline static bool operator==(CFAEnum& lhs, CFAEnum& rhs) { return lhs.name == rhs.name; }
+pair<bool, int> calculateEnumOffset(CFAEnum src, CFAEnum dst) {
+	int offset = 0;
+	if (src == dst) return make_pair(true, 0);
+	for (auto v : dst.members) {
+		if (holds_alternative<Enumerator>(v)) {
+			offset++;
+		} else {
+			auto m = get<CFAEnum>(v);
+			if (m == src) return make_pair(true, offset);
+			auto dist = calculateEnumOffset(src, m);
+			if (dist.first) {
+				return make_pair(true, offset + dist.second);
+			} else {
+				offset += dist.second;
+			}
+		}
+	}
+	return make_pair(false, offset);
+}
+\end{cfa}
+\caption{Compute Offset from Subtype Enumeration to a Supertype}
+\label{s:OffsetSubtypeSuperType}
+\end{figure}
+
+Figure~\ref{s:OffsetSubtypeSuperType} shows a minimum of @offset calculation@, written in \CC. CFAEnum represents \CFA enumeration 
+which has a vector of variants of Enumerator or CFAEnum. Two CFAEnums are differentiable by their unquie name.
+The algorithm takes two CFAEnums as parameters @src@ and @dst@, with @src@ being type of expression the conversion applies on, 
+and @dst@ being type that the expression cast into. The algorithm returns a pair of value: when @src@ is convertible to @dst@ (@src@ is a subtype of @dst@),
+it returns boolean true and the offset. Otherwise, it returns false and the size of @src@ (total number of enumerators in @src@). The offset between a type and itself is defined 
+as 0. 
+
+The algorithm iterates over members in @dst@ to find @src@. If a member is an enumerator of @dst@, the positions of all subsequent members
+increment by one. If the current member is @dst@, the function returns true indicating "found" and the accumulated offset. Otherwise, the algorithm recurse 
+into the current CFAEnum @m@ and find out if the @src@ is convertible to @m@. The @src@ being convertible to the current member @m@ means @src@ 
+is a "subtype of subtype" of @dst@. The offset between @src@ and @dst@ is the sum of the offset of @m@ in @dst@ and the offset of 
+@src@ in @m@. If @src@ is not a subtype of @m@, the loop continue but with offset shifted by the size of @m@. The procedure reaches the end 
+of the loop proves @src@ is not convertible to @dst@. It returns size of @src@ in case it is in a recurse innvocation and size is needed for offset update. 
 
 \section{Control Structures}
