COSC5315		PROGRAM-2		       		Due: 10/3/2013   
			MGU (Most General Unifier)

	TASK:

	Write a well-structured program for an MGU (Most General Unifier)
	using the following conventions:
	1. Symbols are case-insentive.
	2. Predicate symbols are P1, P2, P3, P4, ...
.	3. Function symbols are F1, F2, F3, ...
	4. Variables are V1, V2, V3, ...
	5. Constants are C1, C2, C3, ...

	INPUTS TO BE USED:

	Use the following six input pairs of predicates:

		P1(V1, V2, V1)		// Initially, both input predicates do not have
		P1(C1, V3, F1(V4))	// the same variable appearing.

		P1(V1, F1(V1), F2(V2, V2))
		P1(C1, F1(V3), F2(V3, F3(V4)))

		P1(F1(V1, V2), V1)
		P1(F1(F2(V3), F3(V4)), V3)

		P1(V1, V1, F1(F2(V2)))
		P1(V3, V4, F1(V3))
	
		P2(C1, V1, F1(C2,V2))
		P2(V3, F2(V4), F1(V4,V4))

		P1(F1(V1,C2), V2)
		P2(F1(C1,C2), C1) 
	
	Output requirements:
	For each input pair,
	  1. Success or failure message
	  2. In case of success, the substitutions found and the resulting
	     unified expression.
	     For example, for the fourth input pair
	     a. Unification successful.
	     b. Substitutions are:
		  V3/V1
		  V4/V3
		  F2(V2)/V4
	     c. Unified expression:
		  P1(F2(V2), F2(V2), F1(F2(V2)))
	
	Algorithm:
	Assume that initially both expressions are in the form of a list each.
	For example,  the very first input pair of expressions may look like:
	    (P1 V1 V2 V1)	// A predicate with 3 arguments
	    (P1 C1 V3 (F1 V4))  // The same as above.
	  #typedef char subs[2,Max1,Max2] 
		// Max1=max number of substitutions like 50
		// Max2=max length of symbols of input predicates like 20
	  #typedef char pred[Max3] // max length of input predicates like 60
	  int Unify(pred P1, pred P2, subs Unifier)
	  1. case-1: Both P1 and P2 are atoms (except variables) or
		     the empty lists
	             if (P1!=P2) return 0
	             else { Unifier={};  return 1}
	  2. case-2: Only P1 is a variable and P2 is not
	             if (P1 occurs in P2) return 0
	             else { Unifier={P2,P1}; return 1}
	  3. case-3: Only P2 is a variable and P1 is not.
	             if (P2 occurs in P1) return 0	//Like the third pair above.
	             else { Unifier={P1,P2}; return 1} 
	  4. case-4: Both P1 and P2 are a variable.
		     Unifier={P2,P1} 	// or {P1,P2}
	             return 1
	  5. either one is an empty list but not both.
	             return 0
	  6. otherwise: Both are a non-empty list, each
	     6.1 H1=(CAR P1)		// get first element of P1
	         H2=(CAR P2)		// get first element of P2
	     6.2 if (!Unify(H1,H2,SUB1)) return 0
		 // else continue
	     6.3 T1=apply(SUB1, (CDR,P1))	// Rest of P1
	         T2=apply(SUB1, (CDR,P2))
	     6.4 if (!Unify(T1,T2,SUB2)) return 0
	     6.5 Unifier=compose(SUB1,SUB2)
	         return 1