using System;

namespace FormulaEditor
{
	
	public interface IFormulaSimplification
	{
		ObjectFormulaTree Simplify(ObjectFormulaTree tree);
	}

	public class FormulaSimplification : IFormulaSimplification
	{
		
		
		#region Constructors

		protected FormulaSimplification()
		{
		}

		#endregion
		
		#region IFormulaSimplification Members

		public virtual ObjectFormulaTree Simplify(ObjectFormulaTree tree)
		{
			return tree;
		}

		#endregion

		#region Specific Members

		static public FormulaSimplification operator * (FormulaSimplification f, IFormulaSimplification g)
		{
			return Compose(f, g);
		}

		static public FormulaSimplification Compose(IFormulaSimplification f, IFormulaSimplification g)
		{
			return new FormulaSimplificationComposition(g, f);
		}

		#endregion
	}

	public class FormulaSimplificationComposition : FormulaSimplification
	{
		
		private IFormulaSimplification first;
		private IFormulaSimplification next;

		public FormulaSimplificationComposition(IFormulaSimplification first, IFormulaSimplification next)
		{
			this.first = first;
			this.next = next;
		}
		
		#region IFormulaSimplification Members

		public override ObjectFormulaTree Simplify(ObjectFormulaTree formula)
		{
			ObjectFormulaTree t = first.Simplify(formula);
			return next.Simplify(t);
		}

		#endregion
	}
}
